further bullet proofing
This commit is contained in:
parent
a92fb88e51
commit
899da61555
|
@ -42,7 +42,7 @@ public class Element {
|
|||
}
|
||||
|
||||
public Element findChild(String name) {
|
||||
for(Element child : this.children) {
|
||||
for (Element child : this.children) {
|
||||
if (child.getName().equals(name)) {
|
||||
return child;
|
||||
}
|
||||
|
@ -51,8 +51,9 @@ public class Element {
|
|||
}
|
||||
|
||||
public Element findChild(String name, String xmlns) {
|
||||
for(Element child : this.children) {
|
||||
if (child.getName().equals(name)&&(child.getAttribute("xmlns").equals(xmlns))) {
|
||||
for (Element child : this.children) {
|
||||
if (child.getName().equals(name)
|
||||
&& (child.getAttribute("xmlns").equals(xmlns))) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
@ -67,8 +68,6 @@ public class Element {
|
|||
return findChild(name, xmlns) != null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<Element> getChildren() {
|
||||
return this.children;
|
||||
}
|
||||
|
@ -83,7 +82,9 @@ public class Element {
|
|||
}
|
||||
|
||||
public Element setAttribute(String name, String value) {
|
||||
this.attributes.put(name, value);
|
||||
if (name != null && value != null) {
|
||||
this.attributes.put(name, value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -106,7 +107,7 @@ public class Element {
|
|||
|
||||
public String toString() {
|
||||
StringBuilder elementOutput = new StringBuilder();
|
||||
if ((content==null)&&(children.size() == 0)) {
|
||||
if ((content == null) && (children.size() == 0)) {
|
||||
Tag emptyTag = Tag.empty(name);
|
||||
emptyTag.setAtttributes(this.attributes);
|
||||
elementOutput.append(emptyTag.toString());
|
||||
|
@ -114,10 +115,10 @@ public class Element {
|
|||
Tag startTag = Tag.start(name);
|
||||
startTag.setAtttributes(this.attributes);
|
||||
elementOutput.append(startTag);
|
||||
if (content!=null) {
|
||||
if (content != null) {
|
||||
elementOutput.append(encodeEntities(content));
|
||||
} else {
|
||||
for(Element child : children) {
|
||||
for (Element child : children) {
|
||||
elementOutput.append(child.toString());
|
||||
}
|
||||
}
|
||||
|
@ -132,11 +133,11 @@ public class Element {
|
|||
}
|
||||
|
||||
private String encodeEntities(String content) {
|
||||
content = content.replace("&","&");
|
||||
content = content.replace("<","<");
|
||||
content = content.replace(">",">");
|
||||
content = content.replace("\"",""");
|
||||
content = content.replace("'","'");
|
||||
content = content.replace("&", "&");
|
||||
content = content.replace("<", "<");
|
||||
content = content.replace(">", ">");
|
||||
content = content.replace("\"", """);
|
||||
content = content.replace("'", "'");
|
||||
return content;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue