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

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

Introduction

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

Prototype

public static String trimToEmpty(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null .

Usage

From source file:net.lmxm.ute.executers.tasks.FindReplaceTaskExecuter.java

/**
 * Convert patterns to matchers./*from   w  w w  .j a v a  2 s .  co  m*/
 *
 * @param findReplacePatterns the find replace patterns
 * @return the list
 */
protected List<PatternWrapper> convertFindReplacePatternsToRegexPatterns(
        final List<FindReplacePattern> findReplacePatterns) {
    checkNotNull(findReplacePatterns, "Find replace patterns list may not be null");

    final List<PatternWrapper> patterns = new ArrayList<PatternWrapper>();

    for (final FindReplacePattern findReplacePattern : findReplacePatterns) {
        final Pattern regexPattern = Pattern.compile(findReplacePattern.getFind());
        final String replacement = StringUtils.trimToEmpty(findReplacePattern.getReplace());

        patterns.add(new PatternWrapper(regexPattern, replacement));
    }

    return patterns;
}

From source file:cop.raml.processor.RestApi.java

private static String findLongestPrefix(String basePath, String path) {
    basePath = StringUtils.trimToEmpty(basePath);
    path = StringUtils.trimToEmpty(path);

    if (basePath.isEmpty() || path.isEmpty())
        return StringUtils.EMPTY;

    String[] baseParts = Utils.splitPath(basePath);
    String[] pathParts = Utils.splitPath(path);
    int total = getEqualPartsAmount(baseParts, pathParts);

    if (total > 0) {
        String str = StringUtils.join(ArrayUtils.subarray(baseParts, 0, total), "/");
        return path.startsWith("/") ? '/' + str : str;
    } else/*from   w ww . j  a v a  2s. c om*/
        return StringUtils.EMPTY;
}

From source file:com.xpn.xwiki.plugin.calendar.CalendarEvent.java

public void setTitle(String title) {
    this.title = StringUtils.trimToEmpty(title);
}

From source file:com.jiangyifen.ec2.servlet.http.common.filter.HttpCommonFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
        throws IOException, ServletException {
    try {/*  w w  w . j  a  v  a  2  s.c o  m*/
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        String requestURI = request.getRequestURI(); // ??:

        //         System.out.println(">JRH--->>>HttpCommonFilter.class-----requestURI-------"+requestURI);

        if (!requestURI.startsWith("/ec2/http/common/")) { // ???uri 
            chain.doFilter(new XssHttpServletRequestWrapper(request), response); // 
        } else {
            CommonRespBo commonRespBo = new CommonRespBo(); // ??
            commonRespBo.setCode(0);

            String remoteIp = request.getRemoteAddr();

            if (AnalyzeIfaceJointUtil.IP_FILTERABLE_VALUE) { // ?? IP 
                HashSet<String> ipSet = AnalyzeIfaceJointUtil.AUTHORIZE_IPS_SET;
                if (ipSet == null || !ipSet.contains(remoteIp)) { // IP ?IP??EC2 ?IP
                    commonRespBo.setCode(-1);
                    commonRespBo.setMessage("EC2????");
                    logger.warn(
                            "JRH - IFACE EC2?EC2????");
                    operateResponse(response, commonRespBo);
                    return;
                }
            }

            if (AnalyzeIfaceJointUtil.JOINT_LICENSE_NECESSARY_VALUE) { // EC2???License ??accessId  accessKey ?
                if (jointLicenseService == null) {
                    jointLicenseService = SpringContextHolder.getBean("jointLicenseService");
                }

                String accessId = StringUtils.trimToEmpty(request.getParameter("accessId"));
                String accessKey = StringUtils.trimToEmpty(request.getParameter("accessKey"));
                if ("".equals(accessId) || "".equals(accessKey)) { // ???
                    commonRespBo.setCode(-1);
                    commonRespBo
                            .setMessage("?(accessId) (accessKey) ???");
                    logger.warn(
                            "JRH - IFACE EC2??(accessId) (accessKey) ????");
                    operateResponse(response, commonRespBo);
                    return;
                }

                JointLicense jointLicense = jointLicenseService.getByIdKey(accessId, accessKey);
                if (jointLicense == null) { // License?
                    commonRespBo.setCode(-1);
                    commonRespBo.setMessage("?(accessId)  (accessKey) ?");
                    logger.warn(
                            "JRH - IFACE EC2??(accessId)  (accessKey) ?");
                    operateResponse(response, commonRespBo);
                    return;
                }

                request.setAttribute("domainId", jointLicense.getDomainId()); // ?
            } else {
                request.setAttribute("domainId", 1L); // ?
            }

            chain.doFilter(new XssHttpServletRequestWrapper(request), response); // , 
        }
    } catch (Exception e) {
        logger.error("JRH - IFACE EC2??" + e.getMessage(), e);
    }
}

From source file:com.moviejukebox.tools.GitRepositoryState.java

private static Boolean asBoolean(final String valueToConvert) {
    if (StringUtils.isNotBlank(valueToConvert)) {
        return Boolean.parseBoolean(StringUtils.trimToEmpty(valueToConvert));
    }/* w  ww .  j  av  a2  s.com*/
    return null;
}

From source file:kenh.xscript.elements.Method.java

/**
 * Process method of {@code Method} element.
 * //from  w  ww . j a v  a2s. co  m
 * @param name
 * @param parameter
 * @throws UnsupportedScriptException
 */
@Processing
public void process(@Attribute(ATTRIBUTE_NAME) String name, @Primal @Attribute(ATTRIBUTE_PARA) String parameter)
        throws UnsupportedScriptException {
    this.name = name;

    if (StringUtils.isBlank(name)) {
        UnsupportedScriptException ex = new UnsupportedScriptException(this, "The method name is empty.");
        throw ex;
    }

    Map<String, Element> methods = this.getEnvironment().getMethods();
    if (methods.containsKey(name)) {
        UnsupportedScriptException ex = new UnsupportedScriptException(this,
                "Reduplicate method. [" + name + "]");
        throw ex;
    }

    if (StringUtils.isNotBlank(parameter)) {
        String[] paras = StringUtils.split(parameter, ",");
        Vector<String[]> allParas = new Vector();
        Vector<String> existParas = new Vector(); // exist parameters
        for (String para : paras) {
            if (StringUtils.isBlank(para)) {
                UnsupportedScriptException ex = new UnsupportedScriptException(this,
                        "Parameter format incorrect. [" + name + ", " + parameter + "]");
                throw ex;
            }

            String[] all = StringUtils.split(para, " ");
            String paraName = StringUtils.trimToEmpty(all[all.length - 1]);
            if (StringUtils.isBlank(paraName) || StringUtils.contains(paraName, "{")) {
                UnsupportedScriptException ex = new UnsupportedScriptException(this,
                        "Parameter format incorrect. [" + name + ", " + parameter + "]");
                throw ex;
            }
            if (existParas.contains(paraName)) {
                UnsupportedScriptException ex = new UnsupportedScriptException(this,
                        "Reduplicate parameter. [" + name + ", " + paraName + "]");
                throw ex;
            } else {
                existParas.add(paraName);
            }

            Vector<String> one = new Vector();
            one.add(paraName);
            for (int i = 0; i < all.length - 1; i++) {
                String s = StringUtils.trimToEmpty(all[i]);
                if (StringUtils.isBlank(s))
                    continue;
                if (s.equals(MODI_FINAL) || s.equals(MODI_REQUIRED)
                        || (s.startsWith(MODI_DEFAULT + "(") && s.endsWith(")"))) {
                    one.add(s);
                } else {
                    UnsupportedScriptException ex = new UnsupportedScriptException(this,
                            "Unsupported modifier. [" + name + ", " + paraName + ", " + s + "]");
                    throw ex;
                }
            }

            String[] one_ = one.toArray(new String[] {});
            allParas.add(one_);
        }

        parameters = allParas.toArray(new String[][] {});
    }

    // store into {methods}
    methods.put(name, this);
}

From source file:com.nesscomputing.syslog4j.server.impl.event.SyslogServerEvent.java

protected void parseHost() {
    int i = this.message.indexOf(' ');

    if (i > -1) {
        String hostAddress = null;
        String hostName = null;/*from  w  w w  .j a v  a2 s  .  com*/

        String providedHost = StringUtils.trimToEmpty(this.message.substring(0, i));

        hostAddress = this.inetAddress.getHostAddress();

        if (providedHost.equalsIgnoreCase(hostAddress)) {
            this.host = hostAddress;
            this.message = this.message.substring(i + 1);
            isHostStrippedFromMessage = true;
        }

        if (this.host == null) {
            hostName = this.inetAddress.getHostName();

            if (!hostName.equalsIgnoreCase(hostAddress)) {
                if (providedHost.equalsIgnoreCase(hostName)) {
                    this.host = hostName;
                    this.message = this.message.substring(i + 1);
                    isHostStrippedFromMessage = true;
                }

                if (this.host == null) {
                    int j = hostName.indexOf('.');

                    if (j > -1) {
                        hostName = hostName.substring(0, j);
                    }

                    if (providedHost.equalsIgnoreCase(hostName)) {
                        this.host = hostName;
                        this.message = this.message.substring(i + 1);
                        isHostStrippedFromMessage = true;
                    }
                }
            }
        }

        if (this.host == null) {
            this.host = (hostName != null) ? hostName : hostAddress;
        }
    }
}

From source file:com.omertron.themoviedbapi.model.PersonCredit.java

public void setMovieOriginalTitle(String movieOriginalTitle) {
    this.movieOriginalTitle = StringUtils.trimToEmpty(movieOriginalTitle);
}

From source file:com.nesscomputing.syslog4j.impl.unix.socket.UnixSocketSyslogConfig.java

public void setType(String type) {
    if (type == null) {
        throw new SyslogRuntimeException("Type cannot be null for class \"%s\"", this.getClass().getName());
    }//from   w  ww .j a  v a  2 s.  c om

    if ("SOCK_STREAM".equalsIgnoreCase(StringUtils.trimToEmpty(type))) {
        this.type = SyslogConstants.SOCK_STREAM;

    } else if ("SOCK_DGRAM".equalsIgnoreCase(StringUtils.trimToEmpty(type))) {
        this.type = SyslogConstants.SOCK_DGRAM;

    } else {
        throw new SyslogRuntimeException("Type must be \"SOCK_STREAM\" or \"SOCK_DGRAM\" for class \"%s\"",
                this.getClass().getName());
    }
}

From source file:net.community.chest.gitcloud.facade.ServletUtils.java

public static final Map<String, String> getResponseHeaders(HttpServletResponse rsp) {
    // NOTE: map must be case insensitive as per HTTP requirements
    Map<String, String> hdrsMap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    for (String hdrName : rsp.getHeaderNames()) {
        String hdrValue = rsp.getHeader(hdrName);
        hdrsMap.put(capitalizeHttpHeaderName(hdrName), StringUtils.trimToEmpty(hdrValue));
    }/*from   ww  w .  j a  va 2 s . c o  m*/

    return hdrsMap;
}