List of usage examples for org.dom4j.io XMLWriter close
public void close() throws IOException
From source file:org.jboss.as.ee.deployment.spi.DeploymentMetaData.java
License:Open Source License
public String toXMLString() { try {/*from w w w. jav a 2 s . co m*/ OutputFormat format = OutputFormat.createPrettyPrint(); StringWriter strWriter = new StringWriter(1024); XMLWriter metaWriter = new XMLWriter(strWriter, format); metaWriter.write(getDocument()); metaWriter.close(); return strWriter.toString(); } catch (IOException ex) { ROOT_LOGGER.cannotTransformDeploymentPlanToXML(ex); return null; } }
From source file:org.jboss.deployment.spi.DeploymentMetaData.java
License:Open Source License
public String toXMLString() { try {//from www. j a v a 2 s . c o m OutputFormat format = OutputFormat.createPrettyPrint(); StringWriter strWriter = new StringWriter(1024); XMLWriter metaWriter = new XMLWriter(strWriter, format); metaWriter.write(getDocument()); metaWriter.close(); return strWriter.toString(); } catch (IOException e) { log.error("Cannot get XML string", e); return null; } }
From source file:org.jboss.rusheye.CommandCrawl.java
License:Open Source License
private void writeDocument() { OutputFormat format = OutputFormat.createPrettyPrint(); OutputStream out = openOutputStream(); try {/* ww w .j a v a2 s . c o m*/ XMLWriter writer = new XMLWriter(out, format); writer.write(document); writer.close(); } catch (IOException e) { printErrorMessage(e); System.exit(7); } }
From source file:org.jbpm.jpdl.internal.convert.JpdlConverterTool.java
License:Open Source License
public static void main(String[] args) { JpdlConverterTool jpdlConverterTool = new JpdlConverterTool(); // Parse and validate the command line arguments ConverterContext context = null;/*from www. j a va2s . co m*/ try { context = jpdlConverterTool.parseParam(args); jpdlConverterTool.validate(context); } catch (IllegalCommandException e) { System.err.println(e.getMessage()); System.err.println(jpdlConverterTool.getUsage()); return; } catch (Exception e) { System.err.println(e.getMessage()); return; } boolean verbose = false; if (context.get(ConverterContext.VERBOSE) != null) { verbose = true; } Jpdl3Converter jpdlConverter = new Jpdl3Converter((URL) context.get(context.PROCESS_FILE_URL)); try { if (verbose) { System.out.println( "Loading process file from URL [" + context.get(context.PROCESS_FILE_URL) + "]..."); } Document jpdl4Doc = jpdlConverter.readAndConvert(); if (verbose) { System.out.println("Converting the process file to jPDL4 version...."); } String outputFilePath = (String) context.get(context.OUPUTFILE); File outputFile = new File(outputFilePath); //well print xml to file Writer fileWriter = new FileWriter(outputFile); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(fileWriter, format); writer.write(jpdl4Doc); writer.close(); if (verbose) { System.out.println("Generating converted file to:" + (outputFile.isAbsolute() ? outputFile.getAbsolutePath() : outputFile.getName())); } } catch (Exception e) { for (Problem problem : jpdlConverter.problems) { if (problem.getLevel() == problem.LEVEL_WARNING) { System.err.println(problem); } if (problem.getLevel() < problem.LEVEL_WARNING) { System.err.println(problem); if (problem.getException() != null && context.get(ConverterContext.VERBOSE) != null) { problem.getException().printStackTrace(System.err); System.err.println(); } } } } }
From source file:org.jetbrains.kotlin.projectsextensions.j2se.buildextender.KotlinBuildExtender.java
License:Apache License
private void addKotlinLibProperty(FileObject buildImpl) throws DocumentException, UnsupportedEncodingException, IOException { SAXReader reader = new SAXReader(); Document document = reader.read(buildImpl.toURL()); List<Element> elements = document.getRootElement().elements("property"); for (Element el : elements) { if (el.attribute("name").getValue().equals("kotlin.lib")) { return; }/*from ww w. ja v a2 s . co m*/ } DefaultElement prop = new DefaultElement("property"); prop.addAttribute("name", "kotlin.lib"); prop.addAttribute("value", ProjectUtils.KT_HOME + "lib"); List content = document.getRootElement().content(); if (content != null) { content.add(0, prop); } OutputFormat format = OutputFormat.createPrettyPrint(); FileWriter out = new FileWriter(buildImpl.getPath()); XMLWriter writer; writer = new XMLWriter(out, format); writer.write(document); writer.close(); out.close(); }
From source file:org.jetbrains.kotlin.projectsextensions.j2se.buildextender.KotlinBuildExtender.java
License:Apache License
private void addKotlinAnt(FileObject buildImpl) throws DocumentException, UnsupportedEncodingException, IOException { SAXReader reader = new SAXReader(); Document document = reader.read(buildImpl.toURL()); List<Element> elements = document.getRootElement().elements("typedef"); for (Element el : elements) { if (el.attribute("classpath").getValue().equals("${kotlin.lib}/kotlin-ant.jar")) { return; }//from w w w.j av a2 s. co m } DefaultElement typedef = new DefaultElement("typedef"); typedef.addAttribute("classpath", "${kotlin.lib}/kotlin-ant.jar"); typedef.addAttribute("resource", "org/jetbrains/kotlin/ant/antlib.xml"); List content = document.getRootElement().content(); if (content != null) { content.add(0, typedef); } OutputFormat format = OutputFormat.createPrettyPrint(); FileWriter out = new FileWriter(buildImpl.getPath()); XMLWriter writer; writer = new XMLWriter(out, format); writer.write(document); writer.close(); out.close(); }
From source file:org.jetbrains.kotlin.projectsextensions.j2se.buildextender.KotlinBuildExtender.java
License:Apache License
private void insertWithKotlin(FileObject buildImpl) throws DocumentException, IOException { SAXReader reader = new SAXReader(); Document document = reader.read(buildImpl.toURL()); Element target = null;// w w w .j av a2s . com List<Element> elements = document.getRootElement().elements("target"); for (Element el : elements) { if (el.attribute("name").getValue().equals("-init-macrodef-javac-with-processors")) { target = el; } } if (target == null) { return; } Element macrodef = target.element("macrodef"); if (macrodef == null) { return; } Element sequential = macrodef.element("sequential"); if (sequential == null) { return; } Element javac = sequential.element("javac"); if (javac == null) { return; } if (javac.element("withKotlin") != null) { return; } DefaultElement withKotlin = new DefaultElement("withKotlin"); List content = javac.content(); if (content != null) { content.add(3, withKotlin); } OutputFormat format = OutputFormat.createPrettyPrint(); FileWriter out = new FileWriter(buildImpl.getPath()); XMLWriter writer; writer = new XMLWriter(out, format); writer.write(document); writer.close(); out.close(); }
From source file:org.jin.dic.data.pub.ldoce.v5.Convert2Html.java
License:Open Source License
private static byte[] convert(String data) throws DocumentException, IOException { data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + rmES.matcher(rmDummyTag.matcher(data).replaceAll("")).replaceAll(""); data = data.replaceAll("\\|", ","); _ByteArrayOutputStream bos = new _ByteArrayOutputStream(); _ByteArrayInputStream bis = new _ByteArrayInputStream(data.getBytes("utf-8")); SAXReader saxR = null;// ww w . j a v a 2s .com Document doc = null, des = null; Element root = null, desRoot = null; XMLWriter xmlWriter = null; OutputFormat fmt = null; saxR = new SAXReader(); doc = saxR.read(bis); root = doc.getRootElement(); des = DocumentHelper.createDocument(); desRoot = DocumentHelper.createElement("span"); desRoot.addAttribute("class", getClass(root)); Element child; List children = root.elements(); for (int i = 0; i < children.size(); i++) { child = (Element) children.get(i); addChildren(child, desRoot); } des.setRootElement(desRoot); fmt = OutputFormat.createCompactFormat(); fmt.setEncoding("utf-16le"); fmt.setTrimText(false); xmlWriter = new XMLWriter(bos, fmt); xmlWriter.write(des); xmlWriter.close(); return bos.toByteArray(); }
From source file:org.jogre.server.data.xml.ServerDataXML.java
License:Open Source License
/** * Method for saving an XML file.//w w w . java 2 s .c o m * * @param file File to save to. * @param document */ private void saveXMLFile(File file, Document document) { // write to a file try { XMLWriter writer = new XMLWriter(new FileWriter(file), format); writer.write(document); writer.close(); } catch (IOException ioe) { } }
From source file:org.jogre.server.ServerProperties.java
License:Open Source License
/** * Save the server properties to a file. *///from w w w. ja v a 2 s . co m public void saveXMLFile() { try { OutputFormat format = new OutputFormat(" ", true); XMLWriter writer = new XMLWriter(new FileWriter(DEFAULT_FILENAME), format); writer.write(doc); writer.close(); } catch (IOException ioe) { ioe.printStackTrace(); // FIXME - proper logging } }