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

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

Introduction

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

Prototype

public static String[] splitPreserveAllTokens(String str, String separatorChars) 

Source Link

Document

Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators.

Usage

From source file:org.calrissian.flowmix.api.aggregator.AbstractAggregator.java

/**
 *
 * @param configuration/*  w ww. j a v a2s .c  o  m*/
 */
@Override
public void configure(Map<String, String> configuration) {
    if (configuration.get(GROUP_BY) != null) {
        groupByFields = StringUtils.splitPreserveAllTokens(configuration.get(GROUP_BY), GROUP_BY_DELIM);
    }
    if (configuration.get(OUTPUT_FIELD) != null) {
        outputField = configuration.get(OUTPUT_FIELD);
    }
    if (configuration.get(OPERATED_FIELD) != null) {
        operatedField = configuration.get(OPERATED_FIELD);
    } else {
        throw new RuntimeException(
                "Aggregator needs a field to operate it. Property missing: " + OPERATED_FIELD);
    }
}

From source file:org.calrissian.flowmix.api.aggregator.CountAggregator.java

@Override
public void configure(Map<String, String> configuration) {

    if (configuration.get(GROUP_BY) != null)
        groupByFields = StringUtils.splitPreserveAllTokens(configuration.get(GROUP_BY), GROUP_BY_DELIM);

    if (configuration.get(OUTPUT_FIELD) != null)
        outputField = configuration.get(OUTPUT_FIELD);
}

From source file:org.calrissian.flowmix.api.aggregator.LongSumAggregator.java

@Override
public void configure(Map<String, String> configuration) {

    if (configuration.get(GROUP_BY) != null)
        groupByFields = StringUtils.splitPreserveAllTokens(configuration.get(GROUP_BY), GROUP_BY_DELIM);

    if (configuration.get(OUTPUT_FIELD) != null)
        outputField = configuration.get(OUTPUT_FIELD);

    if (configuration.get(SUM_FIELD) != null)
        sumField = configuration.get(SUM_FIELD);
    else// w ww.  j a v a  2  s .co m
        throw new RuntimeException("Sum aggregator needs a field to sum. Property missing: " + SUM_FIELD);

}

From source file:org.dhatim.edisax.BufferedSegmentReaderTest.java

public void test_split() {
    Arrays.asList(StringUtils.splitPreserveAllTokens("a*b***C*d", "*"));
}

From source file:org.exem.flamingo.web.filesystem.hdfs.HdfsFileSystemServiceImpl.java

/**
 * ?    ?? ?? ?.//from  ww  w . j a v  a2s .com
 *
 * @param path  
 */
private void validateForbiddenPath(String path) {
    String[] paths = StringUtils.splitPreserveAllTokens(configurationHelper.get("hdfs.delete.forbidden.paths"),
            ",");
    AntPathMatcher antPathMatcher = new AntPathMatcher();

    for (String pathToValid : paths) {
        boolean isMatch = antPathMatcher.match(path, pathToValid);
        if (isMatch) {
            throw new ServiceException("A directory is contained in the banned directory list.");
        }
    }
}

From source file:org.exoplatform.wiki.service.diff.DiffService.java

/**
 * Return a DiffResult object representing word diffs between text1 and text2
 * @param text1 original content//from  ww  w  . j a  va2s .  c  o m
 * @param text2 revised content
 * @return list of Delta objects
 * @throws DifferentiationFailedException 
 */
public DiffResult getWordDifferencesAsHTML(String text1, String text2) throws DifferentiationFailedException {
    int changes = 0;
    text1 = "~~PLACEHOLDER~~" + text1 + "~~PLACEHOLDER~~";
    text2 = "~~PLACEHOLDER~~" + text2 + "~~PLACEHOLDER~~";

    StringBuffer html = new StringBuffer("<div class=\"diffmodifiedline\">");
    List list = getWordDifferencesAsList(text1, text2);
    String[] words = StringUtils.splitPreserveAllTokens(text1, ' ');
    int cursor = 0;
    boolean addSpace = false;

    for (int i = 0; i < list.size(); i++) {
        if (addSpace) {
            html.append(" ");
            addSpace = false;
        }

        Delta delta = (Delta) list.get(i);
        boolean isChangeDelta = (delta instanceof ChangeDelta);
        int position = delta.getOriginal().anchor();
        // First we fill in all text that has not been changed
        while (cursor < position) {
            html.append(escape(words[cursor]));
            html.append(" ");
            cursor++;
        }
        // Then we fill in what has been removed
        Chunk orig = delta.getOriginal();
        if (orig.size() > 0) {
            html.append("<span class=\"diffremoveword\">");
            List chunks = orig.chunk();
            for (int j = 0; j < chunks.size(); j++) {
                if (j > 0)
                    html.append(" ");
                html.append(escape((String) chunks.get(j)));
                cursor++;
            }
            changes++;
            html.append("</span>");
            addSpace = true;
        }

        // Then we fill in what has been added
        Chunk rev = delta.getRevised();
        if (rev.size() > 0) {
            html.append("<span class=\"diffaddword\">");
            List chunks = rev.chunk();
            for (int j = 0; j < chunks.size(); j++) {
                if (j > 0)
                    html.append(" ");
                html.append(escape((String) chunks.get(j)));
            }
            // If is changeDelta, only add change 1 times
            if (!isChangeDelta)
                changes++;
            html.append("</span>");
            addSpace = true;
        }
    }

    // First we fill in all text that has not been changed
    while (cursor < words.length) {
        if (addSpace)
            html.append(" ");
        html.append(escape(words[cursor]));
        addSpace = true;
        cursor++;
    }

    html.append("</div>");
    return new DiffResult(html.toString().replaceAll("~~PLACEHOLDER~~", ""), changes);
}

From source file:org.fcrepo.oai.service.OAIProviderService.java

public static ResumptionToken decodeResumptionToken(String token) throws UnsupportedEncodingException {
    String[] data = StringUtils.splitPreserveAllTokens(new String(Base64.decodeBase64(token)), ':');
    final String verb = urlDecode(data[0]);
    final String metadataPrefix = urlDecode(data[1]);
    final String from = urlDecode(data[2]);
    final String until = urlDecode(data[3]);
    final String set = urlDecode(data[4]);
    final int offset = Integer.parseInt(urlDecode(data[5]));
    return new ResumptionToken(verb, metadataPrefix, from, until, offset, set);
}

From source file:org.gradle.nativeplatform.test.xctest.internal.execution.XCTestSelection.java

private String prepareIncludedTest(String testFilter, Set<String> testSuiteCache) {
    String[] tokens = StringUtils.splitPreserveAllTokens(testFilter, '.');
    if (tokens.length > 3) {
        throw new IllegalArgumentException(
                String.format("'%s' is an invalid pattern. Patterns should have one or two dots.", testFilter));
    } else if (tokens.length == 3) {
        if (WILDCARD.equals(tokens[2])) {
            String filter = tokens[0] + "." + tokens[1];
            testSuiteCache.add(filter);//from w  ww  . j a va  2s. c o m
            return filter;
        } else if (tokens[2].isEmpty()) {
            return testFilter;
        }
        return tokens[0] + "." + tokens[1] + "/" + tokens[2];
    } else if (tokens.length == 2 && !WILDCARD.equals(tokens[1])) {
        testSuiteCache.add(testFilter);
    }

    return testFilter;
}

From source file:org.hippoecm.frontend.plugins.cms.dashboard.BrowseLinkTarget.java

public String getDisplayPath() {
    String path;/*from   w ww.j  av a 2s . c o m*/
    try {
        path = getNode().getPath();
    } catch (ItemNotFoundException e) {
        path = getNodeModel().getItemModel().getPath();
    } catch (RepositoryException e) {
        log.error(e.getMessage(), e);
        path = getNodeModel().getItemModel().getPath();
    }

    String[] elements = StringUtils.splitPreserveAllTokens(path, '/');
    for (int i = 0; i < elements.length; i++) {
        elements[i] = NodeNameCodec.decode(elements[i]);
    }
    return StringUtils.join(elements, '/');
}

From source file:org.jannocessor.service.render.TemplateHelper.java

public String indent(String code, String prefix) {

    StringBuilder sb = new StringBuilder();

    String[] lines = StringUtils.splitPreserveAllTokens(code, "\n");
    for (int i = 0; i < lines.length; i++) {
        String line = lines[i];// w  w  w  .  j a  va  2s.c  o m

        if (!StringUtils.isWhitespace(line)) {
            line = prefix + line;
        }
        sb.append(line);

        if (i < lines.length - 1) {
            sb.append("\n");
        }
    }

    return sb.toString();
}