List of usage examples for javax.xml.transform OutputKeys DOCTYPE_PUBLIC
String DOCTYPE_PUBLIC
To view the source code for javax.xml.transform OutputKeys DOCTYPE_PUBLIC.
Click Source Link
From source file:com.krawler.portal.tools.ServiceBuilder.java
public void createBusinessProcessforCRUD(String classname, String companyid) { try {/*from w w w. j a va2 s . c o m*/ DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document doc = docBuilder.parse(new ClassPathResource("logic/businesslogicEx.xml").getFile()); //Document doc = docBuilder.newDocument(); NodeList businessrules = doc.getElementsByTagName("businessrules"); Node businessruleNode = businessrules.item(0); Element processEx = doc.getElementById(classname + "_addNew"); if (processEx != null) { businessruleNode.removeChild(processEx); } processEx = doc.getElementById(classname + "_delete"); if (processEx != null) { businessruleNode.removeChild(processEx); } processEx = doc.getElementById(classname + "_edit"); if (processEx != null) { businessruleNode.removeChild(processEx); } Element process = createBasicProcessNode(doc, classname, "createNewRecord", "_addNew", "createNew"); businessruleNode.appendChild(process); process = createBasicProcessNode(doc, classname, "deleteRecord", "_delete", "deleteRec"); businessruleNode.appendChild(process); process = createBasicProcessNode(doc, classname, "editRecord", "_edit", "editRec"); businessruleNode.appendChild(process); TransformerFactory transfac = TransformerFactory.newInstance(); Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); trans.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//KRAWLER//DTD BUSINESSRULES//EN"); trans.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://192.168.0.4/dtds/businesslogicEx.dtd"); trans.setOutputProperty(OutputKeys.VERSION, "1.0"); trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // create string from xml tree File outputFile = (new ClassPathResource("logic/businesslogicEx.xml").getFile()); outputFile.setWritable(true); // StringWriter sw = new StringWriter(); StreamResult sresult = new StreamResult(outputFile); DOMSource source = new DOMSource(doc); trans.transform(source, sresult); } catch (TransformerException ex) { logger.warn(ex.getMessage(), ex); } catch (SAXException ex) { logger.warn(ex.getMessage(), ex); } catch (IOException ex) { logger.warn(ex.getMessage(), ex); } catch (ParserConfigurationException ex) { logger.warn(ex.getMessage(), ex); } }
From source file:com.google.visualization.datasource.render.HtmlRenderer.java
/** * Transforms a document to a valid html string. * * @param document The document to transform * * @return A string representation of a valid html. *//*from w w w .ja v a 2 s .c o m*/ private static String transformDocumentToHtmlString(Document document) { // Generate a CharSequence from the xml document. Transformer transformer = null; try { transformer = TransformerFactory.newInstance().newTransformer(); } catch (TransformerConfigurationException e) { log.error("Couldn't create a transformer", e); throw new RuntimeException("Couldn't create a transformer. This should never happen.", e); } transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//W3C//DTD HTML 4.01//EN"); transformer.setOutputProperty(OutputKeys.METHOD, "html"); transformer.setOutputProperty(OutputKeys.VERSION, "4.01"); DOMSource source = new DOMSource(document); Writer writer = new StringWriter(); StreamResult result = new StreamResult(writer); try { transformer.transform(source, result); } catch (TransformerException e) { log.error("Couldn't transform", e); throw new RuntimeException("Couldn't transform. This should never happen.", e); } return writer.toString(); }
From source file:com.krawler.portal.tools.ServiceBuilder.java
public void createModuleDef(com.krawler.utils.json.base.JSONArray jsonData, String classname) { String result = ""; try {/* w w w .j a v a 2 s .c o m*/ DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document doc = docBuilder.parse((new ClassPathResource("logic/moduleEx.xml").getFile())); //Document doc = docBuilder.newDocument(); NodeList modules = doc.getElementsByTagName("modules"); Node modulesNode = modules.item(0); Element module_ex = doc.getElementById(classname); if (module_ex != null) { modulesNode.removeChild(module_ex); } Element module = doc.createElement("module"); Element property_list = doc.createElement("property-list"); module.setAttribute("class", "com.krawler.esp.hibernate.impl." + classname); module.setAttribute("type", "pojo"); module.setAttribute("id", classname); for (int cnt = 0; cnt < jsonData.length(); cnt++) { Element propertyNode = doc.createElement("property"); JSONObject jsonObj = jsonData.optJSONObject(cnt); propertyNode.setAttribute("name", jsonObj.optString("varname")); propertyNode.setAttribute("type", jsonObj.optString("modulename").toLowerCase()); property_list.appendChild(propertyNode); } module.appendChild(property_list); modulesNode.appendChild(module); TransformerFactory transfac = TransformerFactory.newInstance(); Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); trans.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//KRAWLER//DTD BUSINESSRULES//EN"); trans.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://localhost/dtds/module.dtd"); trans.setOutputProperty(OutputKeys.VERSION, "1.0"); trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // create string from xml tree File outputFile = (new ClassPathResource("logic/moduleEx.xml").getFile()); outputFile.setWritable(true); // StringWriter sw = new StringWriter(); StreamResult sresult = new StreamResult(outputFile); DOMSource source = new DOMSource(doc); trans.transform(source, sresult); // result = sw.toString(); } catch (SAXException ex) { logger.warn(ex.getMessage(), ex); } catch (IOException ex) { logger.warn(ex.getMessage(), ex); } catch (TransformerException ex) { logger.warn(ex.getMessage(), ex); } catch (ParserConfigurationException ex) { logger.warn(ex.getMessage(), ex); } }
From source file:com.krawler.portal.tools.ServiceBuilder.java
public void createModuleDef(ArrayList list, String classname) { String result = ""; try {/*w w w .j a v a 2s. c om*/ DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document doc = docBuilder.parse((new ClassPathResource("logic/moduleEx.xml").getFile())); //Document doc = docBuilder.newDocument(); NodeList modules = doc.getElementsByTagName("modules"); Node modulesNode = modules.item(0); Element module_ex = doc.getElementById(classname); if (module_ex != null) { modulesNode.removeChild(module_ex); } Element module = doc.createElement("module"); Element property_list = doc.createElement("property-list"); module.setAttribute("class", "com.krawler.esp.hibernate.impl." + classname); module.setAttribute("type", "pojo"); module.setAttribute("id", classname); for (int cnt = 0; cnt < list.size(); cnt++) { Element propertyNode = doc.createElement("property"); Hashtable mapObj = (Hashtable) list.get(cnt); propertyNode.setAttribute("name", mapObj.get("name").toString()); propertyNode.setAttribute("type", mapObj.get("type").toString().toLowerCase()); property_list.appendChild(propertyNode); } module.appendChild(property_list); modulesNode.appendChild(module); TransformerFactory transfac = TransformerFactory.newInstance(); Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); trans.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//KRAWLER//DTD BUSINESSRULES//EN"); trans.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://192.168.0.4/dtds/module.dtd"); trans.setOutputProperty(OutputKeys.VERSION, "1.0"); trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // create string from xml tree File outputFile = (new ClassPathResource("logic/moduleEx.xml").getFile()); outputFile.setWritable(true); // StringWriter sw = new StringWriter(); StreamResult sresult = new StreamResult(outputFile); DOMSource source = new DOMSource(doc); trans.transform(source, sresult); // result = sw.toString(); } catch (SAXException ex) { logger.warn(ex.getMessage(), ex); } catch (IOException ex) { logger.warn(ex.getMessage(), ex); } catch (TransformerException ex) { logger.warn(ex.getMessage(), ex); } catch (ParserConfigurationException ex) { logger.warn(ex.getMessage(), ex); } finally { // System.out.println(result); // return result; } }
From source file:com.aurel.track.report.datasource.faqs.FaqsDatasource.java
/** * @param items/* w w w . j a v a 2s. c om*/ * @return */ public static void convertToXml(OutputStream outputStream, Document dom) { Transformer transformer = null; try { TransformerFactory factory = TransformerFactory.newInstance(); transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//W3C//DTD XHTML 1.0 Transitional//EN"); transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"); } catch (TransformerConfigurationException e) { LOGGER.error( "Creating the transformer failed with TransformerConfigurationException: " + e.getMessage()); return; } try { transformer.transform(new DOMSource(dom), new StreamResult(outputStream)); } catch (TransformerException e) { LOGGER.error("Transform failed with TransformerException: " + e.getMessage()); } }
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()); }/*from w w w . j a v a 2 s . c o m*/ 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:com.krawler.portal.tools.ServiceBuilder.java
public void createServiceXMLFile(com.krawler.utils.json.base.JSONArray jsonData, String tableName) { try {//from w ww . j a va2 s . co m String filename = PropsValues.GENERATE_DIR_PATH + "service.xml"; File destPath = new File(filename); destPath.createNewFile(); // Creation of an XML document DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); DOMImplementation di = db.getDOMImplementation(); Document doc = di.createDocument(null, "service-builder", null); Element root = doc.getDocumentElement(); root.setAttribute("package-path", "com.krawler.esp.hibernate.impl"); Element classEl = doc.createElement("entity"); classEl.setAttribute("name", tableName); classEl.setAttribute("local-service", "true"); classEl.setAttribute("remote-service", "true"); root.appendChild(classEl); Element el = null; for (int i = 0; i < jsonData.length(); i++) { el = doc.createElement("column"); JSONObject jobj = jsonData.optJSONObject(i); el.setAttribute("name", jobj.optString("varname")); el.setAttribute("type", jobj.optString("modulename")); // if(!jsonData.get(i).get("default").toString().equals("")){ // el.setAttribute("default",columnInfo.get(i).get("default").toString()); // } if (jobj.has("primaryid")) { el.setAttribute("primary", "true"); } if (jobj.has("foreignid")) { el.setAttribute("foreign", "true"); el.setAttribute("class", jobj.get("reftable").toString()); } classEl.appendChild(el); } // output of the XML document DOMSource ds = new DOMSource(doc); StreamResult sr = new StreamResult(destPath); TransformerFactory tf = TransformerFactory.newInstance(); Transformer trans = tf.newTransformer(); trans.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"); trans.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//Hibernate/Hibernate Mapping DTD 3.0//EN"); trans.transform(ds, sr); } catch (Exception e) { logger.warn(e.getMessage(), e); } }
From source file:ambit.data.qmrf.QMRFObject.java
protected void write(Document doc, Writer out) throws Exception { Source source;/* www . j av a 2s. c o m*/ try { DOMResult result = transform_help(doc, false); Document newdoc = (Document) result.getNode(); newdoc.normalize(); source = new DOMSource(newdoc); } catch (Exception x) { source = new DOMSource(doc); } Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, dtdSchema); xformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "qmrf.dtd"); xformer.setOutputProperty(OutputKeys.INDENT, "Yes"); xformer.setOutputProperty(OutputKeys.STANDALONE, "No"); Result result = new StreamResult(out); xformer.transform(source, result); out.flush(); setNotModified(); fireAmbitObjectEvent(); }
From source file:com.krawler.portal.tools.ServiceBuilder.java
public void createServiceXMLFile(ArrayList<Hashtable<String, Object>> columnInfo, String tableName) { try {//from w w w.ja v a2s. c om String filename = PropsValues.GENERATE_DIR_PATH + "service.xml"; File destPath = new File(filename); destPath.createNewFile(); // Creation of an XML document DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); DOMImplementation di = db.getDOMImplementation(); Document doc = di.createDocument(null, "service-builder", null); Element root = doc.getDocumentElement(); root.setAttribute("package-path", "com.krawler.esp.hibernate.impl"); Element classEl = doc.createElement("entity"); classEl.setAttribute("name", tableName); classEl.setAttribute("local-service", "true"); classEl.setAttribute("remote-service", "true"); root.appendChild(classEl); Element el = null; int count = columnInfo.size() - 1; for (int i = count; i >= 0; i--) { el = doc.createElement("column"); el.setAttribute("name", columnInfo.get(i).get("name").toString()); el.setAttribute("type", columnInfo.get(i).get("type").toString()); if (!columnInfo.get(i).get("default").toString().equals("")) { el.setAttribute("default", columnInfo.get(i).get("default").toString()); } if (columnInfo.get(i).containsKey("primaryid")) { el.setAttribute("primary", "true"); } if (columnInfo.get(i).containsKey("foreignid") && Boolean.parseBoolean(columnInfo.get(i).get("foreignid").toString())) { el.setAttribute("foreign", "true"); el.setAttribute("class", columnInfo.get(i).get("reftable").toString()); } classEl.appendChild(el); } // output of the XML document DOMSource ds = new DOMSource(doc); StreamResult sr = new StreamResult(destPath); TransformerFactory tf = TransformerFactory.newInstance(); Transformer trans = tf.newTransformer(); trans.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"); trans.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//Hibernate/Hibernate Mapping DTD 3.0//EN"); trans.transform(ds, sr); } catch (Exception e) { logger.warn(e.getMessage(), e); } }
From source file:jef.tools.XMLUtils.java
private static void output(Node node, StreamResult sr, String encoding, int indent, Boolean XmlDeclarion) throws IOException { if (node.getNodeType() == Node.ATTRIBUTE_NODE) { sr.getWriter().write(node.getNodeValue()); sr.getWriter().flush();/* w ww. j a va 2 s . c om*/ return; } TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = null; try { if (indent > 0) { try { tf.setAttribute("indent-number", indent); t = tf.newTransformer(); // ?XML??XML? t.setOutputProperty(OutputKeys.INDENT, "yes"); } catch (Exception e) { } } else { t = tf.newTransformer(); } t.setOutputProperty(OutputKeys.METHOD, "xml"); if (encoding != null) { t.setOutputProperty(OutputKeys.ENCODING, encoding); } if (XmlDeclarion == null) { XmlDeclarion = (node instanceof Document); } if (node instanceof Document) { Document doc = (Document) node; if (doc.getDoctype() != null) { t.setOutputProperty(javax.xml.transform.OutputKeys.DOCTYPE_PUBLIC, doc.getDoctype().getPublicId()); t.setOutputProperty(javax.xml.transform.OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId()); } } if (XmlDeclarion) { t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); } else { t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); } } catch (Exception tce) { throw new IOException(tce); } DOMSource doms = new DOMSource(node); try { t.transform(doms, sr); } catch (TransformerException te) { IOException ioe = new IOException(); ioe.initCause(te); throw ioe; } }