org.springframework.util.StringUtils#hasText ( )源码实例Demo

下面列出了org.springframework.util.StringUtils#hasText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

protected String[] getTargetDestinations(@Nullable Annotation annotation, Message<?> message, String defaultPrefix) {
	if (annotation != null) {
		String[] value = (String[]) AnnotationUtils.getValue(annotation);
		if (!ObjectUtils.isEmpty(value)) {
			return value;
		}
	}

	String name = DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER;
	String destination = (String) message.getHeaders().get(name);
	if (!StringUtils.hasText(destination)) {
		throw new IllegalStateException("No lookup destination header in " + message);
	}

	return (destination.startsWith("/") ?
			new String[] {defaultPrefix + destination} : new String[] {defaultPrefix + '/' + destination});
}
 
源代码2 项目: roncoo-jui-springboot   文件: SysMenuService.java
public Page<SysMenuVO> listForPage(int pageCurrent, int pageSize, SysMenuQO qo) {
	SysMenuExample example = new SysMenuExample();
	Criteria c = example.createCriteria();
	if (StringUtils.hasText(qo.getMenuName())) {
		c.andMenuNameEqualTo(qo.getMenuName());
	} else {
		c.andParentIdEqualTo(0L);
	}
	example.setOrderByClause(" sort desc, id desc ");
	Page<SysMenu> page = dao.listForPage(pageCurrent, pageSize, example);
	Page<SysMenuVO> p = PageUtil.transform(page, SysMenuVO.class);
	if (!StringUtils.hasText(qo.getMenuName())) {
		if (CollectionUtil.isNotEmpty(p.getList())) {
			for (SysMenuVO sm : p.getList()) {
				sm.setList(recursionList(sm.getId()));
			}
		}
	}
	return p;
}
 
源代码3 项目: spring-cloud-dataflow   文件: AboutController.java
private String getChecksum(String defaultValue, String url,
		String version) {
	String result = defaultValue;
	if (result == null && StringUtils.hasText(url)) {
		CloseableHttpClient httpClient = HttpClients.custom()
				.setSSLHostnameVerifier(new NoopHostnameVerifier())
				.build();
		HttpComponentsClientHttpRequestFactory requestFactory
				= new HttpComponentsClientHttpRequestFactory();
		requestFactory.setHttpClient(httpClient);
		url = constructUrl(url, version);
		try {
			ResponseEntity<String> response
					= new RestTemplate(requestFactory).exchange(
					url, HttpMethod.GET, null, String.class);
			if (response.getStatusCode().equals(HttpStatus.OK)) {
				result = response.getBody();
			}
		}
		catch (HttpClientErrorException httpException) {
			// no action necessary set result to undefined
			logger.debug("Didn't retrieve checksum because", httpException);
		}
	}
	return result;
}
 
@Override
public Result<Page<RcDataDictionaryList>> listForPage(int pageCurrent, int pageSize, String fieldCode, String premise, String datePremise) {
	Result<Page<RcDataDictionaryList>> result = new Result<>();
	if (pageCurrent < 1) {
		result.setErrMsg("参数pageCurrent有误,pageCurrent=" + pageCurrent);
		return result;
	}
	if (pageSize < 1) {
		result.setErrMsg("参数pageSize有误,pageSize=" + pageSize);
		return result;
	}
	if (!StringUtils.hasText(fieldCode)) {
		result.setErrMsg("fieldCode不能为空");
		return result;
	}
	Page<RcDataDictionaryList> resultData = dao.listForPage(pageCurrent, pageSize, fieldCode, premise, datePremise);
	result.setResultData(resultData);
	result.setStatus(true);
	result.setErrCode(0);
	return result;
}
 
源代码5 项目: jeecg-boot   文件: DateUtils.java
/**
 * String类型 转换为Date, 如果参数长度为10 转换格式”yyyy-MM-dd“ 如果参数长度为19 转换格式”yyyy-MM-dd
 * HH:mm:ss“ * @param text String类型的时间值
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
    if (StringUtils.hasText(text)) {
        try {
            if (text.indexOf(":") == -1 && text.length() == 10) {
                setValue(DateUtils.date_sdf.get().parse(text));
            } else if (text.indexOf(":") > 0 && text.length() == 19) {
                setValue(DateUtils.datetimeFormat.get().parse(text));
            } else {
                throw new IllegalArgumentException("Could not parse date, date format is error ");
            }
        } catch (ParseException ex) {
            IllegalArgumentException iae = new IllegalArgumentException("Could not parse date: " + ex.getMessage());
            iae.initCause(ex);
            throw iae;
        }
    } else {
        setValue(null);
    }
}
 
private void registerAsyncExecutionAspect(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME)) {
		BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ASYNC_EXECUTION_ASPECT_CLASS_NAME);
		builder.setFactoryMethod("aspectOf");
		String executor = element.getAttribute("executor");
		if (StringUtils.hasText(executor)) {
			builder.addPropertyReference("executor", executor);
		}
		String exceptionHandler = element.getAttribute("exception-handler");
		if (StringUtils.hasText(exceptionHandler)) {
			builder.addPropertyReference("exceptionHandler", exceptionHandler);
		}
		parserContext.registerBeanComponent(new BeanComponentDefinition(builder.getBeanDefinition(),
				TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME));
	}
}
 
源代码7 项目: bdf3   文件: DataTabInterceptor.java
public void onInit(DefaultEntityDataType dataTypeData) throws Exception {
	DoradoContext dc = DoradoContext.getCurrent();
	String dbInfoId = (String) dc.getAttribute(DoradoContext.VIEW, "dbInfoId");
	String tableName = (String) dc.getAttribute(DoradoContext.VIEW, "tableName");
	String sql = (String) dc.getAttribute(DoradoContext.VIEW, "sql");
	String type = (String) dc.getAttribute(DoradoContext.VIEW, "type");
	List<ColumnInfo> columns = null;
	if (type.equals(SIMPLE_TYPE)) {
		if (StringUtils.hasText(tableName)) {
			columns = dbService.findColumnInfos(dbInfoId, tableName);
		}
	} else {
		columns = dbService.findMultiColumnInfos(dbInfoId, sql);
	}
	DataTypeManager dataTypeManager = (DataTypeManager) DoradoContext.getCurrent().getServiceBean("dataTypeManager");
	BasePropertyDef pd;
	if (columns != null) {
		for (ColumnInfo info : columns) {
			pd = new BasePropertyDef();
			PropertyDef propertyDef = dataTypeData.getPropertyDef(info.getColumnName());
			if (propertyDef != null) {
				continue;
			}
			pd.setName(info.getColumnName());
			log.debug(String.format("datagrid[columnName=%s,columnType=%s]", info.getColumnName(), info.getColumnType()));
			String doradoType = ColumnTypeUtils.getDroadoType(info);
			if (StringUtils.hasText(doradoType)) {
				pd.setDataType(dataTypeManager.getDataType(doradoType));
			}
			if (type.equals(SIMPLE_TYPE)) {
				if (info.isIsnullAble()) {
					pd.setRequired(false);
				} else {
					pd.setRequired(true);
				}
			}
			dataTypeData.addPropertyDef(pd);
		}
	}
}
 
源代码8 项目: eds-starter6-jpa   文件: JpaUserDetails.java
public JpaUserDetails(User user) {
	this.userDbId = user.getId();

	this.password = user.getPasswordHash();
	this.loginName = user.getLoginName();
	this.enabled = user.isEnabled();

	if (StringUtils.hasText(user.getLocale())) {
		this.locale = new Locale(user.getLocale());
	}
	else {
		this.locale = Locale.ENGLISH;
	}

	this.locked = user.getLockedOutUntil() != null
			&& user.getLockedOutUntil().isAfter(ZonedDateTime.now(ZoneOffset.UTC));

	this.userAuthorities = user.getAuthorities();

	if (StringUtils.hasText(user.getSecret())) {
		this.authorities = Collections.unmodifiableCollection(
				AuthorityUtils.createAuthorityList("PRE_AUTH"));
	}
	else {
		this.authorities = Collections.unmodifiableCollection(AuthorityUtils
				.commaSeparatedStringToAuthorityList(user.getAuthorities()));
	}
}
 
protected String computeKey(@Nullable HttpServletRequest request, String requestPath) {
	StringBuilder key = new StringBuilder(RESOLVED_RESOURCE_CACHE_KEY_PREFIX);
	key.append(requestPath);
	if (request != null) {
		String codingKey = getContentCodingKey(request);
		if (StringUtils.hasText(codingKey)) {
			key.append("+encoding=").append(codingKey);
		}
	}
	return key.toString();
}
 
private String[] mergePackagesToScan() {
	String[] packages = null;
	if (StringUtils.hasText(packagesToScan) && StringUtils.hasText(customPackagesToScan)) {
		packages = (packagesToScan + "," + customPackagesToScan).split(",");
	} else if (StringUtils.hasText(packagesToScan)) {
		packages = packagesToScan.split(",");
	}  else if (StringUtils.hasText(customPackagesToScan)) {
		packages = customPackagesToScan.split(",");
	}
	return packages;
}
 
@Override
public Result<String> deleteByFieldCode(String fieldCode) {
	Result<String> result = new Result<>();
	if (!StringUtils.hasText(fieldCode)) {
		result.setErrMsg("fieldCode不能为空");
		return result;
	}
	dao.deleteByFieldCode(fieldCode);
	result.setStatus(true);
	result.setErrCode(0);
	return result;
}
 
源代码12 项目: pgptool   文件: EncryptOnePm.java
protected void refreshPrimaryOperationAvailability() {
	boolean result = true;
	result &= !selectedRecipients.getList().isEmpty();
	result &= StringUtils.hasText(sourceFile.getValue()) && new File(sourceFile.getValue()).exists();
	result &= isUseSameFolder.getValue() || StringUtils.hasText(targetFile.getValue());
	actionDoOperation.setEnabled(result);
}
 
public String fromIvyNotationToId(String ivyNotation) {
	StubConfiguration stubConfiguration = new StubConfiguration(ivyNotation);
	String id = this.idsToServiceIds.get(ivyNotation);
	if (StringUtils.hasText(id)) {
		return id;
	}
	String groupAndArtifact = this.idsToServiceIds.get(
			stubConfiguration.getGroupId() + ":" + stubConfiguration.getArtifactId());
	if (StringUtils.hasText(groupAndArtifact)) {
		return groupAndArtifact;
	}
	return this.idsToServiceIds.get(stubConfiguration.getArtifactId());
}
 
/**
 * Generate the name to use to set the header defined by the specified
 * {@code propertyName} to the {@link MessageHeaders} instance.
 * @see #setInboundPrefix(String)
 */
protected String toHeaderName(String propertyName) {
	String headerName = propertyName;
	if (StringUtils.hasText(this.inboundPrefix) && !headerName.startsWith(this.inboundPrefix)) {
		headerName = this.inboundPrefix + propertyName;
	}
	return headerName;
}
 
private void parseWriteConcern(Element element, Map<String, String> attributeMap) {
	String writeConcern = element.getAttribute(WRITE_CONCERN);
	if (StringUtils.hasText(writeConcern)) {
		attributeMap.put(WRITE_CONCERN, writeConcern);
	}
}
 
private boolean allParams(RequestParam requestParam, Class<?> type) {
	return (Map.class.isAssignableFrom(type) && !StringUtils.hasText(requestParam.name()));
}
 
public FormValidation doCheckPassword(@QueryParameter final String password) {
    if (StringUtils.hasText(password)) {
        return FormValidation.ok();
    }
    return FormValidation.warning(Messages.DashboardView_artifactoryPassword());
}
 
private String getSql(StatementInformation statementInformation) {
    return includeParameterValues && StringUtils.hasText(statementInformation.getSqlWithValues())
            ? statementInformation.getSqlWithValues()
            : statementInformation.getSql();
}
 
源代码19 项目: herd   文件: RequestLoggingFilter.java
/**
 * Log the request message.
 *
 * @param request the request.
 */
public void logRequest(HttpServletRequest request)
{
    StringBuilder message = new StringBuilder();

    // Append the log message prefix.
    message.append(logMessagePrefix);

    // Append the URI.
    message.append("uri=").append(request.getRequestURI());

    // Append the query string if present.
    if (isIncludeQueryString() && StringUtils.hasText(request.getQueryString()))
    {
        message.append('?').append(request.getQueryString());
    }

    // Append the HTTP method.
    message.append(";method=").append(request.getMethod());
   
    // Append the client information.
    if (isIncludeClientInfo())
    {
        // The client remote address.
        String client = request.getRemoteAddr();
        if (StringUtils.hasLength(client))
        {
            message.append(";client=").append(client);
        }

        // The HTTP session information.
        HttpSession session = request.getSession(false);
        if (session != null)
        {
            message.append(";session=").append(session.getId());
        }

        // The remote user information.
        String user = request.getRemoteUser();
        if (user != null)
        {
            message.append(";user=").append(user);
        }
    }

    // Get the request payload.
    String payloadString = "";
    try
    {
        if (payload != null && payload.length > 0)
        {
            payloadString = new String(payload, 0, payload.length, getCharacterEncoding());
        }
    }
    catch (UnsupportedEncodingException e)
    {
        payloadString = "[Unknown]";
    }

    // Append the request payload if present.
    if (isIncludePayload() && StringUtils.hasLength(payloadString))
    {
        String sanitizedPayloadString = HerdStringUtils.sanitizeLogText(payloadString);
        message.append(";payload=").append(sanitizedPayloadString);
    }

    // Append the log message suffix.
    message.append(logMessageSuffix);

    // Log the actual message.
    LOGGER.debug(message.toString());
}
 
/**
 * @param clientRegistrations Can be null. Only required for Client Credentials Grant authentication
 * @param clientCredentialsTokenResponseClient Can be null. Only required for Client Credentials Grant authentication
 * @return DataFlowOperations
 */
@Bean
public DataFlowOperations dataFlowOperations(
	@Autowired(required = false) ClientRegistrationRepository  clientRegistrations,
	@Autowired(required = false) OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient) {

	final RestTemplate restTemplate = DataFlowTemplate.getDefaultDataflowRestTemplate();
	validateUsernamePassword(this.properties.getDataflowServerUsername(), this.properties.getDataflowServerPassword());

	HttpClientConfigurer clientHttpRequestFactoryBuilder = null;

	if (this.properties.getOauth2ClientCredentialsClientId() != null
			|| StringUtils.hasText(this.properties.getDataflowServerAccessToken())
			|| (StringUtils.hasText(this.properties.getDataflowServerUsername())
					&& StringUtils.hasText(this.properties.getDataflowServerPassword()))) {
		clientHttpRequestFactoryBuilder = HttpClientConfigurer.create(this.properties.getDataflowServerUri());
	}

	String accessTokenValue = null;

	if (this.properties.getOauth2ClientCredentialsClientId() != null) {
		final ClientRegistration clientRegistration = clientRegistrations.findByRegistrationId("default");
		final OAuth2ClientCredentialsGrantRequest grantRequest = new OAuth2ClientCredentialsGrantRequest(clientRegistration);
		final OAuth2AccessTokenResponse res = clientCredentialsTokenResponseClient.getTokenResponse(grantRequest);
		accessTokenValue = res.getAccessToken().getTokenValue();
		logger.debug("Configured OAuth2 Client Credentials for accessing the Data Flow Server");
	}
	else if (StringUtils.hasText(this.properties.getDataflowServerAccessToken())) {
		accessTokenValue = this.properties.getDataflowServerAccessToken();
		logger.debug("Configured OAuth2 Access Token for accessing the Data Flow Server");
	}
	else if (StringUtils.hasText(this.properties.getDataflowServerUsername())
			&& StringUtils.hasText(this.properties.getDataflowServerPassword())) {
		accessTokenValue = null;
		clientHttpRequestFactoryBuilder.basicAuthCredentials(properties.getDataflowServerUsername(), properties.getDataflowServerPassword());
		logger.debug("Configured basic security for accessing the Data Flow Server");
	}
	else {
		logger.debug("Not configuring basic security for accessing the Data Flow Server");
	}

	if (accessTokenValue != null) {
		restTemplate.getInterceptors().add(new OAuth2AccessTokenProvidingClientHttpRequestInterceptor(accessTokenValue));
	}

	if (clientHttpRequestFactoryBuilder != null) {
		restTemplate.setRequestFactory(clientHttpRequestFactoryBuilder.buildClientHttpRequestFactory());
	}

	return new DataFlowTemplate(this.properties.getDataflowServerUri(), restTemplate);
}