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

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

Introduction

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

Prototype

public static boolean isEmpty(final CharSequence cs) 

Source Link

Document

Checks if a CharSequence is empty ("") or null.

 StringUtils.isEmpty(null)      = true StringUtils.isEmpty("")        = true StringUtils.isEmpty(" ")       = false StringUtils.isEmpty("bob")     = false StringUtils.isEmpty("  bob  ") = false 

NOTE: This method changed in Lang version 2.0.

Usage

From source file:com.gdo.stencils.faces.FacetsRendererWithContent.java

@Override
public String getHtmlContent(C stclContext) {
    String content = _content;/*w  w  w.  j a v  a  2  s . c o  m*/
    if (StringUtils.isEmpty(content)) {
        if (getLog().isWarnEnabled())
            getLog().warn(stclContext, "iterator tag with no content...");
        content = ""; // at least not null;
    }
    return content;
}

From source file:cherry.foundation.validator.MinLengthValidator.java

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
    if (StringUtils.isEmpty(value)) {
        return true;
    }//from   ww w . j  ava2  s .  c o  m
    return value.length() >= minLength;
}

From source file:cherry.foundation.validator.ZipCodeValidator.java

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
    if (StringUtils.isEmpty(value)) {
        return true;
    }/*from   ww w. jav a2  s . c o  m*/
    if (hyphen) {
        return value.matches("^\\d{3}-\\d{4}$");
    } else {
        return value.matches("^\\d{3}\\d{4}$");
    }
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesApiVersion.java

@JsonCreator
public static KubernetesApiVersion fromString(String name) {
    if (StringUtils.isEmpty(name)) {
        return null;
    }//from w  w  w  .  j  av  a 2  s  .co m

    synchronized (values) {
        Optional<KubernetesApiVersion> versionOptional = values.stream()
                .filter(v -> v.name.equalsIgnoreCase(name)).findAny();

        // separate from the above chain to avoid concurrent modification of the values list
        return versionOptional.orElseGet(() -> new KubernetesApiVersion(name));
    }
}

From source file:applica.framework.modules.LicenseModule.java

@Action(value = "generate", description = "Generate a new license file")
public void generate(Properties properties) {
    File file = new File(LicenseManager.LICENSE_FILE);
    if (file.exists()) {
        p("Cannot create license file: %s already exists", LicenseManager.LICENSE_FILE);
        return;//from  w w  w.  j  a  v a  2  s . c om
    }

    String user = properties.getProperty("user");

    if (StringUtils.isEmpty(user)) {
        p("Please specify a user (-Duser={user}");
        return;
    }

    String dateString = properties.getProperty("validity");

    if (StringUtils.isEmpty(dateString)) {
        p("Please specify a user (-validity={yyyy-MM-dd}");
        return;
    }

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = null;
    try {
        date = dateFormat.parse(dateString);
    } catch (ParseException e) {
        p("Bad date format. Use yyyy-MM-dd");
        return;
    }

    if (date != null) {
        try {
            LicenseManager.instance().generateLicenseFile(user, date, file.getAbsolutePath());

            p("License generated: %s", file.getAbsolutePath());
        } catch (LicenseGenerationException e) {
            p("Error generating license file: %s", e.getMessage());
        }
    }
}

From source file:com.khs.sherpa.util.Util.java

public static String getObjectName(Class<?> type) {
    String name = null;/*from   w  ww  . j  av a2 s . com*/
    if (type.isAnnotationPresent(Endpoint.class)) {
        name = type.getAnnotation(Endpoint.class).value();
    }

    if (StringUtils.isEmpty(name)) {
        name = type.getSimpleName();
    }
    return name;
}

From source file:com.vilt.minium.impl.WindowWebElementsDriver.java

@Override
public String toString() {
    if (StringUtils.isEmpty(windowHandle)) {
        return "window";
    } else {/*  w  w  w . ja v a  2s.c o m*/
        return format("window(handle='%s')", windowHandle);
    }
}

From source file:hoot.services.utils.ReviewUtils.java

/**
 * Handles all thrown exceptions from review services
 *
 * @param e// w ww . j  a  v  a  2s  .  co m
 *            a thrown exception
 * @param errorMessageStart
 *            text to prepend to the error message
 * //TODO: go through and clean out these message text checks
 */
public static void handleError(Exception e, String errorMessageStart) {
    Status status = null;
    if (!StringUtils.isEmpty(e.getMessage())) {
        if (e.getMessage().contains("Invalid input parameter")
                || e.getMessage().contains("Invalid reviewed item")
                || e.getMessage().contains("Error parsing unique ID tag")
                || e.getMessage().contains("empty String") || e.getMessage().contains("Invalid coordinate")) {
            status = Status.BAD_REQUEST;
        } else if (e.getMessage().contains("record exists") || e.getMessage().contains("records exist")
                || e.getMessage().contains("to be updated does not exist")
                || e.getMessage().contains("does not exist")) {
            status = Status.NOT_FOUND;
        } else if (e.getMessage().contains("Invalid version") || e.getMessage().contains("Invalid changeset ID")
                || e.getMessage().contains("references itself")
                || e.getMessage().contains("Changeset maximum element threshold exceeded")
                || e.getMessage().contains("was closed at")
                || e.getMessage().contains("has become out of sync")) {
            status = Status.CONFLICT;
        } else if (e.getMessage().contains("exist specified for") || e.getMessage().contains("exist for")
                || e.getMessage().contains("is still used by")) {
            status = Status.PRECONDITION_FAILED;
        }
    }

    if (status == null) {
        status = Status.INTERNAL_SERVER_ERROR;
    }

    String message = "Error " + errorMessageStart + ": ";
    if ((e.getMessage() != null) && e.getMessage().contains("empty String")) {
        // added for giving a better error message when passing invalid params to jersey
        message += "Invalid input parameter";
    } else {
        message += e.getMessage();
    }

    if (e instanceof SQLException) {
        SQLException sqlException = (SQLException) e;
        if (sqlException.getNextException() != null) {
            message += "  " + sqlException.getNextException().getMessage();
        }
    }

    if (e.getCause() instanceof SQLException) {
        SQLException sqlException = (SQLException) e.getCause();
        if (sqlException.getNextException() != null) {
            message += "  " + sqlException.getNextException().getMessage();
        }
    }

    String exceptionCode = status.getStatusCode() + ": " + status.getReasonPhrase();
    logger.error("{} {}", exceptionCode, message, e);

    throw new WebApplicationException(e, Response.status(status).entity(message).build());
}

From source file:com.assignmentone.snippet.SimpleSnippet.java

public Renderer render(String name) {
    // replace the whole title node
    if (StringUtils.isEmpty(name)) {
        name = "Asta4D";
    }/*w w  w  .  j a  va  2 s .co  m*/
    Element element = ElementUtil.parseAsSingle("<div>Hello " + name + "!</div>");
    return Renderer.create(":root", element);
}

From source file:com.google.mr4c.config.resources.ResourceLimit.java

public static ResourceLimit extractFrom(ResourceInfo resource, Configuration conf) {
    String strVal = conf.get(resource.getMaxHadoopName());
    if (StringUtils.isEmpty(strVal)) {
        return null;
    }/* www . j av a 2 s  .c  o m*/
    int val = Integer.parseInt(strVal);
    return new ResourceLimit(resource, val, LimitSource.CONFIG);
}