Example usage for org.jdom2 Element getText

List of usage examples for org.jdom2 Element getText

Introduction

In this page you can find the example usage for org.jdom2 Element getText.

Prototype

public String getText() 

Source Link

Document

Returns the textual content directly held under this element as a string.

Usage

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);//w w w. ja v  a2s  . c o 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());
    }/*ww w  . j a  v  a  2  s.c om*/

    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

private String parseTextConstructToString(final Element e) {

    String type = getAttributeValue(e, "type");
    if (type == null) {
        type = Content.TEXT;/*from w ww .j ava2s  . c om*/
    }

    String value = null;
    if (type.equals(Content.XHTML) || type.indexOf("/xml") != -1 || type.indexOf("+xml") != -1) {
        // XHTML content needs special handling
        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);
    } else {
        // Everything else comes in verbatim
        value = e.getText();
    }

    return value;

}

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);//from   ww w.  j  a va2  s  . c o 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

/**
 * Utility method to parse a statistics.
 * <p>//from   w  w  w . j  a va 2 s  . com
 *
 * @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>// ww  w.  jav  a2 s.c  o m
 *
 * @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>/*from  www.ja v  a  2s.  co  m*/
 *
 * @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>/*from   ww w  .  j av 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;
}

From source file:com.rometools.rome.io.impl.CBModuleParser.java

License:Apache License

/**
 * Utility method to parse a otherStatistic.
 * <p>/*from  w  w  w  .  j av a 2s .  c o  m*/
 *
 * @param the element to parse.
 * @return otherStatistic parsed from the element.
 */
protected final CBOtherStatistics parseOtherStatistic(final Element element) {
    final CBOtherStatistics otherStatistic = new CBOtherStatisticsImpl();

    final Element observation = element.getChild("observation", getCBNamespace());
    if (observation != null) {
        otherStatistic.setObservation(parseObservation(observation));
    }

    final Element topic = element.getChild("topic", getCBNamespace());
    if (topic != null) {
        otherStatistic.setTopic(topic.getText());
    }

    final Element coverage = element.getChild("coverage", getCBNamespace());
    if (coverage != null) {
        otherStatistic.setCoverage(coverage.getText());
    }

    final Element dataType = element.getChild("dataType", getCBNamespace());
    if (dataType != null) {
        otherStatistic.setDataType(dataType.getText());
    }

    final Element observationPeriod = element.getChild("observationPeriod", getCBNamespace());
    if (observationPeriod != null) {
        otherStatistic.setObservationPeriod(parseObservationPeriod(observationPeriod));
    }

    return otherStatistic;
}

From source file:com.rometools.rome.io.impl.CBModuleParser.java

License:Apache License

/**
 * Utility method to parse a observationPeriod.
 * <p>/*w  w w. j a v a2  s  .com*/
 *
 * @param the element to parse.
 * @return observationPeriod parsed from the element.
 */
protected final CBObservationPeriod parseObservationPeriod(final Element element) {
    final CBObservationPeriod observationPeriod = new CBObservationPeriodImpl();

    final Element frequency = element.getChild("frequency", getCBNamespace());
    if (frequency != null) {
        observationPeriod.setFrequency(frequency.getText());
    }

    final Element period = element.getChild("period", getCBNamespace());
    if (period != null) {
        observationPeriod.setPeriod(period.getText());
    }

    return observationPeriod;
}