Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New function for XML Documents #721

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/flickr4java/flickr/RESTResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Element>) XMLUtilities.getChildElements(rspElement);
} else if ("fail".equals(stat)) {
Element errElement = (Element) rspElement.getElementsByTagName("err").item(0);
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/flickr4java/flickr/util/XMLUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("</") && finalLabel.endsWith(">")) {
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;
}

}