Ejemplo n.º 1
0
 public String toString() {
   StringBuilder builder = new StringBuilder();
   builder.append("<");
   builder.append(name);
   for (Map.Entry<Object, Object> entry : attributes.entrySet()) {
     builder.append(" ");
     builder.append(entry.getKey());
     builder.append("=\"");
     builder.append(entry.getValue());
     builder.append("\"");
   }
   List<XNode> children = getChildren();
   if (children.size() > 0) {
     builder.append(">\n");
     for (XNode node : children) {
       builder.append(node.toString());
     }
     builder.append("</");
     builder.append(name);
     builder.append(">");
   } else if (body != null) {
     builder.append(">");
     builder.append(body);
     builder.append("</");
     builder.append(name);
     builder.append(">");
   } else {
     builder.append("/>");
   }
   builder.append("\n");
   return builder.toString();
 }
Ejemplo n.º 2
0
 public Properties getChildrenAsProperties() {
   Properties properties = new Properties();
   for (XNode child : getChildren()) {
     String name = child.getStringAttribute("name");
     String value = child.getStringAttribute("value");
     if (name != null && value != null) {
       properties.setProperty(name, value);
     }
   }
   return properties;
 }
Ejemplo n.º 3
0
 public String getValueBasedIdentifier() {
   StringBuilder builder = new StringBuilder();
   XNode current = this;
   while (current != null) {
     if (current != this) {
       builder.insert(0, "_");
     }
     String value =
         current.getStringAttribute(
             "id",
             current.getStringAttribute("value", current.getStringAttribute("property", null)));
     if (value != null) {
       builder.insert(0, "]");
       builder.insert(0, value);
       builder.insert(0, "[");
     }
     builder.insert(0, current.getName());
     current = current.getParent();
   }
   return builder.toString();
 }