List of usage examples for org.jdom2.output Format getPrettyFormat
public static Format getPrettyFormat()
From source file:it.cnr.ilc.clavius.controller.TranscriptionController.java
public String getTemplate() { Document doc = transcriptionManager.getDocTemplate(sentence.getLetterIdentificator()); XMLOutputter xop = new XMLOutputter(Format.getPrettyFormat()); template = xop.outputString(doc);/*from ww w. ja va2 s .com*/ return template; }
From source file:it.cnr.ilc.clavius.controller.TranscriptionController.java
public String getTeiDoc() throws Exception { Document doc = transcriptionManager.getDoc(getDocid()); XMLOutputter xop = new XMLOutputter(Format.getPrettyFormat()); teiDoc = xop.outputString(doc);/* w ww .j a v a 2 s . c o m*/ return teiDoc; }
From source file:it.cnr.ilc.clavius.manager.action.HelperIO.java
public static void fromDomToFile(Document doc, String filePath) { System.err.println("in fromDomToFile"); try {//from www . ja va 2s . co m File parent = new File(filePath).getParentFile(); parent.mkdirs(); XMLOutputter xo = new XMLOutputter(Format.getPrettyFormat()); xo.output(doc, new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8"))); } catch (IOException e) { e.printStackTrace(); } }
From source file:it.isislab.floasys.core.security.users.UserAccountXMLParser.java
License:Open Source License
/** * Write another account to the XML file. * @param is/*from w w w . j ava 2 s .co m*/ * @param os * @param account * @throws CannotParseException */ public void write(InputStream is, OutputStream os, UserAccount account) throws CannotParseException { try { //Read the existing file. Document doc = new SAXBuilder().build(is); Element rootNode = doc.getRootElement(); //Create a new user element. Element elAccount = new Element(EL_USERACCOUNT); Element elUsername = new Element(EL_USERNAME); Element elPassword = new Element(EL_PASSWORD); Element elActivationCode = new Element(EL_ACTIVATIONCODE); Element elActivated = new Element(EL_ACTIVATED); elAccount.addContent(elUsername); elAccount.addContent(elPassword); elAccount.addContent(elActivationCode); elAccount.addContent(elActivated); //Add the account to the root element. rootNode.addContent(elAccount); //Set the root for document. doc.setContent(rootNode); //Write the file content. XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(doc, os); } catch (Exception ex) { throw new CannotParseException(ex); } }
From source file:jcodecollector.io.PackageManager.java
License:Apache License
public static boolean exportSnippets(File file, String category) { ArrayList<Snippet> array = null; if (category == null) { array = DBMS.getInstance().getAllSnippets(); } else {//from w ww . j av a 2s. com array = DBMS.getInstance().getSnippets(category); } Element root = new Element("jcc-snippets-package"); root.setAttribute("version", GeneralInfo.APPLICATION_VERSION); Iterator<Snippet> iterator = array.iterator(); while (iterator.hasNext()) { Snippet snippet = iterator.next(); Element element = new Element("snippet"); Element category_xml = new Element("category"); category_xml.setText(snippet.getCategory()); element.addContent(category_xml); Element name_xml = new Element("name"); name_xml.setText(snippet.getName()); element.addContent(name_xml); String[] tags = snippet.getTags(); for (String tag : tags) { Element tag_xml = new Element("tag"); tag_xml.setText(tag); element.addContent(tag_xml); } Element syntax_xml = new Element("syntax"); syntax_xml.setText(snippet.getSyntax()); element.addContent(syntax_xml); Element code_xml = new Element("code"); code_xml.setText(snippet.getCode()); element.addContent(code_xml); Element comment_xml = new Element("comment"); comment_xml.setText(snippet.getComment()); element.addContent(comment_xml); root.addContent(element); } try { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(new Document(root), new FileOutputStream(file)); return true; } catch (Exception ex) { ex.printStackTrace(); return false; } }
From source file:jcodecollector.io.XMLManagerOldVersion.java
License:Apache License
public static boolean createPackage(File file, String name) { ArrayList<Snippet> array = DBMS.getInstance().getSnippets(name); Element root_xml = new Element("jcc-snippets-package"); boolean success; Iterator<Snippet> iterator = array.iterator(); while (iterator.hasNext()) { Snippet snippet = iterator.next(); Element element = new Element("snippet"); Element category_xml = new Element("category"); category_xml.setText(snippet.getCategory()); element.addContent(category_xml); Element name_xml = new Element("name"); name_xml.setText(snippet.getName()); element.addContent(name_xml);/* w w w.j ava2 s .co m*/ String[] tags = snippet.getTags(); for (String tag : tags) { Element tag_xml = new Element("tag"); tag_xml.setText(tag); element.addContent(tag_xml); } Element syntax_xml = new Element("syntax"); syntax_xml.setText(snippet.getSyntax()); element.addContent(syntax_xml); Element code_xml = new Element("code"); code_xml.setText(snippet.getCode()); element.addContent(code_xml); Element comment_xml = new Element("comment"); comment_xml.setText(snippet.getComment()); element.addContent(comment_xml); Element locked_xml = new Element("locked"); locked_xml.setText(String.valueOf(snippet.isLocked())); element.addContent(locked_xml); root_xml.addContent(element); } try { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(new Document(root_xml), new FileOutputStream(file)); success = true; } catch (Exception ex) { ex.printStackTrace(); success = false; } return success; }
From source file:jetbrains.buildServer.tools.XmlUtil.java
License:Apache License
public static void saveDocument(@NotNull Document document, @NotNull OutputStream os) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(os, Charset.forName("UTF-8")); try {/*from ww w . j a v a 2 s. c om*/ final Format format = Format.getPrettyFormat(); format.setLineSeparator(System.getProperty("line.separator")); format.setEncoding("UTF-8"); new XMLOutputter(format).output(document, writer); } finally { writer.flush(); writer.close(); } }
From source file:jmri.jmrit.vsdecoder.StoreXmlVSDecoderAction.java
License:Open Source License
public void saveVSDecoderProfile(java.io.File f) { try {//from w w w .ja v a 2 s.c o m Element root = new Element("VSDecoderConfig"); Document doc = XmlFile.newDocument(root, XmlFile.dtdLocation + "vsdecoder-config.dtd"); // add XSLT processing instruction // <?xml-stylesheet type="text/xsl" href="XSLT/throttle-layout-config.xsl"?> /*TODO java.util.Map<String,String> m = new java.util.HashMap<String,String>(); m.put("type", "text/xsl"); m.put("href", jmri.jmrit.XmlFile.xsltLocation + "throttle-layout-config.xsl"); ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m); doc.addContent(0, p); */ java.util.ArrayList<Element> children = new java.util.ArrayList<Element>(5); for (java.util.Iterator<VSDecoder> i = VSDecoderManager.instance().getVSDecoderList().iterator(); i .hasNext();) { VSDecoder vsd = i.next(); children.add(vsd.getXml()); } // Throttle-specific stuff below. Kept for reference /* // throttle list window children.add(ThrottleFrameManager.instance().getThrottlesListPanel().getXml() ); // throttle windows for (Iterator<ThrottleWindow> i = ThrottleFrameManager.instance().getThrottleWindows(); i.hasNext();) { ThrottleWindow tw = i.next(); Element throttleElement = tw.getXml(); children.add(throttleElement); } */ // End Throttle-specific stuff. root.setContent(children); FileOutputStream o = new java.io.FileOutputStream(f); try { XMLOutputter fmt = new XMLOutputter(); fmt.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")) .setTextMode(Format.TextMode.PRESERVE)); fmt.output(doc, o); } catch (IOException ex) { log.warn("Exception in storing VSDecoder xml: " + ex); } finally { o.close(); } } catch (FileNotFoundException ex) { log.warn("Exception in storing VSDecoder xml: " + ex); } catch (IOException ex) { log.warn("Exception in storing VSDecoder xml: " + ex); } }
From source file:json.JSONConverter.java
License:Apache License
/** * . Gives a string representation of the object * /* w w w. j a v a 2s . c o m*/ * @param format * uses prettyFormat if format is 2 * @return String representation of the object */ public final String toString(int format) { XMLOutputter sortie; if (format == 2) { sortie = new XMLOutputter(Format.getPrettyFormat()); } else { sortie = new XMLOutputter(); } return sortie.outputString(document); }
From source file:jworkspace.ui.plaf.PlafFactory.java
License:Open Source License
/** * Save all look and feel user config/*from w w w .j a v a 2 s .c om*/ */ public void save() { String fileName = CONFIG_FILE_PATH + File.separator + sysConfig; LOG.info( WorkspaceGUI.PROMPT + "Writing file" + WorkspaceGUI.LOG_SPACE + fileName + WorkspaceGUI.LOG_FINISH); File file = new File(fileName); try (StringWriter sw = new StringWriter(); FileOutputStream os = new FileOutputStream(file)) { Element plafs = new Element("plafs"); for (XPlafConnector connector : connectors) { plafs.addContent(connector.serialize()); } XMLOutputter serializer = new XMLOutputter(); serializer.setFormat(Format.getPrettyFormat()); serializer.output(plafs, sw); os.write(sw.toString().getBytes(StandardCharsets.UTF_8)); os.flush(); } catch (IOException e) { LOG.warn("Cannot save plaf factory", e); } }