List of usage examples for org.springframework.util StringUtils hasLength
public static boolean hasLength(@Nullable String str)
From source file:com.xdtech.core.orm.utils.AssertUtils.java
/** * Assert that the given String is not empty; that is, * it must not be <code>null</code> and not the empty String. * <pre class="code">Assert.hasLength(name, "Name must not be empty");</pre> * @param text the String to check//from ww w . ja va2 s . com * @param message the exception message to use if the assertion fails * @see StringUtils#hasLength */ public static void hasLength(String text, String message) { if (!StringUtils.hasLength(text)) { throw new IllegalArgumentException(message); } }
From source file:org.openspaces.persistency.cassandra.HectorCassandraClientConfigurer.java
/** * @return An instance of {@link HectorCassandraClient} matching this configurer * configuration.//from ww w . j a va 2s.co m */ public HectorCassandraClient create() { if (hosts == null) { throw new IllegalArgumentException("hosts must be set"); } if (!StringUtils.hasLength(hosts.replace(",", ""))) { throw new IllegalArgumentException("hosts cannot be null or empty"); } if (port != null && port <= 0) { throw new IllegalArgumentException("port must be positive number"); } else if (port == null) { port = CassandraHost.DEFAULT_PORT; } CassandraHostConfigurator config = new CassandraHostConfigurator(); config.setHosts(hosts); config.setPort(port); return new HectorCassandraClient(config, keyspaceName, clusterName, columnFamilyGcGraceSeconds, readConsistencyLevel, writeConsistencyLevel); }
From source file:com.mengka.diamond.server.service.NotifyService.java
/** * ?url/* w w w . j av a2 s. c om*/ * http://192.168.1.109:8136/notify.do?method=notifyConfigInfo&dataId=***&group=*** */ String generateNotifyConfigInfoPath(String dataId, String group, String address, Properties nodeProperties) { String specialUrl = nodeProperties.getProperty(address); String urlString = PROTOCOL + address + URL_PREFIX; // urlurl if (specialUrl != null && StringUtils.hasLength(specialUrl.trim())) { urlString = specialUrl; } urlString += "?method=notifyConfigInfo&dataId=" + dataId + "&group=" + group; return urlString; }
From source file:org.jasypt.spring31.xml.encryption.DigesterBeanDefinitionParser.java
@Override protected void doParse(final Element element, final BeanDefinitionBuilder builder) { builder.addConstructorArgValue(new Integer(this.digesterType)); processStringAttribute(element, builder, PARAM_ALGORITHM, "algorithm"); processBeanAttribute(element, builder, PARAM_CONFIG_BEAN, "config"); processIntegerAttribute(element, builder, PARAM_ITERATIONS, "iterations"); processIntegerAttribute(element, builder, PARAM_SALT_SIZE_BYTES, "saltSizeBytes"); processBeanAttribute(element, builder, PARAM_SALT_GENERATOR_BEAN, "saltGenerator"); processBeanAttribute(element, builder, PARAM_PROVIDER_BEAN, "provider"); processStringAttribute(element, builder, PARAM_PROVIDER_NAME, "providerName"); processBooleanAttribute(element, builder, PARAM_INVERT_POSITION_OF_SALT_IN_MESSAGE_BEFORE_DIGESTING, "invertPositionOfSaltInMessageBeforeDigesting"); processBooleanAttribute(element, builder, PARAM_INVERT_POSITION_OF_PLAIN_SALT_IN_ENCRYPTION_RESULTS, "invertPositionOfPlainSaltInEncryptionResults"); processBooleanAttribute(element, builder, PARAM_USE_LENIENT_SALT_SIZE_CHECK, "useLenientSaltSizeCheck"); processIntegerAttribute(element, builder, PARAM_POOL_SIZE, "poolSize"); processStringAttribute(element, builder, PARAM_STRING_OUTPUT_TYPE, "stringOutputType"); processBooleanAttribute(element, builder, PARAM_UNICODE_NORMALIZATION_IGNORED, "unicodeNormalizationIgnored"); processStringAttribute(element, builder, PARAM_PREFIX, "prefix"); processStringAttribute(element, builder, PARAM_SUFFIX, "suffix"); String scope = element.getAttribute(SCOPE_ATTRIBUTE); if (StringUtils.hasLength(scope)) { builder.setScope(scope);//w ww. java 2s .co m } }
From source file:es.osoco.grails.plugins.otp.access.AnnotationMultipleVoterFilterInvocationDefinition.java
@Override protected String determineUrl(final FilterInvocation filterInvocation) { HttpServletRequest request = filterInvocation.getHttpRequest(); HttpServletResponse response = filterInvocation.getHttpResponse(); GrailsWebRequest existingRequest = WebUtils.retrieveGrailsWebRequest(); String requestUrl = request.getRequestURI().substring(request.getContextPath().length()); String url = null;//from w w w. j ava 2 s . c om try { GrailsWebRequest grailsRequest = new GrailsWebRequest(request, response, ServletContextHolder.getServletContext()); WebUtils.storeGrailsWebRequest(grailsRequest); Map<String, Object> savedParams = copyParams(grailsRequest); for (UrlMappingInfo mapping : _urlMappingsHolder.matchAll(requestUrl)) { configureMapping(mapping, grailsRequest, savedParams); url = findGrailsUrl(mapping); if (url != null) { break; } } } finally { if (existingRequest == null) { WebUtils.clearGrailsWebRequest(); } else { WebUtils.storeGrailsWebRequest(existingRequest); } } if (!StringUtils.hasLength(url)) { // probably css/js/image url = requestUrl; } return lowercaseAndStripQuerystring(url); }
From source file:com.xdtech.core.orm.utils.AssertUtils.java
public static void hasLength(String text, RuntimeException throwIfAssertFail) { if (!StringUtils.hasLength(text)) { throw throwIfAssertFail; }/*from w w w . j av a2 s. c o m*/ }
From source file:org.mitre.discovery.util.WebfingerURLNormalizer.java
public static String serializeURL(UriComponents uri) { if (uri.getScheme() != null && (uri.getScheme().equals("acct") || uri.getScheme().equals("mailto") || uri.getScheme().equals("tel") || uri.getScheme().equals("device"))) { // serializer copied from HierarchicalUriComponents but with "//" removed StringBuilder uriBuilder = new StringBuilder(); if (uri.getScheme() != null) { uriBuilder.append(uri.getScheme()); uriBuilder.append(':'); }/*from ww w.j ava 2 s. c o m*/ if (uri.getUserInfo() != null || uri.getHost() != null) { if (uri.getUserInfo() != null) { uriBuilder.append(uri.getUserInfo()); uriBuilder.append('@'); } if (uri.getHost() != null) { uriBuilder.append(uri.getHost()); } if (uri.getPort() != -1) { uriBuilder.append(':'); uriBuilder.append(uri.getPort()); } } String path = uri.getPath(); if (StringUtils.hasLength(path)) { if (uriBuilder.length() != 0 && path.charAt(0) != '/') { uriBuilder.append('/'); } uriBuilder.append(path); } String query = uri.getQuery(); if (query != null) { uriBuilder.append('?'); uriBuilder.append(query); } if (uri.getFragment() != null) { uriBuilder.append('#'); uriBuilder.append(uri.getFragment()); } return uriBuilder.toString(); } else { return uri.toUriString(); } }
From source file:edu.txstate.dmlab.clusteringwiki.rest.BaseRestController.java
/** * Execute a search given criteria/*from w ww. ja va 2 s. c o m*/ * @param service * @param icwservice * @param query * @param numResults * @param start * @return */ protected ICWSearchResultCol doSearch(String service, String icwservice, String query, String numResults, String start) throws Exception { //Sanitize values service = service.toLowerCase(); if (cWSearchers == null) { throw new Exception("No cWSearchers have been configured."); } if (!cWSearchers.containsKey(service)) { throw new Exception("Invalid Searcher service."); } if (!StringUtils.hasLength(query)) { throw new Exception("Query must be provided."); } icwservice = _cleanExtensions(icwservice); query = _cleanExtensions(query); numResults = _cleanExtensions(numResults); start = _cleanExtensions(start); ICWSearcher cWSearcher = cWSearchers.get(service); cWSearcher.setKey(service); int numRes = DEFAULT_SEARCH_NUM_RESULTS; try { numRes = Integer.parseInt(numResults); } catch (NumberFormatException nfe) { } ; int strt = DEFAULT_SEARCH_START; try { strt = Integer.parseInt(start); } catch (NumberFormatException nfe) { } ; if (strt < 0) { throw new Exception("Start value must be positive."); } if (numRes > DEFAULT_SEARCH_MAX) { throw new Exception("The maximum number of requested results is " + DEFAULT_SEARCH_MAX + "."); } //Execute search return cWSearcher.search(icwservice, query, strt, Integer.valueOf(numRes)); }
From source file:fr.xebia.xke.test.jdbc.core.SqlScriptProcessor.java
/** * Initializes SQL scripts./*from w w w .j a v a 2 s.c om*/ */ public void process() throws IOException { if (lSqlScripts != null) { for (String sqlScript : lSqlScripts) { String sql = null; Resource resource = resourceLoader.getResource(sqlScript); if (!resource.exists()) { sql = sqlScript; } else { BufferedReader br = null; try { if (charset == null) { br = new BufferedReader(new InputStreamReader(resource.getInputStream())); } else { br = new BufferedReader(new InputStreamReader(resource.getInputStream(), charset)); } StringBuilder sb = new StringBuilder(); String line = null; while ((line = br.readLine()) != null) { sb.append(line); sb.append("\n"); } sql = sb.toString(); } finally { br.close(); } } if (StringUtils.hasLength(sql)) { logger.debug("Initializing db with '" + sql + "'."); // execute sql template.execute(sql); } } } }
From source file:com.lightning.testplatform.configure.mybatis.MybatisAutoConfiguration.java
@Bean @ConditionalOnMissingBean/*from w w w .ja v a 2 s . co m*/ public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { SqlSessionFactoryBean factory = new SqlSessionFactoryBean(); factory.setDataSource(dataSource); // factory.setVfs(SpringBootVFS.class); if (StringUtils.hasText(this.properties.getConfigLocation())) { factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation())); // ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); // factory.setConfigLocation(resolver.getResource(this.properties.getConfigLocation())); } factory.setConfiguration(properties.getConfiguration()); if (!ObjectUtils.isEmpty(this.interceptors)) { factory.setPlugins(this.interceptors); } if (this.databaseIdProvider != null) { factory.setDatabaseIdProvider(this.databaseIdProvider); } if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) { factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage()); } if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) { factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage()); } if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) { factory.setMapperLocations(this.properties.resolveMapperLocations()); } return factory.getObject(); }