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.rome.io.impl.CBModuleParser.java

License:Apache License

/**
 * Utility method to parse an news.//from   w  w  w . ja v a2 s . co m
 * <p>
 *
 * @param the element to parse.
 * @return news parsed from the element.
 */
protected final CBNews parseNews(final Element element) {

    final CBNews news = new CBNewsImpl();

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

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

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

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

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

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

    return news;
}

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

License:Open Source License

/**
 * Parse an element tree and return the module found in it.
 * <p>/*from  w  ww.j av  a  2  s.c om*/
 *
 * @param dcRoot the root element containing the module elements.
 * @param locale for date/time parsing
 * @return the module parsed from the element tree, <i>null</i> if none.
 */
@Override
public Module parse(final Element dcRoot, final Locale locale) {

    boolean foundSomething = false;
    final DCModule dcm = new DCModuleImpl();

    final List<Element> titles = dcRoot.getChildren("title", getDCNamespace());
    if (!titles.isEmpty()) {
        foundSomething = true;
        dcm.setTitles(parseElementList(titles));
    }

    final List<Element> creators = dcRoot.getChildren("creator", getDCNamespace());
    if (!creators.isEmpty()) {
        foundSomething = true;
        dcm.setCreators(parseElementList(creators));
    }

    final List<Element> subjects = dcRoot.getChildren("subject", getDCNamespace());
    if (!subjects.isEmpty()) {
        foundSomething = true;
        dcm.setSubjects(parseSubjects(subjects));
    }

    final List<Element> descriptions = dcRoot.getChildren("description", getDCNamespace());
    if (!descriptions.isEmpty()) {
        foundSomething = true;
        dcm.setDescriptions(parseElementList(descriptions));
    }

    final List<Element> publishers = dcRoot.getChildren("publisher", getDCNamespace());
    if (!publishers.isEmpty()) {
        foundSomething = true;
        dcm.setPublishers(parseElementList(publishers));
    }

    final List<Element> contributors = dcRoot.getChildren("contributor", getDCNamespace());
    if (!contributors.isEmpty()) {
        foundSomething = true;
        dcm.setContributors(parseElementList(contributors));
    }

    final List<Element> dates = dcRoot.getChildren("date", getDCNamespace());
    if (!dates.isEmpty()) {
        foundSomething = true;
        dcm.setDates(parseElementListDate(dates, locale));
    }

    final List<Element> types = dcRoot.getChildren("type", getDCNamespace());
    if (!types.isEmpty()) {
        foundSomething = true;
        dcm.setTypes(parseElementList(types));
    }

    final List<Element> formats = dcRoot.getChildren("format", getDCNamespace());
    if (!formats.isEmpty()) {
        foundSomething = true;
        dcm.setFormats(parseElementList(formats));
    }

    final List<Element> identifiers = dcRoot.getChildren("identifier", getDCNamespace());
    if (!identifiers.isEmpty()) {
        foundSomething = true;
        dcm.setIdentifiers(parseElementList(identifiers));
    }

    final List<Element> sources = dcRoot.getChildren("source", getDCNamespace());
    if (!sources.isEmpty()) {
        foundSomething = true;
        dcm.setSources(parseElementList(sources));
    }

    final List<Element> languages = dcRoot.getChildren("language", getDCNamespace());
    if (!languages.isEmpty()) {
        foundSomething = true;
        dcm.setLanguages(parseElementList(languages));
    }

    final List<Element> relations = dcRoot.getChildren("relation", getDCNamespace());
    if (!relations.isEmpty()) {
        foundSomething = true;
        dcm.setRelations(parseElementList(relations));
    }

    final List<Element> coverages = dcRoot.getChildren("coverage", getDCNamespace());
    if (!coverages.isEmpty()) {
        foundSomething = true;
        dcm.setCoverages(parseElementList(coverages));
    }

    final List<Element> rights = dcRoot.getChildren("rights", getDCNamespace());
    if (!rights.isEmpty()) {
        foundSomething = true;
        dcm.setRightsList(parseElementList(rights));
    }

    if (foundSomething) {
        return dcm;
    } else {
        return null;
    }

}

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

License:Open Source License

/**
 * Utility method to parse a list of subjects out of a list of elements.
 * <p>//www  .  ja v  a 2s  .co  m
 *
 * @param eList the element list to parse.
 * @return a list of subjects parsed from the elements.
 */
protected final List<DCSubject> parseSubjects(final List<Element> eList) {

    final List<DCSubject> subjects = new ArrayList<DCSubject>();

    for (final Element eSubject : eList) {

        final Element description = eSubject.getChild("Description", getRDFNamespace());

        if (description != null) {

            final String taxonomy = getTaxonomy(description);

            final List<Element> values = description.getChildren("value", getRDFNamespace());
            for (final Element value : values) {

                final DCSubject subject = new DCSubjectImpl();
                subject.setTaxonomyUri(taxonomy);
                subject.setValue(value.getText());
                subjects.add(subject);

            }

        } else {
            final DCSubject subject = new DCSubjectImpl();
            subject.setValue(eSubject.getText());
            subjects.add(subject);
        }
    }

    return subjects;
}

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

License:Open Source License

protected void checkItemsConstraints(final Element parent) throws FeedException {
    final int count = parent.getChildren("item", getFeedNamespace()).size();
    if (count < 1 || count > 15) {
        throw new FeedException(
                "Invalid " + getType() + " feed, item count is " + count + " it must be between 1 an 15");
    }/*from  w  ww  .  jav a 2 s .c  o  m*/
}

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

License:Open Source License

/**
 * This method exists because RSS0.90 and RSS1.0 have the 'item' elements under the root
 * elemment. And RSS0.91, RSS0.02, RSS0.93, RSS0.94 and RSS2.0 have the item elements under the
 * 'channel' element./*from   www  . j  av a 2 s.  c  o  m*/
 * <p/>
 */
protected List<Element> getItems(final Element rssRoot) {
    return rssRoot.getChildren("item", getRSSNamespace());
}

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

License:Open Source License

/**
 * Parses the root element of an RSS document into a Channel bean.
 * <p/>//from w w  w.  ja va2  s . co  m
 * It first invokes super.parseChannel and then parses and injects the following properties if
 * present: language, pubDate, rating and copyright.
 * <p/>
 *
 * @param rssRoot the root element of the RSS document to parse.
 * @return the parsed Channel bean.
 */
@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {

    final Channel channel = (Channel) super.parseChannel(rssRoot, locale);

    final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());

    final Element language = eChannel.getChild("language", getRSSNamespace());
    if (language != null) {
        channel.setLanguage(language.getText());
    }

    final Element atinge = eChannel.getChild("rating", getRSSNamespace());
    if (atinge != null) {
        channel.setRating(atinge.getText());
    }

    final Element copyright = eChannel.getChild("copyright", getRSSNamespace());
    if (copyright != null) {
        channel.setCopyright(copyright.getText());
    }

    final Element pubDate = eChannel.getChild("pubDate", getRSSNamespace());
    if (pubDate != null) {
        channel.setPubDate(DateParser.parseDate(pubDate.getText(), locale));
    }

    final Element lastBuildDate = eChannel.getChild("lastBuildDate", getRSSNamespace());
    if (lastBuildDate != null) {
        channel.setLastBuildDate(DateParser.parseDate(lastBuildDate.getText(), locale));
    }

    final Element docs = eChannel.getChild("docs", getRSSNamespace());
    if (docs != null) {
        channel.setDocs(docs.getText());
    }

    final Element generator = eChannel.getChild("generator", getRSSNamespace());
    if (generator != null) {
        channel.setGenerator(generator.getText());
    }

    final Element managingEditor = eChannel.getChild("managingEditor", getRSSNamespace());
    if (managingEditor != null) {
        channel.setManagingEditor(managingEditor.getText());
    }

    final Element webMaster = eChannel.getChild("webMaster", getRSSNamespace());
    if (webMaster != null) {
        channel.setWebMaster(webMaster.getText());
    }

    final Element eSkipHours = eChannel.getChild("skipHours");
    if (eSkipHours != null) {
        final List<Integer> skipHours = new ArrayList<Integer>();
        final List<Element> eHours = eSkipHours.getChildren("hour", getRSSNamespace());
        for (final Element eHour : eHours) {
            skipHours.add(new Integer(eHour.getText().trim()));
        }
        channel.setSkipHours(skipHours);
    }

    final Element eSkipDays = eChannel.getChild("skipDays");
    if (eSkipDays != null) {
        final List<String> skipDays = new ArrayList<String>();
        final List<Element> eDays = eSkipDays.getChildren("day", getRSSNamespace());
        for (final Element eDay : eDays) {
            skipDays.add(eDay.getText().trim());
        }
        channel.setSkipDays(skipDays);
    }

    return channel;
}

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

License:Open Source License

/**
 * It looks for the 'item' elements under the 'channel' elemment.
 *///from w ww  .  j av  a 2 s. c o  m
@Override
protected List<Element> getItems(final Element rssRoot) {

    final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());

    if (eChannel != null) {
        return eChannel.getChildren("item", getRSSNamespace());
    } else {
        return Collections.emptyList();
    }

}

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

License:Open Source License

@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {

    final Channel channel = (Channel) super.parseChannel(rssRoot, locale);

    final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());

    final List<Element> categories = eChannel.getChildren("category", getRSSNamespace());
    channel.setCategories(parseCategories(categories));

    final Element ttl = eChannel.getChild("ttl", getRSSNamespace());
    if (ttl != null && ttl.getText() != null) {
        final Integer ttlValue = NumberParser.parseInt(ttl.getText());
        if (ttlValue != null) {
            channel.setTtl(ttlValue);/*from ww w .j  a  va 2s . com*/
        }
    }

    return channel;
}

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

License:Open Source License

protected WireFeed parseFeed(Element eFeed) {

    com.sun.syndication.feed.atom.Feed feed = new com.sun.syndication.feed.atom.Feed(getType());

    Element e = eFeed.getChild("title", getAtomNamespace());
    if (e != null) {
        feed.setTitleEx(parseContent(e));
    }/*from  ww w  .  ja v  a 2s  .  co  m*/

    List eList = eFeed.getChildren("link", getAtomNamespace());
    feed.setAlternateLinks(parseAlternateLinks(eList));
    feed.setOtherLinks(parseOtherLinks(eList));

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

    eList = eFeed.getChildren("contributor", getAtomNamespace());
    if (eList.size() > 0) {
        feed.setContributors(parsePersons(eList));
    }

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

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

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

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

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

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

    feed.setModules(parseFeedModules(eFeed));

    eList = eFeed.getChildren("entry", getAtomNamespace());
    if (eList.size() > 0) {
        feed.setEntries(parseEntries(eList));
    }

    List foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace());
    if (foreignMarkup.size() > 0) {
        feed.setForeignMarkup(foreignMarkup);
    }
    return feed;
}

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

License:Open Source License

private Entry parseEntry(Element eEntry) {
    Entry entry = new Entry();

    Element e = eEntry.getChild("title", getAtomNamespace());
    if (e != null) {
        entry.setTitleEx(parseContent(e));
    }//  ww w . j  av a 2s.c o m

    List eList = eEntry.getChildren("link", getAtomNamespace());
    entry.setAlternateLinks(parseAlternateLinks(eList));
    entry.setOtherLinks(parseOtherLinks(eList));

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

    eList = eEntry.getChildren("contributor", getAtomNamespace());
    if (eList.size() > 0) {
        entry.setContributors(parsePersons(eList));
    }

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

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

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

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

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

    eList = eEntry.getChildren("content", getAtomNamespace());
    if (eList.size() > 0) {
        List content = new ArrayList();
        for (int i = 0; i < eList.size(); i++) {
            content.add(parseContent((Element) eList.get(i)));
        }
        entry.setContents(content);
    }

    entry.setModules(parseItemModules(eEntry));

    List foreignMarkup = extractForeignMarkup(eEntry, entry, getAtomNamespace());
    if (foreignMarkup.size() > 0) {
        entry.setForeignMarkup(foreignMarkup);
    }
    return entry;
}