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:nl.surfnet.coin.shared.log.ApiCallLogContextListener.java

@Override
public void requestInitialized(ServletRequestEvent requestEvent) {
    ApiCallLog apiCallLog = new ApiCallLog();
    HttpServletRequest request = (HttpServletRequest) requestEvent.getServletRequest();
    String queryString = request.getQueryString();
    StringBuffer requestURL = request.getRequestURL();
    if (StringUtils.hasText(queryString)) {
        requestURL.append("?").append(queryString);
    }/*from  ww  w.ja va 2s  .  co  m*/
    try {
        apiCallLog.setResourceUrl(URLEncoder.encode(requestURL.toString(), "utf-8"));
        apiCallLog.setIpAddress(request.getRemoteAddr());
    } catch (UnsupportedEncodingException e) {
        // will never happen as utf-8 is the encoding
    }
    apiCallLogHolder.set(apiCallLog);
}

From source file:com.mtgi.analytics.aop.config.v11.BtJdbcPersisterBeanDefinitionParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

    //configure ID generator settings
    NodeList children = element.getElementsByTagNameNS("*", ELT_ID_SQL);
    if (children.getLength() == 1) {
        BeanDefinition def = builder.getRawBeanDefinition();
        MutablePropertyValues props = def.getPropertyValues();

        Element child = (Element) children.item(0);
        String sql = child.getTextContent();
        if (StringUtils.hasText(sql))
            props.addPropertyValue("idSql", sql);

        if (child.hasAttribute(ATT_INCREMENT))
            props.addPropertyValue("idIncrement", child.getAttribute(ATT_INCREMENT));
    }//from w  w w  .  ja v a2  s  . c o m

    //configure nested dataSource
    NodeList nodes = element.getElementsByTagNameNS("*", "data-source");
    if (nodes.getLength() == 1) {
        Element ds = (Element) nodes.item(0);
        ds.setAttribute("name", "dataSource");
        parserContext.getDelegate().parsePropertyElement(ds, builder.getRawBeanDefinition());
    }

    //push persister into parent manager bean, if applicable
    if (parserContext.isNested()) {
        AbstractBeanDefinition def = builder.getBeanDefinition();
        String id = element.hasAttribute("id") ? element.getAttribute("id")
                : BeanDefinitionReaderUtils.generateBeanName(def,
                        parserContext.getReaderContext().getRegistry(), true);
        BeanDefinitionHolder holder = new BeanDefinitionHolder(def, id);
        BtManagerBeanDefinitionParser.registerNestedBean(holder, "persister", parserContext);
    }
}

From source file:org.springmodules.validation.bean.conf.loader.xml.handler.RangeRuleElementHandler.java

protected AbstractValidationRule createValidationRule(Element element) {

    String minText = element.getAttribute(MIN_ATTR);
    String maxText = element.getAttribute(MAX_ATTR);

    BigDecimal min = (StringUtils.hasText(minText)) ? new BigDecimal(minText) : null;
    BigDecimal max = (StringUtils.hasText(maxText)) ? new BigDecimal(maxText) : null;

    if (min != null && max != null) {
        return new RangeValidationRule(min, max);
    }/*  w  ww  .  jav a 2s. c o  m*/

    if (min != null) {
        return new MinValidationRule(min);
    }

    if (max != null) {
        return new MaxValidationRule(max);
    }

    throw new ValidationConfigurationException(
            "Element '" + ELEMENT_NAME + "' must have either 'min' attribute, 'max' attribute, or both");
}

From source file:com.trigonic.utils.spring.beans.ImportBeanDefinitionParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    XmlReaderContext readerContext = parserContext.getReaderContext();
    String primaryLocation = element.getAttribute(RESOURCE_ATTRIBUTE);
    if (!StringUtils.hasText(primaryLocation)) {
        readerContext.error("Resource location must not be empty", element);
        return null;
    }/*from  ww  w . ja v a 2s .com*/

    String alternateLocation = element.getAttribute(ALTERNATE_ATTRIBUTE);
    boolean optional = Boolean.parseBoolean(element.getAttribute(OPTIONAL_ATTRIBUTE));

    String currentLocation = primaryLocation;
    try {
        Set<Resource> actualResources = ImportHelper.importResource(readerContext.getReader(),
                readerContext.getResource(), currentLocation);

        if (actualResources.isEmpty() && StringUtils.hasLength(alternateLocation)) {
            currentLocation = alternateLocation;
            actualResources = ImportHelper.importResource(readerContext.getReader(),
                    readerContext.getResource(), currentLocation);
        }

        if (actualResources.isEmpty() && !optional) {
            readerContext.error("Primary location [" + primaryLocation + "]"
                    + (alternateLocation == null ? "" : " and alternate location [" + alternateLocation + "]")
                    + " are not optional", element);
            return null;
        }

        Resource[] actResArray = actualResources.toArray(new Resource[actualResources.size()]);
        readerContext.fireImportProcessed(primaryLocation, actResArray, readerContext.extractSource(element));
    } catch (BeanDefinitionStoreException ex) {
        readerContext.error("Failed to import bean definitions from location [" + currentLocation + "]",
                element, ex);
    }

    return null;
}

From source file:ch.sdi.plugins.oxwall.profile.OxProfileQuestionString.java

/**
 * @see ch.sdi.plugins.oxwall.profile.OxProfileQuestion#hasValue(ch.sdi.core.impl.data.Person)
 *//*  w w w.jav  a2 s.  c  o  m*/
@Override
public boolean hasValue(Person<?> aPerson) throws SdiException {
    return StringUtils.hasText(aPerson.getStringProperty(myPersonKey));
}

From source file:io.jmnarloch.spring.cloud.zuul.route.MatcherProxyRouteLocator.java

/**
 * {@inheritDoc}//  w ww . java 2s  . c  o  m
 */
@Override
public ProxyRouteSpec getMatchingRoute(String path) {

    if (StringUtils.hasText(this.servletPath) && !this.servletPath.equals("/")
            && path.startsWith(this.servletPath)) {
        path = path.substring(this.servletPath.length());
    }

    return toProxyRouteSpec(path, routeMatcher.getMatchingRoute(path));
}

From source file:io.cloudslang.schema.BeanRegistrator.java

public BeanRegistrator addDependsOn(String... beanNames) {
    if (beanNames != null) {
        for (String beanName : beanNames) {
            if (StringUtils.hasText(beanName))
                builder.addDependsOn(beanName.trim());
        }/*w  ww  .j  a v  a2  s. com*/
    }
    return this;
}

From source file:com.brienwheeler.svc.users.validation.EmailAddressNotExistValidator.java

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
    if (!StringUtils.hasText(value))
        return !constraintAnnotation.failOnEmpty();

    if (!EmailAddress.isValid(value))
        return true; // invalid email addresses don't exist in the system

    IUserEmailAddressService userEmailAddressService = applicationContext
            .getBean(constraintAnnotation.userEmailAddressService(), IUserEmailAddressService.class);
    return userEmailAddressService.findByEmailAddress(new EmailAddress(value)) == null;
}

From source file:org.jmxtrans.embedded.spring.EmbeddedJmxTransBeanDefinitionParser.java

@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) {
    String id = element.getAttribute(ID_ATTRIBUTE);
    return (StringUtils.hasText(id) ? id : "jmxtrans");
}

From source file:org.terasoluna.gfw.functionaltest.app.DBLogProvider.java

public long countContainsByRegexExceptionMessage(String xTrack, String loggerNamePattern, String messagePattern,
        String exceptionMessagePattern) {

    StringBuilder sql = new StringBuilder();
    StringBuilder where = new StringBuilder();
    sql.append("SELECT COUNT(e.*) FROM logging_event e");
    where.append(" WHERE e.formatted_message REGEXP :message");

    sql.append(" JOIN logging_event_exception ee ON ee.event_id = e.event_id");
    where.append(" AND ee.I = '0' AND ee.TRACE_LINE REGEXP :exceptionMessage");

    if (StringUtils.hasText(xTrack)) {
        sql.append(" JOIN logging_event_property ep ON ep.event_id = e.event_id");
        where.append(" AND ep.mapped_key = 'X-Track' AND ep.mapped_value = :xTrack");
    }/*from  ww w . ja va2s. c om*/
    if (StringUtils.hasText(loggerNamePattern)) {
        where.append(" AND e.logger_name REGEXP :loggerName");
    }
    sql.append(where);

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("xTrack", xTrack);
    params.addValue("loggerName", loggerNamePattern);
    params.addValue("message", messagePattern);
    params.addValue("exceptionMessage", exceptionMessagePattern);
    Long count = jdbcOperations.queryForObject(sql.toString(), params, Long.class);
    return count;
}