diff --git a/src/main/java/com/flickr4java/flickr/RESTResponse.java b/src/main/java/com/flickr4java/flickr/RESTResponse.java index e35da74..8a34f6e 100644 --- a/src/main/java/com/flickr4java/flickr/RESTResponse.java +++ b/src/main/java/com/flickr4java/flickr/RESTResponse.java @@ -30,6 +30,7 @@ public void parse(Document document) { stat = rspElement.getAttribute("stat"); if ("ok".equals(stat)) { // TODO: Verify that the payload is always a single XML node + // Function has been made in XMLUtilities.java payload = (List) XMLUtilities.getChildElements(rspElement); } else if ("fail".equals(stat)) { Element errElement = (Element) rspElement.getElementsByTagName("err").item(0); diff --git a/src/main/java/com/flickr4java/flickr/util/XMLUtilities.java b/src/main/java/com/flickr4java/flickr/util/XMLUtilities.java index fb104ff..f384feb 100644 --- a/src/main/java/com/flickr4java/flickr/util/XMLUtilities.java +++ b/src/main/java/com/flickr4java/flickr/util/XMLUtilities.java @@ -93,4 +93,27 @@ public static boolean getBooleanAttribute(Element el, String name) { return Boolean.getBoolean(s); } + /** + * Verifies if a given xml code is a single node or not + * + * @param xmlCode + * The xml code that has to be checked + + * @return True if a xml code is a single node, otherwise returns False + */ + public static boolean isASingleXMLNode(String xmlCode) { + String initialLabel = xmlCode.substring(0, xmlCode.substring(1, xmlCode.length()).indexOf('>')+2); + String finalLabel = xmlCode.substring(xmlCode.substring(0, xmlCode.length()-1).lastIndexOf('<'), xmlCode.length()); + boolean answer = false; + if(initialLabel.startsWith("<") && initialLabel.endsWith(">") && finalLabel.startsWith("")) { + if(initialLabel.substring(1, initialLabel.length()-1).equals(finalLabel.substring(2, finalLabel.length()-1))) { + String payloadBody = xmlCode.substring(initialLabel.length(), xmlCode.length()-finalLabel.length()); + if(!(payloadBody.contains(initialLabel) || payloadBody.contains(finalLabel))){ + answer = true; + } + } + } + return answer; + } + }