Exemple #1
0
void GeneralPage::GetLangList()
{
	if (m_languagesList.empty())
	{
		m_languagesList.insert(make_pair(L"English", "en-US.xml"));
		const StringList& l_files = File::findFiles(Util::getLocalisationPath(), "*-*.xml");
		for (auto i = l_files.cbegin(); i != l_files.cend(); ++i)
		{
			string l_langFileName = Util::getFileName(*i);
			if (!GetLangByFile(l_langFileName, m_languagesList))
			{
				XMLParser::XMLResults xRes;
				const XMLParser::XMLNode xRootNode = XMLParser::XMLNode::parseFile(Text::toT(*i).c_str(), 0, &xRes);
				if (xRes.error == XMLParser::eXMLErrorNone)
				{
					const XMLParser::XMLNode ResNode = xRootNode.getChildNode("Language");
					if (!ResNode.isEmpty())
					{
						m_languagesList.insert(make_pair(Text::toT(ResNode.getAttributeOrDefault("Name")), l_langFileName));
					}
				}
			}
		}
	}
}
bool
RSSFeed::UpdateFeedNewXML()
{
	time_t maxLastDate = 0;
	clearNewsList();
	string data;
	try
	{
		GetRSSData(feedURL, data);
		XMLParser::XMLResults xRes;
		XMLParser::XMLNode xRootNode = XMLParser::XMLNode::parseString(Text::toUtf8(data).c_str(), 0, &xRes);
		if (xRes.error == XMLParser::eXMLErrorNone)
		{
			string codeingType = codeing;
			if (codeingType.empty() && xRootNode.isAttributeSet("encoding"))
			{
				// "windows-1251" or "utf-8"
				codeingType = xRootNode.getAttributeOrDefault("encoding");
			}
			std::transform(codeingType.begin(), codeingType.end(), codeingType.begin(), ::tolower);
			bool isUtf8 = false;
			if (codeingType == "utf-8")
				isUtf8 = true;
				
			const RssFormat rssFormat = DetectRSSFormat(&xRootNode, XML_PARSER);
			
			switch (rssFormat)
			{
				case RSS_2_0:
					return ProcessRSS(&xRootNode, XML_PARSER, isUtf8);
				case RSS_ATOM:
					return ProcessAtom(&xRootNode, XML_PARSER, isUtf8);
			}
		}
		else
		{
			return UpdateFeedOldParser(data);
		}
		return false;
	}
	catch (const Exception& e)
	{
		LogManager::message(e.getError());
		return false;
	}
}