Example usage for org.apache.commons.lang3 StringUtils trimToNull

List of usage examples for org.apache.commons.lang3 StringUtils trimToNull

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils trimToNull.

Prototype

public static String trimToNull(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null .

Usage

From source file:org.openestate.io.examples.CasaItReadingExample.java

/**
 * Print some content of a {@link CasaItDocument} to console.
 *
 * @param doc/* www.j  a va  2s  . c  o  m*/
 * the document to process
 *
 * @throws JAXBException
 * if XML conversion into Java objects failed
 */
protected static void printToConsole(CasaItDocument doc) throws JAXBException {
    Container container = doc.toObject();

    // process real estates
    if (container.getRealestateitems() != null) {
        for (Container.Realestateitems.Realestate obj : container.getRealestateitems().getRealestate()) {
            // get object nr
            String objectNr = StringUtils.trimToNull(obj.getReference());
            if (objectNr == null)
                objectNr = "???";

            // get object title
            String objectTitle = (obj.getDescription() != null)
                    ? StringUtils.trimToNull(obj.getDescription().getValue())
                    : null;
            if (objectTitle == null)
                objectTitle = "???";

            // print object informations to console
            LOGGER.info("> found object '" + objectNr + "' " + "with title '" + objectTitle + "'");
        }
    }
}

From source file:org.openestate.io.examples.DaftIeReadingExample.java

/**
 * Print some content of a {@link DaftIeDocument} to console.
 *
 * @param doc/*  w ww .ja va  2s. com*/
 * the document to process
 *
 * @throws JAXBException
 * if XML conversion into Java objects failed
 */
protected static void printToConsole(DaftIeDocument doc) throws JAXBException {
    LOGGER.info("> process document in version " + doc.getDocumentVersion());

    Daft daft = doc.toObject();

    // process overseas rental
    if (daft.getOverseasRental() != null) {
        for (OverseasRentalAdType ad : daft.getOverseasRental().getOverseasRentalAd()) {
            // get object nr
            String objectNr = StringUtils.trimToNull(ad.getExternalId());
            if (objectNr == null)
                objectNr = "???";

            // get object description
            String objectInfo = StringUtils.trimToNull(ad.getDescription());
            if (objectInfo == null)
                objectInfo = "???";

            // print object informations to console
            LOGGER.info("> found object " + "'" + objectNr + "' for rent: " + objectInfo);
        }
    }

    // process overseas sales
    if (daft.getOverseasSales() != null) {
        for (OverseasSaleAdType ad : daft.getOverseasSales().getOverseasSaleAd()) {
            // get object nr
            String objectNr = StringUtils.trimToNull(ad.getExternalId());
            if (objectNr == null)
                objectNr = "???";

            // get object description
            String objectInfo = StringUtils.trimToNull(ad.getDescription());
            if (objectInfo == null)
                objectInfo = "???";

            // print object informations to console
            LOGGER.info("> found object " + "'" + objectNr + "' for sale: " + objectInfo);
        }
    }
}

From source file:org.openestate.io.examples.ImmobiliareItReadingExample.java

/**
 * Print some content of an {@link ImmobiliareItDocument} to console.
 *
 * @param doc//from  w  ww  .ja va 2  s  .c  om
 * the document to process
 *
 * @throws JAXBException
 * if XML conversion into Java objects failed
 */
protected static void printToConsole(ImmobiliareItDocument doc) throws JAXBException {
    LOGGER.info("> process document in version " + doc.getDocumentVersion());

    Feed feed = doc.toObject();

    // process properties
    if (feed.getProperties() != null) {
        for (Property object : feed.getProperties().getProperty()) {
            // get object nr
            String objectNr = StringUtils.trimToNull(object.getUniqueId());
            if (objectNr == null)
                objectNr = "???";

            // get object description
            String objectInfo = (object.getFeatures() != null
                    && !object.getFeatures().getDescription().isEmpty())
                            ? StringUtils.trimToNull(object.getFeatures().getDescription().get(0).getValue())
                            : null;
            if (objectInfo == null)
                objectInfo = "???";

            // print object informations to console
            LOGGER.info("> found object " + "'" + objectNr + "': " + objectInfo);
        }
    }
}

From source file:org.openestate.io.examples.KyeroReadingExample.java

/**
 * Print some content of a {@link KyeroDocument} to console.
 *
 * @param doc/*from  w w  w  .jav  a 2  s  .  c o  m*/
 * the document to process
 *
 * @throws JAXBException
 * if XML conversion into Java objects failed
 */
protected static void printToConsole(KyeroDocument doc) throws JAXBException {
    Root root = doc.toObject();

    // process properties in the document
    for (PropertyType obj : root.getProperty()) {
        // get object nr
        String objectNr = (obj.getId() != null) ? obj.getId() : "???";

        // get object description
        String objectInfo = null;
        if (obj.getDesc() != null) {
            objectInfo = StringUtils.trimToNull(obj.getDesc().getEn());
            if (objectInfo == null)
                objectInfo = StringUtils.trimToNull(obj.getDesc().getDe());
            if (objectInfo == null)
                objectInfo = StringUtils.trimToNull(obj.getDesc().getEs());
        }

        // print object informations to console
        LOGGER.info("> found object '" + objectNr + "' " + "with title '" + objectInfo + "'");
    }
}

From source file:org.openestate.io.examples.TrovitReadingExample.java

/**
 * Print some content of a {@link TrovitDocument} to console.
 *
 * @param doc//from www.  j  a v  a2s  . c  o  m
 * the document to process
 *
 * @throws JAXBException
 * if XML conversion into Java objects failed
 */
protected static void printToConsole(TrovitDocument doc) throws JAXBException {
    Trovit trovit = doc.toObject();

    // process ads
    for (Ad ad : trovit.getAd()) {
        // get object nr
        String objectNr = StringUtils.trimToNull(ad.getId());
        if (objectNr == null)
            objectNr = "???";

        // get object title
        String objectTitle = StringUtils.trimToNull(ad.getTitle());
        if (objectTitle == null)
            objectTitle = "???";

        // print object informations to console
        LOGGER.info("> found object '" + objectNr + "' " + "with title '" + objectTitle + "'");
    }
}

From source file:org.openestate.io.examples.WisItReadingExample.java

/**
 * Print some content of a {@link WisItDocument} to console.
 *
 * @param doc/*from   ww  w.j  av a  2s. c o m*/
 * the document to process
 *
 * @throws JAXBException
 * if XML conversion into Java objects failed
 */
protected static void printToConsole(WisItDocument doc) throws JAXBException {
    WIS wis = doc.toObject();

    // process objects
    if (wis.getOBJEKTE() != null) {
        for (ObjectType obj : wis.getOBJEKTE().getOBJEKT()) {
            // get object nr
            String objectNr = StringUtils.trimToNull(obj.getID());
            if (objectNr == null)
                objectNr = "???";

            // get object description
            String objectInfo = StringUtils.trimToNull(obj.getINFODE());
            if (objectInfo == null)
                objectInfo = obj.getINFOIT();
            if (objectInfo == null)
                objectInfo = "???";

            // print object informations to console
            LOGGER.info("> found object '" + objectNr + "' " + "with title '" + objectInfo + "'");
        }
    }
}

From source file:org.openestate.io.filemaker.FilemakerUtils.java

public static Boolean parseBoolean(String value) {
    value = StringUtils.trimToNull(value);
    if ("yes".equalsIgnoreCase(value))
        return true;
    if ("no".equalsIgnoreCase(value))
        return false;
    return null;/*www .ja v a 2 s.co m*/
}

From source file:org.openestate.io.idx.IdxFormat.java

@SuppressFBWarnings(value = "NP_BOOLEAN_RETURN_NULL", justification = "This behaviour is intended.")
public static Boolean parseBoolean(String value) {
    value = StringUtils.trimToNull(value);
    if ("1".equalsIgnoreCase(value) || "Y".equalsIgnoreCase(value))
        return true;
    else if ("0".equalsIgnoreCase(value) || "N".equalsIgnoreCase(value))
        return false;
    else/*from  w w  w  .j av  a 2  s.c om*/
        return null;
}

From source file:org.openestate.io.idx.IdxFormat.java

public static Date parseDate(String value) throws ParseException {
    value = StringUtils.trimToNull(value);
    return (value != null) ? getDateFormat().parse(value) : null;
}

From source file:org.openestate.io.idx.IdxFormat.java

public static Date parseDateTime(String value) throws ParseException {
    value = StringUtils.trimToNull(value);
    return (value != null) ? getDateTimeFormat().parse(value) : null;
}