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.openflamingo.el.ELServiceImpl.java

/**
 * Comma Separated String?  ./*from w  w w . ja va2s .c o m*/
 *   Trim  .
 *
 * @param commaSeparatedList Comma Separated String
 * @return ? 
 */
private String[] split(String commaSeparatedList) {
    List<String> params = new ArrayList<String>();
    String[] values = StringUtils.splitPreserveAllTokens(commaSeparatedList.trim(), ",");
    for (String value : values) {
        params.add(value.trim());
    }
    return org.openflamingo.util.StringUtils.collectionToStringArray(params);
}

From source file:org.openflamingo.engine.dag.TSWorkflowExecutionPlanner.java

/**
 *  ??. ?  ??    ?/*  ww  w  .j av a 2 s . c o  m*/
 *  ?   ?   ?  ?.
 *
 * @param workflow Workflow XML JAXB Object
 * @throws Exception    
 */
public TSWorkflowExecutionPlanner(Workflow workflow) throws Exception {
    this.workflow = workflow;
    this.namesOfActions = new LinkedList<String>();
    this.orderedActions = new LinkedList<BaseType>();
    this.actionMap = new HashMap<String, Object>();
    this.reversedActions = new HashMap<String, String>();
    this.nextOfAction = new HashMap<String, String>();
    this.iterator = new TopologicalOrderIterator(createGraph());

    // ? ? Action Name? ?.   ? ? ?.
    while (iterator.hasNext()) {
        namesOfActions.add((String) iterator.next());
    }

    // ? ?   ?   .
    for (String currentAction : namesOfActions) {
        if (actionMap.get(currentAction) instanceof NodeType) {
            //     ?? ?   .
            NodeType node = (NodeType) actionMap.get(currentAction);
            String[] tos = StringUtils.splitPreserveAllTokens(node.getTo(), ',');

            // ?? ? ?  ?   ? ?   .
            for (String to : tos) {
                String reversedActions = buildReversedActions(this.reversedActions.get(to), currentAction);
                this.reversedActions.put(to, reversedActions);
            }

            // ?  for        ?  ?.
            orderedActions.add((BaseType) actionMap.get(currentAction));
        } else { // BaseType ?  ?  End  ? .
            // ?  for        ?  ?.
            orderedActions.add((BaseType) actionMap.get(currentAction));
        }
    }
}

From source file:org.openflamingo.engine.dag.TSWorkflowExecutionPlanner.java

/**
 *    ? ?  ?  ?  ?? .// w w w  .j a  v  a 2  s .  c om
 *    (node1) ?? ?  node2? node2  ?   .
 * ?  ? node2? ?  node1    ?  ??  ?.
 * Hadoop  Workflow? ? ?    ?     ? .
 *
 * @param predecessor  ? ? 
 * @param current      
 * @return    ? ?  ?  ?  ?
 */
private String buildReversedActions(String predecessor, String current) {
    List<String> nodes = new ArrayList<String>();
    if (predecessor != null) {
        String[] strings = StringUtils.splitPreserveAllTokens(predecessor, ',');
        Collections.addAll(nodes, strings);
    }
    nodes.add(current);
    return org.springframework.util.StringUtils.collectionToCommaDelimitedString(nodes);
}

From source file:org.openflamingo.engine.dag.TSWorkflowExecutionPlanner.java

/**
 * Topological Sort Graph Algorithm?   ?.
 *
 * @return Topological Sort Graph/*from ww w . j  a  va2s. c  om*/
 */
private DirectedMultigraph<String, DefaultEdge> createGraph() {
    DirectedMultigraph<String, DefaultEdge> graph = new DirectedMultigraph<String, DefaultEdge>(
            DefaultEdge.class);

    // Add Action's Vertex
    List<ActionType> actions = workflow.getAction();
    for (ActionType actionType : actions) {
        graph.addVertex(actionType.getName());
        actionMap.put(actionType.getName(), actionType);
    }

    // Add Start's Vertex
    if (workflow.getStart() != null) {
        graph.addVertex(workflow.getStart().getName());
        actionMap.put(workflow.getStart().getName(), workflow.getStart());
    }

    // Add End's Vertex
    if (workflow.getEnd() != null) {
        graph.addVertex(workflow.getEnd().getName());
        actionMap.put(workflow.getEnd().getName(), workflow.getEnd());
    }

    // Add Action's Edge
    for (ActionType actionType : actions) {
        if (!StringUtils.isEmpty(actionType.getTo())) {
            nextOfAction.put(actionType.getName(), actionType.getTo());
            String[] targets = StringUtils.splitPreserveAllTokens(actionType.getTo(), ",");
            for (String target : targets) {
                logger.trace("[Graph] {} => {}", actionType.getName(), target);
                graph.addEdge(actionType.getName(), target);
            }
        }
    }

    // Add Start's Edge
    if (workflow.getStart() != null) {
        if (!StringUtils.isEmpty(workflow.getStart().getTo())) {
            nextOfAction.put(workflow.getStart().getName(), workflow.getStart().getTo());
            String[] targets = StringUtils.splitPreserveAllTokens(workflow.getStart().getTo(), ",");
            for (String target : targets) {
                logger.trace("[Graph] {} => {}", workflow.getStart().getName(), target);
                graph.addEdge(workflow.getStart().getName(), target);
            }
        }
    }

    return graph;
}

From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java

@Override
public boolean createDirectory(Context context, FileSystemCommand command) {
    ResourceBundleRetreiver bundle = getResourceBundle(context);
    String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ",");
    AntPathMatcher antPathMatcher = new AntPathMatcher();
    for (String path : paths) {
        String pathToValid = command.getString("path");
        boolean isMatch = antPathMatcher.match(path, pathToValid);
        if (isMatch) {
            throw new FileSystemException(
                    bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid));
        }/* w w w  .  j a  v a  2  s.  c om*/
    }

    try {
        FileSystemProvider provider = getFileSystemProvider(context);
        boolean created = provider.mkdir(command.getString("path"));
        auditService.log(context, FileSystemType.HDFS, AuditType.CREATE, FileType.DIRECTORY,
                command.getString("path"), "", 0);
        return created;
    } catch (Exception ex) {
        throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_CREATE_DIRECTORY"), ex);
    }
}

From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java

@Override
public boolean deleteDirectory(Context context, FileSystemCommand command) {
    ResourceBundleRetreiver bundle = getResourceBundle(context);
    String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ",");
    AntPathMatcher antPathMatcher = new AntPathMatcher();
    for (String path : paths) {
        String pathToValid = command.getString("path");
        boolean isMatch = antPathMatcher.match(path, pathToValid);
        if (isMatch) {
            throw new FileSystemException(
                    bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid));
        }/*from   w  w  w  .j  a  v a  2s. co  m*/
    }

    try {
        FileSystemProvider provider = getFileSystemProvider(context);
        long length = getFileInfo(context, command.getString("path")).getLength();
        boolean deleted = provider.delete(command.getString("path"));
        auditService.log(context, FileSystemType.HDFS, AuditType.DELETE, FileType.DIRECTORY,
                command.getString("path"), "", length);
        return deleted;
    } catch (Exception ex) {
        throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_DELETE_DIRECTORY"), ex);
    }
}

From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java

@Override
public boolean renameDirectory(Context context, FileSystemCommand command) {
    ResourceBundleRetreiver bundle = getResourceBundle(context);
    String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ",");
    AntPathMatcher antPathMatcher = new AntPathMatcher();
    for (String path : paths) {
        String pathToValid = command.getString("from");
        boolean isMatch = antPathMatcher.match(path, pathToValid);
        if (isMatch) {
            throw new FileSystemException(
                    bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid));
        }/*from  ww w. j  a va  2s. co m*/
    }

    try {
        FileSystemProvider provider = getFileSystemProvider(context);
        boolean renamed = provider.rename(command.getString("from"), command.getString("to"));
        auditService.log(context, FileSystemType.HDFS, AuditType.RENAME, FileType.DIRECTORY,
                command.getString("from"), command.getString("to"), 0);
        return renamed;
    } catch (Exception ex) {
        throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_RENAME_DIRECTORY"), ex);
    }
}

From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java

@Override
public boolean moveDirectory(Context context, FileSystemCommand command) {
    ResourceBundleRetreiver bundle = getResourceBundle(context);
    String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ",");
    AntPathMatcher antPathMatcher = new AntPathMatcher();
    for (String path : paths) {
        String pathToValid = command.getString("to");
        boolean isMatch = antPathMatcher.match(path, pathToValid);
        if (isMatch) {
            throw new FileSystemException(
                    bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid));
        }/*from   w  w  w .  j  av  a 2  s . c o m*/
    }

    for (String path : paths) {
        String pathToValid = command.getString("from");
        boolean isMatch = antPathMatcher.match(path, pathToValid);
        if (isMatch) {
            throw new FileSystemException(
                    bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid));
        }
    }

    try {
        FileSystemProvider provider = getFileSystemProvider(context);
        long length = getFileInfo(context, command.getString("from")).getLength();
        boolean moved = provider.rename(command.getString("from"), command.getString("to"));
        auditService.log(context, FileSystemType.HDFS, AuditType.MOVE, FileType.DIRECTORY,
                command.getString("from"), command.getString("to"), length);
        return moved;
    } catch (Exception ex) {
        throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_MOVE_DIRECTORY"), ex);
    }
}

From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java

@Override
public boolean copyDirectory(Context context, FileSystemCommand command) {
    ResourceBundleRetreiver bundle = getResourceBundle(context);
    String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ",");
    AntPathMatcher antPathMatcher = new AntPathMatcher();
    for (String path : paths) {
        String pathToValid = command.getString("to");
        boolean isMatch = antPathMatcher.match(path, pathToValid);
        if (isMatch) {
            throw new FileSystemException(
                    bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid));
        }//from   w w w.  ja  v  a  2s  .c  o m
    }

    try {
        FileSystemProvider provider = getFileSystemProvider(context);
        boolean copied = provider.copy(command.getString("from"), command.getString("to"));
        auditService.log(context, FileSystemType.HDFS, AuditType.COPY, FileType.DIRECTORY,
                command.getString("from"), command.getString("to"),
                getFileInfo(context, command.getString("from")).getLength());
        return copied;
    } catch (Exception ex) {
        throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_COPY_DIRECTORY"), ex);
    }
}

From source file:org.openflamingo.fs.hdfs.HdfsFileSystemServiceImpl.java

@Override
public boolean renameFile(Context context, FileSystemCommand command) {
    ResourceBundleRetreiver bundle = getResourceBundle(context);
    String[] paths = StringUtils.splitPreserveAllTokens(context.getString("hdfs.delete.forbidden.paths"), ",");
    AntPathMatcher antPathMatcher = new AntPathMatcher();
    for (String path : paths) {
        String pathToValid = FileUtils.getPath(command.getString("path"));
        boolean isMatch = antPathMatcher.match(path, pathToValid);
        if (isMatch) {
            throw new FileSystemException(
                    bundle.message("S_FS_SERVICE", "INCLUDED_FOBIDDEN_RULES", pathToValid));
        }/*from  w w w. j  a v a2  s .co m*/
    }

    try {
        FileSystemProvider provider = getFileSystemProvider(context);
        boolean renamed = provider.rename(command.getString("path"), command.getString("filename"));
        auditService.log(context, FileSystemType.HDFS, AuditType.RENAME, FileType.FILE,
                command.getString("path"),
                FileUtils.getPath(command.getString("path")) + "/" + command.getString("filename"), 0);
        return renamed;
    } catch (Exception ex) {
        throw new FileSystemException(bundle.message("S_FS_SERVICE", "CANNOT_LIST_FILES"), ex);
    }
}