protected void printName(Node node) { Object name = node.name(); if (name != null) { out.print(name.toString()); } else { out.print("null"); } }
private String getName(Object object) { if (object instanceof String) { return (String) object; } else if (object instanceof QName) { QName qname = (QName) object; if (!namespaceAware) { return qname.getLocalPart(); } return qname.getQualifiedName(); } else if (object instanceof Node) { Object name = ((Node) object).name(); return getName(name); } return object.toString(); }
protected boolean printSpecialNode(Node node) { Object name = node.name(); if (name != null && name instanceof QName) { QName qn = (QName) name; // check uri and for legacy cases just check prefix name (not recommended) if (qn.getNamespaceURI().equals("http://groovy.codehaus.org/2005/gsp") || qn.getPrefix().equals("gsp")) { String s = qn.getLocalPart(); if (s.length() == 0) { throw new RuntimeException("No local part after 'gsp:' given in node " + node); } printGroovyTag(s, node.text()); return true; } } return false; } }
/** * Provides lookup of elements by QName. * * @param name the QName of interest * @return the nodes matching name */ public NodeList getAt(QName name) { NodeList answer = new NodeList(); for (Object child : children()) { if (child instanceof Node) { Node childNode = (Node) child; Object childNodeName = childNode.name(); if (name.matches(childNodeName)) { answer.add(childNode); } } } return answer; }
/** * Provides lookup of elements by name. * * @param name the name of interest * @return the nodes matching name */ private NodeList getByName(String name) { NodeList answer = new NodeList(); for (Object child : children()) { if (child instanceof Node) { Node childNode = (Node) child; Object childNodeName = childNode.name(); if (childNodeName instanceof QName) { QName qn = (QName) childNodeName; if (qn.matches(name)) { answer.add(childNode); } } else if (name.equals(childNodeName)) { answer.add(childNode); } } } return answer; }
private void appendNodes(Closure c) { List tail = getTail(); for (Node child : buildChildrenFromClosure(c)) { parent().appendNode(child.name(), child.attributes(), child.value()); } parent().children().addAll(tail); }
/** * Replaces the current node with the supplied node. * * @param n the new Node * @return the original now replaced node */ public Node replaceNode(Node n) { if (parent() == null) { throw new UnsupportedOperationException("Replacing the root node is not supported"); } List tail = getTail(); parent().appendNode(n.name(), n.attributes(), n.value()); parent().children().addAll(tail); getParentList(parent()).remove(this); this.setParent(null); return this; }
protected void printName(Node node, NamespaceContext ctx, boolean begin, boolean preserve) { if (node == null) { throw new NullPointerException("Node must not be null."); } Object name = node.name(); if (name == null) { throw new NullPointerException("Name must not be null."); } if (!preserve || begin) printLineBegin(); out.print("<"); if (!begin) { out.print("/"); } out.print(getName(node)); if (ctx != null) { printNamespace(node, ctx); } if (begin) { printNameAttributes(node.attributes(), ctx); } out.print(">"); if (!preserve || !begin) printLineEnd(); }
protected void printNamespace(Object object, NamespaceContext ctx) { if (namespaceAware) { if (object instanceof Node) { printNamespace(((Node) object).name(), ctx); } else if (object instanceof QName) { QName qname = (QName) object; String namespaceUri = qname.getNamespaceURI(); if (namespaceUri != null) { String prefix = qname.getPrefix(); if (!ctx.isPrefixRegistered(prefix, namespaceUri)) { ctx.registerNamespacePrefix(prefix, namespaceUri); out.print(" "); out.print("xmlns"); if (prefix.length() > 0) { out.print(":"); out.print(prefix); } out.print("=" + quote); out.print(namespaceUri); out.print(quote); } } } } }
private void merge(Properties props, Node node, String prefix) { assert props != null; assert node != null; assert prefix != null; String name = prefix + node.name(); Object value = node.value(); if (value instanceof String) { props.setProperty(name, String.valueOf(value)); } Map attrs = node.attributes(); for (Object key : attrs.keySet()) { props.setProperty(name + "." + key, String.valueOf(attrs.get(key))); } for (Object child : node.children()) { if (child instanceof Node) { merge(props, (Node) child, name + "."); } } } }
private Xpp3Dom nodeToXpp3(final Node node) { Xpp3Dom dom = new Xpp3Dom((String) node.name()); Object value = node.value(); if (value instanceof String) { dom.setValue(String.valueOf(value)); } Map attrs = node.attributes(); for (Object key : attrs.keySet()) { dom.setAttribute(String.valueOf(key), String.valueOf(attrs.get(key))); } for (Object child : node.children()) { if (child instanceof Node) { dom.addChild(nodeToXpp3((Node) child)); } } return dom; } }
private Node findChild(Node node, String name) { for (Object childObject : node.children()) { if ((childObject instanceof Node) && ((Node) childObject).name().equals(name)) { return (Node) childObject; } } return null; }
protected void printName(Node node) { Object name = node.name(); if (name != null) { out.print(name.toString()); } else { out.print("null"); } }
protected void printName(Node node) { Object name = node.name(); if (name != null) { out.print(name.toString()); } else { out.print("null"); } }
protected void printName(Node node) { Object name = node.name(); if (name != null) { out.print(name.toString()); } else { out.print("null"); } }
protected void printName(Node node) { Object name = node.name(); if (name != null) { out.print(name.toString()); } else { out.print("null"); } }
private Node appendNodes(Closure c) { List list = parent().children(); int afterIndex = list.indexOf(this); List leftOvers = new ArrayList(list.subList(afterIndex + 1, list.size())); list.subList(afterIndex + 1, list.size()).clear(); Node lastAppended = null; for (Node child : buildChildrenFromClosure(c)) { lastAppended = parent().appendNode(child.name(), child.attributes(), child.value()); } parent().children().addAll(leftOvers); return lastAppended; }
private void convertNode(Node node, HierarchicalStreamWriter writer) { writer.startNode(node.name().toString()); if (node.value() instanceof Collection) { for (Object subNode : (Collection) node.value()) { convertNode((Node) subNode, writer); } } else { writer.setValue(node.value().toString()); } writer.endNode(); }
private void convertNode(Node node, HierarchicalStreamWriter writer) { writer.startNode(node.name().toString()); writeNodeAttributes(node, writer); if (node.value() instanceof Collection) { for (Object subNode : (Collection) node.value()) { convertNode((Node) subNode, writer); } } else { writer.setValue(node.value().toString()); } writer.endNode(); }
private static String pretty(Node node) { return "Node: " + new Object() { String print(Node cur) { return cur.isTerminal() ? cur.name() : ("("+print(cur.left())+":"+print(cur.right())+")"); } }.print(node); }