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.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 ww w. j a va 2 s. c o m*/ } 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 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)); }// ww w . ja va 2 s . c om 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; }
From source file:com.rometools.rome.io.impl.Atom10Parser.java
License:Open Source License
private Feed parseFeedMetadata(final String baseURI, final Element eFeed, final Locale locale) { final com.rometools.rome.feed.atom.Feed feed = new com.rometools.rome.feed.atom.Feed(getType()); final Element title = eFeed.getChild("title", getAtomNamespace()); if (title != null) { final Content c = new Content(); c.setValue(parseTextConstructToString(title)); c.setType(getAttributeValue(title, "type")); feed.setTitleEx(c);/*from w ww.j a v a 2 s. co m*/ } final List<Element> links = eFeed.getChildren("link", getAtomNamespace()); feed.setAlternateLinks(parseAlternateLinks(feed, null, baseURI, links)); feed.setOtherLinks(parseOtherLinks(feed, null, baseURI, links)); final List<Element> categories = eFeed.getChildren("category", getAtomNamespace()); feed.setCategories(parseCategories(baseURI, categories)); final List<Element> authors = eFeed.getChildren("author", getAtomNamespace()); if (!authors.isEmpty()) { feed.setAuthors(parsePersons(baseURI, authors, locale)); } final List<Element> contributors = eFeed.getChildren("contributor", getAtomNamespace()); if (!contributors.isEmpty()) { feed.setContributors(parsePersons(baseURI, contributors, locale)); } final Element subtitle = eFeed.getChild("subtitle", getAtomNamespace()); if (subtitle != null) { final Content content = new Content(); content.setValue(parseTextConstructToString(subtitle)); content.setType(getAttributeValue(subtitle, "type")); feed.setSubtitle(content); } 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()); final String uri = getAttributeValue(generator, "uri"); if (uri != null) { gen.setUrl(uri); } final String version = getAttributeValue(generator, "version"); if (version != null) { gen.setVersion(version); } feed.setGenerator(gen); } final Element rights = eFeed.getChild("rights", getAtomNamespace()); if (rights != null) { feed.setRights(parseTextConstructToString(rights)); } final Element icon = eFeed.getChild("icon", getAtomNamespace()); if (icon != null) { feed.setIcon(icon.getText()); } final Element logo = eFeed.getChild("logo", getAtomNamespace()); if (logo != null) { feed.setLogo(logo.getText()); } final Element updated = eFeed.getChild("updated", getAtomNamespace()); if (updated != null) { feed.setUpdated(DateParser.parseDate(updated.getText(), locale)); } return feed; }
From source file:com.rometools.rome.io.impl.Atom10Parser.java
License:Open Source License
private Person parsePerson(final String baseURI, final Element ePerson, final Locale locale) { final Person person = new Person(); final Element name = ePerson.getChild("name", getAtomNamespace()); if (name != null) { person.setName(name.getText());/*w w w . ja va2s. co m*/ } final Element uri = ePerson.getChild("uri", getAtomNamespace()); if (uri != null) { person.setUri(uri.getText()); if (isRelativeURI(uri.getText())) { person.setUriResolved(resolveURI(baseURI, ePerson, uri.getText())); } } final Element email = ePerson.getChild("email", getAtomNamespace()); if (email != null) { person.setEmail(email.getText()); } person.setModules(parsePersonModules(ePerson, locale)); return person; }
From source file:com.rometools.rome.io.impl.Atom10Parser.java
License:Open Source License
protected Entry parseEntry(final Feed feed, final Element eEntry, final String baseURI, final Locale locale) { final Entry entry = new Entry(); final String xmlBase = eEntry.getAttributeValue("base", Namespace.XML_NAMESPACE); if (xmlBase != null) { entry.setXmlBase(xmlBase);// w w w . j a va 2s. co m } final Element title = eEntry.getChild("title", getAtomNamespace()); if (title != null) { final Content c = new Content(); c.setValue(parseTextConstructToString(title)); c.setType(getAttributeValue(title, "type")); entry.setTitleEx(c); } final List<Element> links = eEntry.getChildren("link", getAtomNamespace()); entry.setAlternateLinks(parseAlternateLinks(feed, entry, baseURI, links)); entry.setOtherLinks(parseOtherLinks(feed, entry, baseURI, links)); final List<Element> authors = eEntry.getChildren("author", getAtomNamespace()); if (!authors.isEmpty()) { entry.setAuthors(parsePersons(baseURI, authors, locale)); } final List<Element> contributors = eEntry.getChildren("contributor", getAtomNamespace()); if (!contributors.isEmpty()) { entry.setContributors(parsePersons(baseURI, contributors, locale)); } final Element id = eEntry.getChild("id", getAtomNamespace()); if (id != null) { entry.setId(id.getText()); } final Element updated = eEntry.getChild("updated", getAtomNamespace()); if (updated != null) { entry.setUpdated(DateParser.parseDate(updated.getText(), locale)); } final Element published = eEntry.getChild("published", getAtomNamespace()); if (published != null) { entry.setPublished(DateParser.parseDate(published.getText(), locale)); } final Element summary = eEntry.getChild("summary", getAtomNamespace()); if (summary != null) { entry.setSummary(parseContent(summary)); } final Element content = eEntry.getChild("content", getAtomNamespace()); if (content != null) { final List<Content> contents = new ArrayList<Content>(); contents.add(parseContent(content)); entry.setContents(contents); } final Element rights = eEntry.getChild("rights", getAtomNamespace()); if (rights != null) { entry.setRights(rights.getText()); } final List<Element> categories = eEntry.getChildren("category", getAtomNamespace()); entry.setCategories(parseCategories(baseURI, categories)); // TODO: SHOULD handle Atom entry source element final Element source = eEntry.getChild("source", getAtomNamespace()); if (source != null) { entry.setSource(parseFeedMetadata(baseURI, source, locale)); } entry.setModules(parseItemModules(eEntry, locale)); final List<Element> foreignMarkup = extractForeignMarkup(eEntry, entry, getAtomNamespace()); if (!foreignMarkup.isEmpty()) { entry.setForeignMarkup(foreignMarkup); } return entry; }
From source file:com.rometools.rome.io.impl.CBModuleParser.java
License:Apache License
/** * Parse an element tree and return the module found in it. * <p>/*from www.j a v a 2 s .c om*/ * * @param cbRoot the root element containing the module elements. * @param locale for date/time parsing * @return the module parsed from the element tree, <i>null</i> if none. */ @Override public Module parse(final Element cbRoot, final Locale locale) { boolean foundSomething = false; final CBModule cbm = new CBModuleImpl(); final Element event = cbRoot.getChild("event", getCBNamespace()); if (event != null) { foundSomething = true; cbm.setEvent(parseEvent(event)); } final Element news = cbRoot.getChild("news", getCBNamespace()); if (news != null) { foundSomething = true; cbm.setNews(parseNews(news)); } final Element paper = cbRoot.getChild("paper", getCBNamespace()); if (paper != null) { foundSomething = true; cbm.setPaper(parsePaper(paper)); } final Element speech = cbRoot.getChild("speech", getCBNamespace()); if (speech != null) { foundSomething = true; cbm.setSpeech(parseSpeech(speech)); } final Element statistics = cbRoot.getChild("statistics", getCBNamespace()); if (statistics != null) { foundSomething = true; cbm.setStatistics(parseStatistics(statistics)); } if (foundSomething) { return cbm; } else { return null; } }
From source file:com.rometools.rome.io.impl.CBModuleParser.java
License:Apache License
/** * Utility method to parse a statistics. * <p>/*w ww. j a va2s . c o m*/ * * @param the element to parse. * @return statistics parsed from the element. */ protected final CBStatistics parseStatistics(final Element element) { final CBStatistics statistics = new CBStatisticsImpl(); final Element institutionAbbrev = element.getChild("institutionAbbrev", getCBNamespace()); if (institutionAbbrev != null) { statistics.setInstitutionAbbrev(institutionAbbrev.getText()); } final Element country = element.getChild("country", getCBNamespace()); if (country != null) { statistics.setLocationCountry(ISO3166CountyCode.fromValue(country.getText())); } final Element exchangeRate = element.getChild("exchangeRate", getCBNamespace()); if (exchangeRate != null) { statistics.setExchangeRate(parseExchangeRate(exchangeRate)); } final Element interestRate = element.getChild("interestRate", getCBNamespace()); if (interestRate != null) { statistics.setInterestRate(parseInterestRate(interestRate)); } final Element transaction = element.getChild("transaction", getCBNamespace()); if (transaction != null) { statistics.setTransaction(parseTransaction(transaction)); } final Element otherStatistic = element.getChild("otherStatistic", getCBNamespace()); if (otherStatistic != null) { statistics.setOtherStatistic(parseOtherStatistic(otherStatistic)); } return statistics; }
From source file:com.rometools.rome.io.impl.CBModuleParser.java
License:Apache License
/** * Utility method to parse a exchangeRate. * <p>// w ww . j a va 2s . c om * * @param the element to parse. * @return exchangeRate parsed from the element. */ protected final CBExchangeRate parseExchangeRate(final Element element) { final CBExchangeRate exchangeRate = new CBExchangeRateImpl(); final Element observation = element.getChild("observation", getCBNamespace()); if (observation != null) { exchangeRate.setObservation(parseObservation(observation)); } final Element baseCurrency = element.getChild("baseCurrency", getCBNamespace()); if (baseCurrency != null) { exchangeRate.setBaseCurrency(baseCurrency.getText()); } final Element targetCurrency = element.getChild("targetCurrency", getCBNamespace()); if (targetCurrency != null) { exchangeRate.setTargetCurrency(targetCurrency.getText()); } final Element rateType = element.getChild("rateType", getCBNamespace()); if (rateType != null) { exchangeRate.setRateType(rateType.getText()); } final Element observationPeriod = element.getChild("observationPeriod", getCBNamespace()); if (observationPeriod != null) { exchangeRate.setObservationPeriod(parseObservationPeriod(observationPeriod)); } return exchangeRate; }
From source file:com.rometools.rome.io.impl.CBModuleParser.java
License:Apache License
/** * Utility method to parse a interestRate. * <p>// w ww . j ava2 s.com * * @param the element to parse. * @return interestRate parsed from the element. */ protected final CBInterestRate parseInterestRate(final Element element) { final CBInterestRate interestRate = new CBInterestRateImpl(); final Element observation = element.getChild("observation", getCBNamespace()); if (observation != null) { interestRate.setObservation(parseObservation(observation)); } final Element rateName = element.getChild("rateName", getCBNamespace()); if (rateName != null) { interestRate.setRateName(rateName.getText()); } final Element rateType = element.getChild("rateType", getCBNamespace()); if (rateType != null) { interestRate.setRateType(rateType.getText()); } final Element observationPeriod = element.getChild("observationPeriod", getCBNamespace()); if (observationPeriod != null) { interestRate.setObservationPeriod(parseObservationPeriod(observationPeriod)); } return interestRate; }
From source file:com.rometools.rome.io.impl.CBModuleParser.java
License:Apache License
/** * Utility method to parse a transaction. * <p>/* w w w. ja v a 2 s .c o m*/ * * @param the element to parse. * @return transaction parsed from the element. */ protected final CBTransaction parseTransaction(final Element element) { final CBTransaction transaction = new CBTransactionImpl(); final Element observation = element.getChild("observation", getCBNamespace()); if (observation != null) { transaction.setObservation(parseObservation(observation)); } final Element transactionName = element.getChild("transactionName", getCBNamespace()); if (transactionName != null) { transaction.setTransactionName(transactionName.getText()); } final Element transactionType = element.getChild("transactionType", getCBNamespace()); if (transactionType != null) { transaction.setTransactionType(transactionType.getText()); } final Element observationPeriod = element.getChild("observationPeriod", getCBNamespace()); if (observationPeriod != null) { transaction.setObservationPeriod(parseObservationPeriod(observationPeriod)); } final Element transactionTerm = element.getChild("transactionTerm", getCBNamespace()); if (transactionTerm != null) { transaction.setTransactionTerm(transactionTerm.getText()); } return transaction; }