org.w3c.dom.DocumentType#getPublicId ( )源码实例Demo

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

源代码1 项目: jdk1.8-source-analysis   文件: OutputFormat.java
/**
 * Returns the document type public identifier
 * specified for this document, or null.
 */
public static String whichDoctypePublic( Document doc )
{
    DocumentType doctype;

       /*  DOM Level 2 was introduced into the code base*/
       doctype = doc.getDoctype();
       if ( doctype != null ) {
       // Note on catch: DOM Level 1 does not specify this method
       // and the code will throw a NoSuchMethodError
       try {
       return doctype.getPublicId();
       } catch ( Error except ) {  }
       }

    if ( doc instanceof HTMLDocument )
        return DTD.XHTMLPublicId;
    return null;
}
 
源代码2 项目: mapper-generator-javafx   文件: DomWriter.java
protected void write(DocumentType node) {
    printWriter.print("<!DOCTYPE ");
    printWriter.print(node.getName());
    String publicId = node.getPublicId();
    String systemId = node.getSystemId();
    if (publicId != null) {
        printWriter.print(" PUBLIC \"");
        printWriter.print(publicId);
        printWriter.print("\" \"");
        printWriter.print(systemId);
        printWriter.print('\"');
    } else if (systemId != null) {
        printWriter.print(" SYSTEM \"");
        printWriter.print(systemId);
        printWriter.print('"');
    }

    String internalSubset = node.getInternalSubset();
    if (internalSubset != null) {
        printWriter.println(" [");
        printWriter.print(internalSubset);
        printWriter.print(']');
    }
    printWriter.println('>');
}
 
源代码3 项目: TencentKona-8   文件: OutputFormat.java
/**
 * Returns the document type public identifier
 * specified for this document, or null.
 */
public static String whichDoctypePublic( Document doc )
{
    DocumentType doctype;

       /*  DOM Level 2 was introduced into the code base*/
       doctype = doc.getDoctype();
       if ( doctype != null ) {
       // Note on catch: DOM Level 1 does not specify this method
       // and the code will throw a NoSuchMethodError
       try {
       return doctype.getPublicId();
       } catch ( Error except ) {  }
       }

    if ( doc instanceof HTMLDocument )
        return DTD.XHTMLPublicId;
    return null;
}
 
源代码4 项目: JDKSourceCode1.8   文件: OutputFormat.java
/**
 * Returns the document type public identifier
 * specified for this document, or null.
 */
public static String whichDoctypePublic( Document doc )
{
    DocumentType doctype;

       /*  DOM Level 2 was introduced into the code base*/
       doctype = doc.getDoctype();
       if ( doctype != null ) {
       // Note on catch: DOM Level 1 does not specify this method
       // and the code will throw a NoSuchMethodError
       try {
       return doctype.getPublicId();
       } catch ( Error except ) {  }
       }

    if ( doc instanceof HTMLDocument )
        return DTD.XHTMLPublicId;
    return null;
}
 
源代码5 项目: MikuMikuStudio   文件: DOMSerializer.java
private void writeDocumentType(DocumentType docType, Writer writer, int depth) throws IOException {
    String publicId = docType.getPublicId();
    String internalSubset = docType.getInternalSubset();

    for (int i = 0; i < depth; ++i) { writer.append(' '); }
    writer.append("<!DOCTYPE ").append(docType.getName());
    if (publicId != null) {
        writer.append(" PUBLIC '").append(publicId).append("' ");
    } else {
        writer.write(" SYSTEM ");
    }
    writer.append("'").append(docType.getSystemId()).append("'");
    if (internalSubset != null) {
        writer.append(" [").append(internalSubset).append("]");
    }
    writer.append('>').append(lineSeparator);
}
 
源代码6 项目: mybatis-generator-core-fix   文件: DomWriter.java
/**
 * Write.
 *
 * @param node
 *            the node
 * @throws ShellException
 *             the shell exception
 */
protected void write(DocumentType node) throws ShellException {
    printWriter.print("<!DOCTYPE "); //$NON-NLS-1$
    printWriter.print(node.getName());
    String publicId = node.getPublicId();
    String systemId = node.getSystemId();
    if (publicId != null) {
        printWriter.print(" PUBLIC \""); //$NON-NLS-1$
        printWriter.print(publicId);
        printWriter.print("\" \""); //$NON-NLS-1$
        printWriter.print(systemId);
        printWriter.print('\"');
    } else if (systemId != null) {
        printWriter.print(" SYSTEM \""); //$NON-NLS-1$
        printWriter.print(systemId);
        printWriter.print('"');
    }

    String internalSubset = node.getInternalSubset();
    if (internalSubset != null) {
        printWriter.println(" ["); //$NON-NLS-1$
        printWriter.print(internalSubset);
        printWriter.print(']');
    }
    printWriter.println('>');
}
 
源代码7 项目: openjdk-8   文件: OutputFormat.java
/**
 * Returns the document type public identifier
 * specified for this document, or null.
 */
public static String whichDoctypePublic( Document doc )
{
    DocumentType doctype;

       /*  DOM Level 2 was introduced into the code base*/
       doctype = doc.getDoctype();
       if ( doctype != null ) {
       // Note on catch: DOM Level 1 does not specify this method
       // and the code will throw a NoSuchMethodError
       try {
       return doctype.getPublicId();
       } catch ( Error except ) {  }
       }

    if ( doc instanceof HTMLDocument )
        return DTD.XHTMLPublicId;
    return null;
}
 
源代码8 项目: xmlunit   文件: DefaultComparisonFormatter.java
/**
 * Appends the XML DOCTYPE for {@link #getShortString} or {@link #appendFullDocumentHeader} if present.
 *
 * @param sb the builder to append to
 * @param type the document type
 * @return true if the DOCTPYE has been appended
 *
 * @since XMLUnit 2.4.0
 */
protected boolean appendDocumentType(StringBuilder sb, DocumentType type) {
    if (type == null) {
        return false;
    }
    sb.append("<!DOCTYPE ").append(type.getName());
    boolean hasNoPublicId = true;
    if (type.getPublicId() != null && type.getPublicId().length() > 0) {
        sb.append(" PUBLIC \"").append(type.getPublicId()).append('"');
        hasNoPublicId = false;
    }
    if (type.getSystemId() != null && type.getSystemId().length() > 0) {
        if (hasNoPublicId) {
            sb.append(" SYSTEM");
        }
        sb.append(" \"").append(type.getSystemId()).append("\"");
    }
    sb.append(">");
    return true;
}
 
源代码9 项目: netbeans   文件: DDProvider.java
/**
 * Extracts version of deployment descriptor.
 */
private static String extractVersion(Document document) {
    // first check the doc type to see if there is one
    String id = null;
    DocumentType dt = document.getDoctype();
    if (dt != null) {
        // it is DTD-based
        id = dt.getPublicId();
    } else {
        // it is XSD-based
        String schemaLocation = document.getDocumentElement().getAttribute("xsi:schemaLocation");
        if (schemaLocation != null) {
            id = schemaLocation.substring(schemaLocation.lastIndexOf(" ") + 1);
        }
    }
    // This is the default version
    if (id != null) {
        if (EJB_21_DOCTYPE.equals(id)) {
            return EjbJar.VERSION_2_1;
        }
    }
    return EjbJar.VERSION_3_0;

}
 
源代码10 项目: netbeans   文件: DDProvider.java
private String getPublicIdFromImpl(RootInterfaceImpl rootProxyImpl) {
    String result = null;
    
    GraphManager gm = rootProxyImpl.graphManager();
    if(gm != null) {
        Document d = gm.getXmlDocument();
        if(d != null) {
            DocumentType dt = d.getDoctype();
            if(dt != null) {
                result = dt.getPublicId();
            }
        }
    }
    
    return result;
}
 
源代码11 项目: netbeans   文件: PayaraDDProvider.java
private String getPublicIdFromImpl(RootInterfaceImpl rootProxyImpl) {
    String result = null;

    GraphManager gm = rootProxyImpl.graphManager();
    if (gm != null) {
        Document d = gm.getXmlDocument();
        if (d != null) {
            DocumentType dt = d.getDoctype();
            if (dt != null) {
                result = dt.getPublicId();
            }
        }
    }

    return result;
}
 
源代码12 项目: openjdk-jdk8u-backup   文件: OutputFormat.java
/**
 * Returns the document type public identifier
 * specified for this document, or null.
 */
public static String whichDoctypePublic( Document doc )
{
    DocumentType doctype;

       /*  DOM Level 2 was introduced into the code base*/
       doctype = doc.getDoctype();
       if ( doctype != null ) {
       // Note on catch: DOM Level 1 does not specify this method
       // and the code will throw a NoSuchMethodError
       try {
       return doctype.getPublicId();
       } catch ( Error except ) {  }
       }

    if ( doc instanceof HTMLDocument )
        return DTD.XHTMLPublicId;
    return null;
}
 
源代码13 项目: htmlunit   文件: Document.java
private boolean isQuirksDocType() {
    final DocumentType docType = getPage().getDoctype();
    if (docType != null) {
        final String systemId = docType.getSystemId();
        if (systemId != null) {
            if ("http://www.w3.org/TR/html4/strict.dtd".equals(systemId)) {
                return false;
            }

            if ("http://www.w3.org/TR/html4/loose.dtd".equals(systemId)) {
                final String publicId = docType.getPublicId();
                if ("-//W3C//DTD HTML 4.01 Transitional//EN".equals(publicId)) {
                    return false;
                }
            }

            if ("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd".equals(systemId)
                || "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd".equals(systemId)) {
                return false;
            }
        }
        else if (docType.getPublicId() == null) {
            return docType.getName() == null;
        }
    }
    return true;
}
 
源代码14 项目: htmlunit   文件: XmlUtils.java
/**
 * Recursively appends a {@link Node} child to {@link DomNode} parent.
 *
 * @param page the owner page of {@link DomElement}s to be created
 * @param parent the parent DomNode
 * @param child the child Node
 * @param handleXHTMLAsHTML if true elements from the XHTML namespace are handled as HTML elements instead of
 *     DOM elements
 * @param attributesOrderMap (optional) the one returned by {@link #getAttributesOrderMap(Document)}
 */
public static void appendChild(final SgmlPage page, final DomNode parent, final Node child,
    final boolean handleXHTMLAsHTML, final Map<Integer, List<String>> attributesOrderMap) {
    final DocumentType documentType = child.getOwnerDocument().getDoctype();
    if (documentType != null && page instanceof XmlPage) {
        final DomDocumentType domDoctype = new DomDocumentType(
                page, documentType.getName(), documentType.getPublicId(), documentType.getSystemId());
        ((XmlPage) page).setDocumentType(domDoctype);
    }
    final DomNode childXml = createFrom(page, child, handleXHTMLAsHTML, attributesOrderMap);
    parent.appendChild(childXml);
    copy(page, child, childXml, handleXHTMLAsHTML, attributesOrderMap);
}
 
源代码15 项目: JVoiceXML   文件: AbstractXmlDocumentType.java
/**
 * {@inheritDoc}
 */
public final String getPublicId() {
    final DocumentType type = getDocumentType();
    return type.getPublicId();
}
 
源代码16 项目: j2objc   文件: DOM3TreeWalker.java
/**
 * Serializes a Document Type Node.
 * 
 * @param node The Docuemnt Type Node to serialize
 * @param bStart Invoked at the start or end of node.  Default true. 
 */
protected void serializeDocType(DocumentType node, boolean bStart)
    throws SAXException {
    // The DocType and internalSubset can not be modified in DOM and is
    // considered to be well-formed as the outcome of successful parsing.
    String docTypeName = node.getNodeName();
    String publicId = node.getPublicId();
    String systemId = node.getSystemId();
    String internalSubset = node.getInternalSubset();

    //DocumentType nodes are never passed to the filter
    
    if (internalSubset != null && !"".equals(internalSubset)) {

        if (bStart) {
            try {
                // The Serializer does not provide a way to write out the
                // DOCTYPE internal subset via an event call, so we write it
                // out here.
                Writer writer = fSerializer.getWriter();
                StringBuffer dtd = new StringBuffer();

                dtd.append("<!DOCTYPE ");
                dtd.append(docTypeName);
                if (null != publicId) {
                    dtd.append(" PUBLIC \"");
                    dtd.append(publicId);
                    dtd.append('\"');
                }

                if (null != systemId) {
                    if (null == publicId) {
                        dtd.append(" SYSTEM \"");
                    } else {
                        dtd.append(" \"");
                    }    
                    dtd.append(systemId);
                    dtd.append('\"');
                }
                
                dtd.append(" [ ");
                
                dtd.append(fNewLine);
                dtd.append(internalSubset);
                dtd.append("]>");
                dtd.append(new String(fNewLine));
                
                writer.write(dtd.toString());
                writer.flush();
                
            } catch (IOException e) {
                throw new SAXException(Utils.messages.createMessage(
                        MsgKey.ER_WRITING_INTERNAL_SUBSET, null), e);
            }
        } // else if !bStart do nothing
        
    } else {
        
        if (bStart) {
            if (fLexicalHandler != null) {
                fLexicalHandler.startDTD(docTypeName, publicId, systemId);
            }
        } else {
            if (fLexicalHandler != null) {
                fLexicalHandler.endDTD();
            }
        }
    }
}
 
源代码17 项目: exificient   文件: DOMWriter.java
protected void encodeChildNodes(NodeList children) throws EXIException,
		IOException {
	for (int i = 0; i < children.getLength(); i++) {
		Node n = children.item(i);
		switch (n.getNodeType()) {
		case Node.ELEMENT_NODE:
			encodeNode(n);
			break;
		case Node.ATTRIBUTE_NODE:
			break;
		case Node.TEXT_NODE:
			exiBody.encodeCharacters(new StringValue(n.getNodeValue()));
			break;
		case Node.COMMENT_NODE:
			if (preserveComments) {
				String c = n.getNodeValue();
				exiBody.encodeComment(c.toCharArray(), 0, c.length());
			}
			break;
		case Node.DOCUMENT_TYPE_NODE:
			DocumentType dt = (DocumentType) n;
			String publicID = dt.getPublicId() == null ? "" : dt
					.getPublicId();
			String systemID = dt.getSystemId() == null ? "" : dt
					.getSystemId();
			String text = dt.getInternalSubset() == null ? "" : dt
					.getInternalSubset();
			exiBody.encodeDocType(dt.getName(), publicID, systemID, text);
			break;
		case Node.ENTITY_REFERENCE_NODE:
			// checkPendingChars();
			// TODO ER
			break;
		case Node.CDATA_SECTION_NODE:
			// String cdata = n.getNodeValue();
			// exiBody.encodeCharacters(new
			// StringValue(Constants.CDATA_START
			// + cdata + Constants.CDATA_END));
			exiBody.encodeCharacters(new StringValue(n.getNodeValue()));
			break;
		case Node.PROCESSING_INSTRUCTION_NODE:
			if (preservePIs) {
				ProcessingInstruction pi = (ProcessingInstruction) n;
				exiBody.encodeProcessingInstruction(pi.getTarget(),
						pi.getData());
			}
			break;
		default:
			System.err.println("[WARNING] Unhandled DOM NodeType: "
					+ n.getNodeType());
			// throw new EXIException("Unknown NodeType? " +
			// n.getNodeType());
		}
	}
}
 
源代码18 项目: netbeans   文件: XMLUtil.java
/**
 * Writes a DOM document to a stream.
 * The precise output format is not guaranteed but this method will attempt to indent it sensibly.
 * 
 * <p class="nonnormative"><b>Important</b>: There might be some problems with
 * <code>&lt;![CDATA[ ]]&gt;</code> sections in the DOM tree you pass into this method. Specifically,
 * some CDATA sections my not be written as CDATA section or may be merged with
 * other CDATA section at the same level. Also if plain text nodes are mixed with
 * CDATA sections at the same level all text is likely to end up in one big CDATA section.
 * <br/>
 * For nodes that only have one CDATA section this method should work fine.
 * </p>
 * 
 * @param doc DOM document to be written
 * @param out data sink
 * @param enc XML-defined encoding name (e.g. "UTF-8")
 * @throws IOException if JAXP fails or the stream cannot be written to
 */
public static void write(Document doc, OutputStream out, String enc) throws IOException {
    if (enc == null) {
        throw new NullPointerException("You must set an encoding; use \"UTF-8\" unless you have a good reason not to!"); // NOI18N
    }
    Document doc2 = normalize(doc);
    ClassLoader orig = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { // #195921
        @Override public ClassLoader run() {
            return new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) {
                @Override public InputStream getResourceAsStream(String name) {
                    if (name.startsWith("META-INF/services/")) {
                        return new ByteArrayInputStream(new byte[0]); // JAXP #6723276
                    }
                    return super.getResourceAsStream(name);
                }
            };
        }
    }));
    try {
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer t = tf.newTransformer(
                new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT)));
        DocumentType dt = doc2.getDoctype();
        if (dt != null) {
            String pub = dt.getPublicId();
            if (pub != null) {
                t.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, pub);
            }
            String sys = dt.getSystemId();
            if (sys != null) {
                t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, sys);
            }
        }
        t.setOutputProperty(OutputKeys.ENCODING, enc);
        try {
            t.setOutputProperty(ORACLE_IS_STANDALONE, "yes");
        } catch (IllegalArgumentException x) {
            // fine, introduced in JDK 7u4
        }

        // See #123816
        Set<String> cdataQNames = new HashSet<String>();
        collectCDATASections(doc2, cdataQNames);
        if (cdataQNames.size() > 0) {
            StringBuilder cdataSections = new StringBuilder();
            for(String s : cdataQNames) {
                cdataSections.append(s).append(' '); //NOI18N
            }
            t.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, cdataSections.toString());
        }

        Source source = new DOMSource(doc2);
        Result result = new StreamResult(out);
        t.transform(source, result);
    } catch (Exception e) {
        throw new IOException(e);
    } finally {
        Thread.currentThread().setContextClassLoader(orig);
    }
}
 
源代码19 项目: Bytecoder   文件: DOMNormalizer.java
private void processDTD(String xmlVersion, String schemaLocation) {

        String rootName = null;
        String publicId = null;
        String systemId = schemaLocation;
        String baseSystemId = fDocument.getDocumentURI();
        String internalSubset = null;

        DocumentType docType = fDocument.getDoctype();
        if (docType != null) {
            rootName = docType.getName();
            publicId = docType.getPublicId();
            if (systemId == null || systemId.length() == 0) {
                systemId = docType.getSystemId();
            }
            internalSubset = docType.getInternalSubset();
        }
        // If the DOM doesn't have a DocumentType node we may still
        // be able to fetch a DTD if the application provided a URI
        else {
            Element elem = fDocument.getDocumentElement();
            if (elem == null) return;
            rootName = elem.getNodeName();
            if (systemId == null || systemId.length() == 0) return;
        }

        XMLDTDLoader loader = null;
        try {
            fValidationHandler.doctypeDecl(rootName, publicId, systemId, null);
            loader = CoreDOMImplementationImpl.singleton.getDTDLoader(xmlVersion);
            loader.setFeature(DOMConfigurationImpl.XERCES_VALIDATION, true);
            loader.setEntityResolver(fConfiguration.getEntityResolver());
            loader.setErrorHandler(fConfiguration.getErrorHandler());
            loader.loadGrammarWithContext((XMLDTDValidator) fValidationHandler, rootName,
                    publicId, systemId, baseSystemId, internalSubset);
        }
        // REVISIT: Should probably report this exception to the error handler.
        catch (IOException e) {
        }
        finally {
            if (loader != null) {
                CoreDOMImplementationImpl.singleton.releaseDTDLoader(xmlVersion, loader);
            }
        }
    }
 
源代码20 项目: seleniumtestsframework   文件: NodeDescription.java
protected static void appendDocumentTypeDetail(final StringBuffer buf, final Node aNode) {

        DocumentType type = (DocumentType) aNode;

        buf.append(XMLConstants.START_DOCTYPE).append(type.getName());

        boolean hasNoPublicId = true;

        if (type.getPublicId() != null

                && type.getPublicId().length() > 0) {

            buf.append(" PUBLIC \"").append(type.getPublicId()).append('"');

            hasNoPublicId = false;

        }

        if (type.getSystemId() != null

                && type.getSystemId().length() > 0) {

            if (hasNoPublicId) {

                buf.append(" SYSTEM");

            }

            buf.append(" \"").append(type.getSystemId()).append('"');

        }

    }