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

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

Introduction

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

Prototype

public static String[] split(String str, String separatorChars) 

Source Link

Document

Splits the provided text into an array, separators specified.

Usage

From source file:mitm.common.net.NetUtils.java

/**
 * Parses the provided URL query and returns a map with all names to values. The values are URL decoded. If 
 * toLowercase is true the keys of the map will be converted to lowecase.
 * /*  www .ja va2  s . co  m*/
 * Example:
 * test=123&value=%27test%27&value=abc maps to test -> [123] and value -> ["test", abc]
 * @throws IOException 
 */
public static Map<String, String[]> parseQuery(String query, boolean toLowercase) throws IOException {
    Map<String, String[]> map = new HashMap<String, String[]>();

    if (query == null) {
        return map;
    }

    String[] elements = StringUtils.split(query, '&');

    for (String element : elements) {
        element = element.trim();

        if (StringUtils.isEmpty(element)) {
            continue;
        }

        String name;
        String value;

        int i = element.indexOf('=');

        if (i > -1) {
            name = StringUtils.substring(element, 0, i);
            value = StringUtils.substring(element, i + 1);
        } else {
            name = element;
            value = "";
        }

        name = StringUtils.trimToEmpty(name);
        value = StringUtils.trimToEmpty(value);

        if (toLowercase) {
            name = name.toLowerCase();
        }

        value = URLDecoder.decode(value, CharacterEncoding.UTF_8);

        String[] updated = (String[]) ArrayUtils.add(map.get(name), value);

        map.put(name, updated);
    }

    return map;
}

From source file:gov.nih.nci.cabig.caaers.tools.hibernate.WonderfulNamingStrategy.java

@Required
public void setUppercaseColumnNames(String uppercaseColumnNames) {
    this.uppercaseColumnNames = uppercaseColumnNames;
    this.uppercaseColumns = StringUtils.split(uppercaseColumnNames, ',');
}

From source file:com.gzj.tulip.load.LoadScope.java

private void init(String loadScope, String defType) {
    if (StringUtils.isBlank(loadScope) || "*".equals(loadScope)) {
        return;/*from   w  w  w.  j  a v a2s .c o  m*/
    }
    loadScope = loadScope.trim();
    String[] componetConfs = StringUtils.split(loadScope, ";");
    for (String componetConf : componetConfs) {
        if (StringUtils.isBlank(loadScope)) {
            continue;
        }
        // "controllers=com.renren.xoa, com.renren.yourapp"
        componetConf = componetConf.trim();
        int componetTypeIndex;
        String componetType = defType; // "controllers", "applicationContext", "dao", "messages", "*"
        String componetConfValue = componetConf;
        if ((componetTypeIndex = componetConf.indexOf('=')) != -1) {
            componetType = componetConf.substring(0, componetTypeIndex).trim();
            componetConfValue = componetConf.substring(componetTypeIndex + 1).trim();
        }
        if (componetType.startsWith("!")) {
            componetType = componetType.substring(1);
        } else {
            componetConfValue = componetConfValue + ", com.gzj.tulip";
        }
        String[] packages = StringUtils.split(componetConfValue, ", \t\n\r\0");//\t
        this.load.put(componetType, packages);
    }
}

From source file:com.alibaba.cobar.client.router.rules.ibatis.AbstractIBatisOrientedRule.java

public synchronized List<String> action() {
    if (CollectionUtils.isEmpty(dataSourceIds)) {
        List<String> ids = new ArrayList<String>();
        for (String id : StringUtils.split(getAction(), getActionPatternSeparator())) {
            ids.add(StringUtils.trimToEmpty(id));
        }/*  w ww.j  a v  a  2 s  . c  o m*/
        setDataSourceIds(ids);
    }
    return dataSourceIds;
}

From source file:com.qualogy.qafe.gwt.server.ui.assembler.MenuItemUIAssembler.java

public ComponentGVO convert(Component object, Window currentWindow, ApplicationMapping applicationMapping,
        ApplicationContext context, SessionContainer ss) {
    ComponentGVO vo = null;/*from   w w w. j ava2 s  . c o m*/
    if (object != null) {
        if (object instanceof MenuItem) {
            MenuItem menuItem = (MenuItem) object;
            MenuItemGVO voTemp = new MenuItemGVO();
            voTemp.setId(menuItem.getId());
            UIAssemblerHelper.copyFields(menuItem, currentWindow, voTemp, applicationMapping, context, ss);

            voTemp.setShortcut(menuItem.getShortcut());
            // shortcut
            if (voTemp.getShortcut() != null && voTemp.getShortcut().length() > 0) {
                String[] keys = StringUtils.split(voTemp.getShortcut(), '+');

                List<String> modifiers = Arrays.asList(keys);
                String key = findKey(keys);

                voTemp.setModifiers((String[]) modifiers.toArray(new String[] {}));
                voTemp.setKey(key);

            }

            if (menuItem.getSubMenus() != null) {
                MenuItemGVO[] subMenus = new MenuItemGVO[menuItem.getSubMenus().size()];
                int index = 0;
                for (MenuItem mi : menuItem.getSubMenus()) {
                    subMenus[index] = (MenuItemGVO) ComponentUIAssembler.convert(mi, currentWindow,
                            applicationMapping, context, ss);
                    index++;
                }
                voTemp.setSubMenus(subMenus);
            }
            vo = voTemp;
        }
    }
    return vo;
}

From source file:com.redhat.rhn.domain.rhnpackage.PackageSource.java

/**
 * Retrieves the file portion of the path. For example, if
 * path=/foo/bar/baz.rpm, getFile() would return 'baz.rpm'.
 * @return Returns the file portion of the path.
 *//* w w w. j av a  2 s . co  m*/
public String getFile() {
    String[] parts = StringUtils.split(getPath(), '/');
    if (parts != null && parts.length > 0) {
        return parts[parts.length - 1];
    }

    return null;
}

From source file:com.qualogy.qafe.gwt.server.event.assembler.LogAssembler.java

private void assembleAttributes(LogFunctionGVO eventItemGVO, LogFunction eventItem, Event event,
        ApplicationContext applicationContext) {
    Parameter messageParameters = eventItem.getMessage();
    ParameterGVO messageGVOParameters = assembleParameter(messageParameters);
    eventItemGVO.setMessageGVO(messageGVOParameters);
    eventItemGVO.setDebug(Boolean.FALSE);
    eventItemGVO.setDelay(eventItem.getDelay());

    String[] properties = StringUtils.split(eventItem.getStyle() == null ? "" : eventItem.getStyle(), ';');
    String[][] styleProperties = new String[properties.length][2];
    for (int i = 0; i < properties.length; i++) {
        styleProperties[i] = StringUtils.split(properties[i], ':');
    }//from w  ww  .  j a v a  2  s.  c  o  m

    /*
     * Modify the properties since this is DOM manipulation : font-size for css has to become fontSize for DOM
     */
    for (int i = 0; i < styleProperties.length; i++) {
        styleProperties[i][0] = StyleDomUtil.initCapitalize(styleProperties[i][0]);
    }

    eventItemGVO.setStyleProperties(styleProperties);
    eventItemGVO.setStyleClass(eventItem.getStyleClass());
}

From source file:de.qaware.chronix.solr.ingestion.format.OpenTsdbTelnetFormatParser.java

@Override
public Iterable<MetricTimeSeries> parse(InputStream stream) throws FormatParseException {
    Map<Metric, MetricTimeSeries.Builder> metrics = new HashMap<>();

    BufferedReader reader = new BufferedReader(new InputStreamReader(stream, UTF_8));
    String line;/*from w w w.ja v a2  s . c  o m*/
    try {
        while ((line = reader.readLine()) != null) {
            // Format is: put <metric> <timestamp> <value> <tagk1=tagv1[ tagk2=tagv2 ...tagkN=tagvN]>
            // Example: put sys.cpu.user 1356998400 42.5 host=webserver01 cpu=0

            String[] parts = StringUtils.split(line, ' ');
            // 5 parts, because "Each data point must have at least one tag."
            if (parts.length < 5) {
                throw new FormatParseException(
                        "Expected at least 5 parts, found " + parts.length + " in line '" + line + "'");
            }

            if (!parts[0].equals("put")) {
                throw new FormatParseException(
                        "Expected first segment to be 'put', but was '" + parts[0] + "'");
            }

            String metricName = getMetricName(parts);
            Instant timestamp = getMetricTimestamp(parts);
            double value = getMetricValue(parts);
            Map<String, String> tags = getMetricTags(parts);

            // If the metric is already known, add a point. Otherwise create the metric and add the point.
            Metric metric = new Metric(metricName, tags);
            MetricTimeSeries.Builder metricBuilder = metrics.get(metric);
            if (metricBuilder == null) {
                metricBuilder = new MetricTimeSeries.Builder(metricName, METRIC_TYPE);
                for (Map.Entry<String, String> tagEntry : tags.entrySet()) {
                    metricBuilder.attribute(tagEntry.getKey(), tagEntry.getValue());
                }
                metrics.put(metric, metricBuilder);
            }

            metricBuilder.point(timestamp.toEpochMilli(), value);
        }
    } catch (IOException e) {
        throw new FormatParseException("IO exception while parsing OpenTSDB telnet format", e);
    }

    return metrics.values().stream().map(MetricTimeSeries.Builder::build).collect(Collectors.toList());
}

From source file:ml.shifu.shifu.udf.FullScoreUDFTest.java

public void testExec() throws IOException {
    Tuple input = TupleFactory.getInstance().newTuple(31);
    for (int i = 0; i < 31; i++) {
        input.set(i, 1);/* ww  w. j av  a 2 s  .  co  m*/
    }

    check(instance.exec(input), StringUtils.split("42,74,5,35,30,74,65,5", ","));
}

From source file:acromusashi.stream.ml.clustering.kmeans.KmeansCreator.java

/**
 * {@inheritDoc}//from ww  w.  jav a  2s  .  c  o  m
 */
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String receivedStr = tuple.getString(0);

    String[] splitedStr = StringUtils.split(receivedStr, this.delimeter);
    int dataNum = splitedStr.length;
    double[] points = new double[splitedStr.length];

    try {
        for (int index = 0; index < dataNum; index++) {
            points[index] = Double.parseDouble(splitedStr[index].trim());
        }

        KmeansPoint result = new KmeansPoint();
        result.setDataPoint(points);
        collector.emit(new Values(result));
    } catch (Exception ex) {
        logger.warn("Received data is invalid. skip this data. ReceivedData=" + receivedStr, ex);
    }
}