Example usage for org.jdom2 Element addContent

List of usage examples for org.jdom2 Element addContent

Introduction

In this page you can find the example usage for org.jdom2 Element addContent.

Prototype

@Override
public Element addContent(final Collection<? extends Content> newContent) 

Source Link

Document

Appends all children in the given collection to the end of the content list.

Usage

From source file:com.rometools.rome.io.impl.Atom03Generator.java

License:Open Source License

protected void fillPersonElement(final Element element, final SyndPerson person) {

    final String name = person.getName();
    if (name != null) {
        element.addContent(generateSimpleElement("name", name));
    }/*from w w w . j av a  2  s.co m*/

    final String uri = person.getUri();
    if (uri != null) {
        element.addContent(generateSimpleElement("url", uri));
    }

    final String email = person.getEmail();
    if (email != null) {
        element.addContent(generateSimpleElement("email", email));
    }

}

From source file:com.rometools.rome.io.impl.Atom03Generator.java

License:Open Source License

protected Element generateTagLineElement(final Content tagline) {

    final Element taglineElement = new Element("tagline", getFeedNamespace());

    final String type = tagline.getType();
    if (type != null) {
        final Attribute typeAttribute = new Attribute("type", type);
        taglineElement.setAttribute(typeAttribute);
    }/*from  ww  w . jav  a2 s. c o m*/

    final String value = tagline.getValue();
    if (value != null) {
        taglineElement.addContent(value);
    }

    return taglineElement;

}

From source file:com.rometools.rome.io.impl.Atom03Generator.java

License:Open Source License

protected void fillContentElement(final Element contentElement, final Content content) throws FeedException {

    final String type = content.getType();
    if (type != null) {
        final Attribute typeAttribute = new Attribute("type", type);
        contentElement.setAttribute(typeAttribute);
    }//  www.  j  a  va2 s  .  c  o  m

    final String mode = content.getMode();
    if (mode != null) {
        final Attribute modeAttribute = new Attribute("mode", mode.toString());
        contentElement.setAttribute(modeAttribute);
    }

    final String value = content.getValue();
    if (value != null) {

        if (mode == null || mode.equals(Content.ESCAPED)) {

            contentElement.addContent(value);

        } else if (mode.equals(Content.BASE64)) {

            contentElement.addContent(Base64.encode(value));

        } else if (mode.equals(Content.XML)) {

            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);
        }

    }
}

From source file:com.rometools.rome.io.impl.Atom03Generator.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("url", url);
        generatorElement.setAttribute(urlAttribute);
    }//from w ww . j  a  v  a2  s  . c o  m

    final String version = generator.getVersion();
    if (version != null) {
        final Attribute versionAttribute = new Attribute("version", version);
        generatorElement.setAttribute(versionAttribute);
    }

    final String value = generator.getValue();
    if (value != null) {
        generatorElement.addContent(value);
    }

    return generatorElement;

}

From source file:com.rometools.rome.io.impl.Atom03Generator.java

License:Open Source License

protected Element generateSimpleElement(final String name, final String value) {
    final Element element = new Element(name, getFeedNamespace());
    element.addContent(value);
    return element;
}

From source file:com.rometools.rome.io.impl.Atom10Generator.java

License:Open Source License

protected void addEntry(final Entry entry, final Element parent) throws FeedException {

    final Element eEntry = new Element("entry", getFeedNamespace());

    final String xmlBase = entry.getXmlBase();
    if (xmlBase != null) {
        eEntry.setAttribute("base", xmlBase, Namespace.XML_NAMESPACE);
    }/*  w  w  w.java 2  s.com*/

    populateEntry(entry, eEntry);
    generateForeignMarkup(eEntry, entry.getForeignMarkup());
    checkEntryConstraints(eEntry);
    generateItemModules(entry.getModules(), eEntry);
    parent.addContent(eEntry);

}

From source file:com.rometools.rome.io.impl.Atom10Generator.java

License:Open Source License

protected void populateFeedHeader(final Feed feed, final Element eFeed) throws FeedException {

    final Content titleEx = feed.getTitleEx();
    if (titleEx != null) {
        final Element titleElement = new Element("title", getFeedNamespace());
        fillContentElement(titleElement, titleEx);
        eFeed.addContent(titleElement);
    }//from ww w.j  a v a 2  s  .c  o  m

    final List<Link> alternateLinks = feed.getAlternateLinks();
    if (alternateLinks != null) {
        for (final Link link : alternateLinks) {
            eFeed.addContent(generateLinkElement(link));
        }
    }

    final List<Link> otherLinks = feed.getOtherLinks();
    if (otherLinks != null) {
        for (final Link link : otherLinks) {
            eFeed.addContent(generateLinkElement(link));
        }
    }

    final List<Category> cats = feed.getCategories();
    if (cats != null) {
        for (final Category category : cats) {
            eFeed.addContent(generateCategoryElement(category));
        }
    }

    final List<SyndPerson> authors = feed.getAuthors();
    if (Lists.isNotEmpty(authors)) {
        for (final SyndPerson author : authors) {
            final Element authorElement = new Element("author", getFeedNamespace());
            fillPersonElement(authorElement, author);
            eFeed.addContent(authorElement);
        }
    }

    final List<SyndPerson> contributors = feed.getContributors();
    if (Lists.isNotEmpty(contributors)) {
        for (final SyndPerson contributor : contributors) {
            final Element contributorElement = new Element("contributor", getFeedNamespace());
            fillPersonElement(contributorElement, contributor);
            eFeed.addContent(contributorElement);
        }
    }

    final Content subtitle = feed.getSubtitle();
    if (subtitle != null) {
        final Element subtitleElement = new Element("subtitle", getFeedNamespace());
        fillContentElement(subtitleElement, subtitle);
        eFeed.addContent(subtitleElement);
    }

    final String id = feed.getId();
    if (id != null) {
        eFeed.addContent(generateSimpleElement("id", id));
    }

    final Generator generator = feed.getGenerator();
    if (generator != null) {
        eFeed.addContent(generateGeneratorElement(generator));
    }

    final String rights = feed.getRights();
    if (rights != null) {
        eFeed.addContent(generateSimpleElement("rights", rights));
    }

    final String icon = feed.getIcon();
    if (icon != null) {
        eFeed.addContent(generateSimpleElement("icon", icon));
    }

    final String logo = feed.getLogo();
    if (logo != null) {
        eFeed.addContent(generateSimpleElement("logo", logo));
    }

    final Date updated = feed.getUpdated();
    if (updated != null) {
        final Element updatedElement = new Element("updated", getFeedNamespace());
        updatedElement.addContent(DateParser.formatW3CDateTime(updated, Locale.US));
        eFeed.addContent(updatedElement);
    }

}

From source file:com.rometools.rome.io.impl.Atom10Generator.java

License:Open Source License

protected void populateEntry(final Entry entry, final Element eEntry) throws FeedException {

    final Content titleEx = entry.getTitleEx();
    if (titleEx != null) {
        final Element titleElement = new Element("title", getFeedNamespace());
        fillContentElement(titleElement, titleEx);
        eEntry.addContent(titleElement);
    }/*  w  w w  .  ja  va 2  s.c om*/

    final List<Link> alternateLinks = entry.getAlternateLinks();
    if (alternateLinks != null) {
        for (final Link link : alternateLinks) {
            eEntry.addContent(generateLinkElement(link));
        }
    }

    final List<Link> otherLinks = entry.getOtherLinks();
    if (otherLinks != null) {
        for (final Link link : otherLinks) {
            eEntry.addContent(generateLinkElement(link));
        }
    }

    final List<Category> cats = entry.getCategories();
    if (cats != null) {
        for (final Category category : cats) {
            eEntry.addContent(generateCategoryElement(category));
        }
    }

    final List<SyndPerson> authors = entry.getAuthors();
    if (Lists.isNotEmpty(authors)) {
        for (final SyndPerson author : authors) {
            final Element authorElement = new Element("author", getFeedNamespace());
            fillPersonElement(authorElement, author);
            eEntry.addContent(authorElement);
        }
    }

    final List<SyndPerson> contributors = entry.getContributors();
    if (Lists.isNotEmpty(contributors)) {
        for (final SyndPerson contributor : contributors) {
            final Element contributorElement = new Element("contributor", getFeedNamespace());
            fillPersonElement(contributorElement, contributor);
            eEntry.addContent(contributorElement);
        }
    }

    final String id = entry.getId();
    if (id != null) {
        eEntry.addContent(generateSimpleElement("id", id));
    }

    final Date updated = entry.getUpdated();
    if (updated != null) {
        final Element updatedElement = new Element("updated", getFeedNamespace());
        updatedElement.addContent(DateParser.formatW3CDateTime(updated, Locale.US));
        eEntry.addContent(updatedElement);
    }

    final Date published = entry.getPublished();
    if (published != null) {
        final Element publishedElement = new Element("published", getFeedNamespace());
        publishedElement.addContent(DateParser.formatW3CDateTime(published, Locale.US));
        eEntry.addContent(publishedElement);
    }

    final List<Content> contents = entry.getContents();
    if (Lists.isNotEmpty(contents)) {
        final Element contentElement = new Element("content", getFeedNamespace());
        final Content content = contents.get(0);
        fillContentElement(contentElement, content);
        eEntry.addContent(contentElement);
    }

    final Content summary = entry.getSummary();
    if (summary != null) {
        final Element summaryElement = new Element("summary", getFeedNamespace());
        fillContentElement(summaryElement, summary);
        eEntry.addContent(summaryElement);
    }

    final Feed source = entry.getSource();
    if (source != null) {
        final Element sourceElement = new Element("source", getFeedNamespace());
        populateFeedHeader(source, sourceElement);
        eEntry.addContent(sourceElement);
    }

}

From source file:com.rometools.rome.io.impl.Atom10Generator.java

License:Open Source License

protected void fillPersonElement(final Element element, final SyndPerson person) {

    final String name = person.getName();
    if (name != null) {
        element.addContent(generateSimpleElement("name", name));
    }/*from w ww  . j  a  va 2s . c  o  m*/

    final String uri = person.getUri();
    if (uri != null) {
        element.addContent(generateSimpleElement("uri", uri));
    }

    final String email = person.getEmail();
    if (email != null) {
        element.addContent(generateSimpleElement("email", email));
    }

    generatePersonModules(person.getModules(), element);

}

From source file:com.rometools.rome.io.impl.Atom10Generator.java

License:Open Source License

protected Element generateTagLineElement(final Content tagline) {

    final Element taglineElement = new Element("subtitle", getFeedNamespace());

    final String type = tagline.getType();
    if (type != null) {
        final Attribute typeAttribute = new Attribute("type", type);
        taglineElement.setAttribute(typeAttribute);
    }//from w  w w  .j av a2 s  .c om

    final String value = tagline.getValue();
    if (value != null) {
        taglineElement.addContent(value);
    }

    return taglineElement;

}