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:com.votingcentral.services.maxmind.MaxMindGeoLocationService.java

public MaxMindLocationTO getLocation(String ipAddress) {
    MaxMindLocationTO mto = new MaxMindLocationTO();
    String specificData = data + FastURLEncoder.encode(ipAddress, "UTF-8");
    URL url;/*from   www .j a  v a2s. c o m*/
    OutputStreamWriter wr = null;
    BufferedReader rd = null;
    try {
        url = new URL(surl);
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(specificData);
        wr.flush();
        // Get the response
        rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) {
            String[] values = StringUtils.split(line, ",");
            int maxIndex = values.length - 1;
            if (maxIndex >= 0) {
                mto.setISO3166TwoLetterCountryCode(values[0]);
            }
            if (maxIndex >= 1) {
                mto.setRegionCode(values[1]);
            }
            if (maxIndex >= 2) {
                mto.setCity(values[2]);
            }
            if (maxIndex >= 3) {
                mto.setPostalCode(values[3]);
            }
            if (maxIndex >= 4) {
                mto.setLatitude(values[4]);
            }
            if (maxIndex >= 5) {
                mto.setLongitude(values[5]);
            }
            if (maxIndex >= 6) {
                mto.setMetropolitanCode(values[6]);
            }
            if (maxIndex >= 7) {
                mto.setAreaCode(values[7]);
            }
            if (maxIndex >= 8) {
                mto.setIsp(values[8]);
            }
            if (maxIndex >= 9) {
                mto.setOranization(values[9]);
            }
            if (maxIndex >= 10) {
                mto.setError(MaxMindErrorsEnum.get(values[10]));
            }
        }
    } catch (MalformedURLException e) {
        log.fatal("Issue calling Maxmind", e);
        mto.setError(MaxMindErrorsEnum.VC_INTERNAL_ERROR);
    } catch (IOException e) {
        log.fatal("Issue reading Maxmind", e);
        mto.setError(MaxMindErrorsEnum.VC_INTERNAL_ERROR);
    } finally {
        if (wr != null) {
            try {
                wr.close();
            } catch (IOException e1) {
                log.fatal("Issue closing Maxmind", e1);
                mto.setError(MaxMindErrorsEnum.VC_INTERNAL_ERROR);
            }
        }
        if (rd != null) {
            try {
                rd.close();
            } catch (IOException e1) {
                log.fatal("Issue closing Maxmind", e1);
                mto.setError(MaxMindErrorsEnum.VC_INTERNAL_ERROR);
            }
        }
    }
    return mto;
}

From source file:com.symantec.cpe.config.ConfigHelper.java

/**
 * Load config from file: implement the function loadConfig, blind to users.
 *//*from w  w w  . j a  va2 s  . c  o m*/
private static Config loadConfigFromFile(String propertiesFileName) throws IOException {

    Config conf = new Config();

    try {
        // Load configs from properties file
        LOG.debug("Loading properties from " + propertiesFileName);
        InputStream fileInputStream = new FileInputStream(propertiesFileName);
        Properties properties = new Properties();
        try {
            properties.load(fileInputStream);
        } finally {
            fileInputStream.close();
        }

        for (@SuppressWarnings("rawtypes")
        Map.Entry me : properties.entrySet()) {
            try {
                // Check every property and covert to appropriate data type before
                // adding it to storm config. If no data type defined keep it as string
                if (keyTypeMap.containsKey(me.getKey().toString())) {
                    if (Number.class.equals(keyTypeMap.get(me.getKey().toString()))) {
                        conf.put((String) me.getKey(), Long.valueOf(((String) me.getValue()).trim()));
                    } else if (Map.class.equals(keyTypeMap.get(me.getKey().toString()))) {
                        if (me.getValue() != null) {
                            Map<String, Object> map = new HashMap<String, Object>();
                            String kvPairs[] = StringUtils.split(me.getValue().toString(),
                                    properties.getProperty("map.kv.pair.separator", ","));
                            for (String kvPair : kvPairs) {
                                String kv[] = StringUtils.split(kvPair,
                                        properties.getProperty("map.kv.separator", "="));
                                map.put((String) kv[0], kv[1].trim());
                            }
                            conf.put((String) me.getKey(), map);
                        }
                    } else if (Boolean.class.equals(keyTypeMap.get((String) me.getKey()))) {
                        conf.put((String) me.getKey(), Boolean.valueOf(((String) me.getValue()).trim()));
                    }
                } else {
                    conf.put(me.getKey().toString(), me.getValue());
                }
            } catch (NumberFormatException nfe) {
                LOG.error("Failed while loading properties from file " + propertiesFileName + ". The value '"
                        + me.getValue() + "' for property " + me.getKey() + " is expected to be numeric", nfe);
                throw nfe;
            }
        }
    } catch (IOException ioe) {
        LOG.error("Failed while loading properties from file " + propertiesFileName, ioe);
        throw ioe;
    }
    return conf;
}

From source file:com.redhat.rhn.common.security.SessionSwap.java

/** given a session swap string, this will crack it open and
 * return the data./*from   w  w w.j  a  v  a 2s . c  o  m*/
 * @param in The session swap to inspect.
 * @return The data extracted from the session swap
 * @throws SessionSwapTamperException if the data was
 *         tampered with, making it easy to use and trust
 */
public static String[] extractData(String in) {
    String[] splitResults = StringUtils.split(in, 'x');
    String[] data = StringUtils.split(splitResults[0], ':');

    String recomputedDigest = encodeData(data);

    if (recomputedDigest.equals(in)) {
        return data;
    }
    throw new SessionSwapTamperException(in);
}

From source file:info.archinnov.achilles.configuration.ArgumentExtractor.java

public List<String> initEntityPackages(Map<String, Object> configurationMap) {
    List<String> entityPackages = new ArrayList<String>();
    String entityPackagesParameter = (String) configurationMap.get(ENTITY_PACKAGES_PARAM);
    if (StringUtils.isNotBlank(entityPackagesParameter)) {
        entityPackages = Arrays.asList(StringUtils.split(entityPackagesParameter, ","));
    }//ww w. j  av a2s  . c o m

    return entityPackages;
}

From source file:edu.mayo.cts2.framework.plugin.service.lexevs.naming.VersionNameConverter.java

public boolean isValidVersionName(String cts2CodeSystemVersionName) {
    String[] nameParts = StringUtils.split(cts2CodeSystemVersionName, SEPARATOR);
    return nameParts.length >= 2;
}

From source file:de.hybris.platform.acceleratorfacades.urlencoder.impl.DefaultUrlEncoderFacade.java

@Deprecated
@Override// w w  w.  j  a  v  a2s.  c  o  m
public UrlEncoderPatternData patternForUrlEncoding(final String uri, final String contextPath,
        final boolean newSession) {
    final List<UrlEncoderData> urlEncodingAttributes = variablesForUrlEncoding();
    final UrlEncoderPatternData patternData = new UrlEncoderPatternData();
    final String[] splitUrl = StringUtils.split(uri, "/");
    int splitUrlCounter = (ArrayUtils.isNotEmpty(splitUrl)
            && (StringUtils.remove(contextPath, "/").equals(splitUrl[0]))) ? 1 : 0;
    for (final UrlEncoderData urlEncoderData : urlEncodingAttributes) {
        boolean applicationDriven = false;
        if ((splitUrlCounter) < splitUrl.length) {
            String tempValue = splitUrl[splitUrlCounter];
            if (!isValid(urlEncoderData.getAttributeName(), tempValue)) {
                tempValue = urlEncoderData.getDefaultValue();
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Encoding attributes are absent. Injecting default value :  [" + tempValue + "]");
                }
            }
            final UrlEncodingAttributeManager attributeManager = getUrlEncoderService()
                    .getUrlEncodingAttrManagerMap().get(urlEncoderData.getAttributeName());
            //Check if its driven by user and if so redirect
            if (!newSession && !StringUtils.equalsIgnoreCase(urlEncoderData.getCurrentValue(),
                    attributeManager.getCurrentValue())) {
                urlEncoderData.setCurrentValue(attributeManager.getCurrentValue());
                patternData.setRedirectRequired(true);
                applicationDriven = true;
            }
            if (!applicationDriven) {
                urlEncoderData.setCurrentValue(tempValue);
            }
            splitUrlCounter++;
        } else {
            break;
        }
    }
    patternData.setPattern(extractEncodingPattern(urlEncodingAttributes));

    return patternData;
}

From source file:com.ning.metrics.eventtracker.TestThriftEncoding.java

private Event extractEvent(String category, String message) throws TException, IOException {
    Event event;/*from  w  w w  . j  a v a  2s . c om*/
    Long eventDateTime;

    String[] payload = StringUtils.split(message, ":");

    byte[] thrift = new Base64().decode(payload[1].getBytes());
    try {
        eventDateTime = Long.parseLong(payload[0]);
        event = ThriftToThriftEnvelopeEvent.extractEvent(category, new DateTime(eventDateTime), thrift);
    } catch (RuntimeException e) {
        event = ThriftToThriftEnvelopeEvent.extractEvent(category, thrift);
    }

    return event;
}

From source file:com.edgenius.wiki.service.impl.SitemapMetadata.java

/**
 * @param pageUuid//from  w ww.j  a v  a 2s  .co  m
 * @return
 */
public String getSitemapIndex(String pageUuid) {
    String value = pageMap.get(pageUuid);
    String[] str = StringUtils.split(value, SEP);
    if (str != null && str.length == 2) {
        return str[0];
    }
    return null;
}

From source file:be.i8c.codequality.sonar.plugins.sag.webmethods.flow.FlowLanguage.java

private String[] getNodeFileSuffixes() {
    String[] suffixes = filterEmptyStrings(
            config.getStringArray(FlowLanguageProperties.NODE_FILE_SUFFIXES_KEY));
    if (suffixes.length == 0) {
        suffixes = StringUtils.split(FlowLanguageProperties.NODE_FILE_SUFFIXES_DEFVALUE, ",");
    }/*  w  w  w  . j a  v a  2 s.c om*/
    return suffixes;
}

From source file:com.netflix.simianarmy.conformity.TestCrossZoneLoadBalancing.java

@Override
protected List<String> getLoadBalancerNamesForAsg(String region, String asgName) {
    return Arrays.asList(StringUtils.split(asgToElbs.get(asgName), ","));
}