List of usage examples for org.dom4j.io XMLWriter write
public void write(Object object) throws IOException
From source file:gov.nih.nci.rembrandt.web.helper.ReportGeneratorHelper.java
License:BSD License
/** * Render report with paging params// w w w . ja v a 2 s .c o m * @param request * @param reportXMLParam * @param xsltFilename * @param out * @param params */ public static void renderReportWithParams(HttpServletRequest request, Document reportXMLParam, String xsltFilename, JspWriter out, HashMap<String, String> params) { File styleSheet = new File(RembrandtContextListener.getContextPath() + "/XSL/" + xsltFilename); // load the transformer using JAX logger.debug("Applying XSLT with paging " + xsltFilename); Transformer transformer; Document reportXML; try { if (reportXMLParam != null) reportXML = reportXMLParam; else reportXML = (Document) request.getSession() .getAttribute(RembrandtConstants.SESSION_ATTR_PATHWAY_XML); transformer = new Transformer(styleSheet, params); Document transformedDoc = transformer.transform(reportXML); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer; writer = new XMLWriter(out, format); writer.write(transformedDoc); } catch (UnsupportedEncodingException uee) { logger.error("UnsupportedEncodingException"); logger.error(uee); } catch (IOException ioe) { logger.error("IOException"); logger.error(ioe); } }
From source file:gr.abiss.calipso.util.XmlUtils.java
License:Open Source License
/** * Override that accepts an XML DOM Document * @param document XML as DOM Document// w w w . j ava2 s. c o m */ public static String getAsPrettyXml(Document document) { OutputFormat format = new OutputFormat(" ", true); format.setSuppressDeclaration(true); StringWriter out = new StringWriter(); XMLWriter writer = new XMLWriter(out, format); try { try { writer.write(document); } finally { writer.close(); } } catch (IOException ioe) { throw new RuntimeException(ioe); } return out.toString().trim(); }
From source file:gtu._work.etc.HotnoteMakerUI.java
License:Open Source License
private void initGUI() { try {/*from w w w. java 2 s.c o m*/ ToolTipManager.sharedInstance().setInitialDelay(0); BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("hott notes - checklist", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(612, 348)); { checkListArea = new JTextArea(); jScrollPane1.setViewportView(checkListArea); checkListArea.addMouseListener(new MouseAdapter() { String randomColor() { StringBuilder sb = new StringBuilder().append("#"); for (int ii = 0; ii < 6; ii++) { sb.append(RandomUtil.randomChar('a', 'b', 'c', 'd', 'f', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9')); } return sb.toString(); } void saveXml(Document document, File file) { OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("utf-16"); XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(file), format); writer.write(document); } catch (IOException e) { JCommonUtil.handleException(e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { JCommonUtil.handleException(e); } } } } public void mouseClicked(MouseEvent evt) { if (!JMouseEventUtil.buttonLeftClick(2, evt)) { return; } if (StringUtils.isEmpty(checkListArea.getText())) { JCommonUtil ._jOptionPane_showMessageDialog_error("checklist area is empty!"); return; } File file = JCommonUtil._jFileChooser_selectFileOnly_saveFile(); if (file == null) { JCommonUtil._jOptionPane_showMessageDialog_error("file is not correct!"); return; } //XXX StringTokenizer tok = new StringTokenizer(checkListArea.getText(), "\t\n\r\f"); List<String> list = new ArrayList<String>(); String tmp = null; for (; tok.hasMoreElements();) { tmp = ((String) tok.nextElement()).trim(); System.out.println(tmp); list.add(tmp); } //XXX Document document = DocumentHelper.createDocument(); Element rootHot = document.addElement("hottnote"); rootHot.addAttribute("creationtime", new Timestamp(System.currentTimeMillis()).toString()); rootHot.addAttribute("lastmodified", new Timestamp(System.currentTimeMillis()).toString()); rootHot.addAttribute("type", "checklist"); //appearence Element appearenceE = rootHot.addElement("appearence"); appearenceE.addAttribute("alpha", "204"); Element fontE = appearenceE.addElement("font"); fontE.addAttribute("face", "Default"); fontE.addAttribute("size", "0"); Element styleE = appearenceE.addElement("style"); styleE.addElement("bg2color").addAttribute("color", randomColor()); styleE.addElement("bgcolor").addAttribute("color", randomColor()); styleE.addElement("textcolor").addAttribute("color", randomColor()); styleE.addElement("titlecolor").addAttribute("color", randomColor()); //behavior rootHot.addElement("behavior"); //content Element contentE = rootHot.addElement("content"); Element checklistE = contentE.addElement("checklist"); for (String val : list) { checklistE.addElement("item").addCDATA(val); } //desktop Element desktopE = rootHot.addElement("desktop"); desktopE.addElement("position").addAttribute("x", RandomUtil.numberStr(3)) .addAttribute("y", RandomUtil.numberStr(3)); desktopE.addElement("size").addAttribute("height", "200").addAttribute("width", "200"); //title Element titleE = rootHot.addElement("title"); titleE.addCDATA(StringUtils.defaultIfEmpty(checkListTitle.getText(), DateFormatUtils.format(System.currentTimeMillis(), "dd/MM/yyyy"))); if (!file.getName().toLowerCase().endsWith(".hottnote")) { file = new File(file.getParentFile(), file.getName() + ".hottnote"); } saveXml(document, file); JCommonUtil._jOptionPane_showMessageDialog_info("completed!\n" + file); } }); } } { checkListTitle = new JTextField(); checkListTitle.setToolTipText("title"); jPanel1.add(checkListTitle, BorderLayout.NORTH); } } } pack(); this.setSize(633, 415); } catch (Exception e) { //add your error handling code here e.printStackTrace(); } }
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 {//from w w w . j a v a2s . c o m // 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//from ww w . ja v a 2s .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. * /* w w w .j a v a2s .c om*/ * @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;//w w w . j a va 2 s. c o 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); }//from w w w .java2 s . 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. j a v a 2 s . com*/ 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 {/* w w w . jav a2s . c o m*/ 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(); } }