List of usage examples for javax.xml.transform OutputKeys VERSION
String VERSION
To view the source code for javax.xml.transform OutputKeys VERSION.
Click Source Link
From source file:net.sf.joost.trax.TransformerImpl.java
/** * Constructor//from www . ja v a2 s .c o m * * @param processor A <code>Processor</code> object. */ protected TransformerImpl(Processor processor) { this.processor = processor; // set tracing manager on processor object if (processor instanceof DebugProcessor) { DebugProcessor dbp = (DebugProcessor) processor; dbp.setTraceManager(traceManager); dbp.setTransformer(this); Emitter emitter = processor.getEmitter(); if (emitter instanceof DebugEmitter) { ((DebugEmitter) emitter).setTraceManager(traceManager); } } supportedProperties.add(OutputKeys.ENCODING); supportedProperties.add(OutputKeys.MEDIA_TYPE); supportedProperties.add(OutputKeys.METHOD); supportedProperties.add(OutputKeys.OMIT_XML_DECLARATION); supportedProperties.add(OutputKeys.STANDALONE); supportedProperties.add(OutputKeys.VERSION); supportedProperties.add(TrAXConstants.OUTPUT_KEY_SUPPORT_DISABLE_OUTPUT_ESCAPING); ignoredProperties.add(OutputKeys.CDATA_SECTION_ELEMENTS); ignoredProperties.add(OutputKeys.DOCTYPE_PUBLIC); ignoredProperties.add(OutputKeys.DOCTYPE_SYSTEM); ignoredProperties.add(OutputKeys.INDENT); }
From source file:com.alfaariss.oa.util.configuration.handler.file.FileConfigurationHandler.java
/** * Save the configuration to the file.//from w w w. j av a2s . c o m * @see IConfigurationHandler#saveConfiguration(org.w3c.dom.Document) */ public void saveConfiguration(Document oConfigurationDocument) throws ConfigurationException { OutputStream os = null; try { os = new FileOutputStream(_fConfig); //create output format which uses new lines and tabs Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.VERSION, "1.0"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(oConfigurationDocument), new StreamResult(os)); } catch (FileNotFoundException e) { _logger.error("Error writing configuration, file not found", e); throw new ConfigurationException(SystemErrors.ERROR_RESOURCE_CONNECT); } catch (TransformerException e) { _logger.error("Error while transforming document", e); throw new ConfigurationException(SystemErrors.ERROR_CONFIG_WRITE); } finally { try { if (os != null) os.close(); } catch (IOException e) { _logger.debug("Error closing configuration outputstream", e); } } }
From source file:com.krawler.portal.tools.ServiceBuilder.java
public void createBusinessProcessforCRUD(String classname, String companyid) { try {/*from w w w.j av a 2 s .com*/ 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. */// w w w .ja v a2 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:org.alloy.metal.xml.merge.MergeContext.java
/** * Merge 2 xml document streams together into a final resulting stream. During * the merge, various merge business rules are followed based on configuration * defined for various merge points.// w ww. jav a 2 s .c o m * * @param stream1 * @param stream2 * @return the stream representing the merged document * @throws org.broadleafcommerce.common.extensibility.context.merge.exceptions.MergeException */ public ResourceInputStream merge(ResourceInputStream stream1, ResourceInputStream stream2) throws MergeException { try { Document doc1 = builder.parse(stream1); Document doc2 = builder.parse(stream2); List<Node> exhaustedNodes = new ArrayList<Node>(); // process any defined handlers for (MergeHandler handler : this.handlers) { if (LOG.isDebugEnabled()) { LOG.debug("Processing handler: " + handler.getXPath()); } MergePoint point = new MergePoint(handler, doc1, doc2); List<Node> list = point.merge(exhaustedNodes); exhaustedNodes.addAll(list); } TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer xmlTransformer = tFactory.newTransformer(); xmlTransformer.setOutputProperty(OutputKeys.VERSION, "1.0"); xmlTransformer.setOutputProperty(OutputKeys.ENCODING, _String.CHARACTER_ENCODING.toString()); xmlTransformer.setOutputProperty(OutputKeys.METHOD, "xml"); xmlTransformer.setOutputProperty(OutputKeys.INDENT, "yes"); if (doc1.getDoctype() != null && doc1.getDoctype().getSystemId() != null) { xmlTransformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc1.getDoctype().getSystemId()); } DOMSource source = new DOMSource(doc1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(baos)); StreamResult result = new StreamResult(writer); xmlTransformer.transform(source, result); byte[] itemArray = baos.toByteArray(); return new ResourceInputStream(new ByteArrayInputStream(itemArray), stream2.getName(), stream1.getNames()); } catch (Exception e) { throw new MergeException(e); } }
From source file:com.alfaariss.oa.util.configuration.handler.jdbc.JDBCConfigurationHandler.java
/** * Saves the database configuration using the update query. * @see IConfigurationHandler#saveConfiguration(org.w3c.dom.Document) *//*from w w w . j av a 2 s. c om*/ public void saveConfiguration(Document oConfigurationDocument) throws ConfigurationException { Connection oConnection = null; OutputStream os = null; PreparedStatement ps = null; try { os = new ByteArrayOutputStream(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.VERSION, "1.0"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(oConfigurationDocument), new StreamResult(os)); //Save to DB oConnection = _oDataSource.getConnection(); ps = oConnection.prepareStatement(_sUpdateQuery); ps.setString(1, os.toString()); ps.setString(2, _sConfigId); ps.executeUpdate(); } catch (SQLException e) { _logger.error("Database error while writing configuration, SQL eror", e); throw new ConfigurationException(SystemErrors.ERROR_CONFIG_WRITE); } catch (TransformerException e) { _logger.error("Error while transforming document", e); throw new ConfigurationException(SystemErrors.ERROR_CONFIG_WRITE); } catch (Exception e) { _logger.error("Internal error during during configuration save", e); throw new ConfigurationException(SystemErrors.ERROR_CONFIG_WRITE); } finally { try { if (os != null) os.close(); } catch (IOException e) { _logger.debug("Error closing configuration outputstream", e); } try { if (ps != null) ps.close(); } catch (SQLException e) { _logger.debug("Error closing statement", e); } try { if (oConnection != null) oConnection.close(); } catch (SQLException e) { _logger.debug("Error closing connection", e); } } }
From source file:com.krawler.portal.tools.ServiceBuilder.java
public void createModuleDef(com.krawler.utils.json.base.JSONArray jsonData, String classname) { String result = ""; try {//from ww 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:net.sourceforge.fullsync.fs.connection.SyncFileBufferedConnection.java
public void saveToBuffer() throws IOException { File fsRoot = fs.getRoot();/*from w ww.java 2 s . co m*/ File node = fsRoot.getChild(BUFFER_FILENAME); if ((null == node) || !node.exists()) { node = root.createChild(BUFFER_FILENAME, false); } try { DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element e = doc.createElement(ELEMENT_SYNC_FILES); e.appendChild(serializeFile(root, doc)); doc.appendChild(e); TransformerFactory fac = TransformerFactory.newInstance(); fac.setAttribute("indent-number", 2); //$NON-NLS-1$ Transformer tf = fac.newTransformer(); tf.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ tf.setOutputProperty(OutputKeys.VERSION, "1.0"); //$NON-NLS-1$ tf.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ tf.setOutputProperty(OutputKeys.STANDALONE, "no"); //$NON-NLS-1$ DOMSource source = new DOMSource(doc); try (OutputStreamWriter osw = new OutputStreamWriter(new GZIPOutputStream(node.getOutputStream()), StandardCharsets.UTF_8)) { tf.transform(source, new StreamResult(osw)); osw.flush(); } } catch (IOException | ParserConfigurationException | FactoryConfigurationError | TransformerException e) { ExceptionHandler.reportException(e); } }
From source file:com.krawler.portal.tools.ServiceBuilder.java
public void createModuleDef(ArrayList list, String classname) { String result = ""; try {//from www .j ava 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 < 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.granule.json.utils.XML.java
/** * Method to do the transform from an JSON input stream to a XML stream. * Neither input nor output streams are closed. Closure is left up to the caller. * * @param JSONStream The XML stream to convert to JSON * @param XMLStream The stream to write out JSON to. The contents written to this stream are always in UTF-8 format. * @param verbose Flag to denote whether or not to render the XML text in verbose (indented easy to read), or compact (not so easy to read, but smaller), format. * * @throws IOException Thrown if an IO error occurs. *///from w ww . j a v a2 s .c o m public static void toXml(InputStream JSONStream, OutputStream XMLStream, boolean verbose) throws IOException { if (logger.isLoggable(Level.FINER)) { logger.entering(className, "toXml(InputStream, OutputStream)"); } if (XMLStream == null) { throw new NullPointerException("XMLStream cannot be null"); } else if (JSONStream == null) { throw new NullPointerException("JSONStream cannot be null"); } else { if (logger.isLoggable(Level.FINEST)) { logger.logp(Level.FINEST, className, "transform", "Parsing the JSON and a DOM builder."); } try { //Get the JSON from the stream. JSONObject jObject = new JSONObject(JSONStream); //Create a new document DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbf.newDocumentBuilder(); Document doc = dBuilder.newDocument(); if (logger.isLoggable(Level.FINEST)) { logger.logp(Level.FINEST, className, "transform", "Parsing the JSON content to XML"); } convertJSONObject(doc, doc.getDocumentElement(), jObject, "jsonObject"); //Serialize it. TransformerFactory tfactory = TransformerFactory.newInstance(); Transformer serializer = null; if (verbose) { serializer = tfactory.newTransformer(new StreamSource(new StringReader(styleSheet))); ; } else { serializer = tfactory.newTransformer(); } Properties oprops = new Properties(); oprops.put(OutputKeys.METHOD, "xml"); oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes"); oprops.put(OutputKeys.VERSION, "1.0"); oprops.put(OutputKeys.INDENT, "true"); serializer.setOutputProperties(oprops); serializer.transform(new DOMSource(doc), new StreamResult(XMLStream)); } catch (Exception ex) { IOException iox = new IOException("Problem during conversion"); iox.initCause(ex); throw iox; } } if (logger.isLoggable(Level.FINER)) { logger.exiting(className, "toXml(InputStream, OutputStream)"); } }