Example #1
0
 @Override
 public void accept(ThreadContext context, SaveContextVisitor visitor) {
   visitor.enter((Element) node);
   XmlNodeSet xmlNodeSet = (XmlNodeSet) children(context);
   if (xmlNodeSet.length() > 0) {
     RubyArray array = (RubyArray) xmlNodeSet.to_a(context);
     for (int i = 0; i < array.getLength(); i++) {
       Object item = array.get(i);
       if (item instanceof XmlNode) {
         XmlNode cur = (XmlNode) item;
         cur.accept(context, visitor);
       } else if (item instanceof XmlNamespace) {
         XmlNamespace cur = (XmlNamespace) item;
         cur.accept(context, visitor);
       }
     }
   }
   visitor.leave((Element) node);
 }
Example #2
0
 public boolean enter(Element element) {
   String current = indentation.peek();
   buffer.append(current);
   if (needIndent()) {
     indentation.push(current + indentString);
   }
   String name = element.getTagName();
   buffer.append("<" + name);
   NamedNodeMap attrs = element.getAttributes();
   for (int i = 0; i < attrs.getLength(); i++) {
     Attr attr = (Attr) attrs.item(i);
     if (attr.getSpecified()) {
       buffer.append(" ");
       enter(attr);
       leave(attr);
     }
   }
   if (element.hasChildNodes()) {
     buffer.append(">");
     if (needBreakInOpening(element)) buffer.append("\n");
     return true;
   }
   // no child
   if (asHtml) {
     buffer.append(">");
   } else if (asXhtml) {
     buffer.append(" />");
   } else if (asXml && noEmpty) {
     buffer.append(">");
   } else {
     buffer.append("/>");
   }
   if (needBreakInOpening(element)) {
     buffer.append("\n");
   }
   return true;
 }