private static final Element getParent(Object node) { if (node instanceof Element) return((Element) node).getParent(); else if (node instanceof Attribute) return((Attribute) node).getParent(); else if (node instanceof Text) return((Text) node).getParent(); else if (node instanceof ProcessingInstruction) return((ProcessingInstruction) node).getParent(); else if (node instanceof Comment) return((Comment) node).getParent(); else if (node instanceof EntityRef) return((EntityRef) node).getParent(); else // With 2.1 semantics it makes more sense to just return a null and let the core // throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR) return null; // throw new TemplateModelException("_parent can not be applied on " + node.getClass()); }
@Override Object getParent(Object node) { if (node instanceof Element) { return((Element) node).getParent(); } if (node instanceof Attribute) { return((Attribute) node).getParent(); } if (node instanceof Text) { return((Text) node).getParent(); } if (node instanceof ProcessingInstruction) { return((ProcessingInstruction) node).getParent(); } if (node instanceof Comment) { return((Comment) node).getParent(); } if (node instanceof EntityRef) { return((EntityRef) node).getParent(); } return null; }
public List operate(Object node) { Document doc = null; if (node instanceof Element) doc = ((Element) node).getDocument(); else if (node instanceof Attribute) { Element parent = ((Attribute) node).getParent(); doc = parent == null ? null : parent.getDocument(); } else if (node instanceof Text) { Element parent = ((Text) node).getParent(); doc = parent == null ? null : parent.getDocument(); } else if (node instanceof Document) doc = (Document) node; else if (node instanceof ProcessingInstruction) doc = ((ProcessingInstruction) node).getDocument(); else if (node instanceof EntityRef) doc = ((EntityRef) node).getDocument(); else if (node instanceof Comment) doc = ((Comment) node).getDocument(); else // With 2.1 semantics it makes more sense to just return a null and let the core // throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR) return null; // throw new TemplateModelException("_document can not be applied on " + node.getClass()); return doc == null ? Collections.EMPTY_LIST : Collections.singletonList(doc); } }
@Override Object getDocument(Object node) { if (node instanceof Element) { return ((Element) node).getDocument(); } else if (node instanceof Attribute) { Element parent = ((Attribute) node).getParent(); return parent == null ? null : parent.getDocument(); } else if (node instanceof Text) { Element parent = ((Text) node).getParent(); return parent == null ? null : parent.getDocument(); } else if (node instanceof Document) return node; else if (node instanceof ProcessingInstruction) { return ((ProcessingInstruction) node).getDocument(); } else if (node instanceof EntityRef) { return ((EntityRef) node).getDocument(); } else if (node instanceof Comment) { return ((Comment) node).getDocument(); } return null; }
element = ((Attribute)context).getParent();
parent = ((Attribute)contextNode).getParent();
public void remove() { attr.getParent().removeAttribute(attr); }
/** * This retrieves the owning <code>{@link Document}</code> for * this Attribute, or null if not a currently a member of a * <code>{@link Document}</code>. * * @return <code>Document</code> owning this Attribute, or null. */ public Document getDocument() { final Element parentElement = getParent(); if (parentElement != null) { return parentElement.getDocument(); } return null; }
/** * This detaches the <code>Attribute</code> from its parent, or does * nothing if the <code>Attribute</code> has no parent. * * @return <code>Attribute</code> - this <code>Attribute</code> modified. */ public Attribute detach() { final Element parentElement = getParent(); if (parentElement != null) { parentElement.removeAttribute(getName(),getNamespace()); } return this; }
/** * Set the object at the specified location to the supplied * object. Note: does not check for duplicate attributes. * * @param index The location to set the value to. * @param attribute The attribute to set. * @return The object which was replaced. * throws IndexOutOfBoundsException if index < 0 || index >= size() */ Object set(int index, Attribute attribute) { if (index < 0 || index >= size) throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size()); if (attribute.getParent() != null) { throw new IllegalAddException( "The attribute already has an existing parent \"" + attribute.getParent().getQualifiedName() + "\""); } String reason = Verifier.checkNamespaceCollision(attribute, parent); if (reason != null) { throw new IllegalAddException(parent, attribute, reason); } Attribute old = (Attribute) elementData[index]; old.setParent(null); elementData[index] = attribute; attribute.setParent(parent); return old; }
private static final Element getParent(Object node) { if (node instanceof Element) return((Element) node).getParent(); else if (node instanceof Attribute) return((Attribute) node).getParent(); else if (node instanceof Text) return((Text) node).getParent(); else if (node instanceof ProcessingInstruction) return((ProcessingInstruction) node).getParent(); else if (node instanceof Comment) return((Comment) node).getParent(); else if (node instanceof EntityRef) return((EntityRef) node).getParent(); else // With 2.1 semantics it makes more sense to just return a null and let the core // throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR) return null; // throw new TemplateModelException("_parent can not be applied on " + node.getClass()); }
private static final Element getParent(Object node) { if (node instanceof Element) return((Element) node).getParent(); else if (node instanceof Attribute) return((Attribute) node).getParent(); else if (node instanceof Text) return((Text) node).getParent(); else if (node instanceof ProcessingInstruction) return((ProcessingInstruction) node).getParent(); else if (node instanceof Comment) return((Comment) node).getParent(); else if (node instanceof EntityRef) return((EntityRef) node).getParent(); else // With 2.1 semantics it makes more sense to just return a null and let the core // throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR) return null; // throw new TemplateModelException("_parent can not be applied on " + node.getClass()); }
private static final Element getParent(Object node) { if (node instanceof Element) return((Element)node).getParent(); else if (node instanceof Attribute) return((Attribute)node).getParent(); else if (node instanceof Text) return((Text)node).getParent(); else if (node instanceof ProcessingInstruction) return((ProcessingInstruction)node).getParent(); else if (node instanceof Comment) return((Comment)node).getParent(); else if (node instanceof EntityRef) return((EntityRef)node).getParent(); else // With 2.1 semantics it makes more sense to just return a null and let the core // throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR) return null; // throw new TemplateModelException("_parent can not be applied on " + node.getClass()); }
Object getParent(Object node) { if (node instanceof Element) { return((Element)node).getParent(); } if (node instanceof Attribute) { return((Attribute)node).getParent(); } if (node instanceof Text) { return((Text)node).getParent(); } if (node instanceof ProcessingInstruction) { return((ProcessingInstruction)node).getParent(); } if (node instanceof Comment) { return((Comment)node).getParent(); } if (node instanceof EntityRef) { return((EntityRef)node).getParent(); } return null; }
@Override Object getParent(Object node) { if (node instanceof Element) { return((Element) node).getParent(); } if (node instanceof Attribute) { return((Attribute) node).getParent(); } if (node instanceof Text) { return((Text) node).getParent(); } if (node instanceof ProcessingInstruction) { return((ProcessingInstruction) node).getParent(); } if (node instanceof Comment) { return((Comment) node).getParent(); } if (node instanceof EntityRef) { return((EntityRef) node).getParent(); } return null; }
@Override Object getParent(Object node) { if (node instanceof Element) { return((Element) node).getParent(); } if (node instanceof Attribute) { return((Attribute) node).getParent(); } if (node instanceof Text) { return((Text) node).getParent(); } if (node instanceof ProcessingInstruction) { return((ProcessingInstruction) node).getParent(); } if (node instanceof Comment) { return((Comment) node).getParent(); } if (node instanceof EntityRef) { return((EntityRef) node).getParent(); } return null; }
public List operate(Object node) { Document doc = null; if (node instanceof Element) doc = ((Element) node).getDocument(); else if (node instanceof Attribute) { Element parent = ((Attribute) node).getParent(); doc = parent == null ? null : parent.getDocument(); } else if (node instanceof Text) { Element parent = ((Text) node).getParent(); doc = parent == null ? null : parent.getDocument(); } else if (node instanceof Document) doc = (Document) node; else if (node instanceof ProcessingInstruction) doc = ((ProcessingInstruction) node).getDocument(); else if (node instanceof EntityRef) doc = ((EntityRef) node).getDocument(); else if (node instanceof Comment) doc = ((Comment) node).getDocument(); else // With 2.1 semantics it makes more sense to just return a null and let the core // throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR) return null; // throw new TemplateModelException("_document can not be applied on " + node.getClass()); return doc == null ? Collections.EMPTY_LIST : Collections.singletonList(doc); } }
@Override Object getDocument(Object node) { if (node instanceof Element) { return ((Element) node).getDocument(); } else if (node instanceof Attribute) { Element parent = ((Attribute) node).getParent(); return parent == null ? null : parent.getDocument(); } else if (node instanceof Text) { Element parent = ((Text) node).getParent(); return parent == null ? null : parent.getDocument(); } else if (node instanceof Document) return node; else if (node instanceof ProcessingInstruction) { return ((ProcessingInstruction) node).getDocument(); } else if (node instanceof EntityRef) { return ((EntityRef) node).getDocument(); } else if (node instanceof Comment) { return ((Comment) node).getDocument(); } return null; }
@Override Object getDocument(Object node) { if (node instanceof Element) { return ((Element) node).getDocument(); } else if (node instanceof Attribute) { Element parent = ((Attribute) node).getParent(); return parent == null ? null : parent.getDocument(); } else if (node instanceof Text) { Element parent = ((Text) node).getParent(); return parent == null ? null : parent.getDocument(); } else if (node instanceof Document) return node; else if (node instanceof ProcessingInstruction) { return ((ProcessingInstruction) node).getDocument(); } else if (node instanceof EntityRef) { return ((EntityRef) node).getDocument(); } else if (node instanceof Comment) { return ((Comment) node).getDocument(); } return null; }
Object getDocument(Object node) { if (node instanceof Element) { return ((Element)node).getDocument(); } else if (node instanceof Attribute) { Element parent = ((Attribute)node).getParent(); return parent == null ? null : parent.getDocument(); } else if (node instanceof Text) { Element parent = ((Text)node).getParent(); return parent == null ? null : parent.getDocument(); } else if (node instanceof Document) return node; else if (node instanceof ProcessingInstruction) { return ((ProcessingInstruction)node).getDocument(); } else if (node instanceof EntityRef) { return ((EntityRef)node).getDocument(); } else if (node instanceof Comment) { return ((Comment)node).getDocument(); } return null; }