Example usage for org.apache.commons.lang StringUtils isWhitespace

List of usage examples for org.apache.commons.lang StringUtils isWhitespace

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils isWhitespace.

Prototype

public static boolean isWhitespace(String str) 

Source Link

Document

Checks if the String contains only whitespace.

Usage

From source file:de.weltraumschaf.registermachine.asm.CharUtils.java

static boolean isWhitespace(final char c) {
    return StringUtils.isWhitespace(String.valueOf(c));
}

From source file:com.ocs.dynamo.utils.PasteUtilsTest.java

@Test
public void testSplit() {
    Assert.assertNull(PasteUtils.split(null));

    String[] result = PasteUtils.split("3");
    Assert.assertEquals("3", result[0]);

    result = PasteUtils.split("3 4 5");
    Assert.assertEquals("3", result[0]);
    Assert.assertEquals("4", result[1]);
    Assert.assertEquals("5", result[2]);

    result = PasteUtils.split("3\t4\n5");
    Assert.assertEquals("3", result[0]);
    Assert.assertEquals("4", result[1]);
    Assert.assertEquals("5", result[2]);

    Assert.assertTrue(StringUtils.isWhitespace("\t"));
}

From source file:com.hp.alm.ali.idea.model.type.PlainTextType.java

@Override
public String translate(String value, ValueCallback callback) {
    try {/*ww  w. ja v a 2  s .c  om*/
        final StringBuffer buf = new StringBuffer();
        new ParserDelegator().parse(new StringReader(value), new HTMLEditorKit.ParserCallback() {
            @Override
            public void handleText(char[] data, int pos) {
                if (buf.length() > 0 && !StringUtils.isWhitespace(buf.substring(buf.length() - 1))) {
                    buf.append(" ");
                }
                buf.append(data);
            }
        }, false);
        return buf.toString();
    } catch (IOException e) {
        return StringEscapeUtils.escapeHtml(value);
    }
}

From source file:com.fengduo.spark.commons.test.BaseTestCase.java

/**
 * Assert string contains only whitespace.
 */
protected void assertWhitespace(String str) {
    Assert.assertTrue(StringUtils.isWhitespace(str));
}

From source file:net.rim.ejde.internal.ui.editors.locale.ResourceKeyValidator.java

/**
 * This method checks if a key is valid. A key cannot have an empty name unless it is allowed. It also have to follow a
 * certain pattern and cannot contain special characters. This method also checks if a key consists of reserved words or if a
 * key already exists.//  w  ww.j a v  a 2  s .  c o m
 *
 * @param key
 *            The key to be validated
 */
public String isValid(String key) {
    // Check for empty key name
    if (!_allowEmpty && StringUtils.isBlank(key))
        return Messages.ResourceKeyValidator_ResourceKey_Empty;

    // Check if key contains only whitespace
    if (StringUtils.isWhitespace(key))
        return Messages.ResourceKeyValidator_ResourceKey_Whitespace;

    // Check if key is reserved word
    if (isReservedWord(key))
        return Messages.ResourceKeyValidator_ResourceKey_ReservedWord;

    // Check if key contains invalid characters
    if (containsInvalidChar(key))
        return Messages.ResourceKeyValidator_ResourceKey_InvalidCharacter;

    // Check if key already exists
    if (_collection.containsKey(key) && !(key.equals(_currentKey)))
        return Messages.ResourceKeyValidator_ResourceKey_KeyExists;

    return null;
}

From source file:com.gst.infrastructure.core.serialization.DatatableCommandFromApiJsonDeserializer.java

private void validateType(final DataValidatorBuilder baseDataValidator, final JsonElement column) {
    final String type = this.fromApiJsonHelper.extractStringNamed("type", column);
    baseDataValidator.reset().parameter("type").value(type).notBlank()
            .isOneOfTheseStringValues(this.supportedColumnTypes);

    if (type != null && type.equalsIgnoreCase("String")) {
        if (this.fromApiJsonHelper.parameterExists("length", column)) {
            final String lengthStr = this.fromApiJsonHelper.extractStringNamed("length", column);
            if (lengthStr != null && !StringUtils.isWhitespace(lengthStr) && StringUtils.isNumeric(lengthStr)
                    && StringUtils.isNotBlank(lengthStr)) {
                final Integer length = Integer.parseInt(lengthStr);
                baseDataValidator.reset().parameter("length").value(length).positiveAmount();
            } else if (StringUtils.isBlank(lengthStr) || StringUtils.isWhitespace(lengthStr)) {
                baseDataValidator.reset().parameter("length")
                        .failWithCode("must.be.provided.when.type.is.String");
            } else if (!StringUtils.isNumeric(lengthStr)) {
                baseDataValidator.reset().parameter("length").failWithCode("not.greater.than.zero");
            }//ww w. ja  v a2 s .  c o m
        } else {
            baseDataValidator.reset().parameter("length").failWithCode("must.be.provided.when.type.is.String");
        }
    } else {
        baseDataValidator.reset().parameter("length").mustBeBlankWhenParameterProvidedIs("type", type);
    }

    final String code = this.fromApiJsonHelper.extractStringNamed("code", column);
    if (type != null && type.equalsIgnoreCase("Dropdown")) {
        if (code != null) {
            baseDataValidator.reset().parameter("code").value(code).notBlank()
                    .matchesRegularExpression(DATATABLE_NAME_REGEX_PATTERN);
        } else {
            baseDataValidator.reset().parameter("code").value(code).cantBeBlankWhenParameterProvidedIs("type",
                    type);
        }
    } else {
        baseDataValidator.reset().parameter("code").value(code).mustBeBlankWhenParameterProvided("type", type);
    }
}

From source file:net.bible.service.format.OSISInputStream.java

/** load the next verse, or opening or closing <div> into the verse buffer
 * //from  ww w .java  2s .  c  o  m
 * @throws UnsupportedEncodingException
 */
private void loadNextVerse() throws UnsupportedEncodingException {
    try {
        if (isFirstVerse) {
            putInVerseBuffer(DOC_START);
            isFirstVerse = false;
            return;
        }

        boolean isNextVerseLoaded = false;
        while (keyIterator.hasNext() && !isNextVerseLoaded) {
            Key currentVerse = keyIterator.next();
            //get the actual verse text and tidy it up, 
            String rawText = book.getRawText(currentVerse);

            // do not output empty verses (commonly verse 0 is empty)
            if (!StringUtils.isWhitespace(rawText)) {

                // merged verses can cause duplicates so if dup then skip immediately to next verse
                if (!previousVerseRawText.equals(rawText)) {
                    String tidyText = osisVerseTidy.tidy(currentVerse, rawText);
                    putInVerseBuffer(tidyText);
                    previousVerseRawText = rawText;
                    isNextVerseLoaded = true;
                    return;
                } else {
                    log.debug("Duplicate verse:" + currentVerse);
                }

            } else {
                log.debug("Empty or missing verse:" + currentVerse);
            }
        }

        if (!isClosingTagWritten) {
            putInVerseBuffer(DOC_END);
            isClosingTagWritten = true;
        }
    } catch (UnsupportedEncodingException usc) {
        usc.printStackTrace();
    } catch (BookException be) {
        be.printStackTrace();
    }
}

From source file:airlift.util.AirliftUtil.java

/**
 * Checks if is whitespace.//from   w w w .ja  v a  2 s  . c  om
 *
 * @param _string the _string
 * @return true, if is whitespace
 */
public static boolean isWhitespace(String _string) {
    return StringUtils.isWhitespace(_string);
}

From source file:com.baifendian.swordfish.common.utils.CommonUtil.java

/**
 * sql ?, ?, ?? ";"//from  w w w . j ava 2s.  c o m
 */
public static List<String> sqlSplit(String sql) {
    if (StringUtils.isEmpty(sql)) {
        return Collections.EMPTY_LIST;
    }

    List<String> r = new ArrayList<>();

    Status status = Status.START;
    StringBuffer buffer = new StringBuffer();

    for (int i = 0; i < sql.length(); ++i) {
        char c = sql.charAt(i);
        char nextChar = ((i + 1) < sql.length()) ? sql.charAt(i + 1) : ' '; // add at 2017/1/6

        boolean skip = false;

        switch (status) {
        case START: {
            if (c == ';') {
                status = Status.END;
                skip = true; //  ;
            } else if (c == '\'') {
                status = Status.SINGLE_QUOTE;
            } else if (c == '"') {
                status = Status.QUOTE;
            } else if (c == '-' && nextChar == '-') { // add at 2017/1/6
                status = Status.COMMENT;
                ++i; // add at 2017/1/6
                skip = true;
            } else if (Character.isWhitespace(c)) {
                status = Status.BLANK;
            }
        }
            break;
        case BLANK: {
            if (c == ';') {
                status = Status.END;
                skip = true; //  ;
            } else if (c == '"') {
                status = Status.QUOTE;
            } else if (c == '\'') {
                status = Status.SINGLE_QUOTE;
            } else if (c == '-' && nextChar == '-') { // add at 2017/1/6)
                status = Status.COMMENT;
                ++i; // add at 2017/1/6
                skip = true;
            } else if (!Character.isWhitespace(c)) {
                status = Status.START;
            } else {
                skip = true;
            }
        }
            break;
        case END: {
            if (c == '"') {
                status = Status.QUOTE;
            } else if (c == '\'') {
                status = Status.SINGLE_QUOTE;
            } else if (Character.isWhitespace(c)) {
                status = Status.BLANK;
            } else if (c == '-' && nextChar == '-') { // add at 2017/1/6)
                status = Status.COMMENT;
                ++i; // add at 2017/1/6
                skip = true;
            } else if (c != ';') {
                status = Status.START;
            } else {
                skip = true;
            }
        }
            break;
        case QUOTE: {
            if (c == '"') {
                status = Status.START;
            } else if (c == '\\') {
                status = Status.BACKSLASH_FOR_QUOTE;
            }
        }
            break;
        case SINGLE_QUOTE: {
            if (c == '\'') {
                status = Status.START;
            } else if (c == '\\') {
                status = Status.BACKSLASH_FOR_SINGLE_QUOTE;
            }
        }
            break;
        case BACKSLASH_FOR_QUOTE: {
            status = Status.QUOTE;
        }
            break;
        case BACKSLASH_FOR_SINGLE_QUOTE: {
            status = Status.SINGLE_QUOTE;
        }
            break;
        case COMMENT: {
            if (c != '\r' && c != '\n') {
                status = Status.COMMENT;
                skip = true;
            } else {
                status = Status.START;
            }
        }
            break;
        }

        if (!skip) {
            //  white space ??
            if (Character.isWhitespace(c)) {
                buffer.append(' ');
            } else {
                buffer.append(c);
            }
        }

        if (status == Status.END) {
            String sub = buffer.toString();
            if (!StringUtils.isWhitespace(sub)) {
                r.add(sub.trim());
            }
            buffer = new StringBuffer();
        }
    }

    String sub = buffer.toString();
    if (!StringUtils.isWhitespace(sub)) {
        r.add(sub.trim());
    }

    return r;
}

From source file:msi.gama.gui.swt.WorkspaceModelsManager.java

/**
 * @param filePath// w  ww . j a  v a  2s  .  com
 * @return
 */
private IFile findAndLoadIFile(final String filePath) {
    GuiUtils.debug("WorkspaceModelsManager.findAndLoadIFile " + filePath);
    // No error in case of an empty argument
    if (filePath == null || filePath.isEmpty() || StringUtils.isWhitespace(filePath)) {
        return null;
    }
    IPath path = new Path(filePath);
    // 1st case: the path can be identified as a file residing in the workspace
    IFile result = findInWorkspace(path);
    if (result != null) {
        return result;
    }
    // 2nd case: the path is outside the workspace
    result = findOutsideWorkspace(path);
    if (result != null) {
        return result;
    }
    System.out.println("File " + filePath
            + " cannot be located. Please check its name and location. Arguments provided were : "
            + Arrays.toString(CommandLineArgs.getApplicationArgs()));
    return null;
}