Java Code Examples for org.w3c.dom.Document#getDoctype()
The following examples show how to use
org.w3c.dom.Document#getDoctype() .
These examples are extracted from open source projects.
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 Project: jdk1.8-source-analysis File: OutputFormat.java License: Apache License 2.0 | 6 votes |
/** * 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; }
Example 2
Source Project: openjdk-jdk8u File: OutputFormat.java License: GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 3
Source Project: netbeans File: PayaraDDProvider.java License: Apache License 2.0 | 6 votes |
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; }
Example 4
Source Project: jdk8u60 File: OutputFormat.java License: GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 5
Source Project: openjdk-jdk8u-backup File: OutputFormat.java License: GNU General Public License v2.0 | 6 votes |
/** * Returns the document type system identifier * specified for this document, or null. */ public static String whichDoctypeSystem( 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.getSystemId(); } catch ( Error except ) { } } if ( doc instanceof HTMLDocument ) return DTD.XHTMLSystemId; return null; }
Example 6
Source Project: caja File: DomParser.java License: Apache License 2.0 | 6 votes |
private OpenElementStack makeElementStack(Document doc, MessageQueue mq) { Namespaces ns = this.ns; DocumentType doctype = doc.getDoctype(); if (doctype != null) { // If we have a DOCTYPE, use its SYSTEM ID to determine the default // namespace. String sysid = doctype.getSystemId(); String nsUri = DoctypeMaker.systemIdToNsUri(sysid); if (nsUri != null) { ns = new Namespaces(ns, "", nsUri); } } return asXml ? OpenElementStack.Factory.createXmlElementStack( doc, needsDebugData, ns, mq) : OpenElementStack.Factory.createHtml5ElementStack( doc, needsDebugData, mq); }
Example 7
Source Project: netbeans File: XMLUtil.java License: Apache License 2.0 | 6 votes |
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); } }
Example 8
Source Project: hottub File: DOMValidatorHelper.java License: GNU General Public License v2.0 | 5 votes |
/** * Extracts NamedNodeMap of entities. We need this to validate * elements and attributes of type xs:ENTITY, xs:ENTITIES or * types dervied from them. */ private void setupEntityMap(Document doc) { if (doc != null) { DocumentType docType = doc.getDoctype(); if (docType != null) { fEntities = docType.getEntities(); return; } } fEntities = null; }
Example 9
Source Project: netbeans File: SunCmpMappingsProxy.java License: Apache License 2.0 | 5 votes |
private Document removeDocType(Document document) { if (document != null) { org.w3c.dom.Element docElement = document.getDocumentElement(); if (docElement != null) { org.w3c.dom.DocumentType docType = document.getDoctype(); if (docType != null) { document.removeChild(docType); //NOI18N } } } return document; }
Example 10
Source Project: TencentKona-8 File: DOMValidatorHelper.java License: GNU General Public License v2.0 | 5 votes |
/** * Extracts NamedNodeMap of entities. We need this to validate * elements and attributes of type xs:ENTITY, xs:ENTITIES or * types dervied from them. */ private void setupEntityMap(Document doc) { if (doc != null) { DocumentType docType = doc.getDoctype(); if (docType != null) { fEntities = docType.getEntities(); return; } } fEntities = null; }
Example 11
Source Project: Bytecoder File: DOMValidatorHelper.java License: Apache License 2.0 | 5 votes |
/** * Extracts NamedNodeMap of entities. We need this to validate * elements and attributes of type xs:ENTITY, xs:ENTITIES or * types dervied from them. */ private void setupEntityMap(Document doc) { if (doc != null) { DocumentType docType = doc.getDoctype(); if (docType != null) { fEntities = docType.getEntities(); return; } } fEntities = null; }
Example 12
Source Project: openjdk-8 File: DOMValidatorHelper.java License: GNU General Public License v2.0 | 5 votes |
/** * Extracts NamedNodeMap of entities. We need this to validate * elements and attributes of type xs:ENTITY, xs:ENTITIES or * types dervied from them. */ private void setupEntityMap(Document doc) { if (doc != null) { DocumentType docType = doc.getDoctype(); if (docType != null) { fEntities = docType.getEntities(); return; } } fEntities = null; }
Example 13
Source Project: openbd-core File: XmlDocumentHashtable.java License: GNU General Public License v3.0 | 5 votes |
protected cfData getXmlDocType() { Document doc = (Document) nodeData; if (doc.getDoctype() != null) return new cfXmlData(this, doc.getDoctype(), isCaseSensitive()); else return null; }
Example 14
Source Project: netbeans File: SunEjbJarProxy.java License: Apache License 2.0 | 5 votes |
private Document removeDocType(Document document){ if (document != null) { org.w3c.dom.Element docElement = document.getDocumentElement(); if (docElement != null) { org.w3c.dom.DocumentType docType = document.getDoctype(); if (docType != null) { document.removeChild(docType); //NOI18N } } } return document; }
Example 15
Source Project: teamengine File: XMLValidatingParser.java License: Apache License 2.0 | 4 votes |
/** * Validates an XML resource against a list of DTD schemas or as indicated by a * DOCTYPE declaration. Validation errors are reported to the given handler. If * no DTD references are provided the external schema reference in the DOCTYPE * declaration is used (Note: an internal subset is ignored). * * @param doc * The input Document. * @param dtdList * A list of DTD schema references. May be empty but not null. * @param errHandler * An ErrorHandler that collects validation errors. * @throws Exception * If any errors occur while attempting to validate the document. */ private void validateAgainstDTDList(Document doc, ArrayList<Object> dtdList, ErrorHandler errHandler) throws Exception { jlogger.finer("Validating XML resource from " + doc.getDocumentURI()); DocumentBuilder db = dtdValidatingDBF.newDocumentBuilder(); db.setErrorHandler(errHandler); // Fortify Mod: prevent external entity injection // includes try block to capture exceptions to setFeature. TransformerFactory tf = TransformerFactory.newInstance(); try { tf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); } catch (Exception e) { jlogger.warning("Failed to secure Transformer"); } // End Fortify Mod Transformer copier = tf.newTransformer(); ByteArrayOutputStream content = new ByteArrayOutputStream(); Result copy = new StreamResult(content); if (dtdList.isEmpty()) { DocumentType doctype = doc.getDoctype(); if (null == doctype) { return; } URI systemId = URI.create(doctype.getSystemId()); if (!systemId.isAbsolute() && null != doc.getBaseURI()) { systemId = URI.create(doc.getBaseURI()).resolve(systemId); } copier.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, systemId.toString()); copier.transform(new DOMSource(doc), copy); db.parse(new ByteArrayInputStream(content.toByteArray())); } else { for (Object dtdRef : dtdList) { content.reset(); copier.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, dtdRef.toString()); copier.transform(new DOMSource(doc), copy); db.parse(new ByteArrayInputStream(content.toByteArray())); } } }
Example 16
Source Project: jdk1.8-source-analysis File: DOM2DTM.java License: Apache License 2.0 | 4 votes |
/** * The getUnparsedEntityURI function returns the URI of the unparsed * entity with the specified name in the same document as the context * node (see [3.3 Unparsed Entities]). It returns the empty string if * there is no such entity. * <p> * XML processors may choose to use the System Identifier (if one * is provided) to resolve the entity, rather than the URI in the * Public Identifier. The details are dependent on the processor, and * we would have to support some form of plug-in resolver to handle * this properly. Currently, we simply return the System Identifier if * present, and hope that it a usable URI or that our caller can * map it to one. * TODO: Resolve Public Identifiers... or consider changing function name. * <p> * If we find a relative URI * reference, XML expects it to be resolved in terms of the base URI * of the document. The DOM doesn't do that for us, and it isn't * entirely clear whether that should be done here; currently that's * pushed up to a higher level of our application. (Note that DOM Level * 1 didn't store the document's base URI.) * TODO: Consider resolving Relative URIs. * <p> * (The DOM's statement that "An XML processor may choose to * completely expand entities before the structure model is passed * to the DOM" refers only to parsed entities, not unparsed, and hence * doesn't affect this function.) * * @param name A string containing the Entity Name of the unparsed * entity. * * @return String containing the URI of the Unparsed Entity, or an * empty string if no such entity exists. */ public String getUnparsedEntityURI(String name) { String url = ""; Document doc = (m_root.getNodeType() == Node.DOCUMENT_NODE) ? (Document) m_root : m_root.getOwnerDocument(); if (null != doc) { DocumentType doctype = doc.getDoctype(); if (null != doctype) { NamedNodeMap entities = doctype.getEntities(); if(null == entities) return url; Entity entity = (Entity) entities.getNamedItem(name); if(null == entity) return url; String notationName = entity.getNotationName(); if (null != notationName) // then it's unparsed { // The draft says: "The XSLT processor may use the public // identifier to generate a URI for the entity instead of the URI // specified in the system identifier. If the XSLT processor does // not use the public identifier to generate the URI, it must use // the system identifier; if the system identifier is a relative // URI, it must be resolved into an absolute URI using the URI of // the resource containing the entity declaration as the base // URI [RFC2396]." // So I'm falling a bit short here. url = entity.getSystemId(); if (null == url) { url = entity.getPublicId(); } else { // This should be resolved to an absolute URL, but that's hard // to do from here. } } } } return url; }
Example 17
Source Project: j2objc File: DOMHelper.java License: Apache License 2.0 | 4 votes |
/** * The getUnparsedEntityURI function returns the URI of the unparsed * entity with the specified name in the same document as the context * node (see [3.3 Unparsed Entities]). It returns the empty string if * there is no such entity. * <p> * XML processors may choose to use the System Identifier (if one * is provided) to resolve the entity, rather than the URI in the * Public Identifier. The details are dependent on the processor, and * we would have to support some form of plug-in resolver to handle * this properly. Currently, we simply return the System Identifier if * present, and hope that it a usable URI or that our caller can * map it to one. * TODO: Resolve Public Identifiers... or consider changing function name. * <p> * If we find a relative URI * reference, XML expects it to be resolved in terms of the base URI * of the document. The DOM doesn't do that for us, and it isn't * entirely clear whether that should be done here; currently that's * pushed up to a higher levelof our application. (Note that DOM Level * 1 didn't store the document's base URI.) * TODO: Consider resolving Relative URIs. * <p> * (The DOM's statement that "An XML processor may choose to * completely expand entities before the structure model is passed * to the DOM" refers only to parsed entities, not unparsed, and hence * doesn't affect this function.) * * @param name A string containing the Entity Name of the unparsed * entity. * @param doc Document node for the document to be searched. * * @return String containing the URI of the Unparsed Entity, or an * empty string if no such entity exists. */ public String getUnparsedEntityURI(String name, Document doc) { String url = ""; DocumentType doctype = doc.getDoctype(); if (null != doctype) { NamedNodeMap entities = doctype.getEntities(); if(null == entities) return url; Entity entity = (Entity) entities.getNamedItem(name); if(null == entity) return url; String notationName = entity.getNotationName(); if (null != notationName) // then it's unparsed { // The draft says: "The XSLT processor may use the public // identifier to generate a URI for the entity instead of the URI // specified in the system identifier. If the XSLT processor does // not use the public identifier to generate the URI, it must use // the system identifier; if the system identifier is a relative // URI, it must be resolved into an absolute URI using the URI of // the resource containing the entity declaration as the base // URI [RFC2396]." // So I'm falling a bit short here. url = entity.getSystemId(); if (null == url) { url = entity.getPublicId(); } else { // This should be resolved to an absolute URL, but that's hard // to do from here. } } } return url; }
Example 18
Source Project: mycore File: MCRDOMContent.java License: GNU General Public License v3.0 | 4 votes |
/** * @param dom the W3C DOM XML document to read from */ public MCRDOMContent(Document dom) { super(); this.dom = dom; super.docType = dom.getDoctype() == null ? dom.getDocumentElement().getLocalName() : dom.getDoctype().getName(); }
Example 19
Source Project: jdk8u60 File: DOMHelper.java License: GNU General Public License v2.0 | 4 votes |
/** * The getUnparsedEntityURI function returns the URI of the unparsed * entity with the specified name in the same document as the context * node (see [3.3 Unparsed Entities]). It returns the empty string if * there is no such entity. * <p> * XML processors may choose to use the System Identifier (if one * is provided) to resolve the entity, rather than the URI in the * Public Identifier. The details are dependent on the processor, and * we would have to support some form of plug-in resolver to handle * this properly. Currently, we simply return the System Identifier if * present, and hope that it a usable URI or that our caller can * map it to one. * TODO: Resolve Public Identifiers... or consider changing function name. * <p> * If we find a relative URI * reference, XML expects it to be resolved in terms of the base URI * of the document. The DOM doesn't do that for us, and it isn't * entirely clear whether that should be done here; currently that's * pushed up to a higher levelof our application. (Note that DOM Level * 1 didn't store the document's base URI.) * TODO: Consider resolving Relative URIs. * <p> * (The DOM's statement that "An XML processor may choose to * completely expand entities before the structure model is passed * to the DOM" refers only to parsed entities, not unparsed, and hence * doesn't affect this function.) * * @param name A string containing the Entity Name of the unparsed * entity. * @param doc Document node for the document to be searched. * * @return String containing the URI of the Unparsed Entity, or an * empty string if no such entity exists. */ public String getUnparsedEntityURI(String name, Document doc) { String url = ""; DocumentType doctype = doc.getDoctype(); if (null != doctype) { NamedNodeMap entities = doctype.getEntities(); if(null == entities) return url; Entity entity = (Entity) entities.getNamedItem(name); if(null == entity) return url; String notationName = entity.getNotationName(); if (null != notationName) // then it's unparsed { // The draft says: "The XSLT processor may use the public // identifier to generate a URI for the entity instead of the URI // specified in the system identifier. If the XSLT processor does // not use the public identifier to generate the URI, it must use // the system identifier; if the system identifier is a relative // URI, it must be resolved into an absolute URI using the URI of // the resource containing the entity declaration as the base // URI [RFC2396]." // So I'm falling a bit short here. url = entity.getSystemId(); if (null == url) { url = entity.getPublicId(); } else { // This should be resolved to an absolute URL, but that's hard // to do from here. } } } return url; }
Example 20
Source Project: openjdk-8-source File: DOMHelper.java License: GNU General Public License v2.0 | 4 votes |
/** * The getUnparsedEntityURI function returns the URI of the unparsed * entity with the specified name in the same document as the context * node (see [3.3 Unparsed Entities]). It returns the empty string if * there is no such entity. * <p> * XML processors may choose to use the System Identifier (if one * is provided) to resolve the entity, rather than the URI in the * Public Identifier. The details are dependent on the processor, and * we would have to support some form of plug-in resolver to handle * this properly. Currently, we simply return the System Identifier if * present, and hope that it a usable URI or that our caller can * map it to one. * TODO: Resolve Public Identifiers... or consider changing function name. * <p> * If we find a relative URI * reference, XML expects it to be resolved in terms of the base URI * of the document. The DOM doesn't do that for us, and it isn't * entirely clear whether that should be done here; currently that's * pushed up to a higher levelof our application. (Note that DOM Level * 1 didn't store the document's base URI.) * TODO: Consider resolving Relative URIs. * <p> * (The DOM's statement that "An XML processor may choose to * completely expand entities before the structure model is passed * to the DOM" refers only to parsed entities, not unparsed, and hence * doesn't affect this function.) * * @param name A string containing the Entity Name of the unparsed * entity. * @param doc Document node for the document to be searched. * * @return String containing the URI of the Unparsed Entity, or an * empty string if no such entity exists. */ public String getUnparsedEntityURI(String name, Document doc) { String url = ""; DocumentType doctype = doc.getDoctype(); if (null != doctype) { NamedNodeMap entities = doctype.getEntities(); if(null == entities) return url; Entity entity = (Entity) entities.getNamedItem(name); if(null == entity) return url; String notationName = entity.getNotationName(); if (null != notationName) // then it's unparsed { // The draft says: "The XSLT processor may use the public // identifier to generate a URI for the entity instead of the URI // specified in the system identifier. If the XSLT processor does // not use the public identifier to generate the URI, it must use // the system identifier; if the system identifier is a relative // URI, it must be resolved into an absolute URI using the URI of // the resource containing the entity declaration as the base // URI [RFC2396]." // So I'm falling a bit short here. url = entity.getSystemId(); if (null == url) { url = entity.getPublicId(); } else { // This should be resolved to an absolute URL, but that's hard // to do from here. } } } return url; }