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

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

Introduction

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

Prototype

public static String[] split(final String str, final String separatorChars) 

Source Link

Document

Splits the provided text into an array, separators specified.

Usage

From source file:cn.com.infcn.ade.common.persistence.Page.java

/**
 * ???.//from  w ww .  j  a va 2s .c  o m
 * 
 * @param order ?descasc,?','.
 */
public void setOrder(final String order) {
    String lowcaseOrder = StringUtils.lowerCase(order);

    //order?
    String[] orders = StringUtils.split(lowcaseOrder, ',');
    for (String orderStr : orders) {
        if (!StringUtils.equals(DESC, orderStr) && !StringUtils.equals(ASC, orderStr)) {
            throw new IllegalArgumentException("??" + orderStr + "??");
        }
    }

    this.order = lowcaseOrder;
}

From source file:info.magnolia.security.app.dialog.action.SaveGroupDialogAction.java

private String[] itemPropertyToArray(JcrNodeAdapter item, String propertyName) {
    String identifiers = item.getItemProperty(propertyName).getValue().toString();
    identifiers = StringUtils.remove(identifiers, '[');
    identifiers = StringUtils.remove(identifiers, ']');
    return StringUtils.split(identifiers, ',');
}

From source file:org.meruvian.yama.core.application.Application.java

@Transient
public Set<String> getScopes() {
    String[] scopes = StringUtils.split(this.scopes, ',');
    if (scopes == null)
        return new LinkedHashSet<String>();

    return new LinkedHashSet<String>(Arrays.asList(scopes));
}

From source file:com.mingo.convert.ConversionUtils.java

/**
 * Convert specified field from source.//from  w ww. ja va 2s  .c o  m
 *
 * @param type      they type to convert the given source to.
 * @param field     field name in source. supports using of nested paths: "field1.field2.field3"
 * @param source    source the source to create an object of the given type from.
 * @param converter converter
 * @param <T>       the type of the class modeled by this {@code Class} object.
 * @return converted object
 */
public static <T> T convertField(Class<T> type, String field, DBObject source, Converter<T> converter) {
    String[] paths = StringUtils.split(field, ".");
    for (String path : paths) {
        DBObject child = getAsDBObject(path, source);
        if (child != null) {
            source = child;
        } else {
            break;
        }
    }
    return converter.convert(type, source);
}

From source file:com.taobao.android.utils.PathMatcher.java

public boolean match(String pattern, String str) {
    if (str == null) {
        return false;
    }//from   w  ww  .j a v  a  2  s.  c o m
    if (pattern == null) {
        return false;
    }
    if (str.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator)) {
        return false;
    }

    String[] patDirs = StringUtils.split(pattern, this.pathSeparator);
    String[] strDirs = StringUtils.split(str, this.pathSeparator);

    int patIdxStart = 0;
    int patIdxEnd = patDirs.length - 1;
    int strIdxStart = 0;
    int strIdxEnd = strDirs.length - 1;

    // Match all elements up to the first **
    while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
        String patDir = (String) patDirs[patIdxStart];
        if (patDir.equals("**")) {
            break;
        }
        if (!matchStrings(patDir, (String) strDirs[strIdxStart])) {
            return false;
        }
        patIdxStart++;
        strIdxStart++;
    }

    if (strIdxStart > strIdxEnd) {
        // String is exhausted, only match if rest of pattern is * or **'s
        if (patIdxStart == patIdxEnd && patDirs[patIdxStart].equals("*") && str.endsWith(this.pathSeparator)) {
            return true;
        }
        for (int i = patIdxStart; i <= patIdxEnd; i++) {
            if (!patDirs[i].equals("**")) {
                return false;
            }
        }
        return true;
    } else {
        if (patIdxStart > patIdxEnd) {
            // String not exhausted, but pattern is. Failure.
            return false;
        }
    }

    // up to last '**'
    while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
        String patDir = (String) patDirs[patIdxEnd];
        if (patDir.equals("**")) {
            break;
        }
        if (!matchStrings(patDir, (String) strDirs[strIdxEnd])) {
            return false;
        }
        patIdxEnd--;
        strIdxEnd--;
    }
    if (strIdxStart > strIdxEnd) {
        // String is exhausted
        for (int i = patIdxStart; i <= patIdxEnd; i++) {
            if (!patDirs[i].equals("**")) {
                return false;
            }
        }
        return true;
    }

    while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) {
        int patIdxTmp = -1;
        for (int i = patIdxStart + 1; i <= patIdxEnd; i++) {
            if (patDirs[i].equals("**")) {
                patIdxTmp = i;
                break;
            }
        }
        if (patIdxTmp == patIdxStart + 1) {
            // '**/**' situation, so skip one
            patIdxStart++;
            continue;
        }
        // Find the pattern between padIdxStart & padIdxTmp in str between
        // strIdxStart & strIdxEnd
        int patLength = (patIdxTmp - patIdxStart - 1);
        int strLength = (strIdxEnd - strIdxStart + 1);
        int foundIdx = -1;
        strLoop: for (int i = 0; i <= strLength - patLength; i++) {
            for (int j = 0; j < patLength; j++) {
                String subPat = (String) patDirs[patIdxStart + j + 1];
                String subStr = (String) strDirs[strIdxStart + i + j];
                if (!matchStrings(subPat, subStr)) {
                    continue strLoop;
                }
            }

            foundIdx = strIdxStart + i;
            break;
        }

        if (foundIdx == -1) {
            return false;
        }

        patIdxStart = patIdxTmp;
        strIdxStart = foundIdx + patLength;
    }

    for (int i = patIdxStart; i <= patIdxEnd; i++) {
        if (!patDirs[i].equals("**")) {
            return false;
        }
    }

    return true;
}

From source file:com.khs.sherpa.servlet.SherpaRequest.java

public void loadRequest(HttpServletRequest request, HttpServletResponse response) {

    String urlMethod = ReflectionCache.getUrlMethod(UrlUtil.getPath(request), request.getMethod());
    if (StringUtils.isNotEmpty(urlMethod)) {
        String[] str = StringUtils.split(urlMethod, ".");
        this.setEndpoint(str[0]);
        this.setAction(str[1]);
    } else {/*ww  w  . j av  a  2  s  . c o m*/
        this.setEndpoint(request.getParameter("endpoint"));
        this.setAction(request.getParameter("action"));
    }

    this.setServletRequest(request);
    this.setServletResponse(response);
}

From source file:name.martingeisse.stackd.client.console.Console.java

/**
 * Prints the specified string on the console.
 * @param s the string to print//from  www .  j a  va 2  s.  com
 */
public final void print(final String s) {
    for (final String line : StringUtils.split(s, '\n')) {
        outputLines.add(line);
    }
    while (outputLines.size() > 15) {
        outputLines.poll();
    }
}

From source file:com.anrisoftware.globalpom.version.VersionFormat.java

private Version decodeVersion(String source, ParsePosition pos) {
    String[] str = StringUtils.split(source, VERSION_SEP);
    int major = Integer.valueOf(str[0]);
    int minor = Integer.MAX_VALUE;
    int rev = Integer.MAX_VALUE;
    if (str.length > 1) {
        minor = Integer.valueOf(str[1]);
    }//from   ww w .  j a v a2 s.c om
    if (str.length > 2) {
        rev = Integer.valueOf(str[2]);
    }
    return versionFactory.create(major, minor, rev);
}

From source file:com.cognifide.aet.job.common.datafilters.removelines.RemoveLinesDataModifier.java

private String modify(String data, Set<Integer> indexesToRemove) {
    List<String> lines = Arrays.asList(StringUtils.split(data, NEWLINE));
    Set<Integer> dataIndexes = ContiguousSet.create(Range.closed(1, lines.size()), DiscreteDomain.integers());
    if (!dataIndexes.containsAll(indexesToRemove)) {
        LOGGER.warn("Some of defined ranges exceed source lenght. Source length is: " + lines.size());
    }/*w ww.  j  ava 2  s . c om*/
    Set<Integer> filtereedIndexesToRemove = Sets.intersection(dataIndexes, indexesToRemove);
    List<String> modifiedLines = new ArrayList<String>(lines.size() - filtereedIndexesToRemove.size());
    for (int i = 0; i < lines.size(); i++) {
        if (!filtereedIndexesToRemove.contains(i + 1)) {
            modifiedLines.add(lines.get(i));
        }
    }
    return StringUtils.join(modifiedLines, NEWLINE);
}

From source file:com.jdy.ddj.common.orm.PageRequest.java

/**
 * ??.//from w  ww  .  jav  a  2 s.c  om
 */
public List<Sort> getSort() {
    String[] orderBys = StringUtils.split(orderBy, ',');
    String[] orderDirs = StringUtils.split(orderDir, ',');
    Validate.isTrue(orderBys.length == orderDirs.length,
            "???,????");

    List<Sort> orders = Lists.newArrayList();
    for (int i = 0; i < orderBys.length; i++) {
        orders.add(new Sort(orderBys[i], orderDirs[i]));
    }

    return orders;
}