Example usage for org.springframework.util StringUtils hasLength

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

Introduction

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

Prototype

public static boolean hasLength(@Nullable String str) 

Source Link

Document

Check that the given String is neither null nor of length 0.

Usage

From source file:net.neurowork.cenatic.centraldir.workers.XMLRestWorker.java

private FormaJuridica findFormaJuridica(String orgTypeCode, String formaJuridica) {
    if (!StringUtils.hasLength(orgTypeCode))
        return null;

    Integer id = getId(orgTypeCode);
    FormaJuridica ret = null;/*from ww w.  j ava  2  s  .c  o m*/
    List<FormaJuridica> l = null;
    try {
        l = formaJuridicaService.findByName(formaJuridica);
    } catch (ServiceException e) {
        logger.error(e.getMessage());
    }
    if (l != null && l.size() > 0) {
        ret = l.get(0);
    } else {
        ret = findRestFormaJuridica(id);
    }
    return ret;
}

From source file:net.neurowork.cenatic.centraldir.workers.XMLRestWorker.java

private Provincia findProvincia(String provId, String provincia) {
    if (!StringUtils.hasLength(provId))
        return null;

    try {/*from w ww  .  ja v  a2 s .c  o m*/
        return provinciaService.findProvincia(satelite, provincia, Integer.parseInt(provId));
    } catch (NumberFormatException e) {
        logger.error(e.getMessage());
    } catch (ServiceException e) {
        logger.error(e.getMessage());
    }
    return null;
}

From source file:net.neurowork.cenatic.centraldir.workers.XMLRestWorker.java

private ClasificacionOrganizacion findClasificacionOrganizacion(String orgClassCode,
        String organizationClasification) {
    if (!StringUtils.hasLength(orgClassCode))
        return null;

    Integer id = getId(orgClassCode);
    ClasificacionOrganizacion ret = null;
    List<ClasificacionOrganizacion> l = null;
    try {/*from  w ww  . j  a v a 2  s  .c o  m*/
        l = organizacionService.findClasificacionOrganizacionByName(organizationClasification);
    } catch (ServiceException e) {
        logger.error(e.getMessage());
    }
    if (l != null && l.size() > 0) {
        ret = l.get(0);
    } else {
        ret = findRestClasificacionOrganizacion(id);
    }
    return ret;
}

From source file:net.neurowork.cenatic.centraldir.workers.XMLRestWorker.java

private Capacidad importCapacidad(String xmlString, Integer capacityId)
        throws ParserConfigurationException, SAXException, IOException {
    Document doc = XmlParserUtil.createDocumentFromString(xmlString);
    Capacidad ret = null;/*from w ww .  ja  v a2s .com*/
    NodeList nodeLst = doc.getElementsByTagName("capacity");

    for (int s = 0; s < nodeLst.getLength(); s++) {
        Node fstNode = nodeLst.item(s);
        if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
            Element elPDU = (Element) fstNode;
            String code = XmlParserUtil.getAttribute(elPDU, "code");
            String category = XmlParserUtil.getAttribute(elPDU, "category");
            NodeList fstNm = elPDU.getChildNodes();
            String capacidadName = null;

            if (fstNm.getLength() > 0) {
                capacidadName = ((Node) fstNm.item(0)).getNodeValue();

                Integer capId = getId(code);
                Capacidad capacidad = null;
                try {
                    List<Capacidad> capacidades = organizacionService.findCapacidadByName(capacidadName);

                    if (capacidades != null && capacidades.size() > 0) {
                        capacidad = capacidades.get(0);
                    } else {
                        capacidad = new Capacidad();
                        capacidad.setName(capacidadName);
                        if (StringUtils.hasLength(category))
                            capacidad.setCategoria(category);
                        organizacionService.saveCapacidad(capacidad);
                    }

                    if (capId != null && capId.equals(capacityId)) {
                        ret = capacidad;
                    }
                } catch (ServiceException e) {
                    logger.error(e.getMessage());
                }
            }
        }
    }

    if (ret != null) {
        if (logger.isTraceEnabled())
            logger.trace("Se devuelve la Capacidad: " + ret);
        return ret;
    }
    if (logger.isTraceEnabled())
        logger.trace("No se ha encontrado la Capacidad con Id: " + capacityId);
    return null;
}

From source file:net.yasion.common.core.bean.wrapper.CachedIntrospectionResults.java

public PropertyDescriptor getPropertyDescriptor(String name) {
    PropertyDescriptor pd = this.propertyDescriptorCache.get(name);
    if (pd == null && StringUtils.hasLength(name)) {
        // Same lenient fallback checking as in PropertyTypeDescriptor...
        pd = this.propertyDescriptorCache.get(name.substring(0, 1).toLowerCase() + name.substring(1));
        if (pd == null) {
            pd = this.propertyDescriptorCache.get(name.substring(0, 1).toUpperCase() + name.substring(1));
        }/*  w w w. ja  v a2s.c  o  m*/
    }
    return (pd == null || pd instanceof GenericTypeAwarePropertyDescriptor ? pd
            : buildGenericTypeAwarePropertyDescriptor(getBeanClass(), pd));
}

From source file:org.acegisecurity.providers.ldap.LdapAuthenticationProvider.java

protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)
        throws AuthenticationException {
    if (!StringUtils.hasLength(username)) {
        throw new BadCredentialsException(
                messages.getMessage("LdapAuthenticationProvider.emptyUsername", "Empty Username"));
    }/*from w ww  . java  2s  . c  om*/

    if (logger.isDebugEnabled()) {
        logger.debug("Retrieving user " + username);
    }

    String password = (String) authentication.getCredentials();
    Assert.notNull(password, "Null password was supplied in authentication token");

    if (password.length() == 0) {
        logger.debug("Rejecting empty password for user " + username);
        throw new BadCredentialsException(
                messages.getMessage("LdapAuthenticationProvider.emptyPassword", "Empty Password"));
    }

    try {
        LdapUserDetails ldapUser = getAuthenticator().authenticate(username, password);

        return createUserDetails(ldapUser, username, password);

    } catch (DataAccessException ldapAccessFailure) {
        throw new AuthenticationServiceException(ldapAccessFailure.getMessage(), ldapAccessFailure);
    }
}

From source file:org.acegisecurity.ui.rememberme.TokenBasedRememberMeServices.java

public void loginSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication successfulAuthentication) {
    // Exit if the principal hasn't asked to be remembered
    if (!rememberMeRequested(request, parameter)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Did not send remember-me cookie (principal did not set parameter '" + this.parameter
                    + "')");
        }//from   w w  w  . j av a2 s  .c o  m

        return;
    }

    // Determine username and password, ensuring empty strings
    Assert.notNull(successfulAuthentication.getPrincipal());
    Assert.notNull(successfulAuthentication.getCredentials());

    String username = retrieveUserName(successfulAuthentication);
    String password = retrievePassword(successfulAuthentication);

    // If unable to find a username and password, just abort as
    // TokenBasedRememberMeServices unable to construct a valid token in
    // this case
    if (!StringUtils.hasLength(username) || !StringUtils.hasLength(password)) {
        return;
    }

    long expiryTime = System.currentTimeMillis() + (tokenValiditySeconds * 1000);

    // construct token to put in cookie; format is:
    // username + ":" + expiryTime + ":" + Md5Hex(username + ":" +
    // expiryTime + ":" + password + ":" + key)
    String signatureValue = DigestUtils.md5Hex(username + ":" + expiryTime + ":" + password + ":" + key);
    String tokenValue = username + ":" + expiryTime + ":" + signatureValue;
    String tokenValueBase64 = new String(Base64.encodeBase64(tokenValue.getBytes()));
    response.addCookie(makeValidCookie(tokenValueBase64, request, tokenValiditySeconds));

    if (logger.isDebugEnabled()) {
        logger.debug(
                "Added remember-me cookie for user '" + username + "', expiry: '" + new Date(expiryTime) + "'");
    }
}

From source file:org.acegisecurity.ui.rememberme.TokenBasedRememberMeServices.java

protected Cookie makeCancelCookie(HttpServletRequest request) {
    Cookie cookie = new Cookie(cookieName, null);
    cookie.setMaxAge(0);/* w  ww . j  av  a 2 s  .  c o  m*/
    cookie.setPath(StringUtils.hasLength(request.getContextPath()) ? request.getContextPath() : "/");

    return cookie;
}

From source file:org.acegisecurity.ui.rememberme.TokenBasedRememberMeServices.java

protected Cookie makeValidCookie(String tokenValueBase64, HttpServletRequest request, long maxAge) {
    Cookie cookie = new Cookie(cookieName, tokenValueBase64);
    cookie.setMaxAge(new Long(maxAge).intValue());
    cookie.setPath(StringUtils.hasLength(request.getContextPath()) ? request.getContextPath() : "/");

    return cookie;
}

From source file:org.apache.dubbo.config.spring.beans.factory.annotation.CompatibleReferenceAnnotationBeanPostProcessor.java

private InjectionMetadata findReferenceMetadata(String beanName, Class<?> clazz, PropertyValues pvs) {
    // Fall back to class name as cache key, for backwards compatibility with custom callers.
    String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
    // Quick check on the concurrent map first, with minimal locking.
    ReferenceInjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
    if (InjectionMetadata.needsRefresh(metadata, clazz)) {
        synchronized (this.injectionMetadataCache) {
            metadata = this.injectionMetadataCache.get(cacheKey);
            if (InjectionMetadata.needsRefresh(metadata, clazz)) {
                if (metadata != null) {
                    metadata.clear(pvs);
                }/*from   w  ww . j a v a 2s.  c o  m*/
                try {
                    metadata = buildReferenceMetadata(clazz);
                    this.injectionMetadataCache.put(cacheKey, metadata);
                } catch (NoClassDefFoundError err) {
                    throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName()
                            + "] for reference metadata: could not find class that it depends on", err);
                }
            }
        }
    }
    return metadata;
}