List of usage examples for org.jdom2 Document Document
public Document(List<? extends Content> content)
Document
, with the supplied list of content, and a DocType
declaration only if the content contains a DocType instance. From source file:com.rometools.rome.io.impl.RSS091NetscapeGenerator.java
License:Open Source License
@Override protected Document createDocument(final Element root) { final Document doc = new Document(root); final DocType docType = new DocType(RSS091NetscapeParser.ELEMENT_NAME, RSS091NetscapeParser.PUBLIC_ID, RSS091NetscapeParser.SYSTEM_ID); doc.setDocType(docType);// www . j av a2 s .c o m return doc; }
From source file:com.rometools.rome.io.impl.RSS091UserlandGenerator.java
License:Open Source License
@Override protected Document createDocument(final Element root) { return new Document(root); }
From source file:com.soulgalore.web.pagesavings.reporters.XMLReporter.java
License:Apache License
public void report(Set<SiteResult> results, Map<String, DescriptiveStatistics> statistics) { Date reportDate = new Date(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); Element root = new Element("savings"); root.setAttribute("date", "" + reportDate); Element resultsXML = new Element("results"); root.addContent(resultsXML);//from ww w .j av a2 s . c o m Double totalPw = 0D; Double totalUnique = 0D; for (SiteResult siteResult : results) { totalPw += siteResult.getTotalSavings() * siteResult.getSite().getPageViews(); totalUnique += siteResult.getTotalSavings() * siteResult.getSite().getUniqueBrowsers(); Element site = new Element("site"); Element url = new Element("url"); Element weight = new Element("total-page-weight"); Element savingsPerPage = new Element("savings-per-page"); Element savingsForPW = new Element("savings-for-page-view"); Element savingsForUnique = new Element("savings-for-unique-browsers"); Element savingsPercentage = new Element("savings-percentage"); url.addContent(new CDATA(siteResult.getSite().getUrl())); savingsPerPage.setAttribute(READABLE, humanReadableByteCount(Math.round(siteResult.getTotalSavings()), true)); savingsPerPage.setAttribute(KB, "" + Math.round(siteResult.getTotalSavings())); savingsForPW.setAttribute(READABLE, humanReadableByteCount( Math.round(siteResult.getTotalSavings() * siteResult.getSite().getPageViews()), true)); savingsForPW.setAttribute(KB, "" + Math.round(siteResult.getTotalSavings() * siteResult.getSite().getPageViews())); savingsForUnique.setAttribute(READABLE, humanReadableByteCount( Math.round(siteResult.getTotalSavings() * siteResult.getSite().getUniqueBrowsers()), true)); savingsForUnique.setAttribute(KB, "" + Math.round(siteResult.getTotalSavings() * siteResult.getSite().getUniqueBrowsers())); savingsPercentage.addContent("" + Math.round(siteResult.getSavingsPercentage() * 100) / 100.0d); weight.setAttribute(READABLE, humanReadableByteCount(siteResult.getTotalSizeBytes() / 1000, true)); weight.setAttribute(KB, "" + siteResult.getTotalSizeBytes() / 1000); Element rulesSavings = new Element("rule-savings"); for (RuleResult ruleResult : siteResult.getResults()) { Element rule = new Element(ruleResult.getRule()); rule.addContent("" + ruleResult.getSavings()); rulesSavings.addContent(rule); } site.addContent(url); site.addContent(weight); site.addContent(savingsPerPage); site.addContent(savingsForPW); site.addContent(savingsForUnique); site.addContent(savingsPercentage); site.addContent(rulesSavings); resultsXML.addContent(site); } Element summary = new Element("summary"); summary.setAttribute("nrofsites", "" + results.size()); Element totalPW = new Element("total-pw"); Element totalUniqueSummary = new Element("total-unique"); totalPW.setAttribute(READABLE, humanReadableByteCount(Math.round(totalPw), true)); totalPW.setAttribute(KB, "" + Math.round(totalPw)); totalUniqueSummary.setAttribute(READABLE, humanReadableByteCount(Math.round(totalUnique), true)); totalUniqueSummary.setAttribute(KB, "" + Math.round(totalUnique)); summary.addContent(totalPW); summary.addContent(totalUniqueSummary); for (String rule : statistics.keySet()) { DescriptiveStatistics stats = statistics.get(rule); Element ruleElement = new Element(rule); Element max = new Element("max"); Element median = new Element("median"); max.addContent("" + stats.getMax()); median.addContent("" + stats.getPercentile(50)); ruleElement.addContent(max); ruleElement.addContent(median); summary.addContent(ruleElement); } resultsXML.addContent(summary); Document doc = new Document(root); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); try { FileWriter writer = new FileWriter("report-" + df.format(reportDate) + ".xml"); outputter.output(doc, writer); } catch (Exception e) { } }
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected Document createDocument(Element root) { return new Document(root); }
From source file:com.sun.syndication.io.impl.RSS091NetscapeGenerator.java
License:Open Source License
protected Document createDocument(Element root) { Document doc = new Document(root); DocType docType = new DocType(RSS091NetscapeParser.ELEMENT_NAME, RSS091NetscapeParser.PUBLIC_ID, RSS091NetscapeParser.SYSTEM_ID); doc.setDocType(docType);/*from w w w.ja va 2 s. c o m*/ return doc; }
From source file:com.tactfactory.harmony.platform.winphone.updater.XmlProjectWinphone.java
License:Open Source License
public void open(String file) { this.file = file; if (TactFileUtils.exists(file)) { this.doc = XMLUtils.openXMLFile(file); } else {/*from ww w . jav a 2 s. co m*/ Element rootElement = new Element(XML_ELEMENT_ROOT); this.doc = new Document(rootElement); } // Load Root element this.rootNode = doc.getRootElement(); }
From source file:com.tactfactory.harmony.updater.impl.XmlAndroid.java
License:Open Source License
@Override public void open(String file) { this.file = file; if (TactFileUtils.exists(file)) { this.doc = XMLUtils.openXMLFile(file); } else {// w w w.j a v a 2 s .com Element rootElement = new Element("resources"); this.doc = new Document(rootElement); } // Load Root element this.rootNode = doc.getRootElement(); // Load Name space (required for manipulate attributes) this.namespace = rootNode.getNamespace("android"); }
From source file:com.thoughtworks.go.config.MagicalGoConfigXmlWriter.java
License:Apache License
private Document createEmptyCruiseConfigDocument() { Element root = new Element("cruise"); Namespace xsiNamespace = Namespace.getNamespace("xsi", XML_NS); root.addNamespaceDeclaration(xsiNamespace); registry.registerNamespacesInto(root); root.setAttribute("noNamespaceSchemaLocation", "cruise-config.xsd", xsiNamespace); String xsds = registry.xsds(); if (!xsds.isEmpty()) { root.setAttribute("schemaLocation", xsds, xsiNamespace); }//from w ww .j a v a 2 s.co m root.setAttribute("schemaVersion", Integer.toString(GoConstants.CONFIG_SCHEMA_VERSION)); return new Document(root); }
From source file:cz.lbenda.dataman.db.ExportTableData.java
License:Apache License
/** Write rows from sql query to output stream * @param sqlQueryRows rows//from ww w . j a va2s .c o m * @param outputStream stream to which are data write */ public static void writeSqlQueryRowsToXMLv2(SQLQueryRows sqlQueryRows, OutputStream outputStream) throws IOException { Element root = new Element("export"); root.setAttribute("sql", sqlQueryRows.getSQL()); root.setAttribute("version", "2"); List<Element> rows = new ArrayList<>(sqlQueryRows.getRows().size()); sqlQueryRows.getRows().forEach(rowDesc -> { Element row = new Element("row"); List<Element> cols = new ArrayList<>(sqlQueryRows.getMetaData().getColumns().size()); sqlQueryRows.getMetaData().getColumns().forEach(columnDesc -> { Element element = new Element(columnDesc.getName()); if (rowDesc.isColumnNull(columnDesc)) { element.setAttribute("null", "true"); } else { element.setText(rowDesc.getColumnValueStr(columnDesc)); } cols.add(element); }); row.addContent(cols); rows.add(row); }); root.addContent(rows); XMLOutputter xmlOutputter = new XMLOutputter(); xmlOutputter.output(new Document(root), outputStream); }
From source file:cz.lbenda.dbapp.rc.SessionConfiguration.java
License:Apache License
public static String storeToString() { Document doc = new Document(storeAllToElement()); XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); StringWriter sw = new StringWriter(); try {// w ww .j a v a2s .co m xmlOutput.output(doc, sw); return sw.toString(); } catch (IOException e) { LOG.error("There was problem with write XML output to StringWriter", e); throw new RuntimeException("There was problem with write XML output to StringWriter", e); } }