@Override public Element getParent() { // because DocType can only be attached to a Document. return (Element)super.getParent(); }
@Override public Element getParent() { // because DocType can only be attached to a Document. return (Element)super.getParent(); }
@Override public Document getParent() { // because DocType can only be attached to a Document. return (Document)super.getParent(); }
/** * A convenience method that returns any parent element for this element, * or null if the element is unattached or is a root element. This was the * original behavior of getParent() in JDOM Beta 9 which began returning * Parent in Beta 10. This method provides a convenient upgrade path for * JDOM Beta 10 and 1.0 users. * * @return the containing Element or null if unattached or a root element */ final public Element getParentElement() { Parent pnt = getParent(); return (Element) ((pnt instanceof Element) ? pnt : null); }
@Override public final Object getParentNode(Object contextNode) throws UnsupportedAxisException { if (contextNode instanceof Document) { return null; } if (contextNode instanceof NamespaceContainer) { return ((NamespaceContainer)contextNode).getParentElement(); } if (contextNode instanceof Content) { return ((Content)contextNode).getParent(); } if (contextNode instanceof Attribute) { return ((Attribute)contextNode).getParent(); } return null; }
@Override public final Iterator<?> getParentAxisIterator(Object contextNode) throws UnsupportedAxisException { Parent p = null; if (contextNode instanceof Content) { p = ((Content)contextNode).getParent(); } else if (contextNode instanceof NamespaceContainer) { p = ((NamespaceContainer)contextNode).getParentElement(); } else if (contextNode instanceof Attribute) { p = ((Attribute)contextNode).getParent(); } if (p != null) { return new SingleObjectIterator(p); } return JaxenConstants.EMPTY_ITERATOR; }
private final void checkPreConditions(final Content child, final int index, final boolean replace) { if (child == null) { throw new NullPointerException("Cannot add null object"); } checkIndex(index, replace); if (child.getParent() != null) { // the content to be added already has a parent. final Parent p = child.getParent(); if (p instanceof Document) { throw new IllegalAddException((Element) child, "The Content already has an existing parent document"); } throw new IllegalAddException( "The Content already has an existing parent \"" + ((Element) p).getQualifiedName() + "\""); } if (child == parent) { throw new IllegalAddException( "The Element cannot be added to itself"); } // Detect if we have <a><b><c/></b></a> and c.add(a) if ((parent instanceof Element && child instanceof Element) && ((Element) child).isAncestor((Element) parent)) { throw new IllegalAddException( "The Element cannot be added as a descendent of itself"); } }
private static List<String> extractReferencedClasses(@NotNull Element rootElement) { List<String> referencedClasses = new ArrayList<String>(); Iterator<Content> descendants = rootElement.getDescendants(); while (descendants.hasNext()) { Content next = descendants.next(); if (next instanceof Element) { Element element = (Element) next; if (isInterestingName(element.getName())) { referencedClasses.addAll(extractClasses(element.getTextNormalize())); } for (Attribute attribute : element.getAttributes()) { if (isInterestingName(attribute.getName())) { referencedClasses.addAll(extractClasses(attribute.getValue().trim())); } } } else if (next instanceof Text) { Parent parent = next.getParent(); if (parent instanceof Element) { if (isInterestingName(((Element) parent).getName())) { referencedClasses.addAll(extractClasses(((Text) next).getTextTrim())); } } } } return referencedClasses; }
/** * JDOM will throw an exception if we try and add the content to multiple parents. * As a result, we take the opportunity to add it safely, and add a note indicating * this content appears twice. * * @param cell the element to be added * @param xmlContent the collector of content */ private void addContentSafely(final Element cell, final List<Content> xmlContent) { Element note = null; for (Content c : xmlContent) { if (c.getParent() == null) { cell.addContent(c); } else if (note != null) { note.addContent(c.clone()); } else { //we're in the situation where we have added this already. //add note. In this case, we wrap the content that has already been applied. note = appendVersificationNotice(cell, "duplicate"); note.addContent(c.clone()); } } }