List of usage examples for org.dom4j.io XMLWriter XMLWriter
public XMLWriter(OutputStream out, OutputFormat format) throws UnsupportedEncodingException
From source file:de.tud.kom.p2psim.impl.vis.util.Config.java
License:Open Source License
/** * Schreibt die bestehende XML-Struktur in die Config-Datei *///from w w w . j a va 2 s. c o m public static void writeXMLFile() { if (config != null) { // Schreibe Datei nur, wenn XML-Baum im Speicher // vorhanden try { OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(configFile), format); writer.write(Config.config); writer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:de.tudarmstadt.ukp.dkpro.lab.uima.engine.uimaas.AsDeploymentDescription.java
License:Apache License
public void toXML(OutputStream aOutput) throws IOException { Element root = createElement(E_ROOT); if (getName() != null) { root.addElement(E_NAME).setText(getName()); }//from w w w . j av a 2s. co m if (getDescription() != null) { root.addElement(E_DESCRIPTION).setText(getDescription()); } if (getVendor() != null) { root.addElement(E_VENDOR).setText(getVendor()); } if (getVersion() != null) { root.addElement(E_VERSION).setText(getVersion()); } Element deployment = root.addElement(E_DEPLOYMENT).addAttribute(A_PROTOCOL, getProtocol()) .addAttribute(A_PROVIDER, getProvider()); Element service = deployment.addElement(E_SERVICE); service.addElement(E_INPUT_QUEUE).addAttribute(A_ENDPOINT, getEndpoint()) .addAttribute(A_BROKER_URL, getBrokerUrl()).addAttribute(A_PREFETCH, getPrefetch()); service.addElement(E_TOP_DESCRIPTOR).addElement(E_IMPORT).addAttribute(A_LOCATION, getTopDescriptorFile().getAbsolutePath()); OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-8"); XMLWriter writer = new XMLWriter(aOutput, outformat); writer.write(createDocument(root)); writer.flush(); }
From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.Packet.java
License:Open Source License
public String toString() { StringWriter out = new StringWriter(); XMLWriter writer = new XMLWriter(out, OutputFormat.createPrettyPrint()); try {/*from w w w . ja v a 2s . c o m*/ writer.write(element); } catch (Exception e) { // Ignore. } return out.toString(); }
From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.StreamError.java
License:Open Source License
public String toString() { StringWriter out = new StringWriter(); XMLWriter writer = new XMLWriter(out, OutputFormat.createPrettyPrint()); try {//from w w w . j a v a 2 s.co m writer.write(element); } catch (Exception e) { e.printStackTrace(); } return out.toString(); }
From source file:de.tu_berlin.cit.rwx4j.xmpp.util.XMLProperties.java
License:Open Source License
/** * Saves the properties to disk as an XML document. A temporary file is * used during the writing process for maximum safety. *//*w w w . j av a 2s .c o m*/ private synchronized void saveProperties() { boolean error = false; // Write data out to a temporary file first. File tempFile = null; Writer writer = null; try { tempFile = new File(file.getParentFile(), file.getName() + ".tmp"); writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tempFile))); OutputFormat prettyPrinter = OutputFormat.createPrettyPrint(); XMLWriter xmlWriter = new XMLWriter(writer, prettyPrinter); xmlWriter.write(document); } catch (Exception e) { e.printStackTrace(); // There were errors so abort replacing the old property file. error = true; } finally { if (writer != null) { try { writer.close(); } catch (IOException e1) { e1.printStackTrace(); error = true; } } } // No errors occured, so delete the main file. if (!error) { // Delete the old file so we can replace it. if (!file.delete()) { System.err.println("Error deleting property file: " + file.getAbsolutePath()); return; } // Copy new contents to the file. try { copy(tempFile, file); } catch (Exception e) { e.printStackTrace(); // There were errors so abort replacing the old property file. error = true; } // If no errors, delete the temp file. if (!error) { tempFile.delete(); } } }
From source file:de.xaniox.heavyspleef.migration.GameMigrator.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* w ww.j ava 2 s . c o m*/ public void migrate(Configuration inputSource, File outputFolder, Object cookie) throws MigrationException { if (cookie == null || !(cookie instanceof List<?>)) { throw new MigrationException("Cookie must be a game of lists"); } countMigrated = 0; List<Game> gameList = (List<Game>) cookie; Set<String> gameNames = inputSource.getKeys(false); for (String name : gameNames) { ConfigurationSection section = inputSource.getConfigurationSection(name); File xmlFile = new File(outputFolder, name + FILE_EXTENSION); if (xmlFile.exists()) { //Rename this game as there is already a file xmlFile = new File(outputFolder, name + "_1" + FILE_EXTENSION); } XMLWriter writer = null; try { xmlFile.createNewFile(); GameAccessor accessor = new GameAccessor(heavySpleef); Document document = DocumentHelper.createDocument(); Element rootElement = document.addElement("game"); Game game = migrateGame(section, rootElement); if (game == null) { continue; } accessor.write(game, rootElement); gameList.add(game); OutputStream out = new FileOutputStream(xmlFile); writer = new XMLWriter(out, outputFormat); writer.write(document); ++countMigrated; } catch (IOException e) { throw new MigrationException(e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { } } } } }
From source file:de.xaniox.heavyspleef.persistence.handler.CachingReadWriteHandler.java
License:Open Source License
@Override public void saveGame(Game game) throws IOException { File gameFile = new File(xmlFolder, game.getName() + ".xml"); if (!gameFile.exists()) { gameFile.createNewFile();//from w w w . j a va 2s . c om } Document document = DocumentHelper.createDocument(); Element rootElement = document.addElement("game"); xmlContext.write(game, rootElement); File gameSchematicFolder = new File(schematicFolder, game.getName()); if (!gameSchematicFolder.exists()) { gameSchematicFolder.mkdir(); } XMLWriter writer = null; try { FileOutputStream out = new FileOutputStream(gameFile); writer = new XMLWriter(out, xmlOutputFormat); writer.write(document); } finally { if (writer != null) { writer.close(); } } for (File file : gameSchematicFolder.listFiles(FLOOR_SCHEMATIC_FILTER)) { String floorName = file.getName().substring(2, file.getName().length() - 6); if (game.isFloorPresent(floorName)) { continue; } file.delete(); } for (Floor floor : game.getFloors()) { File floorFile = new File(gameSchematicFolder, getFloorFileName(floor)); if (!floorFile.exists()) { floorFile.createNewFile(); } schematicContext.write(floorFile, floor); } }
From source file:de.xaniox.leaderboardextensions.ExtensionXmlHandler.java
License:Open Source License
public void saveExtensions(Set<GameExtension> extensions) throws IOException { if (!xmlFile.exists()) { xmlFile.createNewFile();/*w w w.ja v a2 s. c o m*/ } Document document = DocumentHelper.createDocument(); Element rootElement = document.addElement("extensions"); for (GameExtension extension : extensions) { Element extensionElement = rootElement.addElement("extension"); String name = registry.getExtensionName(extension.getClass()); extensionElement.addAttribute("name", name); context.write(extension, extensionElement); } XMLWriter xmlWriter = null; try (OutputStream out = new FileOutputStream(xmlFile); Writer writer = new OutputStreamWriter(out, UTF8)) { xmlWriter = new XMLWriter(writer, format); xmlWriter.write(document); xmlWriter.flush(); } finally { if (xmlWriter != null) { xmlWriter.close(); } } }
From source file:de.xwic.sandbox.server.installer.XmlExport.java
License:Apache License
/** * @param secDump/* ww w . j a v a 2 s . c o m*/ */ public void exportSecurity(File secDump) throws IOException, ConfigurationException { Document doc = DocumentFactory.getInstance().createDocument(); Element root = doc.addElement(ELM_EXPORT); root.addAttribute("type", "security"); Element info = root.addElement(ELM_EXPORTDDATE); info.setText(DateFormat.getDateTimeInstance().format(new Date())); Element data = root.addElement(ELM_DATA); addAll(IActionDAO.class, data); addAll(IActionSetDAO.class, data); addAll(IScopeDAO.class, data); addAll(IRoleDAO.class, data); addAll(IRightDAO.class, data); addAll(IUserDAO.class, data); OutputFormat prettyFormat = OutputFormat.createPrettyPrint(); OutputStream out = new FileOutputStream(secDump); XMLWriter writer = new XMLWriter(out, prettyFormat); writer.write(doc); writer.flush(); out.close(); }
From source file:de.xwic.sandbox.server.installer.XmlExport.java
License:Apache License
/** * @param plDump// www .j a va 2 s . c o m */ public void exportPicklists(File plDump) throws IOException, ConfigurationException { Document doc = DocumentFactory.getInstance().createDocument(); Element root = doc.addElement(ELM_EXPORT); root.addAttribute("type", "picklists"); Element info = root.addElement(ELM_EXPORTDDATE); info.setText(DateFormat.getDateTimeInstance().format(new Date())); Element data = root.addElement(ELM_DATA); addPicklisten(data); OutputFormat prettyFormat = OutputFormat.createPrettyPrint(); OutputStream out = new FileOutputStream(plDump); XMLWriter writer = new XMLWriter(out, prettyFormat); writer.write(doc); writer.flush(); out.close(); }