Example usage for org.jdom2 Element getChildren

List of usage examples for org.jdom2 Element getChildren

Introduction

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

Prototype

public List<Element> getChildren(final String cname, final Namespace ns) 

Source Link

Document

This returns a List of all the child elements nested directly (one level deep) within this element with the given local name and belonging to the given Namespace, returned as Element objects.

Usage

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

License:Apache License

/** Deserialize a Atom workspace XML element into an object */
protected void parseWorkspaceElement(final Element element) throws ProponoException {
    final Element titleElem = element.getChild("title", AtomService.ATOM_FORMAT);
    setTitle(titleElem.getText());//ww w .  j  ava  2  s.c om
    if (titleElem.getAttribute("type", AtomService.ATOM_FORMAT) != null) {
        setTitleType(titleElem.getAttribute("type", AtomService.ATOM_FORMAT).getValue());
    }
    final List<Element> collections = element.getChildren("collection", AtomService.ATOM_PROTOCOL);
    for (final Element e : collections) {
        addCollection(new Collection(e));
    }
}

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

License:Open Source License

protected WireFeed parseFeed(final Element eFeed, final Locale locale) {

    final String type = getType();
    final Document document = eFeed.getDocument();
    final String styleSheet = getStyleSheet(document);

    final Feed feed = new Feed(type);
    feed.setStyleSheet(styleSheet);//from www  .  j a  v  a2  s  . c om

    final Element title = eFeed.getChild("title", getAtomNamespace());
    if (title != null) {
        feed.setTitleEx(parseContent(title));
    }

    final List<Element> links = eFeed.getChildren("link", getAtomNamespace());
    feed.setAlternateLinks(parseAlternateLinks(links));
    feed.setOtherLinks(parseOtherLinks(links));

    final Element author = eFeed.getChild("author", getAtomNamespace());
    if (author != null) {
        final List<SyndPerson> authors = new ArrayList<SyndPerson>();
        authors.add(parsePerson(author));
        feed.setAuthors(authors);
    }

    final List<Element> contributors = eFeed.getChildren("contributor", getAtomNamespace());
    if (!contributors.isEmpty()) {
        feed.setContributors(parsePersons(contributors));
    }

    final Element tagline = eFeed.getChild("tagline", getAtomNamespace());
    if (tagline != null) {
        feed.setTagline(parseContent(tagline));
    }

    final Element id = eFeed.getChild("id", getAtomNamespace());
    if (id != null) {
        feed.setId(id.getText());
    }

    final Element generator = eFeed.getChild("generator", getAtomNamespace());
    if (generator != null) {
        final Generator gen = new Generator();
        gen.setValue(generator.getText());
        String att = getAttributeValue(generator, "url");
        if (att != null) {
            gen.setUrl(att);
        }
        att = getAttributeValue(generator, "version");
        if (att != null) {
            gen.setVersion(att);
        }
        feed.setGenerator(gen);
    }

    final Element copyright = eFeed.getChild("copyright", getAtomNamespace());
    if (copyright != null) {
        feed.setCopyright(copyright.getText());
    }

    final Element info = eFeed.getChild("info", getAtomNamespace());
    if (info != null) {
        feed.setInfo(parseContent(info));
    }

    final Element modified = eFeed.getChild("modified", getAtomNamespace());
    if (modified != null) {
        feed.setModified(DateParser.parseDate(modified.getText(), locale));
    }

    feed.setModules(parseFeedModules(eFeed, locale));

    final List<Element> entries = eFeed.getChildren("entry", getAtomNamespace());
    if (!entries.isEmpty()) {
        feed.setEntries(parseEntries(entries, locale));
    }

    final List<Element> foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace());
    if (!foreignMarkup.isEmpty()) {
        feed.setForeignMarkup(foreignMarkup);
    }

    return feed;

}

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

License:Open Source License

private Entry parseEntry(final Element eEntry, final Locale locale) {

    final Entry entry = new Entry();

    final Element title = eEntry.getChild("title", getAtomNamespace());
    if (title != null) {
        entry.setTitleEx(parseContent(title));
    }//from   w  w  w  . j a  va 2  s .co m

    final List<Element> links = eEntry.getChildren("link", getAtomNamespace());
    entry.setAlternateLinks(parseAlternateLinks(links));
    entry.setOtherLinks(parseOtherLinks(links));

    final Element author = eEntry.getChild("author", getAtomNamespace());
    if (author != null) {
        final List<SyndPerson> authors = new ArrayList<SyndPerson>();
        authors.add(parsePerson(author));
        entry.setAuthors(authors);
    }

    final List<Element> contributors = eEntry.getChildren("contributor", getAtomNamespace());
    if (!contributors.isEmpty()) {
        entry.setContributors(parsePersons(contributors));
    }

    final Element id = eEntry.getChild("id", getAtomNamespace());
    if (id != null) {
        entry.setId(id.getText());
    }

    final Element modified = eEntry.getChild("modified", getAtomNamespace());
    if (modified != null) {
        entry.setModified(DateParser.parseDate(modified.getText(), locale));
    }

    final Element issued = eEntry.getChild("issued", getAtomNamespace());
    if (issued != null) {
        entry.setIssued(DateParser.parseDate(issued.getText(), locale));
    }

    final Element created = eEntry.getChild("created", getAtomNamespace());
    if (created != null) {
        entry.setCreated(DateParser.parseDate(created.getText(), locale));
    }

    final Element summary = eEntry.getChild("summary", getAtomNamespace());
    if (summary != null) {
        entry.setSummary(parseContent(summary));
    }

    final List<Element> contents = eEntry.getChildren("content", getAtomNamespace());
    if (!contents.isEmpty()) {
        final List<Content> content = new ArrayList<Content>();
        for (final Element eContent : contents) {
            content.add(parseContent(eContent));
        }
        entry.setContents(content);
    }

    entry.setModules(parseItemModules(eEntry, locale));

    final List<Element> foreignMarkup = extractForeignMarkup(eEntry, entry, getAtomNamespace());
    if (!foreignMarkup.isEmpty()) {
        entry.setForeignMarkup(foreignMarkup);
    }

    return entry;

}

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

License:Open Source License

protected WireFeed parseFeed(final Element eFeed, final Locale locale) throws FeedException {

    String baseURI = null;/*from www.  j  a  va2  s  . com*/
    try {
        baseURI = findBaseURI(eFeed);
    } catch (final Exception e) {
        throw new FeedException("ERROR while finding base URI of feed", e);
    }

    final Feed feed = parseFeedMetadata(baseURI, eFeed, locale);
    feed.setStyleSheet(getStyleSheet(eFeed.getDocument()));

    final String xmlBase = eFeed.getAttributeValue("base", Namespace.XML_NAMESPACE);
    if (xmlBase != null) {
        feed.setXmlBase(xmlBase);
    }

    feed.setModules(parseFeedModules(eFeed, locale));

    final List<Element> eList = eFeed.getChildren("entry", getAtomNamespace());
    if (!eList.isEmpty()) {
        feed.setEntries(parseEntries(feed, baseURI, eList, locale));
    }

    final List<Element> foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace());
    if (!foreignMarkup.isEmpty()) {
        feed.setForeignMarkup(foreignMarkup);
    }
    return feed;
}

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

License:Open Source License

private Feed parseFeedMetadata(final String baseURI, final Element eFeed, final Locale locale) {

    final com.rometools.rome.feed.atom.Feed feed = new com.rometools.rome.feed.atom.Feed(getType());

    final Element title = eFeed.getChild("title", getAtomNamespace());
    if (title != null) {
        final Content c = new Content();
        c.setValue(parseTextConstructToString(title));
        c.setType(getAttributeValue(title, "type"));
        feed.setTitleEx(c);//from  w ww  .j av  a 2 s .c o  m
    }

    final List<Element> links = eFeed.getChildren("link", getAtomNamespace());
    feed.setAlternateLinks(parseAlternateLinks(feed, null, baseURI, links));
    feed.setOtherLinks(parseOtherLinks(feed, null, baseURI, links));

    final List<Element> categories = eFeed.getChildren("category", getAtomNamespace());
    feed.setCategories(parseCategories(baseURI, categories));

    final List<Element> authors = eFeed.getChildren("author", getAtomNamespace());
    if (!authors.isEmpty()) {
        feed.setAuthors(parsePersons(baseURI, authors, locale));
    }

    final List<Element> contributors = eFeed.getChildren("contributor", getAtomNamespace());
    if (!contributors.isEmpty()) {
        feed.setContributors(parsePersons(baseURI, contributors, locale));
    }

    final Element subtitle = eFeed.getChild("subtitle", getAtomNamespace());
    if (subtitle != null) {
        final Content content = new Content();
        content.setValue(parseTextConstructToString(subtitle));
        content.setType(getAttributeValue(subtitle, "type"));
        feed.setSubtitle(content);
    }

    final Element id = eFeed.getChild("id", getAtomNamespace());
    if (id != null) {
        feed.setId(id.getText());
    }

    final Element generator = eFeed.getChild("generator", getAtomNamespace());
    if (generator != null) {

        final Generator gen = new Generator();
        gen.setValue(generator.getText());

        final String uri = getAttributeValue(generator, "uri");
        if (uri != null) {
            gen.setUrl(uri);
        }

        final String version = getAttributeValue(generator, "version");
        if (version != null) {
            gen.setVersion(version);
        }

        feed.setGenerator(gen);

    }

    final Element rights = eFeed.getChild("rights", getAtomNamespace());
    if (rights != null) {
        feed.setRights(parseTextConstructToString(rights));
    }

    final Element icon = eFeed.getChild("icon", getAtomNamespace());
    if (icon != null) {
        feed.setIcon(icon.getText());
    }

    final Element logo = eFeed.getChild("logo", getAtomNamespace());
    if (logo != null) {
        feed.setLogo(logo.getText());
    }

    final Element updated = eFeed.getChild("updated", getAtomNamespace());
    if (updated != null) {
        feed.setUpdated(DateParser.parseDate(updated.getText(), locale));
    }

    return feed;

}

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

License:Open Source License

protected Entry parseEntry(final Feed feed, final Element eEntry, final String baseURI, final Locale locale) {

    final Entry entry = new Entry();

    final String xmlBase = eEntry.getAttributeValue("base", Namespace.XML_NAMESPACE);
    if (xmlBase != null) {
        entry.setXmlBase(xmlBase);//from ww w. java2 s .  c o m
    }

    final Element title = eEntry.getChild("title", getAtomNamespace());
    if (title != null) {
        final Content c = new Content();
        c.setValue(parseTextConstructToString(title));
        c.setType(getAttributeValue(title, "type"));
        entry.setTitleEx(c);
    }

    final List<Element> links = eEntry.getChildren("link", getAtomNamespace());
    entry.setAlternateLinks(parseAlternateLinks(feed, entry, baseURI, links));
    entry.setOtherLinks(parseOtherLinks(feed, entry, baseURI, links));

    final List<Element> authors = eEntry.getChildren("author", getAtomNamespace());
    if (!authors.isEmpty()) {
        entry.setAuthors(parsePersons(baseURI, authors, locale));
    }

    final List<Element> contributors = eEntry.getChildren("contributor", getAtomNamespace());
    if (!contributors.isEmpty()) {
        entry.setContributors(parsePersons(baseURI, contributors, locale));
    }

    final Element id = eEntry.getChild("id", getAtomNamespace());
    if (id != null) {
        entry.setId(id.getText());
    }

    final Element updated = eEntry.getChild("updated", getAtomNamespace());
    if (updated != null) {
        entry.setUpdated(DateParser.parseDate(updated.getText(), locale));
    }

    final Element published = eEntry.getChild("published", getAtomNamespace());
    if (published != null) {
        entry.setPublished(DateParser.parseDate(published.getText(), locale));
    }

    final Element summary = eEntry.getChild("summary", getAtomNamespace());
    if (summary != null) {
        entry.setSummary(parseContent(summary));
    }

    final Element content = eEntry.getChild("content", getAtomNamespace());
    if (content != null) {
        final List<Content> contents = new ArrayList<Content>();
        contents.add(parseContent(content));
        entry.setContents(contents);
    }

    final Element rights = eEntry.getChild("rights", getAtomNamespace());
    if (rights != null) {
        entry.setRights(rights.getText());
    }

    final List<Element> categories = eEntry.getChildren("category", getAtomNamespace());
    entry.setCategories(parseCategories(baseURI, categories));

    // TODO: SHOULD handle Atom entry source element
    final Element source = eEntry.getChild("source", getAtomNamespace());
    if (source != null) {
        entry.setSource(parseFeedMetadata(baseURI, source, locale));
    }

    entry.setModules(parseItemModules(eEntry, locale));

    final List<Element> foreignMarkup = extractForeignMarkup(eEntry, entry, getAtomNamespace());
    if (!foreignMarkup.isEmpty()) {
        entry.setForeignMarkup(foreignMarkup);
    }

    return entry;
}

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

License:Open Source License

/**
 * Return URL string of Atom link element under parent element. Link with no rel attribute is
 * considered to be rel="alternate"//from  ww w . j a  va2 s .  c om
 *
 * @param parent Consider only children of this parent element
 * @param rel Consider only links with this relationship
 */
private String findAtomLink(final Element parent, final String rel) {
    String ret = null;
    final List<Element> linksList = parent.getChildren("link", ATOM_10_NS);
    if (linksList != null) {
        for (final Element element : linksList) {
            final Element link = element;
            final Attribute relAtt = getAttribute(link, "rel");
            final Attribute hrefAtt = getAttribute(link, "href");
            if (relAtt == null && "alternate".equals(rel) || relAtt != null && relAtt.getValue().equals(rel)) {
                ret = hrefAtt.getValue();
                break;
            }
        }
    }
    return ret;
}

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

License:Apache License

/**
 * Utility method to parse a speech./*from  ww  w.j a  va2s. c om*/
 * <p>
 *
 * @param the element to parse.
 * @return speech parsed from the element.
 */
protected final CBSpeech parseSpeech(final Element element) {
    final CBSpeech speech = new CBSpeechImpl();

    final Element simpleTitle = element.getChild("simpleTitle", getCBNamespace());
    if (simpleTitle != null) {
        speech.setSimpleTitle(simpleTitle.getText());
    }

    final Element occurrenceDate = element.getChild("occurrenceDate", getCBNamespace());
    if (occurrenceDate != null) {
        speech.setOccurrenceDate(occurrenceDate.getText());
    }

    final Element institutionAbbrev = element.getChild("institutionAbbrev", getCBNamespace());
    if (institutionAbbrev != null) {
        speech.setInstitutionAbbrev(institutionAbbrev.getText());
    }

    final Element audience = element.getChild("audience", getCBNamespace());
    if (audience != null) {
        speech.setAudience(audience.getText());
    }

    final List<Element> keyList = element.getChildren("keyword", getCBNamespace());
    for (Element keyword : keyList) {
        speech.getKeywords().add(keyword.getText());
    }

    final Element resource = element.getChild("resource", getCBNamespace());
    if (resource != null) {
        speech.setResource(parseResource(resource));
    }

    final Element person = element.getChild("person", getCBNamespace());
    if (person != null) {
        speech.setPerson(parsePerson(person));
    }

    final Element venue = element.getChild("venue", getCBNamespace());
    if (venue != null) {
        speech.setVenue(venue.getText());
    }

    final Element locationAsWritten = element.getChild("locationAsWritten", getCBNamespace());
    if (locationAsWritten != null) {
        speech.setLocationAsWritten(locationAsWritten.getText());
    }

    final Element locationCountry = element.getChild("locationCountry", getCBNamespace());
    if (locationCountry != null) {
        speech.setLocationCountry(ISO3166CountyCode.fromValue(locationCountry.getText()));
    }

    final Element locationState = element.getChild("locationState", getCBNamespace());
    if (locationState != null) {
        speech.setLocationState(locationState.getText());
    }

    final Element locationCity = element.getChild("locationCity", getCBNamespace());
    if (locationCity != null) {
        speech.setLocationCity(locationCity.getText());
    }

    return speech;
}

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

License:Apache License

/**
 * Utility method to parse an event./*from w  ww  .  ja va  2s.  c om*/
 * <p>
 *
 * @param the element to parse.
 * @return event parsed from the element.
 */
protected final CBEvent parseEvent(final Element element) {

    final CBEvent event = new CBEventImpl();

    final Element simpleTitle = element.getChild("simpleTitle", getCBNamespace());
    if (simpleTitle != null) {
        event.setSimpleTitle(simpleTitle.getText());
    }

    final Element occurenceDate = element.getChild("occurenceDate", getCBNamespace());
    if (occurenceDate != null) {
        event.setOccurenceDate(occurenceDate.getText());
    }

    final Element institutionAbbrev = element.getChild("institutionAbbrev", getCBNamespace());
    if (institutionAbbrev != null) {
        event.setInstitutionAbbrev(institutionAbbrev.getText());
    }

    final Element audience = element.getChild("audience", getCBNamespace());
    if (audience != null) {
        event.setAudience(audience.getText());
    }

    final List<Element> keyList = element.getChildren("keyword", getCBNamespace());
    for (Element keyword : keyList) {
        event.getKeywords().add(keyword.getText());
    }

    final Element resource = element.getChild("resource", getCBNamespace());
    if (resource != null) {
        event.setResource(parseResource(resource));
    }

    final Element person = element.getChild("person", getCBNamespace());
    if (person != null) {
        event.setPerson(parsePerson(person));
    }

    final Element venue = element.getChild("venue", getCBNamespace());
    if (venue != null) {
        event.setVenue(venue.getText());
    }

    final Element locationAsWritten = element.getChild("locationAsWritten", getCBNamespace());
    if (locationAsWritten != null) {
        event.setLocationAsWritten(locationAsWritten.getText());
    }

    final Element locationCountry = element.getChild("locationCountry", getCBNamespace());
    if (locationCountry != null) {
        event.setLocationCountry(locationCountry.getText());
    }

    final Element locationState = element.getChild("locationState", getCBNamespace());
    if (locationState != null) {
        event.setLocationState(locationState.getText());
    }

    final Element locationCity = element.getChild("locationCity", getCBNamespace());
    if (locationCity != null) {
        event.setLocationCity(locationCity.getText());
    }

    final Element eventDateEnd = element.getChild("eventDateEnd", getCBNamespace());
    if (eventDateEnd != null) {
        event.setEventDateEnd(eventDateEnd.getText());
    }

    return event;
}

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

License:Apache License

/**
 * Utility method to parse a paper.//from   w  ww  .j a  va  2 s .  co m
 * <p>
 *
 * @param the element to parse.
 * @return paper parsed from the element.
 */
protected final CBPaper parsePaper(final Element element) {
    final CBPaper paperObj = new CBPaperImpl();

    final Element simpleTitle = element.getChild("simpleTitle", getCBNamespace());
    if (simpleTitle != null) {
        paperObj.setSimpleTitle(simpleTitle.getText());
    }

    final Element occurrenceDate = element.getChild("occurrenceDate", getCBNamespace());
    if (occurrenceDate != null) {
        paperObj.setOccurrenceDate(occurrenceDate.getText());
    }

    final Element institutionAbbrev = element.getChild("institutionAbbrev", getCBNamespace());
    if (institutionAbbrev != null) {
        paperObj.setInstitutionAbbrev(institutionAbbrev.getText());
    }

    final List<Element> keyList = element.getChildren("keyword", getCBNamespace());
    List<String> kList = new ArrayList<String>();
    for (Element keyword : keyList) {
        kList.add(keyword.getText());
    }
    paperObj.setKeywords(kList);

    final Element resource = element.getChild("resource", getCBNamespace());
    if (resource != null) {
        paperObj.setResource(parseResource(resource));
    }

    final Element person = element.getChild("person", getCBNamespace());
    if (person != null) {
        paperObj.setPerson(parsePerson(person));
    }

    final Element byline = element.getChild("byline", getCBNamespace());
    if (byline != null) {
        paperObj.setByline(byline.getText());
    }

    final Element publicationDate = element.getChild("publicationDate", getCBNamespace());
    if (publicationDate != null) {
        paperObj.setPublicationDate(publicationDate.getText());
    }

    final Element publication = element.getChild("publication", getCBNamespace());
    if (publication != null) {
        paperObj.setPublication(publication.getText());
    }

    final Element issue = element.getChild("issue", getCBNamespace());
    if (issue != null) {
        paperObj.setIssue(issue.getText());
    }

    final Element JELCode = element.getChild("JELCode", getCBNamespace());
    if (JELCode != null) {
        paperObj.setJELCode(JELCode.getText());
    }

    return paperObj;
}