List of usage examples for org.dom4j.io XMLWriter close
public void close() throws IOException
From source file:org.richie.codeGen.ui.util.XmlParse.java
License:Apache License
/** * xml?//from www. j a va2 s . c o m * * @param document ? * @param outFile ? * @throws IOException */ public static void writeDocument(Document document, String outFile) throws IOException { XMLWriter xmlWriter = null; try { // ? OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"); // ? OutputFormat xmlFormat = new OutputFormat(); xmlFormat.setEncoding("UTF-8"); // xmlWriter = new XMLWriter(out, xmlFormat); // xmlWriter.write(document); } catch (IOException e) { throw e; } finally { // if (xmlWriter != null) xmlWriter.close(); } }
From source file:org.safehaus.penrose.config.PenroseConfigWriter.java
License:Open Source License
public void write(File file, PenroseConfig penroseConfig) throws Exception { Element element = createElement(penroseConfig); file.getParentFile().mkdirs();/* w w w . j a va 2 s. co m*/ Writer writer = new FileWriter(file); OutputFormat format = OutputFormat.createPrettyPrint(); format.setTrimText(false); XMLWriter xmlWriter = new XMLWriter(writer, format); xmlWriter.startDocument(); xmlWriter.startDTD("server", "-//Penrose/DTD Server " + Penrose.SPECIFICATION_VERSION + "//EN", "http://penrose.safehaus.org/dtd/server.dtd"); xmlWriter.write(element); xmlWriter.close(); writer.close(); }
From source file:org.safehaus.penrose.federation.FederationWriter.java
License:Open Source License
public void write(File file, FederationConfig federationConfig) throws Exception { log.debug("Writing " + file + "."); Element element = createElement(federationConfig); FileWriter fw = new FileWriter(file); OutputFormat format = OutputFormat.createPrettyPrint(); format.setTrimText(false);//from w w w . ja va 2 s .c o m XMLWriter writer = new XMLWriter(fw, format); writer.startDocument(); writer.startDTD("federation", "-//Penrose/DTD Federation " + getClass().getPackage().getSpecificationVersion() + "//EN", "http://penrose.safehaus.org/dtd/federation.dtd"); writer.write(element); writer.close(); }
From source file:org.safehaus.penrose.log.log4j.Log4jConfigWriter.java
License:Open Source License
public void write(File file, Log4jConfig config) throws Exception { Element element = createConfigElement(config); Writer out;/*from w ww.j a va2 s .c om*/ if (file == null) { out = new PrintWriter(System.out, true); } else { file.getParentFile().mkdirs(); out = new FileWriter(file); } OutputFormat format = OutputFormat.createPrettyPrint(); format.setTrimText(false); XMLWriter writer = new XMLWriter(out, format); writer.startDocument(); writer.startDTD("log4j:configuration", "-//Apache//DTD Log4j 1.2//EN", "http://logging.apache.org/log4j/docs/api/org/apache/log4j/xml/log4j.dtd"); writer.write(element); writer.close(); out.close(); }
From source file:org.safehaus.penrose.partition.PartitionWriter.java
License:Open Source License
public void writePartitionXml(File directory, PartitionConfig partitionConfig) throws Exception { File file = new File(directory, "partition.xml"); log.debug("Writing " + file + "."); Element element = createElement(partitionConfig); FileWriter fw = new FileWriter(file); OutputFormat format = OutputFormat.createPrettyPrint(); format.setTrimText(false);/*w w w . j a v a 2s .c om*/ XMLWriter writer = new XMLWriter(fw, format); writer.startDocument(); writer.startDTD("partition", "-//Penrose/DTD Partition " + getClass().getPackage().getSpecificationVersion() + "//EN", "http://penrose.safehaus.org/dtd/partition.dtd"); writer.write(element); writer.close(); }
From source file:org.safehaus.penrose.studio.util.ApplicationConfig.java
License:Open Source License
public void save(File file) throws Exception { FileWriter fw = new FileWriter(file); OutputFormat format = OutputFormat.createPrettyPrint(); format.setTrimText(false);// ww w . j ava2 s . c o m XMLWriter writer = new XMLWriter(fw, format); writer.startDocument(); writer.write(toElement()); writer.close(); }
From source file:org.seamless_if.processing.scheduler.Scheduler.java
License:Open Source License
/** * Saves the current state of the scheduler in a file with the specified * name./* w ww . j a v a 2 s. c o m*/ * * @param filename of file to store scheduler state in */ public synchronized void save(String filename) { logger.info("Saving scheduler state to file: " + filename); Document document = DocumentHelper.createDocument(toXml()); try { XMLWriter writer = new XMLWriter(new FileWriter(new File(filename), false)); writer.write(document); writer.close(); } catch (Exception ex) { throw new SeamException(ex, "Failed to save scheduler state! Error: %s", ex.getMessage()); } logger.info("Saving scheduler state completed"); }
From source file:org.seamless_if.services.servlets.SchedulerServlet.java
License:Open Source License
@SuppressWarnings("unchecked") private void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // set-up some things for output as XML response.setContentType("text/xml"); XMLWriter writer = new XMLWriter(response.getOutputStream()); Element root = new DOMElement("scheduler"); Document document = DocumentHelper.createDocument(root); // parse arguments to figure out what to do String methodName = request.getParameter("method"); if (methodName == null) methodName = "info"; // invoke method based on reflection (names must match!) try {/*from www.ja va 2 s .c o m*/ if (ACCESSIBLE_METHODS.valueOf(methodName) == null) throw new IllegalAccessException(); Method method = this.getClass().getMethod(methodName, Element.class, HttpServletRequest.class); method.invoke(this, root, request); } catch (Exception e) { root.add(new DOMElement("error").addText(e.toString())); root.add(new DOMElement("method").addText(methodName)); Map<String, String[]> parameters = (Map<String, String[]>) request.getParameterMap(); for (Object key : parameters.keySet()) { Element param = new DOMElement("parameter").addAttribute("name", key.toString()); Element valuesNode = new DOMElement("values"); String[] values = parameters.get(key); for (String value : values) { valuesNode.add(new DOMElement("value").addText(value)); } param.add(valuesNode); root.add(param); } e.printStackTrace(); } // write the output try { writer.write(document); writer.close(); } catch (Exception ex) { throw new SeamException(ex, "Failed to create servlet xml output! Error: %s", ex.getMessage()); } }
From source file:org.smartloli.kafka.eagle.plugin.util.DomUtils.java
License:Apache License
public static void getTomcatServerXML(String xml, String modifyPort) throws Exception { SAXReader reader = new SAXReader(); Document document = reader.read(new File(xml)); Element node = document.getRootElement(); List<?> tasks = node.elements(); for (Object task : tasks) { Element taskNode = (Element) task; String name = taskNode.attributeValue("name"); if ("Catalina".equals(name)) { String protocol = taskNode.element("Connector").attributeValue("protocol"); if ("HTTP/1.1".equals(protocol)) { taskNode.element("Connector").addAttribute("port", modifyPort); }//from w w w .j ava 2 s . com } } XMLWriter writer = new XMLWriter(new FileWriter(xml)); writer.write(document); writer.close(); }
From source file:org.snipsnap.util.JDBCDatabaseExport.java
License:Open Source License
/** * Store snips and users from the SnipSpace to an xml document into a stream. * @param out outputstream to write to//from w w w. j a v a 2s. c o m */ public static void store(OutputStream out, String appOid, Connection connection) { try { OutputFormat outputFormat = new OutputFormat(); outputFormat.setEncoding("UTF-8"); outputFormat.setNewlines(true); XMLWriter xmlWriter = new XMLWriter(out, outputFormat); xmlWriter.startDocument(); Element root = DocumentHelper.createElement("snipspace"); xmlWriter.writeOpen(root); // storeUsers(xmlWriter, connection); storeSnips(xmlWriter, appOid, connection); xmlWriter.writeClose(root); xmlWriter.endDocument(); xmlWriter.flush(); xmlWriter.close(); } catch (Exception e) { System.err.println("JDBCDatabaseExport: error while writing document: " + e.getMessage()); } }