Example usage for org.w3c.dom Node getOwnerDocument

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

Introduction

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

Prototype

public Document getOwnerDocument();

Source Link

Document

The Document object associated with this node.

Usage

From source file:com.twinsoft.convertigo.engine.util.XMLUtils.java

public static String prettyPrintDOM(Node node) {
    return XMLUtils.prettyPrintDOM(node.getOwnerDocument());
}

From source file:net.sourceforge.eclipsetrader.core.CurrencyConverter.java

private void saveHistory(Node root, String symbol) {
    Document document = root.getOwnerDocument();
    List list = (List) historyMap.get(symbol);
    if (list != null) {
        java.util.Collections.sort(list, new Comparator() {
            public int compare(Object o1, Object o2) {
                History d1 = (History) o1;
                History d2 = (History) o2;
                if (d1.date.after(d2.date) == true)
                    return 1;
                else if (d1.date.before(d2.date) == true)
                    return -1;
                return 0;
            }/*from w  w  w  .  j  a  v  a2 s.c om*/
        });

        for (Iterator iter = list.iterator(); iter.hasNext();) {
            History history = (History) iter.next();
            Element node = document.createElement("history"); //$NON-NLS-1$
            node.setAttribute("date", dateFormat.format(history.date)); //$NON-NLS-1$
            node.setAttribute("ratio", String.valueOf(history.ratio)); //$NON-NLS-1$
            root.appendChild(node);
        }
    }
}

From source file:de.rub.nds.burp.utilities.attacks.signatureFaking.SignatureFakingOracle.java

private void appendCertificate(Node keyInfo, String certificate) {
    String prefix = keyInfo.getPrefix();
    if (replaceAll == true) {
        keyInfo.setTextContent("");
        if (prefix == null) {
            prefix = "";
        } else {//from  w w w . j  ava 2s .c  o m
            prefix = prefix + ":";
        }
        Node data = keyInfo.getOwnerDocument().createElementNS(NamespaceConstants.URI_NS_DS,
                prefix + "X509Data");
        keyInfo.appendChild(data);
        Node cert = keyInfo.getOwnerDocument().createElementNS(NamespaceConstants.URI_NS_DS,
                prefix + "X509Certificate");
        data.appendChild(cert);
        cert.setTextContent(certificate);
    } else {
        List<Element> l = DomUtilities.findChildren(keyInfo, "X509Certificate", NamespaceConstants.URI_NS_DS,
                true);
        Node cert = l.get(0);
        cert.setTextContent(certificate);
    }
    Logging.getInstance().log(getClass(),
            "Appending Certificate \r\n" + certificate + "\r\nto the" + prefix + "X509Certificate element",
            Logging.DEBUG);
}

From source file:com.mediaworx.xmlutils.XmlHelper.java

/**
 * Appends a new child node to a parent node.
 * @param parent    the parent node//from   w ww  .  ja v a  2 s. co  m
 * @param newChild  the child node to be appended
 */
public void appendNode(Node parent, Node newChild) {
    Node toBeImported = newChild instanceof Document ? ((Document) newChild).getDocumentElement() : newChild;
    Node importedNode = parent.getOwnerDocument().importNode(toBeImported, true);
    parent.appendChild(importedNode);
}

From source file:net.sf.joost.emitter.DOMEmitter.java

/**
 * DefaultConstructor/*ww w.  ja  v a2 s.co m*/
 *
 * @throws ParserConfigurationException
 *                 if an error occurs while creating
 *                 {@link javax.xml.parsers.DocumentBuilder}
 *                 DOM-DocumentBuilder
 */
public DOMEmitter(DOMResult result) throws ParserConfigurationException {
    if (DEBUG)
        log.debug("init DOMEmitter");

    Node rootNode = result.getNode();
    nextSiblingOfRootNodes = result.getNextSibling();
    if (rootNode != null) {
        // use the document of the provided node
        if (rootNode instanceof Document)
            document = (Document) rootNode;
        else
            document = rootNode.getOwnerDocument();

        stack.push(rootNode);
    } else {
        // create a new document
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = factory.newDocumentBuilder();
        document = docBuilder.newDocument();

        stack.push(document);
    }
}

From source file:com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI.java

protected void checkContextNode(Node contextNode) {
    if (shouldReset(contextNode)) {
        // reset the cache
        xpathApi = new CachedXPathAPI();
        resetCache();//ww w .  j  av a 2 s .c o m
        Document doc = contextNode instanceof Document ? (Document) contextNode
                : contextNode.getOwnerDocument();
        if (doc instanceof DocumentImpl) {
            lastDocument = (DocumentImpl) doc;
            lastDocument.addEventListener(MutationEventImpl.DOM_SUBTREE_MODIFIED, this, false);
            lastDocument.addEventListener(MutationEventImpl.DOM_NODE_INSERTED, this, false);
            lastDocument.addEventListener(MutationEventImpl.DOM_NODE_REMOVED, this, false);
            lastDocument.addEventListener(MutationEventImpl.DOM_ATTR_MODIFIED, this, false);
            lastDocument.addEventListener(MutationEventImpl.DOM_CHARACTER_DATA_MODIFIED, this, false);
        }
    }
}

From source file:cz.muni.fi.mir.mathmlunificator.MathMLUnificator.java

/**
 * Replace the given node with unification element containing unification
 * representing symbol {@code &#x25CD;} (for Presentation MathML, see
 * {@link Constants#PMATHML_UNIFICATOR}) or {@code &#x25D0;} (for Content
 * MathML, see {@link Constants#CMATHML_UNIFICATOR}).
 *
 * @param oldNode The node to be replaced with the unification representing
 * element.//  w w w  .  j a  v  a  2  s . c  om
 * @throws IllegalArgumentException If the given node does not have parent.
 */
public static void replaceNodeWithUnificator(Node oldNode) {

    Node parentNode = oldNode.getParentNode();

    if (parentNode == null) {
        throw new IllegalArgumentException("Cannot replace node [" + oldNode + "] that has no parent.");
    } else {
        if (!Constants.CMATHML_ANNOTATIONS.contains(oldNode.getNodeName())) { // Do not modify annotation elements!
            String unificator = PMATHML_UNIFICATOR;
            String unificatorElementType = oldNode.getNodeName().equals(PMATHML_OPERATOR) ? PMATHML_OPERATOR
                    : PMATHML_IDENTIFIER;
            if (MathMLTools.isContentMathMLNode(oldNode)) {
                unificator = CMATHML_UNIFICATOR;
                unificatorElementType = Constants.CMATHML_IDENTIFIER_OR_NUMBER.contains(oldNode.getNodeName())
                        ? CMATHML_IDENTIFIER
                        : CMATHML_SYMBOL;
            }
            Node newNode = oldNode.getOwnerDocument().createElementNS(oldNode.getNamespaceURI(),
                    unificatorElementType);
            newNode.setTextContent(unificator);
            parentNode.replaceChild(newNode, oldNode);
        }
    }

}

From source file:tut.pori.javadocer.Javadocer.java

/**
 * converts the given node into an xml document and prints out that xml document
 * /*from   w w w  . ja  va2  s . co m*/
 * @param node
 * @return the given node as xml string
 */
private String toString(Node node) {
    StringWriter sw = new StringWriter();
    try {
        if (node.getNodeType() == Node.DOCUMENT_NODE) {
            cleanWhiteSpace((org.w3c.dom.Document) node);
        } else {
            cleanWhiteSpace(node.getOwnerDocument());
        }
        _transformer.transform(new DOMSource(node), new StreamResult(sw));
        return sw.toString();
    } catch (TransformerException ex) {
        LOGGER.error(ex, ex);
        throw new IllegalArgumentException("Invalid transformer settings.");
    }
}

From source file:be.fedict.eid.applet.service.signer.ooxml.RelationshipTransformService.java

@Override
public void init(XMLStructure parent, XMLCryptoContext context) throws InvalidAlgorithmParameterException {
    LOG.debug("init(parent,context)");
    LOG.debug("parent java type: " + parent.getClass().getName());
    DOMStructure domParent = (DOMStructure) parent;
    Node parentNode = domParent.getNode();
    try {//from  w  ww. j a v a2 s . c  o m
        LOG.debug("parent: " + toString(parentNode));
    } catch (TransformerException e) {
        throw new InvalidAlgorithmParameterException();
    }

    Element nsElement = parentNode.getOwnerDocument().createElement("ns");
    nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:ds", Constants.SignatureSpecNS);
    nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:mdssi",
            "http://schemas.openxmlformats.org/package/2006/digital-signature");

    /*
     * RelationshipReference
     */
    NodeList nodeList;
    try {
        nodeList = XPathAPI.selectNodeList(parentNode, "mdssi:RelationshipReference/@SourceId", nsElement);
    } catch (TransformerException e) {
        LOG.error("transformer exception: " + e.getMessage(), e);
        throw new InvalidAlgorithmParameterException();
    }
    for (int nodeIdx = 0; nodeIdx < nodeList.getLength(); nodeIdx++) {
        Node node = nodeList.item(nodeIdx);
        String sourceId = node.getTextContent();
        LOG.debug("sourceId: " + sourceId);
        this.sourceIds.add(sourceId);
    }

    /*
     * RelationshipsGroupReference
     */
    try {
        nodeList = XPathAPI.selectNodeList(parentNode, "mdssi:RelationshipsGroupReference/@SourceType",
                nsElement);
    } catch (TransformerException e) {
        LOG.error("transformer exception: " + e.getMessage(), e);
        throw new InvalidAlgorithmParameterException();
    }
    for (int nodeIdx = 0; nodeIdx < nodeList.getLength(); nodeIdx++) {
        Node node = nodeList.item(nodeIdx);
        String sourceType = node.getTextContent();
        LOG.debug("sourceType: " + sourceType);
        this.sourceTypes.add(sourceType);
    }
}

From source file:be.fedict.eid.applet.service.signer.ooxml.RelationshipTransformService.java

@Override
public void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException {
    LOG.debug("marshallParams(parent,context)");
    DOMStructure domParent = (DOMStructure) parent;
    Node parentNode = domParent.getNode();
    Element parentElement = (Element) parentNode;
    parentElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:mdssi",
            "http://schemas.openxmlformats.org/package/2006/digital-signature");
    Document document = parentNode.getOwnerDocument();
    for (String sourceId : this.sourceIds) {
        Element relationshipReferenceElement = document.createElementNS(
                "http://schemas.openxmlformats.org/package/2006/digital-signature",
                "mdssi:RelationshipReference");
        relationshipReferenceElement.setAttribute("SourceId", sourceId);
        parentElement.appendChild(relationshipReferenceElement);
    }/*from   w  ww . j a  va2s .co  m*/
    for (String sourceType : this.sourceTypes) {
        Element relationshipsGroupReferenceElement = document.createElementNS(
                "http://schemas.openxmlformats.org/package/2006/digital-signature",
                "mdssi:RelationshipsGroupReference");
        relationshipsGroupReferenceElement.setAttribute("SourceType", sourceType);
        parentElement.appendChild(relationshipsGroupReferenceElement);
    }
}