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

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

Introduction

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

Prototype

public static String strip(String str, String stripChars) 

Source Link

Document

Strips any of a set of characters from the start and end of a String.

Usage

From source file:org.apache.hadoop.hive.ql.udf.generic.GenericUDFTrim.java

@Override
protected String performOp(String val) {
    return StringUtils.strip(val, " ");
}

From source file:org.apache.hadoop.hive.ql.udf.UDFTrim.java

public Text evaluate(Text s) {
    if (s == null) {
        return null;
    }//w w  w  . jav  a  2s.  co m
    result.set(StringUtils.strip(s.toString(), " "));
    return result;
}

From source file:org.apache.kylin.rest.util.AdHocUtil.java

static String restoreComputedColumnToExpr(String sql, CCInfo ccInfo) {

    String ccName = ccInfo.getComputedColumnDesc().getColumnName();
    List<Triple<Integer, Integer, String>> replacements = Lists.newArrayList();
    Matcher matcher = identifierInSqlPattern.matcher(sql);

    while (matcher.find()) {
        if (matcher.group(1) != null) { //with quote case: "TABLE"."COLUMN"

            String quotedColumnName = matcher.group(3);
            Preconditions.checkNotNull(quotedColumnName);
            String columnName = StringUtils.strip(quotedColumnName, "\"");
            if (!columnName.equalsIgnoreCase(ccName)) {
                continue;
            }//from   ww  w  . ja v a 2s  . c  o  m

            if (matcher.group(2) != null) { // table name exist 
                String quotedTableAlias = StringUtils.strip(matcher.group(2), ".");
                String tableAlias = StringUtils.strip(quotedTableAlias, "\"");
                replacements.add(Triple.of(matcher.start(1), matcher.end(1), replaceIdentifierInExpr(
                        ccInfo.getComputedColumnDesc().getExpression(), tableAlias, true)));
            } else { //only column
                if (endWithAsPattern.matcher(sql.substring(0, matcher.start(1))).find()) {
                    //select DEAL_AMOUNT as "deal_amount" case
                    continue;
                }
                replacements.add(Triple.of(matcher.start(1), matcher.end(1),
                        replaceIdentifierInExpr(ccInfo.getComputedColumnDesc().getExpression(), null, true)));
            }
        } else if (matcher.group(4) != null) { //without quote case: table.column or simply column
            String columnName = matcher.group(6);
            Preconditions.checkNotNull(columnName);
            if (!columnName.equalsIgnoreCase(ccName)) {
                continue;
            }

            if (matcher.group(5) != null) { //table name exist
                String tableAlias = StringUtils.strip(matcher.group(5), ".");
                replacements.add(Triple.of(matcher.start(4), matcher.end(4), replaceIdentifierInExpr(
                        ccInfo.getComputedColumnDesc().getExpression(), tableAlias, false)));

            } else { //only column 
                if (endWithAsPattern.matcher(sql.substring(0, matcher.start(4))).find()) {
                    //select DEAL_AMOUNT as deal_amount case
                    continue;
                }
                replacements.add(Triple.of(matcher.start(4), matcher.end(4),
                        replaceIdentifierInExpr(ccInfo.getComputedColumnDesc().getExpression(), null, false)));
            }
        }
    }

    Collections.reverse(replacements);
    for (Triple<Integer, Integer, String> triple : replacements) {
        sql = sql.substring(0, triple.getLeft()) + "(" + triple.getRight() + ")"
                + sql.substring(triple.getMiddle());
    }
    return sql;
}

From source file:org.apache.kylin.rest.util.AdHocUtil.java

static String replaceIdentifierInExpr(String expr, String tableAlias, boolean quoted) {
    List<Triple<Integer, Integer, String>> replacements = Lists.newArrayList();
    Matcher matcher = identifierInExprPattern.matcher(expr);
    while (matcher.find()) {

        String t = tableAlias == null ? StringUtils.strip(matcher.group(3), ".") : tableAlias;
        String c = matcher.group(4);

        String replacement = quoted ? "\"" + t.toUpperCase() + "\".\"" + c.toUpperCase() + "\"" : t + "." + c;
        replacements.add(Triple.of(matcher.start(1), matcher.end(1), replacement));
    }/*from w  w w .  j a  va 2 s . co m*/

    Collections.reverse(replacements);
    for (Triple<Integer, Integer, String> triple : replacements) {
        expr = expr.substring(0, triple.getLeft()) + triple.getRight() + expr.substring(triple.getMiddle());
    }
    return expr;
}

From source file:org.apache.kylin.rest.util.PushDownUtil.java

static String restoreComputedColumnToExpr(String sql, ComputedColumnDesc computedColumnDesc) {

    String ccName = computedColumnDesc.getColumnName();
    List<Triple<Integer, Integer, String>> replacements = Lists.newArrayList();
    Matcher matcher = identifierInSqlPattern.matcher(sql);

    while (matcher.find()) {
        if (matcher.group(1) != null) { //with quote case: "TABLE"."COLUMN"

            String quotedColumnName = matcher.group(3);
            Preconditions.checkNotNull(quotedColumnName);
            String columnName = StringUtils.strip(quotedColumnName, "\"");
            if (!columnName.equalsIgnoreCase(ccName)) {
                continue;
            }/* w  ww.j a  va  2 s .  com*/

            if (matcher.group(2) != null) { // table name exist 
                String quotedTableAlias = StringUtils.strip(matcher.group(2), ".");
                String tableAlias = StringUtils.strip(quotedTableAlias, "\"");
                replacements.add(Triple.of(matcher.start(1), matcher.end(1),
                        replaceIdentifierInExpr(computedColumnDesc.getExpression(), tableAlias, true)));
            } else { //only column
                if (endWithAsPattern.matcher(sql.substring(0, matcher.start(1))).find()) {
                    //select DEAL_AMOUNT as "deal_amount" case
                    continue;
                }
                replacements.add(Triple.of(matcher.start(1), matcher.end(1),
                        replaceIdentifierInExpr(computedColumnDesc.getExpression(), null, true)));
            }
        } else if (matcher.group(4) != null) { //without quote case: table.column or simply column
            String columnName = matcher.group(6);
            Preconditions.checkNotNull(columnName);
            if (!columnName.equalsIgnoreCase(ccName)) {
                continue;
            }

            if (matcher.group(5) != null) { //table name exist
                String tableAlias = StringUtils.strip(matcher.group(5), ".");
                replacements.add(Triple.of(matcher.start(4), matcher.end(4),
                        replaceIdentifierInExpr(computedColumnDesc.getExpression(), tableAlias, false)));

            } else { //only column 
                if (endWithAsPattern.matcher(sql.substring(0, matcher.start(4))).find()) {
                    //select DEAL_AMOUNT as deal_amount case
                    continue;
                }
                replacements.add(Triple.of(matcher.start(4), matcher.end(4),
                        replaceIdentifierInExpr(computedColumnDesc.getExpression(), null, false)));
            }
        }
    }

    Collections.reverse(replacements);
    for (Triple<Integer, Integer, String> triple : replacements) {
        sql = sql.substring(0, triple.getLeft()) + "(" + triple.getRight() + ")"
                + sql.substring(triple.getMiddle());
    }
    return sql;
}

From source file:org.apache.reef.runtime.yarn.driver.restart.DFSEvaluatorPreserver.java

@Inject
private DFSEvaluatorPreserver(
        @Parameter(FailDriverOnEvaluatorLogErrors.class) final boolean failDriverOnEvaluatorLogErrors,
        @Parameter(JobSubmissionDirectory.class) final String jobSubmissionDirectory) {

    this.failDriverOnEvaluatorLogErrors = failDriverOnEvaluatorLogErrors;

    try {//www.  j  a  va 2 s .  c  o  m
        final org.apache.hadoop.conf.Configuration config = new org.apache.hadoop.conf.Configuration();
        this.fileSystem = FileSystem.get(config);
        this.changeLogLocation = new Path(
                "/" + StringUtils.strip(jobSubmissionDirectory, "/") + "/evaluatorsChangesLog");

        boolean appendSupported = config.getBoolean("dfs.support.append", false);

        if (appendSupported) {
            this.readerWriter = new DFSEvaluatorLogAppendReaderWriter(this.fileSystem, this.changeLogLocation);
        } else {
            this.readerWriter = new DFSEvaluatorLogOverwriteReaderWriter(this.fileSystem,
                    this.changeLogLocation);
        }
    } catch (final IOException e) {
        final String errMsg = "Cannot read from log file with Exception " + e
                + ", evaluators will not be recovered.";
        final String fatalMsg = "Driver was not able to instantiate FileSystem.";

        this.handleException(e, errMsg, fatalMsg);
        this.fileSystem = null;
        this.changeLogLocation = null;
        this.readerWriter = null;
    }
}

From source file:org.apache.tajo.engine.function.string.BTrim.java

@Override
public Datum eval(Tuple params) {
    if (params.isBlankOrNull(0)) {
        return NullDatum.get();
    }/* w w w . java  2  s  .c  o m*/

    String input = params.getText(0);
    if (!hasTrimCharacters) {
        return DatumFactory.createText(StringUtils.strip(input, null));
    } else {
        return DatumFactory.createText(StringUtils.strip(input, params.getText(1)));
    }
}

From source file:org.archive.modules.forms.ExtractorHTMLForms.java

protected String findAttributeValueGroup(String pattern, int groupNumber, CharSequence cs) {
    Matcher m = TextUtils.getMatcher(pattern, cs);
    try {/*from  ww  w . j  a v a  2s.c om*/
        if (m.find()) {
            String value = m.group(groupNumber);
            /*
             * In a case like this <input name="foo"/> the group here will
             * be "foo"/ ... it's difficult to adjust the regex to avoid
             * slurping that trailing slash, so handle it here
             */
            value = StringUtils.removeEnd(value, "'/");
            value = StringUtils.removeEnd(value, "\"/");
            value = StringUtils.strip(value, "\'\""); // strip quotes if present
            return value;
        } else {
            return null;
        }
    } finally {
        TextUtils.recycleMatcher(m);
    }
}

From source file:org.atomserver.testutils.client.JettyWebAppTestCase.java

/**
 * return the Application Spring WebApplicationContext.
 * Its a bit convoluted to get at it from here, but ultimately its doable.
 * We have to traverse from the Jetty Server, until we get to the ServletContext.
 * NOTE: this code is entirely dependent on the structure of jettyBeans.xml
 * Thus, if that Bean changes, so must this code !!!
 *//*from   w  w w  . j  a va2s  . co  m*/
protected ApplicationContext getSpringFactory() throws Exception {
    if (appSpringFactory == null) {
        Server jserver = getJettyServer();

        WebAppContext webappContext = (WebAppContext) jserver.getHandler();
        log.debug("webappContext= " + webappContext);

        servletHandler = webappContext.getServletHandler();
        log.debug("ServletHandler = " + servletHandler);

        ServletContext servletContext = servletHandler.getServletContext();
        log.debug("servletContext= " + servletContext);

        servletContextName = servletContext.getServletContextName();
        if (servletContextName == null) {
            throw new RuntimeException("No servletContextName defined for atomserver");
        }
        // will come back as e.g. /atomserver/
        servletContextName = StringUtils.strip(servletContextName, "/");
        log.debug("****************** servletContextName= " + servletContextName);

        appSpringFactory = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    }
    return appSpringFactory;
}

From source file:org.cloudifysource.dsl.utils.IPUtils.java

/**
 * Chechs if the given address is an IPv6 address.
 * @param ipAddress IP address//  w  w w .j a  v  a 2 s . c  o m
 * @return True is the address represents and IPv6 address, False otherwise
 */
public static boolean isIPv6Address(final String ipAddress) {

    boolean isIPv6 = false;

    String strippedIp = StringUtils.strip(ipAddress, "[]");
    if (strippedIp.indexOf(NETWORK_INTERFACE_SEPARATOR) > -1) {
        strippedIp = StringUtils.substringBefore(strippedIp, NETWORK_INTERFACE_SEPARATOR);
    }

    try {
        IPv6Address.fromString(strippedIp);
        isIPv6 = true;
    } catch (IllegalArgumentException e) {
        //this is not a valid IPv6 address
    }

    return isIPv6;
}