List of usage examples for org.jdom2 Element Element
public Element(final String name)
From source file:com.rometools.opml.io.impl.OPML10Generator.java
License:Apache License
protected Element generateOutline(final Outline outline) { final Element e = new Element("outline"); addNotNullAttribute(e, "text", outline.getText()); addNotNullAttribute(e, "type", outline.getType()); addNotNullAttribute(e, "title", outline.getTitle()); if (outline.isBreakpoint()) { addNotNullAttribute(e, "isBreakpoint", "true"); }/*from w w w . jav a 2 s . c om*/ if (outline.isComment()) { addNotNullAttribute(e, "isComment", "true"); } final List<Attribute> atts = Collections.synchronizedList(outline.getAttributes()); for (int i = 0; i < atts.size(); i++) { final Attribute att = atts.get(i); addNotNullAttribute(e, att.getName(), att.getValue()); } super.generateItemModules(outline.getModules(), e); e.addContent(generateOutlines(outline.getChildren())); return e; }
From source file:com.rometools.opml.io.impl.OPML20Generator.java
License:Apache License
@Override protected Element generateHead(final Opml opml) { final Element docsElement = new Element("docs"); docsElement.setText(opml.getDocs()); final Element headElement = super.generateHead(opml); headElement.addContent(docsElement); return headElement; }
From source file:com.rometools.rome.io.impl.OPML10Generator.java
License:Apache License
/** * Creates an XML document (JDOM) for the given feed bean. * <p>/*from ww w . j a v a 2 s . c o m*/ * * @param feed the feed bean to generate the XML document from. * @return the generated XML document (JDOM). * @throws IllegalArgumentException thrown if the type of the given feed bean does not match * with the type of the WireFeedGenerator. * @throws FeedException thrown if the XML Document could not be created. */ @Override public Document generate(final WireFeed feed) throws IllegalArgumentException, FeedException { if (!(feed instanceof Opml)) { throw new IllegalArgumentException("Not an OPML file"); } final Opml opml = (Opml) feed; final Document doc = new Document(); final Element root = new Element("opml"); doc.addContent(root); final Element head = generateHead(opml); if (head != null) { root.addContent(head); } final Element body = new Element("body"); root.addContent(body); super.generateFeedModules(opml.getModules(), root); body.addContent(generateOutlines(opml.getOutlines())); return doc; }
From source file:com.rometools.rome.io.impl.OPML10Generator.java
License:Apache License
protected Element generateHead(final Opml opml) { final Element head = new Element("head"); boolean hasHead = false; if (opml.getCreated() != null) { hasHead = addNotNullSimpleElement(head, "dateCreated", DateParser.formatRFC822(opml.getCreated(), Locale.US)); }/*from w ww .j a v a2s. c om*/ hasHead = hasHead || addNotNullSimpleElement(head, "expansionState", intArrayToCsvString(opml.getExpansionState())); if (opml.getModified() != null) { hasHead = hasHead || addNotNullSimpleElement(head, "dateModified", DateParser.formatRFC822(opml.getModified(), Locale.US)); } hasHead = hasHead || addNotNullSimpleElement(head, "ownerEmail", opml.getOwnerEmail()); hasHead = hasHead || addNotNullSimpleElement(head, "ownerName", opml.getOwnerName()); hasHead = hasHead || addNotNullSimpleElement(head, "title", opml.getTitle()); hasHead = hasHead || addNotNullSimpleElement(head, "vertScrollState", opml.getVerticalScrollState()); hasHead = hasHead || addNotNullSimpleElement(head, "windowBottom", opml.getWindowBottom()); hasHead = hasHead || addNotNullSimpleElement(head, "windowLeft", opml.getWindowLeft()); hasHead = hasHead || addNotNullSimpleElement(head, "windowRight", opml.getWindowRight()); hasHead = hasHead || addNotNullSimpleElement(head, "windowTop", opml.getWindowTop()); if (hasHead) { return head; } else { return null; } }
From source file:com.rometools.rome.io.impl.RSS091UserlandGenerator.java
License:Open Source License
protected Element generateSkipDaysElement(final List<String> days) { final Element skipDaysElement = new Element("skipDays"); for (final String day : days) { skipDaysElement.addContent(generateSimpleElement("day", day.toString())); }// w w w .j a v a 2s . co m return skipDaysElement; }
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 .jav a2s .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.RSS091UserlandGenerator.java
License:Open Source License
protected Element generateSkipDaysElement(List days) { Element skipDaysElement = new Element("skipDays"); for (int i = 0; i < days.size(); i++) { skipDaysElement.addContent(generateSimpleElement("day", days.get(i).toString())); }//from w w w. j a v a2s. co m return skipDaysElement; }
From source file:com.tactfactory.harmony.generator.androidxml.AttrsFile.java
License:Open Source License
@Override protected Element getDefaultRoot() { Element rootElement = new Element(ELEMENT_ROOT); rootElement.addNamespaceDeclaration( Namespace.getNamespace("android", "http://schemas.android.com/apk/res/android")); return rootElement; }
From source file:com.tactfactory.harmony.generator.androidxml.ColorsFile.java
License:Open Source License
@Override protected Element getDefaultRoot() { Element rootElement = new Element(ELEMENT_ROOT); return rootElement; }
From source file:com.tactfactory.harmony.generator.androidxml.manifest.ManifestActivity.java
License:Open Source License
@Override public Element toElement(Namespace ns) { Element result = new Element(ELEMENT_ACTIVITY); this.addAttribute(result, ns, ATTRIBUTE_NAME, this.name); this.addAttribute(result, ns, ATTRIBUTE_THEME, this.theme); this.addAttribute(result, ns, ATTRIBUTE_LABEL, this.label); this.addAttribute(result, ns, ATTRIBUTE_EXPORTED, this.exported); if (this.intentFilters != null) { for (ManifestIntentFilter intentFilter : this.intentFilters) { result.addContent(intentFilter.toElement(ns)); }/*from www . ja va2 s .c o m*/ } return result; }