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

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

Introduction

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

Prototype

public StrTokenizer(char[] input, StrMatcher delim, StrMatcher quote) 

Source Link

Document

Constructs a tokenizer splitting using the specified delimiter matcher and handling quotes using the specified quote matcher.

Usage

From source file:it.jnrpe.utils.StringUtils.java

/**
 * Splits the given string using as separator the <code>separator</code>
 * character./*from  ww  w .  java  2 s  .c  o m*/
 * 
 * @param string
 *            The string to be splitted
 * @param separator
 *            The separator character
 * @param ignoreQuotes
 *            <code>true</code> if the quotes must be ignored.
        
 * @return The splitted string */
public static String[] split(final String string, final char separator, final boolean ignoreQuotes) {
    StrTokenizer strtok = new StrTokenizer(string, StrMatcher.charMatcher(separator),
            StrMatcher.quoteMatcher());
    return strtok.getTokenArray();
}

From source file:it.jnrpe.server.console.CommandExecutor.java

public boolean executeCommand(String commandLine) throws Exception {
    StrTokenizer strtok = new StrTokenizer(commandLine, StrMatcher.charMatcher(' '), StrMatcher.quoteMatcher());
    String[] tokensAry = strtok.getTokenArray();
    String commandName = tokensAry[0];
    String[] params;/*from ww  w .jav a2s .  c o  m*/
    if (tokensAry.length == 1) {
        params = new String[0];
    } else {
        params = new String[tokensAry.length - 1];
        System.arraycopy(tokensAry, 1, params, 0, params.length);
    }

    IConsoleCommand command = getCommand(commandName);
    if (command != null) {
        return command.execute(params);
    } else {
        throw new UnknownCommandException("Unknown command :'" + commandName + "'");
    }
}

From source file:com.thed.plugin.QtpZephyrInterceptor.java

/**
 * This method gets called once for each testcase and is the start of the automation for that testcase.
 * In this custom ZIP, we are able to make to determine based on the provided script path whether the
 * automation being ran is QTP or Selenium
 * It updates the Zbot agent real-time status with the current testcase id and name
  * to <b>'STATUS: Script execution starting...'</b> before executing the testcase.
 *//*from  ww w .  j a v  a  2 s.co  m*/
@Override
public void testcaseExecutionStart() {
    currentTcExecutionResult = null;
    comments = "";
    if ((currentTestcaseExecution.getScriptPath() != null)) {
        String[] arguments = new StrTokenizer(currentTestcaseExecution.getScriptPath(), ' ', '"')
                .getTokenArray();

        if (currentTestcaseExecution.getScriptPath().contains("cmdrv.exe")
                || currentTestcaseExecution.getScriptPath().contains("qtRunner")) {
            type = "qtp";
            outputPath = arguments[arguments.length - 1];
        } else {
            type = "selenium";
            if (arguments.length > 2) {
                outputPath = arguments[arguments.length - 1] + File.separator + arguments[arguments.length - 2]
                        + "_result.txt";
            } else {
                outputPath = "";
            }
        }
        logger.info("Test type is determined " + type);
        logger.info("outputPath " + outputPath);
    }
}

From source file:de.sub.goobi.helper.GoobiScript.java

/**
 * Starten des Scripts./* w  ww . j  a v  a  2  s.co  m*/
 */
public void execute(List<Process> inProzesse, String inScript) throws DataException {
    this.myParameters = new HashMap<>();
    /*
     * alle Suchparameter zerlegen und erfassen
     */
    StrTokenizer tokenizer = new StrTokenizer(inScript, ' ', '\"');
    while (tokenizer.hasNext()) {
        String tok = tokenizer.nextToken();
        if (!tok.contains(":")) {
            Helper.setFehlerMeldung("kitodoScriptfield", "missing delimiter / unknown parameter: ", tok);
        } else {
            String myKey = tok.substring(0, tok.indexOf(":"));
            String myValue = tok.substring(tok.indexOf(":") + 1);
            this.myParameters.put(myKey, myValue);
        }
    }

    /*
     * die passende Methode mit den richtigen Parametern bergeben
     */
    if (this.myParameters.get("action") == null) {
        Helper.setFehlerMeldung("kitodoScriptfield", "missing action",
                " - possible: 'action:swapsteps, action:adduser, action:addusergroup, "
                        + "action:swapprozessesout, action:swapprozessesin, action:deleteTiffHeaderFile, "
                        + "action:importFromFileSystem'");
        return;
    }

    /*
     * Aufruf der richtigen Methode ber den Parameter
     */
    if (this.myParameters.get("action").equals("swapSteps")) {
        swapSteps(inProzesse);
    } else if (this.myParameters.get("action").equals("importFromFileSystem")) {
        importFromFileSystem(inProzesse);
    } else if (this.myParameters.get("action").equals("addUser")) {
        adduser(inProzesse);
    } else if (this.myParameters.get("action").equals("addUserGroup")) {
        addusergroup(inProzesse);
    } else if (this.myParameters.get("action").equals("setTaskProperty")) {
        setTaskProperty(inProzesse);
    } else if (this.myParameters.get("action").equals("deleteStep")) {
        deleteStep(inProzesse);
    } else if (this.myParameters.get("action").equals("addStep")) {
        addStep(inProzesse);
    } else if (this.myParameters.get("action").equals("setStepNumber")) {
        setStepNumber(inProzesse);
    } else if (this.myParameters.get("action").equals("setStepStatus")) {
        setStepStatus(inProzesse);
    } else if (this.myParameters.get("action").equals("addShellScriptToStep")) {
        addShellScriptToStep(inProzesse);
    } else if (this.myParameters.get("action").equals("addModuleToStep")) {
        addModuleToStep(inProzesse);
    } else if (this.myParameters.get("action").equals("updateImagePath")) {
        updateImagePath(inProzesse);
    } else if (this.myParameters.get("action").equals("updateContentFiles")) {
        updateContentFiles(inProzesse);
    } else if (this.myParameters.get("action").equals("deleteTiffHeaderFile")) {
        deleteTiffHeaderFile(inProzesse);
    } else if (this.myParameters.get("action").equals("setRuleset")) {
        setRuleset(inProzesse);
    } else if (this.myParameters.get("action").equals("exportDms")) {
        exportDms(inProzesse, this.myParameters.get("exportImages"), true);
    } else if (this.myParameters.get("action").equals("export")) {
        exportDms(inProzesse, this.myParameters.get("exportImages"),
                Boolean.valueOf(this.myParameters.get("exportOcr")));
    } else if (this.myParameters.get("action").equals("doit")) {
        exportDms(inProzesse, "false", false);
    } else if (this.myParameters.get("action").equals("doit2")) {
        exportDms(inProzesse, "false", true);

    } else if (this.myParameters.get("action").equals("runscript")) {
        String stepname = this.myParameters.get("stepname");
        String scriptname = this.myParameters.get("script");
        if (stepname == null) {
            Helper.setFehlerMeldung("kitodoScriptfield", "", "Missing parameter");
        } else {
            runScript(inProzesse, stepname, scriptname);
        }
    } else if (this.myParameters.get("action").equals("deleteProcess")) {
        String value = myParameters.get("contentOnly");
        boolean contentOnly = true;
        if (value != null && value.equalsIgnoreCase("false")) {
            contentOnly = false;
        }
        deleteProcess(inProzesse, contentOnly);
    } else {
        Helper.setFehlerMeldung("kitodoScriptfield", "Unknown action",
                " - use: 'action:swapsteps, action:adduser, action:addusergroup, "
                        + "action:swapprozessesout, action:swapprozessesin, action:deleteTiffHeaderFile, "
                        + "action:importFromFileSystem'");
        return;
    }

    Helper.setMeldung("kitodoScriptfield", "", "kitodoScript finished");
}

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 {/*w w  w .jav  a 2s.  c om*/
        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: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 {/* www.  j  av  a  2 s.  c om*/
        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 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 ww.  j  av  a  2  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:org.apache.felix.sigil.eclipse.preferences.PrefsUtils.java

public static final String[] stringToArray(String string) {
    StrTokenizer tokenizer = new StrTokenizer(string, ',', '"');
    String[] array = new String[tokenizer.size()];

    for (int i = 0; i < array.length; i++) {
        array[i] = tokenizer.nextToken();
    }//from   w  w w . j  a v a2s.c om

    return array;
}

From source file:org.apache.hadoop.hive.metastore.tools.TestSchemaToolForMetastore.java

private void execute(SchemaToolTask task, String taskArgs) throws HiveMetaException {
    try {//ww  w  .  java 2 s  .c om
        StrTokenizer tokenizer = new StrTokenizer(argsBase + taskArgs, ' ', '\"');
        SchemaToolCommandLine cl = new SchemaToolCommandLine(tokenizer.getTokenArray(), null);
        task.setCommandLineArguments(cl);
    } catch (Exception e) {
        throw new IllegalStateException("Could not parse comman line \n" + argsBase + taskArgs, e);
    }

    task.setHiveSchemaTool(schemaTool);
    task.execute();
}

From source file:org.eclipse.skalli.services.search.SearchQuery.java

StrTokenizer getTokenizer() {
    StrTokenizer tokenizer = new StrTokenizer("", StrMatcher.commaMatcher(), StrMatcher.quoteMatcher());
    tokenizer.setTrimmerMatcher(StrMatcher.trimMatcher());
    return tokenizer;
}