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

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

Introduction

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

Prototype


public static boolean containsWhitespace(final CharSequence seq) 

Source Link

Document

Check whether the given CharSequence contains any whitespace characters.

Usage

From source file:de.gbv.ole.Marc21ToOleBulk.java

/**
 * Throws a MarcException if the parameter is not a valid isbn10 number
 * with valid check digit.//from  ww  w . ja  v  a2 s . c o  m
 * 
 * Valid: "00", "19", "27",
 * "2121212124", 
 * "9999999980",
 * "9999999999"
 * 
 * @param isbn10 the number to validate
 */
static void validateIsbn10(final String isbn10) {
    if (StringUtils.isEmpty(isbn10)) {
        throw new MarcException("null or empty number");
    }
    if (StringUtils.isWhitespace(isbn10)) {
        throw new MarcException("number expected, found only whitespace");
    }
    if (StringUtils.containsWhitespace(isbn10)) {
        throw new MarcException(
                "number plus check digit expected, but contains " + "whitespace: '" + isbn10 + "'");
    }
    if (isbn10.length() < 2) {
        throw new MarcException("number plus check digit expected, " + "but found: " + isbn10);
    }
    if (isbn10.length() > 10) {
        throw new MarcException("maximum length of number plus " + "check digit is 10 (9 + 1 check digit),\n"
                + "input is " + isbn10.length() + " characters long: " + isbn10);
    }
    String checkdigit = StringUtils.right(isbn10, 1);
    if (!StringUtils.containsOnly(checkdigit, "0123456789xX")) {
        throw new MarcException("check digit must be 0-9, x or X, " + "but is " + checkdigit);
    }
    String number = withoutCheckdigit(isbn10);
    if (!StringUtils.containsOnly(number, "0123456789")) {
        throw new MarcException("number before check digit must " + "contain 0-9 only, but is " + checkdigit);
    }
    String calculatedCheckdigit = isbn10checkdigit(Integer.parseInt(number));
    if (!StringUtils.equalsIgnoreCase(checkdigit, calculatedCheckdigit)) {
        throw new MarcException("wrong checkdigit " + checkdigit + ", correct check digit is "
                + calculatedCheckdigit + ": " + isbn10);
    }
}

From source file:de.ks.idnadrev.information.chart.ChartDataEditor.java

protected TextField createValueEditor(ChartRow chartRow, int rowNum, int column) {
    TextField editor = new TextField();
    valueEditors.put(rowNum, column, editor);
    validationRegistry.registerValidator(editor, new DoubleValidator());
    dataContainer.add(editor, column + COLUMN_OFFSET, rowNum + ROW_OFFSET);

    editor.focusedProperty().addListener(getEditorFocusListener(rowNum, editor));

    editor.textProperty().addListener((p, o, n) -> {
        editor.setUserData(true);//from   w ww .java  2 s. c o  m
    });

    BiFunction<Integer, Integer, TextField> nextTextField = (row, col) -> valueEditors.row(row).get(col);
    BiConsumer<Integer, Integer> clipBoardHandler = (row, col) -> {
        String string = Clipboard.getSystemClipboard().getString();
        if (StringUtils.containsWhitespace(string)) {
            List<String> datas = Arrays.asList(StringUtils.split(string));
            int missingRows = (row + datas.size()) - rows.size();
            if (missingRows > 0) {
                for (int i = 0; i < missingRows; i++) {
                    rows.add(new ChartRow());
                }
            }
            for (int i = row; i < row + datas.size(); i++) {
                ChartRow currentChartRow = rows.get(i);
                String data = datas.get(i - row);
                currentChartRow.setValue(column, data);
            }
        }
    };
    editor.setOnKeyReleased(getInputKeyHandler(rowNum, column, nextTextField, clipBoardHandler));
    return editor;
}

From source file:com.github.rvesse.airline.model.MetadataLoader.java

/**
 * Loads command group meta-data/*from   w  w w . jav a2s  . c  o  m*/
 * 
 * @param name
 *            Group name
 * @param description
 *            Group description
 * @param hidden
 *            Whether the group is hidden
 * @param defaultCommand
 *            Default command for the group
 * @param commands
 *            Commands for the group
 * @return Command group meta-data
 */
public static CommandGroupMetadata loadCommandGroup(String name, String description, boolean hidden,
        Iterable<CommandGroupMetadata> subGroups, CommandMetadata defaultCommand,
        Iterable<CommandMetadata> commands) {
    // Process the name
    if (StringUtils.containsWhitespace(name)) {
        String[] names = StringUtils.split(name);
        name = names[names.length - 1];
    }

    List<OptionMetadata> groupOptions = new ArrayList<OptionMetadata>();
    if (defaultCommand != null) {
        groupOptions.addAll(defaultCommand.getGroupOptions());
    }
    for (CommandMetadata command : commands) {
        groupOptions.addAll(command.getGroupOptions());
    }
    groupOptions = ListUtils.unmodifiableList(mergeOptionSet(groupOptions));
    return new CommandGroupMetadata(name, description, hidden, groupOptions, subGroups, defaultCommand,
            commands);
}

From source file:com.joyent.manta.config.ConfigContext.java

/**
 * Utility method for validating that the client-side encryption
 * configuration has been instantiated with valid settings.
 *
 * @param config configuration to test//from  w ww . j  a v a 2 s.  c o m
 * @param failureMessages list of messages to present the user for validation failures
 * @throws ConfigurationException thrown when validation fails
 */
static void encryptionSettings(final ConfigContext config, final List<String> failureMessages) {
    // KEY ID VALIDATIONS

    if (config.getEncryptionKeyId() == null) {
        failureMessages.add("Encryption key id must not be null");
    }
    if (config.getEncryptionKeyId() != null && StringUtils.isEmpty(config.getEncryptionKeyId())) {
        failureMessages.add("Encryption key id must not be empty");
    }
    if (config.getEncryptionKeyId() != null && StringUtils.containsWhitespace(config.getEncryptionKeyId())) {
        failureMessages.add("Encryption key id must not contain whitespace");
    }
    if (config.getEncryptionKeyId() != null && !StringUtils.isAsciiPrintable(config.getEncryptionKeyId())) {
        failureMessages.add(("Encryption key id must only contain printable ASCII characters"));
    }

    // AUTHENTICATION MODE VALIDATIONS

    if (config.getEncryptionAuthenticationMode() == null) {
        failureMessages.add("Encryption authentication mode must not be null");
    }

    // PERMIT UNENCRYPTED DOWNLOADS VALIDATIONS

    if (config.permitUnencryptedDownloads() == null) {
        failureMessages.add("Permit unencrypted downloads flag must not be null");
    }

    // PRIVATE KEY VALIDATIONS

    if (config.getEncryptionPrivateKeyPath() == null && config.getEncryptionPrivateKeyBytes() == null) {
        failureMessages.add("Both encryption private key path and private key bytes must not be null");
    }

    if (config.getEncryptionPrivateKeyPath() != null && config.getEncryptionPrivateKeyBytes() != null) {
        failureMessages.add("Both encryption private key path and private key bytes must "
                + "not be set. Choose one or the other.");
    }

    if (config.getEncryptionPrivateKeyPath() != null) {
        File keyFile = new File(config.getEncryptionPrivateKeyPath());

        if (!keyFile.exists()) {
            failureMessages.add(String.format("Key file couldn't be found at path: %s",
                    config.getEncryptionPrivateKeyPath()));
        } else if (!keyFile.canRead()) {
            failureMessages.add(String.format("Key file couldn't be read at path: %s",
                    config.getEncryptionPrivateKeyPath()));
        }
    }

    if (config.getEncryptionPrivateKeyBytes() != null) {
        if (config.getEncryptionPrivateKeyBytes().length == 0) {
            failureMessages.add("Encryption private key byte length must be greater than zero");
        }
    }

    // CIPHER ALGORITHM VALIDATIONS

    final String algorithm = config.getEncryptionAlgorithm();

    if (algorithm == null) {
        failureMessages.add("Encryption algorithm must not be null");
    }

    if (algorithm != null && StringUtils.isBlank(algorithm)) {
        failureMessages.add("Encryption algorithm must not be blank");
    }

    if (algorithm != null && !SupportedCiphersLookupMap.INSTANCE.containsKeyCaseInsensitive(algorithm)) {
        String availableAlgorithms = StringUtils.join(SupportedCiphersLookupMap.INSTANCE.keySet(), ", ");
        failureMessages.add(String.format(
                "Cipher algorithm [%s] was not found among " + "the list of supported algorithms [%s]",
                algorithm, availableAlgorithms));
    }
}

From source file:com.github.rvesse.airline.model.MetadataLoader.java

public static void loadCommandsIntoGroupsByAnnotation(List<CommandMetadata> allCommands,
        List<CommandGroupMetadata> commandGroups, List<CommandMetadata> defaultCommandGroup) {
    List<CommandMetadata> newCommands = new ArrayList<CommandMetadata>();

    // first, create any groups explicitly annotated
    createGroupsFromAnnotations(allCommands, newCommands, commandGroups, defaultCommandGroup);

    for (CommandMetadata command : allCommands) {
        boolean addedToGroup = false;

        // now add the command to any groupNames specified in the Command
        // annotation
        for (String groupName : command.getGroupNames()) {
            CommandGroupMetadata group = CollectionUtils.find(commandGroups, new GroupFinder(groupName));
            if (group != null) {
                // Add to existing top level group
                group.addCommand(command);
                addedToGroup = true;/*w ww  .j  a v  a 2  s  .c o  m*/
            } else {
                if (StringUtils.containsWhitespace(groupName)) {
                    // Add to sub-group
                    String[] groups = StringUtils.split(groupName);
                    CommandGroupMetadata subGroup = null;
                    for (int i = 0; i < groups.length; i++) {
                        if (i == 0) {
                            // Find/create the necessary top level group
                            subGroup = CollectionUtils.find(commandGroups, new GroupFinder(groups[i]));
                            if (subGroup == null) {
                                subGroup = new CommandGroupMetadata(groups[i], "", false,
                                        Collections.<OptionMetadata>emptyList(),
                                        Collections.<CommandGroupMetadata>emptyList(), null,
                                        Collections.<CommandMetadata>emptyList());
                                commandGroups.add(subGroup);
                            }
                        } else {
                            // Find/create the next sub-group
                            CommandGroupMetadata nextSubGroup = CollectionUtils.find(subGroup.getSubGroups(),
                                    new GroupFinder(groups[i]));
                            if (nextSubGroup == null) {
                                nextSubGroup = new CommandGroupMetadata(groups[i], "", false,
                                        Collections.<OptionMetadata>emptyList(),
                                        Collections.<CommandGroupMetadata>emptyList(), null,
                                        Collections.<CommandMetadata>emptyList());
                            }
                            subGroup.addSubGroup(nextSubGroup);
                            subGroup = nextSubGroup;
                        }
                    }
                    if (subGroup == null)
                        throw new IllegalStateException("Failed to resolve sub-group path");
                    subGroup.addCommand(command);
                    addedToGroup = true;
                } else {
                    // Add to newly created top level group
                    CommandGroupMetadata newGroup = loadCommandGroup(groupName, "", false,
                            Collections.<CommandGroupMetadata>emptyList(), null,
                            Collections.singletonList(command));
                    commandGroups.add(newGroup);
                    addedToGroup = true;
                }
            }
        }

        if (addedToGroup && defaultCommandGroup.contains(command)) {
            defaultCommandGroup.remove(command);
        }
    }

    allCommands.addAll(newCommands);
}

From source file:com.github.rvesse.airline.model.MetadataLoader.java

@SuppressWarnings("rawtypes")
private static void createGroupsFromAnnotations(List<CommandMetadata> allCommands,
        List<CommandMetadata> newCommands, List<CommandGroupMetadata> commandGroups,
        List<CommandMetadata> defaultCommandGroup) {

    // We sort sub-groups by name length then lexically
    // This means that when we build the groups hierarchy we'll ensure we
    // build the parent groups first wherever possible
    Map<String, CommandGroupMetadata> subGroups = new TreeMap<String, CommandGroupMetadata>(
            new StringHierarchyComparator());
    for (CommandMetadata command : allCommands) {
        boolean addedToGroup = false;

        // first, create any groups explicitly annotated
        for (Group groupAnno : command.getGroups()) {
            Class defaultCommandClass = null;
            CommandMetadata defaultCommand = null;

            // load default command if needed
            if (!groupAnno.defaultCommand().equals(Group.NO_DEFAULT.class)) {
                defaultCommandClass = groupAnno.defaultCommand();
                defaultCommand = CollectionUtils.find(allCommands, new CommandTypeFinder(defaultCommandClass));
                if (null == defaultCommand) {
                    defaultCommand = loadCommand(defaultCommandClass);
                    newCommands.add(defaultCommand);
                }/*from  w ww. java 2  s  . c  om*/
            }

            // load other commands if needed
            List<CommandMetadata> groupCommands = new ArrayList<CommandMetadata>(groupAnno.commands().length);
            CommandMetadata groupCommand = null;
            for (Class commandClass : groupAnno.commands()) {
                groupCommand = CollectionUtils.find(allCommands, new CommandTypeFinder(commandClass));
                if (null == groupCommand) {
                    groupCommand = loadCommand(commandClass);
                    newCommands.add(groupCommand);
                    groupCommands.add(groupCommand);
                }
            }

            // Find the group metadata
            // May already exist as a top level group
            CommandGroupMetadata groupMetadata = CollectionUtils.find(commandGroups,
                    new GroupFinder(groupAnno.name()));
            if (groupMetadata == null) {
                // Not a top level group

                String subGroupPath = null;
                if (StringUtils.containsWhitespace(groupAnno.name())) {
                    // Is this a sub-group we've already seen?
                    // Make sure to normalize white space in the path
                    subGroupPath = StringUtils.join(StringUtils.split(groupAnno.name()), " ");
                    groupMetadata = subGroups.get(subGroupPath);
                }

                if (groupMetadata == null) {
                    // Newly discovered group
                    groupMetadata = loadCommandGroup(groupAnno.name(), groupAnno.description(),
                            groupAnno.hidden(), Collections.<CommandGroupMetadata>emptyList(), defaultCommand,
                            groupCommands);
                    if (!StringUtils.containsWhitespace(groupAnno.name())) {
                        // Add as top level group
                        commandGroups.add(groupMetadata);
                    } else {
                        // This is a new sub-group, put aside for now and
                        // we'll build the sub-group tree later
                        subGroups.put(subGroupPath, groupMetadata);
                    }
                }
            }

            groupMetadata.addCommand(command);
            addedToGroup = true;
        }

        if (addedToGroup && defaultCommandGroup.contains(command)) {
            defaultCommandGroup.remove(command);
        }
    }

    buildGroupsHierarchy(commandGroups, subGroups);
}

From source file:np.com.drose.parkgarau.validator.Codevalidator.java

@Override
public void validate(FacesContext fc, UIComponent uic, Object o) throws ValidatorException {
    if (StringUtils.containsWhitespace(o.toString())) {
        FacesMessage msg = new FacesMessage("Incorrect input provided", "The input must not have space");
        msg.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(msg);

    }/*from  www.  j  av a 2 s . c o m*/
}

From source file:org.ballerinalang.composer.service.workspace.rest.datamodel.BLangJSONModelBuilder.java

@Override
public void visit(SimpleVarRefExpr simpleVarRefExpr) {
    JsonObject simpleVarRefExprObj = new JsonObject();
    this.addPosition(simpleVarRefExprObj, simpleVarRefExpr.getNodeLocation());
    this.addWhitespaceDescriptor(simpleVarRefExprObj, simpleVarRefExpr.getWhiteSpaceDescriptor());
    simpleVarRefExprObj.addProperty(BLangJSONModelConstants.DEFINITION_TYPE,
            BLangJSONModelConstants.SIMPLE_VARIABLE_REFERENCE_EXPRESSION);
    simpleVarRefExprObj.addProperty(BLangJSONModelConstants.VARIABLE_REFERENCE_NAME,
            simpleVarRefExpr.getSymbolName().getName());
    simpleVarRefExprObj.addProperty(BLangJSONModelConstants.VARIABLE_NAME,
            simpleVarRefExpr.getSymbolName().getName());
    simpleVarRefExprObj.addProperty(BLangJSONModelConstants.PACKAGE_NAME, simpleVarRefExpr.getPkgName());
    if (simpleVarRefExpr.getVariableDef() != null) {
        tempJsonArrayRef.push(new JsonArray());
        simpleVarRefExpr.getVariableDef().accept(this);
        simpleVarRefExprObj.addProperty(BLangJSONModelConstants.IS_IDENTIFIER_LITERAL,
                simpleVarRefExpr.getVariableDef().getIdentifier().isLiteral());
        simpleVarRefExprObj.add(BLangJSONModelConstants.CHILDREN, tempJsonArrayRef.peek());
        tempJsonArrayRef.pop();/*ww w.  j  av a 2 s  . c  o  m*/
    } else if (StringUtils.containsWhitespace(simpleVarRefExpr.getSymbolName().getName())) {
        simpleVarRefExprObj.addProperty(BLangJSONModelConstants.IS_IDENTIFIER_LITERAL, true);
    }
    tempJsonArrayRef.peek().add(simpleVarRefExprObj);
}

From source file:org.trimou.engine.parser.DefaultParsingHandler.java

private void validateTag(ParsedTag tag) {

    if (StringUtils.isEmpty(tag.getContent())) {
        throw new MustacheException(COMPILE_INVALID_TAG, "Tag has no content [type: %s, line: %s]",
                tag.getType(), line);// w w w .j  a  va  2s  . c  om
    }

    if (tag.getContent().contains(delimiters.getStart())) {
        throw new MustacheException(COMPILE_INVALID_TAG,
                "Tag content contains current start delimiter [type: %s, line: %s, delimiter: %s]",
                tag.getType(), line, delimiters.getStart());
    }

    if (handlebarsSupportEnabled) {
        // Only validate segments which cannot have a HelperExecutionHandler
        // associated
        if (MustacheTagType.contentMustBeValidated(tag.getType())
                && !MustacheTagType.supportsHelpers(tag.getType())
                && StringUtils.containsWhitespace(tag.getContent())) {
            contentMustBeNonWhitespaceSequenceException(tag.getType());
        }
    } else {
        if (MustacheTagType.contentMustBeNonWhitespaceCharacterSequence(tag.getType())
                && StringUtils.containsWhitespace(tag.getContent())) {
            contentMustBeNonWhitespaceSequenceException(tag.getType());
        }
    }
}

From source file:uk.ac.ebi.atlas.search.BioentitiesSearchController.java

private Optional<String> getGeneIdRedirectString(String geneQuery, String specie, boolean isExactMatch) {

    boolean singleTerm = !StringUtils.containsWhitespace(geneQuery);
    if (singleTerm && GeneSetUtil.isGeneSet(geneQuery.toUpperCase())) {
        return Optional.of("redirect:/genesets/" + geneQuery);
    }//from ww w .ja  va2 s.  c  om

    BioentityProperty bioentityProperty = solrQueryService.findBioentityIdentifierProperty(geneQuery);

    if (bioentityProperty != null) {
        String bioentityPageName = BioentityType.get(bioentityProperty.getBioentityType())
                .getBioentityPageName();
        return Optional.of("redirect:/" + bioentityPageName + "/" + geneQuery);
    }

    String species = "";
    if (StringUtils.isNotBlank(specie)) {
        species = specie;
    }
    Optional<Set<String>> geneIdsOrSets = solrQueryService.expandGeneQueryIntoGeneIds(geneQuery, species,
            isExactMatch);

    if (geneIdsOrSets.isPresent() && geneIdsOrSets.get().size() == 1) {
        return Optional.of("redirect:/" + BioentityType.GENE.getBioentityPageName() + "/"
                + geneIdsOrSets.get().iterator().next());
    }

    return Optional.absent();

}