List of usage examples for org.jdom2 Element getText
public String getText()
From source file:com.rometools.rome.io.impl.DCModuleParser.java
License:Open Source License
/** * Utility method to parse a list of dates out of a list of elements. * <p>/*w ww . ja va2 s . c o m*/ * * @param elements the list of elements to parse. * @return the list of dates. */ protected final List<Date> parseElementListDate(final List<Element> elements, final Locale locale) { final List<Date> values = new ArrayList<Date>(); for (final Element element : elements) { values.add(DateParser.parseDate(element.getText(), locale)); } return values; }
From source file:com.rometools.rome.io.impl.RSS090Generator.java
License:Open Source License
protected void checkLength(final Element parent, final String childName, final int minLen, final int maxLen) throws FeedException { final 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 ww . j a 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.rometools.rome.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 a2 s. c o m * 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(final Element rssRoot, final Locale locale) { final Channel channel = new Channel(getType()); channel.setStyleSheet(getStyleSheet(rssRoot.getDocument())); final Element eChannel = rssRoot.getChild("channel", getRSSNamespace()); final Element title = eChannel.getChild("title", getRSSNamespace()); if (title != null) { channel.setTitle(title.getText()); } final Element link = eChannel.getChild("link", getRSSNamespace()); if (link != null) { channel.setLink(link.getText()); } final Element description = eChannel.getChild("description", getRSSNamespace()); if (description != null) { channel.setDescription(description.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. final List<Module> allFeedModules = new ArrayList<Module>(); final List<Module> rootModules = parseFeedModules(rssRoot, locale); final List<Module> channelModules = parseFeedModules(eChannel, locale); if (rootModules != null) { allFeedModules.addAll(rootModules); } if (channelModules != null) { allFeedModules.addAll(channelModules); } channel.setModules(allFeedModules); channel.setItems(parseItems(rssRoot, locale)); final List<Element> foreignMarkup = extractForeignMarkup(eChannel, channel, getRSSNamespace()); if (!foreignMarkup.isEmpty()) { channel.setForeignMarkup(foreignMarkup); } return channel; }
From source file:com.rometools.rome.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(final Element rssRoot) { Image image = null; final Element eImage = getImage(rssRoot); if (eImage != null) { image = new Image(); final Element title = eImage.getChild("title", getRSSNamespace()); if (title != null) { image.setTitle(title.getText()); } final Element url = eImage.getChild("url", getRSSNamespace()); if (url != null) { image.setUrl(url.getText()); } final Element link = eImage.getChild("link", getRSSNamespace()); if (link != null) { image.setLink(link.getText()); } } return image; }
From source file:com.rometools.rome.io.impl.RSS090Parser.java
License:Open Source License
/** * Parses an item element of an RSS document looking for item information. * <p/>// ww w . jav a2 s . c o m * 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(final Element rssRoot, final Element eItem, final Locale locale) { final Item item = new Item(); final Element title = eItem.getChild("title", getRSSNamespace()); if (title != null) { item.setTitle(title.getText()); } final Element link = eItem.getChild("link", getRSSNamespace()); if (link != null) { item.setLink(link.getText()); item.setUri(link.getText()); } item.setModules(parseItemModules(eItem, locale)); final List<Element> 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 final Iterator<Element> iterator = foreignMarkup.iterator(); while (iterator.hasNext()) { final Element element = iterator.next(); final Namespace eNamespace = element.getNamespace(); final String eName = element.getName(); if (getContentNamespace().equals(eNamespace) && eName.equals("encoded")) { iterator.remove(); } } if (!foreignMarkup.isEmpty()) { item.setForeignMarkup(foreignMarkup); } return item; }
From source file:com.rometools.rome.io.impl.RSS090Parser.java
License:Open Source License
/** * Parses the root element of an RSS document looking for text-input information. * <p/>//w ww . ja v a 2 s. 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(final Element rssRoot) { TextInput textInput = null; final Element eTextInput = getTextInput(rssRoot); if (eTextInput != null) { textInput = new TextInput(); final Element title = eTextInput.getChild("title", getRSSNamespace()); if (title != null) { textInput.setTitle(title.getText()); } final Element description = eTextInput.getChild("description", getRSSNamespace()); if (description != null) { textInput.setDescription(description.getText()); } final Element name = eTextInput.getChild("name", getRSSNamespace()); if (name != null) { textInput.setName(name.getText()); } final Element link = eTextInput.getChild("link", getRSSNamespace()); if (link != null) { textInput.setLink(link.getText()); } } return textInput; }
From source file:com.rometools.rome.io.impl.RSS091UserlandGenerator.java
License:Open Source License
@Override protected void checkChannelConstraints(final 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); final Element skipHours = eChannel.getChild("skipHours"); if (skipHours != null) { final List<Element> hours = skipHours.getChildren(); for (final Element hour : hours) { final 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"); }// w ww. j a v a 2 s . c o m } else { if (value < 0 || value > 23) { throw new FeedException("Invalid hour value " + value + ", it must be between 0 and 23"); } } } } }
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/>/* ww w .j av a2s . c om*/ * 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 w w. jav a2 s. co m*/ * 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
/** * Parses an item element of an RSS document looking for item information. * <p/>//w w w . ja v a 2s . 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; }