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:net.gtaun.shoebill.ShoebillArtifactLocator.java

private File getArtifactJarFileFromMavenLocalRepo(String coord, File dir) {
    String[] tokens = coord.split(":");
    if (tokens.length != 3)
        return null;

    String groupId = tokens[0];/* w  w  w .  j  a  v a 2s . c  om*/
    String artifactId = tokens[1];
    String version = tokens[2];

    String path = dir.getPath() + File.separator;
    String[] groupTokens = StringUtils.split(groupId, '.');
    for (String child : groupTokens) {
        path += child + File.separator;
    }

    path += artifactId + File.separator + version + File.separator;
    path += artifactId + "-" + version + JAR_EXTENSION;

    File file = new File(path);

    if (!file.exists())
        return null;
    return file;
}

From source file:io.wcm.devops.conga.generator.plugins.fileheader.AbstractFileHeader.java

/**
 * Extract file header from the beginning of file between comment block start and end symbol.
 * @param file File/*  w w  w.j  a  v a2  s .  c  om*/
 * @return File header or null
 */
protected final FileHeaderContext extractFileHeaderBetweenBlockStartEnd(FileContext file) {
    try {
        if (StringUtils.isNotEmpty(getCommentBlockStart()) && StringUtils.isNotEmpty(getCommentBlockEnd())) {
            String content = FileUtils.readFileToString(file.getFile(), file.getCharset());
            int insertPosition = getInsertPosition(content);
            int posBlockStart = content.indexOf(getCommentBlockStart());
            int posBlockEnd = content.indexOf(getCommentBlockEnd());
            if (posBlockStart == insertPosition && posBlockEnd > 0) {
                String fileHeader = content.substring(posBlockStart + getCommentBlockStart().length(),
                        posBlockEnd);
                List<String> lines = ImmutableList.copyOf(StringUtils.split(fileHeader, getLineBreak()));
                return new FileHeaderContext().commentLines(lines);
            }
        }
    } catch (IOException ex) {
        throw new GeneratorException("Unable to parse file header from " + FileUtil.getCanonicalPath(file), ex);
    }
    return null;
}

From source file:com.jaeksoft.searchlib.webservice.document.DocumentImpl.java

@Override
public CommonResult deleteByValue(String index, String login, String key, String field, String values) {
    String[] valueArray = StringUtils.split(values, '/');
    return deleteByValue(index, login, key, field, Arrays.asList(valueArray));
}

From source file:com.monarchapis.driver.configuration.JsonConfiguration.java

/**
 * Returns a JSON node object for a given path.
 * //from www  .j  a  v a  2s . c o  m
 * @param path
 *            The property path
 * @return the JSON node.
 */
protected JsonNode getPathNode(String path) {
    String[] parts = StringUtils.split(path, '.');
    JsonNode node = root;

    for (int i = 0; i < parts.length; i++) {
        node = node.path(parts[i]);
    }

    return node;
}

From source file:com.nesscomputing.migratory.maven.AbstractMigratoryMojo.java

protected MigratoryOption[] parseOptions(final String options) {
    final String[] optionList = StringUtils.stripAll(StringUtils.split(options, ","));

    if (optionList == null) {
        return new MigratoryOption[0];
    }//from   w  w w  .  j ava2s  .  c  om

    final MigratoryOption[] migratoryOptions = new MigratoryOption[optionList.length];
    for (int i = 0; i < optionList.length; i++) {
        migratoryOptions[i] = MigratoryOption.valueOf(optionList[i].toUpperCase(Locale.ENGLISH));
    }

    CONSOLE.debug("Parsed %s into %s", options, migratoryOptions);
    return migratoryOptions;
}

From source file:com.jkoolcloud.tnt4j.streams.transform.FuncGetObjectName.java

private static String resolveObjectName(String objectName, List<?> args) {
    String option = args.size() > 1 ? (String) args.get(1) : null;
    Options opt;/*w  ww. j  ava  2  s .com*/

    try {
        opt = StringUtils.isEmpty(option) ? Options.DEFAULT : Options.valueOf(option.toUpperCase());
    } catch (IllegalArgumentException exc) {
        opt = Options.DEFAULT;
    }

    switch (opt) {
    case FULL:
        break;
    case BEFORE:
        String sSymbol = args.size() > 2 ? (String) args.get(2) : null;
        if (StringUtils.isNotEmpty(sSymbol)) {
            objectName = StringUtils.substringBefore(objectName, sSymbol);
        }
        break;
    case AFTER:
        sSymbol = args.size() > 2 ? (String) args.get(2) : null;
        if (StringUtils.isNotEmpty(sSymbol)) {
            objectName = StringUtils.substringAfter(objectName, sSymbol);
        }
        break;
    case REPLACE:
        sSymbol = args.size() > 2 ? (String) args.get(2) : null;
        if (StringUtils.isNotEmpty(sSymbol)) {
            String rSymbol = args.size() > 3 ? (String) args.get(3) : null;
            objectName = StringUtils.replaceChars(objectName, sSymbol, rSymbol == null ? "" : rSymbol);
        }
        break;
    case SECTION:
        String idxStr = args.size() > 2 ? (String) args.get(2) : null;
        int idx;
        try {
            idx = Integer.parseInt(idxStr);
        } catch (Exception exc) {
            idx = -1;
        }

        if (idx >= 0) {
            sSymbol = args.size() > 3 ? (String) args.get(3) : null;
            String[] onTokens = StringUtils.split(objectName,
                    StringUtils.isEmpty(sSymbol) ? OBJ_NAME_TOKEN_DELIMITERS : sSymbol);
            objectName = idx < ArrayUtils.getLength(onTokens) ? onTokens[idx] : objectName;
        }
        break;
    case DEFAULT:
    default:
        idx = StringUtils.indexOfAny(objectName, OBJ_NAME_TOKEN_DELIMITERS);
        if (idx > 0) {
            objectName = StringUtils.substring(objectName, 0, idx);
        }
        break;
    }

    return objectName;
}

From source file:com.sonicle.webtop.core.sdk.ServiceVersion.java

public String getMinor() {
    if (isUndefined())
        return null;
    String[] tokens = StringUtils.split(this.version, ".");
    return tokens[1];
}

From source file:com.monarchapis.driver.util.MIMEParseTest.java

@Test
public void testSupportWildcards() {
    List<String> mimeTypesSupported = Arrays.asList(StringUtils.split("image/*,application/xml", ','));

    // match using a type wildcard
    assertEquals(MIMEParse.bestMatch(mimeTypesSupported, "image/png"), "image/*");
    // match using a wildcard for both requested and supported
    assertEquals(MIMEParse.bestMatch(mimeTypesSupported, "image/*"), "image/*");
}

From source file:catchla.yep.util.YepArrayUtils.java

@NonNull
public static double[] parseDoubleArray(final String string, final char token) {
    if (TextUtils.isEmpty(string))
        return new double[0];
    final String[] itemsStringArray = StringUtils.split(string, token);
    final double[] array = new double[itemsStringArray.length];
    for (int i = 0, j = itemsStringArray.length; i < j; i++) {
        try {//from  ww  w .  j ava 2s  . c  om
            array[i] = Double.parseDouble(itemsStringArray[i]);
        } catch (final NumberFormatException e) {
            return new double[0];
        }
    }
    return array;
}

From source file:com.quancheng.saluki.gateway.zuul.extend.StoreProxyRouteLocator.java

private List<ZuulProperties.ZuulRoute> findAll() {
    Set<ZuulRouteDto> routers = Sets.newHashSet();
    if (!hasLoaded) {
        routers.addAll(store.loadAllRoute());
        hasLoaded = true;//from  ww w  .  j  a  v a2  s  . c  o m
    } else {
        routers.addAll(store.loadTop10Route());
    }
    RouterLocalCache.getInstance().putAllRouters(routers);
    return Lists.transform(Lists.newArrayList(routers), new Function<ZuulRouteDto, ZuulProperties.ZuulRoute>() {

        @Override
        public ZuulRoute apply(ZuulRouteDto input) {
            String id = input.getRouteId();
            String path = input.getRoutePath();
            String service_id = input.getServiceId();
            String url = input.getRouteUrl();
            boolean strip_prefix = input.getStripPrefix() != null ? input.getStripPrefix() : true;
            Boolean retryable = input.getRetryAble();
            String sensitiveHeader = input.getSensitiveHeaders();
            String[] sensitiveHeaders = null;
            if (sensitiveHeader != null) {
                sensitiveHeaders = StringUtils.split(sensitiveHeader, ",");
            } else {
                sensitiveHeaders = new String[] {};
            }
            return new ZuulRoute(id, path, service_id, url, strip_prefix, retryable,
                    new HashSet<String>(Arrays.asList(sensitiveHeaders)));

        }

    });
}