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.idx.IdxFormat.java

public static String printString(String value, int maxLength) {
    value = StringUtils.trimToNull(value);
    if (maxLength < 1)
        return value;
    else if (maxLength < 4)
        return StringUtils.left(value, maxLength);
    else/*w  w  w .  ja v  a2s.  c  o  m*/
        return StringUtils.abbreviate(value, maxLength);
}

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

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

    // We're not sure, if escaping of the separator is supported by IDX.
    // Therefore the separator (#) is removed from the value before it is
    // written to CSV.
    value = StringUtils.replace(value, "#", StringUtils.EMPTY);

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

    super.print(value);
}

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

@Override
protected void parse(CSVRecord record) {
    String version = StringUtils.trimToNull(record.get(FIELD_VERSION));
    if (version != null && !VERSION.equalsIgnoreCase(version) && !IdxFormat.VERSION.equalsIgnoreCase(version)) {
        LOGGER.warn("IDX version '" + version + "' is not supported. Trying to parse the record anyway.");
    }/*  w w  w.ja  v  a  2s.  c o  m*/
    super.parse(record);
}

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

@Override
protected String parse(String value) {
    // replace <br> elements with native line separator in any parsed value
    value = StringUtils.trimToNull(value);
    if (value == null)
        return null;
    Matcher m = LINEBREAK.matcher(value);
    return (m.find()) ? m.replaceAll(SystemUtils.LINE_SEPARATOR) : value;
}

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

public void setDocument(Media value) {
    String file = (value != null) ? StringUtils.trimToNull(value.getFileName()) : null;
    this.set(FIELD_DOCUMENT_FILE, file);
    this.set(FIELD_DOCUMENT_TITLE,
            (value != null && file != null) ? IdxFormat.printString(value.getTitle(), 200) : null);
    this.set(FIELD_DOCUMENT_TEXT,
            (value != null && file != null) ? IdxFormat.printString(value.getDescription(), 1800) : null);
}

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

public void setMovie(Media value) {
    String file = (value != null) ? StringUtils.trimToNull(value.getFileName()) : null;
    this.set(FIELD_MOVIE_FILE, file);
    this.set(FIELD_MOVIE_TITLE,
            (value != null && file != null) ? IdxFormat.printString(value.getTitle(), 200) : null);
    this.set(FIELD_MOVIE_TEXT,
            (value != null && file != null) ? IdxFormat.printString(value.getDescription(), 1800) : null);
}

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

public void setPicture1(Media value) {
    String file = (value != null) ? StringUtils.trimToNull(value.getFileName()) : null;
    this.set(FIELD_PICTURE_1_FILE, file);
    this.set(FIELD_PICTURE_1_TITLE,
            (value != null && file != null) ? IdxFormat.printString(value.getTitle(), 200) : null);
    this.set(FIELD_PICTURE_1_TEXT,
            (value != null && file != null) ? IdxFormat.printString(value.getDescription(), 1800) : null);
    this.set(FIELD_PICTURE_1_URL, (value != null && file != null) ? value.getUrl() : null);
}

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

public void setPicture2(Media value) {
    String file = (value != null) ? StringUtils.trimToNull(value.getFileName()) : null;
    this.set(FIELD_PICTURE_2_FILE, file);
    this.set(FIELD_PICTURE_2_TITLE,
            (value != null && file != null) ? IdxFormat.printString(value.getTitle(), 200) : null);
    this.set(FIELD_PICTURE_2_TEXT,
            (value != null && file != null) ? IdxFormat.printString(value.getDescription(), 1800) : null);
    this.set(FIELD_PICTURE_2_URL, (value != null && file != null) ? value.getUrl() : null);
}

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

public void setPicture3(Media value) {
    String file = (value != null) ? StringUtils.trimToNull(value.getFileName()) : null;
    this.set(FIELD_PICTURE_3_FILE, file);
    this.set(FIELD_PICTURE_3_TITLE,
            (value != null && file != null) ? IdxFormat.printString(value.getTitle(), 200) : null);
    this.set(FIELD_PICTURE_3_TEXT,
            (value != null && file != null) ? IdxFormat.printString(value.getDescription(), 1800) : null);
    this.set(FIELD_PICTURE_3_URL, (value != null && file != null) ? value.getUrl() : null);
}

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

public void setPicture4(Media value) {
    String file = (value != null) ? StringUtils.trimToNull(value.getFileName()) : null;
    this.set(FIELD_PICTURE_4_FILE, file);
    this.set(FIELD_PICTURE_4_TITLE,
            (value != null && file != null) ? IdxFormat.printString(value.getTitle(), 200) : null);
    this.set(FIELD_PICTURE_4_TEXT,
            (value != null && file != null) ? IdxFormat.printString(value.getDescription(), 1800) : null);
    this.set(FIELD_PICTURE_4_URL, (value != null && file != null) ? value.getUrl() : null);
}