Example usage for org.jdom2 Element Element

List of usage examples for org.jdom2 Element Element

Introduction

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

Prototype

public Element(final String name, final String uri) 

Source Link

Document

Creates a new element with the supplied (local) name and a namespace given by a URI.

Usage

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 w  w . jav  a  2  s  .  c  o  m
    }

    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  w  ww . j a  va  2s . co  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 Element generateCategoryElement(Category cat) {
    Element catElement = new Element("category", getFeedNamespace());

    if (cat.getTerm() != null) {
        Attribute termAttribute = new Attribute("term", cat.getTerm());
        catElement.setAttribute(termAttribute);
    }/*  ww  w .j a v a 2s.  c o  m*/

    if (cat.getLabel() != null) {
        Attribute labelAttribute = new Attribute("label", cat.getLabel());
        catElement.setAttribute(labelAttribute);
    }

    if (cat.getScheme() != null) {
        Attribute schemeAttribute = new Attribute("scheme", cat.getScheme());
        catElement.setAttribute(schemeAttribute);
    }
    return catElement;
}

From source file:com.sun.syndication.io.impl.Atom10Generator.java

License:Open Source License

protected Element generateLinkElement(Link link) {
    Element linkElement = new Element("link", getFeedNamespace());

    if (link.getRel() != null) {
        Attribute relAttribute = new Attribute("rel", link.getRel());
        linkElement.setAttribute(relAttribute);
    }//from  w  w  w  . j  a va2s . c o  m

    if (link.getType() != null) {
        Attribute typeAttribute = new Attribute("type", link.getType());
        linkElement.setAttribute(typeAttribute);
    }

    if (link.getHref() != null) {
        Attribute hrefAttribute = new Attribute("href", link.getHref());
        linkElement.setAttribute(hrefAttribute);
    }

    if (link.getHreflang() != null) {
        Attribute hreflangAttribute = new Attribute("hreflang", link.getHreflang());
        linkElement.setAttribute(hreflangAttribute);
    }
    if (link.getTitle() != null) {
        Attribute title = new Attribute("title", link.getTitle());
        linkElement.setAttribute(title);
    }
    if (link.getLength() != 0) {
        Attribute lenght = new Attribute("length", Long.toString(link.getLength()));
        linkElement.setAttribute(lenght);
    }
    return linkElement;
}

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);
    }/*from ww w.  j  a va  2  s  .  co m*/

    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 Element generateGeneratorElement(Generator generator) {
    Element generatorElement = new Element("generator", getFeedNamespace());

    if (generator.getUrl() != null) {
        Attribute urlAttribute = new Attribute("uri", generator.getUrl());
        generatorElement.setAttribute(urlAttribute);
    }//from w ww  .ja va  2s . 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

/**
 * Utility method to generate an element for a subject.
 * <p>/* w  w  w  . j ava2  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;
}

From source file:com.sun.syndication.io.impl.DCModuleGenerator.java

License:Open Source License

/**
 * Utility method to generate a single element containing a string.
 * <p>//from w w w  . j  a v a 2 s.  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(String name, String value) {
    Element element = new Element(name, getDCNamespace());
    element.addContent(value);

    return element;
}

From source file:com.sun.syndication.io.impl.RSS090Generator.java

License:Open Source License

protected Element createRootElement(Channel channel) {
    Element root = new Element("RDF", getRDFNamespace());
    root.addNamespaceDeclaration(getFeedNamespace());
    root.addNamespaceDeclaration(getRDFNamespace());
    root.addNamespaceDeclaration(getContentNamespace());
    generateModuleNamespaceDefs(root);/*  w  w w  . j a v a 2 s  .com*/
    return root;
}

From source file:com.sun.syndication.io.impl.RSS090Generator.java

License:Open Source License

protected void addChannel(Channel channel, Element parent) throws FeedException {
    Element eChannel = new Element("channel", getFeedNamespace());
    populateChannel(channel, eChannel);/*from w ww  . ja  v a 2s .c  o  m*/
    checkChannelConstraints(eChannel);
    parent.addContent(eChannel);
    generateFeedModules(channel.getModules(), eChannel);
}