List of usage examples for org.dom4j.io XMLWriter endDocument
public void endDocument() throws SAXException
From source file:com.bstek.dorado.idesupport.output.RuleSetOutputter.java
License:Open Source License
public void output(Writer writer, RuleTemplateManager ruleTemplateManager) throws Exception { OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(Constants.DEFAULT_CHARSET); XMLWriter xmlWriter = new XMLWriter(writer, format); xmlWriter.startDocument();/*from ww w . j a v a 2 s .co m*/ Element rootElement = DocumentHelper.createElement("RuleSet"); rootElement.addAttribute("version", ruleTemplateManager.getVersion()); xmlWriter.writeOpen(rootElement); OutputContext context = new OutputContext(); outputPackageInfos(xmlWriter, ruleTemplateManager, context); for (RuleTemplate ruleTemplate : ruleTemplateManager.getRuleTemplates()) { // PropertyDataType? // if (ruleTemplate.isAbstract() // && ruleTemplate.getSubRuleTemplates().length == 0) { // continue; // } outputRuleTemplate(xmlWriter, ruleTemplate, context); } xmlWriter.writeClose(rootElement); xmlWriter.endDocument(); xmlWriter.close(); }
From source file:com.rowtheboat.gui.OptionsSingleton.java
License:Open Source License
/** * This method saves the options to the options.xml file *//*from w ww . j a va 2 s . c o m*/ public void saveOptions() throws SAXException, IOException { /* Start the document */ OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(optionsFile), format); writer.startDocument(); /* Add the main options section */ Document document = DocumentHelper.createDocument(); Element root = document.addElement("Options"); /* Standard options */ DefaultElement standardElement = new DefaultElement("Standard"); standardElement.addElement("FullStrokeData").addText(getFullStrokeData() + ""); standardElement.addElement("BoatSmoothing").addText(getBoatSmoothing() + ""); root.add(standardElement); /* Input options */ DefaultElement inputElement = new DefaultElement("Input"); inputElement.addElement("SerialPort").addText(getSerialPort()); root.add(inputElement); /* Race options */ DefaultElement raceElement = new DefaultElement("Race"); raceElement.addElement("Countdown").addText(getDelay() + ""); root.add(raceElement); /* End the document */ writer.write(root); writer.endDocument(); writer.close(); }
From source file:net.sourceforge.sqlexplorer.XMLUtils.java
License:Open Source License
public static void save(Element pRoot, File pFile) { try {// www . j a v a2s . c o m XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(pFile), OutputFormat.createPrettyPrint()); xmlWriter.startDocument(); xmlWriter.write(pRoot); xmlWriter.endDocument(); xmlWriter.flush(); xmlWriter.close(); } catch (Exception e) { SQLExplorerPlugin.error("Couldn't save: " + pFile.getAbsolutePath(), e); } }
From source file:org.alfresco.repo.admin.patch.util.ImportFileUpdater.java
License:Open Source License
/** * Updates the passed import file into the equivalent 1.4 format. * /* w w w. j a va2 s . c om*/ * @param source the source import file * @param destination the destination import file */ public void updateImportFile(String source, String destination) { XmlPullParser reader = getReader(source); XMLWriter writer = getWriter(destination); this.shownWarning = false; try { // Start the documentation writer.startDocument(); // Start reading the document int eventType = reader.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { ImportFileUpdater.this.outputCurrentElement(reader, writer, new OutputChildren()); } eventType = reader.next(); } // End and close the document writer.endDocument(); writer.close(); } catch (Exception exception) { throw new AlfrescoRuntimeException("Unable to update import file.", exception); } }
From source file:org.itracker.web.util.ImportExportUtilities.java
License:Open Source License
public static void exportIssues(XMLWriter writer, List<Issue> issues, SystemConfiguration config) throws ImportExportException { Element elRoot = getDocumentFactory().createElement(TAG_ROOT); try {//from w ww . j a v a2 s . c o m writer.startDocument(); writer.writeOpen(elRoot); exportConfigModels(writer, config); exportIssuesModels(writer, issues); writer.writeClose(elRoot); writer.endDocument(); } catch (SAXException e) { throw new ImportExportException(e.getMessage(), ImportExportException.TYPE_UNKNOWN); } catch (IOException e) { throw new ImportExportException("Problem writing export stream. " + e.getMessage(), ImportExportException.TYPE_UNKNOWN); } }
From source file:org.neo4j.neoclipse.util.XMLUtils.java
License:Apache License
public static void save(Element pRoot, File pFile) { try {/*ww w .ja va 2 s . c o m*/ pFile.getParentFile().mkdirs(); FileOutputStream fileOutputStream = new FileOutputStream(pFile); XMLWriter xmlWriter = new XMLWriter(fileOutputStream, OutputFormat.createPrettyPrint()); xmlWriter.startDocument(); xmlWriter.write(pRoot); xmlWriter.endDocument(); xmlWriter.flush(); xmlWriter.close(); } catch (Exception e) { ErrorMessage.showDialog("Couldn't save: " + pFile.getAbsolutePath(), e); } }
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/*w w w .j a va2s .c om*/ */ 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()); } }
From source file:org.waarp.openr66.database.data.DbTaskRunner.java
License:Open Source License
/** * Write selected TaskRunners to an XML file using an XMLWriter * //from ww w. j a v a 2s .c om * @param preparedStatement * @param filename * @return the NbAndSpecialId for the number of transfer and higher rank found * @throws WaarpDatabaseNoConnectionException * @throws WaarpDatabaseSqlException * @throws OpenR66ProtocolBusinessException */ public static NbAndSpecialId writeXMLWriter(DbPreparedStatement preparedStatement, String filename) throws WaarpDatabaseNoConnectionException, WaarpDatabaseSqlException, OpenR66ProtocolBusinessException { NbAndSpecialId nbAndSpecialId = null; OutputStream outputStream = null; XMLWriter xmlWriter = null; try { outputStream = new FileOutputStream(filename); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("ISO-8859-1"); xmlWriter = new XMLWriter(outputStream, format); preparedStatement.executeQuery(); nbAndSpecialId = writeXML(preparedStatement, xmlWriter); } catch (FileNotFoundException e) { logger.error("Cannot write XML file", e); throw new OpenR66ProtocolBusinessException("File not found"); } catch (UnsupportedEncodingException e) { logger.error("Cannot write XML file", e); throw new OpenR66ProtocolBusinessException("Unsupported Encoding"); } finally { if (xmlWriter != null) { try { xmlWriter.endDocument(); xmlWriter.flush(); xmlWriter.close(); } catch (SAXException e) { try { outputStream.close(); } catch (IOException e2) { } File file = new File(filename); file.delete(); logger.error("Cannot write XML file", e); throw new OpenR66ProtocolBusinessException("Unsupported Encoding"); } catch (IOException e) { try { outputStream.close(); } catch (IOException e2) { } File file = new File(filename); file.delete(); logger.error("Cannot write XML file", e); throw new OpenR66ProtocolBusinessException("Unsupported Encoding"); } } else if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { } File file = new File(filename); file.delete(); } } return nbAndSpecialId; }
From source file:org.waarp.openr66.database.data.DbTaskRunner.java
License:Open Source License
/** * Method to write the current DbTaskRunner for NoDb client instead of updating DB. 'setToArray' * must be called priorly to be able to store the values. * //from ww w.j a v a 2s . c o m * @throws OpenR66ProtocolBusinessException */ public void writeXmlWorkNoDb() throws OpenR66ProtocolBusinessException { String filename = backendXmlFilename(); OutputStream outputStream = null; XMLWriter xmlWriter = null; try { outputStream = new FileOutputStream(filename); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("ISO-8859-1"); xmlWriter = new XMLWriter(outputStream, format); Element root = new DefaultElement(XMLRUNNERS); try { xmlWriter.writeOpen(root); Element node; node = DbTaskRunner.getElementFromRunner(this); xmlWriter.write(node); xmlWriter.flush(); xmlWriter.writeClose(root); } catch (IOException e) { logger.error("Cannot write XML file", e); throw new OpenR66ProtocolBusinessException("Cannot write file: " + e.getMessage()); } catch (WaarpDatabaseSqlException e) { logger.error("Cannot write Data", e); throw new OpenR66ProtocolBusinessException("Cannot write Data: " + e.getMessage()); } } catch (FileNotFoundException e) { logger.error("Cannot write XML file", e); throw new OpenR66ProtocolBusinessException("File not found"); } catch (UnsupportedEncodingException e) { logger.error("Cannot write XML file", e); throw new OpenR66ProtocolBusinessException("Unsupported Encoding"); } finally { if (xmlWriter != null) { try { xmlWriter.endDocument(); xmlWriter.flush(); xmlWriter.close(); } catch (SAXException e) { try { outputStream.close(); } catch (IOException e2) { } File file = new File(filename); file.delete(); logger.error("Cannot write XML file", e); throw new OpenR66ProtocolBusinessException("Unsupported Encoding"); } catch (IOException e) { try { outputStream.close(); } catch (IOException e2) { } File file = new File(filename); file.delete(); logger.error("Cannot write XML file", e); throw new OpenR66ProtocolBusinessException("Unsupported Encoding"); } } else if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { } File file = new File(filename); file.delete(); } } }
From source file:org.xwiki.store.serialization.xml.internal.AbstractXMLSerializer.java
License:Open Source License
/** * {@inheritDoc}/*from ww w .jav a 2 s . com*/ * * @see org.xwiki.store.filesystem.internal.XMLSerializer#serialize(T) */ public InputStream serialize(final R object) throws IOException { // This puts everything on the heap for now. // if size becomes a major problem, the alternitive is to fork over another thread // and use a PipedInputStream. final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final XMLWriter writer; try { // This should always be UTF-8 because it is a property of the serializer. final OutputFormat of = new OutputFormat(" ", true, "UTF-8"); writer = new XMLWriter(baos, of); writer.startDocument(); } catch (SAXException e) { throw new IOException("Could not open the XML writer."); } this.serialize(object, writer); try { writer.endDocument(); } catch (SAXException e) { throw new IOException("Could not close the XML writer."); } return new ByteArrayInputStream(baos.toByteArray()); }