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:aode.lx.persistence.SearchFilter.java

/**
 * searchParamskey?LIKES_name//ww  w.j av  a  2 s .  c o m
 */
public static Map<String, SearchFilter> parse(HttpServletRequest request) {
    Map<String, Object> searchParams = Servlets.getParametersStartingWith(request, "search_");
    Map<String, SearchFilter> filters = Maps.newHashMap();

    for (Entry<String, Object> entry : searchParams.entrySet()) {
        // 
        String key = entry.getKey();

        Object value = entry.getValue();
        if (StringUtils.isBlank((String) value)) {
            continue;
        }
        // operatorfiledAttribute
        String[] names = StringUtils.split(key, "_");
        if (names.length != 2 && names.length != 3) {
            // throw new IllegalArgumentException(key +
            // " is not a valid search filter name");
            logger.warn(key + " is not a valid search filter name");
            continue;
        }

        Class<?> propertyClass = null;
        if (names.length == 3) {
            try {
                propertyClass = Enum.valueOf(PropertyType.class, names[2]).getValue();
                logger.debug(key + ":" + propertyClass.getName());
                if (propertyClass != null) {
                    if (propertyClass.getName().equals("java.util.Date")) {
                        String str = value.toString();
                        if (str.length() == 10) {
                            if (names[0].equals("GT") || names[0].equals("GTE")) {
                                str += " 00:00:00";
                            } else if (names[0].equals("LT") || names[0].equals("LTE")) {
                                str += " 23:59:59";
                            }
                        }
                        value = dateTimeFormat.parseObject(str);
                    } else {
                        //value = ConvertUtils.convert(value, propertyClass);
                    }

                }

            } catch (RuntimeException e) {
                logger.warn(key + " PropertyType is not a valid type!", e);
            } catch (ParseException e) {
                logger.warn(key + " PropertyType is not a valid type!", e);
            }
        }

        String filedName = names[1];
        Operator operator = Operator.valueOf(names[0]);

        // searchFilter
        SearchFilter filter = new SearchFilter(filedName, operator, value);
        filters.put(key, filter);
    }

    return filters;
}

From source file:gov.nih.nci.cabig.ccts.hibernate.NamingStrategy.java

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

From source file:com.netflix.spinnaker.kork.astyanax.EurekaHostSupplier.java

static Host buildHost(InstanceInfo info) {
    String[] parts = StringUtils.split(StringUtils.split(info.getHostName(), ".")[0], '-');

    Host host = new Host(info.getHostName(), info.getPort())
            .addAlternateIpAddress(/*from ww w .  j a v  a  2 s . c  o m*/
                    StringUtils.join(new String[] { parts[1], parts[2], parts[3], parts[4] }, "."))
            .addAlternateIpAddress(info.getIPAddr()).setId(info.getId());

    try {
        if (info.getDataCenterInfo() instanceof AmazonInfo) {
            AmazonInfo amazonInfo = (AmazonInfo) info.getDataCenterInfo();
            host.setRack(amazonInfo.get(AmazonInfo.MetaDataKey.availabilityZone));
        }
    } catch (Throwable t) {
        logger.error("Error getting rack for host " + host.getName(), t);
    }

    return host;
}

From source file:com.pureinfo.common.sms.action.SMSSendAction.java

/**
 * @see com.pureinfo.ark.interaction.ActionBase#executeAction()
 *///from   w w w.  j  ava 2 s .c om
public ActionForward executeAction() throws PureException {
    //1. to read parameters
    String sAction = request.getParameter("action");
    if (sAction == null) {
        return mapping.getInputForward();
    }
    String sIds = request.getRequiredParameter("receiveIds", "");
    String sContent = request.getString("body", true);

    //2. to read mapping parameter
    MappingString mappingParameters = new MappingString(mapping.getParameter());
    String sMark = mappingParameters.getTrimed("mark");
    mappingParameters.clear();
    if (sMark == null) {
        throw new PureException(PureException.PARAMETER_REQUIRED,
                "parameter [mark] missing in mapping config!");
    }

    //3. to send SMS
    sContent = (sContent == null) ? sMark : sContent + sMark;
    String[] idArray = StringUtils.split(sIds, ',');
    IContentMgr mgr = ArkContentHelper.lookupTypeById(ArkTypes.USER).getManagerBean();
    for (int i = 0; i < idArray.length; i++) {
        int nId = Integer.parseInt(idArray[i]);
        User usr = (User) mgr.lookupById(nId);
        String sPhoneNumber = usr.getMobile();
        User admin = (User) loginUser;
        if (sPhoneNumber != null && sPhoneNumber.length() != 0) {
            SenderHelper.getSender(SenderHelper.TYPE_SMS).send(admin.getMobile(), admin.getTrueName(),
                    sPhoneNumber, usr.getTrueName(), "", sContent);
            //                try {
            //                    Thread.sleep(10000);
            //                } catch (Exception ex) {}
        }
    }
    request.setAttribute("url", "../sms/sms-send.jsp");
    return mapping.findForward("success");
}

From source file:com.bfd.harpc.common.configure.PathUtils.java

/**
 * Normalize the path by suppressing sequences like "path/.." and inner
 * simple dots./*from  ww w.j a  v  a  2  s  .  c o m*/
 * <p>
 * The result is convenient for path comparison. For other uses, notice that
 * Windows separators ("\") are replaced by simple slashes.
 * 
 * @param path
 *            the original path
 * @return the normalized path
 */
public static String cleanPath(String path) {
    if (StringUtils.isEmpty(path)) {
        return null;
    }

    // ClassLoader.getResource??jar
    if (path.startsWith("jar:file")) {
        path = cleanJarPath(path);
    }

    String pathToUse = StringUtils.replace(path, ResourceConstants.WINDOWS_FOLDER_SEPARATOR.getValue(),
            ResourceConstants.FOLDER_SEPARATOR.getValue());

    // Strip prefix from path to analyze, to not treat it as part of the
    // first path element. This is necessary to correctly parse paths like
    // "file:core/../core/io/Resource.class", where the ".." should just
    // strip the first "core" directory while keeping the "file:" prefix.
    int prefixIndex = pathToUse.indexOf(":");
    String prefix = "";
    if (prefixIndex != -1) {
        prefix = pathToUse.substring(0, prefixIndex + 1);
        pathToUse = pathToUse.substring(prefixIndex + 1);
    }
    if (pathToUse.startsWith(ResourceConstants.FOLDER_SEPARATOR.getValue())) {
        prefix = prefix + ResourceConstants.FOLDER_SEPARATOR.getValue();
        pathToUse = pathToUse.substring(1);
    }

    String[] pathArray = StringUtils.split(pathToUse, ResourceConstants.FOLDER_SEPARATOR.getValue());
    List<String> pathElements = new LinkedList<String>();
    int tops = 0;

    for (int i = pathArray.length - 1; i >= 0; i--) {
        String element = pathArray[i];
        if (ResourceConstants.CURRENT_PATH.getValue().equals(element)) {
            // Points to current directory - drop it.
        } else if (ResourceConstants.TOP_PATH.getValue().equals(element)) {
            // Registering top path found.
            tops++;
        } else {
            if (tops > 0) {
                // Merging path element with element corresponding to top
                // path.
                tops--;
            } else {
                // Normal path element found.
                pathElements.add(0, element);
            }
        }
    }

    // Remaining top paths need to be retained.
    for (int i = 0; i < tops; i++) {
        pathElements.add(0, ResourceConstants.TOP_PATH.getValue());
    }

    return prefix + StringUtils.join(pathElements, ResourceConstants.FOLDER_SEPARATOR.getValue());
}

From source file:fr.fastconnect.factory.tibco.bw.codereview.BW.java

/**
 * {@inheritDoc}//ww w . ja va 2  s.  c om
 * 
 * @see org.sonar.api.resources.AbstractLanguage#getFileSuffixes()
 */
@Override
public String[] getFileSuffixes() {
    String[] suffixes = filterEmptyStrings(settings.getStringArray(BW.FILE_SUFFIXES_KEY));
    if (suffixes.length == 0) {
        suffixes = StringUtils.split(DEFAULT_FILE_SUFFIXES, ",");
    }
    return suffixes;
}

From source file:mysoft.sonar.plugins.web.check.StyleAttributeRegExpCheck.java

@Override
public void startDocument(List<Node> nodes) {
    for (String item : trimSplitCommaSeparatedList(attributes)) {
        String[] pair = StringUtils.split(item, "=");
        if (pair.length <= 0)
            continue;

        StyleRule a = new StyleRule();
        a.name = pair[0].trim();//from   www .  ja  va 2s.c  o m
        a.rule = pair[1].trim();
        styleRules.add(a);
    }
}

From source file:com.hangum.tadpole.monitoring.core.jobs.UserJOB.java

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    StringBuffer sbMailContent = new StringBuffer();

    String strKey = context.getJobDetail().getKey().toString();
    if (logger.isDebugEnabled())
        logger.debug("start job is " + strKey);
    String[] keys = StringUtils.split(StringUtils.removeStart(strKey, "DEFAULT."),
            PublicTadpoleDefine.DELIMITER);

    int dbSeq = NumberUtils.createInteger(keys[0]);
    int scheduleSeq = NumberUtils.createInteger(keys[1]);

    boolean isResult = true;
    String strMessage = "";
    try {/*from   w w  w.  ja  v a2  s.  c  o m*/
        UserDBDAO userDB = TadpoleSystem_UserDBQuery.getUserDBInstance(dbSeq);
        ScheduleMainDAO scheduleMainDao = TadpoleSystem_Schedule.findScheduleMain(scheduleSeq);
        List<ScheduleDAO> listSchedule = TadpoleSystem_Schedule.findSchedule(scheduleMainDao.getSeq());

        for (ScheduleDAO scheduleDAO : listSchedule) {
            try {
                sbMailContent.append(
                        DailySummaryReportJOB.executSQL(userDB, scheduleDAO.getName(), scheduleDAO.getSql()));
            } catch (Exception e) {
                sbMailContent.append("Rise Exception :" + e.getMessage());
                strMessage += e.getMessage() + "\n";
                isResult = false;
            }
        }

        DailySummaryReport report = new DailySummaryReport();
        String mailContent = report.makeFullSummaryReport(scheduleMainDao.getTitle(), sbMailContent.toString());

        Utils.sendEmail(scheduleMainDao.getUser_seq(), scheduleMainDao.getTitle(), mailContent);
        ;

        TadpoleSystem_Schedule.saveScheduleResult(scheduleSeq, isResult, strMessage);
    } catch (Exception e) {
        logger.error("execute User Job", e);

        try {
            TadpoleSystem_Schedule.saveScheduleResult(scheduleSeq, false, strMessage + e.getMessage());
        } catch (Exception e1) {
            logger.error("save schedule result", e1);
        }
    }

}

From source file:com.bstek.dorado.core.SpringApplicationContext.java

private Resource[] getConfigLocations(String configLocation) throws IOException {
    Set<Resource> resourceSet = new LinkedHashSet<Resource>();

    String[] configLocations = StringUtils.split(configLocation, LOCATION_SEPARATOR);
    for (String location : configLocations) {
        if (StringUtils.isNotBlank(location)) {
            CollectionUtils.addAll(resourceSet, getResources(location));
        }//from   w w  w  . ja  v  a 2s  . c  o  m
    }

    for (Iterator<Resource> it = resourceSet.iterator(); it.hasNext();) {
        Resource resource = it.next();
        if (!resource.exists()) {
            logger.warn("Resource [" + resource + "] does not exist.");
            it.remove();
        }
    }

    Resource[] resources = new Resource[resourceSet.size()];
    resourceSet.toArray(resources);
    return resources;
}

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

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

    BufferedReader reader = new BufferedReader(new InputStreamReader(stream, UTF_8));
    String line;//from w  w w.  ja  v  a 2 s  . c  om
    try {
        while ((line = reader.readLine()) != null) {
            // Format is: <metric path> <metric value> <metric timestamp>
            String[] parts = StringUtils.split(line, ' ');
            if (parts.length != 3) {
                throw new FormatParseException(
                        "Expected 3 parts, found " + parts.length + " in line '" + line + "'");
            }

            String metricName = getMetricName(parts);
            double value = getMetricValue(parts);
            Instant timestamp = getMetricTimestamp(parts);

            // If the metric is already known, add a point. Otherwise create the metric and add the point.
            MetricTimeSeries.Builder metricBuilder = metrics.get(metricName);
            if (metricBuilder == null) {
                metricBuilder = new MetricTimeSeries.Builder(metricName, METRIC_TYPE);
                metrics.put(metricName, metricBuilder);
            }
            metricBuilder.point(timestamp.toEpochMilli(), value);
        }
    } catch (IOException e) {
        throw new FormatParseException("IO exception while parsing Graphite format", e);
    }

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