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.neocotic.bloggaer.common.Requests.java

/**
 * Returns the IP address that appears to be the source of the specified {@code request}.
 * /* www  . j  av  a  2s . co  m*/
 * @param request
 *            the {@code HttpServletRequest} to check
 * @return The IP address.
 */
public static String getIpAddress(HttpServletRequest request) {
    logger.entering(request);

    String ipAddress = request.getHeader("X-Forwarded-For");
    if (ipAddress == null) {
        ipAddress = request.getRemoteAddr();
    } else {
        String[] ipAddresses = StringUtils.split(ipAddress, ",");
        if (ipAddresses.length > 0)
            ipAddress = ipAddresses[0];
    }

    logger.exiting(ipAddress);
    return ipAddress;
}

From source file:de.bmarwell.j9kwsolver.util.ResponseUtils.java

/**
 * @param response The response sent by the server.
 * @return null if response is null or empty, else a HashMap.
 *//*  w ww.  ja  v  a 2 s.c  o  m*/
public static Map<String, Integer> stringResponseToIntMap(final String response) {
    Map<String, Integer> result = new HashMap<String, Integer>();

    if (StringUtils.isEmpty(response)) {
        /* 
         * Response should be like so:
         * worker=15|avg24h=12s|avg1h=12s|avg15m=13s|avg5m=13s|inwork=8|
         *     queue=0|queue1=0|queue2=0|workermouse=13|
         *     workerconfirm=14|workertext=13
         */
        return null;
    }

    List<String> serverstatelist = Arrays.asList(StringUtils.split(response, '|'));

    /* Iterate each item in response */
    for (String item : serverstatelist) {
        String[] keyValue = StringUtils.split(item, '=');
        int value = 0;

        if (keyValue.length != 2) {
            LOG.warn("Key-Value splitting on '=' doesn't return 2 items: {}.", item);
            continue;
        }

        String key = keyValue[0];
        String textvalue = keyValue[1];
        textvalue = StringUtils.removeEnd(textvalue, "s");

        if (!NumberUtils.isDigits(textvalue)) {
            LOG.warn("Key-Value where value is non-numeric: {}", item);
            continue;
        } else {
            value = NumberUtils.toInt(textvalue);
        }

        result.put(key, value);
    }

    return result;
}

From source file:com.whizzosoftware.hobson.dto.ExpansionFields.java

/**
 * Constructor./* w  ww.ja  va 2 s  . c o m*/
 *
 * @param expansions a comma-separated list of expansion fields
 */
public ExpansionFields(String expansions) {
    if (expansions != null) {
        expansionFields = new ArrayList(Arrays.asList(StringUtils.split(expansions, ',')));
    }
}

From source file:kenh.expl.functions.Split.java

public String[] process(String str, String separatorChar) {
    return StringUtils.split(str, separatorChar);
}

From source file:flpitu88.web.backend.psicoweb.config.Jwt.java

/**
 * Static method to decode a JSON Web Token
 *
 * @param token Token to decode/*from   w w  w. j  a v  a  2s.c om*/
 * @param key Key used for the signature
 * @param verify True if you want to verify the signature
 *
 * @return payload
 *
 * @throws IllegalStateException
 * @throws IllegalArgumentException
 * @throws VerifyException
 * @throws NoSuchAlgorithmException
 * @throws UnsupportedEncodingException
 * @throws InvalidKeyException
 * @throws AlgorithmException
 */
public static Map<String, Object> decode(String token, String key, Boolean verify)
        throws IllegalStateException, VerifyException, IllegalArgumentException, NoSuchAlgorithmException,
        UnsupportedEncodingException, InvalidKeyException, AlgorithmException {
    if (token == null || token.length() == 0) {
        throw new IllegalStateException("Token not set");
    }
    // Check key
    if (key == null || key.length() == 0) {
        throw new IllegalArgumentException("Key cannot be null or empty");
    }

    String[] segments = StringUtils.split(token, ".");
    if (segments.length != 3) {
        throw new IllegalStateException("Bad number of segments: " + segments.length);
    }

    // All segment should be base64
    String headerSeg = segments[0];
    String payloadSeg = segments[1];
    String signatureSeg = segments[2];

    Type stringObjectMap = new TypeToken<HashMap<String, Object>>() {
    }.getType();
    Gson gson = new Gson();
    HashMap<String, Object> header = gson.fromJson(base64Decode(headerSeg), stringObjectMap);
    HashMap<String, Object> payload = gson.fromJson(base64Decode(payloadSeg), stringObjectMap);

    if (verify) {
        Algorithm algorithm = getAlgorithm(header.get("alg").toString());

        // Verify signature. `sign` will return base64 String
        String signinInput = StringUtils.join(new String[] { headerSeg, payloadSeg }, ".");
        if (!verify(signinInput, key, algorithm.getValue(), signatureSeg)) {
            throw new VerifyException("Bad signature");
        }
    }

    return payload;
}

From source file:com.techcavern.wavetact.eventListeners.PrivMsgListener.java

@Override
public void onPrivateMessage(PrivateMessageEvent event) throws Exception {
    class process implements Runnable {
        public void run() {
            String[] message = StringUtils.split(Colors.removeFormatting(event.getMessage()), " ");
            String commandchar = IRCUtils.getCommandChar(event.getBot(), null);
            String privcommand = message[0].toLowerCase();
            IRCUtils.sendLogChanMsg(event.getBot(),
                    "[PM] " + IRCUtils.noPing(event.getUser().getNick()) + "!" + event.getUser().getLogin()
                            + "@" + event.getUser().getHostname() + ": " + event.getMessage());
            if (commandchar != null)
                privcommand = StringUtils.replaceOnce(privcommand, commandchar, "");
            IRCCommand Command = IRCUtils.getCommand(privcommand,
                    IRCUtils.getNetworkNameByNetwork(event.getBot()), null);
            message = ArrayUtils.remove(message, 0);
            if (Command != null) {
                String logmsg = StringUtils.join(message, " ");
                if (Command.getChannelRequired()) {
                    Channel channel = null;
                    String prefix = null;
                    if (message.length > 0) {
                        prefix = IRCUtils.getPrefix(event.getBot(), message[0]);
                        if (!prefix.isEmpty())
                            channel = IRCUtils.getChannelbyName(event.getBot(), message[0].replace(prefix, ""));
                        else
                            channel = IRCUtils.getChannelbyName(event.getBot(), message[0]);
                        message = ArrayUtils.remove(message, 0);
                    }/*from  w w  w.j a va  2  s.  c om*/
                    if (channel != null) {
                        int userPermLevel = PermUtils.getPermLevel(event.getBot(), event.getUser().getNick(),
                                channel);
                        if (userPermLevel >= Command.getPermLevel()) {
                            try {
                                Command.onCommand(privcommand, event.getUser(), event.getBot(), prefix, channel,
                                        true, userPermLevel, message);
                            } catch (Exception e) {
                                IRCUtils.sendError(event.getUser(), event.getBot(), null,
                                        "Failed to execute command, please make sure you are using the correct syntax ("
                                                + Command.getSyntax() + ")",
                                        "");
                                e.printStackTrace();
                            }
                        } else {
                            IRCUtils.sendError(event.getUser(), event.getBot(), null, "Permission denied", "");
                        }
                    } else {
                        IRCUtils.sendError(event.getUser(), event.getBot(), null,
                                "Please specify channel as argument #1 in front of all the other arguments",
                                "");
                    }
                } else {
                    int userPermLevel = PermUtils.getPermLevel(event.getBot(), event.getUser().getNick(), null);
                    if (Command.getPermLevel() == 0) {
                        try {
                            Command.onCommand(privcommand, event.getUser(), event.getBot(), null, null, true,
                                    userPermLevel, message);
                        } catch (Exception e) {
                            IRCUtils.sendError(event.getUser(), event.getBot(), null,
                                    "Failed to execute command, please make sure you are using the correct syntax ("
                                            + Command.getSyntax() + ")",
                                    "");
                            e.printStackTrace();
                        }
                    } else if (Command.getPermLevel() <= 5 && userPermLevel >= 1) {
                        try {
                            Command.onCommand(privcommand, event.getUser(), event.getBot(), null, null, true,
                                    userPermLevel, message);
                        } catch (Exception e) {
                            IRCUtils.sendError(event.getUser(), event.getBot(), null,
                                    "Failed to execute command, please make sure you are using the correct syntax ("
                                            + Command.getSyntax() + ")",
                                    "");
                            e.printStackTrace();
                        }
                    } else {
                        if (userPermLevel >= Command.getPermLevel()) {
                            try {
                                Command.onCommand(privcommand, event.getUser(), event.getBot(), null, null,
                                        true, userPermLevel, message);
                            } catch (Exception e) {
                                IRCUtils.sendError(event.getUser(), event.getBot(), null,
                                        "Failed to execute command, please make sure you are using the correct syntax ("
                                                + Command.getSyntax() + ")",
                                        "");
                                e.printStackTrace();
                            }
                        } else {
                            IRCUtils.sendError(event.getUser(), event.getBot(), null, "Permission denied", "");
                        }
                    }
                }
            }
        }

    }
    Registry.threadPool.execute(new process());
}

From source file:com.asiainfo.tfsPlatform.po.Role.java

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

From source file:io.wcm.devops.maven.nodejsproxy.resource.Checksums.java

/**
 * @param data Checksums file content/*from ww w .j ava 2  s  . c om*/
 */
public Checksums(String data) {
    String[] lines = StringUtils.split(data, "\n");
    for (String line : lines) {
        String checksum = StringUtils.substringBefore(line, "  ");
        String filename = StringUtils.substringAfter(line, "  ");
        if (StringUtils.isNoneBlank(checksum, filename)) {
            checksums.put(filename, checksum);
        }
    }
}

From source file:de.jfachwert.math.Bruch.java

private static BigInteger[] toNumbers(String bruch) {
    BigInteger[] numbers = new BigInteger[2];
    String[] parts = StringUtils.split(bruch, "/");
    try {/*  w w  w  . jav  a  2  s .co  m*/
        switch (parts.length) {
        case 1:
            Bruch dezimalBruch = toBruch(new BigDecimal(parts[0]));
            numbers[0] = dezimalBruch.getZaehler();
            numbers[1] = dezimalBruch.getNenner();
            break;
        case 2:
            numbers[0] = new BigInteger(parts[0]);
            numbers[1] = new BigInteger(parts[1]);
            break;
        default:
            throw new LocalizedIllegalArgumentException(bruch, "fraction");
        }
        return numbers;
    } catch (IllegalArgumentException ex) {
        throw new LocalizedIllegalArgumentException(bruch, "fraction", ex);
    }
}

From source file:com.cognifide.qa.bb.modules.BobcatRunModule.java

@Override
protected void configure() {
    String runmodes = System.getProperty("runmode", "default");
    String[] separateRunModes = StringUtils.split(runmodes, ",");
    List<String> modules = new ArrayList<>();
    TypeReference typeReference = new TypeReference<List<String>>() {
    };/*from  www.j a v a  2s.  com*/
    Arrays.stream(separateRunModes).forEach(
            runmode -> modules.addAll(YamlReader.readFromTestResources("runmodes/" + runmode, typeReference)));
    modules.stream().forEach(this::installFromName);
}