Navigation Menu

Skip to content

Commit

Permalink
Separate extendable methods for xml key and value processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Rass committed Apr 8, 2014
1 parent fcb2260 commit 8102cd1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/main/com/trendrr/oss/DynMap.java
Expand Up @@ -847,15 +847,15 @@ else if (o instanceof java.util.Collection) {
collection += this
.toXMLStringCollection((java.util.Collection) b);
else
collection += processXMLString(b.toString());
collection += processXMLValue(b.toString());
collection += "</item>";
}
} else if (o instanceof java.util.Map) {
DynMap dm = new DynMap();
dm.putAll((java.util.Map) o);
collection += dm.toXMLString();
} else
collection += processXMLString(o.toString());
collection += processXMLValue(o.toString());
collection += "</item>";
}
return collection;
Expand All @@ -874,7 +874,7 @@ public String toXMLString() {
Iterator iter = this.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
String element = String.valueOf(entry.getKey()).replaceAll(" ", "_");
String element = processXMLKey(String.valueOf(entry.getKey()));
buf.append("<" + element + ">");
if (entry.getValue() instanceof DynMap) {
buf.append(((DynMap) entry.getValue())
Expand All @@ -889,7 +889,7 @@ public String toXMLString() {
} else if ((entry.getValue()) instanceof Date) {
buf.append(IsoDateUtil.getIsoDateNoMillis(((Date)entry.getValue())));
} else {
buf.append(processXMLString(entry.getValue().toString()));
buf.append(processXMLValue(entry.getValue().toString()));
}
buf.append("</" + element + ">");
}
Expand All @@ -898,11 +898,20 @@ public String toXMLString() {
}

/**
* Simple string process for xml output
* Simple key processing. Extend DynMap to override how xml keys are processed
* @param str
* @return
*/
private String processXMLString(String str) {
protected String processXMLKey(String str) {
return str;
}

/**
* Simple value processing. Extend DynMap to override how xml values are processed
* @param str
* @return
*/
protected String processXMLValue(String str) {
return str;
}
}
Binary file modified trendrr-oss.jar
Binary file not shown.

0 comments on commit 8102cd1

Please sign in to comment.