/** * Detaches this child from its parent or does nothing if the child * has no parent. * * @return this child detached */ public Content detach() { if (parent != null) { parent.removeContent(this); } return this; }
/** * 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; }
/** * Iterator for the descendants of the supplied object. * * @param parent document or element whose descendants will be iterated */ DescendantIterator(Parent parent) { if (parent == null) { throw new IllegalArgumentException("parent parameter was null"); } this.iterator = parent.getContent().iterator(); }
/** * 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(); }
protected Content setParent(Parent parent) { // Save previous owning document (if any). Document prevDoc = this.getDocument(); Document newDoc = (parent != null)? parent.getDocument(): null; // Attach to new parent element. super.setParent(parent); if (newDoc != prevDoc) { // New and previous owning documents are different. // => Remove all the IDs for the subtree this element is the root // of from the previous owning document's lookup table and // insert them into the new owning document's lookup table. transferIds(prevDoc, newDoc); } return this; }
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); } } }
Map<String, JsonElement> parentMap = p.getParent(); Set<String> keyMap = parentMap.keySet();
@NotNull private static ProcessingInstruction getFormatInstruction( @NotNull Parent document ) { List<? extends ProcessingInstruction> processingInstructions = document.getContent( new PiFormatFilter() ); if ( processingInstructions.size() != 1 ) { throw new IllegalStateException( "No processing instructions found" ); } return processingInstructions.get( 0 ); }
protected Attribute setParent(Element parent) { Parent oldParent = this.getParent(); super.setParent(parent); if (this.getAttributeType() == Attribute.ID_TYPE) { Document doc; // Udpate the owning document's lookup table. if (oldParent != null) { doc = oldParent.getDocument(); if (doc instanceof IdDocument) { ((IdDocument)doc).removeId(this.getValue()); } } doc = this.getDocument(); if (doc instanceof IdDocument) { ((IdDocument)doc).addId(this.getValue(), this.getParent()); } } return this; }
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; }
private XMLNode createTreeNode(Content content) { XMLNode node = new XMLNode(content); if (content instanceof Parent) { Parent parent = (Parent) content; Iterator children = parent.getContent().iterator(); while (children.hasNext()) { Object child = children.next(); if (child instanceof Element) { node.add(createTreeNode((Content) child)); } else if (textSizeLimit != 0 && child instanceof Text) { Text text = (Text) child; if (!text.getTextNormalize().equals("")) { node.add(createTreeNode(text)); } } } } return node; } }
private void populateBeanElementFromXStream(Object obj, Element bean) throws JDOMException, IOException { bean.setAttribute(BEAN_ENCODING, XSTREAM_ENCODING); XStream xstream = new XStream(new DomDriver()); SAXBuilder builder = new SAXBuilder(); Element configElement = builder.build( new StringReader(xstream.toXML(obj))).getRootElement(); configElement.getParent().removeContent(configElement); bean.addContent(configElement); }
/** 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; }
@SuppressWarnings("unchecked") private XMLNode createTreeNode(Content content) { XMLNode node = new XMLNode(content); if (content instanceof Parent) { Parent parent = (Parent) content; Iterator children = parent.getContent().iterator(); while (children.hasNext()) { Object child = children.next(); if (child instanceof Element) { node.add(createTreeNode((Content) child)); } else if (textSizeLimit != 0 && child instanceof Text) { Text text = (Text) child; if (!text.getTextNormalize().equals("")) { node.add(createTreeNode(text)); } } } } return node; } }
private void populateBeanElementFromXStream(Object obj, Element bean) throws JDOMException, IOException { bean.setAttribute(BEAN_ENCODING, XSTREAM_ENCODING); XStream xstream = new XStream(new DomDriver()); SAXBuilder builder = new SAXBuilder(); Element configElement = builder.build( new StringReader(xstream.toXML(obj))).getRootElement(); configElement.getParent().removeContent(configElement); bean.addContent(configElement); }
/** * Get the <java> element from the {@link XMLEncoder} for the given * bean as a JDOM {@link Element}. * * @see net.sf.taverna.t2.util.beanable.jaxb.BeanSerialiser * @param obj * Object to serialise * @return <java> element for serialised bean * @throws JDOMException * @throws IOException * */ @Deprecated public static Element beanAsElement(Object obj) throws JDOMException, IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); XMLEncoder xenc = new XMLEncoder(bos); xenc.writeObject(obj); xenc.close(); byte[] bytes = bos.toByteArray(); ByteArrayInputStream bis = new ByteArrayInputStream(bytes); Element configElement = new SAXBuilder().build(bis).getRootElement(); configElement.getParent().removeContent(configElement); return configElement; }