Example usage for org.apache.commons.lang StringUtils splitByWholeSeparator

List of usage examples for org.apache.commons.lang StringUtils splitByWholeSeparator

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils splitByWholeSeparator.

Prototype

public static String[] splitByWholeSeparator(String str, String separator) 

Source Link

Document

Splits the provided text into an array, separator string specified.

Usage

From source file:org.processbase.ui.bpm.worklist.CandidateCaseList.java

@Override
public int load(int startPosition, int maxResults) {
    int results = 0;
    table.removeAllItems();/*from w  w  w.  j  a va 2s  .  co m*/
    try {
        // 1. load all tasks assigned to logged user
        Set<String> pids = new HashSet<String>();

        // Search states
        List<ActivityState> states = new ArrayList<ActivityState>();
        states.add(ActivityState.READY);
        states.add(ActivityState.EXECUTING);
        states.add(ActivityState.SUSPENDED);

        if (showFinished != null && ((Boolean) showFinished.getValue())) {
            states.add(ActivityState.FINISHED);
            states.add(ActivityState.CANCELLED);
            states.add(ActivityState.ABORTED);
            states.add(ActivityState.SKIPPED);
        }

        // Filter words
        Set<String> filterWords = new HashSet<String>();
        if (additionalFilter != null && additionalFilter.getValue() != null
                && StringUtils.isNotBlank(additionalFilter.getValue() + "")) {
            String[] words = StringUtils.splitByWholeSeparator(additionalFilter.getValue() + "", " ");
            for (int i = 0; i < words.length; i++) {
                filterWords.add(words[i]);
            }
        }

        ProcessbaseApplication application = ProcessbaseApplication.getCurrent();
        BPMModule bpmModule = application.getBpmModule();

        List<LightProcessInstance> processes = new ArrayList<LightProcessInstance>();

        Map<LightProcessInstance, LightTaskInstance> processTask = new HashMap<LightProcessInstance, LightTaskInstance>();

        // Find tasks
        List<LightTaskInstance> tasks = new ArrayList<LightTaskInstance>();
        for (ActivityState state : states) {
            try {
                tasks.addAll(bpmModule.getUserLightTaskList(application.getUserName(), state));
            } catch (Exception e) {
                LOG.warn("could not find tasks", e);
            }
        }

        for (LightTaskInstance task : tasks) {
            if (task.isTask()) {
                try {
                    LightProcessInstance process = bpmModule
                            .getLightProcessInstance(task.getProcessInstanceUUID());

                    // If not root process (#1491)
                    if (process.getParentInstanceUUID() != null) {
                        continue;
                    }

                    // Do filter
                    if (filterWords.size() > 0) {

                        String processName = process.getUUID().toString().split("--")[0] + "  #"
                                + process.getNb();
                        String taskName = task.getActivityLabel();

                        boolean contains = true;
                        for (String w : filterWords) {
                            if (!StringUtils.containsIgnoreCase(processName, w)
                                    && !StringUtils.containsIgnoreCase(taskName, w)) {
                                contains = false;
                                break;
                            }
                        }
                        if (!contains) {
                            continue;
                        }
                    }

                    String pid = task.getProcessInstanceUUID().toString();

                    if (!pids.contains(pid)) {
                        pids.add(pid);// Add to set so we don't show
                        // dublicate processes

                        processes.add(process);
                        processTask.put(process, task);
                    }

                } catch (Exception e) {
                    LOG.warn("could not find process", e);
                }
            }
        }

        // 2. load all instances started by the logged user
        Set<LightProcessInstance> processInstances = bpmModule.getLightUserInstances();

        for (LightProcessInstance process : processInstances) {

            // If not root process (#1491)
            if (process.getParentInstanceUUID() != null) {
                continue;
            }

            // Do filter
            if (filterWords.size() > 0) {

                String name = process.getUUID().toString().split("--")[0] + "  #" + process.getNb();

                boolean contains = true;
                for (String w : filterWords) {
                    if (!StringUtils.containsIgnoreCase(name, w)) {
                        contains = false;
                        break;
                    }
                }
                if (!contains) {
                    continue;
                }

            }

            String pid = process.getProcessInstanceUUID().toString();
            if (process.getInstanceState() == InstanceState.STARTED && !pids.contains(pid)) {
                processes.add(process);
            }
        }

        // Let sort list
        Collections.sort(processes, new Comparator<LightProcessInstance>() {
            public int compare(LightProcessInstance o1, LightProcessInstance o2) {
                return o2.getStartedDate().compareTo(o1.getStartedDate());
            }
        });

        int from = startPosition < processes.size() ? startPosition : processes.size();
        int to = (startPosition + maxResults) < processes.size() ? (startPosition + maxResults)
                : processes.size();

        List<LightProcessInstance> page = processes.subList(from, to);

        for (LightProcessInstance process : page) {
            if (processTask.containsKey(process)) {
                addTableRow(process, true, processTask.get(process));
            } else {
                addTableRow(process, false, null);
            }
        }

        results = page.size();
    } catch (Exception e) {
        e.printStackTrace();
    }

    table.setSortContainerPropertyId("lastUpdate");
    table.setSortAscending(false);
    table.sort();

    return results;
}

From source file:org.processbase.ui.bpm.worklist.CandidateTaskList.java

@Override
public int load(int startPosition, int maxResults) {
    int results = 0;
    table.removeAllItems();/*from   w  w w.jav  a  2 s  . c  om*/
    try {

        BPMModule bpmModule = ProcessbaseApplication.getCurrent().getBpmModule();

        List<LightTaskInstance> tasks = new ArrayList<LightTaskInstance>();
        tasks.addAll(bpmModule.getLightTaskList(ActivityState.READY));
        tasks.addAll(bpmModule.getLightTaskList(ActivityState.EXECUTING));
        tasks.addAll(bpmModule.getLightTaskList(ActivityState.SUSPENDED));

        // Filter words
        Set<String> filterWords = new HashSet<String>();
        if (additionalFilter != null && additionalFilter.getValue() != null
                && StringUtils.isNotBlank(additionalFilter.getValue() + "")) {
            String[] words = StringUtils.splitByWholeSeparator(additionalFilter.getValue() + "", " ");
            for (int i = 0; i < words.length; i++) {
                filterWords.add(words[i]);
            }
        }

        List<LightTaskInstance> filteredTasks = new ArrayList<LightTaskInstance>();

        for (LightTaskInstance task : tasks) {

            //Do filter
            String processName = task.getProcessDefinitionUUID().toString();
            String taskName = task.getActivityLabel();

            boolean contains = true;
            for (String w : filterWords) {
                if (!StringUtils.containsIgnoreCase(processName, w)
                        && !StringUtils.containsIgnoreCase(taskName, w)) {
                    contains = false;
                    break;
                }
            }
            if (!contains) {
                continue;
            }

            filteredTasks.add(task);
        }

        //Let sort list
        Collections.sort(filteredTasks, new Comparator<LightTaskInstance>() {

            public int compare(LightTaskInstance o1, LightTaskInstance o2) {
                return o2.getLastUpdateDate().compareTo(o1.getLastUpdateDate());
            }
        });

        int from = startPosition < filteredTasks.size() ? startPosition : filteredTasks.size();
        int to = (startPosition + maxResults) < filteredTasks.size() ? (startPosition + maxResults)
                : filteredTasks.size();

        //Get page
        List<LightTaskInstance> page = filteredTasks.subList(from, to);

        for (LightTaskInstance task : page) {
            addTableRow(task, null);
        }

        results = page.size();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    table.setSortContainerPropertyId("lastUpdate");
    table.setSortAscending(false);
    table.sort();

    return results;
}

From source file:org.sakaiproject.tool.assessment.services.assessment.AssessmentService.java

public String copyContentHostingAttachments(String text, String toContext) {
    if (text != null) {
        ContentResource cr = null;/*from  ww  w  .ja va 2  s  .c  o  m*/

        String[] sources = StringUtils.splitByWholeSeparator(text, "src=\"");

        Set<String> attachments = new HashSet<String>();
        for (String source : sources) {
            String theHref = StringUtils.substringBefore(source, "\"");
            if (StringUtils.contains(theHref, "/access/content/")) {
                attachments.add(theHref);
            }
        }
        if (attachments.size() > 0) {
            log.info("Found " + attachments.size() + " attachments buried in question or answer text");
            SecurityService.pushAdvisor(new SecurityAdvisor() {
                @Override
                public SecurityAdvice isAllowed(String arg0, String arg1, String arg2) {
                    if ("content.read".equals(arg1)) {
                        return SecurityAdvice.ALLOWED;
                    } else {
                        return SecurityAdvice.PASS;
                    }
                }
            });
            for (String attachment : attachments) {
                String resourceIdOrig = "/" + StringUtils.substringAfter(attachment, "/access/content/");
                String resourceId = URLDecoder.decode(resourceIdOrig);
                String filename = StringUtils.substringAfterLast(attachment, "/");

                try {
                    cr = AssessmentService.getContentHostingService().getResource(resourceId);
                } catch (IdUnusedException e) {
                    log.warn("Could not find resource (" + resourceId
                            + ") that was embedded in a question or answer");
                } catch (TypeException e) {
                    log.warn("TypeException for resource (" + resourceId
                            + ") that was embedded in a question or answer", e);
                } catch (PermissionException e) {
                    log.warn("No permission for resource (" + resourceId
                            + ") that was embedded in a question or answer");
                }

                if (cr != null && StringUtils.isNotEmpty(filename)) {

                    ContentResource crCopy = createCopyOfContentResource(cr.getId(), filename, toContext);
                    text = StringUtils.replace(text, resourceIdOrig,
                            StringUtils.substringAfter(crCopy.getReference(), "/content"));
                }
            }
            SecurityService.popAdvisor();
        }
    }
    return text;
}

From source file:org.sipfoundry.sipxconfig.backup.BackupCommandRunner.java

public List<String> list() {
    if (!m_plan.exists()) {
        return Collections.emptyList();
    }/*from w  w  w. ja  v  a 2s. c o  m*/
    String lines = StringUtils.chomp(runCommand("--list", m_plan.getAbsolutePath()));
    return Arrays.asList(StringUtils.splitByWholeSeparator(lines, "\n"));
}

From source file:org.sonar.api.ce.measure.test.TestSettings.java

@Override
public String[] getStringArray(String key) {
    String value = getString(key);
    if (value != null) {
        String[] strings = StringUtils.splitByWholeSeparator(value, ",");
        String[] result = new String[strings.length];
        for (int index = 0; index < strings.length; index++) {
            result[index] = StringUtils.trim(strings[index]);
        }//ww w .j  av  a2 s.c o  m
        return result;
    }
    return ArrayUtils.EMPTY_STRING_ARRAY;
}

From source file:org.sonar.api.config.Settings.java

/**
 * Value is splitted and trimmed./*from w  w w  .j a va  2 s.c  o m*/
 */
public final String[] getStringArrayBySeparator(String key, String separator) {
    String value = getString(key);
    if (value != null) {
        String[] strings = StringUtils.splitByWholeSeparator(value, separator);
        String[] result = new String[strings.length];
        for (int index = 0; index < strings.length; index++) {
            result[index] = StringUtils.trim(strings[index]);
        }
        return result;
    }
    return ArrayUtils.EMPTY_STRING_ARRAY;
}

From source file:org.sonar.plugins.qualityprofileprogression.server.ProfileProgressedNotificationDispatcher.java

public final String[] getStringArray(String value) {
    String separator = ",";

    if (value != null) {
        String[] strings = StringUtils.splitByWholeSeparator(value, separator);
        String[] result = new String[strings.length];
        for (int index = 0; index < strings.length; index++) {
            result[index] = StringUtils.trim(strings[index]);
        }//  ww  w  . ja v  a  2s. com
        return result;
    }
    return ArrayUtils.EMPTY_STRING_ARRAY;
}

From source file:org.talend.dataprofiler.core.pattern.ImportFactory.java

/**
 * get the IndicatorDefinitionParameter information from the record and build the paraMap, set it into
 * UDIParameters.//w ww. jav a 2  s .c  om
 * 
 * @param record
 */
private static Map<String, String> buildIndDefPara(HashMap<String, String> record) {
    Map<String, String> paraMap = new HashMap<String, String>();
    String string = record.get(PatternToExcelEnum.IndicatorDefinitionParameter.getLiteral());
    if (StringUtils.isNotBlank(string)) {
        String[] keyValues = StringUtils.splitByWholeSeparator(string, UDIHelper.PARA_SEPARATE_2);
        for (String keyValue : keyValues) {
            if (StringUtils.isNotBlank(keyValue)) {
                String[] para = StringUtils.splitByWholeSeparator(keyValue, UDIHelper.PARA_SEPARATE_1);
                // the key should not be blank, the value can be anything
                if (para.length == 2 && StringUtils.isNotBlank(para[0]) && para[1] != null) {
                    paraMap.put(para[0], para[1]);
                }
            }
        }
    }
    return paraMap;
}

From source file:org.tsm.concharto.web.TestBliki.java

@Test
public void render() {

    WikiModel wikiModel = new WikiModel("http://www.concharto.com/images/${image}",
            "http://www.concharto.com/${title}");
    String results = wikiModel.render(WIKI_MARKUP);
    System.out.println(results);/*from  w  ww  .j a  v  a2 s.  c  om*/
    //there should be one url in the string
    assertTrue(-1 != results.indexOf("concharto"));
    //there should be three <li> items in the string
    assertEquals(4, StringUtils.splitByWholeSeparator(results, "<li>").length);

}

From source file:org.yes.cart.service.vo.impl.VoIOSupportImpl.java

static byte[] getByteArray(final String base64) {
    final String[] parts = StringUtils.splitByWholeSeparator(base64, ";base64,");
    if (parts.length == 1) {
        return Base64.decodeBase64(parts[0]);
    } else if (parts.length == 2) {
        return Base64.decodeBase64(parts[1]);
    }//from  w w  w .j av a 2 s . c  o m
    return null;
}