Changeset - b297329ba32f
[Not reviewed]
0 2 0
Sarang Bharadwaj - 13 years ago 2012-06-12 12:13:39
sarang.bh@gmail.com
Handling exceptions related to XML parser
2 files changed with 38 insertions and 4 deletions:
0 comments (0 inline, 0 general)
backends/twitter/TwitterPlugin.cpp
Show inline comments
 
@@ -382,12 +382,21 @@ void TwitterPlugin::directMessageResponse(std::string &user, std::vector<DirectM
 
	if(!messages.size()) return;
 
	
 
	if(twitterMode == SINGLECONTACT) {
 
		std::string msglist = "\n***************MSG LIST****************\n";
 

	
 
		std::string msglist = "";
 
		std::string msgID = getMostRecentDMID(user);
 
		std::string maxID = msgID;
 
		
 
		for(int i=0 ; i < messages.size() ; i++) {
 
			msglist += " - " + messages[i].getSenderData().getScreenName() + ": " + messages[i].getMessage() + "\n";
 
			if(cmp(msgID, messages[i].getID()) == -1) {
 
				msglist += " - " + messages[i].getSenderData().getScreenName() + ": " + messages[i].getMessage() + "\n";
 
				if(cmp(maxID, messages[i].getID()) == -1) maxID = messages[i].getID();
 
			}
 
		}	
 
		msglist += "***************************************\n";
 
		handleMessage(user, "twitter-account", msglist);	
 

	
 
		if(msglist.length()) handleMessage(user, "twitter-account", msglist);	
 
		updateLastDMID(user, maxID);
 

	
 
	} else if(twitterMode == MULTIPLECONTACT) {
 
		
 
		std::string msgID = getMostRecentDMID(user);
backends/twitter/TwitterResponseParser.cpp
Show inline comments
 
@@ -67,6 +67,11 @@ std::vector<Status> getTimeline(std::string &xml)
 
	std::vector<Status> statuses;
 
	Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
 
	
 
	if(rootElement == NULL) {
 
		LOG4CXX_ERROR(logger, "Error while parsing XML")
 
		return statuses;
 
	}
 

	
 
	if(rootElement->getName() != "statuses") {
 
		LOG4CXX_ERROR(logger, "XML doesn't correspond to timeline")
 
		return statuses;
 
@@ -87,6 +92,11 @@ std::vector<DirectMessage> getDirectMessages(std::string &xml)
 
	std::vector<DirectMessage> DMs;
 
	Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
 
	
 
	if(rootElement == NULL) {
 
		LOG4CXX_ERROR(logger, "Error while parsing XML")
 
		return DMs;
 
	}
 
	
 
	if(rootElement->getName() != TwitterReponseTypes::directmessages) {
 
		LOG4CXX_ERROR(logger, "XML doesn't correspond to direct-messages")
 
		return DMs;
 
@@ -107,6 +117,11 @@ std::vector<User> getUsers(std::string &xml)
 
	std::vector<User> users;
 
	Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
 
	
 
	if(rootElement == NULL) {
 
		LOG4CXX_ERROR(logger, "Error while parsing XML")
 
		return users;
 
	}
 

	
 
	if(rootElement->getName() != TwitterReponseTypes::users) {
 
		LOG4CXX_ERROR(logger, "XML doesn't correspond to user list")
 
		return users;
 
@@ -127,6 +142,11 @@ std::vector<std::string> getIDs(std::string &xml)
 
	std::vector<std::string> IDs;
 
	Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
 

	
 
	if(rootElement == NULL) {
 
		LOG4CXX_ERROR(logger, "Error while parsing XML")
 
		return IDs;
 
	}
 

	
 
	if(rootElement->getName() != TwitterReponseTypes::id_list) {
 
		LOG4CXX_ERROR(logger, "XML doesn't correspond to id_list");
 
		return IDs;
 
@@ -146,6 +166,11 @@ std::string getErrorMessage(std::string &xml)
 
	std::string error;
 
	Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
 

	
 
	if(rootElement == NULL) {
 
		LOG4CXX_ERROR(logger, "Error while parsing XML");
 
		return "";
 
	}
 

	
 
	const std::string xmlns = rootElement->getNamespace();
 
	const Swift::ParserElement::ref errorElement = rootElement->getChild(TwitterReponseTypes::error, xmlns);
 
	
0 comments (0 inline, 0 general)