mirror of
https://github.com/moparisthebest/Conversations
synced 2024-12-01 05:02:21 -05:00
further bullet proofing
This commit is contained in:
parent
a92fb88e51
commit
899da61555
@ -42,7 +42,7 @@ public class Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Element findChild(String name) {
|
public Element findChild(String name) {
|
||||||
for(Element child : this.children) {
|
for (Element child : this.children) {
|
||||||
if (child.getName().equals(name)) {
|
if (child.getName().equals(name)) {
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
@ -51,8 +51,9 @@ public class Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Element findChild(String name, String xmlns) {
|
public Element findChild(String name, String xmlns) {
|
||||||
for(Element child : this.children) {
|
for (Element child : this.children) {
|
||||||
if (child.getName().equals(name)&&(child.getAttribute("xmlns").equals(xmlns))) {
|
if (child.getName().equals(name)
|
||||||
|
&& (child.getAttribute("xmlns").equals(xmlns))) {
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,8 +68,6 @@ public class Element {
|
|||||||
return findChild(name, xmlns) != null;
|
return findChild(name, xmlns) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<Element> getChildren() {
|
public List<Element> getChildren() {
|
||||||
return this.children;
|
return this.children;
|
||||||
}
|
}
|
||||||
@ -83,7 +82,9 @@ public class Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Element setAttribute(String name, String value) {
|
public Element setAttribute(String name, String value) {
|
||||||
this.attributes.put(name, value);
|
if (name != null && value != null) {
|
||||||
|
this.attributes.put(name, value);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ public class Element {
|
|||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder elementOutput = new StringBuilder();
|
StringBuilder elementOutput = new StringBuilder();
|
||||||
if ((content==null)&&(children.size() == 0)) {
|
if ((content == null) && (children.size() == 0)) {
|
||||||
Tag emptyTag = Tag.empty(name);
|
Tag emptyTag = Tag.empty(name);
|
||||||
emptyTag.setAtttributes(this.attributes);
|
emptyTag.setAtttributes(this.attributes);
|
||||||
elementOutput.append(emptyTag.toString());
|
elementOutput.append(emptyTag.toString());
|
||||||
@ -114,10 +115,10 @@ public class Element {
|
|||||||
Tag startTag = Tag.start(name);
|
Tag startTag = Tag.start(name);
|
||||||
startTag.setAtttributes(this.attributes);
|
startTag.setAtttributes(this.attributes);
|
||||||
elementOutput.append(startTag);
|
elementOutput.append(startTag);
|
||||||
if (content!=null) {
|
if (content != null) {
|
||||||
elementOutput.append(encodeEntities(content));
|
elementOutput.append(encodeEntities(content));
|
||||||
} else {
|
} else {
|
||||||
for(Element child : children) {
|
for (Element child : children) {
|
||||||
elementOutput.append(child.toString());
|
elementOutput.append(child.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,11 +133,11 @@ public class Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String encodeEntities(String content) {
|
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;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user