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.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);
    }//from  ww  w .  j ava 2  s  . c  om
    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
 *//* w  w  w. j a va2 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  ww.ja v  a 2  s.  c  o  m*/
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);//ww  w  . jav  a2 s . c  om
    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   www .j a  va2  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 Element createRootElement(final Feed feed) {
    final Element root = new Element("feed", getFeedNamespace());
    root.addNamespaceDeclaration(getFeedNamespace());
    final Attribute version = new Attribute("version", getVersion());
    root.setAttribute(version);/* www . j  av  a 2  s . c  om*/
    generateModuleNamespaceDefs(root);
    return root;
}

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 ww.j a va2 s  . c  o  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   www.  j a va2s.  c om*/
    }

    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  w w .j  a  v a 2 s . 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());

}

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

License:Open Source License

protected Element generateLinkElement(final Link link) {

    final Element linkElement = new Element("link", getFeedNamespace());

    final String rel = link.getRel();
    if (rel != null) {
        final Attribute relAttribute = new Attribute("rel", rel.toString());
        linkElement.setAttribute(relAttribute);
    }//ww  w  . j  a v  a  2  s  .  c o  m

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

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

    return linkElement;

}