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.netflix.simianarmy.conformity.TestSameZonesInElbAndAsg.java

@Override
protected List<String> getAvailabilityZonesForLoadBalancer(String region, String lbName) {
    return Arrays.asList(StringUtils.split(elbToZones.get(lbName), ","));
}

From source file:com.flexive.shared.FxArrayUtils.java

/**
 * Converts a list with long items separated by a specific delimeter to a array.
 * <p/>//w w  w. j  a  v  a 2s.co m
 * A empty array will be returned if the list is null or a empty string.
 *
 * @param list      the list
 * @param separator the separator character
 * @return the array
 * @throws FxInvalidParameterException if the list can not be converted, the exception's getParameterName()
 *                                     function will return the token that caused the exception
 */
public static long[] toLongArray(String list, char separator) throws FxInvalidParameterException {
    if (list == null || list.length() == 0)
        return new long[0];
    String sLongs[] = StringUtils.split(list, separator);
    long result[] = new long[sLongs.length];
    for (int i = 0; i < sLongs.length; i++) {
        try {
            result[i] = Long.parseLong(sLongs[i]);
        } catch (Exception exc) {
            throw new FxInvalidParameterException(
                    "'" + list + "' can not be converted to a long[] array using separator '" + separator + "'",
                    sLongs[i]);
        }
    }
    return result;
}

From source file:info.magnolia.cms.filters.HostSecurityFilter.java

/**
 * Adds a mapping (used by content2bean).
 * @param mapping in the form /path=host
 *//*from  w ww  .j  ava 2s.co  m*/
@Override
public void addMapping(String mapping) {
    String[] pathToHost = StringUtils.split(mapping, "=");
    if (pathToHost != null && pathToHost.length == 2) {
        synchronized (uriToHost) {
            uriToHost.add(pathToHost);
        }
    }
}

From source file:com.adobe.acs.commons.users.impl.Ace.java

@SuppressWarnings("squid:S3776")
public Ace(String raw) throws EnsureAuthorizableException {
    String[] segments = StringUtils.split(raw, PARAM_DELIMITER);

    for (String segment : segments) {
        AbstractMap.SimpleEntry<String, String> entry = ParameterUtil.toSimpleEntry(segment,
                KEY_VALUE_SEPARATOR);/*  w  w w .java 2s  . c o m*/

        if (entry == null) {
            continue;
        }
        if (StringUtils.equals(PROP_TYPE, entry.getKey())) {
            this.type = StringUtils.stripToNull(entry.getValue());
        } else if (StringUtils.equals(PROP_PATH, entry.getKey())) {
            this.path = StringUtils.stripToNull(entry.getValue());
        } else if (StringUtils.equals(PROP_REP_GLOB, entry.getKey())) {
            this.repGlob = StringUtils.stripToEmpty(entry.getValue());
        } else if (StringUtils.equals(PROP_REP_NT_NAMES, entry.getKey())) {
            this.repNtNames.addAll(Arrays
                    .asList(StringUtils.split(StringUtils.stripToEmpty(entry.getValue()), LIST_SEPARATOR)));
        } else if (StringUtils.equals(PROP_REP_ITEM_NAMES, entry.getKey())) {
            this.repItemNames.addAll(Arrays
                    .asList(StringUtils.split(StringUtils.stripToEmpty(entry.getValue()), LIST_SEPARATOR)));
        } else if (StringUtils.equals(PROP_REP_PREFIXES, entry.getKey())) {
            this.repPrefixes.addAll(Arrays
                    .asList(StringUtils.split(StringUtils.stripToEmpty(entry.getValue()), LIST_SEPARATOR)));
        } else if (StringUtils.equals(PROP_PRIVILEGES, entry.getKey())) {
            for (String privilege : StringUtils.split(entry.getValue(), LIST_SEPARATOR)) {
                privilege = StringUtils.stripToNull(privilege);
                if (privilege != null) {
                    this.privilegeNames.add(privilege);
                }
            }
        }
    }

    validate(this.type, this.path, this.privilegeNames);
}

From source file:cn.yiyizuche.common.base.Page.java

/**
 * ???./*w w w.j a v  a 2  s . co  m*/
 * 
 * @param order
 *            ?descasc,?','.
 */
public void setOrder(final String order) {
    String lowcaseOrder = StringUtils.lowerCase(order);

    // order?
    String[] orders = StringUtils.split(lowcaseOrder, ',');
    for (String orderStr : orders) {
        if (!StringUtils.equals(DESC, orderStr) && !StringUtils.equals(ASC, orderStr)) {
            throw new IllegalArgumentException("??" + orderStr + "??");
        }
    }

    this.order = lowcaseOrder;
}

From source file:mp.platform.cyclone.webservices.AuthInterceptor.java

public void handleMessage(final SoapMessage message) throws Fault {
    final HttpServletRequest request = WebServiceHelper.requestOf(message);
    ServiceClient client = null;//from ww w.j ava  2s  .c  o  m
    final ServletContext servletContext = servletContextOf(message);
    try {
        if (!applicationService.isOnline()) {
            WebServiceFaultsEnum.APPLICATION_OFFLINE.throwFault();
        }

        // Check non-secure access when HTTP is enabled
        if (Boolean.TRUE.equals(servletContext.getAttribute("cyclos.httpEnabled"))) {
            final String protocol = StringUtils.split(request.getRequestURL().toString(), "://")[0];
            if (!"https".equalsIgnoreCase(protocol)) {
                WebServiceFaultsEnum.SECURE_ACCESS_REQUIRED.throwFault();
            }
        }

        boolean allowed = false;
        // Find the service client
        client = resolveClient(request);
        if (client != null) {
            // Find the requested operation
            final ServiceOperation[] operations = resolveOperations(message);
            if (operations.length == 0) {
                // When there are no operations, access is granted to anyone
                allowed = true;
            } else {
                // Check whether the client has access to the requested operation
                final Set<ServiceOperation> permissions = client.getPermissions();
                for (final ServiceOperation serviceOperation : operations) {
                    if (permissions.contains(serviceOperation)) {
                        allowed = true;
                        break;
                    }
                }
            }
        }
        if (!allowed) {
            WebServiceFaultsEnum.UNAUTHORIZED_ACCESS.throwFault();
        } else {
            loggingHandler.traceWebService(request.getRemoteAddr(), client,
                    WebServiceHelper.getWebServiceOperationName(message),
                    WebServiceHelper.getParameters(message));
        }

        // Ensure the LoggedUser state is consistent
        final Member member = client.getMember();
        if (member != null) {
            // Initialize the LoggedUser when restricted to a member
            LoggedUser.init(member.getUser(), request.getRemoteAddr());
        } else {
            // Not restricted: ensure there's no user logged in
            LoggedUser.cleanup();
        }
    } finally {
        // Initialize the context
        WebServiceContext.set(client, servletContext, request, message);
    }
}

From source file:com.ecyrd.jspwiki.Release.java

/**
 *  Returns true, if this version of JSPWiki is newer or equal than what is requested.
 *  @param version A version parameter string (a.b.c-something). B and C are optional.
 *  @return A boolean value describing whether the given version is newer than the current JSPWiki.
 *  @since 2.4.57//  w w w .  j  a v a2s. c  o m
 *  @throws IllegalArgumentException If the version string could not be parsed.
 */
public static boolean isNewerOrEqual(String version) throws IllegalArgumentException {
    if (version == null)
        return true;
    String[] versionComponents = StringUtils.split(version, VERSION_SEPARATORS);
    int reqVersion = versionComponents.length > 0 ? Integer.parseInt(versionComponents[0]) : Release.VERSION;
    int reqRevision = versionComponents.length > 1 ? Integer.parseInt(versionComponents[1]) : Release.REVISION;
    int reqMinorRevision = versionComponents.length > 2 ? Integer.parseInt(versionComponents[2])
            : Release.MINORREVISION;

    if (VERSION == reqVersion) {
        if (REVISION == reqRevision) {
            if (MINORREVISION == reqMinorRevision) {
                return true;
            }

            return MINORREVISION > reqMinorRevision;
        }

        return REVISION > reqRevision;
    }

    return VERSION > reqVersion;
}

From source file:com.comcast.viper.flume2storm.location.StaticLocationService.java

/**
 * @param configuration/*  ww w . j  a va2  s  .  c o  m*/
 *          The configuration that contains the {@link ServiceProvider}
 * @param serialization
 *          The {@link ServiceProviderSerialization} to use
 * @throws F2SConfigurationException
 *           If the configuration is invalid
 */
public StaticLocationService(Configuration configuration, final ServiceProviderSerialization<SP> serialization)
        throws F2SConfigurationException {
    this.serialization = serialization;
    StaticLocationServiceConfiguration staticLocationServiceConfig = StaticLocationServiceConfiguration
            .from(configuration);

    String configLoaderClassName = staticLocationServiceConfig.getConfigurationLoaderClassName();
    ServiceProviderConfigurationLoader<SP> spLoader = null;
    try {
        @SuppressWarnings("unchecked")
        Class<? extends ServiceProviderConfigurationLoader<SP>> loaderFactoryClass = (Class<? extends ServiceProviderConfigurationLoader<SP>>) Class
                .forName(configLoaderClassName);
        spLoader = loaderFactoryClass.newInstance();
    } catch (Exception e) {
        throw new F2SConfigurationException("Failed to load ServiceProviderConfigurationLoader class", e);
    }
    assert spLoader != null;

    String spString = configuration.getString(StaticLocationServiceConfiguration.SERVICE_PROVIDER_LIST);
    LOG.trace("Service providers to load: {}", spString);
    if (spString == null)
        return;
    Configuration spConfig = configuration.subset(staticLocationServiceConfig.getServiceProviderBase());
    Builder<SP> spBuilders = ImmutableList.builder();
    for (String spName : StringUtils.split(spString,
            StaticLocationServiceConfiguration.SERVICE_PROVIDER_LIST_SEPARATOR)) {
        LOG.trace("Loading service provider: {}", spName);
        Configuration providerConfig = spConfig.subset(spName);
        SP serviceProvider = spLoader.load(providerConfig);
        if (serviceProvider != null) {
            LOG.debug("Loaded service provider {}: {}", spName, serviceProvider);
            spBuilders.add(serviceProvider);
        } else {
            LOG.error("Failed to load service provider identified with {}", spName);
        }
    }
    serviceProviderManager.set(spBuilders.build());
}

From source file:info.magnolia.cms.taglibs.util.TableTag.java

/**
 * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
 *//* w  w  w  .  j  av a  2 s  . c o m*/
public int doEndTag() throws JspException {
    String data = getBodyContent().getString();
    JspWriter out = pageContext.getOut();

    if (StringUtils.isEmpty(data)) {
        return EVAL_PAGE;
    }

    try {
        out.print("<table cellspacing=\"0\" ");
        writeAttributes(out, htmlAttributes);
        out.print(">\n");

        String[] rows = data.split("\n");

        int startingRow = 0;

        if (header && rows.length > 0) {
            startingRow = 1; // for body
            out.print("<thead>\n");
            out.print("<tr>\n");

            String[] cols = StringUtils.split(rows[0], "\t");
            for (int col = 0; col < cols.length; col++) {
                out.print("<th>");
                out.print(cols[col]);
                out.print("</th>\n");
            }

            out.print("</tr>\n");
            out.print("</thead>\n");

        }

        if (rows.length > startingRow) {
            out.print("<tbody>\n");

            for (int row = startingRow; row < rows.length; row++) {

                out.print("<tr");

                out.print(" class=\"");
                out.print(row % 2 == 0 ? "even" : "odd");

                out.print("\">\n");

                String[] cols = StringUtils.split(rows[row], "\t");

                for (int col = 0; col < cols.length; col++) {
                    out.print("<td>");
                    out.print(cols[col]);
                    out.print("</td>\n");
                }
                out.print("</tr>\n");

            }
            out.print("</tbody>\n");
        }
        out.print("</table>\n");
    } catch (IOException e) {
        // should never happen
        log.debug(e.getMessage(), e);
    }

    return EVAL_PAGE;
}

From source file:com.flexive.rest.client.RemoteMapSimple.java

private String[] splitPath(String path) {
    return StringUtils.split(path, '/');
}