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.immobiliare_it.ImmobiliareItUtils.java

public static SizeUnit parseSizeUnit(String value) {
    value = StringUtils.trimToNull(value);
    if (value == null)
        return null;

    SizeUnit unit = SizeUnit.fromXmlValue(value);
    if (unit == null)
        throw new IllegalArgumentException("Can't parse size-unit value '" + value + "'!");

    return unit;/*w  w w.  j a  v  a  2s . c om*/
}

From source file:org.openestate.io.immobiliare_it.ImmobiliareItUtils.java

private static String parseText(String value, int length) {
    return StringUtils.trimToNull(value);
}

From source file:org.openestate.io.immobiliare_it.ImmobiliareItUtils.java

public static Transaction parseTransaction(String value) {
    value = StringUtils.trimToNull(value);
    if (value == null)
        return null;

    Transaction unit = Transaction.fromXmlValue(value);
    if (unit == null)
        throw new IllegalArgumentException("Can't parse transaction value '" + value + "'!");

    return unit;//from www.  ja va 2s . c o  m
}

From source file:org.openestate.io.immobiliare_it.ImmobiliareItUtils.java

public static Integer parseYear(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseInt(value) : null;
}

From source file:org.openestate.io.immobiliare_it.ImmobiliareItUtils.java

public static String printCountry(String value) {
    value = StringUtils.trimToNull(value);
    if (value == null)
        throw new IllegalArgumentException("Can't print country value!");

    String iso2 = StringUtils.trimToNull(ImmobiliareItUtils.getCountryCode(value));
    if (iso2 == null)
        throw new IllegalArgumentException("Can't convert country '" + value + "' to its ISO2 code!");
    else//  ww  w . jav a  2  s  .  c  o m
        return iso2;
}

From source file:org.openestate.io.immoxml.ImmoXmlDocument.java

@Override
public ImmoXmlVersion getDocumentVersion() {
    String version;/*from w  w  w .j a va  2s . c o  m*/
    try {
        Document doc = this.getDocument();
        version = StringUtils
                .trimToNull(XmlUtils.newXPath("/io:immoxml/io:uebertragung/@version", doc).stringValueOf(doc));
        if (version == null) {
            LOGGER.warn("Can't find version informations in the XML document!");
            //System.out.println( "----------------------------" );
            //try
            //{
            //  DocumentUtils.write( doc, System.out );
            //}
            //catch (Exception ex)
            //{
            //  LOGGER.error( "Can't write XML document!" );
            //  LOGGER.error( "> " + ex.getLocalizedMessage(), ex );
            //}
            //System.out.println( "----------------------------" );
            return null;
        }
    } catch (JaxenException ex) {
        LOGGER.error("Can't evaluate XPath expression!");
        LOGGER.error("> " + ex.getLocalizedMessage(), ex);
        return null;
    }

    ImmoXmlVersion v = ImmoXmlVersion.detectFromString(version);
    if (v != null)
        return v;

    LOGGER.warn("The provided version (" + version + ") is not supported!");
    return null;
}

From source file:org.openestate.io.immoxml.ImmoXmlUtils.java

public static BigDecimal parseDecimal(String value) {
    value = StringUtils.trimToNull(value);
    if (value == null)
        return null;
    try {/*from   www  . jav  a2s  .c  om*/
        return DatatypeConverter.parseDecimal(value);
    } catch (NumberFormatException ex) {
        //LOGGER.warn( "Can't parse value '" + value + "' as decimal!" );
        //LOGGER.warn( "> " + ex.getLocalizedMessage(), ex );
    }
    try {
        return BigDecimal.valueOf(NumberUtils.parseNumber(value, Locale.GERMANY).doubleValue());
    } catch (NumberFormatException ex) {
        //LOGGER.warn( "Can't parse value '" + value + "' as decimal!" );
        //LOGGER.warn( "> " + ex.getLocalizedMessage(), ex );
    }
    throw new IllegalArgumentException("Can't parse decimal value '" + value + "'!");
}

From source file:org.openestate.io.immoxml.ImmoXmlUtils.java

public static BigInteger parseInteger(String value) {
    value = StringUtils.trimToNull(value);
    if (value == null)
        return null;
    try {// w  w  w  .ja  va 2s .  co  m
        return DatatypeConverter.parseInteger(value);
    } catch (NumberFormatException ex) {
        throw new IllegalArgumentException(
                "Can't parse integer value '" + value + "'! " + ex.getLocalizedMessage());
    }
}

From source file:org.openestate.io.is24_csv.Is24CsvFormat.java

@SuppressFBWarnings(value = "NP_BOOLEAN_RETURN_NULL", justification = "This behaviour is intended.")
public static Boolean parseBoolean(String value) {
    value = StringUtils.trimToNull(value);
    if ("J".equalsIgnoreCase(value))
        return true;
    else if ("N".equalsIgnoreCase(value))
        return false;
    else/*from ww  w .j  ava  2  s  . c  o  m*/
        return null;
}

From source file:org.openestate.io.is24_csv.Is24CsvPrinter.java

@Override
protected void print(String value) throws IOException {
    value = StringUtils.trimToNull(value);

    // IS24-CSV does not support escaping of the field separator. Therefore the
    // field separator '|' is replaced with '/' from the value before it is
    // written to CSV.
    value = StringUtils.replace(value, "|", "/");

    // Replace any line breaks from the value with <br>
    value = CsvPrinter.replaceLineBreaks(value, "<br>");

    super.print(value);
}