| Method from groovy.xml.dom.DOMCategory Detail: |
public static Element appendNode(Element self,
Object name) {
return appendNode(self, name, (String)null);
}
|
public static Element appendNode(Element self,
Object name,
Map attributes) {
return appendNode(self, name, attributes, null);
}
|
public static Element appendNode(Element self,
Object name,
String value) {
Document doc = self.getOwnerDocument();
Element newChild;
if (name instanceof QName) {
QName qn = (QName) name;
newChild = doc.createElementNS(qn.getNamespaceURI(), qn.getQualifiedName());
} else {
newChild = doc.createElement(name.toString());
}
if (value != null) {
Text text = doc.createTextNode(value);
newChild.appendChild(text);
}
self.appendChild(newChild);
return newChild;
}
|
public static Element appendNode(Element self,
Object name,
Map attributes,
String value) {
Element result = appendNode(self, name, value);
for (Iterator iterator = attributes.entrySet().iterator(); iterator.hasNext();) {
Map.Entry e = (Map.Entry) iterator.next();
putAt(result, "@" + e.getKey().toString(), e.getValue());
}
return result;
}
|
public static NamedNodeMap attributes(Element element) {
return element.getAttributes();
}
|
public static NodeList breadthFirst(Element self) {
List result = new ArrayList();
NodeList thisLevel = createNodeList(self);
while (thisLevel.getLength() > 0) {
result.add(thisLevel);
thisLevel = getNextLevel(thisLevel);
}
return new NodeListsHolder(result);
}
|
public static NodeList children(Element self) {
return getChildElements(self, "*");
}
|
public static NodeList depthFirst(Element self) {
List result = new ArrayList();
result.add(createNodeList(self));
result.add(self.getElementsByTagName("*"));
return new NodeListsHolder(result);
}
|
public static Object get(Element element,
String elementName) {
return xgetAt(element, elementName);
}
|
public static Object get(NodeList nodeList,
String elementName) {
if (nodeList instanceof Element) {
// things like com.sun.org.apache.xerces.internal.dom.DeferredElementNSImpl
// do implement Element, NodeList and Node. But here we prefer element,
// so we force the usage of Element. Without this DOMCategoryTest may fail
// in strange ways
return xgetAt((Element)nodeList, elementName);
} else {
return xgetAt(nodeList, elementName);
}
}
|
public static Object get(NamedNodeMap nodeMap,
String elementName) {
return xgetAt(nodeMap, elementName);
}
|
public static Node getAt(Node o,
int i) {
return nodeGetAt(o, i);
}
|
public static Node getAt(DOMCategory.NodeListsHolder o,
int i) {
return nodeGetAt(o, i);
}
|
public static Node getAt(DOMCategory.NodesHolder o,
int i) {
return nodeGetAt(o, i);
}
|
public static boolean isEmpty(NodeList self) {
return size(self) == 0;
}
|
public static List list(NodeList self) {
List answer = new ArrayList();
Iterator it = DefaultGroovyMethods.iterator(self);
while (it.hasNext()) {
answer.add(it.next());
}
return answer;
}
|
public static String name(Element element) {
return element.getNodeName();
}
|
public static Node parent(Node node) {
return node.getParentNode();
}
|
public static void putAt(Element self,
String property,
Object value) {
if (property.startsWith("@")) {
String attributeName = property.substring(1);
Document doc = self.getOwnerDocument();
Attr newAttr = doc.createAttribute(attributeName);
newAttr.setValue(value.toString());
self.setAttributeNode(newAttr);
return;
}
InvokerHelper.setProperty(self, property, value);
}
|
public static void setValue(Element self,
String value) {
self.getFirstChild().setNodeValue(value);
}
|
public static int size(NamedNodeMap namedNodeMap) {
return namedNodeMap.getLength();
}
|
public static int size(NodeList self) {
return self.getLength();
}
|
public static String text(Node node) {
if (node.getNodeType() == Node.TEXT_NODE) {
return node.getNodeValue();
}
if (node.hasChildNodes()) {
return text(node.getChildNodes());
}
return "";
}
|
public static String text(NodeList nodeList) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < nodeList.getLength(); i++) {
sb.append(text(nodeList.item(i)));
}
return sb.toString();
}
|
public static String toString(Object o) {
if (o instanceof Node) {
if (((Node) o).getNodeType() == Node.TEXT_NODE) {
return ((Node) o).getNodeValue();
}
}
if (o instanceof NodeList) {
return toString((NodeList) o);
}
return o.toString();
}
|
public static String xpath(Node self,
String expression) {
final XPath xpath = XPathFactory.newInstance().newXPath();
try {
return xpath.evaluate(expression, self);
} catch (XPathExpressionException e) {
throw new GroovyRuntimeException(e);
}
}
|
public static Object xpath(Node self,
String expression,
QName returnType) {
final XPath xpath = XPathFactory.newInstance().newXPath();
try {
return xpath.evaluate(expression, self, returnType);
} catch (XPathExpressionException e) {
throw new GroovyRuntimeException(e);
}
}
|