List of usage examples for org.w3c.dom DocumentType getPublicId
public String getPublicId();
From source file:TreeDumper2.java
private void dumpDocumentType(DocumentType node, String indent) { System.out.println(indent + "DOCUMENT_TYPE: " + node.getName()); if (node.getPublicId() != null) System.out.println(indent + " Public ID: " + node.getPublicId()); if (node.getSystemId() != null) System.out.println(indent + " System ID: " + node.getSystemId()); NamedNodeMap entities = node.getEntities(); if (entities.getLength() > 0) { for (int i = 0; i < entities.getLength(); i++) { dumpLoop(entities.item(i), indent + " "); }// w w w. j a v a 2s .c o m } NamedNodeMap notations = node.getNotations(); if (notations.getLength() > 0) { for (int i = 0; i < notations.getLength(); i++) dumpLoop(notations.item(i), indent + " "); } }
From source file:com.amalto.core.storage.hibernate.DefaultStorageClassLoader.java
protected InputStream toInputStream(Document document) throws Exception { StringWriter buffer = new StringWriter(); Transformer transformer = XMLUtils.generateTransformer(); DocumentType doctype = document.getDoctype(); if (doctype != null) { if (doctype.getPublicId() != null) { transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, doctype.getPublicId()); }/*w w w. jav a 2 s . c om*/ if (doctype.getSystemId() != null) { transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doctype.getSystemId()); } } transformer.transform(new DOMSource(document), new StreamResult(buffer)); String cnt = buffer.toString(); return new ByteArrayInputStream(cnt.getBytes("UTF-8")); //$NON-NLS-1$ }
From source file:DOMWriter.java
/** Writes the specified node, recursively. */ public void write(Node node) { // is there anything to do? if (node == null) { return;//from w w w. jav a2 s.co m } short type = node.getNodeType(); switch (type) { case Node.DOCUMENT_NODE: { Document document = (Document) node; fXML11 = "1.1".equals(getVersion(document)); if (!fCanonical) { if (fXML11) { fOut.println("<?xml version=\"1.1\" encoding=\"UTF-8\"?>"); } else { fOut.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); } fOut.flush(); write(document.getDoctype()); } write(document.getDocumentElement()); break; } case Node.DOCUMENT_TYPE_NODE: { DocumentType doctype = (DocumentType) node; fOut.print("<!DOCTYPE "); fOut.print(doctype.getName()); String publicId = doctype.getPublicId(); String systemId = doctype.getSystemId(); if (publicId != null) { fOut.print(" PUBLIC '"); fOut.print(publicId); fOut.print("' '"); fOut.print(systemId); fOut.print('\''); } else if (systemId != null) { fOut.print(" SYSTEM '"); fOut.print(systemId); fOut.print('\''); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { fOut.println(" ["); fOut.print(internalSubset); fOut.print(']'); } fOut.println('>'); break; } case Node.ELEMENT_NODE: { fOut.print('<'); fOut.print(node.getNodeName()); Attr attrs[] = sortAttributes(node.getAttributes()); for (int i = 0; i < attrs.length; i++) { Attr attr = attrs[i]; fOut.print(' '); fOut.print(attr.getNodeName()); fOut.print("=\""); normalizeAndPrint(attr.getNodeValue(), true); fOut.print('"'); } fOut.print('>'); fOut.flush(); Node child = node.getFirstChild(); while (child != null) { write(child); child = child.getNextSibling(); } break; } case Node.ENTITY_REFERENCE_NODE: { if (fCanonical) { Node child = node.getFirstChild(); while (child != null) { write(child); child = child.getNextSibling(); } } else { fOut.print('&'); fOut.print(node.getNodeName()); fOut.print(';'); fOut.flush(); } break; } case Node.CDATA_SECTION_NODE: { if (fCanonical) { normalizeAndPrint(node.getNodeValue(), false); } else { fOut.print("<![CDATA["); fOut.print(node.getNodeValue()); fOut.print("]]>"); } fOut.flush(); break; } case Node.TEXT_NODE: { normalizeAndPrint(node.getNodeValue(), false); fOut.flush(); break; } case Node.PROCESSING_INSTRUCTION_NODE: { fOut.print("<?"); fOut.print(node.getNodeName()); String data = node.getNodeValue(); if (data != null && data.length() > 0) { fOut.print(' '); fOut.print(data); } fOut.print("?>"); fOut.flush(); break; } case Node.COMMENT_NODE: { if (!fCanonical) { fOut.print("<!--"); String comment = node.getNodeValue(); if (comment != null && comment.length() > 0) { fOut.print(comment); } fOut.print("-->"); fOut.flush(); } } } if (type == Node.ELEMENT_NODE) { fOut.print("</"); fOut.print(node.getNodeName()); fOut.print('>'); fOut.flush(); } }
From source file:fr.gouv.finances.dgfip.xemelios.utils.TextWriter.java
private void documentType(Writer writer, DocumentType docType) throws IOException { writer.write("<!DOCTYPE "); writer.write(docType.getName());//from w w w . j ava 2s . co m String pubID = docType.getPublicId(); String sysID = docType.getSystemId(); if (pubID != null) { writer.write(" PUBLIC "); writer.write(pubID); if (sysID != null) { writer.write(' '); writer.write(sysID); } } else if (sysID != null) { writer.write(" SYSTEM "); writer.write(sysID); } String is = docType.getInternalSubset(); if (is != null) { writer.write(" ["); writer.write(is); writer.write("]"); } writer.write(">\n"); }
From source file:DomPrintUtil.java
/** * Returns XML text converted from the target DOM * /*from ww w. j a v a 2 s. com*/ * @return String format XML converted from the target DOM */ public String toXMLString() { StringBuffer tmpSB = new StringBuffer(8192); TreeWalkerImpl treeWalker = new TreeWalkerImpl(document, whatToShow, nodeFilter, entityReferenceExpansion); String lt = escapeTagBracket ? ESC_LT : LT; String gt = escapeTagBracket ? ESC_GT : GT; String line_sep = indent ? LINE_SEP : EMPTY_STR; Node tmpN = treeWalker.nextNode(); boolean prevIsText = false; String indentS = EMPTY_STR; while (tmpN != null) { short type = tmpN.getNodeType(); switch (type) { case Node.ELEMENT_NODE: if (prevIsText) { tmpSB.append(line_sep); } tmpSB.append(indentS + lt + tmpN.getNodeName()); NamedNodeMap attrs = tmpN.getAttributes(); int len = attrs.getLength(); for (int i = 0; i < len; i++) { Node attr = attrs.item(i); String value = attr.getNodeValue(); if (null != value) { tmpSB.append(getAttributeString((Element) tmpN, attr)); } } if (tmpN instanceof HTMLTitleElement && !tmpN.hasChildNodes()) { tmpSB.append(gt + ((HTMLTitleElement) tmpN).getText()); prevIsText = true; } else if (checkNewLine(tmpN)) { tmpSB.append(gt + line_sep); prevIsText = false; } else { tmpSB.append(gt); prevIsText = true; } break; case Node.TEXT_NODE: if (!prevIsText) { tmpSB.append(indentS); } tmpSB.append(getXMLString(tmpN.getNodeValue())); prevIsText = true; break; case Node.COMMENT_NODE: String comment; if (escapeTagBracket) { comment = getXMLString(tmpN.getNodeValue()); } else { comment = tmpN.getNodeValue(); } tmpSB.append(line_sep + indentS + lt + "!--" + comment + "--" + gt + line_sep); prevIsText = false; break; case Node.CDATA_SECTION_NODE: tmpSB.append(line_sep + indentS + lt + "!CDATA[" + tmpN.getNodeValue() + "]]" + line_sep); break; case Node.DOCUMENT_TYPE_NODE: if (tmpN instanceof DocumentType) { DocumentType docType = (DocumentType) tmpN; String pubId = docType.getPublicId(); String sysId = docType.getSystemId(); if (null != pubId && pubId.length() > 0) { if (null != sysId && sysId.length() > 0) { tmpSB.append(lt + "!DOCTYPE " + docType.getName() + " PUBLIC \"" + pubId + " \"" + sysId + "\">" + line_sep); } else { tmpSB.append( lt + "!DOCTYPE " + docType.getName() + " PUBLIC \"" + pubId + "\">" + line_sep); } } else { tmpSB.append(lt + "!DOCTYPE " + docType.getName() + " SYSTEM \"" + docType.getSystemId() + "\">" + line_sep); } } else { System.out.println("Document Type node does not implement DocumentType: " + tmpN); } break; default: System.out.println(tmpN.getNodeType() + " : " + tmpN.getNodeName()); } Node next = treeWalker.firstChild(); if (null != next) { if (indent && type == Node.ELEMENT_NODE) { indentS = indentS + " "; } tmpN = next; continue; } if (tmpN.getNodeType() == Node.ELEMENT_NODE) { tmpSB.append(lt + "/" + tmpN.getNodeName() + gt + line_sep); prevIsText = false; } next = treeWalker.nextSibling(); if (null != next) { tmpN = next; continue; } tmpN = null; next = treeWalker.parentNode(); while (null != next) { if (next.getNodeType() == Node.ELEMENT_NODE) { if (indent) { if (indentS.length() > 0) { indentS = indentS.substring(1); } else { System.err.println("indent: " + next.getNodeName() + " " + next); } } tmpSB.append(line_sep + indentS + lt + "/" + next.getNodeName() + gt + line_sep); prevIsText = false; } next = treeWalker.nextSibling(); if (null != next) { tmpN = next; break; } next = treeWalker.parentNode(); } } return tmpSB.toString(); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument.java
private boolean isQuirksDocType(final BrowserVersion browserVersion) { 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; }/*from ww w . j a v a 2s . c o m*/ 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) { if (docType.getName() != null) { return false; } return true; } } return true; }
From source file:org.apache.stratos.load.balancer.conf.configurator.SynapseConfigurator.java
/** * Write xml document to file.//from w w w . j av a2s . co m * * @param document * @param outputFilePath * @throws IOException */ private static void write(Document document, String outputFilePath) throws IOException { try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); DocumentType documentType = document.getDoctype(); if (documentType != null) { String publicId = documentType.getPublicId(); if (publicId != null) { transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, publicId); } transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, documentType.getSystemId()); } transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); Source source = new DOMSource(document); FileOutputStream outputStream = new FileOutputStream(outputFilePath); Result result = new StreamResult(outputStream); transformer.transform(source, result); } catch (Exception e) { throw new RuntimeException(String.format("Could not write xml file: s%", outputFilePath), e); } }
From source file:org.cruxframework.crux.core.declarativeui.ViewParser.java
/** * @param cruxPageDocument//w w w .j ava 2 s.co m * @return */ private Document createHTMLDocument(Document cruxPageDocument) { Document htmlDocument; DocumentType doctype = cruxPageDocument.getDoctype(); if (doctype != null || Boolean.parseBoolean(ConfigurationFactory.getConfigurations().enableGenerateHTMLDoctype())) { String name = doctype != null ? doctype.getName() : "HTML"; String publicId = doctype != null ? doctype.getPublicId() : null; String systemId = doctype != null ? doctype.getSystemId() : null; DocumentType newDoctype = documentBuilder.getDOMImplementation().createDocumentType(name, publicId, systemId); htmlDocument = documentBuilder.getDOMImplementation().createDocument(XHTML_NAMESPACE, "html", newDoctype); } else { htmlDocument = documentBuilder.newDocument(); Element cruxPageElement = cruxPageDocument.getDocumentElement(); Node htmlElement = htmlDocument.importNode(cruxPageElement, false); htmlDocument.appendChild(htmlElement); } String manifest = cruxPageDocument.getDocumentElement().getAttribute("manifest"); if (!StringUtils.isEmpty(manifest)) { htmlDocument.getDocumentElement().setAttribute("manifest", manifest); } return htmlDocument; }
From source file:org.dspace.installer_edm.InstallerEDMAskosi.java
/** * Modifica el archivo web.xml de Askosi para indicarle el directorio de datos de Askosi * * @param webXmlFile archivo web.xml de Askosi *///from www. java2 s .co m private void changeWebXml(File webXmlFile, String webXmlFileName) { try { // se abre con DOM el archivo web.xml DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(webXmlFile); XPath xpathInputForms = XPathFactory.newInstance().newXPath(); // se busca el elemento SKOSdirectory NodeList results = (NodeList) xpathInputForms.evaluate("//*[contains(*,\"SKOSdirectory\")]", doc, XPathConstants.NODESET); if (results.getLength() > 0) { Element contextParam = (Element) results.item(0); // se busca el elemento context-param como hijo del anterior if (contextParam.getTagName().equals("context-param")) { // se busca el elemento param-value como hijo del anterior NodeList resultsParamValue = contextParam.getElementsByTagName("param-value"); if (resultsParamValue.getLength() > 0) { // se modifica con la ruta del directorio de datos de Askosi Element valueParam = (Element) resultsParamValue.item(0); Text text = doc.createTextNode(finalAskosiDataDestDirFile.getAbsolutePath()); valueParam.replaceChild(text, valueParam.getFirstChild()); // se guarda TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); DocumentType docType = doc.getDoctype(); if (docType != null) { if (docType.getPublicId() != null) transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, docType.getPublicId()); transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, docType.getSystemId()); } DOMSource source = new DOMSource(doc); StreamResult result = (fileSeparator.equals("\\")) ? new StreamResult(webXmlFileName) : new StreamResult(webXmlFile); transformer.transform(source, result); } } } else installerEDMDisplay.showQuestion(currentStepGlobal, "changeWebXml.noSKOSdirectory", new String[] { webXmlFile.getAbsolutePath() }); } catch (ParserConfigurationException e) { showException(e); } catch (SAXException e) { showException(e); } catch (IOException e) { showException(e); } catch (XPathExpressionException e) { showException(e); } catch (TransformerConfigurationException e) { showException(e); } catch (TransformerException e) { showException(e); } }