bool LibreOfficeInspector::_readNodeCallback(XmlNode node, void *data)
{
	vector <XmlAttribute>* attributes;
	bool bIsItem;

	if (g_parsing_state == PropUILocale && node.GetName().compare(L"value")==0)
	{		
		wstring* lang_found = (wstring *) data;
		*lang_found = node.GetText();
		g_parsing_state = ItemOther;
		return false;
	}

	bIsItem = node.GetName().compare(L"item") == 0;

	if (bIsItem && g_parsing_state != ItemOther)
	{
		g_parsing_state = ItemOther;
	}	

	attributes = node.GetAttributes();
	for (unsigned int i = 0; i < attributes->size(); i++)
	{
		XmlAttribute attribute;

		attribute = attributes->at(i);

		if (g_parsing_state == ItemOther && bIsItem && attribute.GetName() == L"oor:path" && attribute.GetValue() == L"/org.openoffice.Office.Linguistic/General")
		{
			g_parsing_state = ItemLinguisticGeneral;			
		}

		if (g_parsing_state == ItemLinguisticGeneral && attribute.GetName() == L"oor:name" && attribute.GetValue() == L"UILocale")
		{
			g_parsing_state = PropUILocale;
		}		
	}
	
	return true;
}
Esempio n. 2
0
//[-------------------------------------------------------]
//[ Protected virtual XmlTextElement functions            ]
//[-------------------------------------------------------]
void XmlTextImage::OnParse(XmlNode &cXmlNode)
{
	// Is this an XML element?
	if (cXmlNode.GetType() == XmlNode::Element) {
		// Destroy the previous image
		if (m_pImage) {
			delete m_pImage;
			m_pImage = nullptr;
		}

		// Get XML element
		XmlElement &cXmlElement = static_cast<XmlElement&>(cXmlNode);

		// Parse attributes
		XmlAttribute *pAttribute = cXmlElement.GetFirstAttribute();
		while (pAttribute) {
			// Get name and value
			String sName  = pAttribute->GetName();
			String sValue = pAttribute->GetValue();

			// Save attribute
			if (sName.CompareNoCase("Src")) {
				// Image filename
				m_sFilename = sValue;
			} else if (sName.CompareNoCase("Width")) {
				// Image width
				m_vSize.x = sValue.GetInt();
			} if (sName.CompareNoCase("Height")) {
				// Image height
				m_vSize.y = sValue.GetInt();
			}

			// Next attribute
			pAttribute = pAttribute->GetNext();
		}

	}
}
Esempio n. 3
0
const char *XmlElement::Parse(const char *pszData, XmlParsingData *pData, EEncoding nEncoding)
{
	pszData = SkipWhiteSpace(pszData, nEncoding);
	if (!pszData || !*pszData) {
		// Set error code
		XmlDocument *pDocument = GetDocument();
		if (pDocument)
			pDocument->SetError(ErrorParsingElement, 0, 0, nEncoding);

		// Error!
		return nullptr;
	}

	if (pData) {
		pData->Stamp(pszData, nEncoding);
		m_cCursor = pData->Cursor();
	}

	if (*pszData != '<') {
		// Set error code
		XmlDocument *pDocument = GetDocument();
		if (pDocument)
			pDocument->SetError(ErrorParsingElement, pszData, pData, nEncoding);

		// Error!
		return nullptr;
	}
	pszData = SkipWhiteSpace(pszData + 1, nEncoding);

	// Read the name
	const char *pszError = pszData;
	pszData = ReadName(pszData, m_sValue, nEncoding);
	if (!pszData || !*pszData) {
		// Set error code
		XmlDocument *pDocument = GetDocument();
		if (pDocument)
			pDocument->SetError(ErrorFailedToReadElementName, pszError, pData, nEncoding);

		// Error!
		return nullptr;
	}

	String sEndTag = "</";
	sEndTag += m_sValue;

	// Check for and read attributes. Also look for an empty tag or an end tag
	while (pszData && *pszData) {
		pszError = pszData;
		pszData = SkipWhiteSpace(pszData, nEncoding);
		if (!pszData || !*pszData) {
			// Set error code
			XmlDocument *pDocument = GetDocument();
			if (pDocument)
				pDocument->SetError(ErrorReadingAttributes, pszError, pData, nEncoding);

			// Error!
			return nullptr;
		}
		if (*pszData == '/') {
			++pszData;

			// Empty tag
			if (*pszData != '>') {
				// Set error code
				XmlDocument *pDocument = GetDocument();
				if (pDocument)
					pDocument->SetError(ErrorParsingEmpty, pszData, pData, nEncoding);

				// Error!
				return nullptr;
			}
			return (pszData + 1);
		} else if (*pszData == '>') {
			// Done with attributes (if there were any)
			// Read the value -- which can include other elements -- read the end tag, and return
			++pszData;
			pszData = ReadValue(pszData, pData, nEncoding);	// Note this is an Element method, and will set the error if one happens
			if (!pszData || !*pszData) {
				// We were looking for the end tag, but found nothing
				XmlDocument *pDocument = GetDocument();
				if (pDocument)
					pDocument->SetError(ErrorReadingEndTag, pszData, pData, nEncoding);

				// Error!
				return nullptr;
			}

			// We should find the end tag now
			// Note that:
			// </foo > and
			// </foo>
			// are both valid end tags
			if (StringEqual(pszData, sEndTag, false, nEncoding)) {
				pszData += sEndTag.GetLength();
				pszData = SkipWhiteSpace(pszData, nEncoding);
				if (pszData && *pszData && *pszData == '>') {
					++pszData;
					return pszData;
				}

				// Set error code
				XmlDocument *pDocument = GetDocument();
				if (pDocument)
					pDocument->SetError(ErrorReadingEndTag, pszData, pData, nEncoding);

				// Error!
				return nullptr;
			} else {
				// Set error code
				XmlDocument *pDocument = GetDocument();
				if (pDocument)
					pDocument->SetError(ErrorReadingEndTag, pszData, pData, nEncoding);

				// Error!
				return nullptr;
			}
		} else {
			// Try to read an attribute
			XmlAttribute *pAttribute = new XmlAttribute();
			pAttribute->m_pDocument = GetDocument();
			pszError = pszData;
			pszData = pAttribute->Parse(pszData, pData, nEncoding);
			if (!pszData || !*pszData) {
				// Set error code
				XmlDocument *pDocument = GetDocument();
				if (pDocument)
					pDocument->SetError(ErrorParsingElement, pszError, pData, nEncoding);

				// Destroy the created attribute
				delete pAttribute;

				// Error!
				return nullptr;
			}

			// Handle the strange case of double attributes
			XmlAttribute *pNode = m_cAttributeSet.Find(pAttribute->GetName());
			if (pNode) {
				// Set error code
				XmlDocument *pDocument = GetDocument();
				if (pDocument)
					pDocument->SetError(ErrorParsingElement, pszError, pData, nEncoding);

				// Destroy the created attribute
				delete pAttribute;

				// Error!
				return nullptr;
			}

			// Register the created attribute
			m_cAttributeSet.Add(*pAttribute);
		}
	}

	// Done
	return pszData;
}