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

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

Introduction

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

Prototype

public static String strip(final String str) 

Source Link

Document

Strips whitespace from the start and end of a String.

This is similar to #trim(String) but removes whitespace.

Usage

From source file:com.eryansky.service.sys.DictionaryTypeManager.java

/**
 * ??code./*from  w  ww.  j ava 2 s  . c  om*/
 * 
 * @param code
 *            ??
 * @return
 * @throws DaoException
 * @throws SystemException
 * @throws ServiceException
 */
@SuppressWarnings("unchecked")
public DictionaryType getByCode(String code) throws DaoException, SystemException, ServiceException {
    if (StringUtils.isBlank(code)) {
        return null;
    }
    code = StringUtils.strip(code);// 
    List<DictionaryType> list = dictionaryTypeDao
            .createQuery("from DictionaryType d where d.code = ?", new Object[] { code }).list();
    return list.isEmpty() ? null : list.get(0);
}

From source file:com.squarespace.less.parse.DirectiveParselet.java

private String parseIdentifier(LessStream stm) throws LessException {
    StringBuilder buf = new StringBuilder();
    stm.skipWs();/*  w w w .  j a v a 2s.  c  o m*/
    char ch = stm.peek();
    while (ch != Chars.NULL && ch != Chars.LEFT_CURLY_BRACKET && ch != Chars.LEFT_SQUARE_BRACKET) {
        buf.append(ch);
        stm.seek1();
        ch = stm.peek();
    }
    return " " + StringUtils.strip(buf.toString());
}

From source file:ch.cyberduck.core.sftp.SFTPChallengeResponseAuthentication.java

public boolean authenticate(final Host host, final Credentials credentials, final LoginCallback controller)
        throws BackgroundException {
    if (StringUtils.isBlank(host.getCredentials().getPassword())) {
        return false;
    }//  w  ww. ja va2  s. c  o m
    if (log.isDebugEnabled()) {
        log.debug(String.format("Login using challenge response authentication with credentials %s",
                credentials));
    }
    try {
        session.getClient().auth(credentials.getUsername(),
                new AuthKeyboardInteractive(new ChallengeResponseProvider() {
                    /**
                     * Password sent flag
                     */
                    private final AtomicBoolean password = new AtomicBoolean();

                    private String name = StringUtils.EMPTY;

                    private String instruction = StringUtils.EMPTY;

                    @Override
                    public List<String> getSubmethods() {
                        return Collections.emptyList();
                    }

                    @Override
                    public void init(final Resource resource, final String name, final String instruction) {
                        if (StringUtils.isNoneBlank(instruction)) {
                            this.instruction = instruction;
                        }
                        if (StringUtils.isNoneBlank(name)) {
                            this.name = name;
                        }
                    }

                    @Override
                    public char[] getResponse(final String prompt, final boolean echo) {
                        if (log.isDebugEnabled()) {
                            log.debug(String.format("Reply to challenge name %s with instruction %s", name,
                                    instruction));
                        }
                        final String response;
                        // For each prompt, the corresponding echo field indicates whether the user input should
                        // be echoed as characters are typed
                        if (!password.get()
                                // Some servers ask for one-time passcode first
                                && !StringUtils.contains(prompt, "Verification code")) {
                            // In its first callback the server prompts for the password
                            if (log.isDebugEnabled()) {
                                log.debug("First callback returning provided credentials");
                            }
                            response = credentials.getPassword();
                            password.set(true);
                        } else {
                            final StringAppender message = new StringAppender().append(instruction)
                                    .append(prompt);
                            // Properly handle an instruction field with embedded newlines.  They should also
                            // be able to display at least 30 characters for the name and prompts.
                            final Credentials additional = new Credentials(credentials.getUsername()) {
                                @Override
                                public String getPasswordPlaceholder() {
                                    return StringUtils.removeEnd(StringUtils.strip(prompt), ":");
                                }
                            };
                            try {
                                final StringAppender title = new StringAppender().append(name).append(
                                        LocaleFactory.localizedString("Provide additional login credentials",
                                                "Credentials"));
                                controller.prompt(host, additional, title.toString(), message.toString(),
                                        new LoginOptions().user(false).keychain(false));
                            } catch (LoginCanceledException e) {
                                return EMPTY_RESPONSE;
                            }
                            response = additional.getPassword();
                        }
                        // Responses are encoded in ISO-10646 UTF-8.
                        return response.toCharArray();
                    }

                    @Override
                    public boolean shouldRetry() {
                        return false;
                    }
                }));
    } catch (IOException e) {
        throw new SFTPExceptionMappingService().map(e);
    }
    return session.getClient().isAuthenticated();
}

From source file:io.cloudslang.content.utils.NumberUtilities.java

/**
 * Given an integer string if it's a valid int (see isValidInt) it converts it into an integer otherwise it throws an exception
 *
 * @param integerStr the integer to convert
 * @return the integer value of the integerStr
 * @throws IllegalArgumentException if the passed integer string is not a valid integer
 *//*from w  w w .j  a v a2 s .  c  om*/
public static int toInteger(@Nullable final String integerStr) {
    if (!isValidInt(integerStr)) {
        throw new IllegalArgumentException(
                integerStr + ExceptionValues.EXCEPTION_DELIMITER + ExceptionValues.INVALID_INTEGER_VALUE);
    }
    final String stripedInteger = StringUtils.strip(integerStr);
    return NumberUtils.createInteger(stripedInteger);
}

From source file:ca.phon.app.query.SaveQueryDialog.java

private boolean checkForm() {
    boolean retVal = true;

    // make sure we have a name
    String scriptName = StringUtils.strip(nameField.getText());

    if (scriptName.length() == 0) {
        final Toast toast = ToastFactory.makeToast("Please provide a name");
        toast.start(nameField);//from  w w w  . j  a v  a 2s.  co  m
        retVal = false;
    }

    return retVal;
}

From source file:io.stallion.dataAccess.db.SqlGenerationAction.java

public int getLastMigrationNumber() {
    Integer max = 0;// ww w  .  java 2 s  .c  o m
    File migrationsFile = new File(System.getProperty("user.dir") + "/src/main/resources/sql/migrations.txt");
    if (migrationsFile.exists()) {
        for (String line : FileUtils.readAllText(migrationsFile, UTF8).split("\\n")) {
            line = StringUtils.strip(line);
            if (empty(line)) {
                continue;
            }
            if (line.startsWith("//") || line.startsWith("#")) {
                continue;
            }
            int dash = line.indexOf("-");
            if (dash == -1) {
                continue;
            }
            Integer version = Integer.valueOf(StringUtils.stripStart(line.substring(0, dash), "0"));
            if (version >= max) {
                max = version;
            }
        }

    } else {
        for (SqlMigration migration : new SqlMigrationAction().getUserMigrations()) {
            if (migration.getVersionNumber() > max) {
                max = migration.getVersionNumber();
            }
        }
    }
    return max;
}

From source file:io.cloudslang.content.utils.NumberUtilities.java

/**
 * Given a long integer string if it's a valid long (see isValidLong) it converts it into a long integer otherwise it throws an exception
 *
 * @param longStr the long integer to convert
 * @return the long integer value of the longStr
 * @throws IllegalArgumentException if the passed long integer string is not a valid long value
 *///ww  w .j  a v a2s .c  om
public static long toLong(@Nullable final String longStr) {
    if (!isValidLong(longStr)) {
        throw new IllegalArgumentException(
                longStr + ExceptionValues.EXCEPTION_DELIMITER + ExceptionValues.INVALID_LONG_VALUE);
    }
    final String stripedLong = StringUtils.strip(longStr);
    return NumberUtils.createLong(stripedLong);
}

From source file:ca.phon.ipadictionary.impl.TransliterationDictionary.java

private void readTokenMap(InputStream is) throws IOException {
    tokenMap = new LinkedHashMap<String, String>();

    final InputStreamReader in = new InputStreamReader(is, "UTF-8");
    final BufferedReader reader = new BufferedReader(in);

    final Pattern dictPattern = getPattern();

    String line = null;//from ww w  .ja  va  2 s . c  om
    while ((line = reader.readLine()) != null) {
        if (line.startsWith("#")) {
            // ignore as a comment
            continue;
        }

        final Matcher m = dictPattern.matcher(line);
        if (m.matches()) {
            final String key = StringUtils.strip(m.group(1));
            final String ipa = StringUtils.strip(m.group(3));

            if (key.length() > 0 && ipa.length() > 0) {
                tokenMap.put(key, ipa);
            }
        }
    }
    reader.close();
}

From source file:de.flapdoodle.embed.process.runtime.AbstractProcess.java

protected static int getPidFromFile(File pidFile) throws IOException {
    // wait for file to be created
    int tries = 0;
    while (!pidFile.exists() && tries < 5) {
        try {/*from  ww w  . jav  a 2s . c  om*/
            Thread.sleep(100);
        } catch (InterruptedException e1) {
            // ignore
        }
        logger.warn("Didn't find pid file in try {}, waiting 100ms...", tries);
        tries++;
    }
    // don't check file to be there. want to throw IOException if
    // something happens
    if (!pidFile.exists()) {
        throw new IOException("Could not find pid file " + pidFile);
    }

    // read the file, wait for the pid string to appear
    String fileContent = StringUtils
            .chomp(StringUtils.strip(new String(java.nio.file.Files.readAllBytes(pidFile.toPath()))));
    tries = 0;
    while (StringUtils.isBlank(fileContent) && tries < 5) {
        fileContent = StringUtils
                .chomp(StringUtils.strip(new String(java.nio.file.Files.readAllBytes(pidFile.toPath()))));
        try {
            Thread.sleep(100);
        } catch (InterruptedException e1) {
            // ignore
        }
        tries++;
    }
    // check for empty file
    if (StringUtils.isBlank(fileContent)) {
        throw new IOException(
                "Pidfile " + pidFile + "does not contain a pid. Waited for " + tries * 100 + "ms.");
    }
    // pidfile exists and has content
    try {
        return Integer.parseInt(fileContent);
    } catch (NumberFormatException e) {
        throw new IOException("Pidfile " + pidFile + "does not contain a valid pid. Content: " + fileContent);
    }
}

From source file:ca.phon.ipadictionary.ContractionRule.java

private void parseVExpr() {
    // split string on '+'
    String[] vparts = vExpr.split("\\+");
    tBuilder.clear();//from  w w  w . j av  a2 s.c o m

    for (String part : vparts) {
        ValueClause type = ValueClause.getClause(StringUtils.strip(part));
        VClause clause = new VClause();
        clause.type = type;
        clause.value = StringUtils.strip(part);

        tBuilder.add(clause);
    }
}