protected List parseTokens()

in src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java [485:510]


    protected List<CommandExecutorImpl.Token> parseTokens(String... commands) {
        List<CommandExecutorImpl.Token> returnValue = new ArrayList<>();
        String cat = String.join(EMPTY, commands);
        for (String token : cat.split(PIPE_SEPARATOR)){
            CommandExecutorImpl.Token currentToken = new CommandExecutorImpl.Token();
            String[] options = token.split(PARAMS_SEPARATOR);
            if (options.length > 1) {
                currentToken.options = getOptions(Arrays.copyOfRange(options, 1, options.length));
            }
            List<String> subTokens = getSpaceSeparatedTokens(options[0]);
            if (! subTokens.isEmpty()) {
                currentToken.pipeKey = subTokens.get(0);
                if (subTokens.size() > 1) {
                    currentToken.args = subTokens.subList(1, subTokens.size());
                    if (JSON_EXPR_KEYS.contains(currentToken.pipeKey) &&
                            JSON_START.indexOf(currentToken.args.get(0).getBytes(StandardCharsets.UTF_8)[0]) > 0) {
                        //in that case we want to concatenate all subsequent 'args' as it is a JSON expression
                        currentToken.args = Collections.singletonList(String.join(EMPTY, currentToken.args));
                    }
                }
            }
            log.trace("generated following token {}", currentToken);
            returnValue.add(currentToken);
        }
        return returnValue;
    }