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

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

Introduction

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

Prototype

public static String trim(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String, handling null by returning null .

The String is trimmed using String#trim() .

Usage

From source file:com.wxxr.nirvana.json.TestUtils.java

/**
 * normalizes a string so that strings generated on different platforms can
 * be compared. any group of one or more space, tab, \r, and \n characters
 * are converted to a single space character
 * //from w w  w.j a  v a  2 s.co m
 * @param obj
 *            the object to be normalized. normalize will perform its
 *            operation on obj.toString().trim() ;
 * @param appendSpace
 * @return the normalized string
 */
public static String normalize(Object obj, boolean appendSpace) {
    Matcher matcher = WHITESPACE_BLOCK.matcher(StringUtils.trim(obj.toString()));
    /*
    FIXME: appendSpace has been always ignored, uncommenting the following line will cause dozen of test fails
    if (appendSpace) {
    return matcher.replaceAll(" ");
    }
    */
    return matcher.replaceAll("");
}

From source file:edu.usf.cutr.obascs.io.FileConsolidator.java

public static String consolidateFile(ListFeed feed, Map<String, String> agencyMap) {
    Logger logger = Logger.getInstance();
    logger.debug("Merging files started...");
    logger.debug("Total Entries : " + feed.getEntries().size());

    StringBuilder sb = new StringBuilder("#summary HART consolidated stops");

    sb.append(SystemUtils.LINE_SEPARATOR).append(SystemUtils.LINE_SEPARATOR);
    sb.append(StringConstants.FILE_START).append(SystemUtils.LINE_SEPARATOR).append(SystemUtils.LINE_SEPARATOR);

    for (ListEntry entry : feed.getEntries()) {

        /*/*from www .  jav a2s  . c om*/
         *  lineCounter: to separate columns by tab character 
         */
        Integer lineCounter = 0;
        for (Map.Entry<String, String> agency : agencyMap.entrySet()) {
            String stopId = StringUtils
                    .trim(entry.getCustomElements().getValue(StringUtils.deleteWhitespace(agency.getKey())));

            if (lineCounter == 0) {
                if (StringUtils.isNotBlank(stopId)) {
                    sb.append("\"").append(agency.getKey()).append(StringConstants.UNDERSCORE).append(stopId)
                            .append("\"").append(StringConstants.TAB);
                }
            } else if (lineCounter == agencyMap.size() - 2) {
                if (StringUtils.isNotBlank(stopId)) {
                    sb.append("\"").append(agency.getKey()).append(StringConstants.UNDERSCORE).append(stopId)
                            .append("\"");
                }
            } else {
                if (StringUtils.isNotBlank(stopId)) {
                    sb.append("\"").append(agency.getKey()).append(StringConstants.UNDERSCORE).append(stopId)
                            .append("\"").append(StringConstants.TAB);
                } else {
                    sb.append(StringConstants.TAB);
                }
            }
            lineCounter++;
        }
        sb.append(SystemUtils.LINE_SEPARATOR);

    }

    sb.append(SystemUtils.LINE_SEPARATOR).append(StringConstants.FILE_END);
    logger.debug("Merge finished");

    return sb.toString();
}

From source file:com.threewks.thundr.transformer.discrete.StringToBoolean.java

@Override
public Boolean from(String from) {
    from = StringUtils.trim(from);
    return from == null ? null : Boolean.valueOf(from);
}

From source file:de.micromata.genome.util.text.StandardHeaderSplitter.java

/**
 * Split.//from w  ww . j  a  v  a2  s  . c  o m
 *
 * @param text the text
 * @return the pair
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static Pair<String, Map<String, String>> split(String text) throws IOException {
    LineNumberReader lnr = new LineNumberReader(new StringReader(text));
    Map<String, String> headers = new HashMap<String, String>();
    String line = null;
    boolean leedingNewlines = true;
    while ((line = lnr.readLine()) != null) {
        if (StringUtils.isBlank(line)) {
            if (leedingNewlines == true) {// es kann sein, dass am Anfang die Newlines sind(wegen Code, etc)
                continue;
            } else {
                break;
            }
        }
        String key = StringUtils.substringBefore(line, ":");
        String value = StringUtils.substringAfter(line, ":");
        headers.put(StringUtils.trim(key), StringUtils.trim(value));
        leedingNewlines = false;
    }
    if (headers.size() == 0) {
        return new Pair<String, Map<String, String>>(text, headers);
    }
    return new Pair<String, Map<String, String>>(slurp(lnr), headers);
}

From source file:ee.ria.xroad.common.conf.globalconf.IdentifierDecoderHelper.java

static ClientId getSubjectName(X509Certificate cert, IdentifierDecoderType decoder, String instanceIdentifier)
        throws Exception {
    String methodName = StringUtils.trim(decoder.getMethodName());
    Method method;/*from  w  w w  .  ja v  a  2  s.  c  o  m*/
    try {
        method = getMethodFromClassName(methodName, X509Certificate.class);
    } catch (ClassNotFoundException e) {
        throw new CodedException(X_INTERNAL_ERROR, "Could not find identifier decoder: '%s'", methodName);
    } catch (NoSuchMethodException e) {
        throw new CodedException(X_INTERNAL_ERROR, "Could not find identifier decoder method: '%s'",
                methodName);
    } catch (Exception e) {
        throw new CodedException(X_INTERNAL_ERROR, e);
    }

    Object result;
    try {
        result = method.invoke(null /* Static, no instance */, cert);
    } catch (Exception e) {
        Throwable t = e instanceof InvocationTargetException ? e.getCause() : e;
        log.error("Error during extraction of subject name from " + "certificate '" + cert.getSubjectDN()
                + "' using " + "identifier decoder '" + methodName + "'", t);
        throw new CodedException(X_INCORRECT_CERTIFICATE, t);
    }

    if (result == null) {
        throw new CodedException(X_INCORRECT_CERTIFICATE,
                "Could not get SubjectName from certificate " + cert.getSubjectDN());
    }

    if (result instanceof String) {
        return ClientId.create(instanceIdentifier, decoder.getMemberClass(), (String) result);
    } else if (result instanceof String[]) {
        String[] parts = (String[]) result;
        if (parts.length == 2) {
            return ClientId.create(instanceIdentifier, parts[0], parts[1]);
        }
    } else if (result instanceof ClientId) {
        return (ClientId) result;
    }

    throw new CodedException(X_INTERNAL_ERROR,
            "Unexpected result from identifier decoder: " + result.getClass());
}

From source file:de.micromata.genome.util.matcher.BeanInspektorMatcherFactory.java

/**
 * Creates a new BeanInspektorMatcher object.
 *
 * @param pattern the pattern//  ww w . j  a  v a  2s  . c o m
 * @return the matcher
 */
@Override
public Matcher<Object> createMatcher(String pattern) {
    String matcherString = StringUtils.trim(StringUtils.substringBefore(pattern, "="));
    String valueString = StringUtils.trimToNull(StringUtils.substringAfter(pattern, "="));

    if (matcherString.trim().equals("instanceOf")) {
        try {
            // TODO (RK) wirklich nur von root classloader, nicht thread?
            return new BeanInstanceOfMatcher(Class.forName(valueString.trim()));
        } catch (Exception ex) {
            throw new RuntimeException(ex); // TODO better ex
        }
    }
    return new BeanPropertiesMatcher(matcherString, valueString);
}

From source file:com.sonicle.webtop.core.bol.OServiceStoreEntry.java

public static String sanitizeKey(String key) {
    return StringUtils.upperCase(StringUtils.trim(key));
}

From source file:com.sonicle.webtop.core.versioning.AnnotationLine.java

public static boolean matches(String text) {
    return PATTERN.matcher(StringUtils.trim(text)).matches();
}

From source file:io.restassured.internal.http.CustomHttpMethod.java

public CustomHttpMethod(String methodName, final URI uri) {
    AssertParameter.notNull(methodName, "Method");
    this.methodName = StringUtils.trim(methodName).toUpperCase();
    setURI(uri);/*from w  w w  .ja v a 2s. c o m*/
}

From source file:com.sample.domain.entities.anagrafica.accessor.TipologiaCliente.java

public static TipologiaCliente decode(String tipologiaClienteCode) {
    return TipologiaCliente.valueMap.get(StringUtils.trim(tipologiaClienteCode));
}