List of usage examples for org.jdom2 Element addContent
@Override public Element addContent(final Collection<? extends Content> newContent)
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected Element generateSimpleElement(String name, String value) { Element element = new Element(name, getFeedNamespace()); element.addContent(value); return element; }
From source file:com.sun.syndication.io.impl.Atom10Generator.java
License:Open Source License
protected void addEntry(Entry entry, Element parent) throws FeedException { Element eEntry = new Element("entry", getFeedNamespace()); if (entry.getXmlBase() != null) { eEntry.setAttribute("base", entry.getXmlBase(), Namespace.XML_NAMESPACE); }/*from ww w.jav a 2s . co m*/ populateEntry(entry, eEntry); generateForeignMarkup(eEntry, (List) entry.getForeignMarkup()); checkEntryConstraints(eEntry); generateItemModules(entry.getModules(), eEntry); parent.addContent(eEntry); }
From source file:com.sun.syndication.io.impl.Atom10Generator.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); }// w ww.j av a 2s.c om List links = feed.getAlternateLinks(); if (links != null) for (int i = 0; i < links.size(); i++) { eFeed.addContent(generateLinkElement((Link) links.get(i))); } links = feed.getOtherLinks(); if (links != null) for (int j = 0; j < links.size(); j++) { eFeed.addContent(generateLinkElement((Link) links.get(j))); } List cats = feed.getCategories(); if (cats != null) for (Iterator iter = cats.iterator(); iter.hasNext();) { eFeed.addContent(generateCategoryElement((Category) iter.next())); } List authors = feed.getAuthors(); if (authors != null && authors.size() > 0) { for (int i = 0; i < authors.size(); i++) { Element authorElement = new Element("author", getFeedNamespace()); fillPersonElement(authorElement, (Person) feed.getAuthors().get(i)); eFeed.addContent(authorElement); } } List contributors = feed.getContributors(); if (contributors != null && contributors.size() > 0) { 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.getSubtitle() != null) { Element subtitleElement = new Element("subtitle", getFeedNamespace()); fillContentElement(subtitleElement, feed.getSubtitle()); eFeed.addContent(subtitleElement); } if (feed.getId() != null) { eFeed.addContent(generateSimpleElement("id", feed.getId())); } if (feed.getGenerator() != null) { eFeed.addContent(generateGeneratorElement(feed.getGenerator())); } if (feed.getRights() != null) { eFeed.addContent(generateSimpleElement("rights", feed.getRights())); } if (feed.getIcon() != null) { eFeed.addContent(generateSimpleElement("icon", feed.getIcon())); } if (feed.getLogo() != null) { eFeed.addContent(generateSimpleElement("logo", feed.getLogo())); } if (feed.getUpdated() != null) { Element updatedElement = new Element("updated", getFeedNamespace()); updatedElement.addContent(DateParser.formatW3CDateTime(feed.getUpdated())); eFeed.addContent(updatedElement); } }
From source file:com.sun.syndication.io.impl.Atom10Generator.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.java2s. c o m*/ List links = entry.getAlternateLinks(); if (links != null) { for (int i = 0; i < links.size(); i++) { eEntry.addContent(generateLinkElement((Link) links.get(i))); } } links = entry.getOtherLinks(); if (links != null) { for (int i = 0; i < links.size(); i++) { eEntry.addContent(generateLinkElement((Link) links.get(i))); } } List cats = entry.getCategories(); if (cats != null) { for (int i = 0; i < cats.size(); i++) { eEntry.addContent(generateCategoryElement((Category) cats.get(i))); } } List authors = entry.getAuthors(); if (authors != null && authors.size() > 0) { for (int i = 0; i < authors.size(); i++) { Element authorElement = new Element("author", getFeedNamespace()); fillPersonElement(authorElement, (Person) entry.getAuthors().get(i)); eEntry.addContent(authorElement); } } List contributors = entry.getContributors(); if (contributors != null && contributors.size() > 0) { 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.getUpdated() != null) { Element updatedElement = new Element("updated", getFeedNamespace()); updatedElement.addContent(DateParser.formatW3CDateTime(entry.getUpdated())); eEntry.addContent(updatedElement); } if (entry.getPublished() != null) { Element publishedElement = new Element("published", getFeedNamespace()); publishedElement.addContent(DateParser.formatW3CDateTime(entry.getPublished())); eEntry.addContent(publishedElement); } if (entry.getContents() != null && entry.getContents().size() > 0) { Element contentElement = new Element("content", getFeedNamespace()); Content content = (Content) entry.getContents().get(0); fillContentElement(contentElement, content); eEntry.addContent(contentElement); } if (entry.getSummary() != null) { Element summaryElement = new Element("summary", getFeedNamespace()); fillContentElement(summaryElement, entry.getSummary()); eEntry.addContent(summaryElement); } if (entry.getSource() != null) { Element sourceElement = new Element("source", getFeedNamespace()); populateFeedHeader(entry.getSource(), sourceElement); eEntry.addContent(sourceElement); } }
From source file:com.sun.syndication.io.impl.Atom10Generator.java
License:Open Source License
protected void fillPersonElement(Element element, Person person) { if (person.getName() != null) { element.addContent(generateSimpleElement("name", person.getName())); }// www . j ava2 s.c om if (person.getUri() != null) { element.addContent(generateSimpleElement("uri", person.getUri())); } if (person.getEmail() != null) { element.addContent(generateSimpleElement("email", person.getEmail())); } generatePersonModules(person.getModules(), element); }
From source file:com.sun.syndication.io.impl.Atom10Generator.java
License:Open Source License
protected Element generateTagLineElement(Content tagline) { Element taglineElement = new Element("subtitle", getFeedNamespace()); if (tagline.getType() != null) { Attribute typeAttribute = new Attribute("type", tagline.getType()); taglineElement.setAttribute(typeAttribute); }// w w w . j a va2 s .com if (tagline.getValue() != null) { taglineElement.addContent(tagline.getValue()); } return taglineElement; }
From source file:com.sun.syndication.io.impl.Atom10Generator.java
License:Open Source License
protected void fillContentElement(Element contentElement, Content content) throws FeedException { String type = content.getType(); String atomType = type;// w w w. ja v a 2 s . c o m if (type != null) { // Fix for issue #39 "Atom 1.0 Text Types Not Set Correctly" // we're not sure who set this value, so ensure Atom types are used if ("text/plain".equals(type)) atomType = Content.TEXT; else if ("text/html".equals(type)) atomType = Content.HTML; else if ("application/xhtml+xml".equals(type)) atomType = Content.XHTML; Attribute typeAttribute = new Attribute("type", atomType); contentElement.setAttribute(typeAttribute); } String href = content.getSrc(); if (href != null) { Attribute srcAttribute = new Attribute("src", href); contentElement.setAttribute(srcAttribute); } if (content.getValue() != null) { if (atomType != null && (atomType.equals(Content.XHTML) || (atomType.indexOf("/xml")) != -1 || (atomType.indexOf("+xml")) != -1)) { 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); } else { // must be type html, text or some other non-XML format // JDOM will escape property for XML contentElement.addContent(content.getValue()); } } }
From source file:com.sun.syndication.io.impl.Atom10Generator.java
License:Open Source License
protected Element generateGeneratorElement(Generator generator) { Element generatorElement = new Element("generator", getFeedNamespace()); if (generator.getUrl() != null) { Attribute urlAttribute = new Attribute("uri", generator.getUrl()); generatorElement.setAttribute(urlAttribute); }/* w ww .j a v a2s .co 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; }
From source file:com.sun.syndication.io.impl.DCModuleGenerator.java
License:Open Source License
/** * Populate an element tree with elements for a module. * <p>// w ww. j a v a 2s. c o m * @param module the module to populate from. * @param element the root element to attach child elements to. */ public final void generate(Module module, Element element) { DCModule dcModule = (DCModule) module; if (dcModule.getTitle() != null) { element.addContent(generateSimpleElementList("title", dcModule.getTitles())); } if (dcModule.getCreator() != null) { element.addContent(generateSimpleElementList("creator", dcModule.getCreators())); } List subjects = dcModule.getSubjects(); for (int i = 0; i < subjects.size(); i++) { element.addContent(generateSubjectElement((DCSubject) subjects.get(i))); } if (dcModule.getDescription() != null) { element.addContent(generateSimpleElementList("description", dcModule.getDescriptions())); } if (dcModule.getPublisher() != null) { element.addContent(generateSimpleElementList("publisher", dcModule.getPublishers())); } if (dcModule.getContributors() != null) { element.addContent(generateSimpleElementList("contributor", dcModule.getContributors())); } if (dcModule.getDate() != null) { for (Iterator i = dcModule.getDates().iterator(); i.hasNext();) { element.addContent(generateSimpleElement("date", DateParser.formatW3CDateTime((Date) i.next()))); } } if (dcModule.getType() != null) { element.addContent(generateSimpleElementList("type", dcModule.getTypes())); } if (dcModule.getFormat() != null) { element.addContent(generateSimpleElementList("format", dcModule.getFormats())); } if (dcModule.getIdentifier() != null) { element.addContent(generateSimpleElementList("identifier", dcModule.getIdentifiers())); } if (dcModule.getSource() != null) { element.addContent(generateSimpleElementList("source", dcModule.getSources())); } if (dcModule.getLanguage() != null) { element.addContent(generateSimpleElementList("language", dcModule.getLanguages())); } if (dcModule.getRelation() != null) { element.addContent(generateSimpleElementList("relation", dcModule.getRelations())); } if (dcModule.getCoverage() != null) { element.addContent(generateSimpleElementList("coverage", dcModule.getCoverages())); } if (dcModule.getRights() != null) { element.addContent(generateSimpleElementList("rights", dcModule.getRightsList())); } }
From source file:com.sun.syndication.io.impl.DCModuleGenerator.java
License:Open Source License
/** * Utility method to generate an element for a subject. * <p>//from w w w. j a v a 2 s .co m * @param subject the subject to generate an element for. * @return the element for the subject. */ protected final Element generateSubjectElement(DCSubject subject) { Element subjectElement = new Element("subject", getDCNamespace()); if (subject.getTaxonomyUri() != null) { Element descriptionElement = new Element("Description", getRDFNamespace()); Element topicElement = new Element("topic", getTaxonomyNamespace()); Attribute resourceAttribute = new Attribute("resource", subject.getTaxonomyUri(), getRDFNamespace()); topicElement.setAttribute(resourceAttribute); descriptionElement.addContent(topicElement); if (subject.getValue() != null) { Element valueElement = new Element("value", getRDFNamespace()); valueElement.addContent(subject.getValue()); descriptionElement.addContent(valueElement); } subjectElement.addContent(descriptionElement); } else { subjectElement.addContent(subject.getValue()); } return subjectElement; }