Java Code Examples for org.apache.commons.lang3.StringUtils.containsAny()

The following are Jave code examples for showing how to use containsAny() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: cyberduck   File: Terminal.java   View Source Code Vote up 6 votes
protected Exit delete(final SessionPool session, final Path remote) throws BackgroundException {
    final List<Path> files = new ArrayList<Path>();
    for(TransferItem i : new DeletePathFinder().find(input, TerminalAction.delete, remote)) {
        files.add(i.remote);
    }
    final DeleteWorker worker;
    if(StringUtils.containsAny(remote.getName(), '*')) {
        worker = new DeleteWorker(new TerminalLoginCallback(reader), files, cache, new DownloadGlobFilter(remote.getName()), progress);
    }
    else {
        worker = new DeleteWorker(new TerminalLoginCallback(reader), files, cache, progress);
    }
    final SessionBackgroundAction<List<Path>> action = new TerminalBackgroundAction<List<Path>>(controller, session, worker);
    if(!this.execute(action)) {
        return Exit.failure;
    }
    return Exit.success;
}
 
Example 2
Project: cyberduck   File: DownloadTransferItemFinder.java   View Source Code Vote up 6 votes
@Override
public Set<TransferItem> find(final CommandLine input, final TerminalAction action, final Path remote) {
    final Local local = LocalFactory.get(input.getOptionValues(action.name())[1]);
    if(StringUtils.containsAny(remote.getName(), '*')) {
        // Treat asterisk as wildcard
        return Collections.singleton(new TransferItem(remote.getParent(), local));
    }
    if(remote.isDirectory()) {
        // Remote path resolves to directory
        if(local.exists()) {
            return Collections.singleton(new TransferItem(remote, LocalFactory.get(local, remote.getName())));
        }
        return Collections.singleton(new TransferItem(remote, local));
    }
    // Remote path resolves to file
    if(local.isDirectory()) {
        // Append remote filename to local target
        return Collections.singleton(new TransferItem(remote, LocalFactory.get(local, remote.getName())));
    }
    // Keep from input
    return Collections.singleton(new TransferItem(remote, local));
}
 
Example 3
Project: cyberduck   File: DeletePathFinder.java   View Source Code Vote up 5 votes
@Override
public Set<TransferItem> find(final CommandLine input, final TerminalAction action, final Path remote) throws AccessDeniedException {
    if(StringUtils.containsAny(remote.getName(), '*')) {
        // Treat asterisk as wildcard
        return Collections.singleton(new TransferItem(remote.getParent()));
    }
    return Collections.singleton(new TransferItem(remote));
}
 
Example 4
Project: cyberduck   File: TerminalTransferFactory.java   View Source Code Vote up 5 votes
public Transfer create(final CommandLine input, final Host host, final Path remote, final List<TransferItem> items)
        throws BackgroundException {
    final Transfer transfer;
    final TerminalAction type = TerminalActionFinder.get(input);
    if(null == type) {
        throw new BackgroundException(LocaleFactory.localizedString("Unknown"), "Unknown transfer type");
    }
    switch(type) {
        case download:
            if(StringUtils.containsAny(remote.getName(), '*')) {
                transfer = new DownloadTransfer(host, items, new DownloadGlobFilter(remote.getName()));
            }
            else {
                transfer = new DownloadTransfer(host, items);
            }
            break;
        case upload:
            transfer = new UploadTransfer(host, items);
            break;
        case synchronize:
            transfer = new SyncTransfer(host, items.iterator().next());
            break;
        default:
            throw new BackgroundException(LocaleFactory.localizedString("Unknown"),
                    String.format("Unknown transfer type %s", type.name()));
    }
    if(input.hasOption(TerminalOptionsBuilder.Params.throttle.name())) {
        try {
            transfer.setBandwidth(Float.valueOf(input.getOptionValue(TerminalOptionsBuilder.Params.throttle.name())));
        }
        catch(NumberFormatException ignore) {
            //
        }
    }
    return transfer;
}
 
Example 5
Project: sentry   File: CronExpressionDescriptor.java   View Source Code Vote up 4 votes
/**
 * @param expressionParts
 * @return
 */
private static String getTimeOfDayDescription(String[] expressionParts) {
    String secondsExpression = expressionParts[0];
    String minutesExpression = expressionParts[1];
    String hoursExpression = expressionParts[2];
    StringBuilder description = new StringBuilder();
    // Handle special cases first
    if (!StringUtils.containsAny(minutesExpression, specialCharacters) && !StringUtils.containsAny(hoursExpression, specialCharacters) && !StringUtils.containsAny(secondsExpression, specialCharacters)) {
        description.append(I18nMessages.get("at")).append(" ").append(DateAndTimeUtils.formatTime(hoursExpression, minutesExpression, secondsExpression)); // Specific time of day (e.g. 10 14)
    } else if (minutesExpression.contains("-") && !minutesExpression.contains("/") && !StringUtils.containsAny(hoursExpression, specialCharacters)) {
        // Minute range in single hour (e.g. 0-10 11)
        String[] minuteParts = minutesExpression.split("-");
        description.append(MessageFormat.format(I18nMessages.get("every_minute_between"), DateAndTimeUtils.formatTime(hoursExpression, minuteParts[0]),
            DateAndTimeUtils.formatTime(hoursExpression, minuteParts[1])));
    } else if (hoursExpression.contains(",") && !StringUtils.containsAny(minutesExpression, specialCharacters)) {
        // Hours list with single minute (e.g. 30 6,14,16)
        String[] hourParts = hoursExpression.split(",");
        description.append(I18nMessages.get("at"));
        for (int i = 0; i < hourParts.length; i++) {
            description.append(" ").append(DateAndTimeUtils.formatTime(hourParts[i], minutesExpression));
            if (i < hourParts.length - 2) {
                description.append(",");
            }
            if (i == hourParts.length - 2) {
                description.append(" ");
                description.append(I18nMessages.get("and"));
            }
        }
    } else {
        String secondsDescription = getSecondsDescription(expressionParts);
        String minutesDescription = getMinutesDescription(expressionParts);
        String hoursDescription = getHoursDescription(expressionParts);
        description.append(secondsDescription);
        if (description.length() > 0 && StringUtils.isNotEmpty(minutesDescription)) {
            description.append(", ");
        }
        description.append(minutesDescription);
        if (description.length() > 0 && StringUtils.isNotEmpty(hoursDescription)) {
            description.append(", ");
        }
        description.append(hoursDescription);
    }
    return description.toString();
}
 
Example 6
Project: unitstack   File: S3ActionInvestigator.java   View Source Code Vote up 4 votes
private boolean hasAction(MockRequest request, String... action) {
  String requestAction = request.getBodyParameters().get(S3RequestTransformer.ACTION);
  return StringUtils.containsAny(requestAction, action);
}
 
Example 7
Project: timesheet-upload   File: FileNameUtils.java   View Source Code Vote up 2 votes
/**
 * Check if the given file name is a valid file name. Return false if any of
 * the characters in the file name has [email protected]#$%^&*()
 *
 * @param fileName
 * @return
 */
public boolean validFileName(String fileName) {
    boolean validFlag = !StringUtils.containsAny(fileName, "[email protected]#$%^&*");
    log.info("Inside validFileName method of FileNameUtils:: fileName: " + fileName + "validFlag: " + validFlag);
    return validFlag;
}