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.opml.io.impl.OPML20Generator.java

License:Apache License

@Override
protected Element generateHead(final Opml opml) {

    final Element docsElement = new Element("docs");
    docsElement.setText(opml.getDocs());

    final Element headElement = super.generateHead(opml);
    headElement.addContent(docsElement);
    return headElement;

}

From source file:com.rometools.propono.atom.common.AtomService.java

License:Apache License

/**
 * Serialize an AtomService object into an XML document
 *//*from ww  w. j  a  va  2s  .  co  m*/
public Document serviceToDocument() {
    final AtomService service = this;

    final Document doc = new Document();
    final Element root = new Element("service", ATOM_PROTOCOL);
    doc.setRootElement(root);
    final List<Workspace> spaces = service.getWorkspaces();
    for (final Workspace space : spaces) {
        root.addContent(space.workspaceToElement());
    }
    return doc;
}

From source file:com.rometools.propono.atom.common.Categories.java

License:Apache License

public Element categoriesToElement() {
    final Categories cats = this;
    final Element catsElem = new Element("categories", AtomService.ATOM_PROTOCOL);
    catsElem.setAttribute("fixed", cats.isFixed() ? "yes" : "no", AtomService.ATOM_PROTOCOL);
    if (cats.getScheme() != null) {
        catsElem.setAttribute("scheme", cats.getScheme(), AtomService.ATOM_PROTOCOL);
    }//  w ww. j  av  a 2 s . c  o m
    if (cats.getHref() != null) {
        catsElem.setAttribute("href", cats.getHref(), AtomService.ATOM_PROTOCOL);
    } else {
        // Loop to create <atom:category> elements
        for (final Object element : cats.getCategories()) {
            final Category cat = (Category) element;
            final Element catElem = new Element("category", AtomService.ATOM_FORMAT);
            catElem.setAttribute("term", cat.getTerm(), AtomService.ATOM_FORMAT);
            if (cat.getScheme() != null) { // optional
                catElem.setAttribute("scheme", cat.getScheme(), AtomService.ATOM_FORMAT);
            }
            if (cat.getLabel() != null) { // optional
                catElem.setAttribute("label", cat.getLabel(), AtomService.ATOM_FORMAT);
            }
            catsElem.addContent(catElem);
        }
    }
    return catsElem;
}

From source file:com.rometools.propono.atom.common.Collection.java

License:Apache License

/**
 * Serialize an AtomService.Collection into an XML element
 *//*from ww  w  . ja va  2 s .c  o m*/
public Element collectionToElement() {
    final Collection collection = this;
    final Element element = new Element("collection", AtomService.ATOM_PROTOCOL);
    element.setAttribute("href", collection.getHref());

    final Element titleElem = new Element("title", AtomService.ATOM_FORMAT);
    titleElem.setText(collection.getTitle());
    if (collection.getTitleType() != null && !collection.getTitleType().equals("TEXT")) {
        titleElem.setAttribute("type", collection.getTitleType(), AtomService.ATOM_FORMAT);
    }
    element.addContent(titleElem);

    // Loop to create <app:categories> elements
    for (final Object element2 : collection.getCategories()) {
        final Categories cats = (Categories) element2;
        element.addContent(cats.categoriesToElement());
    }

    for (final Object element2 : collection.getAccepts()) {
        final String range = (String) element2;
        final Element acceptElem = new Element("accept", AtomService.ATOM_PROTOCOL);
        acceptElem.setText(range);
        element.addContent(acceptElem);
    }

    return element;
}

From source file:com.rometools.propono.atom.common.rome.AppModuleGenerator.java

License:Apache License

/** Generate JDOM element for module and add it to parent element */
@Override//from  w  w w  .j a  v  a 2  s  . c om
public void generate(final Module module, final Element parent) {
    final AppModule m = (AppModule) module;

    if (m.getDraft() != null) {
        final String draft = m.getDraft().booleanValue() ? "yes" : "no";
        final Element control = new Element("control", APP_NS);
        control.addContent(generateSimpleElement("draft", draft));
        parent.addContent(control);
    }
    if (m.getEdited() != null) {
        final Element edited = new Element("edited", APP_NS);
        // Inclulde millis in date/time
        final SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
        dateFormater.setTimeZone(TimeZone.getTimeZone("GMT"));
        edited.addContent(dateFormater.format(m.getEdited()));
        parent.addContent(edited);
    }
}

From source file:com.rometools.propono.atom.common.rome.AppModuleGenerator.java

License:Apache License

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

From source file:com.rometools.propono.atom.common.Workspace.java

License:Apache License

/**
 * Serialize an AtomService.DefaultWorkspace object into an XML element
 *//*from w ww . ja  v  a  2 s  .  co m*/
public Element workspaceToElement() {
    final Workspace space = this;

    final Element element = new Element("workspace", AtomService.ATOM_PROTOCOL);

    final Element titleElem = new Element("title", AtomService.ATOM_FORMAT);
    titleElem.setText(space.getTitle());
    if (space.getTitleType() != null && !space.getTitleType().equals("TEXT")) {
        titleElem.setAttribute("type", space.getTitleType(), AtomService.ATOM_FORMAT);
    }
    element.addContent(titleElem);

    for (final Collection col : space.getCollections()) {
        element.addContent(col.collectionToElement());
    }

    return element;
}

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

License:Open Source License

protected void addEntry(final Entry entry, final Element parent) throws FeedException {
    final Element eEntry = new Element("entry", getFeedNamespace());
    populateEntry(entry, eEntry);/*  w  w  w . ja  va2s .  co  m*/
    checkEntryConstraints(eEntry);
    generateItemModules(entry.getModules(), eEntry);
    parent.addContent(eEntry);
}

From source file:com.rometools.rome.io.impl.Atom03Generator.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  w  w  w .jav a2 s. co m

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

    links = feed.getOtherLinks();
    for (final Link link : links) {
        eFeed.addContent(generateLinkElement(link));
    }

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

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

    final Content tagline = feed.getTagline();
    if (tagline != null) {
        final Element taglineElement = new Element("tagline", getFeedNamespace());
        fillContentElement(taglineElement, tagline);
        eFeed.addContent(taglineElement);
    }

    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 copyright = feed.getCopyright();
    if (copyright != null) {
        eFeed.addContent(generateSimpleElement("copyright", copyright));
    }

    final Content info = feed.getInfo();
    if (info != null) {
        final Element infoElement = new Element("info", getFeedNamespace());
        fillContentElement(infoElement, info);
        eFeed.addContent(infoElement);
    }

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

}

From source file:com.rometools.rome.io.impl.Atom03Generator.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);
    }/*from   w  ww .  ja  va 2s .c o  m*/

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

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

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

    final List<SyndPerson> contributors = entry.getContributors();
    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 modified = entry.getModified();
    if (modified != null) {
        final Element modifiedElement = new Element("modified", getFeedNamespace());
        modifiedElement.addContent(DateParser.formatW3CDateTime(modified, Locale.US));
        eEntry.addContent(modifiedElement);
    }

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

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

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

    final List<Content> contents = entry.getContents();
    for (final Content content : contents) {
        final Element contentElement = new Element("content", getFeedNamespace());
        fillContentElement(contentElement, content);
        eEntry.addContent(contentElement);
    }

    generateForeignMarkup(eEntry, entry.getForeignMarkup());

}