Java Code Examples for javax.xml.transform.OutputKeys
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project eclipse-integration-cloudfoundry, under directory /org.cloudfoundry.ide.eclipse.server.tests/src/org/cloudfoundry/ide/eclipse/server/tests/sts/util/.
Source file: StsTestUtil.java

public static String canocalizeXml(String originalServerXml) throws Exception { DocumentBuilderFactory documentBuilderFactory=DocumentBuilderFactory.newInstance(); DocumentBuilder builder=documentBuilderFactory.newDocumentBuilder(); Document document=builder.parse(new InputSource(new StringReader(originalServerXml))); document.normalize(); TransformerFactory factory=TransformerFactory.newInstance(); Transformer transformer=factory.newTransformer(); StringWriter writer=new StringWriter(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.transform(new DOMSource(document.getDocumentElement()),new StreamResult(writer)); return writer.toString().replace("\\s+\\n","\\n"); }
Example 2
From project CampusLifePortlets, under directory /src/main/java/org/jasig/portlet/campuslife/dao/.
Source file: ScreenScrapingService.java

/** * Get portlet-specific XML for clean, valid HTML. * @param cleanHtml * @return * @throws TransformerException * @throws IOException */ protected String getXml(String cleanHtml) throws TransformerException, IOException { final StreamSource xsltSource=new StreamSource(xslt.getInputStream()); final Transformer identityTransformer=transformerFactory.newTransformer(xsltSource); identityTransformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); final StringWriter outputWriter=new StringWriter(); final StreamResult outputTarget=new StreamResult(outputWriter); final StreamSource xmlSource=new StreamSource(new StringReader(cleanHtml)); identityTransformer.transform(xmlSource,outputTarget); final String content=outputWriter.toString(); return content; }
Example 3
From project eclim, under directory /org.eclim.core/java/org/eclim/plugin/core/command/xml/.
Source file: FormatCommand.java

/** * {@inheritDoc} */ public Object execute(CommandLine commandLine) throws Exception { String restoreNewline=null; FileInputStream in=null; try { String file=commandLine.getValue(Options.FILE_OPTION); int indent=commandLine.getIntValue(Options.INDENT_OPTION); String format=commandLine.getValue("m"); String newline=System.getProperty("line.separator"); if (newline.equals("\r\n") && format.equals("unix")) { restoreNewline=newline; System.setProperty("line.separator","\n"); } else if (newline.equals("\n") && format.equals("dos")) { restoreNewline=newline; System.setProperty("line.separator","\r\n"); } TransformerFactory factory=TransformerFactory.newInstance(); factory.setAttribute("indent-number",Integer.valueOf(indent)); Transformer serializer=factory.newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); StringWriter out=new StringWriter(); in=new FileInputStream(file); serializer.transform(new SAXSource(new InputSource(in)),new StreamResult(out)); return out.toString(); } finally { IOUtils.closeQuietly(in); if (restoreNewline != null) { System.setProperty("line.separator",restoreNewline); } } }
Example 4
From project Flapi, under directory /src/test/java/unquietcode/tools/flapi/examples/xhtml/.
Source file: XHTMLBuilderExample.java

private void printDocument(Document doc){ try { Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputPropertiesFactory.S_KEY_INDENT_AMOUNT,"4"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); System.out.println(); transformer.transform(new DOMSource(doc),new StreamResult(System.out)); } catch ( Exception ex) { throw new RuntimeException(ex); } }
Example 5
From project usergrid-stack, under directory /tools/src/main/java/org/usergrid/tools/.
Source file: ApiDoc.java

public void output(ApiListing listing,String section) throws IOException, TransformerException { Document doc=listing.createWADLApplication(); TransformerFactory transformerFactory=TransformerFactory.newInstance(); transformerFactory.setAttribute("indent-number",4); Transformer transformer=transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4"); DOMSource source=new DOMSource(doc); StreamResult result=new StreamResult(new File(section + ".wadl")); transformer.transform(source,result); File file=new File(section + ".json"); listing.setBasePath("${basePath}"); FileUtils.write(file,JsonUtils.mapToFormattedJsonString(listing)); }
Example 6
From project Activiti-KickStart, under directory /activiti-kickstart-java/src/main/java/org/activiti/kickstart/service/alfresco/.
Source file: AlfrescoKickstartServiceImpl.java

protected void prettyLogXml(String xml){ try { Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); Source xmlInput=new StreamSource(new StringReader(xml)); StreamResult xmlOutput=new StreamResult(new StringWriter()); transformer.transform(xmlInput,xmlOutput); LOGGER.info(xmlOutput.getWriter().toString()); } catch ( Exception e) { e.printStackTrace(); } }
Example 7
From project any23, under directory /core/src/main/java/org/apache/any23/extractor/html/.
Source file: DomUtils.java

/** * Given a <i>DOM</i> {@link Node} produces the <i>XML</i> serializationomitting the <i>XML declaration</i>. * @param node node to be serialized. * @param indent if <code>true</code> the output is indented. * @return the XML serialization. * @throws TransformerException if an error occurs during theserializator initialization and activation. * @throws java.io.IOException */ public static String serializeToXML(Node node,boolean indent) throws TransformerException, IOException { final DOMSource domSource=new DOMSource(node); final Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); transformer.setOutputProperty(OutputKeys.METHOD,"xml"); transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); if (indent) { transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4"); } final StringWriter sw=new StringWriter(); final StreamResult sr=new StreamResult(sw); transformer.transform(domSource,sr); sw.close(); return sw.toString(); }
Example 8
From project autopsy, under directory /Core/src/org/sleuthkit/autopsy/coreutils/.
Source file: XMLUtil.java

/** * Saves XML files to disk * @param clazz the class this method is invoked from * @param xmlPath the full path to save the XML to * @param encoding to encoding, such as "UTF-8", to encode the file with * @param doc the document to save */ public static boolean saveDoc(Class clazz,String xmlPath,String encoding,final Document doc){ TransformerFactory xf=TransformerFactory.newInstance(); xf.setAttribute("indent-number",new Integer(1)); boolean success=false; try { Transformer xformer=xf.newTransformer(); xformer.setOutputProperty(OutputKeys.METHOD,"xml"); xformer.setOutputProperty(OutputKeys.INDENT,"yes"); xformer.setOutputProperty(OutputKeys.ENCODING,encoding); xformer.setOutputProperty(OutputKeys.STANDALONE,"yes"); xformer.setOutputProperty(OutputKeys.VERSION,"1.0"); File file=new File(xmlPath); FileOutputStream stream=new FileOutputStream(file); Result out=new StreamResult(new OutputStreamWriter(stream,encoding)); xformer.transform(new DOMSource(doc),out); stream.flush(); stream.close(); success=true; } catch ( UnsupportedEncodingException e) { Logger.getLogger(clazz.getName()).log(Level.SEVERE,"Should not happen",e); } catch ( TransformerConfigurationException e) { Logger.getLogger(clazz.getName()).log(Level.SEVERE,"Error writing XML file",e); } catch ( TransformerException e) { Logger.getLogger(clazz.getName()).log(Level.SEVERE,"Error writing XML file",e); } catch ( FileNotFoundException e) { Logger.getLogger(clazz.getName()).log(Level.SEVERE,"Error writing XML file: cannot write to file: " + xmlPath,e); } catch ( IOException e) { Logger.getLogger(clazz.getName()).log(Level.SEVERE,"Error writing XML file: cannot write to file: " + xmlPath,e); } return success; }
Example 9
From project blacktie, under directory /blacktie-admin-services/src/main/java/org/jboss/narayana/blacktie/administration/.
Source file: BlacktieStompAdministrationService.java

String printNode(Node node){ try { TransformerFactory transfac=TransformerFactory.newInstance(); Transformer trans=transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); trans.setOutputProperty(OutputKeys.INDENT,"yes"); StringWriter sw=new StringWriter(); StreamResult result=new StreamResult(sw); DOMSource source=new DOMSource(node); trans.transform(source,result); String xmlString=sw.toString(); return xmlString; } catch ( TransformerException e) { log.error(e); } return null; }
Example 10
From project bpelunit, under directory /net.bpelunit.framework/src/main/java/net/bpelunit/framework/control/util/.
Source file: BPELUnitUtil.java

private static String serializeXML(Node node) throws TransformerException { TransformerFactory tf=TransformerFactory.newInstance(); Transformer t=tf.newTransformer(); t.setOutputProperty(OutputKeys.INDENT,"yes"); t.setOutputProperty(OutputKeys.METHOD,"xml"); ByteArrayOutputStream bOS=new ByteArrayOutputStream(); t.transform(new DOMSource(node),new StreamResult(bOS)); return bOS.toString(); }
Example 11
From project Carolina-Digital-Repository, under directory /metadata/src/main/java/edu/unc/lib/dl/util/.
Source file: SOAPUtil.java

private static void print(SOAPMessage msg,StreamResult result){ try { TransformerFactory transformerFactory=TransformerFactory.newInstance(); Transformer transformer=transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); Source sourceContent=msg.getSOAPPart().getContent(); transformer.transform(sourceContent,result); } catch ( TransformerException e) { throw new RuntimeException(e); } catch ( SOAPException e) { throw new RuntimeException(e); } }
Example 12
From project cascading, under directory /src/xml/cascading/operation/xml/.
Source file: XPathOperation.java

/** * Method getTransformer returns the transformer of this XPathOperation object. * @return the transformer (type Transformer) of this XPathOperation object. * @throws TransformerConfigurationException when */ public Transformer getTransformer() throws TransformerConfigurationException { if (transformer != null) return transformer; transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); return transformer; }
Example 13
From project chromattic, under directory /metamodel/src/main/java/org/chromattic/metamodel/typegen/.
Source file: XMLNodeTypeSerializer.java

@Override public void writeTo(Writer writer) throws Exception { SAXTransformerFactory factory=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); TransformerHandler handler=factory.newTransformerHandler(); handler.getTransformer().setOutputProperty(OutputKeys.METHOD,"xml"); handler.getTransformer().setOutputProperty(OutputKeys.ENCODING,"UTF-8"); handler.getTransformer().setOutputProperty(OutputKeys.INDENT,"yes"); handler.getTransformer().setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); handler.setResult(new StreamResult(writer)); docXML=new DocumentEmitter(handler,handler); docXML.comment("Node type generation prototype"); writeTo(); }
Example 14
From project cilia-workbench, under directory /cilia-workbench-common/src/fr/liglab/adele/cilia/workbench/common/xml/.
Source file: XMLHelpers.java

/** * Writes a document using its DOM representation. * @param document the document * @param file the file, on the local file system. * @throws CiliaException the metadata exception */ public static void writeDOM(Document document,File file) throws CiliaException { Source source=new DOMSource(document); TransformerFactory transformerFactory=TransformerFactory.newInstance(); try { Transformer xformer=transformerFactory.newTransformer(); xformer.setOutputProperty(OutputKeys.INDENT,"yes"); StreamResult result=new StreamResult(file); xformer.transform(source,result); } catch ( TransformerException e) { throw new CiliaException("XML transformer error",e); } }
Example 15
From project core_1, under directory /config/src/main/java/org/switchyard/config/.
Source file: DOMConfiguration.java

/** * {@inheritDoc} */ @Override public void write(Writer writer,OutputKey... keys) throws IOException { List<OutputKey> key_list=Arrays.asList(keys); if (key_list.contains(OutputKey.NORMALIZE)) { normalize(); } if (key_list.contains(OutputKey.ORDER_CHILDREN)) { orderChildren(); } Map<String,String> outputProperties=new HashMap<String,String>(); if (key_list.contains(OutputKey.OMIT_XML_DECLARATION)) { outputProperties.put(OutputKeys.OMIT_XML_DECLARATION,"yes"); } if (key_list.contains(OutputKey.PRETTY_PRINT)) { outputProperties.put(OutputKey.PRETTY_PRINT.hint(),"yes"); } XMLHelper.write(_element,writer,outputProperties); }
Example 16
From project Core_2, under directory /parser-xml/src/main/java/org/jboss/forge/parser/xml/.
Source file: XMLParser.java

public static byte[] toXMLByteArray(final Node node){ try { DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder=factory.newDocumentBuilder(); Document root=builder.newDocument(); writeRecursive(root,node); Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); ByteArrayOutputStream stream=new ByteArrayOutputStream(); StreamResult result=new StreamResult(stream); transformer.transform(new DOMSource(root),result); return stream.toByteArray(); } catch ( Exception e) { throw new XMLParserException("Could not export Node strcuture to XML",e); } }
Example 17
From project Cours-3eme-ann-e, under directory /Java/FerryInpres/src/information_client/.
Source file: MainForm.java

private void sendDocument(Document doc) throws TransformerConfigurationException, TransformerException, IOException, ClassNotFoundException { String MAIN_SERVEUR=prop.getProperty("MAIN_SERVEUR"); int MAIN_PORT=Integer.parseInt(prop.getProperty("MAIN_PORT")); Socket sock=new Socket(MAIN_SERVEUR,MAIN_PORT); InputStream sock_in=sock.getInputStream(); OutputStream sock_out=sock.getOutputStream(); StringWriter out=new StringWriter(); TransformerFactory transFactory=TransformerFactory.newInstance(); Transformer transform=transFactory.newTransformer(); transform.setOutputProperty(OutputKeys.METHOD,"xml"); transform.setOutputProperty(OutputKeys.INDENT,"yes"); Source input=new DOMSource(doc); Result output=new StreamResult(out); transform.transform(input,output); ObjectOutputStream obj_out=new ObjectOutputStream(sock_out); String xml_str=out.toString(); System.out.println(xml_str); obj_out.writeObject(xml_str); sock_out.flush(); try { String filename=(String)(new ObjectInputStream(sock_in)).readObject(); this.informationsText.setText(filename); this.erreurLabel.setText("Demande r?ussie"); } catch ( Exception e) { System.err.println(e); this.erreurLabel.setText("Erreur lors du traitement de la demande"); } }
Example 18
From project crash, under directory /jcr/core/src/main/java/org/crsh/jcr/.
Source file: Exporter.java

@Override public void startElement(String uri,String localName,String qName,Attributes attributes) throws SAXException { try { String fileName=XML.fileName(qName); fs.startDirectory(fileName); ByteArrayOutputStream out=new ByteArrayOutputStream(); StreamResult streamResult=new StreamResult(out); SAXTransformerFactory tf=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); TransformerHandler hd=tf.newTransformerHandler(); Transformer serializer=hd.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); hd.setResult(streamResult); hd.startDocument(); for ( Map.Entry<String,String> mapping : mappings.entrySet()) { String prefix=mapping.getKey(); hd.startPrefixMapping(prefix,mapping.getValue()); } hd.startElement(uri,localName,qName,attributes); hd.endElement(uri,localName,qName); for ( String prefix : mappings.keySet()) { hd.endPrefixMapping(prefix); } hd.endDocument(); out.close(); byte[] content=out.toByteArray(); fs.file("crash__content.xml",content.length,new ByteArrayInputStream(content)); } catch ( Exception e) { throw new SAXException(e); } }
Example 19
From project dcm4che, under directory /dcm4che-tool/dcm4che-tool-dcm2xml/src/main/java/org/dcm4che/tool/dcm2xml/.
Source file: Dcm2Xml.java

public void parse(DicomInputStream dis) throws IOException, TransformerConfigurationException { dis.setIncludeBulkData(includeBulkData); dis.setIncludeBulkDataLocator(includeBulkDataLocator); dis.setBulkDataAttributes(blkAttrs); dis.setBulkDataDirectory(blkDirectory); dis.setBulkDataFilePrefix(blkFilePrefix); dis.setBulkDataFileSuffix(blkFileSuffix); dis.setConcatenateBulkDataFiles(catBlkFiles); TransformerHandler th=getTransformerHandler(); th.getTransformer().setOutputProperty(OutputKeys.INDENT,indent ? "yes" : "no"); th.setResult(new StreamResult(System.out)); SAXWriter saxWriter=new SAXWriter(th); saxWriter.setIncludeKeyword(includeKeyword); saxWriter.setIncludeNamespaceDeclaration(includeNamespaceDeclaration); dis.setDicomInputHandler(saxWriter); dis.readDataset(-1,-1); }
Example 20
From project descriptors, under directory /spi/src/main/java/org/jboss/shrinkwrap/descriptor/spi/node/dom/.
Source file: XmlDomDescriptorExporterImpl.java

/** * {@inheritDoc} * @see org.jboss.shrinkwrap.descriptor.spi.node.NodeDescriptorExporterImpl#to(org.jboss.shrinkwrap.descriptor.spi.node.Node,java.io.OutputStream) */ @Override public void to(final Node node,final OutputStream out) throws DescriptorExportException { try { DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder=factory.newDocumentBuilder(); Document root=builder.newDocument(); root.setXmlStandalone(true); writeRecursive(root,node); Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty(OutputKeys.STANDALONE,"yes"); StreamResult result=new StreamResult(out); transformer.transform(new DOMSource(root),result); } catch ( Exception e) { throw new DescriptorExportException("Could not export Node structure to XML",e); } }
Example 21
From project DeuceSTM, under directory /src/test/org/deuce/benchmark/lee/.
Source file: XMLHelper.java

static void generateXMLReportSummary(boolean timeout,boolean xmlreport,double elapsed) throws TransformerFactoryConfigurationError { try { LeeRouterGlobalLock.obtainStats(null,elapsed,xmlreport); LeeRouterGlobalLock.xmlReport(doc); Element root=doc.getDocumentElement(); Element element=doc.createElement("ElapsedTime"); element.setTextContent(Double.toString(elapsed)); root.appendChild(element); element=doc.createElement("Timeout"); element.setTextContent(Boolean.toString(timeout)); root.appendChild(element); DOMSource domSource=new DOMSource(doc); TransformerFactory tf=TransformerFactory.newInstance(); Transformer transformer=tf.newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD,"xml"); transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); StringWriter sw=new StringWriter(); StreamResult sr=new StreamResult(sw); transformer.transform(domSource,sr); System.out.println(sw.toString()); } catch ( TransformerConfigurationException e) { e.printStackTrace(); } catch ( TransformerException e) { e.printStackTrace(); } }
Example 22
From project droolsjbpm-integration, under directory /drools-camel/src/test/java/org/drools/camel/component/.
Source file: BatchTest.java

public String prettyPrintXml(String xmlSource){ try { DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); DocumentBuilder builder=factory.newDocumentBuilder(); Document doc=builder.parse(new InputSource(new StringReader(xmlSource))); TransformerFactory tfactory=TransformerFactory.newInstance(); tfactory.setAttribute("indent-number",4); Transformer serializer; ByteArrayOutputStream baos=new ByteArrayOutputStream(); serializer=tfactory.newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); serializer.transform(new DOMSource(doc),new StreamResult(new OutputStreamWriter(baos,"UTF-8"))); return new String(baos.toByteArray()); } catch ( Exception e) { throw new RuntimeException(e); } }
Example 23
From project EasySOA, under directory /easysoa-proxy/easysoa-proxy-core/easysoa-proxy-core-api/src/main/java/org/easysoa/proxy/core/api/records/assertions/.
Source file: AbstractAssertion.java

/** * Convert a Node in String * @param node The node to convert * @return The XML string representation of the node */ public String nodeToString(Node node) throws Exception { StringWriter sw=new StringWriter(); Transformer t=TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); t.transform(new DOMSource(node),new StreamResult(sw)); return sw.toString(); }
Example 24
From project eclipse-integration-commons, under directory /org.springsource.ide.eclipse.commons.content.core/src/org/springsource/ide/eclipse/commons/content/core/util/.
Source file: DescriptorReader.java

public void write(File file) throws CoreException { DocumentBuilder documentBuilder=ContentUtil.createDocumentBuilder(); Transformer serializer=ContentUtil.createTransformer(); Document document=documentBuilder.newDocument(); writeDocument(document); DOMSource source=new DOMSource(document); try { StreamResult target=new StreamResult(file); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); serializer.transform(source,target); } catch ( TransformerException e) { throw new CoreException(new Status(Status.ERROR,ContentPlugin.PLUGIN_ID,"Could not write initialization data for tutorial")); } }
Example 25
From project ElasticSearchExample, under directory /src/main/java/de/jetwick/ese/util/.
Source file: Helper.java

public static String getDocumentAsString(Node node,boolean prettyXml) throws TransformerException, UnsupportedEncodingException { Transformer transformer=TransformerFactory.newInstance().newTransformer(); if (prettyXml) { transformer.setOutputProperty(OutputKeys.INDENT,"yes"); } transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); ByteArrayOutputStream baos=new ByteArrayOutputStream(); transformer.transform(new DOMSource(node),new StreamResult(baos)); return baos.toString("UTF-8"); }
Example 26
From project Euclidean-Pattern-Generator, under directory /src/com/hisschemoller/sequencer/controller/file/.
Source file: SaveProjectCommand.java

private void printXML(Document document){ try { TransformerFactory transFactory=TransformerFactory.newInstance(); Transformer transformer=transFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); StringWriter stringWriter=new StringWriter(); StreamResult result=new StreamResult(stringWriter); DOMSource source=new DOMSource(document); transformer.transform(source,result); String xmlString=stringWriter.toString(); System.out.println("Here's the xml:\n\n" + xmlString); } catch ( Exception exception) { showMessage("SaveProjectCommand.printXML() Exception: " + exception.getMessage()); } }
Example 27
public static String xmlNodeToString(Node node) throws Exception { Source source=new DOMSource(node); StringWriter stringWriter=new StringWriter(); Result result=new StreamResult(stringWriter); TransformerFactory factory=TransformerFactory.newInstance(); Transformer transformer=factory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); transformer.transform(source,result); return stringWriter.getBuffer().toString(); }
Example 28
From project flyingsaucer, under directory /flying-saucer-examples/src/main/java/org/xhtmlrenderer/demo/browser/.
Source file: ViewSourceAction.java

public void actionPerformed(ActionEvent evt){ TransformerFactory tfactory=TransformerFactory.newInstance(); Transformer serializer; try { serializer=tfactory.newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); Element document=panel.getRootBox().getElement(); DOMSource source=new DOMSource(document); StreamResult output=new StreamResult(System.out); serializer.transform(source,output); } catch ( TransformerException ex) { ex.printStackTrace(); throw new RuntimeException(ex); } }
Example 29
From project gatein-common, under directory /common/src/main/java/org/gatein/common/xml/.
Source file: XMLTools.java

/** */ private static Properties createFormat(boolean omitXMLDeclaration,boolean standalone,boolean indented,String encoding){ Properties format=new Properties(); format.setProperty(OutputKeys.OMIT_XML_DECLARATION,omitXMLDeclaration ? "yes" : "no"); format.setProperty(OutputKeys.STANDALONE,standalone ? "yes" : "no"); format.setProperty(OutputKeys.INDENT,indented ? "yes" : "no"); format.setProperty(OutputKeys.ENCODING,encoding); return format; }
Example 30
From project gatein-toolbox, under directory /gen/core/src/main/java/org/gatein/descriptorgenerator/.
Source file: Main.java

private static void reformatXML(Reader src,Writer dst) throws Exception { String s="" + "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n" + "<xsl:output method=\"xml\" omit-xml-declaration=\"yes\"/>\n"+ "<xsl:strip-space elements=\"*\"/>\n"+ "<xsl:template match=\"@*|node()\">\n"+ "<xsl:copy>\n"+ "<xsl:apply-templates select=\"@*|node()\"/>\n"+ "</xsl:copy>\n"+ "</xsl:template>\n"+ "</xsl:stylesheet>"; TransformerFactory factory=TransformerFactory.newInstance(); factory.setAttribute("indent-number",2); Transformer transformer=factory.newTransformer(new StreamSource(new StringReader(s))); transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); transformer.setOutputProperty(OutputKeys.METHOD,"xml"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",Integer.toString(2)); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); StreamSource source=new StreamSource(src); StreamResult result=new StreamResult(dst); transformer.transform(source,result); }
Example 31
From project GnucashMobile, under directory /GnucashMobile/src/org/gnucash/android/ui/accounts/.
Source file: ExportDialogFragment.java

/** * Writes out the file held in <code>document</code> to <code>outputWriter</code> * @param document {@link Document} containing the OFX document structure * @param outputWriter {@link Writer} to use in writing the file to stream */ public void write(Document document,Writer outputWriter){ try { TransformerFactory transformerFactory=TransformerFactory.newInstance(); Transformer transformer=transformerFactory.newTransformer(); DOMSource source=new DOMSource(document); StreamResult result=new StreamResult(outputWriter); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.transform(source,result); } catch ( TransformerConfigurationException txconfigException) { txconfigException.printStackTrace(); } catch ( TransformerException tfException) { tfException.printStackTrace(); } }
Example 32
From project grails-ide, under directory /org.grails.ide.eclipse.core/src/org/grails/ide/eclipse/core/model/.
Source file: GrailsInstallManager.java

private void save(Document document){ try { IPath grailsInstallFile=GrailsCoreActivator.getDefault().getStateLocation().append("grails.installs"); TransformerFactory transformerFactory=TransformerFactory.newInstance(); Transformer transformer=transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"no"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); Writer out=new OutputStreamWriter(new FileOutputStream(grailsInstallFile.toFile()),"ISO-8859-1"); StreamResult result=new StreamResult(out); DOMSource source=new DOMSource(document); transformer.transform(source,result); out.close(); } catch ( IOException e) { GrailsCoreActivator.log(e); } catch ( TransformerException e) { GrailsCoreActivator.log(e); } }
Example 33
From project gravitext, under directory /gravitext-xmlprod/src/main/java/com/gravitext/xml/producer/perftests/.
Source file: JaxpPerfTest.java

protected void serializeGraph(List<GraphItem> graph,TestOutput out) throws IOException, TransformerConfigurationException, TransformerFactoryConfigurationError, SAXException { StreamResult sr; if (useWriter()) sr=new StreamResult(out.getWriter()); else sr=new StreamResult(out.getStream()); SAXTransformerFactory tf=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); TransformerHandler hd=tf.newTransformerHandler(); Transformer serializer=hd.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING,getEncoding()); serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"bogus.dtd"); if (!getIndent().isCompressed()) { serializer.setOutputProperty(OutputKeys.INDENT,"yes"); } hd.setResult(sr); hd.startDocument(); hd.startElement("","","testdoc",emptyAtts); for ( GraphItem g : graph) { AttributesImpl atts=new AttributesImpl(); atts.addAttribute("","","name","CDATA",g.getName()); atts.addAttribute("","","value","CDATA",String.valueOf(g.getValue())); atts.addAttribute("urn:some-unique-id","score","graph:score","CDATA",String.valueOf(g.getScore())); hd.startElement("urn:some-unique-id","item","graph:item",atts); hd.startElement("","","content",emptyAtts); String cdata=g.getContent(); hd.characters(cdata.toCharArray(),0,cdata.length()); hd.endElement("","","content"); if (g.getList().size() > 0) { hd.startElement("","","list",emptyAtts); for ( String gl : g.getList()) { hd.startElement("","","listItem",emptyAtts); hd.characters(gl.toCharArray(),0,gl.length()); hd.endElement("","","listItem"); } hd.endElement("","","list"); } hd.endElement("urn:some-unique-id","item","graph:item"); } hd.endElement("","","testdoc"); hd.endDocument(); }
Example 34
From project Guit, under directory /src/main/java/com/guit/junit/dom/.
Source file: ElementMock.java

public static String getOuterXml(Node n) throws ParserConfigurationException, TransformerFactoryConfigurationError, TransformerException { Transformer xformer=TransformerFactory.newInstance().newTransformer(); xformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); StreamResult result=new StreamResult(new StringWriter()); DOMSource source=new DOMSource(n); xformer.transform(source,result); String xmlString=result.getWriter().toString(); return xmlString; }
Example 35
From project integration-tests, under directory /picketlink-openid-tests/src/test/java/org/picketlink/test/integration/openid/.
Source file: OpenIDConsumerUnitTestCase.java

protected void write(HtmlPage page) throws Exception { Document doc=page; Source source=new DOMSource(doc); StringWriter sw=new StringWriter(); Result streamResult=new StreamResult(sw); Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); transformer.setOutputProperty(OutputKeys.INDENT,"no"); transformer.transform(source,streamResult); System.out.println(sw.toString()); }
Example 36
From project interoperability-framework, under directory /toolwrapper/src/main/java/eu/impact_project/iif/tw/gen/.
Source file: WsdlCreator.java

/** * Insert data types * @throws GeneratorException */ public void insertDataTypes() throws GeneratorException { File wsdlTemplate=new File(this.wsdlSourcePath); if (!wsdlTemplate.canRead()) { throw new GeneratorException("Unable to read WSDL Template file: " + this.wsdlSourcePath); } try { DocumentBuilderFactory docBuildFact=DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder=docBuildFact.newDocumentBuilder(); doc=docBuilder.parse(this.wsdlSourcePath); for ( Operation operation : operations) { createMessageDataTypes(operation); createSchemaDataTypes(operation); createOperation(doc,operation); createBinding(doc,operation); } Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING,"utf-8"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"no"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4"); DOMSource source=new DOMSource(doc); FileOutputStream fos=new FileOutputStream(this.wsdlTargetPath); StreamResult result=new StreamResult(fos); transformer.transform(source,result); fos.close(); if (!((new File(wsdlTargetPath)).exists())) { throw new GeneratorException("WSDL file has not been created successfully."); } } catch ( Exception ex) { logger.error("An exception occurred: " + ex.getMessage()); } }
Example 37
From project jangaroo-tools, under directory /asdoc-scraping/src/main/java/net/jangaroo/tools/asdocscreenscraper/.
Source file: ASDocScreenScraper.java

private static Document loadAndParse(URI url) throws TransformerException, ParserConfigurationException, SAXException, IOException { Document document=TIDY.parseDOM(new BufferedInputStream(url.toURL().openStream()),null); DOMSource domSource=new DOMSource(document.getDocumentElement()); Transformer serializer=TransformerFactory.newInstance().newTransformer(); serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"no"); serializer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); serializer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,"-//W3C//DTD XHTML 1.0 Transitional//EN"); String localXHtmlDoctype=new File(".").getAbsoluteFile().toURI().toString() + "xhtml1/DTD/xhtml1-transitional.dtd"; serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,localXHtmlDoctype); StringWriter result=new StringWriter(); serializer.transform(domSource,new StreamResult(result)); String xhtmlText=result.toString(); xhtmlText=xhtmlText.replaceAll(" id=\"(pageFilter|propertyDetail)\"",""); DocumentBuilderFactory domFactory=DocumentBuilderFactory.newInstance(); domFactory.setValidating(false); domFactory.setNamespaceAware(true); DocumentBuilder builder=domFactory.newDocumentBuilder(); return builder.parse(new InputSource(new StringReader(xhtmlText))); }
Example 38
From project jbpmmigration, under directory /src/main/java/org/jbpm/migration/.
Source file: XmlUtils.java

/** * Format an XML {@link Source} to a pretty-printable {@link StreamResult}. * @param input The (unformatted) input XML {@link Source}. * @return The formatted {@link StreamResult}. */ public static void format(final Source input,final Result output){ try { final Transformer transformer=createTransformer(null); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.transform(input,output); } catch ( final Exception ex) { LOGGER.error("Problem formatting DOM representation.",ex); } }
Example 39
From project jCAE, under directory /amibe/src/org/jcae/mesh/xmldata/.
Source file: XMLWriter.java

public static void writeDocument(Document document,String fileName) throws IOException { try { DOMSource source=new DOMSource(document); TransformerFactory tf=TransformerFactory.newInstance(); tf.setAttribute("indent-number",2); Transformer t=tf.newTransformer(); t.setOutputProperty(OutputKeys.INDENT,"yes"); StreamResult streamResult=new StreamResult(new FileWriter(fileName)); t.transform(source,streamResult); streamResult.getWriter().close(); } catch ( TransformerException ex) { LOGGER.log(Level.SEVERE,null,ex); } }
Example 40
From project jdeltasync, under directory /src/main/java/com/googlecode/jdeltasync/.
Source file: XmlUtil.java

/** * Writes the specified {@link Document} to an {@link OutputStream} in the specified format. * @param doc the {@link Document}. * @param out the stream to write to. * @param compact if <code>true</code> the XML will be written in compactformat without any extra whitespaces. * @throws XmlException on XML errors. */ public static void writeDocument(Document doc,OutputStream out,boolean compact) throws XmlException { try { TransformerFactory tf=TransformerFactory.newInstance(); Transformer serializer=tf.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); serializer.setOutputProperty(OutputKeys.INDENT,compact ? "no" : "yes"); serializer.transform(new DOMSource(doc),new StreamResult(out)); } catch ( TransformerException e) { throw new XmlException(e); } }
Example 41
public static String getDocumentAsString(Node node,boolean prettyXml) throws TransformerException, UnsupportedEncodingException { Transformer transformer=TransformerFactory.newInstance().newTransformer(); if (prettyXml) { transformer.setOutputProperty(OutputKeys.INDENT,"yes"); } transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); ByteArrayOutputStream baos=new ByteArrayOutputStream(); transformer.transform(new DOMSource(node),new StreamResult(baos)); return baos.toString("UTF-8"); }
Example 42
/** * Returns a string that represents the given node. * @param node Node to return the XML for. * @return Returns an XML string. */ public static String getXml(Node node){ try { Transformer tf=TransformerFactory.newInstance().newTransformer(); tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); tf.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); StreamResult dest=new StreamResult(new StringWriter()); tf.transform(new DOMSource(node),dest); return dest.getWriter().toString(); } catch ( Exception e) { } return ""; }
Example 43
/** * Saves the lesson to an {@link OutputStream} which contains an XMLdocument. Don't use this method directly. Use the {@link LessonProvider} instead.XML-Schema: <lesson> <deck> <card frontside="bla" backside="bla"/> .. </deck> .. </lesson> */ public static void saveAsXMLFile(File file,Lesson lesson) throws IOException, TransformerException, ParserConfigurationException { OutputStream out; ZipOutputStream zipOut=null; if (Settings.loadIsSaveCompressed()) { out=zipOut=new ZipOutputStream(new FileOutputStream(file)); zipOut.putNextEntry(new ZipEntry(LESSON_ZIP_ENTRY_NAME)); } else { out=new FileOutputStream(file); } try { Document document=DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element lessonTag=document.createElement(LESSON); document.appendChild(lessonTag); writeCategory(document,lessonTag,lesson.getRootCategory()); writeLearnHistory(document,lesson.getLearnHistory()); Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.transform(new DOMSource(document),new StreamResult(out)); } finally { if (zipOut != null) zipOut.closeEntry(); else if (out != null) out.close(); } try { removeUnusedImagesFromRepository(lesson); if (zipOut == null) writeImageRepositoryToDisk(new File(file.getParent())); else writeImageRepositoryToZip(zipOut); } finally { if (zipOut != null) zipOut.close(); } }
Example 44
From project jmeter-components, under directory /src/main/java/com/atlantbh/jmeter/plugins/xmlformatter/.
Source file: XMLFormatPostProcessor.java

public String serialize2(String unformattedXml) throws Exception { final Document document=XmlUtil.stringToXml(unformattedXml); TransformerFactory tfactory=TransformerFactory.newInstance(); StringWriter buffer=new StringWriter(); Transformer serializer=tfactory.newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); serializer.transform(new DOMSource(document),new StreamResult(buffer)); return buffer.toString(); }
Example 45
/** * Transform an {@link Element} into a <code>String</code>. */ static final String toString(Element element){ try { ByteArrayOutputStream out=new ByteArrayOutputStream(); Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); Source source=new DOMSource(element); Result target=new StreamResult(out); transformer.transform(source,target); return out.toString(); } catch ( Exception e) { return "[ ERROR IN toString() : " + e.getMessage() + " ]"; } }
Example 46
public void write(OutputStream out,JreepadTreeModel document) throws IOException { StreamResult result=new StreamResult(out); SAXTransformerFactory factory=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); TransformerHandler handler; try { handler=factory.newTransformerHandler(); handler.getTransformer().setOutputProperty(OutputKeys.INDENT,"yes"); } catch ( TransformerConfigurationException e) { throw new IOException(e.toString()); } handler.setResult(result); try { write(handler,document); } catch ( SAXException e) { throw new IOException(e.toString()); } }
Example 47
From project JsTestDriver, under directory /JsTestDriver/src/com/google/jstestdriver/output/.
Source file: TestXmlSerializer.java

public TestXmlSerializer(Writer fileWriter){ try { transformerHandler=((SAXTransformerFactory)SAXTransformerFactory.newInstance()).newTransformerHandler(); Transformer transformer=transformerHandler.getTransformer(); transformer.setOutputProperty(OutputKeys.METHOD,"xml"); transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformerHandler.setResult(new StreamResult(fileWriter)); } catch ( TransformerConfigurationException e) { throw new RuntimeException(e); } catch ( TransformerFactoryConfigurationError e) { throw new RuntimeException(e); } }
Example 48
From project jumpnevolve, under directory /lib/slick/src/org/newdawn/slick/particles/.
Source file: ParticleIO.java

/** * Save a particle system with only ConfigurableEmitters in to an XML file * @param out The location to which we'll save * @param system The system to store * @throws IOException Indicates a failure to save or encode the system XML. */ public static void saveConfiguredSystem(OutputStream out,ParticleSystem system) throws IOException { try { DocumentBuilder builder=DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document=builder.newDocument(); Element root=document.createElement("system"); root.setAttribute("additive","" + (system.getBlendingMode() == ParticleSystem.BLEND_ADDITIVE)); root.setAttribute("points","" + (system.usePoints())); document.appendChild(root); for (int i=0; i < system.getEmitterCount(); i++) { ParticleEmitter current=system.getEmitter(i); if (current instanceof ConfigurableEmitter) { Element element=emitterToElement(document,(ConfigurableEmitter)current); root.appendChild(element); } else { throw new RuntimeException("Only ConfigurableEmitter instances can be stored"); } } Result result=new StreamResult(new OutputStreamWriter(out,"utf-8")); DOMSource source=new DOMSource(document); TransformerFactory factory=TransformerFactory.newInstance(); Transformer xformer=factory.newTransformer(); xformer.setOutputProperty(OutputKeys.INDENT,"yes"); xformer.transform(source,result); } catch ( Exception e) { Log.error(e); throw new IOException("Unable to save configured particle system"); } }
Example 49
From project kwegg, under directory /lib/readwrite/opennlp-tools/src/java/opennlp/tools/dictionary/serializer/.
Source file: DictionarySerializer.java

/** * Serializes the given entries to the given {@link OutputStream}. * @param out * @param entries * @throws IOException If an I/O error occurs */ public static void serialize(OutputStream out,Iterator entries) throws IOException { GZIPOutputStream gzipOut=new GZIPOutputStream(out); StreamResult streamResult=new StreamResult(gzipOut); SAXTransformerFactory tf=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); TransformerHandler hd; try { hd=tf.newTransformerHandler(); } catch ( TransformerConfigurationException e1) { throw new AssertionError("The Tranformer configuration must be valid!"); } Transformer serializer=hd.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING,CHARSET); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); hd.setResult(streamResult); try { hd.startDocument(); hd.startElement("","",DICTIONARY_ELEMENT,new AttributesImpl()); while (entries.hasNext()) { Entry entry=(Entry)entries.next(); serializeEntry(hd,entry); } hd.endElement("","",DICTIONARY_ELEMENT); hd.endDocument(); } catch ( SAXException e) { throw new IOException("There was an error during serialization!"); } gzipOut.finish(); }
Example 50
From project LABPipe, under directory /src/org/bultreebank/labpipe/tools/.
Source file: ClarkAnnotation.java

private String extractResultFragment(Document doc){ try { Transformer tr=TransformerFactory.newInstance().newTransformer(); tr.setOutputProperty(OutputKeys.INDENT,"yes"); tr.setOutputProperty(OutputKeys.METHOD,"xml"); tr.setOutputProperty(OutputKeys.ENCODING,ServiceConstants.PIPE_CHARACTER_ENCODING); tr.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","0"); StringWriter resultBuffer=new StringWriter(); tr.transform(new DOMSource(doc),new StreamResult(resultBuffer)); return resultBuffer.getBuffer().toString(); } catch ( Exception ex) { logger.severe(ex.getMessage()); } return ""; }
Example 51
From project lenya, under directory /org.apache.lenya.core.impl/src/main/java/org/apache/lenya/xml/.
Source file: DocumentHelper.java

/** * Get the transformer. * @param documentType the document type * @return a transformer * @throws TransformerConfigurationException if an error occurs */ protected static Transformer getTransformer(DocumentType documentType) throws TransformerConfigurationException { TransformerFactory factory=TransformerFactory.newInstance(); Transformer transformer=factory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty(OutputKeys.METHOD,"xml"); if (documentType != null) { if (documentType.getPublicId() != null) transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,documentType.getPublicId()); if (documentType.getSystemId() != null) transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,documentType.getSystemId()); } return transformer; }
Example 52
From project leviathan, under directory /scrapper/src/main/java/com/zaubersoftware/leviathan/api/engine/impl/pipe/.
Source file: XMLPipe.java

/** * Applies the XSL Transformation and returns the resulting Node. * @param node * @param model * @param oformat * @return * @throws TransformerFactoryConfigurationError */ private Node applyXSLT(final Node node,final Map<String,Object> model,final Properties oformat){ Validate.notNull(node,"The node cannot be null."); try { final Transformer transformer=template.newTransformer(); Validate.notNull(transformer); for ( final Entry<String,Object> entry : model.entrySet()) { transformer.setParameter(entry.getKey(),entry.getValue()); } Properties options; if (oformat != null) { options=new Properties(oformat); } else { options=new Properties(); } if (this.encoding != null) { options.setProperty(OutputKeys.ENCODING,this.encoding); } transformer.setOutputProperties(options); final DOMResult result=new DOMResult(); transformer.transform(new DOMSource(node),result); return result.getNode(); } catch ( final TransformerException e) { this.logger.error("An error ocurred while applying the XSL transformation",e); throw new NotImplementedException("Handle exception with context stack handlers"); } catch ( final TransformerFactoryConfigurationError e) { this.logger.error("An error ocurred while applying the XSL transformation",e); throw new NotImplementedException("Handle exception with context stack handlers"); } }
Example 53
From project Lily, under directory /global/util/src/main/java/org/lilyproject/util/xml/.
Source file: XmlProducer.java

public XmlProducer(OutputStream outputStream) throws SAXException, TransformerConfigurationException { TransformerHandler serializer=getTransformerHandler(); serializer.getTransformer().setOutputProperty(OutputKeys.METHOD,"xml"); serializer.getTransformer().setOutputProperty(OutputKeys.ENCODING,"UTF-8"); serializer.setResult(new StreamResult(outputStream)); this.result=serializer; result.startDocument(); newLine(); }
Example 54
From project liquibase, under directory /liquibase-core/src/main/java/liquibase/util/xml/.
Source file: DefaultXmlWriter.java

public void write(Document doc,OutputStream outputStream) throws IOException { try { TransformerFactory factory=TransformerFactory.newInstance(); try { factory.setAttribute("indent-number",4); } catch ( Exception e) { ; } Transformer transformer=factory.newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD,"xml"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); transformer.transform(new DOMSource(doc),new StreamResult(new OutputStreamWriter(outputStream,"utf-8"))); } catch ( TransformerException e) { throw new IOException(e.getMessage()); } }
Example 55
From project litle-sdk-for-java, under directory /lib/apache-cxf-2.5.2/samples/js_browser_client_simple/src/main/java/demo/hw/client/.
Source file: Get.java

private static void printSource(Source source){ try { ByteArrayOutputStream bos=new ByteArrayOutputStream(); StreamResult sr=new StreamResult(bos); Transformer trans=TransformerFactory.newInstance().newTransformer(); Properties oprops=new Properties(); oprops.put(OutputKeys.OMIT_XML_DECLARATION,"yes"); trans.setOutputProperties(oprops); trans.transform(source,sr); System.out.println(); System.out.println("**** Response ******"); System.out.println(); System.out.println(bos.toString()); bos.close(); System.out.println(); } catch ( Exception e) { e.printStackTrace(); } }
Example 56
From project lyo.core, under directory /OSLC4JJenaProvider/src/org/eclipse/lyo/oslc4j/provider/jena/.
Source file: JenaModelHelper.java

private static Transformer createTransformer(){ try { Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); return transformer; } catch ( TransformerException e) { throw new RuntimeException(e); } }
Example 57
From project lyo.rio, under directory /org.eclipse.lyo.rio.core/src/main/java/org/eclipse/lyo/rio/util/.
Source file: XmlUtils.java

public static String prettyPrint(Document doc){ TransformerFactory tfactory=TransformerFactory.newInstance(); Transformer serializer; StringWriter writer=new StringWriter(); try { serializer=tfactory.newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); serializer.transform(new DOMSource(doc),new StreamResult(writer)); return writer.toString(); } catch ( TransformerException e) { throw new RuntimeException(e); } }
Example 58
From project lyo.server, under directory /org.eclipse.lyo.samples.bugzilla/src/main/java/org/eclipse/lyo/samples/bugzilla/utils/.
Source file: XmlUtils.java

public static String prettyPrint(Document doc){ TransformerFactory tfactory=TransformerFactory.newInstance(); Transformer serializer; StringWriter writer=new StringWriter(); try { serializer=tfactory.newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); serializer.transform(new DOMSource(doc),new StreamResult(writer)); return writer.toString(); } catch ( TransformerException e) { throw new RuntimeException(e); } }
Example 59
From project lyo.testsuite, under directory /org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/.
Source file: OSLCUtils.java

public static String createStringFromXMLDoc(Document document) throws TransformerException { TransformerFactory tf=TransformerFactory.newInstance(); Transformer transformer=tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); StringWriter writer=new StringWriter(); transformer.transform(new DOMSource(document),new StreamResult(writer)); return writer.getBuffer().toString(); }
Example 60
From project Maimonides, under directory /src/com/codeko/apps/maimonides/seneca/.
Source file: GeneradorFicherosSeneca.java

public Transformer getTransformer(){ if (trans == null) { TransformerFactory transfac=TransformerFactory.newInstance(); try { trans=transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); trans.setOutputProperty(OutputKeys.INDENT,"yes"); } catch ( TransformerConfigurationException ex) { Logger.getLogger(GeneradorFicherosSeneca.class.getName()).log(Level.SEVERE,null,ex); } } return trans; }
Example 61
From project maven-android-plugin, under directory /src/main/java/com/jayway/maven/plugins/android/standalonemojos/.
Source file: ManifestUpdateMojo.java

/** * Write manifest using JAXP transformer */ private void writeManifest(File manifestFile,Document doc) throws IOException, TransformerException { TransformerFactory xfactory=TransformerFactory.newInstance(); Transformer xformer=xfactory.newTransformer(); xformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); Source source=new DOMSource(doc); FileWriter writer=null; try { writer=new FileWriter(manifestFile,false); String xmldecl=String.format("<?xml version=\"%s\" encoding=\"%s\"?>%n",doc.getXmlVersion(),doc.getXmlEncoding()); writer.write(xmldecl); Result result=new StreamResult(writer); xformer.transform(source,result); } finally { IOUtils.closeQuietly(writer); } }
Example 62
From project maven-wagon, under directory /wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/jackrabbit/webdav/client/methods/.
Source file: XmlRequestEntity.java

public XmlRequestEntity(Document xmlDocument) throws IOException { super(); ByteArrayOutputStream out=new ByteArrayOutputStream(); try { TransformerFactory factory=TransformerFactory.newInstance(); Transformer transformer=factory.newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD,"xml"); transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT,"no"); transformer.transform(new DOMSource(xmlDocument),new StreamResult(out)); } catch ( TransformerException e) { log.error("XML serialization failed",e); IOException exception=new IOException("XML serialization failed"); exception.initCause(e); throw exception; } delegatee=new StringRequestEntity(out.toString(),"text/xml","UTF-8"); }
Example 63
From project MEditor, under directory /editor-common/editor-common-server/src/main/java/cz/mzk/editor/server/fedora/utils/.
Source file: FedoraUtils.java

/** * @param document */ public static String getStringFromDocument(Document document,boolean omitXmlDeclaration) throws TransformerException { TransformerFactory transFactory=TransformerFactory.newInstance(); Transformer transformer=transFactory.newTransformer(); StringWriter buffer=new StringWriter(); if (omitXmlDeclaration) { transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); } transformer.transform(new DOMSource(document),new StreamResult(buffer)); return buffer.toString(); }
Example 64
From project mgwt, under directory /src/main/java/com/googlecode/mgwt/linker/linker/.
Source file: XMLPermutationProvider.java

protected String transformDocumentToString(Document document) throws XMLPermutationProviderException { try { StringWriter xml=new StringWriter(); Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.transform(new DOMSource(document),new StreamResult(xml)); String permMapString=xml.toString(); return permMapString; } catch ( TransformerConfigurationException e) { logger.log(Level.SEVERE,"can not transform document to String"); throw new XMLPermutationProviderException("can not transform document to String",e); } catch ( TransformerFactoryConfigurationError e) { logger.log(Level.SEVERE,"can not transform document to String"); throw new XMLPermutationProviderException("can not transform document to String",e); } catch ( TransformerException e) { logger.log(Level.SEVERE,"can not transform document to String"); throw new XMLPermutationProviderException("can not transform document to String",e); } }
Example 65
From project Mockey, under directory /src/java/com/mockey/storage/xml/.
Source file: MockeyXmlFactory.java

private String getDocumentAsString(Document document) throws IOException, TransformerException { Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty(OutputKeys.METHOD,"xml"); transformer.setOutputProperty(OutputKeys.ENCODING,HTTP.UTF_8); StreamResult result=new StreamResult(new StringWriter()); DOMSource source=new DOMSource(document); transformer.transform(source,result); return result.getWriter().toString(); }
Example 66
From project moho, under directory /moho-common/src/main/java/com/voxeo/moho/common/util/.
Source file: XmlUtils.java

public static String render(final Node node){ try { final StringWriter writer=new StringWriter(); final DOMSource domSource=new DOMSource(node); final StreamResult streamResult=new StreamResult(writer); final TransformerFactory tf=TransformerFactory.newInstance(); final Transformer serializer=tf.newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); serializer.transform(domSource,streamResult); return writer.toString(); } catch ( final Exception e) { throw new RuntimeException("Error serializing DOM",e); } }
Example 67
From project ndg, under directory /ndg-commons-core/src/main/java/br/org/indt/ndg/common/.
Source file: ResultWriter.java

public String write() throws ParserConfigurationException, Exception { DOMSource domSource=new DOMSource(getDocument()); StreamResult streamResult=new StreamResult(new StringWriter()); TransformerFactory tf=TransformerFactory.newInstance(); Transformer serializer=tf.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING,Resources.ENCODING); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); serializer.transform(domSource,streamResult); String xmlString=streamResult.getWriter().toString(); return xmlString; }
Example 68
From project ned, under directory /NEDCatalogTool2/src/org/ned/server/nedcatalogtool2/datasource/.
Source file: LanguageInfoSerializer.java

public void printXml(List<NedLanguage> list,PrintWriter writer) throws TransformerConfigurationException, SAXException { StreamResult streamResult=new StreamResult(writer); SAXTransformerFactory tf=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); TransformerHandler hd=tf.newTransformerHandler(); Transformer serializer=hd.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); serializer.setOutputProperty(OutputKeys.STANDALONE,"yes"); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); hd.setResult(streamResult); hd.startDocument(); if (list != null && !list.isEmpty()) { write(hd,list); } hd.endDocument(); }
Example 69
public static void write(NodeLibrary library,StreamResult streamResult,File file){ try { DocumentBuilder builder=DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc=builder.newDocument(); Element rootElement=doc.createElement("ndbx"); rootElement.setAttribute("type","file"); rootElement.setAttribute("formatVersion",NodeLibrary.CURRENT_FORMAT_VERSION); rootElement.setAttribute("uuid",library.getUuid().toString()); doc.appendChild(rootElement); Set<String> propertyNames=library.getPropertyNames(); ArrayList<String> orderedNames=new ArrayList<String>(propertyNames); Collections.sort(orderedNames); for ( String propertyName : orderedNames) { String propertyValue=library.getProperty(propertyName); Element e=doc.createElement("property"); e.setAttribute("name",propertyName); e.setAttribute("value",propertyValue); rootElement.appendChild(e); } writeFunctionRepository(doc,rootElement,library.getFunctionRepository(),file); writeNode(doc,rootElement,library.getRoot(),library.getNodeRepository()); DOMSource domSource=new DOMSource(doc); TransformerFactory tf=TransformerFactory.newInstance(); Transformer serializer=tf.newTransformer(); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4"); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); serializer.transform(domSource,streamResult); } catch ( ParserConfigurationException e) { throw new RuntimeException(e); } catch ( TransformerException e) { throw new RuntimeException(e); } }
Example 70
From project ODE-X, under directory /runtime/src/main/java/org/apache/ode/runtime/exec/platform/task/.
Source file: TaskActionImpl.java

public static byte[] domToContent(Document doc) throws PlatformException { if (doc != null) { try { Transformer tform=transformFactory.newTransformer(); tform.setOutputProperty(OutputKeys.INDENT,"yes"); ByteArrayOutputStream bos=new ByteArrayOutputStream(); tform.transform(new DOMSource(doc),new StreamResult(bos)); return bos.toByteArray(); } catch ( Exception e) { throw new PlatformException(e); } } else { return null; } }
Example 71
From project open-data-node, under directory /src/main/java/sk/opendata/odn/serialization/rdf/.
Source file: AbstractRdfSerializer.java

/** * Initialize serializer to use given repository. * @param repository repository to use for storage of record * @throws IllegalArgumentException if repository is {@code null} * @throws ParserConfigurationException when XML document builder fails to initialize * @throws TransformerConfigurationException when XML document transformer fails to initialize */ public AbstractRdfSerializer(OdnRepositoryStoreInterface<RdfData> repository) throws IllegalArgumentException, ParserConfigurationException, TransformerConfigurationException { super(repository); DocumentBuilderFactory docBuilderFactory=DocumentBuilderFactory.newInstance(); docBuilder=docBuilderFactory.newDocumentBuilder(); TransformerFactory transformerFactory=TransformerFactory.newInstance(); transformer=transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); }
Example 72
From project OpenEMRConnect, under directory /oeclib/src/main/java/ke/go/moh/oec/lib/.
Source file: XmlPacker.java

/** * Packs a DOM Document structure into an XML string. * @param doc the DOM Document structure to pack * @return the packed XML string */ String packDocument(Document doc){ StringWriter stringWriter=new StringWriter(); try { Transformer t=TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.INDENT,"yes"); t.setOutputProperty(OutputKeys.STANDALONE,"yes"); Source source=new DOMSource(doc); t.transform(source,new StreamResult(stringWriter)); } catch ( TransformerConfigurationException ex) { Logger.getLogger(XmlPacker.class.getName()).log(Level.SEVERE,null,ex); } catch ( TransformerException ex) { Logger.getLogger(XmlPacker.class.getName()).log(Level.SEVERE,null,ex); } String returnString=stringWriter.toString(); try { stringWriter.close(); } catch ( IOException ex) { } return returnString; }
Example 73
From project openengsb-framework, under directory /components/common/src/main/java/org/openengsb/core/common/remote/.
Source file: XmlDecoderFilter.java

public static String writeDocument(Node input) throws TransformerException { Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); StringWriter sw=new StringWriter(); transformer.transform(new DOMSource(input),new StreamResult(sw)); return sw.toString(); }
Example 74
From project opennlp, under directory /opennlp-tools/src/main/java/opennlp/tools/dictionary/serializer/.
Source file: DictionarySerializer.java

/** * Serializes the given entries to the given {@link OutputStream}. After the serialization is finished the provided {@link OutputStream} remains open. * @param out stream to serialize to * @param entries entries to serialize * @param casesensitive indicates if the written dictionary should be case sensitive or case insensitive. * @throws IOException If an I/O error occurs */ public static void serialize(OutputStream out,Iterator<Entry> entries,boolean casesensitive) throws IOException { StreamResult streamResult=new StreamResult(out); SAXTransformerFactory tf=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); TransformerHandler hd; try { hd=tf.newTransformerHandler(); } catch ( TransformerConfigurationException e1) { throw new AssertionError("The Tranformer configuration must be valid!"); } Transformer serializer=hd.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING,CHARSET); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); hd.setResult(streamResult); try { hd.startDocument(); AttributesImpl dictionaryAttributes=new AttributesImpl(); dictionaryAttributes.addAttribute("","",ATTRIBUTE_CASE_SENSITIVE,"",String.valueOf(casesensitive)); hd.startElement("","",DICTIONARY_ELEMENT,dictionaryAttributes); while (entries.hasNext()) { Entry entry=entries.next(); serializeEntry(hd,entry); } hd.endElement("","",DICTIONARY_ELEMENT); hd.endDocument(); } catch ( SAXException e) { throw new IOException("There was an error during serialization!"); } }
Example 75
From project org.eclipse.scout.builder, under directory /org.eclipse.scout.releng.ant/src/org/eclipse/scout/releng/ant/category/.
Source file: CategoryTask.java

private void writeXmlFile(Document document) throws Exception { OutputStream fos=null; try { if (!getCategoryFile().exists()) { getCategoryFile().getParentFile().mkdirs(); } fos=new FileOutputStream(getCategoryFile()); TransformerFactory transformerFactory=TransformerFactory.newInstance(); Transformer transformer=transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); DOMSource source=new DOMSource(document); StreamResult result=new StreamResult(fos); transformer.transform(source,result); } finally { fos.close(); } }
Example 76
From project pegadi, under directory /client/src/main/java/org/pegadi/publisher/.
Source file: AbstractPublisher.java

protected Properties getOutputProperties(){ Properties p=new Properties(); p.setProperty(OutputKeys.ENCODING,encoding.getName()); p.setProperty(OutputKeys.METHOD,outputMethod.name()); return p; }
Example 77
From project picketlink-idm, under directory /picketlink-idm-testsuite/common/src/test/java/org/picketlink/idm/test/support/.
Source file: XMLTools.java

/** */ private static Properties createFormat(boolean omitXMLDeclaration,boolean standalone,boolean indented,String encoding){ Properties format=new Properties(); format.setProperty(OutputKeys.OMIT_XML_DECLARATION,omitXMLDeclaration ? "yes" : "no"); format.setProperty(OutputKeys.STANDALONE,standalone ? "yes" : "no"); format.setProperty(OutputKeys.INDENT,indented ? "yes" : "no"); format.setProperty(OutputKeys.ENCODING,encoding); return format; }
Example 78
public static void main(String[] args){ PipelineGenerator gen=new PipelineGenerator(new File("practice_xmlgen.xml")); Collection<InjectableItem> items=gen.getInjectables(); Iterator<InjectableItem> it=items.iterator(); gen.injectMatchingTags("prefix","newPrefix"); Transformer t; try { t=TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.METHOD,"xml"); t.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,"-//W3C//DTD XHTML 1.0 Transitional//EN"); t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"); t.setOutputProperty(OutputKeys.METHOD,"html"); t.transform(new DOMSource(gen.getDocument()),new StreamResult(System.out)); } catch ( TransformerConfigurationException e) { e.printStackTrace(); } catch ( TransformerFactoryConfigurationError e) { e.printStackTrace(); } catch ( TransformerException e) { e.printStackTrace(); } }
Example 79
From project plugin-WoT-staging, under directory /src/plugins/WebOfTrust/.
Source file: XMLTransformer.java

/** * Initializes the XML creator & parser and caches those objects in the new IdentityXML object so that they do not have to be initialized each time an identity is exported/imported. */ public XMLTransformer(WebOfTrust myWoT){ mWoT=myWoT; mDB=mWoT.getDatabase(); try { DocumentBuilderFactory xmlFactory=DocumentBuilderFactory.newInstance(); xmlFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,true); xmlFactory.setAttribute("http://apache.org/xml/features/disallow-doctype-decl",true); mDocumentBuilder=xmlFactory.newDocumentBuilder(); mDOM=mDocumentBuilder.getDOMImplementation(); mSerializer=TransformerFactory.newInstance().newTransformer(); mSerializer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); mSerializer.setOutputProperty(OutputKeys.INDENT,"yes"); mSerializer.setOutputProperty(OutputKeys.STANDALONE,"no"); mDateFormat=new SimpleDateFormat("yyyy-MM-dd"); mDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); } catch ( Exception e) { throw new RuntimeException(e); } }
Example 80
From project pluto, under directory /pluto-util/src/main/java/org/apache/pluto/util/descriptors/web/.
Source file: PlutoWebXmlRewriter.java

public void write(OutputStream dest) throws IOException { try { DOMSource domSource=new DOMSource(descriptor); StreamResult streamResult=new StreamResult(dest); TransformerFactory tf=TransformerFactory.newInstance(); Transformer transformer=tf.newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD,"xml"); if (descriptor.getDoctype() != null) { transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,descriptor.getDoctype().getPublicId()); transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,descriptor.getDoctype().getSystemId()); } transformer.setOutputProperty(OutputKeys.MEDIA_TYPE,"text/xml"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.transform(domSource,streamResult); } catch ( TransformerConfigurationException e) { throw new IOException(e.getMessage()); } catch ( TransformerException e) { throw new IOException(e.getMessage()); } }
Example 81
From project pomodoro4nb, under directory /src/org/matveev/pomodoro4nb/data/io/.
Source file: XMLPropertiesSerializer.java

private static String convertToString(final Document doc) throws TransformerConfigurationException, TransformerException { final DOMSource source=new DOMSource(doc); final Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); transformer.setOutputProperty(OutputKeys.METHOD,"xml"); transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); final StringWriter writer=new StringWriter(); final StreamResult result=new StreamResult(writer); transformer.transform(source,result); return writer.toString(); }
Example 82
From project Possom, under directory /core-api/src/main/java/no/sesat/search/view/velocity/.
Source file: URLVelocityTemplateLoader.java

private void internalWriteDocument(final Document d,final Writer w){ final DOMSource source=new DOMSource(d); final StreamResult result=new StreamResult(w); final TransformerFactory factory=TransformerFactory.newInstance(); try { final Transformer transformer=factory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); transformer.transform(source,result); } catch ( TransformerConfigurationException e) { throw new RuntimeException("Xml Parser: " + e); } catch ( TransformerException ignore) { LOG.debug("Ingoring the following ",ignore); } }
Example 83
/** * Convert a DOM tree into a String using transform * @param domDoc DOM object * @throws java.io.IOException I/O exception * @return XML as String */ public static String docToString2(Document domDoc) throws IOException { try { TransformerFactory transFact=TransformerFactory.newInstance(); Transformer trans=transFact.newTransformer(); trans.setOutputProperty(OutputKeys.INDENT,"no"); StringWriter sw=new StringWriter(); Result result=new StreamResult(sw); trans.transform(new DOMSource(domDoc),result); return sw.toString(); } catch ( Exception ex) { throw new IOException(String.format("Error converting from doc to string %s",ex.getMessage())); } }
Example 84
From project red5-mavenized, under directory /red5_base/src/main/java/org/red5/io/utils/.
Source file: XMLUtils.java

/** * Convert a DOM tree into a String using transform * @param domDoc DOM object * @throws java.io.IOException I/O exception * @return XML as String */ public static String docToString2(Document domDoc) throws IOException { try { TransformerFactory transFact=TransformerFactory.newInstance(); Transformer trans=transFact.newTransformer(); trans.setOutputProperty(OutputKeys.INDENT,"no"); StringWriter sw=new StringWriter(); Result result=new StreamResult(sw); trans.transform(new DOMSource(domDoc),result); return sw.toString(); } catch ( Exception ex) { throw new IOException(String.format("Error converting from doc to string %s",ex.getMessage())); } }
Example 85
/** * Convert a DOM tree into a String using transform * @param domDoc DOM object * @throws java.io.IOException I/O exception * @return XML as String */ public static String docToString2(Document domDoc) throws IOException { try { TransformerFactory transFact=TransformerFactory.newInstance(); Transformer trans=transFact.newTransformer(); trans.setOutputProperty(OutputKeys.INDENT,"no"); StringWriter sw=new StringWriter(); Result result=new StreamResult(sw); trans.transform(new DOMSource(domDoc),result); return sw.toString(); } catch ( Exception ex) { throw new IOException(String.format("Error converting from doc to string %s",ex.getMessage())); } }
Example 86
From project replication-benchmarker, under directory /src/main/java/jbenchmarker/trace/.
Source file: Trace2XML.java

/** * @param args */ public static void transformerXml(Document document,String fichier) throws TransformerConfigurationException, TransformerException { Source source=new DOMSource(document); File file=new File(fichier); Result resultat=new StreamResult(fichier); TransformerFactory fabrique=TransformerFactory.newInstance(); Transformer transformer=fabrique.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); transformer.transform(source,resultat); }
Example 87
From project repose, under directory /project-set/components/translation/src/main/java/com/rackspace/papi/components/translation/xslt/xmlfilterchain/.
Source file: XmlFilterChainExecutor.java

public XmlFilterChainExecutor(XmlFilterChain chain){ this.chain=chain; format.put(OutputKeys.METHOD,"xml"); format.put(OutputKeys.OMIT_XML_DECLARATION,"yes"); format.put(OutputKeys.ENCODING,"UTF-8"); format.put(OutputKeys.INDENT,"yes"); }
Example 88
From project RestFixture, under directory /src/main/java/smartrics/rest/fitnesse/fixture/support/.
Source file: Tools.java

public static String xPathResultToXmlString(Object result){ if (result == null) { return null; } try { StringWriter sw=new StringWriter(); Transformer serializer=TransformerFactory.newInstance().newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); serializer.setOutputProperty(OutputKeys.MEDIA_TYPE,"text/xml"); if (result instanceof NodeList) { serializer.transform(new DOMSource(((NodeList)result).item(0)),new StreamResult(sw)); } else if (result instanceof Node) { serializer.transform(new DOMSource((Node)result),new StreamResult(sw)); } else { return result.toString(); } return sw.toString(); } catch ( Exception e) { throw new RuntimeException("Transformation caused an exception",e); } }
Example 89
From project riot, under directory /common/src/org/riotfamily/common/xml/.
Source file: XmlUtils.java

public static String serialize(Node node){ try { TransformerFactory tf=TransformerFactory.newInstance(); Transformer transformer=tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); Source source=new DOMSource(node); StringWriter sw=new StringWriter(); Result result=new StreamResult(sw); transformer.transform(source,result); return sw.toString(); } catch ( TransformerException e) { throw new RuntimeException(e); } }
Example 90
public static void saveXML(Document doc,File file){ try { TransformerFactory tFactory=TransformerFactory.newInstance(); Transformer transformer=tFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4"); DOMSource source=new DOMSource(doc); StreamResult result=new StreamResult(file); transformer.transform(source,result); } catch ( Exception ex) { } }
Example 91
From project scape, under directory /xa-toolwrapper/src/main/java/eu/scape_project/xa/tw/gen/.
Source file: WsdlCreator.java

/** * Insert data types * @throws GeneratorException */ public void insertDataTypes() throws GeneratorException { File wsdlTemplate=new File(this.wsdlSourcePath); if (!wsdlTemplate.canRead()) { throw new GeneratorException("Unable to read WSDL Template file: " + this.wsdlSourcePath); } try { DocumentBuilderFactory docBuildFact=DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder=docBuildFact.newDocumentBuilder(); doc=docBuilder.parse(this.wsdlSourcePath); for ( Operation operation : operations) { createMessageDataTypes(operation); createSchemaDataTypes(operation); createOperation(doc,operation); createBinding(doc,operation); } Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING,"utf-8"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"no"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4"); DOMSource source=new DOMSource(doc); FileOutputStream fos=new FileOutputStream(this.wsdlTargetPath); StreamResult result=new StreamResult(fos); transformer.transform(source,result); fos.close(); if (!((new File(wsdlTargetPath)).exists())) { throw new GeneratorException("WSDL file has not been created successfully."); } } catch ( Exception ex) { logger.error("An exception occurred: " + ex.getMessage()); } }
Example 92
From project scoutdoc, under directory /main/src/scoutdoc/main/fetch/.
Source file: ScoutDocFetch.java

public static String prettyFormat(String input) throws TransformerException { Source xmlInput=new StreamSource(new StringReader(input)); StringWriter stringWriter=new StringWriter(); StreamResult xmlOutput=new StreamResult(stringWriter); TransformerFactory transformerFactory=TransformerFactory.newInstance(); transformerFactory.setAttribute("indent-number",2); Transformer transformer=transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.transform(xmlInput,xmlOutput); return xmlOutput.getWriter().toString(); }
Example 93
From project seage, under directory /seage-misc/src/main/java/org/seage/data/xml/.
Source file: XmlHelper.java

public static synchronized void writeXml(DataNode dataSet,OutputStream outputStream) throws Exception { TransformerFactory tFactory=TransformerFactory.newInstance(); Transformer transformer=tFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); DOMSource source=new DOMSource(dataSet.toXml()); StreamResult result=new StreamResult(outputStream); transformer.transform(source,result); }
Example 94
From project seamless, under directory /xml/src/main/java/org/seamless/xml/.
Source file: DOMParser.java

public Transformer createTransformer(String method,int indent,boolean standalone) throws ParserException { try { TransformerFactory transFactory=TransformerFactory.newInstance(); if (indent > 0) { try { transFactory.setAttribute("indent-number",indent); } catch ( IllegalArgumentException ex) { } } Transformer transformer=transFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,standalone ? "no" : "yes"); transformer.setOutputProperty(OutputKeys.INDENT,indent > 0 ? "yes" : "no"); if (indent > 0) transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",Integer.toString(indent)); transformer.setOutputProperty(OutputKeys.METHOD,method); return transformer; } catch ( Exception ex) { throw new ParserException(ex); } }
Example 95
From project security, under directory /external/src/main/java/org/jboss/seam/security/external/saml/.
Source file: SamlUtils.java

public static String getDocumentAsString(Document document){ Source source=new DOMSource(document); StringWriter sw=new StringWriter(); Result streamResult=new StreamResult(sw); try { Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); transformer.setOutputProperty(OutputKeys.INDENT,"no"); transformer.transform(source,streamResult); } catch ( TransformerException e) { throw new RuntimeException(e); } return sw.toString(); }
Example 96
From project ServalMapsDataMan, under directory /src/org/servalproject/maps/dataman/builders/.
Source file: KmlBuilder.java

/** * output the contents of the KML to a file * @throws BuildException if an error occurs during xml transformation our file writing */ public void outputToFile(PrintWriter printWriter) throws BuildException { try { TransformerFactory transFactory=TransformerFactory.newInstance(); Transformer transformer=transFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING,"utf-8"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"no"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); StreamResult result=new StreamResult(printWriter); DOMSource source=new DOMSource(xmlDoc); transformer.transform(source,result); } catch ( javax.xml.transform.TransformerException e) { throw new BuildException("unable to create the XML and output it to the file",e); } }
Example 97
From project server-main, under directory /src/main/java/org/powertac/server/.
Source file: CompetitionSetupService.java

private String nodeToString(Node node){ StringWriter sw=new StringWriter(); try { Transformer t=TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); t.setOutputProperty(OutputKeys.INDENT,"no"); t.transform(new DOMSource(node),new StreamResult(sw)); } catch ( TransformerException te) { log.error("nodeToString Transformer Exception " + te.toString()); } String result=sw.toString(); return result; }
Example 98
From project servicemix-utils, under directory /src/main/java/org/apache/servicemix/jbi/jaxp/.
Source file: SourceTransformer.java

/** * Converts the given input Source into the required result, using the specified encoding * @param source the input Source * @param result the output Result * @param charset the required charset, if you specify <code>null</code> the default charset will be used */ public void toResult(Source source,Result result,String charset) throws TransformerConfigurationException, TransformerException { if (source == null) { return; } if (charset == null) { charset=defaultCharset; } Transformer transformer=createTransfomer(); if (transformer == null) { throw new TransformerException("Could not create a transformer - JAXP is misconfigured!"); } transformer.setOutputProperty(OutputKeys.ENCODING,charset); transformer.transform(source,result); }
Example 99
From project skalli, under directory /org.eclipse.skalli.api/src/main/java/org/eclipse/skalli/commons/.
Source file: XMLUtils.java

private static void transform(Document doc,StreamResult result) throws TransformerException { DOMSource source=new DOMSource(doc); Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.transform(source,result); }
Example 100
From project skmclauncher, under directory /src/main/java/com/sk89q/mclauncher/util/.
Source file: XMLUtil.java

/** * Writes out XML. * @param doc document * @param file target file * @throws TransformerException on transformer error */ public static void writeXml(Document doc,File file) throws TransformerException { TransformerFactory transformerFactory=TransformerFactory.newInstance(); Transformer transformer=transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); DOMSource source=new DOMSource(doc); StreamResult result=new StreamResult(file); transformer.transform(source,result); }
Example 101
From project spring-data-jdbc-ext, under directory /spring-data-oracle-test/src/test/java/org/springframework/data/jdbc/jms/xml/.
Source file: MessageDelegate.java

private String xmlDocumentToString(Document xmlDoc) throws TransformerFactoryConfigurationError { Transformer transformer=null; try { transformer=TransformerFactory.newInstance().newTransformer(); } catch ( TransformerConfigurationException e) { e.printStackTrace(); } transformer.setOutputProperty(OutputKeys.INDENT,"no"); StreamResult result=new StreamResult(new StringWriter()); DOMSource source=new DOMSource(xmlDoc); try { transformer.transform(source,result); } catch ( TransformerException e) { e.printStackTrace(); } String xmlString=result.getWriter().toString(); return xmlString; }
Example 102
From project spring-integration-extensions, under directory /spring-integration-xquery/src/main/java/org/springframework/integration/xquery/support/.
Source file: AbstractXQueryResultMapper.java

/** * Transforms the given {@link Node} to a String * @param n * @return * @throws TransformerException */ protected String transformNodeToString(Node n) throws TransformerException { String value; StringWriter writer=new StringWriter(); Transformer transformer=TransformerFactory.newInstance().newTransformer(); if (formatOutput) { transformer.setOutputProperty(OutputKeys.INDENT,"yes"); } transformer.transform(new DOMSource(n),new StreamResult(writer)); value=writer.toString(); return value; }
Example 103
From project spring-integration-samples, under directory /basic/testing-examples/src/main/java/org/springframework/integration/samples/testing/externalgateway/.
Source file: WeatherMarshaller.java

public static final void writeXml(Document document){ Transformer transformer=createIndentingTransformer(); transformer.setOutputProperty(OutputKeys.METHOD,"xml"); try { StringResult streamResult=new StringResult(); transformer.transform(new DOMSource(document),streamResult); } catch ( Exception ex) { throw new IllegalStateException(ex); } }
Example 104
From project Starfish, under directory /starfish/src/profile/edu/duke/starfish/profile/utils/.
Source file: XMLBaseParser.java

/** * Create an XML DOM representing the object and write out to the provided output stream * @param object the object to export in the XML stream * @param out the output stream */ public void exportXML(T object,PrintStream out){ Document doc=null; try { System.setProperty("javax.xml.parsers.DocumentBuilderFactory","com.sun.org.apache.xerces." + "internal.jaxp.DocumentBuilderFactoryImpl"); doc=DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch ( ParserConfigurationException e) { LOG.error("Unable to export XML file",e); } exportXML(object,doc); DOMSource source=new DOMSource(doc); StreamResult result=new StreamResult(out); try { Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.transform(source,result); } catch ( TransformerConfigurationException e) { LOG.error("Unable to export XML file",e); } catch ( TransformerException e) { LOG.error("Unable to export XML file",e); } }
Example 105
From project streams, under directory /stream-plugin/src/main/java/com/rapidminer/stream/util/.
Source file: OperatorList.java

public void insertIntoOperatorsXml(File source,File file) throws Exception { DocumentBuilder builder=DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc=builder.parse(source); insertIntoDom(doc); Transformer trans=TransformerFactory.newInstance().newTransformer(); trans.setOutputProperty(OutputKeys.STANDALONE,"no"); trans.setOutputProperty(OutputKeys.ENCODING,"utf-8"); trans.setOutputProperty(OutputKeys.VERSION,"1.0"); trans.setOutputProperty(OutputKeys.INDENT,"yes"); trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); OutputStream out=new FileOutputStream(file); trans.transform(new DOMSource(doc),new StreamResult(out)); out.close(); }
Example 106
From project substeps-eclipse-plugin, under directory /com.technophobia.substeps.testlauncher/src/main/java/com/technophobia/substeps/model/serialize/.
Source file: SubstepsModelExporter.java

public static void exportTestRunSession(final SubstepsRunSession testRunSession,final OutputStream out) throws TransformerFactoryConfigurationError, TransformerException { final Transformer transformer=TransformerFactory.newInstance().newTransformer(); final InputSource inputSource=new InputSource(); final SAXSource source=new SAXSource(new SubstepsRunSessionSerializer(testRunSession),inputSource); final StreamResult result=new StreamResult(out); transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); try { transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount","2"); } catch ( final IllegalArgumentException e) { } transformer.transform(source,result); }
Example 107
From project sveditor, under directory /sveditor/plugins/net.sf.sveditor.core/src/net/sf/sveditor/core/db/project/.
Source file: SVProjectFileWrapper.java

public void toStream(OutputStream out){ SAXTransformerFactory tf=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); try { marshall(); } catch ( Exception e) { e.printStackTrace(); } try { DOMSource ds=new DOMSource(fDocument); StreamResult sr=new StreamResult(out); tf.setAttribute("indent-number",new Integer(2)); TransformerHandler th=tf.newTransformerHandler(); Properties format=new Properties(); format.put(OutputKeys.METHOD,"xml"); format.put(OutputKeys.ENCODING,"UTF-8"); format.put(OutputKeys.INDENT,"yes"); th.getTransformer().setOutputProperties(format); th.setResult(sr); th.getTransformer().transform(ds,sr); } catch ( Exception e) { e.printStackTrace(); } }
Example 108
/** * Saves the configuration to the file it was loaded from, or the default config file if it has not been loaded at all. <p>Note: This does not save the config to the default config file. To do that, call <code>save(env.getDefaultConfigFile());</code> * @throws ConfigException */ public void save() throws ConfigException { saveDOM(self); doc.getDocumentElement().normalize(); try { FileOutputStream out=new FileOutputStream(configFile); DOMSource ds=new DOMSource(doc); StreamResult sr=new StreamResult(new OutputStreamWriter(out,"utf-8")); TransformerFactory tf=TransformerFactory.newInstance(); tf.setAttribute("indent-number",4); Transformer trans=tf.newTransformer(); trans.setOutputProperty(OutputKeys.INDENT,"yes"); trans.transform(ds,sr); out.close(); } catch ( Exception e) { throw new ConfigException(e); } }
Example 109
From project tapestry-tldgen, under directory /src/main/java/fr/exanpe/tapestry/tldgen/javadoc/writer/.
Source file: JavadocTmpFileWriter.java

/** * Write the element into the given writer * @param infos the javadoc information about the components * @throws IOException * @throws ParserConfigurationException * @throws TransformerException */ public void write(ComponentsInfoBean infos) throws IOException, ParserConfigurationException, TransformerException { try { DocumentBuilderFactory dbfac=DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder=dbfac.newDocumentBuilder(); Document doc=docBuilder.newDocument(); Element root=doc.createElement("components"); doc.appendChild(root); writeElements(doc,root,infos); TransformerFactory transfac=TransformerFactory.newInstance(); Transformer trans=transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"no"); trans.setOutputProperty(OutputKeys.INDENT,"yes"); trans.setOutputProperty(OutputKeys.ENCODING,sourceEncoding); StreamResult result=new StreamResult(writer); DOMSource source=new DOMSource(doc); trans.transform(source,result); } finally { writer.close(); } }
Example 110
From project terraform, under directory /src/main/java/org/urbancode/terraform/xml/.
Source file: XmlWrite.java

public Transformer createTransformer() throws TransformerConfigurationException { TransformerFactory transFactory=TransformerFactory.newInstance(); Transformer transformer=transFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4"); return transformer; }
Example 111
From project teuria, under directory /Teuria/src/il/co/zak/gplv3/hamakor/teuria/.
Source file: QuestionDescriptionTransform.java

/** * Exports xml string from the DOM data structure * @param doc - DOM data structure representing the document * @return String containing the corresponding xml. */ static public String getStringFromDoc(Document doc){ try { DOMSource domSource=new DOMSource(doc); StringWriter writer=new StringWriter(); StreamResult result=new StreamResult(writer); TransformerFactory tf=TransformerFactory.newInstance(); Transformer transformer=tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); transformer.transform(domSource,result); writer.flush(); return writer.toString(); } catch ( TransformerException ex) { ex.printStackTrace(); return null; } }
Example 112
From project thinklab, under directory /src/main/java/org/integratedmodelling/utils/xml/.
Source file: XMLDocument.java

public void flush() throws ThinklabIOException { Transformer transformer=null; try { transformer=TransformerFactory.newInstance().newTransformer(); } catch ( Exception e) { throw new ThinklabIOException(e); } transformer.setOutputProperty(OutputKeys.INDENT,"yes"); StreamResult result=new StreamResult(docFile); DOMSource source=new DOMSource(dom); try { transformer.transform(source,result); } catch ( TransformerException e) { throw new ThinklabIOException(e); } }
Example 113
From project tika, under directory /tika-app/src/main/java/org/apache/tika/cli/.
Source file: TikaCLI.java

/** * Returns a transformer handler that serializes incoming SAX events to XHTML or HTML (depending the given method) using the given output encoding. * @see <a href="https://issues.apache.org/jira/browse/TIKA-277">TIKA-277</a> * @param output output stream * @param method "xml" or "html" * @param encoding output encoding,or <code>null</code> for the platform default * @return {@link System#out} transformer handler * @throws TransformerConfigurationException if the transformer can not be created */ private static TransformerHandler getTransformerHandler(OutputStream output,String method,String encoding,boolean prettyPrint) throws TransformerConfigurationException { SAXTransformerFactory factory=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); TransformerHandler handler=factory.newTransformerHandler(); handler.getTransformer().setOutputProperty(OutputKeys.METHOD,method); handler.getTransformer().setOutputProperty(OutputKeys.INDENT,prettyPrint ? "yes" : "no"); if (encoding != null) { handler.getTransformer().setOutputProperty(OutputKeys.ENCODING,encoding); } handler.setResult(new StreamResult(output)); return handler; }
Example 114
From project Twister, under directory /src/client/userinterface/java/src/.
Source file: Repository.java

public static void createGeneralPluginConf(){ try { DocumentBuilderFactory documentBuilderFactory=DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder=documentBuilderFactory.newDocumentBuilder(); Document document=documentBuilder.newDocument(); TransformerFactory transformerFactory=TransformerFactory.newInstance(); Transformer transformer=transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4"); DOMSource source=new DOMSource(document); Element rootElement=document.createElement("Root"); document.appendChild(rootElement); File file=new File(Repository.PLUGINSLOCALGENERALCONF); Result result=new StreamResult(file); transformer.transform(source,result); c.cd(Repository.USERHOME + "/twister/config/"); System.out.println("Saving to: " + Repository.USERHOME + "/twister/config/"); FileInputStream in=new FileInputStream(file); c.put(in,file.getName()); in.close(); } catch ( Exception e) { System.out.println("There was a problem in generating Plugins general config"); e.printStackTrace(); } }
Example 115
From project uomo, under directory /bundles/org.eclipse.uomo.xml/src/main/java/org/eclipse/uomo/xml/impl/.
Source file: DOMXMLWriter.java

public void endCommentBlock() throws IOException { if (commentBlock == null) throw new IOException("Cannot close a comment block when none existed"); else if (getCurrentElement().getParentNode() != commentBlock) throw new IOException("Cannot close a comment block when it's still opened"); ByteArrayOutputStream temp=new ByteArrayOutputStream(); try { NodeList children=getCurrentElement().getChildNodes(); DocumentFragment frag=doc.createDocumentFragment(); for (int i=0; i < children.getLength(); i++) frag.appendChild(children.item(i)); Transformer trans=TransformerFactory.newInstance().newTransformer(); trans.setOutputProperty(OutputKeys.STANDALONE,"no"); trans.setOutputProperty(OutputKeys.INDENT,"yes"); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); trans.transform(new DOMSource(frag),new StreamResult(temp)); } catch ( Exception e) { throw new IOException(e.getLocalizedMessage()); } finally { current.pop(); commentBlock=null; } comment(temp.toString(),true); }
Example 116
From project utils_1, under directory /src/main/java/net/pterodactylus/util/xml/.
Source file: XML.java

/** * Writes the given document to the given writer. * @param document The document to write * @param writer The writer to write the document to * @param preamble <code>true</code> to include the XML header, <code>false</code> to not include it */ public static void writeToOutputStream(Document document,Writer writer,boolean preamble){ Result transformResult=new StreamResult(writer); Source documentSource=new DOMSource(document); try { Transformer transformer=getTransformerFactory().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,preamble ? "no" : "yes"); transformer.transform(documentSource,transformResult); } catch ( TransformerConfigurationException tce1) { logger.log(Level.WARNING,"Could create Transformer.",tce1); } catch ( TransformerException te1) { logger.log(Level.WARNING,"Could not transform Document.",te1); } }
Example 117
public static void getStringFromXML(Node node,String dtdFilename,Writer outputWriter) throws TransformerException { File dtdFile=null; String workingPath=null; if (dtdFilename != null) { dtdFile=new File(dtdFilename); workingPath=System.setProperty("user.dir",dtdFile.getAbsoluteFile().getParent()); } try { if (node instanceof Document) node=((Document)node).getDocumentElement(); TransformerFactory tranFact=TransformerFactory.newInstance(); Transformer tf=tranFact.newTransformer(); if (dtdFile != null) { tf.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,dtdFile.getName()); tf.setOutputProperty(OutputKeys.INDENT,"yes"); } Source src=new DOMSource(node); Result dest=new StreamResult(outputWriter); tf.transform(src,dest); } finally { if (workingPath != null) System.setProperty("user.dir",workingPath); } }
Example 118
From project wikbook, under directory /core/src/main/java/org/wikbook/core/xml/.
Source file: XML.java

public static TransformerHandler createTransformerHandler(OutputFormat doctype) throws TransformerConfigurationException { SAXTransformerFactory factory=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); if (doctype.getIndent() != null) { factory.setAttribute("indent-number",doctype.getIndent()); } TransformerHandler handler=factory.newTransformerHandler(); Transformer transformer=handler.getTransformer(); if (doctype.getIndent() != null) { transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",Integer.toString(doctype.getIndent())); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); } else { transformer.setOutputProperty(OutputKeys.INDENT,"no"); } transformer.setOutputProperty(OutputKeys.METHOD,"xml"); transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); if (doctype.isEmitDoctype()) { if (doctype.getPublicId() != null) { transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,doctype.getPublicId()); } if (doctype.getSystemId() != null) { transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,doctype.getSystemId()); } } handler.getTransformer().setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,doctype.isEmitDoctype() ? "no" : "yes"); return handler; }
Example 119
From project XACML-Policy-Analysis-Tool, under directory /PolicyAnalysisTool/src/org/linkality/xacmlanalysr/.
Source file: SemanticPolicyAnalyser.java

/** * Convert XML DOM document to a string. * @param document XML DOM document * @return XML string * @throws TransformerException */ public static String toString(Document document) throws TransformerException { StringWriter stringWriter=new StringWriter(); StreamResult streamResult=new StreamResult(stringWriter); TransformerFactory transformerFactory=TransformerFactory.newInstance(); Transformer transformer=transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); transformer.setOutputProperty(OutputKeys.METHOD,"xml"); transformer.transform(new DOMSource(document.getDocumentElement()),streamResult); return stringWriter.toString(); }
Example 120
From project xcode-maven-plugin, under directory /modules/xcode-maven-plugin/src/main/java/com/sap/prd/mobile/ios/mios/.
Source file: DomUtils.java

/** * Serializes a DOM. The OutputStream handed over to this method is not closed inside this method. */ static void serialize(final Document doc,final OutputStream os,final String encoding) throws TransformerFactoryConfigurationError, TransformerException, IOException { if (doc == null) throw new IllegalArgumentException("No document provided."); if (os == null) throw new IllegalArgumentException("No output stream provided"); if (encoding == null || encoding.isEmpty()) throw new IllegalArgumentException("No encoding provided."); final TransformerFactory transformerFactory=TransformerFactory.newInstance(); transformerFactory.setAttribute("indent-number",new Integer(2)); final Transformer t=transformerFactory.newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"no"); t.setOutputProperty(OutputKeys.METHOD,"xml"); t.setOutputProperty(OutputKeys.INDENT,"yes"); t.setOutputProperty(OutputKeys.ENCODING,encoding); final OutputStreamWriter osw=new OutputStreamWriter(os,encoding); t.transform(new DOMSource(doc),new StreamResult(osw)); osw.flush(); }
Example 121
From project xwiki-commons, under directory /xwiki-commons-core/xwiki-commons-extension/xwiki-commons-extension-api/src/main/java/org/xwiki/extension/repository/internal/local/.
Source file: DefaultExtensionSerializer.java

@Override public void saveDescriptor(LocalExtension extension,OutputStream fos) throws ParserConfigurationException, TransformerException { DocumentBuilder documentBuilder=this.documentBuilderFactory.newDocumentBuilder(); Document document=documentBuilder.newDocument(); Element extensionElement=document.createElement("extension"); document.appendChild(extensionElement); addElement(document,extensionElement,ELEMENT_ID,extension.getId().getId()); addElement(document,extensionElement,ELEMENT_VERSION,extension.getId().getVersion().getValue()); addElement(document,extensionElement,ELEMENT_TYPE,extension.getType()); addElement(document,extensionElement,ELEMENT_NAME,extension.getName()); addElement(document,extensionElement,ELEMENT_SUMMARY,extension.getSummary()); addElement(document,extensionElement,ELEMENT_DESCRIPTION,extension.getDescription()); addElement(document,extensionElement,ELEMENT_WEBSITE,extension.getWebSite()); addFeatures(document,extensionElement,extension); addAuthors(document,extensionElement,extension); addLicenses(document,extensionElement,extension); addDependencies(document,extensionElement,extension); addProperties(document,extensionElement,extension.getProperties()); TransformerFactory transfac=TransformerFactory.newInstance(); Transformer trans=transfac.newTransformer(); trans.setOutputProperty(OutputKeys.INDENT,"yes"); DOMSource source=new DOMSource(document); Result result=new StreamResult(fos); trans.transform(source,result); }
Example 122
From project yanel, under directory /src/test/junit/org/wyona/yanel/core/serialization/.
Source file: SerializerFactoryTest.java

private String serializedUsingJAXPAPI(String s,String... outputProps){ ByteArrayOutputStream baos=new ByteArrayOutputStream(); SAXTransformerFactory thFactory=(SAXTransformerFactory)TransformerFactory.newInstance(); try { final TransformerHandler idth=thFactory.newTransformerHandler(); idth.setResult(new StreamResult(baos)); Properties outputProperties=collectProperties(outputProps); idth.getTransformer().setOutputProperties(outputProperties); return serialize(s,idth,baos,outputProperties.getProperty(OutputKeys.ENCODING)); } catch ( Exception e) { throw new RuntimeException(e); } }
Example 123
From project zen-project, under directory /zen-base/src/main/java/com/nominanuda/xml/.
Source file: SAXPipeline.java

public SAXPipeline complete(){ Check.illegalstate.assertFalse(completed); completed=true; Collections.reverse(components); if (outputProperties.isEmpty()) { outputProperties.put(OutputKeys.INDENT,"yes"); outputProperties.put(OutputKeys.OMIT_XML_DECLARATION,"yes"); } return this; }
Example 124
From project zencoder-java, under directory /src/main/java/de/bitzeche/video/transcoding/zencoder/util/.
Source file: XmlUtility.java

public static String xmltoString(final Document document) throws TransformerException { StringWriter stringWriter=new StringWriter(); StreamResult streamResult=new StreamResult(stringWriter); TransformerFactory transformerFactory=TransformerFactory.newInstance(); Transformer transformer=transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); transformer.setOutputProperty(OutputKeys.METHOD,"xml"); transformer.transform(new DOMSource(document.getDocumentElement()),streamResult); return stringWriter.toString(); }
Example 125
From project zencoder-java_1, under directory /src/main/java/de/bitzeche/video/transcoding/zencoder/util/.
Source file: XmlUtility.java

public static String xmltoString(final Document document) throws TransformerException { StringWriter stringWriter=new StringWriter(); StreamResult streamResult=new StreamResult(stringWriter); TransformerFactory transformerFactory=TransformerFactory.newInstance(); Transformer transformer=transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","2"); transformer.setOutputProperty(OutputKeys.METHOD,"xml"); transformer.transform(new DOMSource(document.getDocumentElement()),streamResult); return stringWriter.toString(); }