Example usage for org.jdom2 Element getText

List of usage examples for org.jdom2 Element getText

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the textual content directly held under this element as a string.

Usage

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

License:Open Source License

/**
 * Utility method to parse a list of strings out of a list of elements.
 * <p>//ww w. jav a 2s . c  o  m
 * @param eList the list of elements to parse.
 * @return the list of strings
 */
protected final List parseElementList(List eList) {
    List values = new ArrayList();
    for (Iterator i = eList.iterator(); i.hasNext();) {
        Element e = (Element) i.next();
        values.add(e.getText());
    }

    return values;
}

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

License:Open Source License

/**
 * Utility method to parse a list of dates out of a list of elements.
 * <p>/*from  www  .jav a 2 s  .  co m*/
 * @param eList the list of elements to parse.
 * @return the list of dates.
 */
protected final List parseElementListDate(List eList) {
    List values = new ArrayList();
    for (Iterator i = eList.iterator(); i.hasNext();) {
        Element e = (Element) i.next();
        values.add(DateParser.parseDate(e.getText()));
    }

    return values;
}

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

License:Open Source License

protected void checkLength(Element parent, String childName, int minLen, int maxLen) throws FeedException {
    Element child = parent.getChild(childName, getFeedNamespace());
    if (child != null) {
        if (minLen > 0 && child.getText().length() < minLen) {
            throw new FeedException("Invalid " + getType() + " feed, " + parent.getName() + " " + childName
                    + "short of " + minLen + " length");
        }/*from  w  w  w . ja  v  a 2 s  . c  o m*/
        if (maxLen > -1 && child.getText().length() > maxLen) {
            throw new FeedException("Invalid " + getType() + " feed, " + parent.getName() + " " + childName
                    + "exceeds " + maxLen + " length");
        }
    }
}

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

License:Open Source License

/**
 * Parses the root element of an RSS document into a Channel bean.
 * <p/>/*from w w  w . ja v  a 2  s .c om*/
 * It reads title, link and description and delegates to parseImage, parseItems
 * and parseTextInput. This delegation always passes the root element of the RSS
 * document as different RSS version may have this information in different parts
 * of the XML tree (no assumptions made thanks to the specs variaty)
 * <p/>
 *
 * @param rssRoot the root element of the RSS document to parse.
 * @return the parsed Channel bean.
 */
protected WireFeed parseChannel(Element rssRoot) {
    Element eChannel = rssRoot.getChild("channel", getRSSNamespace());

    Channel channel = new Channel(getType());

    Element e = eChannel.getChild("title", getRSSNamespace());
    if (e != null) {
        channel.setTitle(e.getText());
    }
    e = eChannel.getChild("link", getRSSNamespace());
    if (e != null) {
        channel.setLink(e.getText());
    }
    e = eChannel.getChild("description", getRSSNamespace());
    if (e != null) {
        channel.setDescription(e.getText());
    }

    channel.setImage(parseImage(rssRoot));

    channel.setTextInput(parseTextInput(rssRoot));

    // Unfortunately Microsoft's SSE extension has a special case of 
    // effectively putting the sharing channel module inside the RSS tag 
    // and not inside the channel itself. So we also need to look for 
    // channel modules from the root RSS element.
    List allFeedModules = new ArrayList();
    List rootModules = parseFeedModules(rssRoot);
    List channelModules = parseFeedModules(eChannel);
    if (rootModules != null) {
        allFeedModules.addAll(rootModules);
    }
    if (channelModules != null) {
        allFeedModules.addAll(channelModules);
    }
    channel.setModules(allFeedModules);
    channel.setItems(parseItems(rssRoot));

    List foreignMarkup = extractForeignMarkup(eChannel, channel, getRSSNamespace());
    if (foreignMarkup.size() > 0) {
        channel.setForeignMarkup(foreignMarkup);
    }
    return channel;
}

From source file:com.sun.syndication.io.impl.RSS090Parser.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 o  m
 * It reads title and url out of the 'image' element.
 * <p/>
 *
 * @param rssRoot the root element of the RSS document to parse for image information.
 * @return the parsed image bean.
 */
protected Image parseImage(Element rssRoot) {
    Image image = null;
    Element eImage = getImage(rssRoot);
    if (eImage != null) {
        image = new Image();

        Element e = eImage.getChild("title", getRSSNamespace());
        if (e != null) {
            image.setTitle(e.getText());
        }
        e = eImage.getChild("url", getRSSNamespace());
        if (e != null) {
            image.setUrl(e.getText());
        }
        e = eImage.getChild("link", getRSSNamespace());
        if (e != null) {
            image.setLink(e.getText());
        }
    }
    return image;
}

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

License:Open Source License

/**
 * Parses an item element of an RSS document looking for item information.
 * <p/>/*www . java 2  s. c om*/
 * It reads title and link out of the 'item' element.
 * <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.
 */
protected Item parseItem(Element rssRoot, Element eItem) {
    Item item = new Item();
    Element e = eItem.getChild("title", getRSSNamespace());
    if (e != null) {
        item.setTitle(e.getText());
    }
    e = eItem.getChild("link", getRSSNamespace());
    if (e != null) {
        item.setLink(e.getText());
        item.setUri(e.getText());
    }

    item.setModules(parseItemModules(eItem));

    List foreignMarkup = extractForeignMarkup(eItem, item, getRSSNamespace());
    //content:encoded elements are treated special, without a module, they have to be removed from the foreign
    //markup to avoid duplication in case of read/write. Note that this fix will break if a content module is
    //used
    Iterator iterator = foreignMarkup.iterator();
    while (iterator.hasNext()) {
        Element ie = (Element) iterator.next();
        if (getContentNamespace().equals(ie.getNamespace()) && ie.getName().equals("encoded")) {
            iterator.remove();
        }
    }
    if (foreignMarkup.size() > 0) {
        item.setForeignMarkup(foreignMarkup);
    }
    return item;
}

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

License:Open Source License

/**
 * Parses the root element of an RSS document looking for  text-input information.
 * <p/>/*from w  ww.j a va2s .c o m*/
 * It reads title, description, name and link out of the 'textinput' or 'textInput' element.
 * <p/>
 *
 * @param rssRoot the root element of the RSS document to parse for text-input information.
 * @return the parsed RSSTextInput bean.
 */
protected TextInput parseTextInput(Element rssRoot) {
    TextInput textInput = null;
    Element eTextInput = getTextInput(rssRoot);
    if (eTextInput != null) {
        textInput = new TextInput();
        Element e = eTextInput.getChild("title", getRSSNamespace());
        if (e != null) {
            textInput.setTitle(e.getText());
        }
        e = eTextInput.getChild("description", getRSSNamespace());
        if (e != null) {
            textInput.setDescription(e.getText());
        }
        e = eTextInput.getChild("name", getRSSNamespace());
        if (e != null) {
            textInput.setName(e.getText());
        }
        e = eTextInput.getChild("link", getRSSNamespace());
        if (e != null) {
            textInput.setLink(e.getText());
        }
    }
    return textInput;
}

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

License:Open Source License

protected void checkChannelConstraints(Element eChannel) throws FeedException {
    checkNotNullAndLength(eChannel, "title", 1, 100);
    checkNotNullAndLength(eChannel, "description", 1, 500);
    checkNotNullAndLength(eChannel, "link", 1, 500);
    checkNotNullAndLength(eChannel, "language", 2, 5);

    checkLength(eChannel, "rating", 20, 500);
    checkLength(eChannel, "copyright", 1, 100);
    checkLength(eChannel, "pubDate", 1, 100);
    checkLength(eChannel, "lastBuildDate", 1, 100);
    checkLength(eChannel, "docs", 1, 500);
    checkLength(eChannel, "managingEditor", 1, 100);
    checkLength(eChannel, "webMaster", 1, 100);

    Element skipHours = eChannel.getChild("skipHours");

    if (skipHours != null) {
        List hours = skipHours.getChildren();

        for (int i = 0; i < hours.size(); i++) {
            Element hour = (Element) hours.get(i);
            int value = Integer.parseInt(hour.getText().trim());

            if (isHourFormat24()) {
                if ((value < 1) || (value > 24)) {
                    throw new FeedException("Invalid hour value " + value + ", it must be between 1 and 24");
                }/*www  .  j  av  a2  s.  c om*/
            } else {
                if ((value < 0) || (value > 23)) {
                    throw new FeedException("Invalid hour value " + value + ", it must be between 0 and 23");
                }
            }
        }
    }
}

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/>//w  ww.  j  a  v a 2s .  c o  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.
 */
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

/**
 * Parses the root element of an RSS document looking for  image information.
 * <p/>//from w  w w .  j av  a2  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.
 */
protected Image parseImage(Element rssRoot) {
    Image image = super.parseImage(rssRoot);
    if (image != null) {
        Element eImage = getImage(rssRoot);
        Element e = eImage.getChild("width", getRSSNamespace());
        if (e != null) {
            Integer val = NumberParser.parseInt(e.getText());
            if (val != null) {
                image.setWidth(val.intValue());
            }
        }
        e = eImage.getChild("height", getRSSNamespace());
        if (e != null) {
            Integer val = NumberParser.parseInt(e.getText());
            if (val != null) {
                image.setHeight(val.intValue());
            }
        }
        e = eImage.getChild("description", getRSSNamespace());
        if (e != null) {
            image.setDescription(e.getText());
        }
    }
    return image;
}