Example usage for org.apache.commons.lang.text StrTokenizer getTokenList

List of usage examples for org.apache.commons.lang.text StrTokenizer getTokenList

Introduction

In this page you can find the example usage for org.apache.commons.lang.text StrTokenizer getTokenList.

Prototype

public List<String> getTokenList() 

Source Link

Document

Gets a copy of the full token list as an independent modifiable list.

Usage

From source file:net.formicary.remoterun.examples.Server.java

private void closeInput(String line) {
    StrTokenizer tokenizer = new StrTokenizer(line, ' ', '"');
    @SuppressWarnings("unchecked")
    List<String> tokens = tokenizer.getTokenList();
    tokens.remove(0); // first token is the run command
    long id = Long.parseLong(tokens.remove(0));

    Collection<IAgentConnection> connectedClients = remoteRunMaster.getConnectedClients();
    if (connectedClients.isEmpty()) {
        log.error("Unable to send command: no agent connections");
    } else {/*from   w w w  .  j  a  v  a2  s .  c  o m*/
        IAgentConnection connection = connectedClients.iterator().next();
        RemoteRun.MasterToAgent.Builder builder = RemoteRun.MasterToAgent.newBuilder()
                .setMessageType(RemoteRun.MasterToAgent.MessageType.CLOSE_STDIN).setRequestId(id);
        connection.write(builder.build());
    }
}

From source file:net.formicary.remoterun.examples.Server.java

private void sendInput(String line) {
    StrTokenizer tokenizer = new StrTokenizer(line, ' ', '"');
    @SuppressWarnings("unchecked")
    List<String> tokens = tokenizer.getTokenList();
    tokens.remove(0); // first token is the run command
    long id = Long.parseLong(tokens.remove(0));
    String input = StringUtils.join(tokens, ' ').replaceAll("\\\\n", "\n");

    Collection<IAgentConnection> connectedClients = remoteRunMaster.getConnectedClients();
    if (connectedClients.isEmpty()) {
        log.error("Unable to send command: no agent connections");
    } else {//w w  w  .  jav  a2 s  . c  o m
        IAgentConnection connection = connectedClients.iterator().next();
        RemoteRun.MasterToAgent.Builder builder = RemoteRun.MasterToAgent.newBuilder()
                .setMessageType(RemoteRun.MasterToAgent.MessageType.STDIN_FRAGMENT).setRequestId(id)
                .setFragment(ByteString.copyFromUtf8(input));
        connection.write(builder.build());
    }
}

From source file:net.formicary.remoterun.examples.Server.java

private void runCommand(String line) {
    StrTokenizer tokenizer = new StrTokenizer(line, ' ', '"');
    @SuppressWarnings("unchecked")
    List<String> tokens = tokenizer.getTokenList();
    tokens.remove(0); // first token is the run command
    String command = tokens.remove(0);

    Collection<IAgentConnection> connectedClients = remoteRunMaster.getConnectedClients();
    if (connectedClients.isEmpty()) {
        log.error("Unable to send command: no agent connections");
    } else {/*from  w  w w .j a  v  a2s  .c o m*/
        IAgentConnection connection = connectedClients.iterator().next();

        RemoteRun.MasterToAgent.Builder builder = RemoteRun.MasterToAgent.newBuilder()
                .setMessageType(RemoteRun.MasterToAgent.MessageType.RUN_COMMAND)
                .setRequestId(RemoteRunMaster.getNextRequestId());
        builder.getRunCommandBuilder().setCmd(command).addAllArgs(tokens);
        connection.write(builder.build());
    }
}

From source file:com.haulmont.cuba.testsupport.TestContainer.java

protected void initAppContext() {
    EclipseLinkCustomizer.initTransientCompatibleAnnotations();

    String configProperty = AppContext.getProperty(AbstractAppContextLoader.SPRING_CONTEXT_CONFIG);

    StrTokenizer tokenizer = new StrTokenizer(configProperty);
    List<String> locations = tokenizer.getTokenList();
    locations.add(getSpringConfig());//from www  .  jav  a 2  s  . co m

    springAppContext = new CubaCoreApplicationContext(locations.toArray(new String[locations.size()]));
    AppContext.Internals.setApplicationContext(springAppContext);

    Events events = AppBeans.get(Events.NAME);
    events.publish(new AppContextInitializedEvent(springAppContext));
}

From source file:com.haulmont.cuba.core.sys.AbstractMessages.java

@Nullable
protected String searchMessage(String packs, String key, Locale locale, Locale truncatedLocale,
        Set<String> passedPacks) {
    StrTokenizer tokenizer = new StrTokenizer(packs);
    //noinspection unchecked
    List<String> list = tokenizer.getTokenList();
    Collections.reverse(list);/* w ww  .j  a  va 2 s .  c om*/
    for (String pack : list) {
        if (!enterPack(pack, locale, truncatedLocale, passedPacks))
            continue;

        String msg = searchOnePack(pack, key, locale, truncatedLocale, passedPacks);
        if (msg != null)
            return msg;

        Locale tmpLocale = truncatedLocale;
        while (tmpLocale != null) {
            tmpLocale = truncateLocale(tmpLocale);
            msg = searchOnePack(pack, key, locale, tmpLocale, passedPacks);
            if (msg != null)
                return msg;
        }
    }
    if (log.isTraceEnabled()) {
        String packName = new StrBuilder().appendWithSeparators(list, ",").toString();
        log.trace("Resource '" + makeCacheKey(packName, key, locale, locale) + "' not found");
    }
    return null;
}

From source file:org.rhq.gui.content.ContentHTTPServlet.java

protected String getLastPiece(String requestURI) {
    StrTokenizer st = new StrTokenizer(decodeURL(requestURI), "/");
    List<String> tokens = st.getTokenList();
    if (tokens.size() < 1) {
        return "";
    }/*from ww  w. j  a  va 2  s . c  o m*/
    return tokens.get(tokens.size() - 1);
}

From source file:org.rhq.gui.content.ContentHTTPServlet.java

/**
 *
 * @param requestURI//ww  w. ja va  2 s. c om
 * @return
 */
protected String getDistFilePath(String requestURI) {
    // Goal is we find where the distribution file path starts
    // then we return the entire path, it may include an unknown
    // level of sub-directories.

    StrTokenizer st = new StrTokenizer(decodeURL(requestURI), "/");
    List<String> tokens = st.getTokenList();
    if (tokens.isEmpty()) {
        return "";
    }
    int startIndex = 4;
    String distFilePath = "";
    for (int index = startIndex; index < tokens.size(); index++) {
        distFilePath = distFilePath + "/" + tokens.get(index);
        log.debug("index = " + index + ", distFilePath = " + distFilePath);
    }
    // Remove the '/' we added to the front of this string
    if (distFilePath.startsWith("/")) {
        distFilePath = distFilePath.substring(1);
    }
    return distFilePath;
}

From source file:org.rhq.gui.content.ContentHTTPServlet.java

/**
 * @param n nth element to return from requestURI, (first element corresponds to 1, not 0)
 * @param requestURI//w w  w. ja  v  a  2  s . c  o  m
 * 
 */
protected String getNthPiece(int n, String requestURI) {
    StrTokenizer st = new StrTokenizer(decodeURL(requestURI), "/");
    List<String> tokens = st.getTokenList();
    if (tokens.size() < n) {
        return "";
    }
    return tokens.get(n - 1); // caller is starting at 1 not 0
}