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:org.terasoluna.gfw.web.message.MessagesPanelTag.java

/**
 * appends panelTypeClassPrefix to className if necessary
 * @param className className built by StringBuilder
 * @param type classType//  w  w  w  .  j  av  a 2s  .c  o m
 */
private void appendPanelTypeClassPrefix(StringBuilder className, String type) {
    if (panelTypeClassPrefix != null && StringUtils.hasText(type)) {

        if (StringUtils.hasLength(className)) {
            className.append(" ");
        }
        className.append(panelTypeClassPrefix);
    }
}

From source file:com.taobao.diamond.server.controller.BaseStoneController.java

@RequestMapping(params = "method=updateConfig", method = RequestMethod.POST)
public String updateConfig(HttpServletRequest request, HttpServletResponse response,
        @RequestParam("dataId") String dataId, @RequestParam("group") String group,
        @RequestParam("content") String content) {
    response.setCharacterEncoding("GBK");

    String remoteIp = getRemoteIp(request);

    boolean checkSuccess = true;
    String errorMessage = "";
    if (!StringUtils.hasLength(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) {
        checkSuccess = false;//w w  w.j a  va 2 s. com
        errorMessage = "DataId";
    }
    if (!StringUtils.hasLength(group) || DiamondUtils.hasInvalidChar(group.trim())) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!StringUtils.hasLength(content)) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!checkSuccess) {
        try {
            response.sendError(INVALID_PARAM, errorMessage);
        } catch (IOException e) {
            log.error("response", e);
        }
        return "536";
    }

    // 
    this.updateConfigInfo(dataId, group, content);

    try {
        this.addIpToDataIdAndGroup(remoteIp, dataId, group);
    } catch (Exception e) {
        log.error("redis", e);
    }
    return "200";
}

From source file:com.sinet.gage.tasklets.DominFullImportTasklet.java

private Timestamp getDateWithISOFormat(String dateString) {
    Timestamp formattedDate = null;
    try {/*from  w w w . j ava2s  .  c om*/
        if (StringUtils.hasLength(dateString)) {
            formattedDate = new Timestamp(
                    dateTimeFormatter.withOffsetParsed().parseDateTime(dateString).getMillis());
        }
    } catch (Exception e) {
        logger.error("Invalid date format: " + e.getMessage());
    }
    return formattedDate;
}

From source file:com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.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.
    InjectionMetadata 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  va 2 s  . 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;
}

From source file:com.googlecode.ehcache.annotations.config.AnnotationDrivenEhCacheBeanDefinitionParser.java

/**
 * Setup the default cache resolver factory 
 * /* w  w  w  .  j  av  a 2  s.c  o  m*/
 * @return A reference to the default cache resolver factory.
 */
protected RuntimeBeanReference setupDefaultCacheResolverFactory(Element element, ParserContext parserContext,
        Object elementSource) {
    //If the default cache resolver factory was specified simply return a bean reference for that
    final String defaultCacheResolverFactoryName = element
            .getAttribute(XSD_ATTR__DEFAULT_CACHE_RESOLVER_FACTORY);
    if (StringUtils.hasLength(defaultCacheResolverFactoryName)) {
        return new RuntimeBeanReference(defaultCacheResolverFactoryName);
    }

    //Use no reference
    return null;
}

From source file:com.sinet.gage.tasklets.DominFullImportTasklet.java

private Date getDateFormat(String dateString) {
    Date formattedDate = null;/*from   w w  w.  ja  v  a 2s  . co m*/
    try {
        if (StringUtils.hasLength(dateString)) {
            formattedDate = new Date(dateFormat.parse(dateString).getTime());
        }
    } catch (ParseException e) {
        logger.error("Invalid date format: " + e.getMessage());
    }
    return formattedDate;
}

From source file:org.zilverline.core.AbstractCollection.java

/**
 * The URL maps the cacheDir to another location.
 * /* w  w w .  j a v a2  s. c o m*/
 * <p>
 * e.g. A document 'ldap.pdf' in cacheDir 'e:\collection\cache\books\' with
 * an cacheURL of 'http://search.company.com/cachedBooks/' will be returned
 * in a search result as
 * <code>http://search.company.com/cachedBooks/ldap.pdf</code>
 * </p>
 * 
 * @return the cacheUrl of the collection, or the cacheDir as URL if url is
 *         null or empty.
 */
public final String getCacheUrlWithManagerDefaults() {
    if (StringUtils.hasLength(cacheUrl)) {
        if (cacheUrl.endsWith("/")) {
            return cacheUrl;
        } else {
            return cacheUrl + "/";
        }
    } else {
        return "file://" + getCacheDirWithManagerDefaults().toURI().getPath();
    }
}

From source file:org.jasypt.spring31.xml.encryption.EncryptorConfigBeanDefinitionParser.java

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

    processStringAttribute(element, builder, PARAM_ALGORITHM, "algorithm");
    processIntegerAttribute(element, builder, PARAM_KEY_OBTENTION_ITERATIONS, "keyObtentionIterations");
    processStringAttribute(element, builder, PARAM_PASSWORD, "password");
    processIntegerAttribute(element, builder, PARAM_POOL_SIZE, "poolSize");
    processBeanAttribute(element, builder, PARAM_PROVIDER_BEAN, "provider");
    processStringAttribute(element, builder, PARAM_PROVIDER_CLASS_NAME, "providerClassName");
    processStringAttribute(element, builder, PARAM_PROVIDER_NAME, "providerName");
    processBeanAttribute(element, builder, PARAM_SALT_GENERATOR_BEAN, "saltGenerator");
    processStringAttribute(element, builder, PARAM_SALT_GENERATOR_CLASS_NAME, "saltGeneratorClassName");

    processStringAttribute(element, builder, PARAM_STRING_OUTPUT_TYPE, "stringOutputType");

    processStringAttribute(element, builder, PARAM_ALGORITHM_ENV_NAME, "algorithmEnvName");
    processStringAttribute(element, builder, PARAM_KEY_OBTENTION_ITERATIONS_ENV_NAME,
            "keyObtentionIterationsEnvName");
    processStringAttribute(element, builder, PARAM_PASSWORD_ENV_NAME, "passwordEnvName");
    processStringAttribute(element, builder, PARAM_POOL_SIZE_ENV_NAME, "poolSizeEnvName");
    processStringAttribute(element, builder, PARAM_PROVIDER_CLASS_NAME_ENV_NAME, "providerClassNameEnvName");
    processStringAttribute(element, builder, PARAM_PROVIDER_NAME_ENV_NAME, "providerNameEnvName");
    processStringAttribute(element, builder, PARAM_SALT_GENERATOR_CLASS_NAME_ENV_NAME,
            "saltGeneratorClassNameEnvName");
    processStringAttribute(element, builder, PARAM_ALGORITHM_SYS_PROPERTY_NAME, "algorithmSysPropertyName");
    processStringAttribute(element, builder, PARAM_KEY_OBTENTION_ITERATIONS_SYS_PROPERTY_NAME,
            "keyObtentionIterationsSysPropertyName");
    processStringAttribute(element, builder, PARAM_PASSWORD_SYS_PROPERTY_NAME, "passwordSysPropertyName");
    processStringAttribute(element, builder, PARAM_POOL_SIZE_SYS_PROPERTY_NAME, "poolSizeSysPropertyName");
    processStringAttribute(element, builder, PARAM_PROVIDER_CLASS_NAME_SYS_PROPERTY_NAME,
            "providerClassNameSysPropertyName");
    processStringAttribute(element, builder, PARAM_PROVIDER_NAME_SYS_PROPERTY_NAME,
            "providerNameSysPropertyName");
    processStringAttribute(element, builder, PARAM_SALT_GENERATOR_CLASS_NAME_SYS_PROPERTY_NAME,
            "saltGeneratorClassNameSysPropertyName");

    processStringAttribute(element, builder, PARAM_STRING_OUTPUT_TYPE_ENV_NAME, "stringOutputTypeEnvName");
    processStringAttribute(element, builder, PARAM_STRING_OUTPUT_TYPE_SYS_PROPERTY_NAME,
            "stringOutputTypeSysPropertyName");

    String scope = element.getAttribute(SCOPE_ATTRIBUTE);
    if (StringUtils.hasLength(scope)) {
        builder.setScope(scope);/*from  w ww  . jav  a 2s . co  m*/
    }

}

From source file:com.inspiresoftware.lib.dto.geda.interceptor.impl.TransferableUtils.java

private static void resolveConfigurationAfter(final Map<Occurrence, AdviceConfig> cfg, final String method,
        final Class[] args, final Class retArg, final Transferable ann) {
    if (args.length >= 1) {

        if (ann.after() == Direction.ENTITY_TO_DTO) {

            final boolean filtered = StringUtils.hasLength(ann.dtoFilterKey());

            if (filtered) {

                final boolean firstArgIsCollection = argIsCollection(args[0]);
                final boolean returnIsVoid = isReturnVoid(retArg);

                if (firstArgIsCollection || args.length >= 2) {
                    final boolean secondArgIsCollection = argIsCollection(args[1]);

                    if (firstArgIsCollection && secondArgIsCollection) {
                        // public void toDto(Class<DTO> dtoFilter, Collection<DTO> dto, Collection<Entity> blankCollection, ... )
                        assertKey(method, ann.dtoKey(), true);
                        addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(),
                                ann.dtoFilterKey(), ann.dtoKey(), "",
                                AdviceConfig.DTOSupportMode.ENTITIES_TO_DTOS_BY_FILTER, NO_INDEX, 0, 1,
                                NO_INDEX, ann.context());
                        return;
                    } else if (!firstArgIsCollection && !returnIsVoid) {
                        // public DTO toDto(Class<DTO> dtoFilter, Entity entity, ... )
                        assertKey(method, ann.dtoKey(), true);
                        addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(),
                                ann.dtoFilterKey(), ann.dtoKey(), "",
                                AdviceConfig.DTOSupportMode.ENTITY_TO_DTO_KEY_BY_FILTER, NO_INDEX, RETURN_INDEX,
                                0, NO_INDEX, ann.context());
                        return;

                    } else if (!firstArgIsCollection && !secondArgIsCollection) {
                        // public void toDto(Class<DTO> dtoFilter, DTO dto, Entity entity, ... )
                        addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(),
                                ann.dtoFilterKey(), "", "", AdviceConfig.DTOSupportMode.ENTITY_TO_DTO_BY_FILTER,
                                NO_INDEX, 0, 1, NO_INDEX, ann.context());
                        return;
                    }//from   w w w  . ja va 2 s. co  m
                } else if (args.length == 1 && !returnIsVoid) {
                    // public DTO toDto(Class<DTO> dtoFilter, Entity entity, ... )
                    assertKey(method, ann.dtoKey(), true);
                    addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(), ann.dtoFilterKey(),
                            ann.dtoKey(), "", AdviceConfig.DTOSupportMode.ENTITY_TO_DTO_KEY_BY_FILTER, NO_INDEX,
                            RETURN_INDEX, 0, NO_INDEX, ann.context());
                    return;
                }

            } else {

                final boolean firstArgIsCollection = argIsCollection(args[0]);
                final boolean returnIsVoid = isReturnVoid(retArg);

                if (firstArgIsCollection || args.length >= 2) {
                    final boolean secondArgIsCollection = argIsCollection(args[1]);

                    if (firstArgIsCollection && secondArgIsCollection) {
                        // public void toDto(Collection<DTO> dto, Collection<Entity> blankCollection, ... )
                        assertKey(method, ann.dtoKey(), true);
                        addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(), "", ann.dtoKey(),
                                "", AdviceConfig.DTOSupportMode.ENTITIES_TO_DTOS, NO_INDEX, 0, 1, NO_INDEX,
                                ann.context());
                        return;
                    } else if (!firstArgIsCollection && !returnIsVoid) {
                        // public DTO toDto(Entity entity, ... )
                        assertKey(method, ann.dtoKey(), true);
                        addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(), "", ann.dtoKey(),
                                "", AdviceConfig.DTOSupportMode.ENTITY_TO_DTO_KEY, NO_INDEX, RETURN_INDEX, 0,
                                NO_INDEX, ann.context());
                        return;

                    } else if (!firstArgIsCollection && !secondArgIsCollection) {
                        // public void toDto(DTO dto, Entity entity, ... )
                        addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(), "", "", "",
                                AdviceConfig.DTOSupportMode.ENTITY_TO_DTO, NO_INDEX, 0, 1, NO_INDEX,
                                ann.context());
                        return;
                    }
                } else if (args.length == 1 && !returnIsVoid) {
                    // public DTO toDto(Entity entity, ... )
                    assertKey(method, ann.dtoKey(), true);
                    addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(), "", ann.dtoKey(), "",
                            AdviceConfig.DTOSupportMode.ENTITY_TO_DTO_KEY, NO_INDEX, RETURN_INDEX, 0, NO_INDEX,
                            ann.context());
                    return;
                }

            }

        } else if (ann.after() == Direction.DTO_TO_ENTITY) {

            final boolean filtered = StringUtils.hasLength(ann.dtoFilterKey());
            final boolean returnIsVoid = isReturnVoid(retArg);

            if (filtered) {

                final boolean firstArgIsCollection = argIsCollection(args[0]);

                if (firstArgIsCollection || args.length >= 2) {
                    final boolean secondArgIsCollection = argIsCollection(args[1]);

                    if (firstArgIsCollection && secondArgIsCollection) {
                        // public void toEntity(Class<DTO> dtoFilter, Collection<DTO> dto, Collection<Entity> blankCollection, ... )
                        assertKey(method, ann.entityKey(), false);
                        addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(),
                                ann.dtoFilterKey(), "", ann.entityKey(),
                                AdviceConfig.DTOSupportMode.DTOS_TO_ENTITIES_BY_FILTER, 0, NO_INDEX, NO_INDEX,
                                1, ann.context());
                        return;

                    } else if (!firstArgIsCollection && !returnIsVoid) {
                        // public Entity toEntity(Class<DTO> dtoFilter, DTO dto, ... )
                        assertKey(method, ann.entityKey(), false);
                        addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(),
                                ann.dtoFilterKey(), "", ann.entityKey(),
                                AdviceConfig.DTOSupportMode.DTO_BY_FILTER_TO_ENTITY_KEY, 0, NO_INDEX, NO_INDEX,
                                RETURN_INDEX, ann.context());
                        return;

                    } else if (!firstArgIsCollection && !secondArgIsCollection) {
                        // public void toEntity(Class<DTO> dtoFilter, DTO dto, Entity entity, ... )
                        addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(),
                                ann.dtoFilterKey(), "", "", AdviceConfig.DTOSupportMode.DTO_BY_FILTER_TO_ENTITY,
                                0, NO_INDEX, NO_INDEX, 1, ann.context());
                        return;

                    }
                } else if (args.length == 1 && !returnIsVoid) {
                    // public Entity toEntity(Class<DTO> dtoFilter, DTO dto, ... )
                    assertKey(method, ann.entityKey(), false);
                    addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(), ann.dtoFilterKey(),
                            "", ann.entityKey(), AdviceConfig.DTOSupportMode.DTO_BY_FILTER_TO_ENTITY_KEY, 0,
                            NO_INDEX, NO_INDEX, RETURN_INDEX, ann.context());
                    return;
                }

            } else {

                final boolean firstArgIsCollection = argIsCollection(args[0]);

                if (firstArgIsCollection || args.length >= 2) {
                    final boolean secondArgIsCollection = argIsCollection(args[1]);

                    if (firstArgIsCollection && secondArgIsCollection) {
                        // public void toEntity(Collection<DTO> dto, Collection<Entity> blankCollection, ... )
                        assertKey(method, ann.entityKey(), false);
                        addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(), "", "",
                                ann.entityKey(), AdviceConfig.DTOSupportMode.DTOS_TO_ENTITIES, 0, NO_INDEX,
                                NO_INDEX, 1, ann.context());
                        return;

                    } else if (!firstArgIsCollection && !returnIsVoid) {
                        // public Entity toEntity(DTO dto, ... )
                        assertKey(method, ann.entityKey(), false);
                        addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(), "", "",
                                ann.entityKey(), AdviceConfig.DTOSupportMode.DTO_TO_ENTITY_KEY, 0, NO_INDEX,
                                NO_INDEX, RETURN_INDEX, ann.context());
                        return;

                    } else if (!firstArgIsCollection && !secondArgIsCollection) {
                        // public void toEntity(DTO dto, Entity entity, ... )
                        addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(), "", "", "",
                                AdviceConfig.DTOSupportMode.DTO_TO_ENTITY, 0, NO_INDEX, NO_INDEX, 1,
                                ann.context());
                        return;

                    }
                } else if (args.length == 1 && !returnIsVoid) {
                    // public Entity toEntity(DTO dto, ... )
                    assertKey(method, ann.entityKey(), false);
                    addConfiguration(cfg, Occurrence.AFTER_METHOD_INVOCATION, ann.after(), "", "",
                            ann.entityKey(), AdviceConfig.DTOSupportMode.DTO_TO_ENTITY_KEY, 0, NO_INDEX,
                            NO_INDEX, RETURN_INDEX, ann.context());
                    return;
                }

            }

        }

    }

    throw new UnsupportedOperationException("Unsupported configuration see @Transferable.");
}

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

/**
 * Extracts the validation rule error code from the given element. Expects a "code" attribute to indicate the
 * error code. If no such attribute exisits, returns <code>null</code>.
 *
 * @param element The element that represents the validation rule.
 * @return The validation rule error code.
 *//* w w w .j av  a2 s.c  o  m*/
protected String extractErrorCode(Element element) {
    String code = element.getAttribute(AbstractPropertyValidationElementHandler.ERROR_CODE_ATTR);
    return (StringUtils.hasLength(code)) ? code : null;
}