public List<Element> getChildren () { return getNodes (ELEMENT_FILTER); }
public List<Element> getChildren (final String name, final Namespace ns) { NodeFilter<Element> nameFilter = new NodeFilter<Element> () { @Override public boolean matches (Node n) { if (!isElement (n)) return false; Element e = (Element)n; boolean match = true; if (match && name != null && !e.getName ().equals (name)) match = false; if (match && ns != null && !ns.equals (getNamespace ())) match = false; return match; } }; return getNodes (nameFilter); }
public int childIndexOf (Element element) { int index = 0; for (Node n: getNodes ()) { if (n.equals (element)) return index; if (isElement (n)) index ++; } return -1; }
public Element clearChildren () { if (!hasNodes ()) return this; for (Iterator<Node> iter = getNodes ().iterator (); iter.hasNext (); ) { Node n = iter.next (); if (isElement (n)) iter.remove (); } return this; }
private void validate(Validator validator, Element e) throws IOException, SAXException { String uri = getNamespaceURI(e); if (uri != null && Arrays.asList(camelNamespaces).contains(uri)) { String text = nodeWithNamespacesToText(e, e); validator.validate(new StreamSource(new StringReader(text))); } else { for (Node node : e.getNodes()) { if (node instanceof Element) { validate(validator, (Element) node); } } } }
public boolean hasChildren () { if (!hasNodes ()) return false; for (Node node: getNodes ()) { if (isElement (node)) return true; } return false; }
private void validate(Validator validator, Element e) throws IOException, SAXException { String uri = getNamespaceURI(e); if (uri != null && Arrays.asList(camelNamespaces).contains(uri)) { String text = nodeWithNamespacesToText(e, e); validator.validate(new StreamSource(new StringReader(text))); } else { for (Node node: e.getNodes()) { if (node instanceof Element) { validate(validator, (Element) node); } } } }
public Element getChild (int index) { int count = 0; if (hasNodes ()) { for (Node n: getNodes ()) { if (isElement (n)) { if (index == count) return (Element)n; count ++; } } } throw new IndexOutOfBoundsException ("Cannot return child "+index +", node has only "+count+(count == 1 ? " child" : " children")); }
protected static Element findOrCreateDescriptionOnNextElement(Element element, int commentIndex, Parent root) { // lets find the next peer element node and if it can contain a description lets use that List<Node> nodes = element.getNodes(); Node[] array = nodes.toArray(new Node[nodes.size()]); for (int i = commentIndex + 1; i < array.length; i++) { if (array[i] instanceof Element) { if (elementsWithDescription().contains(element.getName())) { return findOrCreateDescrptionElement((Element) array[i], root); } } } return findOrCreateDescrptionElement(element, root); }
protected static Element findOrCreateDescriptionOnNextElement(Element element, int commentIndex, Parent root) { // lets find the next peer element node and if it can contain a description lets use that List<Node> nodes = element.getNodes(); Node[] array = nodes.toArray(new Node[nodes.size()]); for (int i=commentIndex + 1; i<array.length; i++) { if (array[i] instanceof Element) { if (elementsWithDescription().contains(element.getName())) { return findOrCreateDescrptionElement((Element) array[i], root); } } } return findOrCreateDescrptionElement(element, root); }
public Element clearText () { if (!hasNodes ()) return this; for (Iterator<Node> iter = getNodes ().iterator (); iter.hasNext ();) { Node n = iter.next (); if (isText (n)) { iter.remove (); } else if (isElement (n)) { ((Element)n).clearText (); } } return this; }
public String getText () { if (!hasNodes ()) return ""; StringBuilder buffer = new StringBuilder (); for (Node n: getNodes ()) { if (isText (n)) buffer.append (((Text)n).getText ()); else if (isElement (n)) buffer.append (((Element)n).getText ()); else if (n.getType () == Type.ENTITY) buffer.append (((Entity)n).getText ()); } return buffer.toString (); }
public void removeRootInstalledFeatures() { Element featuresDom = dom.getChild("features"); if (featuresDom != null) { for (int childIx = featuresDom.getNodes().size() - 1; childIx > 0; --childIx) { Node nodeDom = featuresDom.getNode(childIx); if (nodeDom instanceof Element) { Element elementDom = (Element) nodeDom; if (parseFeature(elementDom).getInstallMode() == FeatureRef.InstallMode.root) { featuresDom.removeNode(childIx); } } } } }
public void removeRootInstalledFeatures() { Element featuresDom = dom.getChild("features"); if (featuresDom != null) { for (int childIx = featuresDom.getNodes().size() - 1; childIx > 0; --childIx) { Node nodeDom = featuresDom.getNode(childIx); if (nodeDom instanceof Element) { Element elementDom = (Element) nodeDom; if (parseFeature(elementDom).getInstallMode() == FeatureRef.InstallMode.root) { featuresDom.removeNode(childIx); } } } } }
protected static Element findOrCreateDescrptionElement(Element element, Parent root) { for (Node node : element.getNodes()) { if (node instanceof Element) { if ("description".equals(((Element) node).getName())) { return (Element) node; } } } Element parent = element.getParentElement(); if (element == root || parent == null || parent == root) { return null; } else if (elementsWithDescription.contains(element.getName())) { // lets check for a namespace prefix String ebn = element.getBeginName(); int idx = ebn.indexOf(":"); String name = idx > 0 ? ebn.substring(0, idx + 1) + "description" : "description"; Element description = new Element(name, element.getNamespace()); element.addNode(0, description); return description; } else { return findOrCreateDescrptionElement(parent, root); } }
protected static Element findOrCreateDescrptionElement(Element element, Parent root) { for (Node node : element.getNodes()) { if (node instanceof Element) { if ("description".equals(((Element) node).getName())) { return (Element) node; } } } Element parent = element.getParentElement(); if (element == root || parent == null || parent == root) { return null; } else if (elementsWithDescription.contains(element.getName())) { // lets check for a namespace prefix String ebn = element.getBeginName(); int idx = ebn.indexOf(":"); String name = idx > 0 ? ebn.substring(0, idx + 1) + "description" : "description"; Element description = new Element(name, element.getNamespace()); element.addNode(0, description); return description; } else { return findOrCreateDescrptionElement(parent, root); } }
for (Node n: current.getNodes ())