List of usage examples for org.jdom2 Element getChild
public Element getChild(final String cname, final Namespace ns)
From source file:com.rometools.rome.io.impl.RSS094Generator.java
License:Open Source License
@Override protected void populateItem(final Item item, final Element eItem, final int index) { super.populateItem(item, eItem, index); final Description description = item.getDescription(); if (description != null && description.getType() != null) { final Element eDescription = eItem.getChild("description", getFeedNamespace()); eDescription.setAttribute(new Attribute("type", description.getType())); }/*from ww w . ja v a 2 s.c o m*/ eItem.removeChild("expirationDate", getFeedNamespace()); }
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 w w w. ja va2s.com } } return channel; }
From source file:com.rometools.rome.io.impl.RSS094Parser.java
License:Open Source License
@Override public Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) { final Item item = super.parseItem(rssRoot, eItem, locale); item.setExpirationDate(null);// w w w. j a v a 2s.co m final Element author = eItem.getChild("author", getRSSNamespace()); if (author != null) { item.setAuthor(author.getText()); } final Element eGuid = eItem.getChild("guid", getRSSNamespace()); if (eGuid != null) { final Guid guid = new Guid(); // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK final String att = eGuid.getAttributeValue("isPermaLink"); if (att != null) { guid.setPermaLink(att.equalsIgnoreCase("true")); } guid.setValue(eGuid.getText()); item.setGuid(guid); } final Element comments = eItem.getChild("comments", getRSSNamespace()); if (comments != null) { item.setComments(comments.getText()); } return item; }
From source file:com.rometools.rome.io.impl.RSS10Parser.java
License:Open Source License
/** * Indicates if a JDom document is an RSS instance that can be parsed with the parser. * <p/>//from w w w. j a va2 s . c om * It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") namespace being defined in * the root element and for the RSS 1.0 ("http://purl.org/rss/1.0/") namespace in the channel * element. * * @param document document to check if it can be parsed with this parser implementation. * @return <b>true</b> if the document is RSS1., <b>false</b> otherwise. */ @Override public boolean isMyType(final Document document) { final Element rssRoot = document.getRootElement(); final Namespace defaultNS = rssRoot.getNamespace(); return defaultNS != null && defaultNS.equals(getRDFNamespace()) && rssRoot.getChild("channel", getRSSNamespace()) != null; }
From source file:com.rometools.rome.io.impl.RSS10Parser.java
License:Open Source License
/** * Parses an item element of an RSS document looking for item information. * <p/>/*from www.ja v a 2s. c o m*/ * 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); } final String about = eItem.getAttributeValue("about", getRDFNamespace()); if (about != null) { item.setUri(about); } return item; }
From source file:com.rometools.rome.io.impl.RSS10Parser.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 String uri = eChannel.getAttributeValue("about", getRDFNamespace()); if (uri != null) { channel.setUri(uri);// w w w.j av a 2s.c o m } return channel; }
From source file:com.rometools.rome.io.impl.RSS20Generator.java
License:Open Source License
@Override public void populateItem(final Item item, final Element eItem, final int index) { super.populateItem(item, eItem, index); final Element description = eItem.getChild("description", getFeedNamespace()); if (description != null) { description.removeAttribute("type"); }// w w w . java 2s . co m final String author = item.getAuthor(); if (author != null) { eItem.addContent(generateSimpleElement("author", author)); } final String comments = item.getComments(); if (comments != null) { eItem.addContent(generateSimpleElement("comments", comments)); } final Guid guid = item.getGuid(); if (guid != null) { final Element eGuid = generateSimpleElement("guid", guid.getValue()); if (!guid.isPermaLink()) { eGuid.setAttribute("isPermaLink", "false"); } eItem.addContent(eGuid); } }
From source file:com.rometools.rome.io.impl.SyModuleParser.java
License:Open Source License
@Override public Module parse(final Element syndRoot, final Locale locale) { boolean foundSomething = false; final SyModule sm = new SyModuleImpl(); final Element updatePeriod = syndRoot.getChild("updatePeriod", getDCNamespace()); if (updatePeriod != null) { foundSomething = true;//from w w w .ja v a 2s. c o m sm.setUpdatePeriod(updatePeriod.getText().trim()); } final Element updateFrequency = syndRoot.getChild("updateFrequency", getDCNamespace()); if (updateFrequency != null) { foundSomething = true; sm.setUpdateFrequency(Integer.parseInt(updateFrequency.getText().trim())); } final Element updateBase = syndRoot.getChild("updateBase", getDCNamespace()); if (updateBase != null) { foundSomething = true; sm.setUpdateBase(DateParser.parseDate(updateBase.getText(), locale)); } if (foundSomething) { return sm; } else { return null; } }
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)); }/*w w w. j a v a 2 s . 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 Person parsePerson(Element ePerson) { Person person = new Person(); Element e = ePerson.getChild("name", getAtomNamespace()); if (e != null) { person.setName(e.getText());//from w ww. j a v a 2s . co m } e = ePerson.getChild("url", getAtomNamespace()); if (e != null) { person.setUrl(e.getText()); } e = ePerson.getChild("email", getAtomNamespace()); if (e != null) { person.setEmail(e.getText()); } return person; }