Example usage for org.springframework.util StringUtils hasText

List of usage examples for org.springframework.util StringUtils hasText

Introduction

In this page you can find the example usage for org.springframework.util StringUtils hasText.

Prototype

public static boolean hasText(@Nullable String str) 

Source Link

Document

Check whether the given String contains actual text.

Usage

From source file:com.benfante.taglib.frontend.tags.BootstrapTagHelper.java

/**
 * Writes the opening '//  ww w  .j a va  2s.  c om
 * <code>p</code>' tag and forces a block tag so that field prefix/suffix is
 * written correctly.
 */
public static void writeInputTagHelpBlock(final TagWriter tagWriter, final String text) throws JspException {
    if (StringUtils.hasText(text)) {
        tagWriter.startTag("p");
        tagWriter.writeAttribute("class", "help-block");
        tagWriter.appendValue(text);
        tagWriter.endTag();
        tagWriter.forceBlock();
    }
}

From source file:org.jasig.cas.web.support.CookieRetrievingCookieGenerator.java

public void addCookie(final HttpServletRequest request, final HttpServletResponse response,
        final String cookieValue) {

    if (!StringUtils.hasText(request.getParameter(RememberMeCredentials.REQUEST_PARAMETER_REMEMBER_ME))) {
        super.addCookie(response, cookieValue);
    } else {/*  w  ww.j  a  v a 2s .c  o  m*/
        final Cookie cookie = createCookie(cookieValue);
        cookie.setMaxAge(this.rememberMeMaxAge);
        if (isCookieSecure()) {
            cookie.setSecure(true);
        }
        response.addCookie(cookie);
    }
}

From source file:org.xacml4j.spring.pip.ResolverRegistryDefinitionParser.java

private static BeanDefinitionBuilder parseResolvers(Element element) {
    BeanDefinitionBuilder component = BeanDefinitionBuilder
            .rootBeanDefinition(ResolverRegistrationFactoryBean.class);
    String policyId = element.getAttribute("policyId");
    if (StringUtils.hasText(policyId)) {
        component.addPropertyValue("policyId", policyId);
    }//w w w.ja  v a 2  s.  c  o m
    String ref = element.getAttribute("ref");
    if (StringUtils.hasText(ref)) {
        component.addPropertyReference("resolver", ref);
    }
    return component;
}

From source file:org.openmrs.propertyeditor.ReportSchemaXmlEditor.java

public void setAsText(String text) throws IllegalArgumentException {
    if (StringUtils.hasText(text)) {
        try {// w w w.  java2  s . c o  m
            ReportService rs = (ReportService) Context.getService(ReportService.class);
            setValue(rs.getReportSchemaXml(Integer.valueOf(text)));
        } catch (Exception ex) {
            log.error("Error setting text: " + text, ex);
            throw new IllegalArgumentException("ReportSchemaXml not found: " + ex.getMessage());
        }
    } else {
        setValue(null);
    }
}

From source file:org.data.support.beans.factory.support.QueryDefinitionReaderUtils.java

/**
 * Generate a query name for the given query definition, unique within the
 * given query factory./* w  ww . ja  v  a  2 s.c  om*/
 * @param definition the query definition to generate a query name for
 * @param registry the query factory that the definition is going to be
 * registered with (to check for existing query names)
 * @return the generated query name
 * @throws QueryDefinitionStoreException if no unique name can be generated
 * for the given query definition
 */
public static String generateQueryName(QueryDefinition definition, QueryDefinitionRegistry registry)
        throws QueryDefinitionStoreException {
    String generatedQueryName = definition.getQueryClassName();
    if (!StringUtils.hasText(generatedQueryName)) {
        throw new QueryDefinitionStoreException(
                "Unnamed query definition specified - can't generate bean name");
    }

    int counter = -1;

    String id = generatedQueryName;

    while (counter == -1 || registry.containsQueryDefinition(id)) {
        counter++;
        id = generatedQueryName + GENERATED_QUERY_NAME_SEPERATOR + counter;
    }
    return id;
}

From source file:org.cloudfoundry.identity.uaa.login.test.ProfileActiveUtils.java

private static boolean isTestEnabledInThisEnvironment(ProfileValueSource profileValueSource,
        IfProfileActive ifProfileActive, UnlessProfileActive unlessProfileActive) {
    if (ifProfileActive == null && unlessProfileActive == null) {
        return true;
    }//ww w  .  j  a v  a 2  s.c o m

    List<String> blacklist = getBlacklist(unlessProfileActive);
    Set<String> activeProfiles = StringUtils
            .commaDelimitedListToSet(profileValueSource.get("spring.profiles.active"));

    boolean enabled = true;
    if (ifProfileActive != null && StringUtils.hasText(ifProfileActive.value())) {
        enabled = activeProfiles.contains(ifProfileActive.value());
    }
    for (String profile : blacklist) {
        if (activeProfiles.contains(profile)) {
            enabled = false;
            continue;
        }
    }

    return enabled;
}

From source file:example.springdata.web.users.Username.java

/**
 * Creates a new {@link Username}.//  w  ww. ja  v  a  2s .  co m
 * 
 * @param username must not be {@literal null} or empty.
 */
public Username(String username) {

    if (!StringUtils.hasText(username)) {
        throw new IllegalArgumentException("Invalid username!");
    }

    this.username = username;
}

From source file:org.openmrs.module.encounteralerts.EncounterAlertEditor.java

public void setAsText(String text) throws IllegalArgumentException {
    if (StringUtils.hasText(text)) {
        EncounterAlertsService service = Context.getService(EncounterAlertsService.class);
        try {/*w ww. j a va 2 s  .c o  m*/
            EncounterAlert object = service.getEncounterAlert(Integer.valueOf(text));
            setValue(object);
        } catch (Exception ex) {
            EncounterAlert object = service.getEncounterAlertByUuid(text);
            setValue(object);
            if (object == null) {
                log.error("Error setting text: " + text, ex);
                throw new IllegalArgumentException("Encounter alert not found: " + ex.getMessage());
            }
        }
    } else {
        setValue(null);
    }
}

From source file:org.openmrs.module.restrictbyrole.SerializedObjectEditor.java

public void setAsText(String text) throws IllegalArgumentException {
    if (StringUtils.hasText(text)) {
        RestrictByRoleService service = Context.getService(RestrictByRoleService.class);
        try {// w  w w .j  a v a2s .  c  o  m
            SerializedObject object = service.getSerializedObject(Integer.valueOf(text));
            setValue(object);
        } catch (Exception ex) {
            SerializedObject object = service.getSerializedObjectByUuid(text);
            setValue(object);
            if (object == null) {
                log.error("Error setting text: " + text, ex);
                throw new IllegalArgumentException("SerializedObject not found: " + ex.getMessage());
            }
        }
    } else {
        setValue(null);
    }
}

From source file:org.openmrs.module.restrictbyuser.SerializedObjectEditor.java

public void setAsText(String text) throws IllegalArgumentException {
    if (StringUtils.hasText(text)) {
        RestrictByUserService service = Context.getService(RestrictByUserService.class);
        try {//from w w  w .ja v  a 2s.c o m
            SerializedObject object = service.getSerializedObject(Integer.valueOf(text));
            setValue(object);
        } catch (Exception ex) {
            SerializedObject object = service.getSerializedObjectByUuid(text);
            setValue(object);
            if (object == null) {
                log.error("Error setting text: " + text, ex);
                throw new IllegalArgumentException("SerializedObject not found: " + ex.getMessage());
            }
        }
    } else {
        setValue(null);
    }
}