/** * Determines if this element is the ancestor of another element. * * @param element <code>Element</code> to check against * @return <code>true</code> if this element is the ancestor of the * supplied element */ public boolean isAncestor(final Element element) { Parent p = element.getParent(); while (p instanceof Element) { if (p == this) { return true; } p = p.getParent(); } return false; }
/** * Detaches this child from its parent or does nothing if the child * has no parent. * <p> * This method can be overridden by particular Content subclasses to return * a specific type of Content (co-variant return type). All overriding * subclasses <b>must</b> call <code>super.detach()</code>; * * @return this child detached */ public Content detach() { if (parent != null) { parent.removeContent(this); } return this; }
@Override public final Iterator<?> getChildAxisIterator(Object contextNode) throws UnsupportedAxisException { if (contextNode instanceof Parent) { return ((Parent)contextNode).getContent().iterator(); } return JaxenConstants.EMPTY_ITERATOR; }
/** * Check and add the <code>Content</code> to this list at the given index. * Inserts the specified object at the specified position in this list. * Shifts the object currently at that position (if any) and any subsequent * objects to the right (adds one to their indices). * * @param index * index where to add <code>Element</code> * @param child * <code>Content</code> to add */ @Override public void add(final int index, final Content child) { // Confirm basic sanity of child. checkPreConditions(child, index, false); // Check to see whether this parent believes it can contain this content parent.canContainContent(child, index, false); child.setParent(parent); ensureCapacity(size + 1); if (index == size) { elementData[size++] = child; } else { System.arraycopy(elementData, index, elementData, index + 1, size - index); elementData[index] = child; size++; } // Successful add's increment the AbstractList's modCount incModCount(); }
/** * Return this child's owning document or null if the branch containing * this child is currently not attached to a document. * * @return this child's owning document or null if none */ public Document getDocument() { if (parent == null) return null; return parent.getDocument(); }
/** * Set the object at the specified location to the supplied object. * * @param index * The location to set the value to. * @param child * The location to set the value to. * @return The object which was replaced. throws IndexOutOfBoundsException * if index < 0 || index >= size() */ @Override public Content set(final int index, final Content child) { // Confirm basic sanity of child. checkPreConditions(child, index, true); // Ensure the detail checks out OK too. parent.canContainContent(child, index, true); /* * Do a special case of set() where we don't do a remove() then add() * because that affects the modCount. We want to do a true set(). See * issue #15 */ final Content old = elementData[index]; removeParent(old); child.setParent(parent); elementData[index] = child; // for set method we increment dataModCount, but not modCount // set does not change the structure of the List (size()) incDataModOnly(); return old; }
return ret; p = p.getParent();
parent.removeContent(element);
/** * Iterator for the descendants of the supplied object. * * @param parent document or element whose descendants will be iterated */ DescendantIterator(Parent parent) { this.parent = parent; // can trust that parent is not null, DescendantIterator is package-private. current = parent.getContent().iterator(); hasnext = current.hasNext(); }
while ((current= current.getParent()) instanceof Element);
protected void generateForeignMarkup(Element e, List foreignMarkup) { if (foreignMarkup != null) { Iterator elems = (Iterator) foreignMarkup.iterator(); while (elems.hasNext()) { Element elem = (Element) elems.next(); Parent parent = elem.getParent(); if (parent != null) { parent.removeContent(elem); } e.addContent(elem); } } }
/** * Use xml:base attributes at feed and entry level to resolve relative links */ private static String resolveURI(final URL baseURI, final Parent parent, String url) { url = url.equals(".") || url.equals("./") ? "" : url; if (isRelativeURI(url) && parent != null && parent instanceof Element) { final Attribute baseAtt = ((Element) parent).getAttribute("base", Namespace.XML_NAMESPACE); String xmlBase = baseAtt == null ? "" : baseAtt.getValue(); if (!isRelativeURI(xmlBase) && !xmlBase.endsWith("/")) { xmlBase = xmlBase.substring(0, xmlBase.lastIndexOf("/") + 1); } return resolveURI(baseURI, parent.getParent(), xmlBase + url); } else if (isRelativeURI(url) && parent == null) { return baseURI + url; } else if (baseURI != null && url.startsWith("/")) { String hostURI = baseURI.getProtocol() + "://" + baseURI.getHost(); if (baseURI.getPort() != baseURI.getDefaultPort()) { hostURI = hostURI + ":" + baseURI.getPort(); } return hostURI + url; } return url; }
protected void generateForeignMarkup(Element e, List foreignMarkup) { if (foreignMarkup != null) { Iterator elems = (Iterator) foreignMarkup.iterator(); while (elems.hasNext()) { Element elem = (Element) elems.next(); Parent parent = elem.getParent(); if (parent != null) { parent.removeContent(elem); } e.addContent(elem); } } }
/** Use xml:base attributes at feed and entry level to resolve relative links */ private static String resolveURI(URL baseURI, Parent parent, String url) { url = (url.equals(".") || url.equals("./")) ? "" : url; if (isRelativeURI(url) && parent != null && parent instanceof Element) { Attribute baseAtt = ((Element)parent).getAttribute("base", Namespace.XML_NAMESPACE); String xmlBase = (baseAtt == null) ? "" : baseAtt.getValue(); if (!isRelativeURI(xmlBase) && !xmlBase.endsWith("/")) { xmlBase = xmlBase.substring(0, xmlBase.lastIndexOf("/")+1); } return resolveURI(baseURI, parent.getParent(), xmlBase + url); } else if (isRelativeURI(url) && parent == null) { return baseURI + url; } else if (baseURI != null && url.startsWith("/")) { String hostURI = baseURI.getProtocol() + "://" + baseURI.getHost(); if (baseURI.getPort() != baseURI.getDefaultPort()) { hostURI = hostURI + ":" + baseURI.getPort(); } return hostURI + url; } return url; }
protected void generateForeignMarkup(final Element element, final List<Element> foreignElements) { if (foreignElements != null) { for (final Element foreignElement : foreignElements) { final Parent parent = foreignElement.getParent(); if (parent != null) { parent.removeContent(foreignElement); } element.addContent(foreignElement); } } }
/** Use xml:base attributes at feed and entry level to resolve relative links */ private static String resolveURI(URL baseURI, Parent parent, String url) { url = (url.equals(".") || url.equals("./")) ? "" : url; if (isRelativeURI(url) && parent != null && parent instanceof Element) { Attribute baseAtt = ((Element)parent).getAttribute("base", Namespace.XML_NAMESPACE); String xmlBase = (baseAtt == null) ? "" : baseAtt.getValue(); if (!isRelativeURI(xmlBase) && !xmlBase.endsWith("/")) { xmlBase = xmlBase.substring(0, xmlBase.lastIndexOf("/")+1); } return resolveURI(baseURI, parent.getParent(), xmlBase + url); } else if (isRelativeURI(url) && parent == null) { return baseURI + url; } else if (baseURI != null && url.startsWith("/")) { String hostURI = baseURI.getProtocol() + "://" + baseURI.getHost(); if (baseURI.getPort() != baseURI.getDefaultPort()) { hostURI = hostURI + ":" + baseURI.getPort(); } return hostURI + url; } return url; }
protected void generateForeignMarkup(final Element element, final List<Element> foreignElements) { if (foreignElements != null) { for (final Element foreignElement : foreignElements) { final Parent parent = foreignElement.getParent(); if (parent != null) { parent.removeContent(foreignElement); } element.addContent(foreignElement); } } }
/** * Use xml:base attributes at feed and entry level to resolve relative links */ private static String resolveURI(final URL baseURI, final Parent parent, String url) { url = url.equals(".") || url.equals("./") ? "" : url; if (isRelativeURI(url) && parent != null && parent instanceof Element) { final Attribute baseAtt = ((Element) parent).getAttribute("base", Namespace.XML_NAMESPACE); String xmlBase = baseAtt == null ? "" : baseAtt.getValue(); if (!isRelativeURI(xmlBase) && !xmlBase.endsWith("/")) { xmlBase = xmlBase.substring(0, xmlBase.lastIndexOf("/") + 1); } return resolveURI(baseURI, parent.getParent(), xmlBase + url); } else if (isRelativeURI(url) && parent == null) { return baseURI + url; } else if (baseURI != null && url.startsWith("/")) { String hostURI = baseURI.getProtocol() + "://" + baseURI.getHost(); if (baseURI.getPort() != baseURI.getDefaultPort()) { hostURI = hostURI + ":" + baseURI.getPort(); } return hostURI + url; } return url; }