Example usage for org.springframework.util StringUtils trimWhitespace

List of usage examples for org.springframework.util StringUtils trimWhitespace

Introduction

In this page you can find the example usage for org.springframework.util StringUtils trimWhitespace.

Prototype

public static String trimWhitespace(String str) 

Source Link

Document

Trim leading and trailing whitespace from the given String .

Usage

From source file:org.spring.data.gemfire.rest.GemFireRestInterfaceTest.java

protected synchronized int getHttpServicePort() {
    try {//from   w w  w . j av a 2  s. c o  m
        return Integer.parseInt(StringUtils.trimWhitespace(gemfireProperties.getProperty("http-service-port")));
    } catch (NumberFormatException ignore) {
        int httpServicePort = getHttpServicePort(DEFAULT_HTTP_SERVICE_PORT);
        gemfireProperties.setProperty("http-service-port", String.valueOf(httpServicePort));
        return httpServicePort;
    }
}

From source file:org.apache.servicemix.platform.testing.support.AbstractIntegrationTest.java

protected Resource locateBundle(String bundleId) {
    Assert.hasText(bundleId, "bundleId should not be empty");

    // parse the String
    String[] artifactId = StringUtils.commaDelimitedListToStringArray(bundleId);

    Assert.isTrue(artifactId.length >= 3, "the CSV string " + bundleId + " contains too few values");
    // TODO: add a smarter mechanism which can handle 1 or 2 values CSVs
    for (int i = 0; i < artifactId.length; i++) {
        artifactId[i] = StringUtils.trimWhitespace(artifactId[i]);
    }// w  w  w  .  jav a2  s  . c om

    File f;
    if (artifactId.length == 3) {
        f = localMavenBundle(artifactId[0], artifactId[1], artifactId[2], null,
                ArtifactLocator.DEFAULT_ARTIFACT_TYPE);
    } else {
        f = localMavenBundle(artifactId[0], artifactId[1], artifactId[2], null, artifactId[3]);
    }
    return new FileSystemResource(f);
}

From source file:eap.config.TxAdviceBeanDefinitionParser.java

private void addRollbackRuleAttributesTo(List<RollbackRuleAttribute> rollbackRules, String rollbackForValue) {
    String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(rollbackForValue);
    for (String typeName : exceptionTypeNames) {
        rollbackRules.add(new RollbackRuleAttribute(StringUtils.trimWhitespace(typeName)));
    }//from   w w  w .  j  a  v a 2  s  .  com
}

From source file:eap.config.TxAdviceBeanDefinitionParser.java

private void addNoRollbackRuleAttributesTo(List<RollbackRuleAttribute> rollbackRules,
        String noRollbackForValue) {
    String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(noRollbackForValue);
    for (String typeName : exceptionTypeNames) {
        rollbackRules.add(new NoRollbackRuleAttribute(StringUtils.trimWhitespace(typeName)));
    }/*from   w w w.  ja  va2  s .c  o m*/
}

From source file:org.eclipse.gemini.blueprint.test.AbstractDependencyManagerTests.java

/**
 * Locates (through the {@link ArtifactLocator}) an OSGi bundle given as a
 * String.//ww  w .  j a  v a 2  s. co  m
 * 
 * The default implementation expects the argument to be in Comma Separated
 * Values (CSV) format which indicates an artifact group, id, version and
 * optionally the type.
 * 
 * @param bundleId the bundle identifier in CSV format
 * @return a resource pointing to the artifact location
 */
protected Resource locateBundle(String bundleId) {
    Assert.hasText(bundleId, "bundleId should not be empty");

    // parse the String
    String[] artifactId = StringUtils.commaDelimitedListToStringArray(bundleId);

    Assert.isTrue(artifactId.length >= 3, "the CSV string " + bundleId + " contains too few values");
    // TODO: add a smarter mechanism which can handle 1 or 2 values CSVs
    for (int i = 0; i < artifactId.length; i++) {
        artifactId[i] = StringUtils.trimWhitespace(artifactId[i]);
    }

    ArtifactLocator aLocator = getLocator();

    return (artifactId.length == 3 ? aLocator.locateArtifact(artifactId[0], artifactId[1], artifactId[2])
            : aLocator.locateArtifact(artifactId[0], artifactId[1], artifactId[2], artifactId[3]));
}

From source file:org.jlot.web.api.error.DefaultRestErrorResolver.java

protected RestError toRestError(String exceptionConfig) {
    String[] values = StringUtils.commaDelimitedListToStringArray(exceptionConfig);
    if (values == null || values.length == 0) {
        throw new IllegalStateException(
                "Invalid config mapping.  Exception names must map to a string configuration.");
    }/*  www  .jav a  2s  . co m*/

    RestError restError = new RestError();

    boolean statusCodeSet = false;
    boolean msgSet = false;
    boolean devMsgSet = false;
    boolean moreInfoSet = false;

    for (String value : values) {

        String trimmedVal = StringUtils.trimWhitespace(value);

        // check to see if the value is an explicitly named key/value pair:
        String[] pair = StringUtils.split(trimmedVal, "=");
        if (pair != null) {
            // explicit attribute set:
            String pairKey = StringUtils.trimWhitespace(pair[0]);
            if (!StringUtils.hasText(pairKey)) {
                pairKey = null;
            }
            String pairValue = StringUtils.trimWhitespace(pair[1]);
            if (!StringUtils.hasText(pairValue)) {
                pairValue = null;
            }
            if ("statusCode".equalsIgnoreCase(pairKey)) {
                int statusCode = getRequiredInt(pairKey, pairValue);
                restError.setStatusCode(statusCode);
                statusCodeSet = true;
            } else if ("msg".equalsIgnoreCase(pairKey)) {
                restError.setMessage(pairValue);
                msgSet = true;
            } else if ("devMsg".equalsIgnoreCase(pairKey)) {
                restError.setDeveloperMessage(pairValue);
                devMsgSet = true;
            } else if ("infoUrl".equalsIgnoreCase(pairKey)) {
                restError.setMoreInfoUrl(pairValue);
                moreInfoSet = true;
            }
        } else {
            // not a key/value pair - use heuristics to determine what value
            // is being set:
            int val;
            if (!statusCodeSet) {
                val = getInt("statusCode", trimmedVal);
                if (val > 0) {
                    restError.setStatusCode(val);
                    statusCodeSet = true;
                    continue;
                }
            }
            if (!moreInfoSet && trimmedVal.toLowerCase().startsWith("http")) {
                restError.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                continue;
            }
            if (!msgSet) {
                restError.setMessage(trimmedVal);
                msgSet = true;
                continue;
            }
            if (!devMsgSet) {
                restError.setDeveloperMessage(trimmedVal);
                devMsgSet = true;
                continue;
            }
            if (!moreInfoSet) {
                restError.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                // noinspection UnnecessaryContinue
                continue;
            }
        }
    }

    return restError;
}

From source file:com.novation.eligibility.rest.spring.web.servlet.handler.DefaultRestErrorResolver.java

protected RestError toRestError(String exceptionConfig) {
    String[] values = StringUtils.commaDelimitedListToStringArray(exceptionConfig);
    if (values == null || values.length == 0) {
        throw new IllegalStateException(
                "Invalid config mapping.  Exception names must map to a string configuration.");
    }//from   w w w . j  ava2s.  co m

    RestError.Builder builder = new RestError.Builder();

    boolean statusSet = false;
    boolean codeSet = false;
    boolean msgSet = false;
    boolean devMsgSet = false;
    boolean moreInfoSet = false;

    for (String value : values) {

        String trimmedVal = StringUtils.trimWhitespace(value);

        //check to see if the value is an explicitly named key/value pair:
        String[] pair = StringUtils.split(trimmedVal, "=");
        if (pair != null) {
            //explicit attribute set:
            String pairKey = StringUtils.trimWhitespace(pair[0]);
            if (!StringUtils.hasText(pairKey)) {
                pairKey = null;
            }
            String pairValue = StringUtils.trimWhitespace(pair[1]);
            if (!StringUtils.hasText(pairValue)) {
                pairValue = null;
            }
            if ("status".equalsIgnoreCase(pairKey)) {
                int statusCode = getRequiredInt(pairKey, pairValue);
                builder.setStatus(statusCode);
                statusSet = true;
            } else if ("code".equalsIgnoreCase(pairKey)) {
                int code = getRequiredInt(pairKey, pairValue);
                builder.setCode(code);
                codeSet = true;
            } else if ("msg".equalsIgnoreCase(pairKey)) {
                builder.setMessage(pairValue);
                msgSet = true;
            } else if ("devMsg".equalsIgnoreCase(pairKey)) {
                builder.setDeveloperMessage(pairValue);
                devMsgSet = true;
            } else if ("infoUrl".equalsIgnoreCase(pairKey)) {
                builder.setMoreInfoUrl(pairValue);
                moreInfoSet = true;
            }
        } else {
            //not a key/value pair - use heuristics to determine what value is being set:
            int val;
            if (!statusSet) {
                val = getInt("status", trimmedVal);
                if (val > 0) {
                    builder.setStatus(val);
                    statusSet = true;
                    continue;
                }
            }
            if (!codeSet) {
                val = getInt("code", trimmedVal);
                if (val > 0) {
                    builder.setCode(val);
                    codeSet = true;
                    continue;
                }
            }
            if (!moreInfoSet && trimmedVal.toLowerCase().startsWith("http")) {
                builder.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                continue;
            }
            if (!msgSet) {
                builder.setMessage(trimmedVal);
                msgSet = true;
                continue;
            }
            if (!devMsgSet) {
                builder.setDeveloperMessage(trimmedVal);
                devMsgSet = true;
                continue;
            }
            if (!moreInfoSet) {
                builder.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                //noinspection UnnecessaryContinue
                continue;
            }
        }
    }

    return builder.build();
}

From source file:com.oolong.platform.web.error.DefaultRestErrorResolver.java

protected RestError toRestError(String exceptionConfig) {
    String[] values = StringUtils.commaDelimitedListToStringArray(exceptionConfig);
    if (values == null || values.length == 0) {
        throw new IllegalStateException(
                "Invalid config mapping.  Exception names must map to a string configuration.");
    }/* w  ww  . ja  v  a2s. c  o  m*/

    RestError.Builder builder = new RestError.Builder();

    boolean statusSet = false;
    boolean codeSet = false;
    boolean msgSet = false;
    boolean devMsgSet = false;
    boolean moreInfoSet = false;

    for (String value : values) {

        String trimmedVal = StringUtils.trimWhitespace(value);

        // check to see if the value is an explicitly named key/value pair:
        String[] pair = StringUtils.split(trimmedVal, "=");
        if (pair != null) {
            // explicit attribute set:
            String pairKey = StringUtils.trimWhitespace(pair[0]);
            if (!StringUtils.hasText(pairKey)) {
                pairKey = null;
            }
            String pairValue = StringUtils.trimWhitespace(pair[1]);
            if (!StringUtils.hasText(pairValue)) {
                pairValue = null;
            }
            if ("status".equalsIgnoreCase(pairKey)) {
                int statusCode = getRequiredInt(pairKey, pairValue);
                builder.setStatus(statusCode);
                statusSet = true;
            } else if ("code".equalsIgnoreCase(pairKey)) {
                int code = getRequiredInt(pairKey, pairValue);
                builder.setCode(code);
                codeSet = true;
            } else if ("msg".equalsIgnoreCase(pairKey)) {
                builder.setMessage(pairValue);
                msgSet = true;
            } else if ("devMsg".equalsIgnoreCase(pairKey)) {
                builder.setDeveloperMessage(pairValue);
                devMsgSet = true;
            } else if ("infoUrl".equalsIgnoreCase(pairKey)) {
                builder.setMoreInfoUrl(pairValue);
                moreInfoSet = true;
            }
        } else {
            // not a key/value pair - use heuristics to determine what value
            // is being set:
            int val;
            if (!statusSet) {
                val = getInt("status", trimmedVal);
                if (val > 0) {
                    builder.setStatus(val);
                    statusSet = true;
                    continue;
                }
            }
            if (!codeSet) {
                val = getInt("code", trimmedVal);
                if (val > 0) {
                    builder.setCode(val);
                    codeSet = true;
                    continue;
                }
            }
            if (!moreInfoSet && trimmedVal.toLowerCase().startsWith("http")) {
                builder.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                continue;
            }
            if (!msgSet) {
                builder.setMessage(trimmedVal);
                msgSet = true;
                continue;
            }
            if (!devMsgSet) {
                builder.setDeveloperMessage(trimmedVal);
                devMsgSet = true;
                continue;
            }
            if (!moreInfoSet) {
                builder.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                // noinspection UnnecessaryContinue
                continue;
            }
        }
    }

    return builder.build();
}

From source file:org.craftercms.cstudio.publishing.servlet.FileUploadServlet.java

/**
 * delete files form target//w w  w .  jav a  2  s  . c  om
 * @param parameters
 * @param target
 * @param changeSet
 */
protected void deleteFromTarget(Map<String, String> parameters, PublishingTarget target,
        PublishedChangeSet changeSet) {
    String deletedList = parameters.get(PARAM_DELETED_FILES);
    String site = parameters.get(PARAM_SITE);
    if (deletedList != null) {
        StringTokenizer tokens = new StringTokenizer(deletedList, FILES_SEPARATOR);
        List<String> deletedFiles = new ArrayList<String>(tokens.countTokens());
        while (tokens.hasMoreElements()) {
            String contentLocation = tokens.nextToken();
            contentLocation = StringUtils.trimWhitespace(contentLocation);
            String root = target.getParameter(CONFIG_ROOT);
            String fullPath = root + File.separator + target.getParameter(CONFIG_CONTENT_FOLDER)
                    + contentLocation;
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("deleting " + fullPath);
            }
            if (StringUtils.hasText(site)) {
                fullPath = fullPath.replaceAll(CONFIG_MULTI_TENANCY_VARIABLE, site);
            }
            File file = new File(fullPath);
            if (file.exists()) {
                if (file.isFile()) {
                    file.delete();
                    deletedFiles.add(contentLocation);
                } else {
                    deleteChildren(file.list(), fullPath, contentLocation, deletedFiles);
                    file.delete();
                }
            } else {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(fullPath + " is not deleted since it does not exsit.");
                }
            }
            fullPath = root + '/' + target.getParameter(CONFIG_METADATA_FOLDER) + contentLocation
                    + CONFIG_METADATA_FILENAME_SUFFIX;
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("deleting " + fullPath);
            }
            if (StringUtils.hasText(site)) {
                fullPath = fullPath.replaceAll(CONFIG_MULTI_TENANCY_VARIABLE, site);
            }
            file = new File(fullPath);
            if (file.exists()) {
                file.delete();
            } else if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(fullPath + " is not deleted since it does not exsit.");
            }
        }
        changeSet.setDeletedFiles(deletedFiles);
    }
}

From source file:com.yang.oa.commons.exception.DefaultRestErrorResolver.java

protected RestError toRestError(String exceptionConfig) {
    String[] values = StringUtils.commaDelimitedListToStringArray(exceptionConfig);
    if (values == null || values.length == 0) {
        throw new IllegalStateException(
                "Invalid config mapping.  Exception names must map to a string configuration.");
    }//from   w ww  .  j a  v  a 2  s. c o  m
    System.out.println("??" + exceptionConfig);
    RestError.Builder builder = new RestError.Builder();

    boolean statusSet = false;
    boolean codeSet = false;
    boolean msgSet = false;
    boolean devMsgSet = false;
    boolean moreInfoSet = false;

    for (String value : values) {

        String trimmedVal = StringUtils.trimWhitespace(value);

        //check to see if the value is an explicitly named key/value pair:
        String[] pair = StringUtils.split(trimmedVal, "=");
        if (pair != null) {
            //explicit attribute set:
            String pairKey = StringUtils.trimWhitespace(pair[0]);
            if (!StringUtils.hasText(pairKey)) {
                pairKey = null;
            }
            String pairValue = StringUtils.trimWhitespace(pair[1]);
            if (!StringUtils.hasText(pairValue)) {
                pairValue = null;
            }
            if ("status".equalsIgnoreCase(pairKey)) {
                int statusCode = getRequiredInt(pairKey, pairValue);
                builder.setStatus(statusCode);
                statusSet = true;
            } else if ("code".equalsIgnoreCase(pairKey)) {
                int code = getRequiredInt(pairKey, pairValue);
                builder.setCode(code);
                codeSet = true;
            } else if ("msg".equalsIgnoreCase(pairKey)) {
                builder.setMessage(pairValue);
                msgSet = true;
            } else if ("devMsg".equalsIgnoreCase(pairKey)) {
                builder.setDeveloperMessage(pairValue);
                devMsgSet = true;
            } else if ("infoUrl".equalsIgnoreCase(pairKey)) {
                builder.setMoreInfoUrl(pairValue);
                moreInfoSet = true;
            }
        } else {
            //not a key/value pair - use heuristics to determine what value is being set:
            int val;
            if (!statusSet) {
                val = getInt("status", trimmedVal);
                if (val > 0) {
                    builder.setStatus(val);
                    statusSet = true;
                    continue;
                }
            }
            if (!codeSet) {
                val = getInt("code", trimmedVal);
                if (val > 0) {
                    builder.setCode(val);
                    codeSet = true;
                    continue;
                }
            }
            if (!moreInfoSet && trimmedVal.toLowerCase().startsWith("http")) {
                builder.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                continue;
            }
            if (!msgSet) {
                builder.setMessage(trimmedVal);
                msgSet = true;
                continue;
            }
            if (!devMsgSet) {
                builder.setDeveloperMessage(trimmedVal);
                devMsgSet = true;
                continue;
            }
            if (!moreInfoSet) {
                builder.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                //noinspection UnnecessaryContinue
                continue;
            }
        }
    }

    return builder.build();
}