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

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

Introduction

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

Prototype

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

Source Link

Document

Splits the provided text into an array, separators specified.

Usage

From source file:com.tugo.dt.ApplicationTest.java

@Test
public void test1() throws IOException {
    boolean b = BooleanUtils.toBoolean("true");
    System.out.println(b);/*from  w  w w.ja va2s  .  c  o  m*/

    b = BooleanUtils.toBoolean("false");
    System.out.println(b);

    b = BooleanUtils.toBoolean("true1");
    System.out.println(b);

    b = BooleanUtils.toBoolean((String) null);
    System.out.println(b);

    String[] arr = StringUtils.split("[tushar,gosavi]", ",");
    for (String a : arr) {
        System.out.println(a);
    }
}

From source file:com.xpn.xwiki.render.XWikiVirtualMacro.java

public XWikiVirtualMacro(String mapping) {
    String[] mapping1 = StringUtils.split(mapping, "=");
    this.name = mapping1[0];
    String[] map = StringUtils.split(mapping1[1], ":");
    this.language = map[0];
    this.functionName = map[1];
    if (map.length != 2) {
        String[] aparams = StringUtils.split(map[2], ",");
        if (aparams.length > 0) {
            for (int i = 0; i < aparams.length; i++) {
                String[] param = StringUtils.split(aparams[i], "|");
                String pname = param[0];
                this.params.add(pname);
                if (param.length > 1) {
                    String ptype = param[1];
                    this.paramsTypes.put(pname, ptype);
                } else {
                    this.paramsTypes.put(pname, "string");
                }//from   w  ww  . j  a  va2  s.  c  om

            }
        }

        if (map.length == 4) {
            this.multiLine = true;
        }
    }
}

From source file:com.frame.base.utils.ReflectionUtils.java

/**
 * Setter. valueClass?Setter./*  w ww .  j a  v a  2 s. c  o m*/
 * @throws NoSuchFieldException 
 * @throws SecurityException 
 */
public static void _invokeSetterMethod(Object obj, String propertyName, Object value) {
    String[] methods = StringUtils.split(propertyName, '.');
    int len = methods.length - 1;
    for (int i = 0; i < len; i++)
        obj = invokeGetter(obj, methods[i]);
    try {
        Field filed = obj.getClass().getDeclaredField(methods[len]);
        if (filed.getType().getSimpleName().equals("BigDecimal")) {
            invokeSetter(obj, methods[len], new BigDecimal(value.toString()));
        } else {
            invokeSetter(obj, methods[len], value);
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        invokeSetter(obj, methods[len], value);
    }

}

From source file:net.noday.cat.service.impl.TagServiceImpl.java

@Override
public void save(long aid, String tagStr) {
    String[] ts = StringUtils.split(tagStr, ",");
    for (String tag : ts) {
        Tag obj = dao.getByName(tag);/*from   w  w  w  .j  a  va2  s .  c om*/
        if (obj != null) {
            dao.saveRef(aid, obj.getId(), 1);
            dao.updateTagRefCount(tag);
        } else {
            dao.saveTagAndRef(aid, tag);
        }
    }
}

From source file:name.martingeisse.common.security.SecurityTokenUtil.java

/**
 * Validates the specified security token. Returns the subject if the token is valid.
 * Throws an {@link IllegalArgumentException} if invalid. This exception contains
 * an error message about the problem./*from   w  w w.j  a  v a  2s. co m*/
 * 
 * @param token the token
 * @param minTimestamp the maximum allowed value for the token's timestamp
 * @param secret the secret used to generate the HMAC
 * @return the token's subject
 */
public static String validateToken(String token, ReadableInstant minTimestamp, String secret) {

    // split the token into segments
    String[] tokenSegments = StringUtils.split(token, '|');
    if (tokenSegments.length != 3) {
        throw new IllegalArgumentException("malformed token (has " + tokenSegments.length + " segments)");
    }

    // validate the signature
    String payload = (tokenSegments[0] + '|' + tokenSegments[1]);
    String expectedSignatureBase64 = HmacUtil.generateHmacBase64(payload, secret, HmacUtil.ALGORITHM_SHA256);
    if (!expectedSignatureBase64.equals(tokenSegments[2])) {
        throw new IllegalArgumentException("invalid token signature");
    }

    // validate the timestamp
    ReadableInstant timestamp;
    try {
        timestamp = dateTimeFormatter.parseDateTime(tokenSegments[1]);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("malformed timestamp: " + e.getMessage());
    }
    if (timestamp.isBefore(minTimestamp)) {
        throw new IllegalArgumentException("token has expired");
    }

    // return the subject
    return tokenSegments[0];

}

From source file:io.wcm.dam.assetservice.impl.AssetRequestParser.java

private static List<AssetRequest> getAssetRequestsFromSuffix(String assetPath,
        SlingHttpServletRequest request) {
    List<AssetRequest> requests = new ArrayList<>();

    String suffixWithoutExtension = StringUtils.substringBefore(request.getRequestPathInfo().getSuffix(), ".");
    String[] suffixParts = StringUtils.split(suffixWithoutExtension, "/");
    if (suffixParts != null) {
        for (String suffixPart : suffixParts) {
            Map<String, String> params = parseSuffixPart(suffixPart);
            String mediaFormat = params.get(RP_MEDIAFORMAT);
            long width = NumberUtils.toLong(params.get(RP_WIDTH));
            long height = NumberUtils.toLong(params.get(RP_HEIGHT));
            if (StringUtils.isNotEmpty(mediaFormat) || width > 0 || height > 0) {
                requests.add(new AssetRequest(assetPath, mediaFormat, width, height));
            }/* www . j a  v  a  2  s .c  o m*/
        }
    }

    return requests;
}

From source file:cn.com.qiqi.order.web.system.entity.Role.java

@Transient
public List<String> getPermissionList() {
    return ImmutableList.copyOf(StringUtils.split(permissions, ","));
}

From source file:mesosphere.dcos.hazelcast.discovery.DcosDiscoveryStrategy.java

@Override
public Iterable<DiscoveryNode> discoverNodes() {
    List<DiscoveryNode> servers = new LinkedList<>();

    for (String node : StringUtils.split(System.getenv("HAZELCAST_INITIAL_MEMBERS"), System.lineSeparator())) {
        try {/*from  www .ja  v  a 2s .co m*/
            servers.add(new SimpleDiscoveryNode(new Address(node, 5701)));
        } catch (UnknownHostException e) {
            LOG.warn(String.format("DNS name '%s' not resolvable", node), e);
        }
    }
    return servers;
}

From source file:com.adguard.android.contentblocker.ServiceApiClient.java

/**
 * Downloads filter rules//from ww  w.jav a2 s  . c o m
 *
 * @param filterId    Filter id
 * @return List of rules
 * @throws IOException
 */
public static List<String> downloadFilterRules(Context context, int filterId) throws IOException {
    String downloadUrl = RawResources.getFilterUrl(context);
    downloadUrl = downloadUrl.replace("{0}", UrlUtils.urlEncode(Integer.toString(filterId)));

    LOG.info("Sending request to {}", downloadUrl);
    String response = downloadString(downloadUrl);

    LOG.debug("Response length is {}", response.length());
    String[] rules = StringUtils.split(response, "\r\n");
    List<String> filterRules = new ArrayList<>();
    for (String line : rules) {
        String rule = StringUtils.trim(line);
        if (!StringUtils.isEmpty(rule)) {
            filterRules.add(rule);
        }
    }

    return filterRules;
}

From source file:jp.ambrosoli.http.server.action.IndexAction.java

@Execute(validator = false)
public String helloWorld() {
    String name = this.request.getParameter("name");
    String queryString = this.requestScope.get("javax.servlet.forward.query_string");
    String[] query = StringUtils.split(queryString, "=");
    if (ArrayUtils.isNotEmpty(query)) {
        try {/*from  ww  w. j  a  v a 2  s  .c o m*/
            name = URLDecoder.decode(query[1], this.request.getCharacterEncoding());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    if (StringUtils.isEmpty(name)) {
        this.response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    }
    ResponseUtil.write("Hello, " + name + "!", "UTF-8");
    return null;
}