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.sun.syndication.io.impl.Atom10Parser.java

License:Open Source License

protected WireFeed parseFeed(Element eFeed) throws FeedException {

    String baseURI = null;//  ww  w. j  av a  2s.c o m
    try {
        baseURI = findBaseURI(eFeed);
    } catch (Exception e) {
        throw new FeedException("ERROR while finding base URI of feed", e);
    }

    Feed feed = parseFeedMetadata(baseURI, eFeed);

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

    feed.setModules(parseFeedModules(eFeed));

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

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

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

License:Open Source License

private Feed parseFeedMetadata(String baseURI, 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) {
        Content c = new Content();
        c.setValue(parseTextConstructToString(e));
        c.setType(getAttributeValue(e, "type"));
        feed.setTitleEx(c);/*  w  w  w.ja va 2 s. co m*/
    }

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

    List cList = eFeed.getChildren("category", getAtomNamespace());
    feed.setCategories(parseCategories(baseURI, cList));

    eList = eFeed.getChildren("author", getAtomNamespace());
    if (eList.size() > 0) {
        feed.setAuthors(parsePersons(baseURI, eList));
    }

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

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

    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, "uri");
        if (att != null) {
            gen.setUrl(att);
        }
        att = getAttributeValue(e, "version");
        if (att != null) {
            gen.setVersion(att);
        }
        feed.setGenerator(gen);
    }

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

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

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

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

    return feed;
}

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

License:Open Source License

protected Entry parseEntry(Feed feed, Element eEntry, String baseURI) {
    Entry entry = new Entry();

    String xmlBase = eEntry.getAttributeValue("base", Namespace.XML_NAMESPACE);
    if (xmlBase != null) {
        entry.setXmlBase(xmlBase);//from w w w.  ja  v a 2 s . com
    }

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

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

    eList = eEntry.getChildren("author", getAtomNamespace());
    if (eList.size() > 0) {
        entry.setAuthors(parsePersons(baseURI, eList));
    }

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

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

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

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

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

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

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

    List cList = eEntry.getChildren("category", getAtomNamespace());
    entry.setCategories(parseCategories(baseURI, cList));

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

    entry.setModules(parseItemModules(eEntry));

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

From source file:com.sun.syndication.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"
 * @param parent Consider only children of this parent element
 * @param rel    Consider only links with this relationship
 *///from   www.  j  a v a  2  s  .  c om
private String findAtomLink(Element parent, String rel) {
    String ret = null;
    List linksList = parent.getChildren("link", ATOM_10_NS);
    if (linksList != null) {
        for (Iterator links = linksList.iterator(); links.hasNext();) {
            Element link = (Element) links.next();
            Attribute relAtt = getAttribute(link, "rel");
            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.sun.syndication.io.impl.DCModuleParser.java

License:Open Source License

/**
 * Parse an element tree and return the module found in it.
 * <p>/*from w ww  .  j a  v a2  s  .c om*/
 * @param dcRoot the root element containing the module elements.
 * @return the module parsed from the element tree, <i>null</i> if none.
 */
public Module parse(Element dcRoot) {
    boolean foundSomething = false;
    DCModule dcm = new DCModuleImpl();

    List eList = dcRoot.getChildren("title", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setTitles(parseElementList(eList));
    }
    eList = dcRoot.getChildren("creator", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setCreators(parseElementList(eList));
    }
    eList = dcRoot.getChildren("subject", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setSubjects(parseSubjects(eList));
    }
    eList = dcRoot.getChildren("description", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setDescriptions(parseElementList(eList));
    }
    eList = dcRoot.getChildren("publisher", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setPublishers(parseElementList(eList));
    }
    eList = dcRoot.getChildren("contributor", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setContributors(parseElementList(eList));
    }
    eList = dcRoot.getChildren("date", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setDates(parseElementListDate(eList));
    }
    eList = dcRoot.getChildren("type", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setTypes(parseElementList(eList));
    }
    eList = dcRoot.getChildren("format", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setFormats(parseElementList(eList));
    }
    eList = dcRoot.getChildren("identifier", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setIdentifiers(parseElementList(eList));
    }
    eList = dcRoot.getChildren("source", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setSources(parseElementList(eList));
    }
    eList = dcRoot.getChildren("language", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setLanguages(parseElementList(eList));
    }
    eList = dcRoot.getChildren("relation", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setRelations(parseElementList(eList));
    }
    eList = dcRoot.getChildren("coverage", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setCoverages(parseElementList(eList));
    }
    eList = dcRoot.getChildren("rights", getDCNamespace());
    if (eList.size() > 0) {
        foundSomething = true;
        dcm.setRightsList(parseElementList(eList));
    }

    return (foundSomething) ? dcm : null;
}

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

License:Open Source License

/**
 * Utility method to parse a list of subjects out of a list of elements.
 * <p>//from w w w. ja  v  a2  s.c  o  m
 * @param eList the element list to parse.
 * @return a list of subjects parsed from the elements.
 */
protected final List parseSubjects(List eList) {
    List subjects = new ArrayList();
    for (Iterator i = eList.iterator(); i.hasNext();) {
        Element eSubject = (Element) i.next();
        Element eDesc = eSubject.getChild("Description", getRDFNamespace());
        if (eDesc != null) {
            String taxonomy = getTaxonomy(eDesc);
            List eValues = eDesc.getChildren("value", getRDFNamespace());
            for (Iterator v = eValues.iterator(); v.hasNext();) {
                Element eValue = (Element) v.next();
                DCSubject subject = new DCSubjectImpl();
                subject.setTaxonomyUri(taxonomy);
                subject.setValue(eValue.getText());
                subjects.add(subject);
            }
        } else {
            DCSubject subject = new DCSubjectImpl();
            subject.setValue(eSubject.getText());
            subjects.add(subject);
        }
    }

    return subjects;
}

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

License:Open Source License

protected void checkItemsConstraints(Element parent) throws FeedException {
    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  www . j  a v  a  2s  .  com*/
}

From source file:com.sun.syndication.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.
 * <p/>/* ww w  .  j  a v  a 2 s  . c om*/
 */
protected List getItems(Element rssRoot) {
    return rssRoot.getChildren("item", getRSSNamespace());
}

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

License:Open Source License

/**
 * Parses the root element of an RSS document into a Channel bean.
 * <p/>//from  w ww.j  a v  a 2s .com
 * 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.
 */
protected WireFeed parseChannel(Element rssRoot) {
    Channel channel = (Channel) super.parseChannel(rssRoot);

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

    Element e = eChannel.getChild("language", getRSSNamespace());
    if (e != null) {
        channel.setLanguage(e.getText());
    }
    e = eChannel.getChild("rating", getRSSNamespace());
    if (e != null) {
        channel.setRating(e.getText());
    }
    e = eChannel.getChild("copyright", getRSSNamespace());
    if (e != null) {
        channel.setCopyright(e.getText());
    }
    e = eChannel.getChild("pubDate", getRSSNamespace());
    if (e != null) {
        channel.setPubDate(DateParser.parseDate(e.getText()));
    }
    e = eChannel.getChild("lastBuildDate", getRSSNamespace());
    if (e != null) {
        channel.setLastBuildDate(DateParser.parseDate(e.getText()));
    }
    e = eChannel.getChild("docs", getRSSNamespace());
    if (e != null) {
        channel.setDocs(e.getText());
    }
    e = eChannel.getChild("docs", getRSSNamespace());
    if (e != null) {
        channel.setDocs(e.getText());
    }
    e = eChannel.getChild("managingEditor", getRSSNamespace());
    if (e != null) {
        channel.setManagingEditor(e.getText());
    }
    e = eChannel.getChild("webMaster", getRSSNamespace());
    if (e != null) {
        channel.setWebMaster(e.getText());
    }
    e = eChannel.getChild("skipHours");
    if (e != null) {
        List skipHours = new ArrayList();
        List eHours = e.getChildren("hour", getRSSNamespace());
        for (int i = 0; i < eHours.size(); i++) {
            Element eHour = (Element) eHours.get(i);
            skipHours.add(new Integer(eHour.getText().trim()));
        }
        channel.setSkipHours(skipHours);
    }

    e = eChannel.getChild("skipDays");
    if (e != null) {
        List skipDays = new ArrayList();
        List eDays = e.getChildren("day", getRSSNamespace());
        for (int i = 0; i < eDays.size(); i++) {
            Element eDay = (Element) eDays.get(i);
            skipDays.add(eDay.getText().trim());
        }
        channel.setSkipDays(skipDays);
    }
    return channel;
}

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

License:Open Source License

/**
 * It looks for the 'item' elements under the 'channel' elemment.
 *///from  ww  w  .  ja  va 2  s. c o m
protected List getItems(Element rssRoot) {
    Element eChannel = rssRoot.getChild("channel", getRSSNamespace());
    return (eChannel != null) ? eChannel.getChildren("item", getRSSNamespace()) : Collections.EMPTY_LIST;
}