List of usage examples for org.jdom2 Element getChild
public Element getChild(final String cname, final Namespace ns)
From source file:com.sun.syndication.io.impl.Atom03Parser.java
License:Open Source License
private Entry parseEntry(Element eEntry) { Entry entry = new Entry(); Element e = eEntry.getChild("title", getAtomNamespace()); if (e != null) { entry.setTitleEx(parseContent(e)); }/*ww w .j av a2s.c o m*/ List eList = eEntry.getChildren("link", getAtomNamespace()); entry.setAlternateLinks(parseAlternateLinks(eList)); entry.setOtherLinks(parseOtherLinks(eList)); e = eEntry.getChild("author", getAtomNamespace()); if (e != null) { List authors = new ArrayList(); authors.add(parsePerson(e)); entry.setAuthors(authors); } eList = eEntry.getChildren("contributor", getAtomNamespace()); if (eList.size() > 0) { entry.setContributors(parsePersons(eList)); } e = eEntry.getChild("id", getAtomNamespace()); if (e != null) { entry.setId(e.getText()); } e = eEntry.getChild("modified", getAtomNamespace()); if (e != null) { entry.setModified(DateParser.parseDate(e.getText())); } e = eEntry.getChild("issued", getAtomNamespace()); if (e != null) { entry.setIssued(DateParser.parseDate(e.getText())); } e = eEntry.getChild("created", getAtomNamespace()); if (e != null) { entry.setCreated(DateParser.parseDate(e.getText())); } e = eEntry.getChild("summary", getAtomNamespace()); if (e != null) { entry.setSummary(parseContent(e)); } eList = eEntry.getChildren("content", getAtomNamespace()); if (eList.size() > 0) { List content = new ArrayList(); for (int i = 0; i < eList.size(); i++) { content.add(parseContent((Element) eList.get(i))); } entry.setContents(content); } 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
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);/*from ww w . j a v a 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
private Person parsePerson(String baseURI, Element ePerson) { Person person = new Person(); Element e = ePerson.getChild("name", getAtomNamespace()); if (e != null) { person.setName(e.getText());//from w w w. ja v a2 s . com } e = ePerson.getChild("uri", getAtomNamespace()); if (e != null) { person.setUri(e.getText()); if (isRelativeURI(e.getText())) { person.setUriResolved(resolveURI(baseURI, ePerson, e.getText())); } } e = ePerson.getChild("email", getAtomNamespace()); if (e != null) { person.setEmail(e.getText()); } person.setModules(parsePersonModules(ePerson)); return person; }
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 ww. j ava 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.DCModuleParser.java
License:Open Source License
/** * Utility method to parse a taxonomy from an element. * <p>//w w w. j av a 2 s . c om * @param desc the taxonomy description element. * @return the string contained in the resource of the element. */ protected final String getTaxonomy(Element desc) { String d = null; Element taxo = desc.getChild("topic", getTaxonomyNamespace()); if (taxo != null) { Attribute a = taxo.getAttribute("resource", getRDFNamespace()); if (a != null) { d = a.getValue(); } } return d; }
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 va2 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 checkNotNullAndLength(Element parent, String childName, int minLen, int maxLen) throws FeedException { Element child = parent.getChild(childName, getFeedNamespace()); if (child == null) { throw new FeedException( "Invalid " + getType() + " feed, missing " + parent.getName() + " " + childName); }/*from ww w .j av a 2s .c o m*/ checkLength(parent, childName, minLen, maxLen); }
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 . j ava2 s.com*/ 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 .j av a 2s.com * 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
/** * This method exists because RSS0.90 and RSS1.0 have the 'image' element under the root elemment. * And RSS0.91, RSS0.02, RSS0.93, RSS0.94 and RSS2.0 have it under the 'channel' element. * <p/>/*from w w w . jav a 2 s . co m*/ */ protected Element getImage(Element rssRoot) { return rssRoot.getChild("image", getRSSNamespace()); }