Example usage for org.jdom2 Element getChild

List of usage examples for org.jdom2 Element getChild

Introduction

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

Prototype

public Element getChild(final String cname, final Namespace ns) 

Source Link

Document

This returns the first child element within this element with the given local name and belonging to the given namespace.

Usage

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

License:Open Source License

@Override
protected void addChannel(final Channel channel, final Element parent) throws FeedException {

    super.addChannel(channel, parent);

    final Element eChannel = parent.getChild("channel", getFeedNamespace());

    addImage(channel, eChannel);//from   www .j a  v a  2  s.  c o m
    addTextInput(channel, eChannel);
    addItems(channel, eChannel);

}

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/>/*w  w  w  .  j  a va 2 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

/**
 * Parses the root element of an RSS document looking for image information.
 * <p/>//from w ww .  j a  v  a  2 s .c om
 * It first invokes super.parseImage and then parses and injects the following properties if
 * present: url, link, width, height and description.
 * <p/>
 *
 * @param rssRoot the root element of the RSS document to parse for image information.
 * @return the parsed RSSImage bean.
 */
@Override
protected Image parseImage(final Element rssRoot) {

    final Image image = super.parseImage(rssRoot);
    if (image != null) {

        final Element eImage = getImage(rssRoot);

        final Element width = eImage.getChild("width", getRSSNamespace());
        if (width != null) {
            final Integer val = NumberParser.parseInt(width.getText());
            if (val != null) {
                image.setWidth(val);
            }
        }

        final Element height = eImage.getChild("height", getRSSNamespace());
        if (height != null) {
            final Integer val = NumberParser.parseInt(height.getText());
            if (val != null) {
                image.setHeight(val);
            }
        }

        final Element description = eImage.getChild("description", getRSSNamespace());
        if (description != null) {
            image.setDescription(description.getText());
        }

    }

    return image;

}

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 w w.jav a  2 s. co  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.RSS091UserlandParser.java

License:Open Source License

/**
 * It looks for the 'image' elements under the 'channel' elemment.
 *///from   ww w.ja  va  2  s .  c  om
@Override
protected Element getImage(final Element rssRoot) {

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

    if (eChannel != null) {
        return eChannel.getChild("image", getRSSNamespace());
    } else {
        return null;
    }

}

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

License:Open Source License

/**
 * It looks for the 'textinput' elements under the 'channel' elemment.
 *///from   w w w  .  j  a v a 2s . co  m
@Override
protected Element getTextInput(final Element rssRoot) {

    final String elementName = getTextInputLabel();

    final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());
    if (eChannel != null) {
        return eChannel.getChild(elementName, getRSSNamespace());
    } else {
        return null;
    }

}

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

License:Open Source License

/**
 * Parses an item element of an RSS document looking for item information.
 * <p/>//  w ww .  ja va  2 s  .c om
 * It first invokes super.parseItem and then parses and injects the description property if
 * present.
 * <p/>
 *
 * @param rssRoot the root element of the RSS document in case it's needed for context.
 * @param eItem the item element to parse.
 * @return the parsed RSSItem bean.
 */
@Override
protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) {

    final Item item = super.parseItem(rssRoot, eItem, locale);

    final Element description = eItem.getChild("description", getRSSNamespace());
    if (description != null) {
        item.setDescription(parseItemDescription(rssRoot, description));
    }

    final Element encoded = eItem.getChild("encoded", getContentNamespace());
    if (encoded != null) {
        final Content content = new Content();
        content.setType(Content.HTML);
        content.setValue(encoded.getText());
        item.setContent(content);
    }

    return item;

}

From source file:com.rometools.rome.io.impl.RSS092Parser.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 Element eCloud = eChannel.getChild("cloud", getRSSNamespace());

    if (eCloud != null) {
        final Cloud cloud = new Cloud();

        final String domain = eCloud.getAttributeValue("domain");
        if (domain != null) {
            cloud.setDomain(domain);/*w  w w  .  ja  va  2 s  .  com*/
        }

        // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
        final String port = eCloud.getAttributeValue("port");
        if (port != null) {
            cloud.setPort(Integer.parseInt(port.trim()));
        }

        // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
        final String path = eCloud.getAttributeValue("path");
        if (path != null) {
            cloud.setPath(path);
        }

        // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
        final String registerProcedure = eCloud.getAttributeValue("registerProcedure");
        if (registerProcedure != null) {
            cloud.setRegisterProcedure(registerProcedure);
        }

        // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
        final String protocol = eCloud.getAttributeValue("protocol");
        if (protocol != null) {
            cloud.setProtocol(protocol);
        }

        channel.setCloud(cloud);

    }
    return channel;
}

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

License:Open Source License

@Override
protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) {
    final Item item = super.parseItem(rssRoot, eItem, locale);

    final Element eSource = eItem.getChild("source", getRSSNamespace());
    if (eSource != null) {
        final Source source = new Source();
        // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
        final String url = eSource.getAttributeValue("url");
        source.setUrl(url);/*from   www . ja v a  2  s. com*/
        source.setValue(eSource.getText());
        item.setSource(source);
    }

    // 0.92 allows one enclosure occurrence, 0.93 multiple just saving to write some code.
    // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
    final List<Element> eEnclosures = eItem.getChildren("enclosure");

    if (!eEnclosures.isEmpty()) {

        final List<Enclosure> enclosures = new ArrayList<Enclosure>();

        for (final Element eEnclosure : eEnclosures) {

            final Enclosure enclosure = new Enclosure();
            // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
            final String url = eEnclosure.getAttributeValue("url");
            if (url != null) {
                enclosure.setUrl(url);
            }

            // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
            final String length = eEnclosure.getAttributeValue("length");
            enclosure.setLength(NumberParser.parseLong(length, 0L));

            // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
            final String type = eEnclosure.getAttributeValue("type");
            if (type != null) {
                enclosure.setType(type);
            }

            enclosures.add(enclosure);

        }

        item.setEnclosures(enclosures);
    }

    // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
    final List<Element> categories = eItem.getChildren("category");
    item.setCategories(parseCategories(categories));

    return item;
}

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

License:Open Source License

@Override
protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) {

    final Item item = super.parseItem(rssRoot, eItem, locale);

    final Element pubDate = eItem.getChild("pubDate", getRSSNamespace());
    if (pubDate != null) {
        item.setPubDate(DateParser.parseDate(pubDate.getText(), locale));
    }//from  w ww  . j a  v  a 2 s  . c o m

    final Element expirationDate = eItem.getChild("expirationDate", getRSSNamespace());
    if (expirationDate != null) {
        item.setExpirationDate(DateParser.parseDate(expirationDate.getText(), locale));
    }

    final Element description = eItem.getChild("description", getRSSNamespace());
    if (description != null) {
        final String type = description.getAttributeValue("type");
        if (type != null) {
            item.getDescription().setType(type);
        }
    }

    return item;

}