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

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

Introduction

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

Prototype

public static String trim(String str) 

Source Link

Document

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

Usage

From source file:com.moz.fiji.hive.FijiRowExpression.java

/**
 * Creates an expression./*from ww w  . java 2  s  .c o m*/
 *
 * @param expression The expression string.
 * @param typeInfo The Hive type the expression is mapped to.
 */
public FijiRowExpression(String expression, TypeInfo typeInfo) {
    mExpression = new Parser().parse(StringUtils.trim(expression), typeInfo);
}

From source file:mitm.djigzo.web.services.security.AuthenticationEntryPointWithRequestParams.java

@Override
protected String buildRedirectUrlToLoginPage(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) {
    String url = StringUtils.trim(super.buildRedirectUrlToLoginPage(request, response, authException));

    if (CollectionUtils.isNotEmpty(requestParameters)) {
        boolean addParamSeparator = false;
        boolean addAmp = true;

        if (!url.contains("?")) {
            addParamSeparator = true;/*from  www .j a v a2s. c o m*/
            addAmp = false;
        }

        for (String requestParameter : requestParameters) {
            String value = request.getParameter(requestParameter);

            if (value != null) {
                if (addParamSeparator) {
                    url = url + "?";
                    addParamSeparator = false;
                }

                if (addAmp) {
                    url = url + "&";
                }

                addAmp = true;

                url = url + encode(requestParameter) + "=" + encode(value);
            }
        }
    }

    return url;
}

From source file:mitm.djigzo.web.pages.dlp.patterns.PatternsRename.java

public Object onSuccess() {
    Object result = null;//from  w w w .  j  a va  2  s  . com

    try {
        policyPatternManagerWS.renamePattern(policyPatternNode.getName(), StringUtils.trim(newName));
    } catch (WebServiceCheckedException e) {
        logger.error("Error during submit.", e);

        errorMessage = e.getMessage();
        error = true;
    }

    return result;
}

From source file:jp.ikedam.jenkins.plugins.viewcopy_builder.SetRegexOperation.java

/**
 * @param doc// w  w w.  java2s.c o  m
 * @param env
 * @param logger
 * @return
 * @see jp.ikedam.jenkins.plugins.viewcopy_builder.ViewcopyOperation#perform(org.w3c.dom.Document, hudson.EnvVars, java.io.PrintStream)
 */
@Override
public Document perform(Document doc, EnvVars env, PrintStream logger) {
    if (StringUtils.isEmpty(getRegex())) {
        logger.println("Regular expression is not specified.");
        return null;
    }

    String expandedRegex = StringUtils.trim(env.expand(getRegex()));
    if (StringUtils.isEmpty(expandedRegex)) {
        logger.println("Regular expression got to empty.");
        return null;
    }

    try {
        Pattern.compile(expandedRegex);
    } catch (PatternSyntaxException e) {
        e.printStackTrace(logger);
        return null;
    }

    Node regexNode;
    try {
        regexNode = getNode(doc, "/*/includeRegex");
    } catch (XPathExpressionException e) {
        e.printStackTrace(logger);
        return null;
    }

    if (regexNode == null) {
        // includeRegex is not exist.
        // create new one.
        regexNode = doc.createElement("includeRegex");
        doc.getDocumentElement().appendChild(regexNode);
    }

    regexNode.setTextContent(expandedRegex);
    logger.println(String.format("Set includeRegex to %s", expandedRegex));

    return doc;
}

From source file:gemlite.core.util.CommandBase.java

protected String getValue(CmdField f) {
    Object value = null;/*from w ww  .  j  a  va  2s .  c  o  m*/
    f.field.setAccessible(true);
    try {
        value = f.field.get(this);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return StringUtils.trim("" + value);
}

From source file:net.kamhon.ieagle.function.config.BasicAppConfig.java

@Bean
public Object resourceBaseNames() {
    List<String> resources = new ArrayList<String>();
    String resource = env.getProperty("resourceBaseNames");
    if (StringUtils.isNotBlank(resource)) {
        String[] ss = StringUtils.split(resource, ',');
        for (String s : ss)
            resources.add(StringUtils.trim(s));
    }//www  .  j  av a  2  s . c om

    return resources;
}

From source file:com.alibaba.otter.manager.biz.monitor.impl.AbstractRuleMonitor.java

protected boolean inPeriod(AlarmRule alarmRule) {
    String rule = alarmRule.getMatchValue();
    if (StringUtils.isEmpty(rule)) {
        log.info("rule is empty " + alarmRule);
        return false;
    }//from   w  w  w. j  ava  2  s  .co m

    String periods = StringUtils.substringAfterLast(rule, "@");
    if (StringUtils.isEmpty(periods)) {
        // ?
        return isInPeriodWhenNoPeriod();
    }

    Calendar calendar = currentCalendar();
    periods = StringUtils.trim(periods);
    for (String period : StringUtils.split(periods, ",")) {
        String[] startAndEnd = StringUtils.split(period, "-");
        if (startAndEnd == null || startAndEnd.length != 2) {
            log.error("error period time format in rule : " + alarmRule);
            return isInPeriodWhenErrorFormat();
        }

        String start = startAndEnd[0];
        String end = startAndEnd[1];
        if (checkInPeriod(calendar, start, end)) {
            log.info("rule is in period : " + alarmRule);
            return true;
        }
    }

    log.info("rule is not in period : " + alarmRule);
    return false;
}

From source file:jp.ikedam.jenkins.plugins.extensible_choice_parameter.DatabaseChoiceListProvider.java

@DataBoundConstructor
public DatabaseChoiceListProvider(String userdb, String passworddb, String urldb, String colomndb,
        String namedb, String tabledb, String driverdb, String fallbackfile) {
    this.dbUsername = StringUtils.trim(userdb);
    this.dbPassword = StringUtils.trim(passworddb);
    this.jdbcUrl = StringUtils.trim(urldb);
    this.dbColumn = StringUtils.trim(colomndb);
    this.dbName = StringUtils.trim(namedb);
    this.dbTable = StringUtils.trim(tabledb);
    this.jdbcDriver = StringUtils.trim(driverdb);
    this.fallbackFilePath = StringUtils.trim(fallbackfile);
}

From source file:com.flexive.faces.beans.PluginRegistryBean.java

/**
 * Constructor. Search the classpath for plugin config files and initialize all plugins.
 *//*from  w  w w .  jav  a2s . c o m*/
@SuppressWarnings({ "unchecked" })
public PluginRegistryBean() {
    try {
        // find all config files in our application's classpath
        final Enumeration<URL> configFiles = Thread.currentThread().getContextClassLoader()
                .getResources(CONFIG_FILENAME);
        final Set<String> processedUrls = Sets.newHashSet();
        while (configFiles.hasMoreElements()) {
            final URL configFile = configFiles.nextElement();
            if (!processedUrls.add(configFile.toString())) {
                // avoid adding the same plugin several times
                continue;
            }

            if (LOG.isDebugEnabled()) {
                LOG.debug("Processing plugin config: " + configFile.getPath());
            }
            final Document document = getXmlDocument(configFile);
            // get plugin-factory elements
            final NodeList factories = document.getElementsByTagName("plugin-factory");
            for (int i = 0; i < factories.getLength(); i++) {
                // get the FQCN of the PluginFactory instance
                final String className = StringUtils.trim(factories.item(i).getTextContent());
                try {
                    // load the factory class
                    final Class<?> factoryClass = Thread.currentThread().getContextClassLoader()
                            .loadClass(className);
                    if (!(PluginFactory.class.isAssignableFrom(factoryClass))) {
                        if (LOG.isErrorEnabled()) {
                            LOG.error("Plugin factory " + className + " does not implement "
                                    + PluginFactory.class.getCanonicalName() + " (ignored).");
                        }
                        continue;
                    }
                    try {
                        // instantiate factory
                        final PluginFactory factory = ((Class<PluginFactory>) factoryClass).newInstance();
                        // initialize plugins
                        if (LOG.isInfoEnabled()) {
                            LOG.info("Adding flexive plugin callbacks from " + className + "...");
                        }
                        // add plugin callbacks
                        factory.initialize(this);
                    } catch (Exception e) {
                        LOG.error("Failed to instantiate plugin factory (ignored): " + e.getMessage(), e);
                    }
                } catch (ClassNotFoundException e) {
                    LOG.error("Plugin factory class not found (ignored): " + className);
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Failed to initialize plugin registry bean: " + e.getMessage(), e);
        throw new IllegalArgumentException(e);
    }
}

From source file:com.intuit.tank.report.JobReportOptions.java

/**
 * @param minUsers
 *            the minUsers to set
 */
public void setMinUsers(String minUsers) {
    this.minUsers = StringUtils.trim(minUsers);
}