List of usage examples for org.dom4j.io XMLWriter close
public void close() throws IOException
From source file:hebbNet.HebbNet.java
License:Open Source License
@Override public void exportToFile(File saveFile) { String extension = FrevoMain.getExtension(saveFile); if (extension.equals("net")) { System.out.println("Exporting Pajek network file to " + saveFile.getName()); try {// w ww . j av a 2s . c om // Create file FileWriter fstream = new FileWriter(saveFile); BufferedWriter out = new BufferedWriter(fstream); out.write("*Vertices " + this.nodes); out.newLine(); // input neurons for (int i = 1; i < input_nodes + 1; i++) { out.write(i + " \"I" + i + "\""); out.newLine(); } for (int h = input_nodes + 1; h < nodes - output_nodes + 1; h++) { out.write(h + " \"H" + (h - input_nodes) + "\""); out.newLine(); } int a = 1; for (int o = nodes - output_nodes + 1; o < nodes + 1; o++) { out.write(o + " \"O" + a + "\""); out.newLine(); a++; } // Edges out.write("*Edges"); out.newLine(); for (int n = 0; n < input_nodes - 1; n++) { for (int p = n + 1; p < input_nodes; p++) { if (n != p) { out.write((n + 1) + " " + (p + 1) + " " + 0); out.newLine(); } } } for (int n = input_nodes; n < nodes; n++) { for (int from = 0; from < nodes; from++) { out.write((n + 1) + " " + (from + 1) + " " + weight[from][n]); // out.write((n+1)+" "+(from+1)+" "+plasticity[from][n]); out.newLine(); } } // Close the output stream out.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } else if (extension.equals("xml")) { System.out.println("Saving to XML"); Document doc = DocumentHelper.createDocument(); doc.addDocType("HebbNet", null, System.getProperty("user.dir") + "//Components//Representations//HebbNet//src//HebbNet.dtd"); Element cnetwork = doc.addElement("HebbNet"); this.exportToXmlElement(cnetwork); OutputFormat format = OutputFormat.createPrettyPrint(); format.setLineSeparator(System.getProperty("line.separator")); try { saveFile.createNewFile(); FileWriter out = new FileWriter(saveFile); BufferedWriter bw = new BufferedWriter(out); XMLWriter wr = new XMLWriter(bw, format); wr.write(doc); wr.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:hello.SampleSimpleApplication.java
License:Apache License
private void makeLargeHTML() throws IOException { logger.debug("Start folder : " + dirJsonStart); Files.walkFileTree(dirJsonStart, new SimpleFileVisitor<Path>() { @Override// w w w .j a v a 2 s. c o m public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { final FileVisitResult visitFile = super.visitFile(file, attrs); fileIdx++; logger.debug(fileIdx + "" + fileSeparator + filesCount + procentWorkTime() + file); logger.debug(fileSeparator); String fileStr = file.toFile().toString(); logger.debug(fileStr); if (fileSeparator.equals("\\")) fileStr = fileStr.replace(fileSeparator, "/"); String[] split = fileStr.split("/"); String manufacturerName = split[split.length - 2]; Map<String, Object> jsonMap = readJsonDbFile2map(fileStr); String autoName = (String) jsonMap.get("autoName"); String autoNameWithManufacturer = split[split.length - 1].replace(".json", ""); // String autoNameWithManufacturer = manufacturerName+"_-_"+autoName; String pdfTitleAutoNameWithManufacturer = manufacturerName + " :: " + autoName; logger.debug(autoNameWithManufacturer + " -- BEGIN"); String htmlOutFileName2 = dirLargeHtmlName + autoNameWithManufacturer; logger.debug(htmlOutFileName2); File f = new File(htmlOutFileName2); if (f.exists()) { logger.debug("f.exists() -- " + htmlOutFileName2); return visitFile; } Element autoDocBody = createAutoDocument(pdfTitleAutoNameWithManufacturer); autoTileNr = 0; bookmarkId = 0; debugSkip = 0; Element headEl = (Element) autoDocument.selectSingleNode("/html/head"); bookmarks = headEl.addElement("bookmarks"); // addGroupAndRealInfo2(2,getIndexList(jsonMap)); //buildBookmark(autoDocument); addGroupAndRealInfo(bookmarks, getIndexList(jsonMap)); logger.debug(htmlOutFileName2 + " -- GOTO SAVE"); try { // String htmlOutFileName = dirLargeHtmlName+autoNameWithManufacturer+".html"; saveHtml(autoDocument, htmlOutFileName2); } catch (Exception e) { e.printStackTrace(); } logger.debug(autoNameWithManufacturer + " -- END"); return visitFile; } private void saveHtml(Document document, String htmlOutFileName) { writeToHtmlFile(document, htmlOutFileName); } private void writeToHtmlFile(Document document, String htmlOutFileName) { try { FileOutputStream fileOutputStream = new FileOutputStream(htmlOutFileName); // HTMLWriter xmlWriter = new HTMLWriter(fileOutputStream, prettyPrintFormat); XMLWriter xmlWriter = new XMLWriter(fileOutputStream, prettyPrintFormat); xmlWriter.write(document); xmlWriter.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } OutputFormat prettyPrintFormat = OutputFormat.createPrettyPrint(); private List<Map<String, Object>> getIndexList(Map<String, Object> jsonMap) { return (List<Map<String, Object>>) jsonMap.get("indexList"); } private void addGroupAndRealInfo(Element bookmarkParent, List<Map<String, Object>> indexList) { if (indexList != null) { for (Map<String, Object> map : indexList) { String text = (String) map.get("text"); Element bookmarkElement = bookmarkParent.addElement("bookmark"); bookmarkElement.addAttribute("name", text); bookmarkElement.addAttribute("href", "#b_" + bookmarkId++); String url = (String) map.get("url"); if (url != null) { addRealInfo(url); } // if(debugSkip > 13) // break; addGroupAndRealInfo(bookmarkElement, getIndexList(map)); } } } }); }
From source file:hk.hku.cecid.piazza.commons.util.PropertyTree.java
License:Open Source License
/** * Stores the properties to the specified url location. * // ww w .j a v a2s .c o m * @param url the url of the properties source. * @throws Exception if the operation is unsuccessful. * @see hk.hku.cecid.piazza.commons.module.PersistentComponent#storing(java.net.URL) */ protected void storing(URL url) throws Exception { XMLWriter writer = new XMLWriter(new FileOutputStream(Convertor.toFile(url)), OutputFormat.createPrettyPrint()); writer.write(dom); writer.close(); }
From source file:hvv_admin4.state.HVV_StateKeeperXML.java
public void SaveState() { if (theApp.GetCurrentStep() < 20) return;/*from w ww. j av a2s . co m*/ SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss"); try { Document document = DocumentHelper.createDocument(); Element root = document.addElement("SaveStateXML"); // root.addElement("CurrentStep").addText("" + theApp.GetCurrentStep()); //? root.addElement("SerialNumber").addText(theApp.GetSerial()); // root.addElement("ProcessedDeviceType").addText("" + theApp.GetProcessedDeviceType()); // ? if (theApp.GetDtmTOEnd() == null) root.addElement("dtmTOEnd").addText("NULL"); else root.addElement("dtmTOEnd").addText(formatter.format(theApp.GetDtmTOEnd())); Set set = theApp.SecretSteps().entrySet(); Iterator it = set.iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); String strKey = (String) entry.getKey(); Object objValue = entry.getValue(); Element innerRoot = root.addElement("Step" + strKey); switch (strKey) { case "001": case "061": case "062": case "064": case "101": case "103": case "105": case "141": case "143": case "181": ((TechProcessStepCommon) objValue).SaveItemXML(innerRoot, theApp.GetStepNameWithNum(Integer.parseInt(strKey))); break; case "021": case "022": case "041": case "042": case "043": case "044": case "102": case "104": case "106": case "142": case "144": ((TechProcessHvProcessInfo) objValue).SaveItemXML(innerRoot, theApp.GetStepNameWithNum(Integer.parseInt(strKey))); break; case "063": case "121": case "161": ((TechProcessGetterInfo) objValue).SaveItemXML(innerRoot, theApp.GetStepNameWithNum(Integer.parseInt(strKey))); break; case "081": case "182": ((TechProcessIgenIextProcessInfo) objValue).SaveItemXML(innerRoot, theApp.GetStepNameWithNum(Integer.parseInt(strKey))); break; case "082": case "183": ((TechProcessUacProcessInfo) objValue).SaveItemXML(innerRoot, theApp.GetStepNameWithNum(Integer.parseInt(strKey))); break; case "083": case "184": ((TechProcessCommentInfo) objValue).SaveItemXML(innerRoot, theApp.GetStepNameWithNum(Integer.parseInt(strKey))); break; /* case "122": case "162": (( TechProcessHFInfo ) objValue).SaveItemXML( innerRoot); break; */ } } OutputFormat format = OutputFormat.createPrettyPrint(); //File fl = new File( m_strStateKeepFileName); //fl.createNewFile(); XMLWriter writer = new XMLWriter(new FileWriter(m_strStateKeepFileName), format); writer.write(document); writer.close(); } catch (IOException ex) { logger.error("IOException caught while saving state!", ex); } }
From source file:hvv_constructor.FrmMainWindow.java
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed Document saveFile = DocumentHelper.createDocument(); Element program = saveFile.addElement("Program"); Set set = theApp.m_program.entrySet(); Iterator it = set.iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); int nLineNumber = (int) entry.getKey(); JProg.JProgAStatement abstractStatement = (JProg.JProgAStatement) entry.getValue(); Element statement = program.addElement("LineNumber").addText("" + nLineNumber); abstractStatement.AddXMLStatement(statement); }/*w w w . j a v a2s . c o m*/ OutputFormat format = OutputFormat.createPrettyPrint(); final JFileChooser fc = new JFileChooser(); fc.setFileFilter(new MyXMLFilter()); fc.setCurrentDirectory(new File(theApp.GetAMSRoot() + "/ReadyPrograms")); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { String strFilePathName = fc.getSelectedFile().getAbsolutePath(); if (!strFilePathName.endsWith(".xml")) strFilePathName += ".xml"; File file = new File(strFilePathName); XMLWriter writer; try { writer = new XMLWriter(new FileWriter(file.getAbsolutePath()), format); writer.write(saveFile); writer.close(); } catch (IOException ex) { logger.error("IOException: ", ex); } } else { logger.error( " ? ?? ."); } }
From source file:i.am.jiongxuan.deapk.GenerateProjectOperator.java
License:Apache License
public void generateClassPathFile() { Document document = DocumentHelper.createDocument(); Element classPathElement = document.addElement("classpath"); classPathElement.addElement("classpathentry").addAttribute("kind", "src").addAttribute("path", "src"); classPathElement.addElement("classpathentry").addAttribute("kind", "src").addAttribute("path", "gen"); classPathElement.addElement("classpathentry").addAttribute("kind", "con").addAttribute("path", "com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"); classPathElement.addElement("classpathentry").addAttribute("kind", "con").addAttribute("path", "com.android.ide.eclipse.adt.LIBRARIES"); classPathElement.addElement("classpathentry").addAttribute("kind", "con") .addAttribute("path", "com.android.ide.eclipse.adt.DEPENDENCIES").addAttribute("exported", "true"); classPathElement.addElement("classpathentry").addAttribute("kind", "output").addAttribute("path", "bin/classes"); try {//from w w w. jav a2s . co m XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(new File(mProjectFile, ".classpath"))); xmlWriter.write(document); xmlWriter.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:i.am.jiongxuan.deapk.GenerateProjectOperator.java
License:Apache License
public void generateProjectFile() { Document document = DocumentHelper.createDocument(); Element projectDescriptionElement = document.addElement("projectDescription"); projectDescriptionElement.addElement("name").addText(getProjectNameInManifestXml()); Element buildSpecElement = projectDescriptionElement.addElement("buildSpec"); buildSpecElement.addElement("buildCommand").addElement("name") .addText("com.android.ide.eclipse.adt.ResourceManagerBuilder"); buildSpecElement.addElement("buildCommand").addElement("name") .addText("com.android.ide.eclipse.adt.PreCompilerBuilder"); buildSpecElement.addElement("buildCommand").addElement("name").addText("org.eclipse.jdt.core.javabuilder"); buildSpecElement.addElement("buildCommand").addElement("name") .addText("com.android.ide.eclipse.adt.ApkBuilder"); Element naturesElement = projectDescriptionElement.addElement("natures"); naturesElement.addElement("nature").addText("com.android.ide.eclipse.adt.AndroidNature"); naturesElement.addElement("nature").addText("org.eclipse.jdt.core.javanature"); try {//from www. j a va 2 s .c om XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(new File(mProjectFile, ".project"))); xmlWriter.write(document); xmlWriter.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:iqq.app.service.impl.IMResourceServiceImpl.java
License:Apache License
@Override public void writeXml(Document document, File xmlFile) { try {/*from www.j a va 2 s. co m*/ OutputFormat outputFormat = OutputFormat.createPrettyPrint();// XML? outputFormat.setEncoding("UTF-8");// XML? outputFormat.setIndent(true);// ? outputFormat.setIndent(" ");// TAB? outputFormat.setNewlines(true);// ?? XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(xmlFile), outputFormat); xmlWriter.write(document); xmlWriter.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:iqq.app.util.XmlUtils.java
License:Apache License
/** * XML//from w ww . ja v a2 s . c om * * @param document * @param xmlFile * @throws IOException */ public static void writeXml(String filename, Document document) throws IOException { LOG.debug("XML: " + filename); OutputFormat outputFormat = OutputFormat.createPrettyPrint();// XML? outputFormat.setEncoding("UTF-8");// XML? outputFormat.setIndent(true);// ? outputFormat.setIndent(" ");// TAB? outputFormat.setNewlines(true);// ?? synchronized (document) { XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(filename), outputFormat); xmlWriter.write(document); xmlWriter.close(); } }
From source file:it.eng.qbe.datasource.configuration.dao.fileimpl.CalculatedFieldsDAOFileImpl.java
License:Mozilla Public License
private void guardedWrite(Document document, File file) { Writer out;/*from w w w. j a v a 2s.co m*/ OutputFormat format; XMLWriter writer; logger.debug("IN"); out = null; writer = null; try { logger.debug("acquiring lock..."); getLock(); logger.debug("Lock acquired"); out = null; try { out = new FileWriter(file); } catch (IOException e) { throw new DAOException("Impossible to open file [" + file + "]", e); } Assert.assertNotNull(out, "Output stream cannot be null"); format = OutputFormat.createPrettyPrint(); format.setEncoding("ISO-8859-1"); format.setIndent(" "); writer = new XMLWriter(out, format); try { writer.write(document); writer.flush(); } catch (IOException e) { throw new DAOException("Impossible to write to file [" + file + "]", e); } } catch (Throwable t) { if (t instanceof DAOException) throw (DAOException) t; throw new DAOException("An unpredicetd error occurred while writing on file [" + file + "]"); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { throw new DAOException("Impossible to properly close stream to file file [" + file + "]", e); } } logger.debug("releasing lock..."); releaseLock(); logger.debug("lock released"); logger.debug("OUT"); } }