List of usage examples for org.jdom2.output Format getPrettyFormat
public static Format getPrettyFormat()
From source file:com.astronomy.project.Project.java
/** * Save project as XML file//from ww w . j a va 2 s .com * @param file XML file * @throws FileNotFoundException File not found error * @throws IOException IO error * @throws NullPointerException Null pointer error */ public void toXML(File file) throws FileNotFoundException, IOException, NullPointerException { Element estudioElemento = new Element("estudio"); Document doc = new Document(estudioElemento); estudioElemento.setAttribute("nombre", name); Element aa = new Element("alineamientos"); estudioElemento.addContent(aa); for (int i = 0; i < data.size(); i++) { Alignment ali = (Alignment) data.get(i); aa.addContent(ali.getXMLElement()); } XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); FileOutputStream out = null; try { xmlOutput.output(doc, out = new FileOutputStream(file)); } finally { out.close(); } }
From source file:com.bc.ceres.nbmgen.NbmGenTool.java
License:Open Source License
private static void writeXml(File file, Document document) throws IOException { XMLOutputter xmlOutput = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setIndent(" "); xmlOutput.setFormat(format);/*from ww w .j a v a 2 s . c om*/ xmlOutput.output(document, new FileWriter(file)); }
From source file:com.bennavetta.util.tycho.impl.DefaultWrapperGenerator.java
License:Apache License
private void writeModules(List<String> modules, File pomFile) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); Document pom = builder.build(pomFile); Namespace pomNs = pom.getRootElement().getNamespace(); Element modulesElem = pom.getRootElement().getChild("modules", pomNs); if (modulesElem == null) { modulesElem = new Element("modules", pomNs); pom.getRootElement().addContent(modulesElem); }//ww w . jav a 2 s. c o m for (String module : modules) { boolean exists = false; for (Element existingModule : modulesElem.getChildren()) { if (existingModule.getTextTrim().equals(module)) { exists = true; break; } } if (!exists) { Element moduleElem = new Element("module", pomNs); moduleElem.setText(module); modulesElem.addContent(moduleElem); } } XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat().setIndent("\t")); try (FileOutputStream out = new FileOutputStream(pomFile)) { xout.output(pom, out); } }
From source file:com.c4om.autoconf.ulysses.extra.svrlmultipathinterpreter.SVRLMultipathInterpreterMain.java
License:Apache License
/** * Main method, invoked when the application starts * @param args command-line arguments. First is path to svrl document, second is the path to the configuration, third is the path to the metamodel *//*from ww w . j ava 2 s. c om*/ public static void main(String[] args) throws Exception { SVRLMultipathInterpreterMain multipathInterpreter = new SVRLMultipathInterpreterMain(args[1], args[2], args[3]); Document svrlDocument = loadJDOMDocumentFromFile(new File(args[0])); Document result = multipathInterpreter.interpret(svrlDocument); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); System.out.println(outputter.outputString(result)); }
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// w ww . j av a 2 s. com * @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 {// w w w.j ava 2s .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 w ww . ja v a 2s .c o m*/ 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 {/* ww w . j a va 2 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.dexterapps.android.translator.TranslateAndSaveAndroid.java
License:Apache License
private void generateXMLForCountry(String countryCode, List<String> translatedText, ArrayList<AndroidStringMapping> stringXmlDOM, HashMap<String, Integer> baseStringResourcesMapping, String outPutFolder) {/*from w w w .j a v a 2 s .c o m*/ Element resources = new Element("resources"); Document doc = new Document(resources); //System.out.println("Generating XML"); //int totalNumberOfStrings = 0; for (int i = 0; i < stringXmlDOM.size(); i++) { AndroidStringMapping stringMapping = stringXmlDOM.get(i); if (stringMapping.getType().equalsIgnoreCase("string")) { Element string = new Element("string"); string.setAttribute(new Attribute("name", stringMapping.getAttributeName())); //To get the attribute value, use the hasmap and then string array int translatedTextIndex = baseStringResourcesMapping.get(stringMapping.getAttributeValue()); string.setText(translatedText.get(translatedTextIndex)); //Add element to root doc.getRootElement().addContent(string); } else if (stringMapping.getType().equalsIgnoreCase("string-array")) { Element stringArray = new Element("string-array"); stringArray.setAttribute(new Attribute("name", stringMapping.getAttributeName())); //Since this is String array it will have a list of string items, get the list of string items ArrayList<String> stringArrayItems = (ArrayList<String>) stringMapping.getAttributeValue(); for (int j = 0; j < stringArrayItems.size(); j++) { int translatedTextIndex = baseStringResourcesMapping.get(stringArrayItems.get(j)); stringArray.addContent(new Element("item").setText(translatedText.get(translatedTextIndex))); } //Add element to root doc.getRootElement().addContent(stringArray); } else { Element stringArray = new Element("plurals"); stringArray.setAttribute(new Attribute("name", stringMapping.getAttributeName())); //Since this is plurals it will have a list of string items with values, get the list of string items ArrayList<AndroidStringPlurals> stringPluralItems = (ArrayList<AndroidStringPlurals>) stringMapping .getAttributeValue(); for (int j = 0; j < stringPluralItems.size(); j++) { int translatedTextIndex = baseStringResourcesMapping .get(stringPluralItems.get(j).getAttributeValue()); Element pluralItem = new Element("item"); pluralItem.setAttribute("quantity", stringPluralItems.get(j).getAttributeName()); pluralItem.setText(translatedText.get(translatedTextIndex)); stringArray.addContent(pluralItem); } //Add element to root doc.getRootElement().addContent(stringArray); } } // new XMLOutputter().output(doc, System.out); XMLOutputter xmlOutput = new XMLOutputter(); try { // System.out.println("Saving File"); Format format = Format.getPrettyFormat(); format.setEncoding("UTF-8"); xmlOutput.setFormat(format); File file = new File(outPutFolder + "/values-" + countryCode); if (!file.exists()) { file.mkdir(); } file = new File(outPutFolder + "/values-" + countryCode + "/strings.xml"); FileOutputStream fop = new FileOutputStream(file); xmlOutput.output(doc, fop); System.out.println("Translation Successful !!"); // System.out.println("File Saved!"); } catch (Exception e) { System.out.println(e.getMessage()); } }
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 w w w . j a va 2 s . com*/ 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(); } }