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

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

Introduction

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

Prototype

public static boolean isAlphaSpace(final CharSequence cs) 

Source Link

Document

Checks if the CharSequence contains only Unicode letters and space (' ').

null will return false An empty CharSequence (length()=0) will return true .

 StringUtils.isAlphaSpace(null)   = false StringUtils.isAlphaSpace("")     = true StringUtils.isAlphaSpace("  ")   = true StringUtils.isAlphaSpace("abc")  = true StringUtils.isAlphaSpace("ab c") = true StringUtils.isAlphaSpace("ab2c") = false StringUtils.isAlphaSpace("ab-c") = false 

Usage

From source file:com.github.britter.beanvalidators.strings.AlphabeticConstraintValidator.java

@Override
public boolean isValid(final String value, final ConstraintValidatorContext context) {
    // Don't validate null, empty and blank strings, since these are validated by @NotNull, @NotEmpty and @NotBlank
    return StringUtils.isBlank(value) || allowSpaces ? StringUtils.isAlphaSpace(value)
            : StringUtils.isAlpha(value);
}

From source file:com.bellman.bible.service.format.osistohtml.taghandler.ReferenceHandler.java

/** create a link tag from an OSISref and the content of the tag
 *//*from  ww  w  . j  a v a  2  s .  co m*/
private String getReferenceTag(String reference, String content) {
    log.debug("Ref:" + reference + " Content:" + content);
    StringBuilder result = new StringBuilder();
    try {

        //JSword does not know the basis (default book) so prepend it if it looks like JSword failed to work it out
        //We only need to worry about the first ref because JSword uses the first ref as the basis for the subsequent refs
        // if content starts with a number and is not followed directly by an alpha char e.g. 1Sa
        if (reference == null && content != null && content.length() > 0
                && StringUtils.isNumeric(content.subSequence(0, 1))
                && (content.length() < 2 || !StringUtils.isAlphaSpace(content.subSequence(1, 2)))) {

            // maybe should use VerseRangeFactory.fromstring(orig, basis)
            // this check for a colon to see if the first ref is verse:chap is not perfect but it will do until JSword adds a fix
            int firstColonPos = content.indexOf(":");
            boolean isVerseAndChapter = firstColonPos > 0 && firstColonPos < 4;
            if (isVerseAndChapter) {
                reference = parameters.getBasisRef().getBook().getOSIS() + " " + content;
            } else {
                reference = parameters.getBasisRef().getBook().getOSIS() + " "
                        + parameters.getBasisRef().getChapter() + ":" + content;
            }
            log.debug("Patched reference:" + reference);
        } else if (reference == null) {
            reference = content;
        }

        // convert urns of type book:key to sword://book/key to simplify urn parsing (1 fewer case to check for).  
        // Avoid urls of type 'matt 3:14' by excludng urns with a space
        if (reference.contains(":") && !reference.contains(" ") && !reference.startsWith("sword://")) {
            reference = "sword://" + reference.replace(":", "/");
        }

        boolean isFullSwordUrn = reference.contains("/") && reference.contains(":");
        if (isFullSwordUrn) {
            // e.g. sword://StrongsRealGreek/01909
            // don't play with the reference - just assume it is correct
            result.append("<a href='").append(reference).append("'>");
            result.append(content);
            result.append("</a>");
        } else {
            Passage ref = (Passage) PassageKeyFactory.instance().getKey(parameters.getDocumentVersification(),
                    reference);
            boolean isSingleVerse = ref.countVerses() == 1;
            boolean isSimpleContent = content.length() < 3 && content.length() > 0;
            Iterator<VerseRange> it = ref.rangeIterator(RestrictionType.CHAPTER);

            if (isSingleVerse && isSimpleContent) {
                // simple verse no e.g. 1 or 2 preceding the actual verse in TSK
                result.append("<a href='").append(Constants.BIBLE_PROTOCOL).append(":")
                        .append(it.next().getOsisRef()).append("'>");
                result.append(content);
                result.append("</a>");
            } else {
                // multiple complex references
                boolean isFirst = true;
                while (it.hasNext()) {
                    Key key = it.next();
                    if (!isFirst) {
                        result.append(" ");
                    }
                    // we just references the first verse in each range because that is the verse you would jump to.  It might be more correct to reference the while range i.e. key.getOsisRef() 
                    result.append("<a href='").append(Constants.BIBLE_PROTOCOL).append(":")
                            .append(key.iterator().next().getOsisRef()).append("'>");
                    result.append(key);
                    result.append("</a>");
                    isFirst = false;
                }
            }
        }
    } catch (Exception e) {
        log.error("Error parsing OSIS reference:" + reference);
        // just return the content with no html markup
        result.append(content);
    }
    return result.toString();
}

From source file:com.kynomics.control.HalterController.java

public void validateAlpha(FacesContext context, UIComponent uiComponent, Object value)
        throws ValidatorException {
    if (!StringUtils.isAlphaSpace((String) value)) {
        HtmlInputText htmlInputText = (HtmlInputText) uiComponent;
        FacesMessage facesMessage = new FacesMessage(htmlInputText.getLabel() + ": nur Buchstaben erlaubt");
        throw new ValidatorException(facesMessage);
    }//from   w w  w .jav a2  s  . c om
}

From source file:vista.controlador.Validador.java

/**
 * Valida que el campo sea nombre, esto es que no est vaco y que contenga
 * slo letras y espacios/*from w w  w.j  av  a  2s  .  co m*/
 *
 * @param campo la cadena de texto a validar
 * @return true si el campo ingresado es validado como un nombre, false si
 * ocurre lo contrario
 */
public static boolean esNombre(String campo) {
    boolean ok = true;

    if (estaVacio(campo) || !StringUtils.isAlphaSpace(campo)) {
        ok = false;
    }

    return ok;
}