List of usage examples for org.jdom2 Element getText
public String getText()
From source file:com.rometools.modules.sle.io.ModuleParser.java
License:Apache License
public void insertValues(final SimpleListExtension sle, final List<Element> elements) { for (int i = 0; elements != null && i < elements.size(); i++) { final Element e = elements.get(i); final Group[] groups = sle.getGroupFields(); for (final Group group2 : groups) { final Element value = e.getChild(group2.getElement(), group2.getNamespace()); if (value == null) { continue; }//from w w w. jav a2s . c o m final Element group = new Element("group", TEMP); addNotNullAttribute(group, "element", group2.getElement()); addNotNullAttribute(group, "label", group2.getLabel()); addNotNullAttribute(group, "value", value.getText()); addNotNullAttribute(group, "ns", group2.getNamespace().getURI()); e.addContent(group); } final Sort[] sorts = sle.getSortFields(); for (final Sort sort2 : sorts) { LOG.debug("Inserting for {} {}", sort2.getElement(), sort2.getDataType()); final Element sort = new Element("sort", TEMP); // this is the default sort order, so I am just going to ignore // the actual values and add a number type. It really shouldn't // work this way. I should be checking to see if any of the elements // defined have a value then use that value. This will preserve the // sort order, however, if anyone is using the SleEntry to display // the value of the field, it will not give the correct value. // This, however, would require knowledge in the item parser that I don't // have right now. if (sort2.getDefaultOrder()) { sort.setAttribute("label", sort2.getLabel()); sort.setAttribute("value", Integer.toString(i)); sort.setAttribute("data-type", Sort.NUMBER_TYPE); e.addContent(sort); continue; } // LOG.debug(e.getName()); final Element value = e.getChild(sort2.getElement(), sort2.getNamespace()); if (value == null) { LOG.debug("No value for {} : {}", sort2.getElement(), sort2.getNamespace()); } else { LOG.debug("{} value: {}", sort2.getElement(), value.getText()); } if (value == null) { continue; } addNotNullAttribute(sort, "label", sort2.getLabel()); addNotNullAttribute(sort, "element", sort2.getElement()); addNotNullAttribute(sort, "value", value.getText()); addNotNullAttribute(sort, "data-type", sort2.getDataType()); addNotNullAttribute(sort, "ns", sort2.getNamespace().getURI()); e.addContent(sort); LOG.debug("Added {} {} = {}", sort, sort2.getLabel(), value.getText()); } } }
From source file:com.rometools.propono.atom.client.ClientCollection.java
License:Open Source License
@Override protected void parseCollectionElement(final Element element) throws ProponoException { if (workspace == null) { return;//from ww w. j av a2 s.com } setHref(element.getAttribute("href").getValue()); final Element titleElem = element.getChild("title", AtomService.ATOM_FORMAT); if (titleElem != null) { setTitle(titleElem.getText()); if (titleElem.getAttribute("type", AtomService.ATOM_FORMAT) != null) { setTitleType(titleElem.getAttribute("type", AtomService.ATOM_FORMAT).getValue()); } } final List<Element> acceptElems = element.getChildren("accept", AtomService.ATOM_PROTOCOL); if (acceptElems != null && !acceptElems.isEmpty()) { for (final Element acceptElem : acceptElems) { addAccept(acceptElem.getTextTrim()); } } // Loop to parse <app:categories> element to Categories objects final List<Element> catsElems = element.getChildren("categories", AtomService.ATOM_PROTOCOL); for (final Element catsElem : catsElems) { final Categories cats = new ClientCategories(catsElem, this); addCategories(cats); } }
From source file:com.rometools.propono.atom.client.ClientWorkspace.java
License:Open Source License
/** Deserialize a Atom workspace XML element into an object */ protected void parseWorkspaceElement(final Element element, final String baseURI) throws ProponoException { final Element titleElem = element.getChild("title", AtomService.ATOM_FORMAT); setTitle(titleElem.getText()); if (titleElem.getAttribute("type", AtomService.ATOM_FORMAT) != null) { setTitleType(titleElem.getAttribute("type", AtomService.ATOM_FORMAT).getValue()); }//w ww . j a va2 s.co m final List<Element> collections = element.getChildren("collection", AtomService.ATOM_PROTOCOL); for (final Element e : collections) { addCollection(new ClientCollection(e, this, baseURI)); } }
From source file:com.rometools.propono.atom.common.Collection.java
License:Apache License
protected void parseCollectionElement(final Element element) throws ProponoException { setHref(element.getAttribute("href").getValue()); final Element titleElem = element.getChild("title", AtomService.ATOM_FORMAT); if (titleElem != null) { setTitle(titleElem.getText()); if (titleElem.getAttribute("type", AtomService.ATOM_FORMAT) != null) { setTitleType(titleElem.getAttribute("type", AtomService.ATOM_FORMAT).getValue()); }/*ww w .j a va 2 s .c o m*/ } final List<Element> acceptElems = element.getChildren("accept", AtomService.ATOM_PROTOCOL); if (acceptElems != null && !acceptElems.isEmpty()) { for (final Element acceptElem : acceptElems) { addAccept(acceptElem.getTextTrim()); } } // Loop to parse <app:categories> element to Categories objects final List<Element> catsElems = element.getChildren("categories", AtomService.ATOM_PROTOCOL); for (final Element catsElem : catsElems) { final Categories cats = new Categories(catsElem, baseURI); addCategories(cats); } }
From source file:com.rometools.propono.atom.common.rome.AppModuleParser.java
License:Apache License
/** Parse JDOM element into module */ @Override//from www.j a va 2s . c o m public Module parse(final Element elem, final Locale locale) { final AppModule m = new AppModuleImpl(); final Element control = elem.getChild("control", getContentNamespace()); if (control != null) { final Element draftElem = control.getChild("draft", getContentNamespace()); if (draftElem != null) { if ("yes".equals(draftElem.getText())) { m.setDraft(Boolean.TRUE); } if ("no".equals(draftElem.getText())) { m.setDraft(Boolean.FALSE); } } } final Element edited = elem.getChild("edited", getContentNamespace()); if (edited != null) { try { m.setEdited(DateParser.parseW3CDateTime(edited.getTextTrim(), locale)); } catch (final Exception ignored) { } } return m; }
From source file:com.rometools.propono.atom.common.Workspace.java
License:Apache License
/** Deserialize a Atom workspace XML element into an object */ protected void parseWorkspaceElement(final Element element) throws ProponoException { final Element titleElem = element.getChild("title", AtomService.ATOM_FORMAT); setTitle(titleElem.getText()); if (titleElem.getAttribute("type", AtomService.ATOM_FORMAT) != null) { setTitleType(titleElem.getAttribute("type", AtomService.ATOM_FORMAT).getValue()); }/*from w w w. j ava2 s.co m*/ final List<Element> collections = element.getChildren("collection", AtomService.ATOM_PROTOCOL); for (final Element e : collections) { addCollection(new Collection(e)); } }
From source file:com.rometools.rome.io.impl.Atom03Parser.java
License:Open Source License
protected WireFeed parseFeed(final Element eFeed, final Locale locale) { final String type = getType(); final Document document = eFeed.getDocument(); final String styleSheet = getStyleSheet(document); final Feed feed = new Feed(type); feed.setStyleSheet(styleSheet);/* w ww. j av a 2s .c o m*/ final Element title = eFeed.getChild("title", getAtomNamespace()); if (title != null) { feed.setTitleEx(parseContent(title)); } final List<Element> links = eFeed.getChildren("link", getAtomNamespace()); feed.setAlternateLinks(parseAlternateLinks(links)); feed.setOtherLinks(parseOtherLinks(links)); final Element author = eFeed.getChild("author", getAtomNamespace()); if (author != null) { final List<SyndPerson> authors = new ArrayList<SyndPerson>(); authors.add(parsePerson(author)); feed.setAuthors(authors); } final List<Element> contributors = eFeed.getChildren("contributor", getAtomNamespace()); if (!contributors.isEmpty()) { feed.setContributors(parsePersons(contributors)); } final Element tagline = eFeed.getChild("tagline", getAtomNamespace()); if (tagline != null) { feed.setTagline(parseContent(tagline)); } final Element id = eFeed.getChild("id", getAtomNamespace()); if (id != null) { feed.setId(id.getText()); } final Element generator = eFeed.getChild("generator", getAtomNamespace()); if (generator != null) { final Generator gen = new Generator(); gen.setValue(generator.getText()); String att = getAttributeValue(generator, "url"); if (att != null) { gen.setUrl(att); } att = getAttributeValue(generator, "version"); if (att != null) { gen.setVersion(att); } feed.setGenerator(gen); } final Element copyright = eFeed.getChild("copyright", getAtomNamespace()); if (copyright != null) { feed.setCopyright(copyright.getText()); } final Element info = eFeed.getChild("info", getAtomNamespace()); if (info != null) { feed.setInfo(parseContent(info)); } final Element modified = eFeed.getChild("modified", getAtomNamespace()); if (modified != null) { feed.setModified(DateParser.parseDate(modified.getText(), locale)); } feed.setModules(parseFeedModules(eFeed, locale)); final List<Element> entries = eFeed.getChildren("entry", getAtomNamespace()); if (!entries.isEmpty()) { feed.setEntries(parseEntries(entries, locale)); } final List<Element> foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace()); if (!foreignMarkup.isEmpty()) { feed.setForeignMarkup(foreignMarkup); } return feed; }
From source file:com.rometools.rome.io.impl.Atom03Parser.java
License:Open Source License
private Person parsePerson(final Element ePerson) { final Person person = new Person(); final Element name = ePerson.getChild("name", getAtomNamespace()); if (name != null) { person.setName(name.getText()); }/*from w w w . jav a 2 s .c om*/ final Element url = ePerson.getChild("url", getAtomNamespace()); if (url != null) { person.setUrl(url.getText()); } final Element email = ePerson.getChild("email", getAtomNamespace()); if (email != null) { person.setEmail(email.getText()); } return person; }
From source file:com.rometools.rome.io.impl.Atom03Parser.java
License:Open Source License
private Content parseContent(final Element e) { String value = null;/*w w w .j a va 2s.c o m*/ String type = getAttributeValue(e, "type"); if (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)) { final XMLOutputter outputter = new XMLOutputter(); final List<org.jdom2.Content> contents = e.getContent(); for (final org.jdom2.Content content : contents) { if (content instanceof Element) { final Element element = (Element) content; if (element.getNamespace().equals(getAtomNamespace())) { element.setNamespace(Namespace.NO_NAMESPACE); } } } value = outputter.outputString(contents); } final Content content = new Content(); content.setType(type); content.setMode(mode); content.setValue(value); return content; }
From source file:com.rometools.rome.io.impl.Atom03Parser.java
License:Open Source License
private Entry parseEntry(final Element eEntry, final Locale locale) { final Entry entry = new Entry(); final Element title = eEntry.getChild("title", getAtomNamespace()); if (title != null) { entry.setTitleEx(parseContent(title)); }//w w w. j a v a 2 s. co m final List<Element> links = eEntry.getChildren("link", getAtomNamespace()); entry.setAlternateLinks(parseAlternateLinks(links)); entry.setOtherLinks(parseOtherLinks(links)); final Element author = eEntry.getChild("author", getAtomNamespace()); if (author != null) { final List<SyndPerson> authors = new ArrayList<SyndPerson>(); authors.add(parsePerson(author)); entry.setAuthors(authors); } final List<Element> contributors = eEntry.getChildren("contributor", getAtomNamespace()); if (!contributors.isEmpty()) { entry.setContributors(parsePersons(contributors)); } final Element id = eEntry.getChild("id", getAtomNamespace()); if (id != null) { entry.setId(id.getText()); } final Element modified = eEntry.getChild("modified", getAtomNamespace()); if (modified != null) { entry.setModified(DateParser.parseDate(modified.getText(), locale)); } final Element issued = eEntry.getChild("issued", getAtomNamespace()); if (issued != null) { entry.setIssued(DateParser.parseDate(issued.getText(), locale)); } final Element created = eEntry.getChild("created", getAtomNamespace()); if (created != null) { entry.setCreated(DateParser.parseDate(created.getText(), locale)); } final Element summary = eEntry.getChild("summary", getAtomNamespace()); if (summary != null) { entry.setSummary(parseContent(summary)); } final List<Element> contents = eEntry.getChildren("content", getAtomNamespace()); if (!contents.isEmpty()) { final List<Content> content = new ArrayList<Content>(); for (final Element eContent : contents) { content.add(parseContent(eContent)); } entry.setContents(content); } entry.setModules(parseItemModules(eEntry, locale)); final List<Element> foreignMarkup = extractForeignMarkup(eEntry, entry, getAtomNamespace()); if (!foreignMarkup.isEmpty()) { entry.setForeignMarkup(foreignMarkup); } return entry; }