本文整理汇总了Java中org.w3c.dom.DocumentType.getPublicId方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentType.getPublicId方法的具体用法?Java DocumentType.getPublicId怎么用?Java DocumentType.getPublicId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.DocumentType
的用法示例。
在下文中一共展示了DocumentType.getPublicId方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import org.w3c.dom.DocumentType; //导入方法依赖的package包/类
public static void write(Document doc, OutputStream out) throws IOException {
// XXX note that this may fail to write out namespaces correctly if the document
// is created with namespaces and no explicit prefixes; however no code in
// this package is likely to be doing so
try {
Transformer t = TransformerFactory.newInstance().newTransformer(
new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT)));
DocumentType dt = doc.getDoctype();
if (dt != null) {
String pub = dt.getPublicId();
if (pub != null) {
t.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, pub);
}
t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, dt.getSystemId());
}
t.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // NOI18N
Source source = new DOMSource(doc);
Result result = new StreamResult(out);
t.transform(source, result);
} catch (Exception | TransformerFactoryConfigurationError e) {
throw new IOException(e);
}
}
示例2: write
import org.w3c.dom.DocumentType; //导入方法依赖的package包/类
/**
* 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('>');
}
示例3: write
import org.w3c.dom.DocumentType; //导入方法依赖的package包/类
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('>');
}
示例4: whichDoctypePublic
import org.w3c.dom.DocumentType; //导入方法依赖的package包/类
/**
* 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: getDocumentTypeDeclarationPublicIdentifier
import org.w3c.dom.DocumentType; //导入方法依赖的package包/类
/**
* Return the public identifier of the external subset,
* normalized as described in 4.2.2 External Entities [XML]. If there is
* no external subset or if it has no public identifier, this property
* has no value.
*
* @return the public identifier String object, or null if there is none.
*/
public String getDocumentTypeDeclarationPublicIdentifier()
{
Document doc;
if (m_root.getNodeType() == Node.DOCUMENT_NODE)
doc = (Document) m_root;
else
doc = m_root.getOwnerDocument();
if (null != doc)
{
DocumentType dtd = doc.getDoctype();
if (null != dtd)
{
return dtd.getPublicId();
}
}
return null;
}
示例6: writeDocumentType
import org.w3c.dom.DocumentType; //导入方法依赖的package包/类
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);
}
示例7: write
import org.w3c.dom.DocumentType; //导入方法依赖的package包/类
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('>');
}
示例8: write
import org.w3c.dom.DocumentType; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* @since TFP 1.0
*/
public void write (final Document document)
{
DocumentType doctype = document.getDoctype ();
output.print ("<?xml version=\"1.0\" encoding=\"" + getEncoding () + "\"?>");
if (doctype != null) {
output.print ("<!DOCTYPE " + doctype.getName ());
if (doctype.getPublicId () != null) {
output.print (" PUBLIC \"" + doctype.getPublicId () + "\"");
output.print (" \"" + doctype.getSystemId () +"\"");
}
else if (doctype.getSystemId () != null)
output.print (" SYSTEM \"" + doctype.getSystemId () + "\"");
if (doctype.getInternalSubset () != null) {
output.print (" [");
output.print (doctype.getInternalSubset ());
}
output.print (">");
}
write (document.getDocumentElement ());
}
示例9: write
import org.w3c.dom.DocumentType; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* @since TFP 1.0
*/
public void write (Document document)
{
DocumentType doctype = document.getDoctype ();
output.println ("<?xml version=\"1.0\" encoding=\"" + getEncoding () + "\"?>");
if (doctype != null) {
output.print ("<!DOCTYPE " + doctype.getName ());
if (doctype.getPublicId () != null) {
output.print (" PUBLIC \"" + doctype.getPublicId () + "\"");
output.print (" \"" + doctype.getSystemId () +"\"");
}
else if (doctype.getSystemId () != null)
output.print (" SYSTEM \"" + doctype.getSystemId () + "\"");
if (doctype.getInternalSubset () != null) {
output.println (" [");
output.println (doctype.getInternalSubset ());
output.print ("]");
}
output.println (">");
}
write (document.getDocumentElement ());
}
示例10: invoke
import org.w3c.dom.DocumentType; //导入方法依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getName().equals("getDoctype") && args == null) { // NOI18N
return (DocumentType)proxyDocument;
} else if (method.getName().equals("getPublicId") && args == null) { // NOI18N
Document d = getDocumentImpl(false);
if (d != null) {
DocumentType doctype = d.getDoctype();
return doctype == null ? null : doctype.getPublicId();
} else {
return obj.getIP().getPublicId();
}
} else {
return method.invoke(getDocumentImpl(true), args);
}
}
示例11: isInstance
import org.w3c.dom.DocumentType; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* @since TFP 1.0
*/
public boolean isInstance (Document document)
{
DocumentType doctype = document.getDoctype ();
if (doctype != null) {
String publicId = doctype.getPublicId ();
Element root = document.getDocumentElement ();
if ((publicId != null) && publicId.equals (this.publicId)
&& hasRootElement (root.getLocalName ()))
return (true);
}
return (false);
}
示例12: write
import org.w3c.dom.DocumentType; //导入方法依赖的package包/类
/**
* 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><![CDATA[ ]]></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);
}
}
示例13: serializeDocType
import org.w3c.dom.DocumentType; //导入方法依赖的package包/类
/**
* 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(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();
}
}
}
}
示例14: createTransformer
import org.w3c.dom.DocumentType; //导入方法依赖的package包/类
/**
* Creates a new JAXP Transformer object that will be used to serialize this
* DOM. This method may be overridden in order to set custom properties on
* the Transformer.
*
* @return The transformer to be used for serialization.
*/
protected javax.xml.transform.Transformer createTransformer()
throws IOException {
try {
javax.xml.transform.Transformer transformer = javax.xml.transform.TransformerFactory
.newInstance().newTransformer();
transformer.setOutputProperty(
javax.xml.transform.OutputKeys.METHOD, "xml");
transformer.setOutputProperty(
javax.xml.transform.OutputKeys.INDENT,
isIndenting() ? "yes" : "no");
if (getCharacterSet() != null) {
transformer.setOutputProperty(
javax.xml.transform.OutputKeys.ENCODING,
getCharacterSet().getName());
} else {
transformer.setOutputProperty(
javax.xml.transform.OutputKeys.ENCODING,
CharacterSet.ISO_8859_1.getName());
}
DocumentType docType = getDocument().getDoctype();
if (docType != null) {
if (docType.getSystemId() != null) {
transformer.setOutputProperty(
javax.xml.transform.OutputKeys.DOCTYPE_SYSTEM,
getDocument().getDoctype().getSystemId());
}
if (docType.getPublicId() != null) {
transformer.setOutputProperty(
javax.xml.transform.OutputKeys.DOCTYPE_PUBLIC,
getDocument().getDoctype().getPublicId());
}
}
return transformer;
} catch (javax.xml.transform.TransformerConfigurationException tce) {
throw new IOException("Couldn't write the XML representation: "
+ tce.getMessage());
}
}