Java Code Examples for org.springframework.util.StringUtils#hasLength()
The following examples show how to use
org.springframework.util.StringUtils#hasLength() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChannelController.java From app-version with Apache License 2.0 | 6 votes |
@ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户登录凭证", paramType = "header", dataType = "string", defaultValue = "Bearer ", required = true), }) @GetMapping public ServiceResult list(@RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "10") int pageSize, @RequestParam(required = false, defaultValue = "") String channelName, @RequestParam(required = false, defaultValue = "") String channelCode, @RequestParam(required = false, defaultValue = "") Integer channelStatus) { EntityWrapper<Channel> wrapper = new EntityWrapper<>(); wrapper.and().eq("app_id", ThreadLocalUtils.USER_THREAD_LOCAL.get().getAppId()); if (StringUtils.hasLength(channelName)) { wrapper.and().like("channel_name", "%" + channelName + "%"); } if (StringUtils.hasLength(channelCode)) { wrapper.and().like("channel_code", "%" + channelCode + "%"); } if (channelStatus != null && (channelStatus == 1 || channelStatus == 2 || channelStatus == 3)) { wrapper.and().eq("channel_status", channelStatus); } wrapper.and().eq("del_flag",0); wrapper.orderBy("created_time", false); return channelService.list(page, pageSize, wrapper); }
Example 2
Source File: PetValidator.java From amazon-ecs-java-microservices with Apache License 2.0 | 6 votes |
@Override public void validate(Object obj, Errors errors) { Pet pet = (Pet) obj; String name = pet.getName(); // name validation if (!StringUtils.hasLength(name)) { errors.rejectValue("name", REQUIRED, REQUIRED); } // type validation if (pet.isNew() && pet.getType() == null) { errors.rejectValue("type", REQUIRED, REQUIRED); } // birth date validation if (pet.getBirthDate() == null) { errors.rejectValue("birthDate", REQUIRED, REQUIRED); } }
Example 3
Source File: MessageHeaderAccessor.java From java-technology-stack with MIT License | 6 votes |
/** * Removes all headers provided via array of 'headerPatterns'. * <p>As the name suggests, array may contain simple matching patterns for header * names. Supported pattern styles are: "xxx*", "*xxx", "*xxx*" and "xxx*yyy". */ public void removeHeaders(String... headerPatterns) { List<String> headersToRemove = new ArrayList<>(); for (String pattern : headerPatterns) { if (StringUtils.hasLength(pattern)){ if (pattern.contains("*")){ headersToRemove.addAll(getMatchingHeaderNames(pattern, this.headers)); } else { headersToRemove.add(pattern); } } } for (String headerToRemove : headersToRemove) { removeHeader(headerToRemove); } }
Example 4
Source File: AndroidVersionServiceTest.java From app-version with Apache License 2.0 | 6 votes |
@Test public void list() throws Exception { String appVersion = ""; Integer updateType = null; Integer versionStatus = null; ExtWrapper<AndroidVersion> wrapper = new ExtWrapper<>(); wrapper.and().eq("app_id", ThreadLocalUtils.USER_THREAD_LOCAL.get().getAppId()); wrapper.and().eq("del_flag", 0); wrapper.setVersionSort("app_version", false); if (StringUtils.hasLength(appVersion)) { wrapper.and().like("app_version", "%" + appVersion + "%"); } if (updateType != null) { wrapper.and().eq("update_type", updateType); } if (versionStatus != null) { wrapper.and().eq("version_status", versionStatus); } ServiceResult result = androidVersionService.list(1, 1, wrapper); if (result.getData() != null) { logger.info(result.getData().toString()); } }
Example 5
Source File: AbstractServerHttpRequest.java From spring-analysis-note with MIT License | 6 votes |
/** * A method for parsing of the query into name-value pairs. The return * value is turned into an immutable map and cached. * <p>Note that this method is invoked lazily on first access to * {@link #getQueryParams()}. The invocation is not synchronized but the * parsing is thread-safe nevertheless. */ protected MultiValueMap<String, String> initQueryParams() { MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>(); String query = getURI().getRawQuery(); if (query != null) { Matcher matcher = QUERY_PATTERN.matcher(query); while (matcher.find()) { String name = decodeQueryParam(matcher.group(1)); String eq = matcher.group(2); String value = matcher.group(3); value = (value != null ? decodeQueryParam(value) : (StringUtils.hasLength(eq) ? "" : null)); queryParams.add(name, value); } } return queryParams; }
Example 6
Source File: HttpRequestConfigTokenProvider.java From spring-cloud-config with Apache License 2.0 | 6 votes |
@Override public String getToken() { HttpServletRequest request = httpRequest.getIfAvailable(); if (request == null) { throw new IllegalStateException("No HttpServletRequest available"); } String token = request.getHeader(ConfigClientProperties.TOKEN_HEADER); if (!StringUtils.hasLength(token)) { throw new IllegalArgumentException( "Missing required header in HttpServletRequest: " + ConfigClientProperties.TOKEN_HEADER); } return token; }
Example 7
Source File: AdminServiceTest.java From app-version with Apache License 2.0 | 5 votes |
@Test public void listApp() throws Exception { String appName = "syl"; EntityWrapper<App> wrapper = new EntityWrapper<>(); wrapper.and().eq("del_flag", 0); if (StringUtils.hasLength(appName)) { wrapper.andNew().like("app_name", "%" + appName + "%"); } ServiceResult result = adminService.listApp(1, 10, wrapper); if (result.getData() != null) { logger.info(result.getData().toString()); } }
Example 8
Source File: CloudbreakTestSuiteInitializer.java From cloudbreak with Apache License 2.0 | 5 votes |
private void putStackToContextIfExist(StackV4Endpoint endpoint, Long workspaceId, String stackName) { if (StringUtils.hasLength(stackName)) { Long resourceId = endpoint.getStatusByName(workspaceId, stackName).getId(); itContext.putContextParam(CloudbreakITContextConstants.STACK_ID, resourceId.toString()); itContext.putContextParam(STACK_NAME, stackName); } }
Example 9
Source File: InternalSpelExpressionParser.java From lams with GNU General Public License v2.0 | 5 votes |
private boolean isValidQualifiedId(Token node) { if (node == null || node.kind == TokenKind.LITERAL_STRING) { return false; } if (node.kind == TokenKind.DOT || node.kind == TokenKind.IDENTIFIER) { return true; } String value = node.stringValue(); return (StringUtils.hasLength(value) && VALID_QUALIFIED_ID_PATTERN.matcher(value).matches()); }
Example 10
Source File: MockHttpServletRequest.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void updateContentTypeHeader() { if (StringUtils.hasLength(this.contentType)) { StringBuilder sb = new StringBuilder(this.contentType); if (!this.contentType.toLowerCase().contains(CHARSET_PREFIX) && StringUtils.hasLength(this.characterEncoding)) { sb.append(";").append(CHARSET_PREFIX).append(this.characterEncoding); } doAddHeaderValue(CONTENT_TYPE_HEADER, sb.toString(), true); } }
Example 11
Source File: CustomBeanNameGenerator.java From unitime with Apache License 2.0 | 5 votes |
@Override protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) { AnnotationMetadata amd = annotatedDef.getMetadata(); Set<String> types = amd.getAnnotationTypes(); String beanName = null; for (String type : types) { Map<String, Object> attributes = amd.getAnnotationAttributes(type); if (isStereotypeWithNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) { String value = null; if (PermissionForRight.class.getName().equals(type)) { Right right = (Right)attributes.get("value"); value = "permission" + right.name(); } else if (GwtRpcImplements.class.getName().equals(type)) { Class<?> requestClass = (Class<?>)attributes.get("value"); value = requestClass.getName(); } else if (GwtRpcLogging.class.getName().equals(type)) { continue; } else { value = (String) attributes.get("value"); } if (StringUtils.hasLength(value)) { if (beanName != null && !value.equals(beanName)) { throw new IllegalStateException("Stereotype annotations suggest inconsistent " + "component names: '" + beanName + "' versus '" + value + "'"); } beanName = value; } } } return beanName; }
Example 12
Source File: ApolloLdapAuthenticationProvider.java From apollo with Apache License 2.0 | 5 votes |
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication, this.messages .getMessage("LdapAuthenticationProvider.onlySupports", "Only UsernamePasswordAuthenticationToken is supported")); UsernamePasswordAuthenticationToken userToken = (UsernamePasswordAuthenticationToken) authentication; String username = userToken.getName(); String password = (String) authentication.getCredentials(); if (this.logger.isDebugEnabled()) { this.logger.debug("Processing authentication request for user: " + username); } if (!StringUtils.hasLength(username)) { throw new BadCredentialsException( this.messages.getMessage("LdapAuthenticationProvider.emptyUsername", "Empty Username")); } if (!StringUtils.hasLength(password)) { throw new BadCredentialsException(this.messages .getMessage("AbstractLdapAuthenticationProvider.emptyPassword", "Empty Password")); } Assert.notNull(password, "Null password was supplied in authentication token"); DirContextOperations userData = this.doAuthentication(userToken); String loginId = userData.getStringAttribute(properties.getMapping().getLoginId()); UserDetails user = this.userDetailsContextMapper.mapUserFromContext(userData, loginId, this.loadUserAuthorities(userData, loginId, (String) authentication.getCredentials())); return this.createSuccessfulAuthentication(userToken, user); }
Example 13
Source File: UtilEncryptorBeanDefinitionParser.java From jasypt with Apache License 2.0 | 5 votes |
@Override protected void doParse(final Element element, final BeanDefinitionBuilder builder) { processStringAttribute(element, builder, PARAM_PASSWORD, "password"); String scope = element.getAttribute(SCOPE_ATTRIBUTE); if (StringUtils.hasLength(scope)) { builder.setScope(scope); } }
Example 14
Source File: RequestParamMethodArgumentResolver.java From spring-analysis-note with MIT License | 5 votes |
@Override public void contributeMethodArgument(MethodParameter parameter, @Nullable Object value, UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) { Class<?> paramType = parameter.getNestedParameterType(); if (Map.class.isAssignableFrom(paramType) || MultipartFile.class == paramType || Part.class == paramType) { return; } RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class); String name = (requestParam != null && StringUtils.hasLength(requestParam.name()) ? requestParam.name() : parameter.getParameterName()); Assert.state(name != null, "Unresolvable parameter name"); parameter = parameter.nestedIfOptional(); if (value instanceof Optional) { value = ((Optional<?>) value).orElse(null); } if (value == null) { if (requestParam != null && (!requestParam.required() || !requestParam.defaultValue().equals(ValueConstants.DEFAULT_NONE))) { return; } builder.queryParam(name); } else if (value instanceof Collection) { for (Object element : (Collection<?>) value) { element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element); builder.queryParam(name, element); } } else { builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value)); } }
Example 15
Source File: JmxUtils.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Attempt to find a locally running {@code MBeanServer}. Fails if no * {@code MBeanServer} can be found. Logs a warning if more than one * {@code MBeanServer} found, returning the first one from the list. * @param agentId the agent identifier of the MBeanServer to retrieve. * If this parameter is {@code null}, all registered MBeanServers are considered. * If the empty String is given, the platform MBeanServer will be returned. * @return the {@code MBeanServer} if found * @throws org.springframework.jmx.MBeanServerNotFoundException * if no {@code MBeanServer} could be found * @see javax.management.MBeanServerFactory#findMBeanServer(String) */ public static MBeanServer locateMBeanServer(String agentId) throws MBeanServerNotFoundException { MBeanServer server = null; // null means any registered server, but "" specifically means the platform server if (!"".equals(agentId)) { List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(agentId); if (servers != null && servers.size() > 0) { // Check to see if an MBeanServer is registered. if (servers.size() > 1 && logger.isWarnEnabled()) { logger.warn("Found more than one MBeanServer instance" + (agentId != null ? " with agent id [" + agentId + "]" : "") + ". Returning first from list."); } server = servers.get(0); } } if (server == null && !StringUtils.hasLength(agentId)) { // Attempt to load the PlatformMBeanServer. try { server = ManagementFactory.getPlatformMBeanServer(); } catch (SecurityException ex) { throw new MBeanServerNotFoundException("No specific MBeanServer found, " + "and not allowed to obtain the Java platform MBeanServer", ex); } } if (server == null) { throw new MBeanServerNotFoundException( "Unable to locate an MBeanServer instance" + (agentId != null ? " with agent id [" + agentId + "]" : "")); } if (logger.isDebugEnabled()) { logger.debug("Found MBeanServer: " + server); } return server; }
Example 16
Source File: HttpHeaders.java From spring-analysis-note with MIT License | 4 votes |
/** * Return the {@linkplain MediaType media type} of the body, as specified * by the {@code Content-Type} header. * <p>Returns {@code null} when the content-type is unknown. */ @Nullable public MediaType getContentType() { String value = getFirst(CONTENT_TYPE); return (StringUtils.hasLength(value) ? MediaType.parseMediaType(value) : null); }
Example 17
Source File: BeanDefinitionParserDelegate.java From spring-analysis-note with MIT License | 4 votes |
public boolean isDefaultNamespace(@Nullable String namespaceUri) { return (!StringUtils.hasLength(namespaceUri) || BEANS_NAMESPACE_URI.equals(namespaceUri)); }
Example 18
Source File: StringToUUIDConverter.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public UUID convert(String source) { return (StringUtils.hasLength(source) ? UUID.fromString(source.trim()) : null); }
Example 19
Source File: EncryptorConfigBeanDefinitionParser.java From jasypt with Apache License 2.0 | 4 votes |
@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"); processBeanAttribute(element, builder, PARAM_IV_GENERATOR_BEAN, "ivGenerator"); processStringAttribute(element, builder, PARAM_IV_GENERATOR_CLASS_NAME, "ivGeneratorClassName"); 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_IV_GENERATOR_CLASS_NAME_ENV_NAME, "ivGeneratorClassNameEnvName"); 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_IV_GENERATOR_CLASS_NAME_SYS_PROPERTY_NAME, "ivGeneratorClassNameSysPropertyName"); 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); } }
Example 20
Source File: AbstractBeanFactory.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Return a RootBeanDefinition for the given bean, by merging with the * parent if the given bean's definition is a child bean definition. * @param beanName the name of the bean definition * @param bd the original bean definition (Root/ChildBeanDefinition) * @param containingBd the containing bean definition in case of inner bean, * or {@code null} in case of a top-level bean * @return a (potentially merged) RootBeanDefinition for the given bean * @throws BeanDefinitionStoreException in case of an invalid bean definition */ protected RootBeanDefinition getMergedBeanDefinition( String beanName, BeanDefinition bd, BeanDefinition containingBd) throws BeanDefinitionStoreException { synchronized (this.mergedBeanDefinitions) { RootBeanDefinition mbd = null; // Check with full lock now in order to enforce the same merged instance. if (containingBd == null) { mbd = this.mergedBeanDefinitions.get(beanName); } if (mbd == null) { if (bd.getParentName() == null) { // Use copy of given root bean definition. if (bd instanceof RootBeanDefinition) { mbd = ((RootBeanDefinition) bd).cloneBeanDefinition(); } else { mbd = new RootBeanDefinition(bd); } } else { // Child bean definition: needs to be merged with parent. BeanDefinition pbd; try { String parentBeanName = transformedBeanName(bd.getParentName()); if (!beanName.equals(parentBeanName)) { pbd = getMergedBeanDefinition(parentBeanName); } else { BeanFactory parent = getParentBeanFactory(); if (parent instanceof ConfigurableBeanFactory) { pbd = ((ConfigurableBeanFactory) parent).getMergedBeanDefinition(parentBeanName); } else { throw new NoSuchBeanDefinitionException(parentBeanName, "Parent name '" + parentBeanName + "' is equal to bean name '" + beanName + "': cannot be resolved without an AbstractBeanFactory parent"); } } } catch (NoSuchBeanDefinitionException ex) { throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanName, "Could not resolve parent bean definition '" + bd.getParentName() + "'", ex); } // Deep copy with overridden values. mbd = new RootBeanDefinition(pbd); mbd.overrideFrom(bd); } // Set default singleton scope, if not configured before. if (!StringUtils.hasLength(mbd.getScope())) { mbd.setScope(RootBeanDefinition.SCOPE_SINGLETON); } // A bean contained in a non-singleton bean cannot be a singleton itself. // Let's correct this on the fly here, since this might be the result of // parent-child merging for the outer bean, in which case the original inner bean // definition will not have inherited the merged outer bean's singleton status. if (containingBd != null && !containingBd.isSingleton() && mbd.isSingleton()) { mbd.setScope(containingBd.getScope()); } // Cache the merged bean definition for the time being // (it might still get re-merged later on in order to pick up metadata changes) if (containingBd == null && isCacheBeanMetadata()) { this.mergedBeanDefinitions.put(beanName, mbd); } } return mbd; } }