Example usage for com.liferay.portal.kernel.util StringUtil trim

List of usage examples for com.liferay.portal.kernel.util StringUtil trim

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringUtil trim.

Prototype

public static String trim(String s, char[] exceptions) 

Source Link

Document

Trims leading and trailing whitespace from the string, up to but not including the whitespace characters specified by exceptions.

Usage

From source file:org.opencps.backend.util.DossierNoGenerator.java

License:Open Source License

/**
 * Generate noReception with pattern//from   ww w  .  j  a va2  s .  c o  m
 * 
 * @param pattern
 * @return
 */
public static String genaratorNoReception(String pattern) {

    String noReception = StringPool.BLANK;

    pattern = StringUtil.lowerCase(pattern);
    pattern = StringUtil.trim(pattern, ' ');

    StringBuffer sbNoReception = new StringBuffer(pattern);

    Calendar cal = Calendar.getInstance();

    String strYearTypeOne = Integer.toString(cal.get(Calendar.YEAR));
    String strYearTypeTwo = Integer.toString(cal.get(Calendar.YEAR)).substring(2);

    String strMonth = (cal.get(Calendar.MONTH) + 1) < 10 ? "0" + Integer.toString(cal.get(Calendar.MONTH) + 1)
            : Integer.toString(cal.get(Calendar.MONTH) + 1);
    String strDay = cal.get(Calendar.DAY_OF_MONTH) < 10 ? "0" + Integer.toString(cal.get(Calendar.DAY_OF_MONTH))
            : Integer.toString(cal.get(Calendar.DAY_OF_MONTH));

    if (_validateParttern(pattern)) {
        int numberSerial = StringUtil.count(pattern, "n");

        String serialNumber = noGenarator(numberSerial);

        sbNoReception.replace(pattern.indexOf('n') - 1, pattern.lastIndexOf('n') + 2, serialNumber);

        pattern = sbNoReception.toString();

        if (pattern.contains(FIX_YEAR_PATTERN_TYPE_1)) {
            pattern = StringUtil.replace(pattern, FIX_YEAR_PATTERN_TYPE_1, strYearTypeOne);
        }

        if (pattern.contains(FIX_YEAR_PATTERN_TYPE_2)) {
            pattern = StringUtil.replace(pattern, FIX_YEAR_PATTERN_TYPE_2, strYearTypeTwo);
        }

        if (pattern.contains(FIX_MONTH_PATTERN)) {
            pattern = StringUtil.replace(pattern, FIX_MONTH_PATTERN, strMonth);
        }

        if (pattern.contains(FIX_DAY_PATTERN)) {
            pattern = StringUtil.replace(pattern, FIX_DAY_PATTERN, strDay);
        }

        noReception = pattern;

    } else {

        StringBuffer sbNoReceptionDefault = new StringBuffer();

        String serialNumber = noGenarator(FIX_DEFAULT_SERIAL_NUMBER);

        sbNoReceptionDefault.append(strYearTypeOne);
        sbNoReceptionDefault.append(strMonth);
        sbNoReceptionDefault.append(strDay);
        sbNoReceptionDefault.append(serialNumber);

        noReception = sbNoReceptionDefault.toString();

    }

    return noReception;
}