@Override public void setAttribute(final Object object, final String attribute, final Object newValue) { Node n = (Node) object; n.attributes().put(attribute, newValue); }
@Override public void setAttribute(final Object object, final String attribute, final Object newValue) { for (Object o : (NodeList) object) { Node node = (Node) o; node.attributes().put(attribute, newValue); } }
@Override public Object getAttribute(final Object object, final String attribute) { NodeList nl = (NodeList) object; Iterator it = nl.iterator(); List result = new ArrayList(); while (it.hasNext()) { Node node = (Node) it.next(); result.add(node.attributes().get(attribute)); } return result; }
/** * Provides lookup of elements by non-namespaced name * * @param key the name (or shortcut key) of the node(s) of interest * @return the nodes which match key */ public Object get(String key) { if (key != null && key.charAt(0) == '@') { String attributeName = key.substring(1); return attributes().get(attributeName); } if ("..".equals(key)) { return parent(); } if ("*".equals(key)) { return children(); } if ("**".equals(key)) { return depthFirst(); } return getByName(key); }
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(); }
public void print(Node node) { out.printIndent(); printName(node); Map attributes = node.attributes(); boolean hasAttributes = attributes != null && !attributes.isEmpty(); if (hasAttributes) { printAttributes(attributes); } Object value = node.value(); if (value instanceof List) { if (!hasAttributes) { out.print("()"); } printList((List) value); } else { if (value instanceof String) { out.print("('"); out.print((String) value); out.println("')"); } else { out.println("()"); } } out.flush(); }
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 + "."); } } } }
printNamespace(node, ctx); printNameAttributes(node.attributes(), ctx); if (expandEmptyElements) { out.print("></");
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; } }
@Override public void setAttribute(final Object object, final String attribute, final Object newValue) { Node n = (Node) object; n.attributes().put(attribute, newValue); }
/** * @param node node to check id * @return assigned node id or null */ private static String nid(Node node) { return (String) node.attributes().get(NID_ATTR); }
@Override public void setAttribute(final Object object, final String attribute, final Object newValue) { Node n = (Node) object; n.attributes().put(attribute, newValue); }
public void setProperty(Object object, String property, Object newValue) { if (property.startsWith("@")) { String attribute = property.substring(1); Node n = (Node) object; n.attributes().put(attribute, newValue); return; } delegate.setProperty(object, property, newValue); }
public void setProperty(Object object, String property, Object newValue) { if (property.startsWith("@")) { String attribute = property.substring(1); Node n = (Node) object; n.attributes().put(attribute, newValue); return; } delegate.setProperty(object, property, newValue); }
@Override public Object getAttribute(final Object object, final String attribute) { NodeList nl = (NodeList) object; Iterator it = nl.iterator(); List result = new ArrayList(); while (it.hasNext()) { Node node = (Node) it.next(); result.add(node.attributes().get(attribute)); } return result; }
public void setAttribute(final Object object, final String attribute, final Object newValue) { NodeList nl = (NodeList) object; Iterator it = nl.iterator(); while (it.hasNext()) { Node node = (Node) it.next(); node.attributes().put(attribute, newValue); } }
/** * Associates node in original tree with target tree node to avoid overriding already inserted content. * * @param root current source node * @param child current child (which parent's id will be associated with root node) */ private static void associate(Node root, Node child) { root.attributes().put(NID_ATTR, nid(child.parent())); }
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; }