Example usage for org.w3c.dom Element getOwnerDocument

List of usage examples for org.w3c.dom Element getOwnerDocument

Introduction

In this page you can find the example usage for org.w3c.dom Element getOwnerDocument.

Prototype

public Document getOwnerDocument();

Source Link

Document

The Document object associated with this node.

Usage

From source file:org.docx4j.openpackaging.parts.PresentationML.SlidePart.java

public Sld unmarshal(org.w3c.dom.Element el) throws JAXBException {

    // Note comments above about AlternateContent.  
    // unmarshalling here from an Element doesn't implement that fix, so beware.

    try {// w  w w. ja  v  a  2  s .  c  o  m

        binder = jc.createBinder();
        JaxbValidationEventHandler eventHandler = new JaxbValidationEventHandler();
        eventHandler.setContinue(false);
        binder.setEventHandler(eventHandler);

        try {
            jaxbElement = (Sld) binder.unmarshal(el);
        } catch (UnmarshalException ue) {
            log.info("encountered unexpected content; pre-processing");
            try {
                org.w3c.dom.Document doc;
                if (el instanceof org.w3c.dom.Document) {
                    doc = (org.w3c.dom.Document) el;
                } else {
                    // Hope for the best. Dodgy though; what if this is
                    // being used on something deep in the tree?
                    // TODO: revisit
                    doc = el.getOwnerDocument();
                }
                eventHandler.setContinue(true);
                DOMResult result = new DOMResult();
                Templates mcPreprocessorXslt = JaxbValidationEventHandler.getMcPreprocessor();
                XmlUtils.transform(doc, mcPreprocessorXslt, null, result);
                doc = (org.w3c.dom.Document) result.getNode();
                jaxbElement = (Sld) binder.unmarshal(doc);
            } catch (Exception e) {
                throw new JAXBException("Preprocessing exception", e);
            }
        }
        return jaxbElement;

    } catch (JAXBException e) {
        log.error(e.getMessage(), e);
        throw e;
    }
}

From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.wst.WTPCopyUtil.java

public static void fillAppInfo(Element appInfoElement, String libraryName, String libraryNamespace) {
    NodeList children = appInfoElement.getChildNodes();

    Element typeLibElement = null;
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child instanceof Element) {
            Element childElement = (Element) child;
            if (SOATypeLibraryConstants.TAG_TYPE_LIB.equals(childElement.getTagName())) {
                typeLibElement = childElement;
                break;
            }/*from www .j  a v a2  s . co  m*/
        }

    }
    //no element exists already
    if (typeLibElement == null) {
        typeLibElement = appInfoElement.getOwnerDocument().createElement(SOATypeLibraryConstants.TAG_TYPE_LIB);
        appInfoElement.appendChild(typeLibElement);
    }
    typeLibElement.setAttribute(SOATypeLibraryConstants.ATTR_LIB, libraryName);
    typeLibElement.setAttribute(SOATypeLibraryConstants.ATTR_NMSPC, libraryNamespace);

}

From source file:org.eclipse.ecr.common.xmap.DOMHelper.java

/**
 * Parses a string containing XML and returns a DocumentFragment containing
 * the nodes of the parsed XML.//  w w w  . j  ava2  s  .c o  m
 */
public static void loadFragment(Element el, String fragment) {
    // Wrap the fragment in an arbitrary element
    fragment = "<fragment>" + fragment + "</fragment>";
    try {
        // Create a DOM builder and parse the fragment
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(fragment)));

        Document doc = el.getOwnerDocument();

        // Import the nodes of the new document into doc so that they
        // will be compatible with doc
        Node node = doc.importNode(d.getDocumentElement(), true);

        // Create the document fragment node to hold the new nodes
        DocumentFragment docfrag = doc.createDocumentFragment();

        // Move the nodes into the fragment
        while (node.hasChildNodes()) {
            el.appendChild(node.removeChild(node.getFirstChild()));
        }

    } catch (Exception e) {
        log.error(e, e);
    }
}

From source file:org.eclipse.ecr.common.xmap.XMLBuilder.java

public static void toXML(Object o, Element parent, XAnnotatedObject xao) throws Exception {
    // XPath xpath = XPathFactory.newInstance().newXPath();
    Element currentNode = parent;
    String path = xao.getPath().toString();
    if (path.length() > 0) {
        currentNode = parent.getOwnerDocument().createElement(path);
        parent.appendChild(currentNode);
    }/*from www. j  a  v a 2  s. co  m*/
    // process annotated members
    for (XAnnotatedMember m : xao.members) {
        if (m instanceof XAnnotatedMap) {
            m.toXML(o, currentNode);
        } else if (m instanceof XAnnotatedList) {
            m.toXML(o, currentNode);
        } else if (m instanceof XAnnotatedContent) {
            m.toXML(o, currentNode);
        } else if (m instanceof XAnnotatedParent) {

        } else {
            m.toXML(o, currentNode);
        }
    }
}

From source file:org.eclipse.ecr.common.xmap.XMLBuilder.java

public static Element addElement(Element parent, String segment) {
    Element e = parent.getOwnerDocument().createElement(segment);
    parent.appendChild(e);/* ww w. j a v  a 2 s .c om*/
    return e;
}

From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java

public BeanDefinitionHolder parseAsHolder(Element componentElement, ParserContext parserContext) {
    // save parser context
    this.parserContext = parserContext;
    this.defaults = new BlueprintDefaultsDefinition(componentElement.getOwnerDocument(), parserContext);

    // let Spring do its standard parsing
    BeanDefinitionHolder bdHolder = parseComponentDefinitionElement(componentElement, null);

    BeanDefinition bd = bdHolder.getBeanDefinition();
    if (bd != null) {
        bd.setAttribute(ParsingUtils.BLUEPRINT_MARKER_NAME, Boolean.TRUE);
    }/*from w ww .  j  a va2  s  .c om*/

    return bdHolder;
}

From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java

private BlueprintDefaultsDefinition getDefaults(Element ele) {
    if (defaults == null) {
        defaults = new BlueprintDefaultsDefinition(ele.getOwnerDocument(), parserContext);
    }//from   w  w w  .  ja  v  a 2 s  .co m
    return defaults;
}

From source file:org.eclipse.smila.datamodel.record.dom.RecordBuilder.java

/**
 * Append a rec:Record element describing the given record to the given parent element. The record element is appended
 * as a new last child to the parent element. The element contains a namespace declaration for "xmlns:rec".
 *
 * @param parent//from www .  j  av a 2  s  .  c  o  m
 *          the parent element to append to.
 * @param record
 *          the record to transform.
 *
 * @return the appended element
 */
public Element appendRecord(final Element parent, final Record record) {
    final Document factory = parent.getOwnerDocument();
    newline(factory, parent);
    final Element recordElement = buildRecord(factory, record);
    recordElement.setAttribute(ATTRIBUTE_XMLNSREC, NAMESPACE_RECORD);
    parent.appendChild(recordElement);
    newline(factory, parent);
    return recordElement;

}

From source file:org.eclipse.smila.datamodel.record.dom.RecordBuilder.java

/**
 * Append a rec:RecordList element describing the given record list to the given parent element. The record list
 * element is appended as a new last child to the parent element. The element contains a namespace declaration for
 * "xmlns:rec"./*from  w  w  w.j av  a2s . com*/
 *
 * @param parent
 *          the parent element to append to.
 * @param records
 *          the record list to transform.
 *
 * @return the appended element
 */
public Element appendRecordList(final Element parent, final Iterable<Record> records) {
    final Document factory = parent.getOwnerDocument();
    newline(factory, parent);
    final Element recordListElement = appendElement(factory, parent, TAG_RECORDLIST);
    for (final Record record : records) {
        final Element recordElement = buildRecord(factory, record);
        recordListElement.appendChild(recordElement);
        newline(factory, parent);
    }
    return recordListElement;
}

From source file:org.eclipse.smila.datamodel.record.dom.RecordBuilder.java

/**
 * Append a rec:RecordList element describing the given record list to the given parent element. The record list
 * element is appended as a new last child to the parent element. The element contains a namespace declaration for
 * "xmlns:rec".//from   w  w w  .  j  a va 2s . co m
 *
 * @param parent
 *          the parent element to append to.
 * @param records
 *          the record list to transform.
 *
 * @return the appended element
 */
public Element appendRecordList(final Element parent, final Record[] records) {
    final Document factory = parent.getOwnerDocument();
    newline(factory, parent);
    final Element recordListElement = appendElement(factory, parent, TAG_RECORDLIST);
    for (final Record record : records) {
        final Element recordElement = buildRecord(factory, record);
        recordListElement.appendChild(recordElement);
        newline(factory, parent);
    }
    return recordListElement;
}