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.Atom10Generator.java
License:Open Source License
protected void fillContentElement(final Element contentElement, final Content content) throws FeedException { final String type = content.getType(); String atomType = type;//from w ww .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; } final Attribute typeAttribute = new Attribute("type", atomType); contentElement.setAttribute(typeAttribute); } final String href = content.getSrc(); if (href != null) { final Attribute srcAttribute = new Attribute("src", href); contentElement.setAttribute(srcAttribute); } final String value = content.getValue(); if (value != null) { if (atomType != null && (atomType.equals(Content.XHTML) || atomType.indexOf("/xml") != -1 || atomType.indexOf("+xml") != -1)) { final StringBuffer tmpDocString = new StringBuffer("<tmpdoc>"); tmpDocString.append(value); tmpDocString.append("</tmpdoc>"); final StringReader tmpDocReader = new StringReader(tmpDocString.toString()); Document tmpDoc; try { final SAXBuilder saxBuilder = new SAXBuilder(); tmpDoc = saxBuilder.build(tmpDocReader); } catch (final Exception ex) { throw new FeedException("Invalid XML", ex); } final List<org.jdom2.Content> 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(value); } } }
From source file:com.rometools.rome.io.impl.Atom10Generator.java
License:Open Source License
protected Element generateGeneratorElement(final Generator generator) { final Element generatorElement = new Element("generator", getFeedNamespace()); final String url = generator.getUrl(); if (url != null) { final Attribute urlAttribute = new Attribute("uri", url); generatorElement.setAttribute(urlAttribute); }/*from w w w.j a va 2 s .co m*/ final String version2 = generator.getVersion(); if (version2 != null) { final Attribute versionAttribute = new Attribute("version", version2); generatorElement.setAttribute(versionAttribute); } final String value = generator.getValue(); if (value != null) { generatorElement.addContent(value); } return generatorElement; }
From source file:com.rometools.rome.io.impl.CBModuleGenerator.java
License:Apache License
/** * Populate an element tree with elements for a module. * <p>//from ww w.j a va2 s . co m * * @param module the module to populate from. * @param element the root element to attach child elements to. */ @Override public final void generate(final Module module, final Element element) { final CBModule cbModule = (CBModule) module; final CBSpeech speech = cbModule.getSpeech(); element.addContent(generateSpeechElement(speech)); }
From source file:com.rometools.rome.io.impl.CBModuleGenerator.java
License:Apache License
/** * Utility method to generate an element for a speech. * <p>/*from w w w .j a v a2 s .com*/ * * @param speech the speech to generate an element for. * @return the element for the speech. */ protected final Element generateSpeechElement(final CBSpeech speech) { final Element speechElement = new Element("speech", getCBNamespace()); final String simpleTitle = speech.getSimpleTitle(); if (simpleTitle != null) { final Element simpleTitleElement = new Element("simpleTitle", getCBNamespace()); simpleTitleElement.addContent(simpleTitle); speechElement.addContent(simpleTitleElement); } return speechElement; }
From source file:com.rometools.rome.io.impl.CBModuleGenerator.java
License:Apache License
/** * Utility method to generate a single element containing a string. * <p>//from w w w. j a va2 s . c om * * @param name the name of the elment to generate. * @param value the value of the text in the element. * @return the element generated. */ protected final Element generateSimpleElement(final String name, final String value) { final Element element = new Element(name, getCBNamespace()); element.addContent(value); return element; }
From source file:com.rometools.rome.io.impl.DCModuleGenerator.java
License:Open Source License
/** * Populate an element tree with elements for a module. * <p>/* ww w .ja v a2 s . c o m*/ * * @param module the module to populate from. * @param element the root element to attach child elements to. */ @Override public final void generate(final Module module, final Element element) { final DCModule dcModule = (DCModule) module; final String title = dcModule.getTitle(); if (title != null) { element.addContent(generateSimpleElementList("title", dcModule.getTitles())); } final String creator = dcModule.getCreator(); if (creator != null) { element.addContent(generateSimpleElementList("creator", dcModule.getCreators())); } final List<DCSubject> subjects = dcModule.getSubjects(); for (final DCSubject dcSubject : subjects) { element.addContent(generateSubjectElement(dcSubject)); } final String description = dcModule.getDescription(); if (description != null) { element.addContent(generateSimpleElementList("description", dcModule.getDescriptions())); } final String publisher = dcModule.getPublisher(); if (publisher != null) { element.addContent(generateSimpleElementList("publisher", dcModule.getPublishers())); } final List<String> contributors = dcModule.getContributors(); if (contributors != null) { element.addContent(generateSimpleElementList("contributor", contributors)); } final Date dcDate = dcModule.getDate(); if (dcDate != null) { for (final Date date : dcModule.getDates()) { element.addContent(generateSimpleElement("date", DateParser.formatW3CDateTime(date, Locale.US))); } } final String type = dcModule.getType(); if (type != null) { element.addContent(generateSimpleElementList("type", dcModule.getTypes())); } final String format = dcModule.getFormat(); if (format != null) { element.addContent(generateSimpleElementList("format", dcModule.getFormats())); } final String identifier = dcModule.getIdentifier(); if (identifier != null) { element.addContent(generateSimpleElementList("identifier", dcModule.getIdentifiers())); } final String source = dcModule.getSource(); if (source != null) { element.addContent(generateSimpleElementList("source", dcModule.getSources())); } final String language = dcModule.getLanguage(); if (language != null) { element.addContent(generateSimpleElementList("language", dcModule.getLanguages())); } final String relation = dcModule.getRelation(); if (relation != null) { element.addContent(generateSimpleElementList("relation", dcModule.getRelations())); } final String coverage = dcModule.getCoverage(); if (coverage != null) { element.addContent(generateSimpleElementList("coverage", dcModule.getCoverages())); } final String rights = dcModule.getRights(); if (rights != null) { element.addContent(generateSimpleElementList("rights", dcModule.getRightsList())); } }
From source file:com.rometools.rome.io.impl.DCModuleGenerator.java
License:Open Source License
/** * Utility method to generate an element for a subject. * <p>/*ww w. j ava 2 s. com*/ * * @param subject the subject to generate an element for. * @return the element for the subject. */ protected final Element generateSubjectElement(final DCSubject subject) { final Element subjectElement = new Element("subject", getDCNamespace()); final String taxonomyUri = subject.getTaxonomyUri(); final String value = subject.getValue(); if (taxonomyUri != null) { final Attribute resourceAttribute = new Attribute("resource", taxonomyUri, getRDFNamespace()); final Element topicElement = new Element("topic", getTaxonomyNamespace()); topicElement.setAttribute(resourceAttribute); final Element descriptionElement = new Element("Description", getRDFNamespace()); descriptionElement.addContent(topicElement); if (value != null) { final Element valueElement = new Element("value", getRDFNamespace()); valueElement.addContent(value); descriptionElement.addContent(valueElement); } subjectElement.addContent(descriptionElement); } else { subjectElement.addContent(value); } return subjectElement; }
From source file:com.rometools.rome.io.impl.DCModuleGenerator.java
License:Open Source License
/** * Utility method to generate a single element containing a string. * <p>/*from w w w. ja v a 2s. c o m*/ * * @param name the name of the elment to generate. * @param value the value of the text in the element. * @return the element generated. */ protected final Element generateSimpleElement(final String name, final String value) { final Element element = new Element(name, getDCNamespace()); element.addContent(value); return element; }
From source file:com.rometools.rome.io.impl.OPML10Generator.java
License:Apache License
/** * Creates an XML document (JDOM) for the given feed bean. * <p>// w w w.j a v a 2 s . co 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.RSS090Generator.java
License:Open Source License
protected void addChannel(final Channel channel, final Element parent) throws FeedException { final Element eChannel = new Element("channel", getFeedNamespace()); populateChannel(channel, eChannel);//from w w w . j a va 2s . com checkChannelConstraints(eChannel); parent.addContent(eChannel); generateFeedModules(channel.getModules(), eChannel); }