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:com.gargoylesoftware.htmlunit.javascript.host.dom.DOMTokenList.java

/**
 * Returns the length property.//  w  w w  .  j a  v  a 2s  .c  om
 * @return the length
 */
@JsxGetter
public int getLength() {
    final String value = getDefaultValue(null);
    return StringUtils.split(value, whitespaceChars()).length;
}

From source file:android.databinding.tool.processing.ScopedException.java

private String createEncodedMessage() {
    ScopedErrorReport scopedError = getScopedErrorReport();
    StringBuilder sb = new StringBuilder();
    sb.append(ERROR_LOG_PREFIX).append(MSG_KEY).append(super.getMessage()).append("\n").append(FILE_KEY)
            .append(scopedError.getFilePath()).append("\n");
    if (scopedError.getLocations() != null) {
        for (Location location : scopedError.getLocations()) {
            sb.append(LOCATION_KEY).append(location.toUserReadableString()).append("\n");
        }//  w ww . j av  a2  s. c om
    }
    sb.append(ERROR_LOG_SUFFIX);
    return StringUtils.join(StringUtils.split(sb.toString(), System.lineSeparator()), " ");
}

From source file:com.refreshsf.contrib.client.types.opts.HtmlOptions.java

public List<String> ignoreCustomComments() {
    return Arrays.asList(StringUtils.split(get("ignoreCustomComments", ""), ","));
}

From source file:hk.mcc.utils.applog2es.Main.java

private static void post2ES(List<AppLog> appLogs) {
    try {/*w  w  w.java 2  s.  com*/
        // on startup
        DateTimeFormatter sdf = ISODateTimeFormat.dateTime();
        Settings settings = Settings.settingsBuilder().put("cluster.name", "my-application").build();
        //Add transport addresses and do something with the client...
        Client client = TransportClient.builder().settings(settings).build()
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));

        XContentBuilder mapping = jsonBuilder().startObject().startObject("applog").startObject("properties")
                .startObject("Url").field("type", "string").field("index", "not_analyzed").endObject()
                .startObject("Event").field("type", "string").field("index", "not_analyzed").endObject()
                .startObject("ClassName").field("type", "string").field("index", "not_analyzed").endObject()
                .startObject("UserId").field("type", "string").field("index", "not_analyzed").endObject()
                .startObject("Application").field("type", "string").field("index", "not_analyzed").endObject()
                .startObject("ecid").field("type", "string").field("index", "not_analyzed").endObject()
                .endObject().endObject().endObject();

        PutMappingResponse putMappingResponse = client.admin().indices().preparePutMapping("applog")
                .setType("applog").setSource(mapping).execute().actionGet();
        BulkRequestBuilder bulkRequest = client.prepareBulk();
        for (AppLog appLog : appLogs) {
            // either use client#prepare, or use Requests# to directly build index/delete requests
            if (appLog != null) {
                if (StringUtils.contains(appLog.getMessage(), "[CIMS_INFO] Filter Processing time")) {
                    String[] split = StringUtils.split(appLog.getMessage(), ",");
                    int elapsedTime = 0;
                    String url = "";
                    String event = "";
                    for (String token : split) {
                        if (StringUtils.contains(token, "elapsedTime")) {
                            elapsedTime = Integer.parseInt(StringUtils.substringAfter(token, "="));
                        } else if (StringUtils.contains(token, "with URL")) {
                            url = StringUtils.substringAfter(token, "=");
                        } else if (StringUtils.contains(token, "event")) {
                            event = StringUtils.substringAfter(token, "=");
                        }
                    }

                    bulkRequest.add(client.prepareIndex("applog", "applog").setSource(jsonBuilder()
                            .startObject().field("className", appLog.getClassName())
                            .field("logTime", appLog.getLogTime()).field("application", appLog.getApplication())
                            .field("code", appLog.getCode()).field("message", appLog.getMessage())
                            .field("ecid", appLog.getEcid()).field("application", appLog.getApplication())
                            .field("level", appLog.getLevel()).field("server", appLog.getServer())
                            .field("tid", appLog.getTid()).field("userId", appLog.getUserId())
                            .field("urls", url).field("elapsedTime", elapsedTime).field("events", event)
                            .endObject()));
                }
            }
        }
        BulkResponse bulkResponse = bulkRequest.get();
        if (bulkResponse.hasFailures()) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, bulkResponse.buildFailureMessage());
            // process failures by iterating through each bulk response item
        }

        // on shutdown
        client.close();
    } catch (UnknownHostException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.norconex.importer.handler.filter.impl.EmptyMetadataFilter.java

@Override
protected void loadFilterFromXML(XMLConfiguration xml) throws IOException {
    String fieldsStr = xml.getString("[@fields]");
    String[] props = StringUtils.split(fieldsStr, ",");
    if (ArrayUtils.isEmpty(props)) {
        props = ArrayUtils.EMPTY_STRING_ARRAY;
    }/*from  w  ww .j  a v a2s  .  c o m*/
    setFields(props);
}

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

protected MigrationPlan createMigrationPlan(final String migrations) throws MojoExecutionException {
    final MigrationPlan migrationPlan = new MigrationPlan();

    if (StringUtils.isBlank(migrations)) {
        return migrationPlan;
    }/*from  www  .j a va2  s.c  om*/

    final String[] migrationNames = StringUtils.stripAll(StringUtils.split(migrations, ","));

    for (String migrationName : migrationNames) {
        final String[] migrationFields = StringUtils.stripAll(StringUtils.split(migrationName, "@"));

        if (migrationFields == null || migrationFields.length < 1 || migrationFields.length > 2) {
            throw new MojoExecutionException("Migration " + migrationName + " is invalid.");
        }

        int targetVersion = migrationFields.length == 2 ? Integer.parseInt(migrationFields[1], 10)
                : Integer.MAX_VALUE;

        final String[] priorityFields = StringUtils.stripAll(StringUtils.split(migrationFields[0], ":"));

        if (priorityFields == null || priorityFields.length < 1 || priorityFields.length > 2) {
            throw new MojoExecutionException("Migration " + migrationName + " is invalid.");
        }

        int priority = priorityFields.length == 2 ? Integer.parseInt(priorityFields[1], 10) : 0;

        migrationPlan.addMigration(priorityFields[0], targetVersion, priority);
    }

    return migrationPlan;
}

From source file:com.sonicle.webtop.core.versioning.SqlScript.java

private void readFile(InputStreamReader readable) throws IOException {
    this.statements = new ArrayList<>();
    String lines[] = null;//from  www. j  a  v  a  2s . c  o m
    StringBuilder sbsql = null;

    Scanner s = new Scanner(readable);
    s.useDelimiter("(;( )?(\r)?\n)");
    while (s.hasNext()) {
        String block = s.next();
        block = StringUtils.replace(block, "\r", "");
        if (!StringUtils.isEmpty(block)) {
            // Remove remaining ; at the end of the block (only if this block is the last one)
            if (!s.hasNext() && StringUtils.endsWith(block, ";"))
                block = StringUtils.left(block, block.length() - 1);

            sbsql = new StringBuilder();
            lines = StringUtils.split(block, "\n");
            for (String line : lines) {
                if (CommentLine.matches(line))
                    continue;
                sbsql.append(StringUtils.trim(line));
                sbsql.append(" ");
            }
            if (sbsql.length() > 0)
                statements.add(sbsql.toString());
        }
    }
}

From source file:annis.utils.LegacyGraphConverter.java

public static AnnotationGraph convertToAnnotationGraph(SDocument document) {
    List<String> matchedIDs = new ArrayList<String>();
    SFeature featMatchedIDs = document.getSFeature(ANNIS_NS, FEAT_MATCHEDIDS);
    if (featMatchedIDs != null && featMatchedIDs.getSValueSTEXT() != null) {
        matchedIDs = Arrays.asList(StringUtils.split(featMatchedIDs.getSValueSTEXT(), ','));
    }// w ww .  ja  va2 s.  c om
    SDocumentGraph docGraph = document.getSDocumentGraph();

    // get matched node names by using the IDs
    List<String> matchedNodeNames = new ArrayList<String>();
    for (String id : matchedIDs) {
        SNode node = docGraph.getSNode(id);
        if (node == null) {
            // that's weird, fallback to the id
            log.warn("Could not get matched node from id {}", id);
            matchedNodeNames.add(id);
        } else {
            matchedNodeNames.add(node.getSName());
        }
    }

    AnnotationGraph result = convertToAnnotationGraph(docGraph, matchedNodeNames);

    return result;
}

From source file:com.precioustech.fxtrading.tradingbot.social.twitter.tweethandler.SignalFactoryFXTweetHandler.java

@Override
public FXTradeTweet<String> handleTweet(Tweet tweet) {
    String tweetTxt = tweet.getText();
    String tokens[] = StringUtils.split(tweetTxt, TradingConstants.PIPE_CHR);
    if (tokens.length >= 5) {
        String action = tokens[1].trim();
        if (action.startsWith(BUY) || action.startsWith(SELL)) {
            return parseNewTrade(tokens);
        } else if (action.startsWith(CLOSE)) {
            return parseCloseTrade(tokens);
        }/*from  w  w w  .jav  a  2  s.c om*/
    }
    return null;
}

From source file:com.thinkmore.framework.orm.Page.java

/**
 * ???./*w  w w. ja  v a 2  s. c om*/
 * 
 * @param order
 *            ?descasc,?','.
 */
public void setOrder(final String order) {
    // order?
    String[] orders = StringUtils.split(StringUtils.lowerCase(order), ',');
    for (String orderStr : orders) {
        if (!StringUtils.equals(DESC, orderStr) && !StringUtils.equals(ASC, orderStr)) {
            throw new IllegalArgumentException("??" + orderStr + "??");
        }
    }
    this.order = StringUtils.lowerCase(order);
}