aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/xml/Element.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-01-30 16:42:35 +0100
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-01-30 16:42:35 +0100
commit6c5c3ac2decac75ec3208d47912e67c4e1a33548 (patch)
treec6cdcc5d76608369da08eb76891c48ffefbb9a48 /src/de/gultsch/chat/xml/Element.java
parentad11dab6359a1eb2b6921d36117093066999fb96 (diff)
first draft on xml parser and communication. a long way to go. code definitly not perfect. will refactor asap
Diffstat (limited to '')
-rw-r--r--src/de/gultsch/chat/xml/Element.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/de/gultsch/chat/xml/Element.java b/src/de/gultsch/chat/xml/Element.java
new file mode 100644
index 00000000..d6d1b23d
--- /dev/null
+++ b/src/de/gultsch/chat/xml/Element.java
@@ -0,0 +1,65 @@
+package de.gultsch.chat.xml;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+public class Element {
+ protected String name;
+ protected Hashtable<String, String> attributes = new Hashtable<String, String>();
+ protected String content;
+ protected List<Element> children = new ArrayList<Element>();
+
+ public Element(String name) {
+ this.name = name;
+ }
+
+ public Element addChild(Element child) {
+ this.content = null;
+ children.add(child);
+ return this;
+ }
+
+ public Element setContent(String content) {
+ this.content = content;
+ this.children.clear();
+ return this;
+ }
+
+ public Element setAttribute(String name, String value) {
+ this.attributes.put(name, value);
+ return this;
+ }
+
+ public Element setAttributes(Hashtable<String, String> attributes) {
+ this.attributes = attributes;
+ return this;
+ }
+
+ public String toString() {
+ StringBuilder elementOutput = new StringBuilder();
+ if ((content==null)&&(children.size() == 0)) {
+ Tag emptyTag = Tag.empty(name);
+ emptyTag.setAtttributes(this.attributes);
+ elementOutput.append(emptyTag.toString());
+ } else {
+ Tag startTag = Tag.start(name);
+ startTag.setAtttributes(this.attributes);
+ elementOutput.append(startTag);
+ if (content!=null) {
+ elementOutput.append(content);
+ } else {
+ for(Element child : children) {
+ elementOutput.append(child.toString());
+ }
+ }
+ Tag endTag = Tag.end(name);
+ elementOutput.append(endTag);
+ }
+ return elementOutput.toString();
+ }
+
+ public String getName() {
+ return name;
+ }
+}