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:com.norconex.collector.core.data.store.impl.mongo.MongoUtil.java

/**
 * Return or generate a DB name//from www.ja v a 2  s.  co m
 * 
 * If a valid dbName is provided, it is returned as is. If none is provided,
 * a name is generated from the crawl ID (provided in HttpCrawlerConfig)
 * 
 * @param dbName database name
 * @param crawlerId crawler id
 * @throws IllegalArgumentException
 *             if the dbName provided contains invalid characters
 * @return DB name
 */
public static String getDbNameOrGenerate(String dbName, String crawlerId) {

    // If we already have a name, try to use it
    if (dbName != null && dbName.length() > 0) {
        // Validate it
        if (StringUtils.containsAny(dbName, MONGO_INVALID_DBNAME_CHARACTERS)
                || StringUtils.containsWhitespace(dbName)) {
            throw new IllegalArgumentException("Invalid Mongo DB name: " + dbName);
        }
        return dbName;
    }

    // Generate a name from the crawl ID
    String dbIdName = crawlerId;
    // Replace invalid character with '_'
    for (int i = 0; i < MONGO_INVALID_DBNAME_CHARACTERS.length(); i++) {
        char c = MONGO_INVALID_DBNAME_CHARACTERS.charAt(i);
        dbIdName = dbIdName.replace(c, '_');
    }
    // Replace whitespaces
    dbIdName = dbIdName.replaceAll("\\s", "_");
    return dbIdName;
}

From source file:kenh.expl.functions.ContainsWhitespace.java

public boolean process(String seq) {
    return StringUtils.containsWhitespace(seq);
}

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

public CommandGroupMetadata(String name, String description, boolean hidden, Iterable<OptionMetadata> options,
        Iterable<CommandGroupMetadata> subGroups, CommandMetadata defaultCommand,
        Iterable<CommandMetadata> commands) {
    //@formatter:on
    if (StringUtils.isEmpty(name))
        throw new IllegalArgumentException("Group name may not be null/empty");
    if (StringUtils.containsWhitespace(name))
        throw new IllegalArgumentException("Group name may not contain whitespace");

    this.name = name;
    this.description = description;
    this.hidden = hidden;
    this.options = AirlineUtils.unmodifiableListCopy(options);
    this.subGroups = AirlineUtils.listCopy(subGroups);
    this.defaultCommand = defaultCommand;
    this.commands = AirlineUtils.listCopy(commands);
    if (this.defaultCommand != null && !this.commands.contains(this.defaultCommand)) {
        this.commands.add(this.defaultCommand);
    }//from w  ww  . j  av  a  2s  .  com
}

From source file:com.twosigma.beakerx.kernel.PathToJar.java

private void checkNotWhitespaces(String path) {
    if (StringUtils.containsWhitespace(path)) {
        throw new RuntimeException("Can not create path with whitespace.");
    }//from w w  w .  j  ava 2  s.  com
}

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

public CommandMetadata(String name, String description, boolean hidden, Iterable<OptionMetadata> globalOptions,
        Iterable<OptionMetadata> groupOptions, Iterable<OptionMetadata> commandOptions,
        OptionMetadata defaultOption, ArgumentsMetadata arguments, Iterable<Accessor> metadataInjections,
        Class<?> type, List<String> groupNames, List<Group> groups, List<HelpSection> sections) {
    //@formatter:on
    if (StringUtils.isEmpty(name))
        throw new IllegalArgumentException("Command name may not be null/empty");
    if (StringUtils.containsWhitespace(name))
        throw new IllegalArgumentException("Command name may not contain whitespace");

    this.name = name;
    this.description = description;
    this.hidden = hidden;
    this.globalOptions = AirlineUtils.unmodifiableListCopy(globalOptions);
    this.groupOptions = AirlineUtils.unmodifiableListCopy(groupOptions);
    this.commandOptions = AirlineUtils.unmodifiableListCopy(commandOptions);
    this.defaultOption = defaultOption;
    this.arguments = arguments;

    if (this.defaultOption != null && this.arguments != null) {
        throw new IllegalArgumentException("Command cannot declare both @Arguments and @DefaultOption");
    }/* ww  w  .ja  va 2s .  com*/

    this.metadataInjections = AirlineUtils.unmodifiableListCopy(metadataInjections);
    this.type = type;
    this.groupNames = groupNames;
    this.groups = groups;

    this.sections = AirlineUtils.unmodifiableListCopy(sections);
}

From source file:com.beans.CustomerMBean.java

public String addAction() throws ProcessingException {

    if (StringUtils.containsWhitespace(userName)) {
        FacesMessage msg = new FacesMessage("Username contains white spaces");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        return null;
    }//from   www. j  a va2 s  .c  o m
    if (customerrepo.findByUsername(userName) != null) {
        FacesMessage msg = new FacesMessage("Username already exists");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        return null;
    } else if (userName != null && userName.length() > 11) {
        FacesMessage msg = new FacesMessage("Username Length is greater than eleven");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        return null;
    } else if (customerrepo.findByEmail(email) != null) {
        FacesMessage msg = new FacesMessage("Email already exists");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        return null;
    }
    if (customerrepo.findByPhone(phone) != null) {
        FacesMessage msg = new FacesMessage("Phone number already exists");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        return null;
    } else if (customerrepo.findByUsername(userName) == null) {
        Customer cust = new Customer();
        cust.setUsername(userName);
        cust.setStatus(CustomerStatus.INACTIVE.ordinal());
        cust.setReward(0d);
        cust.setReseller(this.customer.getCustomerId());
        cust.setPhone(phone);
        cust.setPassword(Util.hash(passwd));
        cust.setLastName(lname);
        cust.setFirstName(fname);
        cust.setEmail(email);
        cust.setAddress(address);
        cust.setBalance(0d);//customerrepo.getProperty("SignUpBonus"));
        String code = Util.generateCode();
        cust.setActivationCode(code);
        cust.setAccountType(UserType.ResellerCustomer.ordinal());
        cust.setRegDate(new Date());
        cust.setRate(customerrepo.getProperty("FlatRate"));
        customerrepo.create(cust);
        customerList.add(cust);

        String accountRole = "Customer";
        if (accountType == 1) {
            accountRole = "Reseller";
        }

        //SENDING EMAIL
        //        SendEmail sendObject=new SendEmail();
        //        Email mail=new Email();
        //        mail.setEmailAddress(email);
        //        mail.setMessage("Dear "+fname+", SMS Solutions welcomes you. "
        //                + "Your "+accountRole+" account has been successfully created. "
        //                + "Your Username is "+userName+" and your password is "+passwd+" ."
        //                + " Your number verification code has been sent to your phone. \n" +
        //"Kindly click on the link below to verify your number and activate your account:\n" +
        //"http://smssolutions.com.ng:8180/BulkSMS/verifycode\n" +
        //"Thank you for your patronage.");
        //        mail.setSubject("SMS Account Created");
        //    sendObject.sendSimpleMail(mail);
        //END OF EMAIL

        String SMSMESSAGE = "Your " + accountRole + " account has been created successfully." + " Username = "
                + userName + " and" + " password = " + passwd + " . Your verification code is " + code + "."
                + " Kindly confirm your phone to log in";
        smsrepo.sendSMS(username, SMSMESSAGE, null, phone, new Date());

        FacesMessage msg = new FacesMessage("Account Created successfully");
        FacesContext.getCurrentInstance().addMessage(null, msg);

        email = "";
        phone = "";
        lname = "";
        fname = "";
        userName = "";
        status = 0;
        return null;
    } else {
        FacesMessage msg = new FacesMessage("Account Created successfully");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        return null;
    }
}

From source file:alfio.manager.EventNameManager.java

/**
 * Generates and returns a short name based on the given display name.<br>
 * The generated short name will be returned only if it was not already used.<br>
 * The input parameter will be clean from "evil" characters such as punctuation and accents
 *
 * 1) if the {@code displayName} is a one-word name, then no further calculation will be done and it will be returned as it is, to lower case
 * 2) the {@code displayName} will be split by word and transformed to lower case. If the total length is less than 15, then it will be joined using "-" and returned
 * 3) the first letter of each word will be taken, excluding numbers
 * 4) a random code will be returned//from w w  w.  j  a  va2 s. c o m
 *
 * @param displayName
 * @return
 */
public String generateShortName(String displayName) {
    Validate.isTrue(StringUtils.isNotBlank(displayName));
    String cleanDisplayName = StringUtils.stripAccents(StringUtils.normalizeSpace(displayName))
            .toLowerCase(Locale.ENGLISH).replaceAll(FIND_EVIL_CHARACTERS, "-");
    if (!StringUtils.containsWhitespace(cleanDisplayName) && isUnique(cleanDisplayName)) {
        return cleanDisplayName;
    }
    Optional<String> dashedName = getDashedName(cleanDisplayName);
    if (dashedName.isPresent()) {
        return dashedName.get();
    }
    Optional<String> croppedName = getCroppedName(cleanDisplayName);
    if (croppedName.isPresent()) {
        return croppedName.get();
    }
    return generateRandomName();
}

From source file:com.beans.CustomerAdminMBean.java

public String addAction() throws ProcessingException {

    if (StringUtils.containsWhitespace(userName)) {
        FacesMessage msg = new FacesMessage("Username contains white spaces");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        return null;
    }/* w  w w  .  ja  va2 s  .com*/
    if (customerrepo.findByUsername(userName) != null) {
        FacesMessage msg = new FacesMessage("Username already exists");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        return null;
    } else if (userName != null && userName.length() > 11) {
        FacesMessage msg = new FacesMessage("Username Length is greater than eleven");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        return null;
    } else if (customerrepo.findByEmail(email) != null) {
        FacesMessage msg = new FacesMessage("Email already exists");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        return null;
    }
    if (customerrepo.findByPhone(phone) != null) {
        FacesMessage msg = new FacesMessage("Phone already exists");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        return null;
    } else {
        Customer cust = new Customer();
        cust.setUsername(userName);
        cust.setStatus(CustomerStatus.INACTIVE.ordinal());
        cust.setReward(0d);
        cust.setPhone(phone);
        cust.setPassword(Util.hash(passwd));
        cust.setLastName(lname);
        cust.setFirstName(fname);
        cust.setEmail(email);
        cust.setAddress(address);
        cust.setBalance(customerrepo.getProperty("SignUpBonus"));
        String code = Util.generateCode();
        cust.setActivationCode(code);
        cust.setRegDate(new Date());
        cust.setAccountType(accountType);
        cust.setRate(customerrepo.getProperty("FlatRate"));
        customerrepo.create(cust);
        customerList.add(cust);

        //SENDING EMAIL
        SendEmail sendObject = new SendEmail();
        Email mail = new Email();
        mail.setEmailAddress(email);
        mail.setMessage("Dear " + fname + ", SMS Solutions welcomes you. "
                + "Your sms account has been successfully created. " + "Your Username is " + userName
                + " and your password is " + passwd + " ."
                + " Your number verification code has been sent to your phone. \n"
                + "Kindly click on the link below to verify your number and activate your account:\n"
                + "http://smssolutions.com.ng:8180/BulkSMS/verifycode\n" + "Thank you for your patronage.");
        mail.setSubject("SMS Account Created");
        sendObject.sendSimpleMail(mail);
        //END OF EMAIL

        String SMSMESSAGE = "Your SMS account has been created successfully." + " Username = " + userName
                + " and" + " password = " + passwd + " . Your verification code is " + code + "."
                + " Kindly confirm your phone to log in";
        smsrepo.sendSMS(ResponseCode.HEADER, SMSMESSAGE, null, phone, new Date());

        FacesMessage msg = new FacesMessage("Account Created successfully");
        FacesContext.getCurrentInstance().addMessage(null, msg);

        email = "";
        phone = "";
        lname = "";
        fname = "";
        status = 0;
        return null;
    }
}

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

public ParserMetadata(CommandFactory<T> commandFactory, List<OptionParser<T>> optionParsers,
        TypeConverter typeConverter, boolean allowAbbreviateCommands, boolean allowAbbreviatedOptions,
        List<AliasMetadata> aliases, UserAliasesSource<T> userAliases, boolean aliasesOverrideBuiltIns,
        boolean aliasesMayChain, String argumentsSeparator) {
    if (optionParsers == null)
        throw new NullPointerException("optionParsers cannot be null");
    if (aliases == null)
        throw new NullPointerException("aliases cannot be null");

    // Command parsing
    this.commandFactory = commandFactory != null ? commandFactory : new DefaultCommandFactory<T>();
    this.allowAbbreviatedCommands = allowAbbreviateCommands;

    // Option Parsing
    this.typeConverter = typeConverter != null ? typeConverter : new DefaultTypeConverter();
    this.optionParsers = AirlineUtils.unmodifiableListCopy(optionParsers);
    this.allowAbbreviatedOptions = allowAbbreviatedOptions;

    // Aliases/*from w w w . j a v a  2  s . co m*/
    this.aliases = AirlineUtils.unmodifiableListCopy(aliases);
    this.userAliases = userAliases;
    this.aliasesOverrideBuiltIns = aliasesOverrideBuiltIns;
    this.aliasesMayChain = aliasesMayChain;

    // Arguments Separator
    if (StringUtils.isNotEmpty(argumentsSeparator)) {
        if (StringUtils.containsWhitespace(argumentsSeparator))
            throw new IllegalArgumentException("argumentsSeparator cannot contain any whitespace");
    }
    this.argsSeparator = StringUtils.isNotEmpty(argumentsSeparator) ? argumentsSeparator
            : DEFAULT_ARGUMENTS_SEPARATOR;

}

From source file:com.erudika.para.persistence.MongoDBUtils.java

/**
 * Creates a table in MongoDB./*from  w  w  w  .j av  a2  s. co  m*/
 * @param appid name of the {@link com.erudika.para.core.App}
 * @return true if created
 */
public static boolean createTable(String appid) {
    if (StringUtils.isBlank(appid) || StringUtils.containsWhitespace(appid) || existsTable(appid)) {
        return false;
    }
    try {
        getClient().createCollection(getTableNameForAppid(appid));
        // *** Don't need to create a secondary index here until when will be developed a full "Search" implementation for MongoDB ***
        // create a default seconday index for parentid field as string
        // getClient().getCollection(appid).createIndex(Indexes.text(Config._PARENTID));
    } catch (Exception e) {
        logger.error(null, e);
        return false;
    }
    return true;
}