List of usage examples for javax.xml.transform OutputKeys ENCODING
String ENCODING
To view the source code for javax.xml.transform OutputKeys ENCODING.
Click Source Link
From source file:com.eucalyptus.imaging.manifest.DownloadManifestFactory.java
private static final String nodeToString(Node node, boolean addDeclaration) throws Exception { Transformer tf = TransformerFactory.newInstance().newTransformer(); tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); if (!addDeclaration) tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); Writer out = new StringWriter(); tf.transform(new DOMSource(node), new StreamResult(out)); return out.toString(); }
From source file:net.sourceforge.eclipsetrader.ats.Repository.java
protected void saveDocument(Document document, String path, String name) { try {/* w ww . j ava 2s .co m*/ TransformerFactory factory = TransformerFactory.newInstance(); try { factory.setAttribute("indent-number", new Integer(4)); } catch (Exception e) { } Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http\u003a//xml.apache.org/xslt}indent-amount", "4"); DOMSource source = new DOMSource(document); File file = new File(Platform.getLocation().toFile(), path); file.mkdirs(); file = new File(file, name); BufferedWriter out = new BufferedWriter(new FileWriter(file)); StreamResult result = new StreamResult(out); transformer.transform(source, result); out.flush(); out.close(); } catch (Exception e) { log.error(e.toString(), e); } }
From source file:eu.impact_project.iif.tw.gen.DeploymentCreator.java
/** * Insert data types// w w w . ja va 2s . co m * @throws GeneratorException */ public void createPom() throws GeneratorException { File wsdlTemplate = new File(this.pomAbsPath); if (!wsdlTemplate.canRead()) { throw new GeneratorException("Unable to read pom.xml template file: " + this.pomAbsPath); } try { DocumentBuilderFactory docBuildFact = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuildFact.newDocumentBuilder(); doc = docBuilder.parse(this.pomAbsPath); NodeList profilesNodes = doc.getElementsByTagName("profiles"); Node firstProfilesNode = profilesNodes.item(0); List<Deployref> dks = service.getDeployto().getDeployref(); NodeList executionsNode = doc.getElementsByTagName("executions"); Node thirdExecutionsNode = executionsNode.item(2); for (Deployref dk : dks) { boolean isDefaultDeployment = dk.isDefault(); Deployment d = (Deployment) dk.getRef(); String host = d.getHost(); String id = d.getId(); //<profile> // <id>deployment1</id> // <properties> // <tomcat.manager.url>http://localhost:8080/manager</tomcat.manager.url> // <tomcat.user>tomcat</tomcat.user> // <tomcat.password>TxF781!P</tomcat.password> // <war.suffix>deployment1</war.suffix> // </properties> //</profile> //<profile> // <id>deployment2</id> // <properties> // <tomcat.manager.url>http://localhost:8080/manager</tomcat.manager.url> // <tomcat.user>tomcat</tomcat.user> // <tomcat.password>TxF781!P</tomcat.password> // <war.suffix>deployment2</war.suffix> // </properties> //</profile> Element profileElm = doc.createElement("profile"); if (isDefaultDeployment) { Element activationElm = doc.createElement("activation"); Element activeByDefaultElm = doc.createElement("activeByDefault"); activeByDefaultElm.setTextContent("true"); activationElm.appendChild(activeByDefaultElm); profileElm.appendChild(activationElm); } firstProfilesNode.appendChild(profileElm); Element idElm = doc.createElement("id"); idElm.setTextContent(d.getId()); profileElm.appendChild(idElm); Element propertiesElm = doc.createElement("properties"); profileElm.appendChild(propertiesElm); List<Port> ports = d.getPorts().getPort(); String port = "8080"; String type = "http"; for (Port p : ports) { if (p.getType().equals("http")) { port = String.valueOf(p.getValue()); type = p.getType(); } } Element tomcatManagerUrlElm = doc.createElement("tomcat.manager.url"); String managerPath = d.getManager().getPath(); managerPath = (managerPath != null && !managerPath.isEmpty()) ? managerPath : "manager"; tomcatManagerUrlElm.setTextContent(type + "://" + d.getHost() + ":" + port + "/" + managerPath); propertiesElm.appendChild(tomcatManagerUrlElm); Element tomcatUserPropElm = doc.createElement("tomcat.user"); Manager manager = d.getManager(); tomcatUserPropElm.setTextContent(manager.getUser()); propertiesElm.appendChild(tomcatUserPropElm); Element tomcatPasswordPropElm = doc.createElement("tomcat.password"); tomcatPasswordPropElm.setTextContent(manager.getPassword()); propertiesElm.appendChild(tomcatPasswordPropElm); Element warSuffixElm = doc.createElement("war.suffix"); warSuffixElm.setTextContent(d.getId()); propertiesElm.appendChild(warSuffixElm); //<execution> // <id>package-deployment1</id> // <phase>package</phase> // <configuration> // <classifier>deployment1</classifier> // <webappDirectory>${project.build.directory}/${project.build.finalName}_deployment1</webappDirectory> // <webResources> // <resource> // <directory>src/env/deployment1</directory> // </resource> // </webResources> // </configuration> // <goals> // <goal>war</goal> // </goals> //</execution> Element executionElm = doc.createElement("execution"); Element id2Elm = doc.createElement("id"); id2Elm.setTextContent("package-" + d.getId()); executionElm.appendChild(id2Elm); Element phaseElm = doc.createElement("phase"); phaseElm.setTextContent("package"); executionElm.appendChild(phaseElm); Element configurationElm = doc.createElement("configuration"); executionElm.appendChild(configurationElm); Element classifierElm = doc.createElement("classifier"); classifierElm.setTextContent(d.getId()); configurationElm.appendChild(classifierElm); Element webappDirectoryElm = doc.createElement("webappDirectory"); webappDirectoryElm .setTextContent("${project.build.directory}/${project.build.finalName}_" + d.getId()); configurationElm.appendChild(webappDirectoryElm); Element webResourcesElm = doc.createElement("webResources"); Element resourceElm = doc.createElement("resource"); Element directoryElm = doc.createElement("directory"); directoryElm.setTextContent("src/env/" + d.getId()); resourceElm.appendChild(directoryElm); webResourcesElm.appendChild(resourceElm); configurationElm.appendChild(webResourcesElm); Element goalsElm = doc.createElement("goals"); executionElm.appendChild(goalsElm); Element goalElm = doc.createElement("goal"); goalElm.setTextContent("war"); goalsElm.appendChild(goalElm); thirdExecutionsNode.appendChild(executionElm); if (isDefaultDeployment) { NodeList directories = doc.getElementsByTagName("directory"); Node directoryNode = directories.item(0); directoryNode.setTextContent("src/env/" + d.getId()); } // Create different environment dependent configuration files. // Deployment environment dependent files will be stored in // src/env and will then be activated by choosing the corresponding // profile during the corresponding maven phase. // E.g. mvn tomcat:redeploy -P deployment1 // will replace the deployment dependent files by the ones // available under src/env/deployment1. String generatedDir = st.getGenerateDir(); String projMidfix = st.getProjectMidfix(); String projDir = st.getProjectDirectory(); String servDir = FileUtil.makePath(generatedDir, projDir, "src/env", d.getId(), "WEB-INF/services", projMidfix, "META-INF"); FileUtils.forceMkdir(new File(servDir)); String sxmlFile = FileUtil.makePath(generatedDir, projDir, "src/main/webapp/WEB-INF/services", st.getProjectMidfix(), "META-INF") + "services.xml"; GenericCode deplDepServXmlCode = new GenericCode(sxmlFile); //<parameter name="cliCommand1">${clicmd}</parameter> //<parameter name="processingUnit">${tomcat_public_procunitid}</parameter> //<parameter name="publicHttpAccessDir">${tomcat_public_http_access_dir}</parameter> //<parameter name="publicHttpAccessUrl">${tomcat_public_http_access_url}</parameter> //<parameter name="serviceUrlFilter">${service_url_filter}</parameter> List<Operation> operations = service.getOperations().getOperation(); for (Operation operation : operations) { String command = operation.getCommand(); String toolsbasedir = d.getToolsbasedir(); if (toolsbasedir != null && !toolsbasedir.equals("")) { command = toolsbasedir + command; } deplDepServXmlCode.put("cli_cmd_" + String.valueOf(operation.getOid()), command); } deplDepServXmlCode.put("tomcat_public_procunitid", d.getIdentifier()); Dataexchange de = d.getDataexchange(); String accessDir = FileUtil.makePath(de.getAccessdir()); String accessUrl = de.getAccessurl(); deplDepServXmlCode.put("tomcat_public_http_access_dir", accessDir); deplDepServXmlCode.put("tomcat_public_http_access_url", accessUrl); // TODO: filter //deplDepServXmlCode.put("service_url_filter", ); deplDepServXmlCode.evaluate(); deplDepServXmlCode.create(servDir + "services.xml"); logger.debug("Writing: " + servDir + "services.xml"); if (isDefaultDeployment) { defaultDeplServicesFile = servDir + "services.xml"; defaultServicesFile = sxmlFile; } // source String htmlIndexSourcePath = FileUtil.makePath(generatedDir, projDir, "src/main", "webapp") + "index.html"; // substitution GenericCode htmlSourceIndexCode = new GenericCode(htmlIndexSourcePath); htmlSourceIndexCode.put("service_description", service.getDescription()); htmlSourceIndexCode.put("tomcat_public_host", d.getHost()); htmlSourceIndexCode.put("tomcat_public_http_port", port); // target String htmlIndexDir = FileUtil.makePath(generatedDir, projDir, "src/env", d.getId()); FileUtils.forceMkdir(new File(htmlIndexDir)); String htmlIndexTargetPath = FileUtil.makePath(generatedDir, projDir, "src/env", d.getId()) + "index.html"; htmlSourceIndexCode.create(htmlIndexTargetPath); if (isDefaultDeployment) { this.defaultDeplHtmlFile = htmlIndexTargetPath; this.defaultHtmlFile = htmlIndexSourcePath; } // source String wsdlSourcePath = FileUtil.makePath(generatedDir, projDir, "src/main", "webapp") + st.getProjectMidfix() + ".wsdl"; // substitution GenericCode wsdlSourceCode = new GenericCode(wsdlSourcePath); wsdlSourceCode.put("tomcat_public_host", d.getHost()); wsdlSourceCode.put("tomcat_public_http_port", port); // target String wsdlDir = FileUtil.makePath(generatedDir, projDir, "src/env", d.getId()); FileUtils.forceMkdir(new File(wsdlDir)); String wsdlTargetPath = FileUtil.makePath(generatedDir, projDir, "src/env", d.getId()) + st.getProjectMidfix() + ".wsdl"; wsdlSourceCode.create(wsdlTargetPath); if (isDefaultDeployment) { this.defaultDeplWsdlFile = wsdlTargetPath; this.defaultWsdlFile = wsdlSourcePath; } } if (defaultDeplServicesFile != null && !defaultDeplServicesFile.isEmpty()) { FileUtils.copyFile(new File(defaultDeplServicesFile), new File(defaultServicesFile)); FileUtils.copyFile(new File(this.defaultDeplHtmlFile), new File(this.defaultHtmlFile)); FileUtils.copyFile(new File(this.defaultDeplWsdlFile), new File(this.defaultWsdlFile)); } 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.pomAbsPath); StreamResult result = new StreamResult(fos); transformer.transform(source, result); fos.close(); } catch (Exception ex) { logger.error("An exception occurred: " + ex.getMessage()); } }
From source file:es.upm.fi.dia.oeg.sitemap4rdf.Generator.java
/** * Save as zip file the given XML Document using a given file name * @param fileName the name of the generated zip file * @param doc the XML document to store in the zip file *///from w ww . ja v a 2s . c o m protected void saveZipFile(String fileName, Document doc) { String outfileName = fileName + zipFileExtension; if (outputDir != null && !outputDir.isEmpty()) outfileName = outputDir + outfileName; try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Source xmlSource = new DOMSource(doc); Result outputTarget = new StreamResult(new OutputStreamWriter(outputStream, DEFAULT_ENCODING)); TransformerFactory tf = TransformerFactory.newInstance(); tf.setAttribute(xmlAttributeIdentNumber, new Integer(4)); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, DEFAULT_ENCODING); transformer.setOutputProperty("{http://xml. customer .org/xslt}indent-amount", "4"); transformer.transform(xmlSource, outputTarget); InputStream in = new ByteArrayInputStream(outputStream.toString(DEFAULT_ENCODING).getBytes()); byte[] buf = new byte[1024]; //create the zip file GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(outfileName)); //Transfer bytes from the inputstream to the ZIP int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } //Complete the entry in.close(); //complete the zip file out.finish(); out.close(); } catch (FileNotFoundException e) { logger.debug("FileNotFoundException ", e); System.err.println(e.getMessage()); System.exit(3); } catch (IOException e) { logger.debug("IOException ", e); System.err.println(e.getMessage()); System.exit(3); } catch (TransformerConfigurationException e) { logger.debug("TransformerConfigurationException ", e); System.err.println(e.getMessage()); System.exit(3); } catch (TransformerException e) { logger.debug("TransformerException ", e); System.err.println(e.getMessage()); System.exit(3); } catch (TransformerFactoryConfigurationError e) { logger.debug("TransformerFactoryConfigurationError ", e); System.err.println(e.getMessage()); System.exit(3); } }
From source file:br.org.indt.ndg.server.client.TemporaryOpenRosaBussinessDelegate.java
/********** Uploading OpenRosa Surveys and Results **********/ public boolean parseAndPersistSurvey(InputStreamReader inputStreamReader, String contentType) throws IOException { String surveyString = parseMultipartEncodedFile(inputStreamReader, contentType, "filename"); String surveyId = null;/*from w w w. jav a 2 s . com*/ String surveyIdOriginal = null; Document surveyDomDocument = null; ByteArrayInputStream streamToParse = new ByteArrayInputStream(surveyString.getBytes("UTF-8")); try { surveyDomDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(streamToParse); } catch (SAXException e) { e.printStackTrace(); return false; } catch (ParserConfigurationException e) { e.printStackTrace(); return false; } finally { streamToParse.close(); } NodeList dataNodeList = surveyDomDocument.getElementsByTagName("data"); if (dataNodeList.getLength() != 1) { return false; // there MUST be exactly 1 <data> node } else { Element dataElement = (Element) dataNodeList.item(0); Random rand = new Random(System.currentTimeMillis()); int newId = rand.nextInt(Integer.MAX_VALUE); surveyId = String.valueOf(newId); surveyIdOriginal = dataElement.getAttribute("id"); dataElement.setAttribute("id", String.valueOf(newId)); StringWriter stringWriter = null; try { Source source = new DOMSource(surveyDomDocument); stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "no"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.transform(source, result); surveyString = stringWriter.getBuffer().toString(); } catch (Exception e) { e.printStackTrace(); return false; } finally { stringWriter.close(); } log.info("========================"); log.info("Original Survey Id: " + surveyIdOriginal); log.info("New Survey Id: " + surveyId); log.info("========================"); } return persistSurvey(surveyString, surveyId, surveyIdOriginal); }
From source file:es.juntadeandalucia.panelGestion.negocio.utiles.Utils.java
public static String documentToString(Document document) throws TransformerException { StringWriter sw = new StringWriter(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform(new DOMSource(document), new StreamResult(sw)); return sw.toString(); }
From source file:es.juntadeandalucia.panelGestion.negocio.utiles.Utils.java
public static byte[] documentToByte(Document document) throws TransformerException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform(new DOMSource(document), new StreamResult(bos)); return bos.toByteArray(); }
From source file:gov.nasa.ensemble.common.io.FileUtilities.java
public static void saveDocument(Document doc, Result result) throws TransformerFactoryConfigurationError, TransformerException { Source source = new DOMSource(doc); // Write the DOM document to the file Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "ASCII"); transformer.transform(source, result); }
From source file:com.offbynull.portmapper.upnpigd.UpnpIgdController.java
private Map<String, String> parseResponseXml(String expectedTagName, byte[] data) { try {// w w w .j a v a 2 s.c om MessageFactory factory = MessageFactory.newInstance(); SOAPMessage soapMessage = factory.createMessage(new MimeHeaders(), new ByteArrayInputStream(data)); if (soapMessage.getSOAPBody().hasFault()) { StringWriter writer = new StringWriter(); try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform(new DOMSource(soapMessage.getSOAPPart()), new StreamResult(writer)); } catch (IllegalArgumentException | TransformerException | TransformerFactoryConfigurationError e) { writer.append("Failed to dump fault: " + e); } throw new ResponseException(writer.toString()); } Iterator<SOAPBodyElement> responseBlockIt = soapMessage.getSOAPBody() .getChildElements(new QName(serviceType, expectedTagName)); if (!responseBlockIt.hasNext()) { throw new ResponseException(expectedTagName + " tag missing"); } Map<String, String> ret = new HashMap<>(); SOAPBodyElement responseNode = responseBlockIt.next(); Iterator<SOAPBodyElement> responseChildrenIt = responseNode.getChildElements(); while (responseChildrenIt.hasNext()) { SOAPBodyElement param = responseChildrenIt.next(); String name = StringUtils.trim(param.getLocalName().trim()); String value = StringUtils.trim(param.getValue().trim()); ret.put(name, value); } return ret; } catch (IllegalArgumentException | IOException | SOAPException | DOMException e) { throw new IllegalStateException(e); // should never happen } }
From source file:net.sourceforge.eclipsetrader.charts.ChartsPlugin.java
public static void saveDefaultChart(Chart chart) { Log logger = LogFactory.getLog(ChartsPlugin.class); SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); //$NON-NLS-1$ try {/*w ww.j av a2s .c o m*/ DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.getDOMImplementation().createDocument(null, "chart", null); //$NON-NLS-1$ Element root = document.getDocumentElement(); Element node = document.createElement("title"); //$NON-NLS-1$ node.appendChild(document.createTextNode(chart.getTitle())); root.appendChild(node); node = document.createElement("compression"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(chart.getCompression()))); root.appendChild(node); node = document.createElement("period"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(chart.getPeriod()))); root.appendChild(node); node = document.createElement("autoScale"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(chart.isAutoScale()))); root.appendChild(node); if (chart.getBeginDate() != null) { node = document.createElement("begin"); //$NON-NLS-1$ node.appendChild(document.createTextNode(dateTimeFormat.format(chart.getBeginDate()))); root.appendChild(node); } if (chart.getEndDate() != null) { node = document.createElement("end"); //$NON-NLS-1$ node.appendChild(document.createTextNode(dateTimeFormat.format(chart.getEndDate()))); root.appendChild(node); } for (int r = 0; r < chart.getRows().size(); r++) { ChartRow row = (ChartRow) chart.getRows().get(r); row.setId(new Integer(r)); Element rowNode = document.createElement("row"); //$NON-NLS-1$ root.appendChild(rowNode); for (int t = 0; t < row.getTabs().size(); t++) { ChartTab tab = (ChartTab) row.getTabs().get(t); tab.setId(new Integer(t)); Element tabNode = document.createElement("tab"); //$NON-NLS-1$ tabNode.setAttribute("label", tab.getLabel()); //$NON-NLS-1$ rowNode.appendChild(tabNode); for (int i = 0; i < tab.getIndicators().size(); i++) { ChartIndicator indicator = (ChartIndicator) tab.getIndicators().get(i); indicator.setId(new Integer(i)); Element indicatorNode = document.createElement("indicator"); //$NON-NLS-1$ indicatorNode.setAttribute("pluginId", indicator.getPluginId()); //$NON-NLS-1$ tabNode.appendChild(indicatorNode); for (Iterator iter = indicator.getParameters().keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); node = document.createElement("param"); //$NON-NLS-1$ node.setAttribute("key", key); //$NON-NLS-1$ node.setAttribute("value", (String) indicator.getParameters().get(key)); //$NON-NLS-1$ indicatorNode.appendChild(node); } } for (int i = 0; i < tab.getObjects().size(); i++) { ChartObject object = (ChartObject) tab.getObjects().get(i); object.setId(new Integer(i)); Element indicatorNode = document.createElement("object"); //$NON-NLS-1$ indicatorNode.setAttribute("pluginId", object.getPluginId()); //$NON-NLS-1$ tabNode.appendChild(indicatorNode); for (Iterator iter = object.getParameters().keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); node = document.createElement("param"); //$NON-NLS-1$ node.setAttribute("key", key); //$NON-NLS-1$ node.setAttribute("value", (String) object.getParameters().get(key)); //$NON-NLS-1$ indicatorNode.appendChild(node); } } } } TransformerFactory factory = TransformerFactory.newInstance(); try { factory.setAttribute("indent-number", new Integer(4)); //$NON-NLS-1$ } catch (Exception e) { } Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); //$NON-NLS-1$ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ transformer.setOutputProperty("{http\u003a//xml.apache.org/xslt}indent-amount", "4"); //$NON-NLS-1$ //$NON-NLS-2$ DOMSource source = new DOMSource(document); File file = ChartsPlugin.getDefault().getStateLocation().append("defaultChart.xml").toFile(); //$NON-NLS-1$ BufferedWriter out = new BufferedWriter(new FileWriter(file)); StreamResult result = new StreamResult(out); transformer.transform(source, result); out.flush(); out.close(); } catch (Exception e) { logger.error(e.toString(), e); } }