Ejemplo n.º 1
0
 @Override
 public void write(PrintWriter writer, int indent) {
   writeIndent(indent, writer);
   if (_children != null && _children.size() > 0) {
     writer.print("<");
     writer.print(_name);
     writeAttributes(writer);
     writer.print(">");
     if (_children.size() == 1 && _children.get(0) instanceof ERXML.Text) {
       _children.get(0).write(writer, 0);
     } else {
       writer.println();
       for (ERXML.Node node : _children) {
         node.write(writer, indent + 1);
       }
       writeIndent(indent, writer);
     }
     writer.print("</");
     writer.print(_name);
     writer.println(">");
   } else {
     writer.print("<");
     writer.print(_name);
     writeAttributes(writer);
     writer.println(" />");
   }
 }
Ejemplo n.º 2
0
 @Override
 public void visit(ERXML.Visitor visitor) {
   if (visitor.visit(this) && _children != null) {
     for (ERXML.Node node : _children) {
       node.visit(visitor);
     }
   }
 }
Ejemplo n.º 3
0
 @Override
 public org.w3c.dom.Node w3c(Document doc) {
   Element e = doc.createElement(_name);
   if (_attributes != null) {
     for (ERXML.Attr attribute : _attributes) {
       e.setAttribute(attribute.name(), attribute.value());
     }
   }
   if (_children != null) {
     for (ERXML.Node child : _children) {
       org.w3c.dom.Node childNode = child.w3c(doc);
       e.appendChild(childNode);
     }
   }
   return e;
 }
Ejemplo n.º 4
0
    /**
     * Returns a set of descendent elements of this element that have the given name, or an empty
     * list if there aren't any.
     *
     * @param name the name of the descendent elements to look up
     * @return a set of descendents of this element that have the given name, or an empty set if
     *     there aren't any
     */
    public Set<ERXML.E> descendents(final String name) {
      final Set<ERXML.E> descendents = new LinkedHashSet<ERXML.E>();
      if (_children != null) {
        ERXML.Visitor visitor =
            new ERXML.Visitor() {
              public boolean visit(Item item) {
                if (item instanceof ERXML.E && ((ERXML.E) item)._name.equals(name)) {
                  descendents.add((ERXML.E) item);
                }
                return true;
              }
            };

        for (ERXML.Node node : _children) {
          node.visit(visitor);
        }
      }
      return descendents;
    }