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:edu.ku.brc.specify.extras.FixSQLString.java

/**
 * // ww  w. j av  a 2  s. c o  m
 */
private void fix() {
    StringBuilder sb = new StringBuilder("sql = \"");
    String srcStr = srcTA.getText();
    boolean wasInner = false;
    for (String line : StringUtils.splitByWholeSeparator(srcStr, "\n")) {
        String str = line;//StringUtils.deleteWhitespace(line);

        //            while (str.startsWith("  INNER"))
        //            {
        //                str = 
        //            }

        if (str.toUpperCase().startsWith("INNER") || str.toUpperCase().startsWith("ORDER")
                || str.toUpperCase().startsWith("GROUP")) {
            if (!wasInner) {
                sb.append(" \" +");
                wasInner = false;
            }
            sb.append("\n    \"" + line.trim() + " \" +");
            wasInner = true;
        } else {
            if (wasInner) {
                sb.append("    \"");
                wasInner = false;
            }
            sb.append(' ');
            sb.append(StringUtils.replace(line.trim(), "\n", " "));
            //sb.append(StringUtils.replace(line.trim(), "\r\n", " "));
            //sb.append(StringUtils.replace(line.trim(), "\r", " "));
        }
    }

    if (wasInner) {
        sb.setLength(sb.length() - 3);
        sb.append("\";");
    } else {
        sb.append("\";");
    }
    dstTA.setText(sb.toString());

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            dstTA.requestFocus();
            dstTA.selectAll();
            UIHelper.setTextToClipboard(dstTA.getText());
        }
    });

}

From source file:com.netflix.explorers.AbstractExplorerModule.java

@Override
public void initialize() {
    LOG.info("Initialize " + name);

    loadPropertiesFileFromForms();/* w  w w .  j  a  v a2  s  .c om*/

    String prefix = "com.netflix.explorers." + name + ".";
    config = getConfigInstance();

    title = config.getString(prefix + "title", name + " (MissingTitle)");
    description = config.getString(prefix + "description", name + " (MissingDescription)");
    layoutName = config.getString(prefix + "pageLayout");
    isCmcEnabled = config.getBoolean(prefix + "cmcEnabled", false);
    isSecure = config.getBoolean(prefix + "secure", false);
    rolesAllowed = Sets.newHashSet(StringUtils.split(config.getString(prefix + "rolesAllowed", ""), ","));

    String items = config.getString(prefix + "menu");
    Map<String, String> menuLayout = getMenuLayout();
    if (menuLayout != null) {
        rootMenu = new MenuItem().setName("root").setTitle("root");
        for (Entry<String, String> item : menuLayout.entrySet()) {
            // Parse the menu hierarchy and build it if necessary
            String[] nameComponents = StringUtils.split(item.getKey(), "/");
            String[] pathComponents = StringUtils.split(item.getValue(), "/");
            if (nameComponents.length == 1) {
                rootMenu.addChild(
                        new MenuItem().setName(item.getKey()).setHref(item.getValue()).setTitle(item.getKey()));
            } else {
                if (nameComponents.length != pathComponents.length)
                    LOG.error("Name and path must have same number of components: " + item.getKey() + " -> "
                            + item.getValue());

                MenuItem node = rootMenu;
                for (int i = 0; i < nameComponents.length - 1; i++) {
                    MenuItem next = node.getChild(pathComponents[i]);
                    if (next == null) {
                        next = new MenuItem().setName(pathComponents[i]).setTitle(nameComponents[i]);
                        node.addChild(next);
                    }
                    node = next;
                }

                MenuItem leaf = new MenuItem().setName(pathComponents[pathComponents.length - 1])
                        .setHref(item.getValue()).setTitle(nameComponents[nameComponents.length - 1]);
                // Add the menu item to the leaf
                node.addChild(leaf);
            }
        }
    } else if (items != null) {
        rootMenu = new MenuItem().setName("root").setTitle("root");
        for (String item : StringUtils.split(items, ",")) {
            String[] parts = StringUtils.splitByWholeSeparator(item, "->");
            try {
                String[] nameComponents = StringUtils.split(parts[0].trim(), "/");
                MenuItem node = rootMenu;
                for (int i = 0; i < nameComponents.length; i++) {
                    MenuItem next = node.getChild(nameComponents[i]);
                    if (next == null) {
                        next = new MenuItem().setName(nameComponents[i]).setTitle(nameComponents[i]);
                        node.addChild(next);
                    }
                    node = next;
                }
                node.setHref(parts[1].trim());
            } catch (Exception e) {
                LOG.error("Failed to load menu for explorer " + name, e);
            }
        }
    }
    LOG.info(toString());
}

From source file:dk.dma.enav.serialization.RouRouteParser.java

private static String[] parsePair(String str) throws IOException {
    String[] parts = StringUtils.splitByWholeSeparator(str, ": ");
    if (parts.length != 2) {
        throw new IOException("Error in ROU key value pair: " + str);
    }//  w w  w. jav a2 s  .c o m
    return parts;
}

From source file:eionet.cr.web.action.factsheet.CompiledDatasetActionBean.java

/**
 * Populates the filters property from the dataset data.
 *
 * @param dataset/*from  w  w  w  .  jav a  2  s . c  om*/
 */
private void extractFilters(SubjectDTO dataset) {
    Collection<ObjectDTO> filterObjects = dataset.getObjects(Predicates.CR_SEARCH_CRITERIA);
    if (filterObjects == null) {
        return;
    }
    for (ObjectDTO o : filterObjects) {
        DeliveryFilterDTO filter = new DeliveryFilterDTO();
        String value = o.getDisplayValue();
        String[] arr = StringUtils.splitByWholeSeparator(value, WebConstants.FILTER_SEPARATOR);
        if (!WebConstants.NOT_AVAILABLE.equals(arr[0])) {
            // Obligation value
            String[] data = getValueAndLabel(arr[0]);
            filter.setObligation(data[0]);
            filter.setObligationLabel(data[1]);
        }
        if (!WebConstants.NOT_AVAILABLE.equals(arr[1])) {
            // Locality value
            String[] data = getValueAndLabel(arr[1]);
            filter.setLocality(data[0]);
            filter.setLocalityLabel(data[1]);
        }
        if (!WebConstants.NOT_AVAILABLE.equals(arr[2])) {
            // Year value
            filter.setYear(arr[2]);
        }
        filters.add(filter);
    }
}

From source file:com.justinmobile.core.dao.support.PropertyFilter.java

private void buildFilterName(String filterName) {
    // ????//from   ww  w  .j  a v a2  s  .c  o m
    String aliasPart = StringUtils.substringBefore(filterName, "_");
    if (ALIAS.equals(aliasPart)) {
        String allPart = StringUtils.substringAfter(filterName, "_");
        String firstPart = StringUtils.substringBefore(allPart, "_");
        this.aliasName = StringUtils.substring(firstPart, 0, firstPart.length() - 1);
        String joinTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length());
        this.joinType = Enum.valueOf(JoinType.class, joinTypeCode).getValue();
        filterName = StringUtils.substringAfter(allPart, "_");
    }
    // ?????matchTypepropertyTypeCode
    String firstPart = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1);
    String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }
    // ??OR
    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    Assert.isTrue(StringUtils.isNotBlank(propertyNameStr),
            "filter??" + filterName + ",??.");
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);
}

From source file:cppsensor.sonar.CppProjectAnalysisHandler.java

private String[] getStringArrayBySeparator(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]);
        }/*from  www.  j  a va  2s.  c  o m*/
        return result;
    }
    return ArrayUtils.EMPTY_STRING_ARRAY;
}

From source file:com.justinmobile.core.dao.support.PropertyFilter.java

public PropertyFilter(final String filterName, final MatchType matchType, final PropertyType propertyType,
        final String value) {
    this.matchType = matchType;
    this.propertyClass = propertyType.getValue();
    this.propertyNames = StringUtils.splitByWholeSeparator(filterName, PropertyFilter.OR_SEPARATOR);
    this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass);
}

From source file:com.adobe.acs.commons.workflow.bulk.removal.impl.WorkflowInstanceRemoverImpl.java

private String getStatus(Resource workflowInstanceResource) {
    String instanceStatus = workflowInstanceResource.getValueMap().get(PN_STATUS, "UNKNOWN");

    if (!STATUS_RUNNING.equalsIgnoreCase(instanceStatus)) {
        log.debug("Status of [ {} ] is not RUNNING, so we can take it at face value", instanceStatus);
        return instanceStatus;
    }//from   w w w. j  a v  a 2  s.co  m

    // Else check if its RUNNING or STALE
    log.debug("Status is [ {} ] so we have to determine if its RUNNING or STALE", instanceStatus);

    Resource metadataResource = workflowInstanceResource.getChild("data/metaData");
    if (metadataResource == null) {
        log.debug("Workflow instance data/metaData does not exist for [ {} ]",
                workflowInstanceResource.getPath());
        return instanceStatus;
    }

    final ValueMap properties = metadataResource.getValueMap();
    final String[] jobIds = StringUtils.splitByWholeSeparator(properties.get("currentJobs", ""), JOB_SEPARATOR);

    if (jobIds.length == 0) {
        log.debug("No jobs found for [ {} ] so assuming status as [ {} ]", workflowInstanceResource.getPath(),
                instanceStatus);
    }

    // Make sure there are no JOBS that match to this jobs name
    for (final String jobId : jobIds) {
        if (jobManager.getJobById(jobId) != null) {
            // Found a job for this jobID; so this is a RUNNING job
            log.debug("JobManager found a job for jobId [ {} ] so marking workflow instances [ {} ] as RUNNING",
                    jobId, workflowInstanceResource.getPath());
            return STATUS_RUNNING;
        }
    }
    log.debug(
            "JobManager could not find any jobs for jobIds [ {} ] so  workflow instance [ {} ] is potentially STALE",
            StringUtils.join(jobIds, ", "), workflowInstanceResource.getPath());

    final WorkflowSession workflowSession = workflowInstanceResource.getResourceResolver()
            .adaptTo(WorkflowSession.class);
    Workflow workflow = null;
    try {
        workflow = workflowSession.getWorkflow(workflowInstanceResource.getPath());
        if (workflow == null) {
            throw new WorkflowException(String.format("Workflow instance object is null for [ %s]",
                    workflowInstanceResource.getPath()));
        }
    } catch (WorkflowException e) {
        log.warn("Unable to locate Workflow Instance for [ {} ] So it cannot be RUNNING and must be STALE. ",
                workflowInstanceResource.getPath(), e);
        return "STALE";
    }

    final List<WorkItem> workItems = workflow.getWorkItems(new WorkItemFilter() {
        public boolean doInclude(WorkItem workItem) {
            // Only include active Workflow instances (ones without an End Time) in this list
            return workItem.getTimeEnded() == null;
        }
    });

    if (!workItems.isEmpty()) {
        // If at least 1 work item exists that does not have an end time (meaning its still active), then its RUNNING
        return STATUS_RUNNING;
    }

    return "STALE";
}

From source file:com.justinmobile.core.dao.support.PropertyFilter.java

/**
 * ??/*from  w  ww  .  ja  va 2 s. com*/
 * 
 * @param aliasName
 * @param filterName
 * @param matchType
 * @param propertyType
 * @param value
 */
public PropertyFilter(final String aliasName, final JoinType joinType, final String filterName,
        final MatchType matchType, final PropertyType propertyType, final String value) {
    this.aliasName = aliasName;
    this.joinType = joinType.getValue();
    this.matchType = matchType;
    this.propertyClass = propertyType.getValue();
    this.propertyNames = StringUtils.splitByWholeSeparator(filterName, PropertyFilter.OR_SEPARATOR);
    this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass);
}

From source file:com.flexive.core.search.cmis.impl.sql.MySQL.MySqlColumnReference.java

@Override
protected List<String> splitMultivaluedResult(String result) {
    return result != null ? Arrays.asList(StringUtils.splitByWholeSeparator(result, GROUPSEP))
            : new ArrayList<String>(0);
}