Java Code Examples for org.w3c.dom.DOMException#WRONG_DOCUMENT_ERR

The following examples show how to use org.w3c.dom.DOMException#WRONG_DOCUMENT_ERR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElementImpl.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public Attr setAttributeNode(Attr newAttr) throws DOMException {
    AttrImpl newAttrImpl = (AttrImpl) newAttr;

    if (newAttrImpl.document != this.document) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
    }

    if (newAttrImpl.getOwnerElement() != null) {
        throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, null);
    }

    AttrImpl oldAttrImpl = null;

    int i = indexOfAttribute(newAttr.getName());
    if (i != -1) {
        oldAttrImpl = attributes.get(i);
        attributes.remove(i);
    }

    attributes.add(newAttrImpl);
    newAttrImpl.ownerElement = this;

    return oldAttrImpl;
}
 
Example 2
Source File: RangeImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public void setEnd(Node refNode, int offset)
                   throws RangeException, DOMException
{
    if (fDocument.errorChecking) {
        if (fDetach) {
            throw new DOMException(
                    DOMException.INVALID_STATE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
        }
        if ( !isLegalContainer(refNode)) {
            throw new RangeExceptionImpl(
                    RangeException.INVALID_NODE_TYPE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
        }
        if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) {
            throw new DOMException(
                    DOMException.WRONG_DOCUMENT_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null));
        }
    }

    checkIndex(refNode, offset);

    fEndContainer = refNode;
    fEndOffset = offset;

    // If one boundary-point of a Range is set to have a root container
    // other
    // than the current one for the Range, the Range should be collapsed to
    // the new position.
    // The start position of a Range should never be after the end position.
    if (getCommonAncestorContainer() == null
            || (fStartContainer == fEndContainer && fEndOffset < fStartOffset)) {
        collapse(false);
    }
}
 
Example 3
Source File: RangeImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void setStartBefore(Node refNode)
    throws RangeException
{
    if (fDocument.errorChecking) {
        if (fDetach) {
            throw new DOMException(
                    DOMException.INVALID_STATE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
        }
        if ( !hasLegalRootContainer(refNode) ||
                !isLegalContainedNode(refNode) )
        {
            throw new RangeExceptionImpl(
                    RangeException.INVALID_NODE_TYPE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
        }
        if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) {
            throw new DOMException(
                    DOMException.WRONG_DOCUMENT_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null));
        }
    }

    fStartContainer = refNode.getParentNode();
    int i = 0;
    for (Node n = refNode; n!=null; n = n.getPreviousSibling()) {
        i++;
    }
    fStartOffset = i-1;

    // If one boundary-point of a Range is set to have a root container
    // other
    // than the current one for the Range, the Range should be collapsed to
    // the new position.
    // The start position of a Range should never be after the end position.
    if (getCommonAncestorContainer() == null
            || (fStartContainer == fEndContainer && fEndOffset < fStartOffset)) {
        collapse(true);
    }
}
 
Example 4
Source File: RangeImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public void setEndBefore(Node refNode)
    throws RangeException
{
    if (fDocument.errorChecking) {
        if (fDetach) {
            throw new DOMException(
                    DOMException.INVALID_STATE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
        }
        if ( !hasLegalRootContainer(refNode) ||
                !isLegalContainedNode(refNode)) {
            throw new RangeExceptionImpl(
                    RangeException.INVALID_NODE_TYPE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
        }
        if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) {
            throw new DOMException(
                    DOMException.WRONG_DOCUMENT_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null));
        }
    }
    fEndContainer = refNode.getParentNode();
    int i = 0;
    for (Node n = refNode; n!=null; n = n.getPreviousSibling()) {
        i++;
    }
    fEndOffset = i-1;

    // If one boundary-point of a Range is set to have a root container
    // other
    // than the current one for the Range, the Range should be collapsed to
    // the new position.
    // The start position of a Range should never be after the end position.
    if (getCommonAncestorContainer() == null
            || (fStartContainer == fEndContainer && fEndOffset < fStartOffset)) {
        collapse(false);
    }
}
 
Example 5
Source File: RangeImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void setEndAfter(Node refNode)
    throws RangeException
{
    if (fDocument.errorChecking) {
        if( fDetach) {
            throw new DOMException(
                    DOMException.INVALID_STATE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
        }
        if ( !hasLegalRootContainer(refNode) ||
                !isLegalContainedNode(refNode)) {
            throw new RangeExceptionImpl(
                    RangeException.INVALID_NODE_TYPE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
        }
        if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) {
            throw new DOMException(
                    DOMException.WRONG_DOCUMENT_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null));
        }
    }
    fEndContainer = refNode.getParentNode();
    int i = 0;
    for (Node n = refNode; n!=null; n = n.getPreviousSibling()) {
        i++;
    }
    fEndOffset = i;

    // If one boundary-point of a Range is set to have a root container
    // other
    // than the current one for the Range, the Range should be collapsed to
    // the new position.
    // The start position of a Range should never be after the end position.
    if (getCommonAncestorContainer() == null
            || (fStartContainer == fEndContainer && fEndOffset < fStartOffset)) {
        collapse(false);
    }
}
 
Example 6
Source File: CoreDocumentImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/** For DOM2 support. */
public CoreDocumentImpl(DocumentType doctype, boolean grammarAccess) {
    this(grammarAccess);
    if (doctype != null) {
        DocumentTypeImpl doctypeImpl;
        try {
            doctypeImpl = (DocumentTypeImpl) doctype;
        } catch (ClassCastException e) {
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
        }
        doctypeImpl.ownerDocument = this;
        appendChild(doctype);
    }
}
 
Example 7
Source File: RangeImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public void selectNode(Node refNode)
    throws RangeException
{
    if (fDocument.errorChecking) {
        if (fDetach) {
            throw new DOMException(
                    DOMException.INVALID_STATE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
        }
        if ( !isLegalContainer( refNode.getParentNode() ) ||
                !isLegalContainedNode( refNode ) ) {
            throw new RangeExceptionImpl(
                    RangeException.INVALID_NODE_TYPE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
        }
        if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) {
            throw new DOMException(
                    DOMException.WRONG_DOCUMENT_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null));
        }
    }
    Node parent = refNode.getParentNode();
    if (parent != null ) // REVIST: what to do if it IS null?
    {
        fStartContainer = parent;
        fEndContainer = parent;
        int i = 0;
        for (Node n = refNode; n!=null; n = n.getPreviousSibling()) {
            i++;
        }
        fStartOffset = i-1;
        fEndOffset = fStartOffset+1;
    }
}
 
Example 8
Source File: RangeImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public void setEndAfter(Node refNode)
    throws RangeException
{
    if (fDocument.errorChecking) {
        if( fDetach) {
            throw new DOMException(
                    DOMException.INVALID_STATE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
        }
        if ( !hasLegalRootContainer(refNode) ||
                !isLegalContainedNode(refNode)) {
            throw new RangeExceptionImpl(
                    RangeException.INVALID_NODE_TYPE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
        }
        if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) {
            throw new DOMException(
                    DOMException.WRONG_DOCUMENT_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null));
        }
    }
    fEndContainer = refNode.getParentNode();
    int i = 0;
    for (Node n = refNode; n!=null; n = n.getPreviousSibling()) {
        i++;
    }
    fEndOffset = i;

    // If one boundary-point of a Range is set to have a root container
    // other
    // than the current one for the Range, the Range should be collapsed to
    // the new position.
    // The start position of a Range should never be after the end position.
    if (getCommonAncestorContainer() == null
            || (fStartContainer == fEndContainer && fEndOffset < fStartOffset)) {
        collapse(false);
    }
}
 
Example 9
Source File: RangeImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void setEndAfter(Node refNode)
    throws RangeException
{
    if (fDocument.errorChecking) {
        if( fDetach) {
            throw new DOMException(
                    DOMException.INVALID_STATE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
        }
        if ( !hasLegalRootContainer(refNode) ||
                !isLegalContainedNode(refNode)) {
            throw new RangeExceptionImpl(
                    RangeException.INVALID_NODE_TYPE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
        }
        if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) {
            throw new DOMException(
                    DOMException.WRONG_DOCUMENT_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null));
        }
    }
    fEndContainer = refNode.getParentNode();
    int i = 0;
    for (Node n = refNode; n!=null; n = n.getPreviousSibling()) {
        i++;
    }
    fEndOffset = i;

    // If one boundary-point of a Range is set to have a root container
    // other
    // than the current one for the Range, the Range should be collapsed to
    // the new position.
    // The start position of a Range should never be after the end position.
    if (getCommonAncestorContainer() == null
            || (fStartContainer == fEndContainer && fEndOffset < fStartOffset)) {
        collapse(false);
    }
}
 
Example 10
Source File: RangeImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public void setStartAfter(Node refNode)
    throws RangeException
{
    if (fDocument.errorChecking) {
        if (fDetach) {
            throw new DOMException(
                    DOMException.INVALID_STATE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
        }
        if ( !hasLegalRootContainer(refNode) ||
                !isLegalContainedNode(refNode)) {
            throw new RangeExceptionImpl(
                    RangeException.INVALID_NODE_TYPE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
        }
        if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) {
            throw new DOMException(
                    DOMException.WRONG_DOCUMENT_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null));
        }
    }
    fStartContainer = refNode.getParentNode();
    int i = 0;
    for (Node n = refNode; n!=null; n = n.getPreviousSibling()) {
        i++;
    }
    fStartOffset = i;

    // If one boundary-point of a Range is set to have a root container
    // other
    // than the current one for the Range, the Range should be collapsed to
    // the new position.
    // The start position of a Range should never be after the end position.
    if (getCommonAncestorContainer() == null
            || (fStartContainer == fEndContainer && fEndOffset < fStartOffset)) {
        collapse(true);
    }
}
 
Example 11
Source File: RangeImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void setStartAfter(Node refNode)
    throws RangeException
{
    if (fDocument.errorChecking) {
        if (fDetach) {
            throw new DOMException(
                    DOMException.INVALID_STATE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
        }
        if ( !hasLegalRootContainer(refNode) ||
                !isLegalContainedNode(refNode)) {
            throw new RangeExceptionImpl(
                    RangeException.INVALID_NODE_TYPE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
        }
        if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) {
            throw new DOMException(
                    DOMException.WRONG_DOCUMENT_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null));
        }
    }
    fStartContainer = refNode.getParentNode();
    int i = 0;
    for (Node n = refNode; n!=null; n = n.getPreviousSibling()) {
        i++;
    }
    fStartOffset = i;

    // If one boundary-point of a Range is set to have a root container
    // other
    // than the current one for the Range, the Range should be collapsed to
    // the new position.
    // The start position of a Range should never be after the end position.
    if (getCommonAncestorContainer() == null
            || (fStartContainer == fEndContainer && fEndOffset < fStartOffset)) {
        collapse(true);
    }
}
 
Example 12
Source File: RangeImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public void selectNode(Node refNode)
    throws RangeException
{
    if (fDocument.errorChecking) {
        if (fDetach) {
            throw new DOMException(
                    DOMException.INVALID_STATE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
        }
        if ( !isLegalContainer( refNode.getParentNode() ) ||
                !isLegalContainedNode( refNode ) ) {
            throw new RangeExceptionImpl(
                    RangeException.INVALID_NODE_TYPE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
        }
        if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) {
            throw new DOMException(
                    DOMException.WRONG_DOCUMENT_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null));
        }
    }
    Node parent = refNode.getParentNode();
    if (parent != null ) // REVIST: what to do if it IS null?
    {
        fStartContainer = parent;
        fEndContainer = parent;
        int i = 0;
        for (Node n = refNode; n!=null; n = n.getPreviousSibling()) {
            i++;
        }
        fStartOffset = i-1;
        fEndOffset = fStartOffset+1;
    }
}
 
Example 13
Source File: RangeImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void setStartBefore(Node refNode)
    throws RangeException
{
    if (fDocument.errorChecking) {
        if (fDetach) {
            throw new DOMException(
                    DOMException.INVALID_STATE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
        }
        if ( !hasLegalRootContainer(refNode) ||
                !isLegalContainedNode(refNode) )
        {
            throw new RangeExceptionImpl(
                    RangeException.INVALID_NODE_TYPE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
        }
        if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) {
            throw new DOMException(
                    DOMException.WRONG_DOCUMENT_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null));
        }
    }

    fStartContainer = refNode.getParentNode();
    int i = 0;
    for (Node n = refNode; n!=null; n = n.getPreviousSibling()) {
        i++;
    }
    fStartOffset = i-1;

    // If one boundary-point of a Range is set to have a root container
    // other
    // than the current one for the Range, the Range should be collapsed to
    // the new position.
    // The start position of a Range should never be after the end position.
    if (getCommonAncestorContainer() == null
            || (fStartContainer == fEndContainer && fEndOffset < fStartOffset)) {
        collapse(true);
    }
}
 
Example 14
Source File: IIOMetadataNode.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that the node is either <code>null</code> or an
 * <code>IIOMetadataNode</code>.
 */
private void checkNode(Node node) throws DOMException {
    if (node == null) {
        return;
    }
    if (!(node instanceof IIOMetadataNode)) {
        throw new IIODOMException(DOMException.WRONG_DOCUMENT_ERR,
                                  "Node not an IIOMetadataNode!");
    }
}
 
Example 15
Source File: RangeImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public void insertNode(Node newNode)
    throws DOMException, RangeException
{
    if ( newNode == null ) return; //throw exception?

    int type = newNode.getNodeType();

    if (fDocument.errorChecking) {
        if (fDetach) {
            throw new DOMException(
                    DOMException.INVALID_STATE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
        }
        if ( fDocument != newNode.getOwnerDocument() ) {
            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null));
        }

        if (type == Node.ATTRIBUTE_NODE
                || type == Node.ENTITY_NODE
                || type == Node.NOTATION_NODE
                || type == Node.DOCUMENT_NODE)
        {
            throw new RangeExceptionImpl(
                    RangeException.INVALID_NODE_TYPE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
        }
    }
    Node cloneCurrent;
    Node current;
    int currentChildren = 0;
    fInsertedFromRange = true;

    //boolean MULTIPLE_MODE = false;
    if (fStartContainer.getNodeType() == Node.TEXT_NODE) {

        Node parent = fStartContainer.getParentNode();
        currentChildren = parent.getChildNodes().getLength(); //holds number of kids before insertion
        // split text node: results is 3 nodes..
        cloneCurrent = fStartContainer.cloneNode(false);
        ((TextImpl)cloneCurrent).setNodeValueInternal(
                (cloneCurrent.getNodeValue()).substring(fStartOffset));
        ((TextImpl)fStartContainer).setNodeValueInternal(
                (fStartContainer.getNodeValue()).substring(0,fStartOffset));
        Node next = fStartContainer.getNextSibling();
        if (next != null) {
                if (parent !=  null) {
                    parent.insertBefore(newNode, next);
                    parent.insertBefore(cloneCurrent, next);
                }
        } else {
                if (parent != null) {
                    parent.appendChild(newNode);
                    parent.appendChild(cloneCurrent);
                }
        }
         //update ranges after the insertion
         if ( fEndContainer == fStartContainer) {
              fEndContainer = cloneCurrent; //endContainer is the new Node created
              fEndOffset -= fStartOffset;
         }
         else if ( fEndContainer == parent ) {    //endContainer was not a text Node.
              //endOffset + = number_of_children_added
               fEndOffset += (parent.getChildNodes().getLength() - currentChildren);
         }

         // signal other Ranges to update their start/end containers/offsets
         signalSplitData(fStartContainer, cloneCurrent, fStartOffset);


    } else { // ! TEXT_NODE
        if ( fEndContainer == fStartContainer )      //need to remember number of kids
            currentChildren= fEndContainer.getChildNodes().getLength();

        current = fStartContainer.getFirstChild();
        int i = 0;
        for(i = 0; i < fStartOffset && current != null; i++) {
            current=current.getNextSibling();
        }
        if (current != null) {
            fStartContainer.insertBefore(newNode, current);
        } else {
            fStartContainer.appendChild(newNode);
        }
        //update fEndOffset. ex:<body><p/></body>. Range(start;end): body,0; body,1
        // insert <h1>: <body></h1><p/></body>. Range(start;end): body,0; body,2
        if ( fEndContainer == fStartContainer && fEndOffset != 0 ) {     //update fEndOffset if not 0
            fEndOffset += (fEndContainer.getChildNodes().getLength() - currentChildren);
        }
    }
    fInsertedFromRange = false;
}
 
Example 16
Source File: CoreDOMImplementationImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document createDocument(
        String namespaceURI,
        String qualifiedName,
        DocumentType doctype)
        throws DOMException {
        if (doctype != null && doctype.getOwnerDocument() != null) {
                String msg =
                        DOMMessageFormatter.formatMessage(
                                DOMMessageFormatter.DOM_DOMAIN,
                                "WRONG_DOCUMENT_ERR",
                                null);
                throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
        }
        CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
        Element e = doc.createElementNS(namespaceURI, qualifiedName);
        doc.appendChild(e);
        return doc;
}
 
Example 17
Source File: CoreDOMImplementationImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document createDocument(
        String namespaceURI,
        String qualifiedName,
        DocumentType doctype)
        throws DOMException {
        if (doctype != null && doctype.getOwnerDocument() != null) {
                String msg =
                        DOMMessageFormatter.formatMessage(
                                DOMMessageFormatter.DOM_DOMAIN,
                                "WRONG_DOCUMENT_ERR",
                                null);
                throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
        }
        CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
        Element e = doc.createElementNS(namespaceURI, qualifiedName);
        doc.appendChild(e);
        return doc;
}
 
Example 18
Source File: CoreDOMImplementationImpl.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document createDocument(
        String namespaceURI,
        String qualifiedName,
        DocumentType doctype)
        throws DOMException {
        if (doctype != null && doctype.getOwnerDocument() != null) {
                String msg =
                        DOMMessageFormatter.formatMessage(
                                DOMMessageFormatter.DOM_DOMAIN,
                                "WRONG_DOCUMENT_ERR",
                                null);
                throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
        }
        CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
        Element e = doc.createElementNS(namespaceURI, qualifiedName);
        doc.appendChild(e);
        return doc;
}
 
Example 19
Source File: CoreDocumentImpl.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * DOM Level 3 WD - Experimental.
 * Save the document or the given node and all its descendants to a string
 * (i.e. serialize the document or node).
 * <br>The parameters used in the <code>LSSerializer</code> interface are
 * assumed to have their default values when invoking this method.
 * <br> The result of a call to this method is the same the result of a
 * call to <code>LSSerializer.writeToString</code> with the document as
 * the node to write.
 * @param node Specifies what to serialize, if this parameter is
 *   <code>null</code> the whole document is serialized, if it's
 *   non-null the given node is serialized.
 * @return The serialized document or <code>null</code> in case an error
 *   occurred.
 * @exception DOMException
 *   WRONG_DOCUMENT_ERR: Raised if the node passed in as the node
 *   parameter is from an other document.
 */
public String saveXML(Node node)
throws DOMException {
    if ( errorChecking && node != null &&
        this != node.getOwnerDocument() ) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
    }
    DOMImplementationLS domImplLS = (DOMImplementationLS)DOMImplementationImpl.getDOMImplementation();
    LSSerializer xmlWriter = domImplLS.createLSSerializer();
    if (node == null) {
        node = this;
    }
    return xmlWriter.writeToString(node);
}
 
Example 20
Source File: CoreDocumentImpl.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * DOM Level 3 WD - Experimental.
 * Save the document or the given node and all its descendants to a string
 * (i.e. serialize the document or node).
 * <br>The parameters used in the <code>LSSerializer</code> interface are
 * assumed to have their default values when invoking this method.
 * <br> The result of a call to this method is the same the result of a
 * call to <code>LSSerializer.writeToString</code> with the document as
 * the node to write.
 * @param node Specifies what to serialize, if this parameter is
 *   <code>null</code> the whole document is serialized, if it's
 *   non-null the given node is serialized.
 * @return The serialized document or <code>null</code> in case an error
 *   occurred.
 * @exception DOMException
 *   WRONG_DOCUMENT_ERR: Raised if the node passed in as the node
 *   parameter is from an other document.
 */
public String saveXML(Node node)
throws DOMException {
    if ( errorChecking && node != null &&
        this != node.getOwnerDocument() ) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
    }
    DOMImplementationLS domImplLS = (DOMImplementationLS)DOMImplementationImpl.getDOMImplementation();
    LSSerializer xmlWriter = domImplLS.createLSSerializer();
    if (node == null) {
        node = this;
    }
    return xmlWriter.writeToString(node);
}