@Override public boolean matches(Node n) { if (n instanceof Element) { Namespace ns = ((Element) n).getNamespace(); // TODO this doesn't work with empty prefixes! if (!((Element) n).getName().equals(localName)) { return false; } else { String uri = getNamespaceURI(n); return ns != null;// && namespaceUri.equals(uri); // (!) } } return false; } };
private static FeatureRef parseFeature(Element featureDom) throws ModelFileSyntaxException { // knowing the name of the parent element is useful for the error message, so we check the name here if (!"feature".equals(featureDom.getName())) { throw new ModelFileSyntaxException("Invalid child element \"" + featureDom.getName() + "\" in \"features\""); } return new FeatureRef(featureDom); }
@Override public boolean matches(Node n) { if (n instanceof Element) { Namespace ns = ((Element) n).getNamespace(); // TODO this doesn't work with empty prefixes! if (!((Element) n).getName().equals(localName)) { return false; } else { String uri = getNamespaceURI(n); return ns != null;// && namespaceUri.equals(uri); // (!) } } return false; } };
private static FeatureRef parseFeature(Element featureDom) throws ModelFileSyntaxException { // knowing the name of the parent element is useful for the error message, so we check the name here if (!"feature".equals(featureDom.getName())) { throw new ModelFileSyntaxException("Invalid child element \"" + featureDom.getName() + "\" in \"features\""); } return new FeatureRef(featureDom); }
@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; } };
public String getChildPath () { if (getParent () == null) return getName (); Element p = getParentElement (); if (p == null) return "/" + getName (); int index = p.childIndexOf (this); if (index == 0) return p.getChildPath () + "/" + getName (); return p.getChildPath () + "/" + getName () + "[" + index + "]"; }
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); } }
public static List<Element> findElementsWithName(Element rootElement, String elementName) { List<Element> answer = new ArrayList<>(); List<Element> children = rootElement.getChildren(); for (Element child : children) { if (Objects.equal(elementName, child.getName())) { answer.add(child); } else { answer.addAll(findElementsWithName(child, elementName)); } } return answer; }
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); } }
public static List<Element> findElementsWithName(Element rootElement, String elementName) { List<Element> answer = new ArrayList<>(); List<Element> children = rootElement.getChildren(); for (Element child : children) { if (Objects.equal(elementName, child.getName())) { answer.add(child); } else { answer.addAll(findElementsWithName(child, elementName)); } } return answer; }
if (path.equals (getRootElement ().getName ()) && (ns == null || ns.equals (getRootElement ().getNamespace ())) throw new XMLParseException ("Namespace prefix '"+prefix+"' is not defined"); if (!name.equals (getRootElement ().getName ()) || (ns2 != null && !ns2.equals (getRootElement ().getNamespace ()))
public Element checkMandatoryAttribute (String name) { Attribute a = getAttribute (name); if (a == null) throw new XMLParseException ("Element "+getName ()+" has no attribute "+name); return this; }
String name = endName.trim (); String elementName = parent.getName (); if (parent.getNamespace ().getPrefix ().length () != 0) elementName = parent.getNamespace ().getPrefix () + ":" + elementName; throw new XMLParseException ("End element '"+name+"' at line "+l.getLine ()+", column "+l.getColumn ()+" doesn't match with '"+parent.getName ()+"'", parent.getStartToken ()); if (endName.length () != parent.getName ().length ()) parent.setEndName (endName);
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); }
private void processElem(Element from, Parent to) { String merge = from.getAttributeValue("merge"); if ("replace".equals(merge)) { // find first element by the same name and merge into that one Element other = to.getChild(from.getName()); if (other != null) { replace(other, cleanup(from.copy())); return; } } else if (Boolean.parseBoolean(merge)) { // find first element by the same name and merge into that one Element other = to.getChild(from.getName()); if (other != null) { merge(from, other); return; } } to.addNode(cleanup(from.copy())); }
private boolean mergeDoc(Document from, Document to) { Element rootFrom = from.getRootElement(); String appendPath = rootFrom.getAttributeValue("appendPath"); if (appendPath != null) { return appendPath(rootFrom, to, appendPath); } String replacePath = rootFrom.getAttributeValue("replacePath"); if (replacePath != null) { return replacePath(rootFrom, to, replacePath); } Element rootTo; String mergePath = rootFrom.getAttributeValue("mergePath"); if (mergePath != null) { Element child = to.getChild(mergePath); if (child == null) { throw new IllegalStateException("Cannot merge " + name + " to path " + mergePath); } rootTo = child; } else if (rootFrom.getName().equals(to.getRootElement().getName())) { rootTo = to.getRootElement(); } else { return false; } merge(rootFrom, rootTo); return true; }
public void apply (Document doc) { for (TreeIterator iter = doc.iterator (); iter.hasNext (); ) { Node node = iter.next (); if (XMLUtils.isText (node)) { textHandler.handle (node); } else if (XMLUtils.isElement (node)) { String name = ((Element)node).getName (); INodeHandler handler = handlers.get (name); if (handler != null) handler.handle (node); } // TODO what about other nodes? } }
if (model.isRoutesContext() && camelDoc.getRootElement().getName().equals("camelContext")) { camelDoc.getRootElement().setName("routeContext");
return; throw new XMLParseException ("Expanded entity "+entity+" is not well-formed since it contains the end-token for '"+parent.getName ()+"'", entityToken);