List of usage examples for org.jdom2.output XMLOutputter XMLOutputter
public XMLOutputter(XMLOutputProcessor processor)
XMLOutputter
with the specified XMLOutputProcessor. From source file:com.c4om.utils.xmlutils.JDOMUtils.java
License:Apache License
/** * Method that converts a JDOM2 {@link Document} to String * @param document the document//from w w w.j a v a2s .c o m * @return the string */ public static String convertJDOMDocumentToString(Document document) { Format xmlFormat = Format.getPrettyFormat(); xmlFormat.setLineSeparator(LineSeparator.SYSTEM); XMLOutputter outputter = new XMLOutputter(xmlFormat); String result = outputter.outputString(document); return result; }
From source file:com.cats.version.VersionCfgParseAndSave.java
License:Apache License
public boolean saveVersionInfo(List<VersionInfo> infos, String fullPath) { try {//from w w w .j a v a 2 s . c o m Document doc = new Document(); Element root = new Element("software-group"); for (VersionInfo info : infos) { Element softEle = new Element("software"); softEle.setAttribute("name", info.getAppName()); Element versionCodeEle = new Element("latest-version-code"); Element versionNameEle = new Element("latest-version"); Element versionPathEle = new Element("latest-version-abspath"); Element startupNameEle = new Element("latest-version-startup"); versionCodeEle.setText(String.valueOf(info.getVersionCode())); versionNameEle.setText(info.getVersion()); versionPathEle.setText(info.getPath()); startupNameEle.setText(info.getStartupName()); softEle.addContent(versionCodeEle); softEle.addContent(versionNameEle); softEle.addContent(versionPathEle); softEle.addContent(startupNameEle); List<VersionInfoDetail> details = info.getDetails(); if (null != details) { Element detailEles = new Element("latest-version-detail"); for (VersionInfoDetail verDetail : details) { Element itemElem = new Element("item"); itemElem.setAttribute("name", verDetail.getTitle()); List<String> detailList = verDetail.getDetail(); for (String detailInfo : detailList) { Element detailEle = new Element("detail"); detailEle.setText(detailInfo); itemElem.addContent(detailEle); } detailEles.addContent(itemElem); } softEle.addContent(detailEles); } List<String> ignoreFiles = info.getIgnoreFiles(); if (ignoreFiles != null) { Element ignoreEles = new Element("ignore-files"); for (String ignoreInfo : ignoreFiles) { Element ignoreItemEle = new Element("item"); ignoreItemEle.setText(ignoreInfo); ignoreEles.addContent(ignoreItemEle); } softEle.addContent(ignoreEles); } root.addContent(softEle); } doc.setRootElement(root); //Save to xml file XMLOutputter xmlOut = null; FileOutputStream fos = null; try { fos = new FileOutputStream(fullPath); xmlOut = new XMLOutputter(Format.getPrettyFormat()); xmlOut.output(doc, fos); } catch (Exception e) { e.printStackTrace(); } finally { if (null != fos) { try { fos.close(); } catch (Exception e) { e.printStackTrace(); } } } } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:com.collir24.policyextractor.Extract.java
License:Apache License
private static void format(List<ModulePermissions> modulePermissions) { XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); Writer writer = null;/*from www . j a va 2s .c om*/ try { writer = new BufferedWriter(new FileWriter("test.xml")); Document doc = buildDocument(modulePermissions); xmlOut.output(doc, writer); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Problem writing output file.", e); throw new RuntimeException(e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Problem writing output file.", e); } } } }
From source file:com.cybernostics.jsp2thymeleaf.JSP2Thymeleaf.java
private void writeTree(JspTree jspTree, OutputStream outputStream) { try {/*from ww w .j a v a2 s . c o m*/ Document doc = new Document(); final List<Content> content = rootContentFor(jspTree); doc.addContent(content); XMLOutputter out = new XMLOutputter(Format.getPrettyFormat().setTextMode(Format.TextMode.NORMALIZE) .setLineSeparator(NEWLINE).setOmitDeclaration(true)); out.output(doc, outputStream); } catch (IOException ex) { Logger.getLogger(JSP2Thymeleaf.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.facebook.buck.ide.intellij.projectview.ProjectView.java
License:Apache License
private void saveDocument(String path, String filename, XML mode, Document document) { if (path != null) { filename = fileJoin(path, filename); }/*from ww w . j av a 2 s. c o m*/ if (dryRun) { stderr("Writing %s\n", filename); return; } Format prettyFormat = Format.getPrettyFormat(); prettyFormat.setOmitDeclaration(mode == XML.NO_DECLARATION); XMLOutputter outputter = new XMLOutputter(prettyFormat); try (Writer writer = new FileWriter(filename)) { outputter.output(document, writer); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.forum.action.eder.PerfilACT.java
public void write(Document document, String url) { try {//from w ww .j a va 2 s . co m new XMLOutputter(Format.getPrettyFormat()).output(document, new FileOutputStream(url, false)); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:com.forum.action.eder.TemaACT.java
private void write(Document document, String url) { try {//from w w w.ja v a 2 s . com new XMLOutputter(Format.getPrettyFormat()).output(document, new FileOutputStream(url, false)); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:com.github.cat.yum.store.util.YumUtil.java
private static void xmlToFile(Document doc, File outfile) throws IOException { FileOutputStream fileOutputStream = null; try {/*from w ww . j ava2 s . com*/ Format formate = Format.getPrettyFormat(); formate.setOmitEncoding(true); formate.setLineSeparator(LineSeparator.NL); // System.out.println(new XMLOutputter(formate).outputString(doc)); fileOutputStream = new FileOutputStream(outfile, false); new XMLOutputter(formate).output(doc, fileOutputStream); } finally { try { if (null != fileOutputStream) { fileOutputStream.close(); } } catch (IOException ignore) { } } }
From source file:com.googlecode.mipnp.mediaserver.cds.DidlLiteDocument.java
License:Open Source License
@Override public String toString() { Format format = Format.getRawFormat(); format.setOmitDeclaration(true);/*from w w w . j a v a 2 s . c om*/ XMLOutputter outputter = new XMLOutputter(format); return outputter.outputString(document); }
From source file:com.googlesource.gerrit.plugins.manifest.ManifestXml.java
License:Apache License
private void printDocument(OutputStream out) throws IOException { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.setXMLOutputProcessor(new CustomOutputter(dtdAttributes)); outputter.output(doc, out);//from w w w . ja v a 2 s .c o m }