Java Code Examples for org.w3c.dom.DocumentType#getOwnerDocument()

The following examples show how to use org.w3c.dom.DocumentType#getOwnerDocument() . 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: CoreDOMImplementationImpl.java    From Bytecoder with Apache License 2.0 6 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 = createDocument(doctype);
        // If namespaceURI and qualifiedName are null return a Document with no document element.
        if (qualifiedName != null || namespaceURI != null) {
            Element e = doc.createElementNS(namespaceURI, qualifiedName);
            doc.appendChild(e);
        }
        return doc;
}
 
Example 2
Source File: PSVIDOMImplementationImpl.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) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
                               DOMMessageFormatter.formatMessage(
                               DOMMessageFormatter.XML_DOMAIN,
                                                   "WRONG_DOCUMENT_ERR", null));
    }
    DocumentImpl doc = new PSVIDocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
Example 3
Source File: DOMImplementationImpl.java    From Bytecoder with Apache License 2.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(namespaceURI == null && qualifiedName == null && doctype == null){
    //if namespaceURI, qualifiedName and doctype are null, returned document is empty with
    //no document element
        return new DocumentImpl();
    }
    else 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);
    }
    DocumentImpl doc = new DocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
Example 4
Source File: CoreDOMImplementationImpl.java    From openjdk-jdk8u-backup 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 5
Source File: PSVIDOMImplementationImpl.java    From openjdk-jdk8u-backup 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) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
                               DOMMessageFormatter.formatMessage(
                               DOMMessageFormatter.XML_DOMAIN,
                                                   "WRONG_DOCUMENT_ERR", null));
    }
    DocumentImpl doc = new PSVIDocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
Example 6
Source File: DOMImplementationImpl.java    From openjdk-jdk8u-backup 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(namespaceURI == null && qualifiedName == null && doctype == null){
    //if namespaceURI, qualifiedName and doctype are null, returned document is empty with
    //no document element
        return new DocumentImpl();
    }
    else 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);
    }
    DocumentImpl doc = new DocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
Example 7
Source File: CoreDOMImplementationImpl.java    From openjdk-8-source 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 8
Source File: PSVIDOMImplementationImpl.java    From openjdk-jdk8u 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) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
                               DOMMessageFormatter.formatMessage(
                               DOMMessageFormatter.XML_DOMAIN,
                                                   "WRONG_DOCUMENT_ERR", null));
    }
    DocumentImpl doc = new PSVIDocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
Example 9
Source File: CoreDOMImplementationImpl.java    From openjdk-jdk9 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 10
Source File: PSVIDOMImplementationImpl.java    From openjdk-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) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
                               DOMMessageFormatter.formatMessage(
                               DOMMessageFormatter.XML_DOMAIN,
                                                   "WRONG_DOCUMENT_ERR", null));
    }
    DocumentImpl doc = new PSVIDocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
Example 11
Source File: Nodes.java    From caja with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a rendering of document type.  This is handled explicitly here
 * rather than in {@link Nodes#render(Node, MarkupRenderMode)} to avoid
 * rendering a document type in the middle of a document.
 *
 * @return null if nothing to render or docType is invalid.
 */
private static @Nullable String renderDocumentType(DocumentType docType) {
  String publicId = docType.getPublicId();
  String systemId = docType.getSystemId();
  String nodeName;

  if (null != docType.getOwnerDocument() &&
      null != docType.getOwnerDocument().getDocumentElement() &&
      null != docType.getOwnerDocument().getDocumentElement().getNodeName()) {
    nodeName = docType.getOwnerDocument()
      .getDocumentElement()
      .getNodeName();
  } else {
    return null;
  }

  if (!DoctypeMaker.isHtml(nodeName, publicId, systemId)) {
    return null;
  }

  StringBuilder sb = new StringBuilder();
  sb.append("<!DOCTYPE ").append(nodeName);
  // The Name in the document type declaration must match the element type
  // of the root element.
  if (null != publicId && publicId.length() > 0) {
    sb.append(" PUBLIC ")
      .append('"')
      .append(publicId.replaceAll("\"", "%22"))
      .append('"');
  }
  if (null != systemId && systemId.length() > 0) {
    // Sanity check - system urls should parse as an absolute uris
    try {
      URI u = new URI(systemId);
      if (u.isAbsolute() &&
          ("http".equals(u.getScheme()) || "https".equals(u.getScheme()))) {
        sb.append(" ")
          .append('"')
          .append(systemId.replaceAll("\"", "%22"))
          .append('"');
      }
    } catch (URISyntaxException e) {
      return null;
    }
  }
  sb.append(">");
  return sb.toString();
}
 
Example 12
Source File: DOMImplementationImpl.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(namespaceURI == null && qualifiedName == null && doctype == null){
    //if namespaceURI, qualifiedName and doctype are null, returned document is empty with
    //no document element
        return new DocumentImpl();
    }
    else 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);
    }
    DocumentImpl doc = new DocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
Example 13
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 14
Source File: DOMImplementationImpl.java    From hottub 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(namespaceURI == null && qualifiedName == null && doctype == null){
    //if namespaceURI, qualifiedName and doctype are null, returned document is empty with
    //no document element
        return new DocumentImpl();
    }
    else 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);
    }
    DocumentImpl doc = new DocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
Example 15
Source File: CoreDOMImplementationImpl.java    From openjdk-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 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: PSVIDOMImplementationImpl.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) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
                               DOMMessageFormatter.formatMessage(
                               DOMMessageFormatter.XML_DOMAIN,
                                                   "WRONG_DOCUMENT_ERR", null));
    }
    DocumentImpl doc = new PSVIDocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
Example 18
Source File: DOMImplementationImpl.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(namespaceURI == null && qualifiedName == null && doctype == null){
    //if namespaceURI, qualifiedName and doctype are null, returned document is empty with
    //no document element
        return new DocumentImpl();
    }
    else 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);
    }
    DocumentImpl doc = new DocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
Example 19
Source File: PSVIDOMImplementationImpl.java    From openjdk-8-source 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) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
                               DOMMessageFormatter.formatMessage(
                               DOMMessageFormatter.XML_DOMAIN,
                                                   "WRONG_DOCUMENT_ERR", null));
    }
    DocumentImpl doc = new PSVIDocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
Example 20
Source File: CoreDOMImplementationImpl.java    From hottub 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;
}