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:ch.aonyx.broker.ib.api.account.ManagedAccountListEvent.java

public List<String> getAccounts() {
    return Collections.unmodifiableList(
            Lists.transform(Lists.newArrayList(StringUtils.split(commaSeparatedAccountList, separator)),
                    toTrimmedStringFunction));
}

From source file:io.mapzone.controller.email.EmailService.java

public void send(Email email) throws EmailException {
    String env = System.getProperty("io.mapzone.controller.SMTP");
    if (env == null) {
        throw new IllegalStateException(
                "Environment variable missing: io.mapzone.controller.SMTPP. Format: <host>|<login>|<passwd>|<from>");
    }/* w  w w.  ja  v  a  2  s  .co m*/
    String[] parts = StringUtils.split(env, "|");
    if (parts.length < 3 || parts.length > 4) {
        throw new IllegalStateException(
                "Environment variable wrong: io.mapzone.controller.SMTP. Format: <host>|<login>|<passwd>|<from> : "
                        + env);
    }

    email.setDebug(true);
    email.setHostName(parts[0]);
    //email.setSmtpPort( 465 );
    //email.setSSLOnConnect( true );
    email.setAuthenticator(new DefaultAuthenticator(parts[1], parts[2]));
    if (email.getFromAddress() == null && parts.length == 4) {
        email.setFrom(parts[3]);
    }
    if (email.getSubject() == null) {
        throw new EmailException("Missing subject.");
    }
    email.send();
}

From source file:com.quancheng.saluki.core.grpc.router.internal.ConditionRouter.java

@Override
protected void parseRouter() {
    whenCondition = Maps.newHashMap();//from ww w .ja  v  a2  s .  c  o  m
    thenCondition = Maps.newHashMap();
    String rulestr = super.getRule();
    String[] rules = StringUtils.split(rulestr, "\n");
    for (String rule : rules) {
        int i = rule.trim().indexOf("=>");
        String whenRule = i < 0 ? null : rule.substring(0, i).trim();
        String thenRule = i < 0 ? rule.trim() : rule.substring(i + 2).trim();
        try {
            whenCondition.putAll(doParseRule(whenRule));
            thenCondition.putAll(doParseRule(thenRule));
        } catch (ParseException e) {
            log.error(e.getMessage(), e);
        }
    }
}

From source file:com.rabidgremlin.onepagewebstarter.guice.CxfGuiceServlet.java

@Override
protected List<Object> getProviders(ServletConfig servletConfig, String splitChar) throws ServletException {
    List<Object> providers = new ArrayList<Object>();

    String providersList = servletConfig.getInitParameter("jaxrs.providers");
    if (providersList == null) {
        return providers;
    }/*from w ww  . j  av  a2 s . c o m*/

    Injector injector = (Injector) servletConfig.getServletContext().getAttribute(Injector.class.getName());

    String[] classNames = StringUtils.split(providersList, splitChar);
    for (String cName : classNames) {
        Class<?> cls = loadClass(StringUtils.strip(cName));
        providers.add(injector.getInstance(cls));
    }

    return providers;
}

From source file:com.mowitnow.lawnmower.service.InputService.java

public List<Mower> createMowerList(String input) {
    this.mowerCounter.lazySet(0);
    final List<Mower> mowerList = new ArrayList<Mower>();
    final String lines[] = StringUtils.split(input, System.getProperty("line.separator"));
    for (int i = 1; i < lines.length - 1; i = i + 2) {
        final String conf[] = StringUtils.split(lines[i], " ");
        final int id = this.mowerCounter.incrementAndGet();
        final int x = Integer.valueOf(conf[0]);
        final int y = Integer.valueOf(conf[1]);
        final Direction d = Direction.valueOf(conf[2]);
        final Mower mower = new Mower(id, x, y, d);

        final List<Command> commandList = new ArrayList<Command>();
        final String[] cmds = lines[i + 1].split("");
        for (int j = 1; j < cmds.length; j++) {
            Command cmd = Command.valueOf(cmds[j]);
            commandList.add(cmd);//  w  ww.j a v a  2 s .co  m
        }
        mower.setCommandList(commandList);
        mowerList.add(mower);
    }
    return mowerList;
}

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

@Override
public void onMessage(MessageEvent event) throws Exception {
    class process implements Runnable {
        public void run() {
            //sends Relay Message
            if (PermUtils.getPermLevel(event.getBot(), event.getUser().getNick(), event.getChannel()) > -4
                    && IRCUtils.getPrefix(event.getBot(), event.getChannelSource()).isEmpty())
                IRCUtils.sendRelayMessage(event.getBot(), event.getChannel(),
                        IRCUtils.noPing(event.getUser().getNick()) + ": " + event.getMessage());
            if (PermUtils.getPermLevel(event.getBot(), event.getUser().getNick(), event.getChannel()) > -3) {
                IRCUtils.addVoice(event.getBot(), event.getChannel(), event.getUser());
            }/*from   w  w w.  j a  v  a  2 s  . c  om*/

            //Begin Input Parsing
            String[] message = StringUtils.split(Colors.removeFormatting(event.getMessage()), " ");
            String commandchar = IRCUtils.getCommandChar(event.getBot(), event.getChannel());
            if (commandchar == null) {
                return;
            }
            if (event.getMessage().startsWith(commandchar)) {
                String chancommand = StringUtils.replaceOnce(message[0].toLowerCase(), commandchar, "");
                message = ArrayUtils.remove(message, 0);
                IRCCommand Command = IRCUtils.getCommand(chancommand,
                        IRCUtils.getNetworkNameByNetwork(event.getBot()), event.getChannel().getName());
                if (Command != null) {
                    int userPermLevel = PermUtils.getPermLevel(event.getBot(), event.getUser().getNick(),
                            event.getChannel());
                    if (userPermLevel >= Command.getPermLevel()) {
                        try {
                            Command.onCommand(chancommand, event.getUser(), event.getBot(),
                                    IRCUtils.getPrefix(event.getBot(), event.getChannelSource()),
                                    event.getChannel(), false, userPermLevel, message);
                        } catch (Exception e) {
                            IRCUtils.sendError(event.getUser(), event.getBot(), event.getChannel(),
                                    "Failed to execute command, please make sure you are using the correct syntax ("
                                            + Command.getSyntax() + ")",
                                    IRCUtils.getPrefix(event.getBot(), event.getChannelSource()));
                            e.printStackTrace();
                        }
                    } else {
                        IRCUtils.sendError(event.getUser(), event.getBot(), event.getChannel(),
                                "Permission denied",
                                IRCUtils.getPrefix(event.getBot(), event.getChannelSource()));
                    }
                }
            } else {
                Record rec = DatabaseUtils.getChannelUserProperty(
                        IRCUtils.getNetworkNameByNetwork(event.getBot()), event.getChannel().getName(),
                        PermUtils.authUser(event.getBot(), event.getUser().getNick()), "relaybotsplit");
                if (rec == null)
                    return;
                String relaysplit = rec.getValue(CHANNELUSERPROPERTY.VALUE);
                String startingmessage = event.getMessage();
                if (relaysplit != null) {
                    Pattern r = Pattern.compile(relaysplit);
                    Matcher matcher = r.matcher(startingmessage);
                    matcher.find();
                    startingmessage = startingmessage.replaceFirst(matcher.group(0), "");
                } else {
                    return;
                }
                String[] relayedmessage = StringUtils.split(startingmessage, " ");
                if (relayedmessage[0].startsWith(commandchar)) {
                    String relayedcommand = StringUtils.replaceOnce(relayedmessage[0], commandchar, "");
                    relayedmessage = ArrayUtils.remove(relayedmessage, 0);
                    IRCCommand Command = IRCUtils.getCommand(relayedcommand,
                            IRCUtils.getNetworkNameByNetwork(event.getBot()), event.getChannel().getName());
                    if (Command != null && Command.getPermLevel() == 0) {
                        try {
                            Command.onCommand(relayedcommand, event.getUser(), event.getBot(),
                                    IRCUtils.getPrefix(event.getBot(), event.getChannelSource()),
                                    event.getChannel(), false, 0, relayedmessage);
                        } catch (Exception e) {
                            IRCUtils.sendError(event.getUser(), event.getBot(), event.getChannel(),
                                    "Failed to execute command, please make sure you are using the correct syntax ("
                                            + Command.getSyntax() + ")",
                                    IRCUtils.getPrefix(event.getBot(), event.getChannelSource()));
                        }
                    }

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

From source file:com.creditcloud.corporation.factoring.Factoring.java

/**
 * centralBankRegisterNo/*w w  w .  j  a v  a 2s .  c  o m*/
 *
 * @param centralBankRegisterNo
 * @return
 */
public static String[] fromCentralBankRegisterNo(String centralBankRegisterNo) {
    if (centralBankRegisterNo == null) {
        return ArrayUtils.EMPTY_STRING_ARRAY;
    }
    return StringUtils.split(centralBankRegisterNo, CENTRALBANCK_REGISTER_NO_SEPERATOR);
}

From source file:com.reprezen.kaizen.oasparser.jsonoverlay.gen.SimpleJavaGenerator.java

private static String indent(int n, String text) {
    String[] lines = StringUtils.split(text, "\n");
    String result = "";
    for (String line : lines) {
        result += indent(n) + line + "\n";
    }/*from w  ww  . j  av  a 2s  . c om*/
    return result;
}

From source file:flpitu88.web.backend.psicoweb.services.AutenticacionUtilsService.java

@Override
public void validateToken(String token) throws Exception {

    String[] segments = StringUtils.split(token, ".");
    if (segments.length != 3) {
        throw new IllegalStateException("Bad number of segments: " + segments.length);
    }//from ww  w .  j av  a2  s.c om

    // 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(Jwt.base64Decode(headerSeg), stringObjectMap);

    HashMap<String, Object> payload = gson.fromJson(Jwt.base64Decode(payloadSeg), stringObjectMap);
    Long expirationDate = ((Double) payload.get("exp")).longValue();

    if (System.currentTimeMillis() > expirationDate) {
        throw new VerifyException("Expired token");
    }

    Algorithm algorithm = Jwt.getAlgorithm(header.get("alg").toString());

    // Verify signature. `sign` will return base64 String
    String signinInput = StringUtils.join(new String[] { headerSeg, payloadSeg }, ".");

    if (!Jwt.verify(signinInput, key, algorithm.getValue(), signatureSeg)) {
        throw new VerifyException("Bad signature");
    }
}

From source file:com.nesscomputing.migratory.information.DefaultMigrationInformationStrategy.java

public MigrationInformation getInformation(final URI location) {
    if (location == null) {
        return null;
    }/*from w  w w  . jav  a 2  s  .com*/
    // Must be loaded from an URL, e.g. jar:file:... ends up on schema specific part and path is null.
    try {
        final String path = location.toURL().getPath();
        final String fileName = path.substring(path.lastIndexOf('/') + 1);
        final String[] pieces = StringUtils.split(fileName, '.');
        if (pieces.length < 3 || pieces.length > 4) {
            throw new MigratoryException(Reason.INTERNAL, "'%s' is not a valid migration name!", fileName);
        }

        final String[] versionPieces = StringUtils.split(pieces[1], '-');

        int startVersion = -1;
        int endVersion = -1;
        switch (versionPieces.length) {
        case 1:
            endVersion = Integer.parseInt(versionPieces[0], 10);
            if (endVersion < 1) {
                throw new MigratoryException(Reason.INTERNAL, "'%s' has an end version of 0!", fileName);
            }

            startVersion = endVersion - 1;
            break;

        case 2:
            startVersion = Integer.parseInt(versionPieces[0], 10);
            endVersion = Integer.parseInt(versionPieces[1], 10);

            if (endVersion < 1) {
                throw new MigratoryException(Reason.INTERNAL, "'%s' has an end version of 0!", fileName);
            }

            if (startVersion == endVersion) {
                throw new MigratoryException(Reason.INTERNAL, "'%s' has the same start and end version!",
                        fileName);
            }
            break;
        default:
            throw new MigratoryException(Reason.INTERNAL, "Can not interpret '%s'!", fileName);
        }

        final boolean needsRoot = (pieces.length == 4 && "root".equals(pieces[2].toLowerCase(Locale.ENGLISH)));

        boolean template = false;

        if ("st".equals(pieces[pieces.length - 1])) {
            template = true;
        } else if (!"sql".equals(pieces[pieces.length - 1])) {
            throw new MigratoryException(Reason.INTERNAL, "'%s' has a bad suffix (not .st or .sql)!", fileName);
        }

        return new MigrationInformation(pieces[0], startVersion, endVersion, needsRoot, template);
    } catch (MalformedURLException mue) {
        throw new MigratoryException(Reason.INTERNAL, mue);
    }
}