List of usage examples for org.jdom2 Element addContent
@Override public Element addContent(final Collection<? extends Content> newContent)
From source file:com.rometools.rome.io.impl.RSS20Generator.java
License:Open Source License
@Override public void populateItem(final Item item, final Element eItem, final int index) { super.populateItem(item, eItem, index); final Element description = eItem.getChild("description", getFeedNamespace()); if (description != null) { description.removeAttribute("type"); }//from w w w . j ava 2s . co m final String author = item.getAuthor(); if (author != null) { eItem.addContent(generateSimpleElement("author", author)); } final String comments = item.getComments(); if (comments != null) { eItem.addContent(generateSimpleElement("comments", comments)); } final Guid guid = item.getGuid(); if (guid != null) { final Element eGuid = generateSimpleElement("guid", guid.getValue()); if (!guid.isPermaLink()) { eGuid.setAttribute("isPermaLink", "false"); } eItem.addContent(eGuid); } }
From source file:com.rometools.rome.io.impl.SyModuleGenerator.java
License:Open Source License
@Override public void generate(final Module module, final Element element) { final SyModule syModule = (SyModule) module; final String updatePeriod = syModule.getUpdatePeriod(); if (updatePeriod != null) { final Element updatePeriodElement = new Element("updatePeriod", SY_NS); updatePeriodElement.addContent(updatePeriod); element.addContent(updatePeriodElement); }/*from w ww . j a va 2 s . c o m*/ final Element updateFrequencyElement = new Element("updateFrequency", SY_NS); updateFrequencyElement.addContent(String.valueOf(syModule.getUpdateFrequency())); element.addContent(updateFrequencyElement); final Date updateBase = syModule.getUpdateBase(); if (updateBase != null) { final Element updateBaseElement = new Element("updateBase", SY_NS); updateBaseElement.addContent(DateParser.formatW3CDateTime(updateBase, Locale.US)); element.addContent(updateBaseElement); } }
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); Double totalPw = 0D;// w ww.ja va 2s . c om 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 void addEntry(Entry entry, Element parent) throws FeedException { Element eEntry = new Element("entry", getFeedNamespace()); populateEntry(entry, eEntry);//w w w .jav a2s .c o m checkEntryConstraints(eEntry); generateItemModules(entry.getModules(), eEntry); parent.addContent(eEntry); }
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected void populateFeedHeader(Feed feed, Element eFeed) throws FeedException { if (feed.getTitleEx() != null) { Element titleElement = new Element("title", getFeedNamespace()); fillContentElement(titleElement, feed.getTitleEx()); eFeed.addContent(titleElement); }/*from w ww . j a va 2 s. c o m*/ List links = feed.getAlternateLinks(); for (int i = 0; i < links.size(); i++) { eFeed.addContent(generateLinkElement((Link) links.get(i))); } links = feed.getOtherLinks(); for (int i = 0; i < links.size(); i++) { eFeed.addContent(generateLinkElement((Link) links.get(i))); } if (feed.getAuthors() != null && feed.getAuthors().size() > 0) { Element authorElement = new Element("author", getFeedNamespace()); fillPersonElement(authorElement, (Person) feed.getAuthors().get(0)); eFeed.addContent(authorElement); } List contributors = feed.getContributors(); for (int i = 0; i < contributors.size(); i++) { Element contributorElement = new Element("contributor", getFeedNamespace()); fillPersonElement(contributorElement, (Person) contributors.get(i)); eFeed.addContent(contributorElement); } if (feed.getTagline() != null) { Element taglineElement = new Element("tagline", getFeedNamespace()); fillContentElement(taglineElement, feed.getTagline()); eFeed.addContent(taglineElement); } if (feed.getId() != null) { eFeed.addContent(generateSimpleElement("id", feed.getId())); } if (feed.getGenerator() != null) { eFeed.addContent(generateGeneratorElement(feed.getGenerator())); } if (feed.getCopyright() != null) { eFeed.addContent(generateSimpleElement("copyright", feed.getCopyright())); } if (feed.getInfo() != null) { Element infoElement = new Element("info", getFeedNamespace()); fillContentElement(infoElement, feed.getInfo()); eFeed.addContent(infoElement); } if (feed.getModified() != null) { Element modifiedElement = new Element("modified", getFeedNamespace()); modifiedElement.addContent(DateParser.formatW3CDateTime(feed.getModified())); eFeed.addContent(modifiedElement); } }
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected void populateEntry(Entry entry, Element eEntry) throws FeedException { if (entry.getTitleEx() != null) { Element titleElement = new Element("title", getFeedNamespace()); fillContentElement(titleElement, entry.getTitleEx()); eEntry.addContent(titleElement); }//from ww w . ja v a 2 s .c o m List links = entry.getAlternateLinks(); for (int i = 0; i < links.size(); i++) { eEntry.addContent(generateLinkElement((Link) links.get(i))); } links = entry.getOtherLinks(); for (int i = 0; i < links.size(); i++) { eEntry.addContent(generateLinkElement((Link) links.get(i))); } if (entry.getAuthors() != null && entry.getAuthors().size() > 0) { Element authorElement = new Element("author", getFeedNamespace()); fillPersonElement(authorElement, (Person) entry.getAuthors().get(0)); eEntry.addContent(authorElement); } List contributors = entry.getContributors(); for (int i = 0; i < contributors.size(); i++) { Element contributorElement = new Element("contributor", getFeedNamespace()); fillPersonElement(contributorElement, (Person) contributors.get(i)); eEntry.addContent(contributorElement); } if (entry.getId() != null) { eEntry.addContent(generateSimpleElement("id", entry.getId())); } if (entry.getModified() != null) { Element modifiedElement = new Element("modified", getFeedNamespace()); modifiedElement.addContent(DateParser.formatW3CDateTime(entry.getModified())); eEntry.addContent(modifiedElement); } if (entry.getIssued() != null) { Element issuedElement = new Element("issued", getFeedNamespace()); issuedElement.addContent(DateParser.formatW3CDateTime(entry.getIssued())); eEntry.addContent(issuedElement); } if (entry.getCreated() != null) { Element createdElement = new Element("created", getFeedNamespace()); createdElement.addContent(DateParser.formatW3CDateTime(entry.getCreated())); eEntry.addContent(createdElement); } if (entry.getSummary() != null) { Element summaryElement = new Element("summary", getFeedNamespace()); fillContentElement(summaryElement, entry.getSummary()); eEntry.addContent(summaryElement); } List contents = entry.getContents(); for (int i = 0; i < contents.size(); i++) { Element contentElement = new Element("content", getFeedNamespace()); fillContentElement(contentElement, (Content) contents.get(i)); eEntry.addContent(contentElement); } generateForeignMarkup(eEntry, (List) entry.getForeignMarkup()); }
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected void fillPersonElement(Element element, Person person) { if (person.getName() != null) { element.addContent(generateSimpleElement("name", person.getName())); }/*www . java 2s. c o m*/ if (person.getUrl() != null) { element.addContent(generateSimpleElement("url", person.getUrl())); } if (person.getEmail() != null) { element.addContent(generateSimpleElement("email", person.getEmail())); } }
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected Element generateTagLineElement(Content tagline) { Element taglineElement = new Element("tagline", getFeedNamespace()); if (tagline.getType() != null) { Attribute typeAttribute = new Attribute("type", tagline.getType()); taglineElement.setAttribute(typeAttribute); }//from w ww . j a v a2s . co m if (tagline.getValue() != null) { taglineElement.addContent(tagline.getValue()); } return taglineElement; }
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected void fillContentElement(Element contentElement, Content content) throws FeedException { if (content.getType() != null) { Attribute typeAttribute = new Attribute("type", content.getType()); contentElement.setAttribute(typeAttribute); }/*from w ww. j a v a 2s .c om*/ String mode = content.getMode(); if (mode != null) { Attribute modeAttribute = new Attribute("mode", content.getMode().toString()); contentElement.setAttribute(modeAttribute); } if (content.getValue() != null) { if (mode == null || mode.equals(Content.ESCAPED)) { contentElement.addContent(content.getValue()); } else if (mode.equals(Content.BASE64)) { contentElement.addContent(Base64.encode(content.getValue())); } else if (mode.equals(Content.XML)) { StringBuffer tmpDocString = new StringBuffer("<tmpdoc>"); tmpDocString.append(content.getValue()); tmpDocString.append("</tmpdoc>"); StringReader tmpDocReader = new StringReader(tmpDocString.toString()); Document tmpDoc; try { SAXBuilder saxBuilder = new SAXBuilder(); tmpDoc = saxBuilder.build(tmpDocReader); } catch (Exception ex) { throw new FeedException("Invalid XML", ex); } List children = tmpDoc.getRootElement().removeContent(); contentElement.addContent(children); } } }
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected Element generateGeneratorElement(Generator generator) { Element generatorElement = new Element("generator", getFeedNamespace()); if (generator.getUrl() != null) { Attribute urlAttribute = new Attribute("url", generator.getUrl()); generatorElement.setAttribute(urlAttribute); }//www . j a va2s.c o m if (generator.getVersion() != null) { Attribute versionAttribute = new Attribute("version", generator.getVersion()); generatorElement.setAttribute(versionAttribute); } if (generator.getValue() != null) { generatorElement.addContent(generator.getValue()); } return generatorElement; }