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.dianping.lion.web.action.system.OperationLogAction.java

public String viewKeys() {
    String[] keyTokens = StringUtils.split(keys, ",");
    for (String keyToken : keyTokens) {
        String[] tokens = StringUtils.split(keyToken, ":");
        String keycontent = operationLogService.getLogKey(logid, tokens[1]);
        keyMap.put(tokens[0], keycontent);
    }/*from  w  w  w  .  j  av  a 2  s.co m*/
    return SUCCESS;
}

From source file:com.shishu.utility.url.TableUtil.java

private static void reverseAppendSplits(String string, StringBuilder buf) {
    String[] splits = StringUtils.split(string, '.');
    if (splits.length > 0) {
        for (int i = splits.length - 1; i > 0; i--) {
            buf.append(splits[i]);/*w  ww.j  a va  2 s  .c  o  m*/
            buf.append('.');
        }
        buf.append(splits[0]);
    } else {
        buf.append(string);
    }
}

From source file:ips1ap101.lib.core.db.util.DBUtils.java

public static String[] getConstraintMessageKeys(String message) {
    String trimmed = StringUtils//from w  w  w. j  a  v a2s .  com
            .trimToEmpty(StringUtils.substringAfter(StringUtils.substringBefore(message, WHERE), ERROR));
    if (StringUtils.isNotBlank(trimmed)) {
        String[] tokens = StringUtils.split(trimmed, ';');
        if (tokens != null && tokens.length > 1) {
            String key = tokens[0].trim();
            if (key.matches("^[0-9]{1,3}$")) {
                int length = Integer.valueOf(key);
                if (length == tokens.length - 1) {
                    String string;
                    String[] keys = new String[length];
                    for (int i = 1; i < tokens.length; i++) {
                        key = tokens[i].trim();
                        if (key.endsWith(SUFIJO) && StringUtils.indexOfAny(key, INFIJOS) > 0) {
                            key = StringUtils.removeEnd(key, SUFIJO);
                            string = BundleMensajes.getString(key);
                            keys[i - 1] = isKey(string) ? string : "<" + key + ">";
                        } else {
                            return null;
                        }
                    }
                    return keys;
                }
            }
        }
        String key, string;
        String stripChars = BOMK + EOMK;
        List<String> list = new ArrayList<>();
        Pattern pattern = Pattern.compile("\\" + BOMK + ".*\\" + EOMK);
        Matcher matcher = pattern.matcher(trimmed);
        while (matcher.find()) {
            key = StringUtils.strip(matcher.group(), stripChars);
            if (key.endsWith(SUFIJO) && StringUtils.indexOfAny(key, INFIJOS) > 0) {
                key = StringUtils.removeEnd(key, SUFIJO);
                string = BundleMensajes.getString(key);
                key = isKey(string) ? string : "<" + key + ">";
                list.add(key);
            }
        }
        return (list.isEmpty()) ? null : list.toArray(new String[list.size()]);
    }
    return null;
}

From source file:com.alibaba.otter.canal.extend.communication.CanalCommmunicationClient.java

public void setManagerAddress(String managerAddress) {
    String server = StringUtils.replace(managerAddress, ";", ",");
    String[] servers = StringUtils.split(server, ',');
    this.managerAddress = Arrays.asList(servers);
    this.index = RandomUtils.nextInt(this.managerAddress.size()); // ??
}

From source file:edu.jhu.pha.vospace.node.NodePath.java

/**
 * Generates new path adding the appContainer to the beginning if the application access level is sandbox
 * @param path/*from   www  .jav a2 s . c o m*/
 * @param level
 * @param consumerKey
 * @throws ParseException
 */
public NodePath(String path, String root_container) {
    if (null == path)
        path = "";
    if (root_container.isEmpty()) { // root access level
        this.pathTokens = StringUtils.split(path, SEPARATOR);
        this.enableAppContainer = false;
    } else {
        this.pathTokens = StringUtils.split(root_container + SEPARATOR + path, SEPARATOR);
        this.enableAppContainer = true;
    }
}

From source file:com.zb.app.common.cookie.manager.WebSocketCookieManager.java

private Map<String, String> str2Map(String cookies) {
    String[] kvs = StringUtils.split(cookies, COOKIE_SPLIT_SEPARATOR_CHAR);
    if (kvs == null || kvs.length == 0) {
        return Collections.<String, String>emptyMap();
    }/*from   w  ww .  j a va 2  s  . co  m*/
    Map<String, String> kvMap = new HashMap<String, String>();
    for (String kv : kvs) {
        int offset = kv.indexOf(COOKIE_KEY_VALUE_SEPARATOR_CHAR);
        if (offset > 0 && offset < kv.length()) {
            String key = kv.substring(0, offset);
            if (key != null) {
                kvMap.put(key, kv.substring(offset + 1, kv.length()));
            }
        }
    }
    return kvMap;
}

From source file:net.morematerials.cmds.SMExecutor.java

@SuppressWarnings("unchecked")
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length == 0) {
        sender.sendMessage(MainManager.getUtils()
                .getMessage("This server is running " + this.plugin.getDescription().getName() + " " + "v"
                        + plugin.getDescription().getVersion() + "! " + "Credits to "
                        + StringUtils.join(this.plugin.getDescription().getAuthors(), ", ") + "!"));
        return true;
    }/*ww  w .  ja va 2s .c  om*/

    // Help parameter.
    if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help")) {
        // Someone specified the command to get help for.
        if (args.length > 1) {
            Map<String, Object> commands = (HashMap<String, Object>) this.plugin.getDescription().getCommands()
                    .values();
            if (!commands.containsKey(args[1])) {
                return false;
            }
            sender.sendMessage(MainManager.getUtils().getMessage("Help page for /" + args[1], Level.SEVERE));
            sender.sendMessage(MainManager.getUtils().getMessage("---------------------------------"));
            String commandInfo = (String) ((HashMap<String, Object>) commands.get(args[1])).get("usage");
            for (String usage : StringUtils.split(commandInfo, "\n")) {
                usage = usage.replaceAll("<command>", args[1] + ChatColor.GOLD);
                sender.sendMessage(MainManager.getUtils().getMessage(usage, Level.WARNING));
            }
            // Someone wants to see all commands.
        } else {
            sender.sendMessage(MainManager.getUtils().getMessage("Help page", Level.SEVERE));
            sender.sendMessage(MainManager.getUtils().getMessage("---------------------------------"));
            // Getting commands from plugin.yml
            // TODO unsafe cast warning remove
            HashMap<String, Object> commands = (HashMap<String, Object>) this.plugin.getDescription()
                    .getCommands().values();
            for (String commandsEntry : commands.keySet()) {
                // TODO unsafe cast warning remove
                HashMap<String, Object> commandInfo = (HashMap<String, Object>) commands.get(commandsEntry);
                sender.sendMessage(MainManager.getUtils().getMessage(
                        "/" + commandsEntry + " -> " + ChatColor.GOLD + commandInfo.get("description"),
                        Level.WARNING));
            }
        }
    }

    // This is some kind of weird command - do we actualy need it?
    if (args[0].equalsIgnoreCase("fixme")) {
        if (!(sender instanceof Player)) {
            return false;
        }
        Player player = (Player) sender;
        SpoutItemStack itemStack = new SpoutItemStack(player.getItemInHand());
        player.sendMessage(MainManager.getUtils()
                .getMessage("The item in your hand is custom: " + itemStack.isCustomItem()));
        player.sendMessage(
                MainManager.getUtils().getMessage("It's called " + itemStack.getMaterial().getName() + "!"));
    }

    return true;
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.FirstLastVerifier.java

/**
 * @param args/*ww w .ja  v  a 2s .  c om*/
 */
public static void main(String[] args) {
    if (true) {
        testLastNames();
        return;
    }
    FirstLastVerifier flv = new FirstLastVerifier();
    System.out.println(flv.isFirstName("Bill"));
    System.out.println(flv.isLastName("Bill"));

    System.out.println(flv.isFirstName("Johnson"));
    System.out.println(flv.isLastName("Johnson"));

    try {
        if (false) {
            for (String nm : new String[] { "firstnames", "lastnames" }) {
                File file = new File("/Users/rods/Downloads/" + nm + ".txt");
                try {
                    PrintWriter pw = new PrintWriter("/Users/rods/Downloads/" + nm + ".list");
                    for (String line : (List<String>) FileUtils.readLines(file)) {
                        String[] toks = StringUtils.split(line, '\t');
                        if (toks != null && toks.length > 0)
                            pw.println(toks[0]);
                    }
                    pw.close();

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        Vector<String> lnames = new Vector<String>();
        File file = XMLHelper.getConfigDir("lastnames.list");
        if (false) {
            for (String name : (List<String>) FileUtils.readLines(file)) {
                if (flv.isFirstName(name)) {
                    System.out.println(name + " is first.");
                } else {
                    lnames.add(name);
                }
            }
            Collections.sort(lnames);
            FileUtils.writeLines(file, lnames);
        }

        lnames.clear();
        file = XMLHelper.getConfigDir("firstnames.list");
        for (String name : (List<String>) FileUtils.readLines(file)) {
            if (flv.isLastName(name)) {
                System.out.println(name + " is first.");
            } else {
                lnames.add(name);
            }
        }
        Collections.sort(lnames);
        //FileUtils.writeLines(file, lnames);

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:edu.ku.brc.specify.toycode.mexconabio.AgentNames.java

private void parseForNames(final String nameStr) {
    String str = nameStr;//from   w w  w  .  j  av  a2s  . co  m
    if (StringUtils.contains(str, '\"')) {
        str = StringUtils.remove(str, '\"');
    }

    if (StringUtils.contains(str, ';')) {
        String[] toks = StringUtils.split(str, ';');
        for (String s : toks) {
            parseForFirstLastName(s);
        }
    } else {
        parseForFirstLastName(str);
        /*String[] toks = str.split("^([-\\w]+)(?:(?:\\s?[,|&]\\s)([-\\w]+)\\s?)*(.*)");   //"((?:[^, &]+\\s*[,&]+\\s*)*[^, &]+)\\s+([^,&]+)");
        for (String s : toks)
        {
        System.out.println("    ["+s+"]");
        }*/
    }
    System.out.println();
}

From source file:com.qualogy.qafe.gwt.server.processor.impl.EventProcessorImpl.java

public GDataObject execute(EventDataGVO eventData, ApplicationIdentifier appId,
        SessionContainer sessionContainer) {

    ApplicationContext context = ApplicationCluster.getInstance().get(appId);
    EventHandler eventHandler = context.getEventHandler();

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();//from   ww  w . j a v a  2 s  .  c o m

    GDataObject data = new GDataObject();
    data.setSenderId(eventData.getSender());
    data.setListenerType(eventData.getListenerType());
    data.setEventId(eventData.getEventId());
    data.setUuid(eventData.getUuid());
    data.setParent(eventData.getParent());
    ApplicationStoreIdentifier appStoreId = new ApplicationStoreIdentifier(eventData.getUuid());
    String[] senderInfo = StringUtils.split(eventData.getSender(), '|');
    logger.fine(eventData.toString() + ", WindowID " + senderInfo[1]);

    String windowId = "";
    if (senderInfo.length == 2 || senderInfo.length == 3) {
        if (senderInfo.length == 2) {// dealing with a RootPanel only
            windowId = senderInfo[0];
        }
        if (senderInfo.length == 3) {

            windowId = senderInfo[1];
        }
        try {

            List<InputVariable> inputVariables = new ArrayList<InputVariable>();

            if (eventData.getInputVariables() != null && eventData.getInputVariables().size() > 0) {
                for (InputVariableGVO inVar : eventData.getInputVariables()) {
                    inputVariables.add(
                            new InputVariable(inVar.getName(), inVar.getReference(), inVar.getDefaultValue(),
                                    inVar.getComponentValue(), convert(inVar.getDataContainerObject())));
                }
            }

            EventDataObject eventDataObject = new EventDataObject(eventData.getEventId(),
                    eventData.getSourceInfo(), appId, eventData.getListenerType(), inputVariables,
                    eventData.getInternalVariables(), senderInfo[0], eventData.getSenderName(), windowId,
                    eventData.getUuid(), eventData.getUserUID(), eventData.getWindowSession(),
                    eventData.getRequest(), eventData.getParameters(), eventData.getMouse());
            eventDataObject.setApplicationStoreIdentifier(appStoreId);

            Collection<?> builtInFunctionsToExecute = eventHandler.manage(eventDataObject);
            Iterator<?> itr = builtInFunctionsToExecute.iterator();
            Collection<BuiltInFunctionGVO> builtInFunctions = new ArrayList<BuiltInFunctionGVO>();
            while (itr.hasNext()) {
                BuiltInFunction builtInFunctionToExecute = (BuiltInFunction) itr.next();
                BuiltInFunctionGVO builtInFunction = EventUIAssembler
                        .convert((EventItem) builtInFunctionToExecute, eventData, context, sessionContainer);
                if (builtInFunction != null) {
                    builtInFunctions.add(builtInFunction);
                }
            }
            data.setFunctions((BuiltInFunctionGVO[]) builtInFunctions.toArray(new BuiltInFunctionGVO[] {}));
        } catch (RuntimeException e) {
            ExceptionHelper.printStackTrace(e);
            throw e;

        } catch (ExternalException e) {
            ExceptionHelper.printStackTrace(e.getCause());
            throw new RuntimeException(e.getMessage(), e);
        }
    } else {
        logger.warning("Error in sender string (is not partionable in size 2) : " + eventData.getSender());
    }
    stopWatch.stop();

    logger.warning("EventProcessorImpl uuid:[" + eventData.getUuid() + "], sender[" + eventData.getSender()
            + "], eventId [" + eventData.getEventName() + "]  took  [" + stopWatch.getTime() + "]ms ");
    return data;
}