List of usage examples for javax.xml.transform OutputKeys STANDALONE
String STANDALONE
To view the source code for javax.xml.transform OutputKeys STANDALONE.
Click Source Link
From source file:net.sf.joost.emitter.XmlEmitter.java
/** Constructor */ public XmlEmitter(Writer writer, String encoding, Properties outputProperties) { super(writer, encoding); if (outputProperties != null) { String val; val = outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION); if (val != null) propOmitXmlDeclaration = val.equals("yes"); if (!encoding.equals("UTF-8") && !encoding.equals("UTF-16")) propOmitXmlDeclaration = false; val = outputProperties.getProperty(OutputKeys.STANDALONE); if (val != null) propStandalone = val.equals("yes"); val = outputProperties.getProperty(OutputKeys.VERSION); if (val != null) propVersion = val; }/*from w w w.ja va 2s .co m*/ }
From source file:Main.java
private static Transformer getThreadedTransformer(final boolean omitXmlDeclaration, final boolean standalone, final Map<Thread, Transformer> threadMap, final String xslURL) throws TransformerConfigurationException { final Thread currentThread = Thread.currentThread(); Transformer transformer = null; if (threadMap != null) { transformer = threadMap.get(currentThread); }/* www .java2 s. c o m*/ if (transformer == null) { if (xslURL == null) { transformer = tFactory.newTransformer(); // "never null" } else { transformer = tFactory.newTransformer(new StreamSource(xslURL)); } transformer.setOutputProperty(OutputKeys.INDENT, "yes"); if (threadMap != null) { threadMap.put(currentThread, transformer); } } transformer.setOutputProperty(OutputKeys.STANDALONE, standalone ? "yes" : "no"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, omitXmlDeclaration ? "yes" : "no"); return transformer; }
From source file:net.sf.joost.trax.TransformerImpl.java
/** * Constructor// w w w .jav a 2s .co 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:de.betterform.connector.xslt.XSLTSubmissionHandler.java
/** * Serializes and submits the specified instance data over the * <code>xslt</code> protocol. * * @param submission the submission issuing the request. * @param instance the instance data to be serialized and submitted. * @return xslt transformation result.//w ww.j a v a 2 s . co m * @throws XFormsException if any error occurred during submission. */ public Map submit(Submission submission, Node instance) throws XFormsException { try { if (LOGGER.isDebugEnabled()) { LOGGER.debug("uri: " + getURI()); } URI uri = ConnectorHelper.resolve(submission.getContainerObject().getProcessor().getBaseURI(), getURI()); Map parameters = ConnectorHelper.getURLParameters(uri); URI stylesheetURI = ConnectorHelper.removeURLParameters(uri); if (LOGGER.isDebugEnabled()) { LOGGER.debug("stylesheet uri: " + stylesheetURI); } // pass output properties from submission CachingTransformerService transformerService = (CachingTransformerService) getContext() .get(TransformerService.TRANSFORMER_SERVICE); if (transformerService == null) { if (uri.getScheme().equals("http")) { transformerService = new CachingTransformerService(new HttpResourceResolver()); } else if (uri.getScheme().equals("file")) { transformerService = new CachingTransformerService(new FileResourceResolver()); } else { throw new XFormsException( "Protocol " + stylesheetURI.getScheme() + " not supported for XSLT Submission Handler"); } } if (parameters != null && parameters.get("nocache") != null) { transformerService.setNoCache(true); } Transformer transformer = transformerService.getTransformer(stylesheetURI); if (submission.getVersion() != null) { transformer.setOutputProperty(OutputKeys.VERSION, submission.getVersion()); } if (submission.getIndent() != null) { transformer.setOutputProperty(OutputKeys.INDENT, Boolean.TRUE.equals(submission.getIndent()) ? "yes" : "no"); } if (submission.getMediatype() != null) { transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, submission.getMediatype()); } if (submission.getEncoding() != null) { transformer.setOutputProperty(OutputKeys.ENCODING, submission.getEncoding()); } else { transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); } if (submission.getOmitXMLDeclaration() != null) { transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, Boolean.TRUE.equals(submission.getOmitXMLDeclaration()) ? "yes" : "no"); } if (submission.getStandalone() != null) { transformer.setOutputProperty(OutputKeys.STANDALONE, Boolean.TRUE.equals(submission.getStandalone()) ? "yes" : "no"); } if (submission.getCDATASectionElements() != null) { transformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, submission.getCDATASectionElements()); } // pass parameters form uri if any if (parameters != null) { Iterator iterator = parameters.keySet().iterator(); String name; while (iterator.hasNext()) { name = (String) iterator.next(); transformer.setParameter(name, parameters.get(name)); } } // transform instance to byte array ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); long start = System.currentTimeMillis(); DOMSource domSource; //check for 'parse' param String parseParam = null; if (parameters.containsKey("parseString")) { parseParam = (String) parameters.get("parseString"); } if (parseParam != null && parseParam.equalsIgnoreCase("true")) { String xmlString = DOMUtil.getTextNodeAsString(instance); domSource = new DOMSource(DOMUtil.parseString(xmlString, true, false)); } else { domSource = new DOMSource(instance); } transformer.transform(domSource, new StreamResult(outputStream)); long end = System.currentTimeMillis(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("transformation time: " + (end - start) + " ms"); } // create input stream from result InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); Map response = new HashMap(); response.put(XFormsProcessor.SUBMISSION_RESPONSE_STREAM, inputStream); return response; } catch (Exception e) { throw new XFormsException(e); } }
From source file:tut.pori.javadocer.Javadocer.java
/** * //from w w w. j a v a 2 s. c o m * @throws IllegalArgumentException */ public Javadocer() throws IllegalArgumentException { _restUri = System.getProperty(PROPERTY_REST_URI); if (StringUtils.isBlank(_restUri)) { throw new IllegalArgumentException("Bad " + PROPERTY_REST_URI); } try { _documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); _transformer = TransformerFactory.newInstance().newTransformer(); _transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); _transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); // because of an issue with java's transformer indent, we need to add standalone attribute _transformer.setOutputProperty(OutputKeys.METHOD, "xml"); _transformer.setOutputProperty(OutputKeys.ENCODING, CHARSET); _transformer.setOutputProperty(OutputKeys.INDENT, "yes"); _transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); } catch (ParserConfigurationException | TransformerConfigurationException | TransformerFactoryConfigurationError ex) { LOGGER.error(ex, ex); throw new IllegalArgumentException("Failed to create document builder/transformer instance."); } _xPath = XPathFactory.newInstance().newXPath(); _client = HttpClients.createDefault(); }
From source file:dicoogle.ua.dim.DIMGeneric.java
public String getXML() { StringWriter writer = new StringWriter(); StreamResult streamResult = new StreamResult(writer); SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance(); // SAX2.0 ContentHandler. TransformerHandler hd = null; try {//from w w w. j a v a2s . c o m hd = tf.newTransformerHandler(); } catch (TransformerConfigurationException ex) { Logger.getLogger(DIMGeneric.class.getName()).log(Level.SEVERE, null, ex); } Transformer serializer = hd.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); serializer.setOutputProperty(OutputKeys.METHOD, "xml"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty(OutputKeys.STANDALONE, "yes"); hd.setResult(streamResult); try { hd.startDocument(); AttributesImpl atts = new AttributesImpl(); hd.startElement("", "", "DIM", atts); for (Patient p : this.patients) { atts.clear(); atts.addAttribute("", "", "name", "", p.getPatientName().trim()); atts.addAttribute("", "", "id", "", p.getPatientID().trim()); hd.startElement("", "", "Patient", atts); for (Study s : p.getStudies()) { atts.clear(); atts.addAttribute("", "", "date", "", s.getStudyData().trim()); atts.addAttribute("", "", "id", "", s.getStudyInstanceUID().trim()); hd.startElement("", "", "Study", atts); for (Serie serie : s.getSeries()) { atts.clear(); atts.addAttribute("", "", "modality", "", serie.getModality().trim()); atts.addAttribute("", "", "id", "", serie.getSerieInstanceUID().trim()); hd.startElement("", "", "Serie", atts); ArrayList<URI> img = serie.getImageList(); ArrayList<String> uid = serie.getSOPInstanceUIDList(); int size = img.size(); for (int i = 0; i < size; i++) { atts.clear(); atts.addAttribute("", "", "path", "", img.get(i).toString().trim()); atts.addAttribute("", "", "uid", "", uid.get(i).trim()); hd.startElement("", "", "Image", atts); hd.endElement("", "", "Image"); } hd.endElement("", "", "Serie"); } hd.endElement("", "", "Study"); } hd.endElement("", "", "Patient"); } hd.endElement("", "", "DIM"); } catch (SAXException ex) { Logger.getLogger(DIMGeneric.class.getName()).log(Level.SEVERE, null, ex); } return writer.toString(); }
From source file:org.joy.config.Configuration.java
public void save() { try {/*from ww w. j av a2 s . c o m*/ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbf.newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element root = doc.createElement("configuration"); doc.appendChild(root); Element classpathEle = doc.createElement("classpath"); root.appendChild(classpathEle); for (String s : classPathEntries) { Element e = doc.createElement("entry"); e.appendChild(doc.createTextNode(s)); classpathEle.appendChild(e); } Element connectionsEle = doc.createElement("connections"); root.appendChild(connectionsEle); for (DatabaseElement d : connectionHistory) { writeDatabase(connectionsEle, d); } Element e = doc.createElement("tagertProject"); e.appendChild(doc.createTextNode(tagertProject)); root.appendChild(e); e = doc.createElement("basePackage"); e.appendChild(doc.createTextNode(basePackage)); root.appendChild(e); e = doc.createElement("moduleName"); e.appendChild(doc.createTextNode(moduleName)); root.appendChild(e); Element templatesEle = doc.createElement("templates"); root.appendChild(templatesEle); for (TemplateElement t : templates) { writeTemplate(templatesEle, t); } // Write the file DOMSource ds = new DOMSource(doc); StreamResult sr = new StreamResult(new File(configurationFile)); Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.METHOD, "xml"); t.setOutputProperty(OutputKeys.ENCODING, "utf-8"); t.setOutputProperty(OutputKeys.INDENT, "yes"); t.setOutputProperty(OutputKeys.STANDALONE, "yes"); t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); t.transform(ds, sr); } catch (Exception e) { LOGGER.info(e.getMessage(), e); } }
From source file:net.sourceforge.fullsync.fs.connection.SyncFileBufferedConnection.java
public void saveToBuffer() throws IOException { File fsRoot = fs.getRoot();//from w ww .j a v a 2 s. c om 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.legstar.cob2xsd.Cob2Xsd.java
/** * Serialize the XML Schema to a string. * <p/>//from w w w.j a v a 2 s . com * If we are provided with an XSLT customization file then we transform the * XMLSchema. * * @param xsd the XML Schema before customization * @return a string serialization of the customized XML Schema * @throws XsdGenerationException if customization fails */ public String xsdToString(final XmlSchema xsd) throws XsdGenerationException { if (_log.isDebugEnabled()) { StringWriter writer = new StringWriter(); xsd.write(writer); debug("6. Writing XML Schema: ", writer.toString()); } String errorMessage = "Customizing XML Schema failed."; try { TransformerFactory tFactory = TransformerFactory.newInstance(); try { tFactory.setAttribute("indent-number", "4"); } catch (IllegalArgumentException e) { _log.debug("Unable to set indent-number on transfomer factory", e); } StringWriter writer = new StringWriter(); Source source = new DOMSource(xsd.getAllSchemas()[0]); Result result = new StreamResult(writer); Transformer transformer; String xsltFileName = getModel().getCustomXsltFileName(); if (xsltFileName == null || xsltFileName.trim().length() == 0) { transformer = tFactory.newTransformer(); } else { Source xsltSource = new StreamSource(new File(xsltFileName)); transformer = tFactory.newTransformer(xsltSource); } transformer.setOutputProperty(OutputKeys.ENCODING, getModel().getXsdEncoding()); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.STANDALONE, "no"); transformer.transform(source, result); writer.flush(); return writer.toString(); } catch (TransformerConfigurationException e) { _log.error(errorMessage, e); throw new XsdGenerationException(e); } catch (TransformerFactoryConfigurationError e) { _log.error(errorMessage, e); throw new XsdGenerationException(e); } catch (TransformerException e) { _log.error(errorMessage, e); throw new XsdGenerationException(e); } }
From source file:com.sap.prd.mobile.ios.mios.XCodeVersionInfoMojo.java
void transformVersionsXml(File versionsXmlInBuild, File versionsXmlInApp) throws ParserConfigurationException, SAXException, IOException, TransformerFactoryConfigurationError, TransformerException, XCodeException { final InputStream transformerRule = getClass().getClassLoader() .getResourceAsStream("versionInfoCensorTransformation.xml"); if (transformerRule == null) { throw new XCodeException("Could not read transformer rule."); }/*from w w w.j a v a 2 s . c o m*/ try { final Transformer transformer = TransformerFactory.newInstance() .newTransformer(new StreamSource(transformerRule)); transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.transform(new StreamSource(versionsXmlInBuild), new StreamResult(versionsXmlInApp)); } finally { IOUtils.closeQuietly(transformerRule); } }