List of usage examples for org.jdom2 Element getText
public String getText()
From source file:com.sangupta.jerry.util.DomUtils.java
License:Apache License
/** * Returns the value of the element with the given tagName amongst the * supplied foreign markup values.//from w w w . ja v a2s. c o m * * @param tagName * the tag name to look for * * @param elements * the elements to search in * * @return list of all values that match the tag name * */ public static List<String> getTagValues(String tagName, List<Element> elements) { List<String> values = new ArrayList<String>(); for (Element element : elements) { if (tagName.equals(element.getName())) { values.add(element.getText()); } } return values; }
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)); }/*from w ww . ja va 2s . c o 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()); }//ww w . j a v a2s . c o 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; }
From source file:com.sun.syndication.io.impl.Atom03Parser.java
License:Open Source License
private Content parseContent(Element e) { String value = null;//from w ww .ja va2s . c o m String type = getAttributeValue(e, "type"); type = (type != null) ? type : "text/plain"; String mode = getAttributeValue(e, "mode"); if (mode == null) { mode = Content.XML; // default to xml content } if (mode.equals(Content.ESCAPED)) { // do nothing XML Parser took care of this value = e.getText(); } else if (mode.equals(Content.BASE64)) { value = Base64.decode(e.getText()); } else if (mode.equals(Content.XML)) { XMLOutputter outputter = new XMLOutputter(); List eContent = e.getContent(); Iterator i = eContent.iterator(); while (i.hasNext()) { org.jdom2.Content c = (org.jdom2.Content) i.next(); if (c instanceof Element) { Element eC = (Element) c; if (eC.getNamespace().equals(getAtomNamespace())) { ((Element) c).setNamespace(Namespace.NO_NAMESPACE); } } } value = outputter.outputString(eContent); } Content content = new Content(); content.setType(type); content.setMode(mode); content.setValue(value); return content; }
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)); }//from w w w . java 2 s . com 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);//ww w .j a v a 2 s .com } 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 ww w . j ava 2s. c o m 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
private String parseTextConstructToString(Element e) { String value = null;/*from w w w. j a v a2 s . com*/ String type = getAttributeValue(e, "type"); type = (type != null) ? type : Content.TEXT; if (type.equals(Content.XHTML) || (type.indexOf("/xml")) != -1 || (type.indexOf("+xml")) != -1) { // XHTML content needs special handling XMLOutputter outputter = new XMLOutputter(); List eContent = e.getContent(); Iterator i = eContent.iterator(); while (i.hasNext()) { org.jdom2.Content c = (org.jdom2.Content) i.next(); if (c instanceof Element) { Element eC = (Element) c; if (eC.getNamespace().equals(getAtomNamespace())) { ((Element) c).setNamespace(Namespace.NO_NAMESPACE); } } } value = outputter.outputString(eContent); } else { // Everything else comes in verbatim value = e.getText(); } return value; }
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 . jav a2s . c o m*/ } 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 list of subjects out of a list of elements. * <p>// ww w. j a 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; }