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

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

Introduction

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

Prototype

public static String[] stripAll(final String... strs) 

Source Link

Document

Strips whitespace from the start and end of every String in an array.

Usage

From source file:com.nesscomputing.migratory.mojo.database.AbstractDatabaseMojo.java

protected MigratoryOption[] parseOptions(final String options) {
    final String[] optionList = StringUtils.stripAll(StringUtils.split(options, ","));

    if (optionList == null) {
        return new MigratoryOption[0];
    }/* w  w  w  .j a  va2 s .co m*/

    final MigratoryOption[] migratoryOptions = new MigratoryOption[optionList.length];
    for (int i = 0; i < optionList.length; i++) {
        migratoryOptions[i] = MigratoryOption.valueOf(optionList[i].toUpperCase(Locale.ENGLISH));
    }

    LOG.debug("Parsed %s into %s", options, migratoryOptions);
    return migratoryOptions;
}

From source file:com.nesscomputing.migratory.mojo.database.AbstractDatabaseMojo.java

protected void addMigrations(final String property, final Map<String, MigrationInformation> availableMigrations)
        throws MojoExecutionException {
    final String[] personalities = StringUtils.stripAll(config.getStringArray(property));
    for (String personality : personalities) {
        final String[] personalityParts = StringUtils.stripAll(StringUtils.split(personality, ":"));

        if (personalityParts == null || personalityParts.length < 1 || personalityParts.length > 2) {
            throw new MojoExecutionException("Personality " + personality + " is invalid.");
        }//  w  ww  .  ja  v a  2  s . c  o  m

        if (personalityParts.length == 1) {
            availableMigrations.put(personalityParts[0], new MigrationInformation(personalityParts[0], 0));
        } else {
            availableMigrations.put(personalityParts[0],
                    new MigrationInformation(personalityParts[0], Integer.parseInt(personalityParts[1], 10)));
        }
    }
}

From source file:nu.localhost.tapestry5.springsecurity.services.RequestInvocationDefinition.java

public RequestInvocationDefinition(String pattern, String roles, Long id) {
    this.requestMatcher = new AntPathRequestMatcher(pattern);
    String[] allAttrs = StringUtils.stripAll(StringUtils.splitPreserveAllTokens(roles, ','));
    this.configAttributes = new ArrayList<ConfigAttribute>();
    for (String attr : allAttrs) {
        this.configAttributes.add(new SecurityConfig(attr));
    }/*w  w w  .j a  v a 2s . co m*/

}

From source file:org.apache.nifi.reporting.SiteToSiteProvenanceReportingTask.java

@OnScheduled
public void onScheduled(final ConfigurationContext context) throws IOException {
    consumer = new ProvenanceEventConsumer();
    consumer.setStartPositionValue(context.getProperty(START_POSITION).getValue());
    consumer.setBatchSize(context.getProperty(BATCH_SIZE).asInteger());
    consumer.setLogger(getLogger());//from  w ww . j av  a2 s  . c  om

    // initialize component type filtering
    consumer.setComponentTypeRegex(context.getProperty(FILTER_COMPONENT_TYPE).getValue());

    final String[] targetEventTypes = StringUtils
            .stripAll(StringUtils.split(context.getProperty(FILTER_EVENT_TYPE).getValue(), ','));
    if (targetEventTypes != null) {
        for (String type : targetEventTypes) {
            try {
                consumer.addTargetEventType(ProvenanceEventType.valueOf(type));
            } catch (Exception e) {
                getLogger().warn(type + " is not a correct event type, removed from the filtering.");
            }
        }
    }

    // initialize component ID filtering
    final String[] targetComponentIds = StringUtils
            .stripAll(StringUtils.split(context.getProperty(FILTER_COMPONENT_ID).getValue(), ','));
    if (targetComponentIds != null) {
        consumer.addTargetComponentId(targetComponentIds);
    }

    consumer.setScheduled(true);
}

From source file:org.libreplan.importers.ImportRosterFromTim.java

@Override
@Transactional/* ww w  . j  a  v a  2s .c o m*/
public List<SynchronizationInfo> importRosters() throws ConnectorException {
    Connector connector = connectorDAO.findUniqueByName(PredefinedConnectors.TIM.getName());
    if (connector == null) {
        throw new ConnectorException(_("Tim connector not found"));
    }

    if (!connector.areConnectionValuesValid()) {
        throw new ConnectorException(_("Connection values of Tim connector are invalid"));
    }

    Map<String, String> properties = connector.getPropertiesAsMap();
    String url = properties.get(PredefinedConnectorProperties.SERVER_URL);

    String userName = properties.get(PredefinedConnectorProperties.USERNAME);

    String password = properties.get(PredefinedConnectorProperties.PASSWORD);

    int nrDaysRosterFromTim = Integer
            .parseInt(properties.get(PredefinedConnectorProperties.TIM_NR_DAYS_ROSTER));

    int productivityFactor = Integer
            .parseInt(properties.get(PredefinedConnectorProperties.TIM_PRODUCTIVITY_FACTOR));

    String departmentIds = properties.get(PredefinedConnectorProperties.TIM_DEPARTAMENTS_IMPORT_ROSTER);

    if (StringUtils.isBlank(departmentIds)) {
        LOG.warn("No departments configured");
        throw new ConnectorException(_("No departments configured"));
    }

    String[] departmentIdsArray = StringUtils.stripAll(StringUtils.split(departmentIds, ","));

    List<SynchronizationInfo> syncInfos = new ArrayList<SynchronizationInfo>();

    for (String department : departmentIdsArray) {
        LOG.info("Department: " + department);

        synchronizationInfo = new SynchronizationInfo(_("Import roster for department {0}", department));

        RosterRequestDTO rosterRequestDTO = createRosterRequest(department, nrDaysRosterFromTim);
        RosterResponseDTO rosterResponseDTO = TimSoapClient.sendRequestReceiveResponse(url, userName, password,
                rosterRequestDTO, RosterResponseDTO.class);

        if (rosterResponseDTO != null) {
            updateWorkersCalendarException(rosterResponseDTO, productivityFactor);
            if (!synchronizationInfo.isSuccessful()) {
                syncInfos.add(synchronizationInfo);
            }
        } else {
            LOG.error("No valid response for department " + department);
            synchronizationInfo.addFailedReason(_("No valid response for department \"{0}\"", department));
            syncInfos.add(synchronizationInfo);
        }
    }
    return syncInfos;
}

From source file:org.perfcake.examples.weaver.Weaver.java

/**
 * Parses worker configuration line.//from w w w. ja  va 2  s. c  om
 *
 * @param configLine
 *       The configuration line.
 * @return The number of worker instances created.
 */
private int parseWorker(final String configLine) {
    if (configLine != null && !configLine.isEmpty() && !configLine.startsWith("#")) {
        final String[] spaceSplit = configLine.split(" ", 2);
        final String[] equalsSplit = spaceSplit[1].split("=", 2);
        final int count = Integer.parseInt(StringUtils.strip(spaceSplit[0], " x"));
        String clazz = StringUtils.strip(equalsSplit[0]);
        clazz = clazz.contains(".") ? clazz : "org.perfcake.examples.weaver.worker." + clazz;
        final String[] propertiesConfig = StringUtils.stripAll(StringUtils.strip(equalsSplit[1]).split(","));
        final Properties properties = new Properties();
        final Properties mapProperties = new Properties();
        for (final String property : propertiesConfig) {
            final String[] keyValue = StringUtils.stripAll(property.split(":", 2));
            if (keyValue[0].matches("worker[0-9][0-9]*_.*")) {
                mapProperties.setProperty(keyValue[0], keyValue[1]);
            } else {
                properties.setProperty(keyValue[0], keyValue[1]);
            }
        }

        try {
            log.info("Summoning " + count + " instances of " + clazz + " with properties " + properties
                    + " and map properties " + mapProperties);
            for (int i = 0; i < count; i++) {
                final Worker worker = (Worker) ObjectFactory.summonInstance(clazz, properties);

                boolean add = true;
                if (worker instanceof MapConfigurable) {
                    add = ((MapConfigurable) worker).configure(mapProperties);
                }

                if (add) {
                    workers.add(worker);
                } else {
                    log.warn("Bad configuration. Skipping worker " + clazz);
                }
            }

            return count;
        } catch (ReflectiveOperationException e) {
            log.error("Unable to parse line '" + configLine + "': ", e);
        }
    }

    return 0;
}

From source file:org.starnub.commandparser.CommandParser.java

private void handleCommand(ObjectEvent objectEvent) {
    StarNubEventTwo starNubEventTwo = (StarNubEventTwo) objectEvent;
    PlayerSession playerSession = (PlayerSession) starNubEventTwo.getEVENT_DATA();
    String fullCommandString = (String) starNubEventTwo.getEVENT_DATA_2();

    List<String> argsList = new ArrayList<>();
    Matcher m = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(fullCommandString);
    while (m.find()) {
        argsList.add(m.group(1).replace("\"", ""));
    }//w w w.j  a  v a 2  s.  co m

    if (argsList.size() < 1) {
        return;
    }

    String commandString = argsList.get(0).replace("/", "").toLowerCase();
    ConcurrentHashMap<String, Command> commands = PluggableManager.getInstance().getCOMMANDS();
    Command command = commands.get(commandString);

    if (command == null) {
        new StarNubEventTwo("Player_Command_Failed_No_Command", playerSession, fullCommandString);
        sendChatMessage(playerSession,
                "Command named \"" + commandString + "\" does not exist or is not loaded.");
        return;
    }

    /* Splits are number of splits on spaces , I.E /r hi how are you (split on 2) = [hi, how are you] */
    int customSplit = command.getCustomSplit();
    boolean fullPermission = true;
    if (customSplit != 0) {
        System.out.println(argsList);
        argsList.clear();
        Collections.addAll(argsList, StringUtils.stripAll(fullCommandString.split(" ", customSplit + 2)));
        System.out.println(argsList);
        fullPermission = false;
    }

    /* Remove the plugin command from the args list*/
    argsList.remove(0);

    CanUse canUse = command.getCanUse();
    Connection connection = playerSession.getCONNECTION();
    boolean isInGame = true;
    if (!(connection instanceof ProxyConnection)) {
        isInGame = false;
    }

    switch (canUse) {
    case PLAYER: {
        if (!isInGame) {
            new StarNubEventTwo("Player_Command_Failed_Remote_Player_Cannot_Use", playerSession,
                    fullCommandString);
            sendChatMessage(playerSession, "Remote Player's cannot use the command \"" + commandString + "\".");
            return;
        }
        break;
    }
    case REMOTE_PLAYER: {
        if (isInGame) {
            new StarNubEventTwo("Player_Command_Failed_Player_Cannot_Use", playerSession, fullCommandString);
            sendChatMessage(playerSession, "Player's cannot use the command \"" + commandString + "\".");
            return;
        }
        break;
    }
    }

    String commandOwner = command.getDetails().getORGANIZATION().toLowerCase();
    String main_arg = null;
    String args[];
    boolean hasPermission;
    if (argsList.size() > 0) {
        main_arg = argsList.get(0);
        boolean hasMainArg = false;
        for (String arg : command.getMainArgs()) {
            if (arg.equals(main_arg)) {
                hasMainArg = true;
                break;
            }
        }
        if (!hasMainArg) {
            sendChatMessage(playerSession, "Command named \"" + commandString
                    + "\" does not have any main argument named \"" + main_arg + "\'.");
            return;
        }
        args = argsList.toArray(new String[argsList.size()]);
        hasPermission = playerSession.hasPermission(commandOwner, commandString, main_arg, true);
    } else {
        args = new String[0];
        fullPermission = false;
        hasPermission = playerSession.hasPermission(commandOwner, commandString, true);
    }

    if (!hasPermission) {
        String failedCommand = commandString;
        String permissionString = commandOwner + "." + commandString;
        if (fullPermission) {
            failedCommand = failedCommand + " " + main_arg;
            permissionString = permissionString + "." + main_arg;
        }
        new StarNubEventTwo("Player_Command_Failed_Permissions", playerSession, fullCommandString);
        sendChatMessage(playerSession, "You do not have permission to use the command \"/" + failedCommand
                + "\"." + " Permission required: \"" + permissionString + "\".");
        return;
    }
    new StarNubEventTwo("Player_Command_Delivered_To_Plugin", playerSession, fullCommandString);
    command.onCommand(playerSession, commandString, args.length, args);
}

From source file:org.wikipedia.nirvana.nirvanabot.templates.TemplateFindItem.java

public static TemplateFindItem parseTemplateFindData(String templateFindData) throws BadFormatException {
    int slashes = StringTools.howMany(templateFindData, '/');
    if (slashes == 2) {
        String parts[] = StringUtils.splitPreserveAllTokens(templateFindData, "/", 3);
        parts = StringUtils.stripAll(parts);
        if (parts[0].isEmpty()) {
            throw new BadFormatException();
        }/*from   w ww.  j  a  v  a2s.co  m*/
        return new TemplateFindItem(parts[0], parts[1], parts[2]);
    } else if (slashes == 1) {
        String parts[] = StringUtils.splitPreserveAllTokens(templateFindData, "/", 3);
        parts = StringUtils.stripAll(parts);
        if (parts[0].isEmpty()) {
            throw new BadFormatException();
        }
        return new TemplateFindItem(parts[0], parts[1], "");
    } else if (slashes == 0) {
        if (templateFindData.trim().isEmpty()) {
            throw new BadFormatException();
        }
        return new TemplateFindItem(templateFindData.trim(), "", "");
    } else {
        throw new BadFormatException();
    }
}

From source file:v7db.files.Configuration.java

/**
 * property string value is split by comma and trimmed for space
 */// www .j a  v a 2  s.co  m
static String[] getArrayProperty(String key) {
    String[] x = StringUtils.stripAll(StringUtils.split(getProperty(key), ','));
    if (x == null)
        x = ArrayUtils.EMPTY_STRING_ARRAY;
    return x;
}

From source file:v7db.files.GlobalAuthorisationProvider.java

private boolean authorise(V7File resource, AuthenticationToken user, String permission) {
    Object[] roles = getRoles(user);
    if (roles == null)
        return false;

    String[] acl = StringUtils.stripAll(StringUtils.split(getProperty(permission), ','));
    for (Object role : roles) {
        if (ArrayUtils.contains(acl, role))
            return true;
    }/* ww w.  j  av a2 s . c  o m*/
    return false;
}