org.w3c.dom.DOMImplementation#createDocumentType ( )源码实例Demo

下面列出了org.w3c.dom.DOMImplementation#createDocumentType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: JarBundler   文件: PropertyListWriter.java
private Document createDOM() throws ParserConfigurationException
{

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = factory.newDocumentBuilder();
    DOMImplementation domImpl = documentBuilder.getDOMImplementation();

    // We needed to reference using the full class name here because we already have
    //  a class named "DocumentType"

    org.w3c.dom.DocumentType doctype = domImpl.createDocumentType(
            "plist",
            "-//Apple Computer//DTD PLIST 1.0//EN",
            "http://www.apple.com/DTDs/PropertyList-1.0.dtd");

    return domImpl.createDocument(null, "plist", doctype);
}
 
源代码2 项目: JVoiceXML   文件: XmlDocument.java
/**
 * Creates an empty XML document.
 *
 * @throws ParserConfigurationException
 *         Error creating the document builder.
 */
public XmlDocument()
        throws ParserConfigurationException {
    // Check if there is a document type specified. 
    final DocumentType prototype = getDoctype();
    final DocumentBuilder builder = LOCAL_BUILDER.get();
    if (prototype == null) {
        // If there is none, simply create a new document as usual.
        document = builder.newDocument();
        if (document != null) {
            final Node root = createRootNode();
            appendChild(root);
        }
    } else {
        // otherwise create a document with the given doctype as a
        // prototype
        final DOMImplementation impl = builder.getDOMImplementation();
        final DocumentType type =
            impl.createDocumentType(prototype.getName(),
                prototype.getPublicId(), prototype.getSystemId());
        document = impl.createDocument(getDefaultNamespaceURI(),
                prototype.getName(), type);
    }
}
 
源代码3 项目: caja   文件: DoctypeMaker.java
public static Function<DOMImplementation, DocumentType> parse(String text) {
  // We recognize a subset of the XML DOCTYPE grammar.  Specifically, we
  // do not recognize embedded entity declarations to avoid XXE, or
  // annotations.

  // As noted above, we do not recognize the intSubset portion.
  Matcher m = DOCTYPE_PATTERN.matcher(text);
  if (!m.matches()) { return null; }

  String name = m.group(1), system2 = dequote(m.group(2)),
      pubid = dequote(m.group(3)), system4 = dequote(m.group(4));
  final String system = system2 == null ? system4 : system2;
  boolean isHtml = isHtml(name, pubid, system);
  if (isHtml && name.indexOf(':') < 0) {
    name = Strings.lower(name);
  }
  final String qname = name;
  final String publicId = pubid;
  final String systemId = system;
  return new Function<DOMImplementation, DocumentType>() {
    public DocumentType apply(DOMImplementation impl) {
      return impl.createDocumentType(qname, publicId, systemId);
    }
  };
}
 
源代码4 项目: caja   文件: Html5ElementStackTest.java
@Override
public void setUp() throws Exception {
  super.setUp();
  DOMImplementationRegistry registry =
      DOMImplementationRegistry.newInstance();
  DOMImplementation domImpl = registry.getDOMImplementation(
      "XML 1.0 Traversal 2.0");

  String qname = "html";
  String systemId = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
  String publicId = "-//W3C//DTD XHTML 1.0 Transitional//EN";

  DocumentType documentType = domImpl.createDocumentType(
      qname, publicId, systemId);
  Document doc = domImpl.createDocument(null, null, documentType);
  mq = new SimpleMessageQueue();

  stack = new Html5ElementStack(doc, false, mq);
  stack.open(false);
}
 
源代码5 项目: ph-commons   文件: XMLFactory.java
/**
 * Create a new document with a document type using a custom document builder.
 *
 * @param aDocBuilder
 *        the document builder to be used. May not be <code>null</code>.
 * @param eVersion
 *        The XML version to use. If <code>null</code> is passed,
 *        {@link EXMLVersion#XML_10} will be used.
 * @param sQualifiedName
 *        The qualified name to use.
 * @param sPublicId
 *        The public ID of the document type.
 * @param sSystemId
 *        The system ID of the document type.
 * @return The created document. Never <code>null</code>.
 */
@Nonnull
public static Document newDocument (@Nonnull final DocumentBuilder aDocBuilder,
                                    @Nullable final EXMLVersion eVersion,
                                    @Nonnull final String sQualifiedName,
                                    @Nullable final String sPublicId,
                                    @Nullable final String sSystemId)
{
  ValueEnforcer.notNull (aDocBuilder, "DocBuilder");

  final DOMImplementation aDomImpl = aDocBuilder.getDOMImplementation ();
  final DocumentType aDocType = aDomImpl.createDocumentType (sQualifiedName, sPublicId, sSystemId);

  final Document aDoc = aDomImpl.createDocument (sSystemId, sQualifiedName, aDocType);
  aDoc.setXmlVersion ((eVersion != null ? eVersion : EXMLVersion.XML_10).getVersion ());
  return aDoc;
}
 
源代码6 项目: jpexs-decompiler   文件: SVGExporter.java
public SVGExporter(ExportRectangle bounds, double zoom) {

        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        try {
            DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
            DOMImplementation impl = docBuilder.getDOMImplementation();
            DocumentType svgDocType = impl.createDocumentType("svg", "-//W3C//DTD SVG 1.0//EN",
                    "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd");
            _svg = impl.createDocument(sNamespace, "svg", svgDocType);
            Element svgRoot = _svg.getDocumentElement();
            svgRoot.setAttribute("xmlns:xlink", xlinkNamespace);
            if (bounds != null) {
                svgRoot.setAttribute("width", (bounds.getWidth() / SWF.unitDivisor) + "px");
                svgRoot.setAttribute("height", (bounds.getHeight() / SWF.unitDivisor) + "px");
                createDefGroup(bounds, null, zoom);
            }
        } catch (ParserConfigurationException ex) {
            Logger.getLogger(SVGExporter.class.getName()).log(Level.SEVERE, null, ex);
        }
        gradients = new ArrayList<>();
    }
 
源代码7 项目: Connect-SDK-Android-Core   文件: PListBuilder.java
public PListBuilder() {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder;
        builder = factory.newDocumentBuilder();
        DOMImplementation di = builder.getDOMImplementation();
        dt = di.createDocumentType("plist",
                "-//Apple//DTD PLIST 1.0//EN",
                "http://www.apple.com/DTDs/PropertyList-1.0.dtd");

        doc = di.createDocument("", "plist", dt);
        doc.setXmlStandalone(true);

        root = doc.getDocumentElement();
        root.setAttribute("version", "1.0");

        rootDict = doc.createElement("dict");
        root.appendChild(rootDict);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
}
 
源代码8 项目: phoebus   文件: FilePreferencesXmlSupport.java
/**
 * Create a new prefs XML document.
 */
private static Document createPrefsDoc(String qname) {
    try {
        DOMImplementation di = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
        DocumentType dt = di.createDocumentType(qname, null, PREFS_DTD_URI);
        return di.createDocument(null, qname, dt);
    } catch (ParserConfigurationException e) {
        throw new AssertionError(e);
    }
}
 
源代码9 项目: openjdk-jdk9   文件: DomImplementationTest.java
@Test
public void testCreateDocumentType01() throws ParserConfigurationException {
    final String name = "document:localName";
    final String publicId = "pubid";
    final String systemId = "sysid";

    DOMImplementation domImpl = getDOMImplementation();
    DocumentType documentType = domImpl.createDocumentType(name, publicId, systemId);
    verifyDocumentType(documentType, name, publicId, systemId);
}
 
源代码10 项目: openjdk-jdk9   文件: DomImplementationTest.java
@Test
public void testCreateDocumentType02() throws ParserConfigurationException {
    final String name = "document:localName";
    final String publicId = "-//W3C//DTD HTML 4.0 Transitional//EN";
    final String systemId = "http://www.w3.org/TR/REC-html40/loose.dtd";
    DOMImplementation domImpl = getDOMImplementation();

    DocumentType documentType = domImpl.createDocumentType(name, publicId, systemId);
    Document document = domImpl.createDocument("http://www.document.com", "document:localName", documentType);
    verifyDocumentType(document.getDoctype(), name, publicId, systemId);
}
 
源代码11 项目: java-scanner-access-twain   文件: XmlSupport.java
private static Document createPrefsDoc( String qname ) {
    try {
        DOMImplementation di = DocumentBuilderFactory.newInstance().
            newDocumentBuilder().getDOMImplementation();
        DocumentType dt = di.createDocumentType(qname, null, PREFS_DTD_URI);
        return di.createDocument(null, qname, dt);
    } catch(ParserConfigurationException e) {
        throw new AssertionError(e);
    }
}
 
源代码12 项目: java-ocr-api   文件: XmlSupport.java
private static Document createPrefsDoc( String qname ) {
    try {
        DOMImplementation di = DocumentBuilderFactory.newInstance().
            newDocumentBuilder().getDOMImplementation();
        DocumentType dt = di.createDocumentType(qname, null, PREFS_DTD_URI);
        return di.createDocument(null, qname, dt);
    } catch(ParserConfigurationException e) {
        throw new AssertionError(e);
    }
}
 
源代码13 项目: birt   文件: SVGRendererImpl.java
/**
 * Creates an SVG document and assigns width and height to the root "svg"
 * element.
 * 
 * @return Document the SVG document
 * @throws Exception
 */
protected Document createSvgDocument( ) throws Exception
{
	DocumentBuilderFactory factory = SecurityUtil.newDocumentBuilderFactory( );
	DocumentBuilder builder;

	builder = factory.newDocumentBuilder( );
	DOMImplementation domImpl = builder.getDOMImplementation( );
	DocumentType dType = domImpl.createDocumentType( "svg", //$NON-NLS-1$
			SVG_VERSION,
			SVG_DTD );
	Document svgDocument = domImpl.createDocument( XMLNS, "svg", dType ); //$NON-NLS-1$
	svgDocument.getDocumentElement( ).setAttribute( "xmlns", XMLNS ); //$NON-NLS-1$
	svgDocument.getDocumentElement( )
			.setAttribute( "xmlns:xlink", XMLNSXINK ); //$NON-NLS-1$

	if ( _resizeSVG )
	{
		svgDocument.getDocumentElement( )
				.setAttribute( "onload", "resizeSVG(evt)" ); //$NON-NLS-1$ //$NON-NLS-2$
		// the onload() effect could be inaccurate, call onreisze again to
		// ensure, Note onload() is still needed, because onresize may never
		// be called.
		svgDocument.getDocumentElement( )
				.setAttribute( "onresize", "resizeSVG(evt)" ); //$NON-NLS-1$ //$NON-NLS-2$
	}

	return svgDocument;
}
 
源代码14 项目: netbeans   文件: XMLUtil.java
/**
 * Creates an empty DOM document. E.g.:
 * <p><pre>
 * Document doc = createDocument("book", null, null, null);
 * </pre><p>
 * creates new DOM of a well-formed document with root element named book.
 *
 * @param rootQName qualified name of root element. e.g. <code>myroot</code> or <code>ns:myroot</code>
 * @param namespaceURI URI of root element namespace or <code>null</code>
 * @param doctypePublicID public ID of DOCTYPE or <code>null</code>
 * @param doctypeSystemID system ID of DOCTYPE or <code>null</code> if no DOCTYPE
 *        required and doctypePublicID is also <code>null</code>
 *
 * @throws DOMException if new DOM with passed parameters can not be created
 * @throws FactoryConfigurationError Application developers should never need to directly catch errors of this type.
 *
 * @return new DOM Document
 */
public static Document createDocument(
    String rootQName, String namespaceURI, String doctypePublicID, String doctypeSystemID
) throws DOMException {
    DOMImplementation impl = getDOMImplementation();

    if ((doctypePublicID != null) && (doctypeSystemID == null)) {
        throw new IllegalArgumentException("System ID cannot be null if public ID specified. "); //NOI18N
    }

    DocumentType dtd = null;

    if (doctypeSystemID != null) {
        dtd = impl.createDocumentType(rootQName, doctypePublicID, doctypeSystemID);
    }

    return impl.createDocument(namespaceURI, rootQName, dtd);
}