List of usage examples for org.springframework.util StringUtils hasLength
public static boolean hasLength(@Nullable String str)
From source file:com.nimble.http.client.GzipClientHttpResponse.java
public InputStream getBody() throws IOException { InputStream errorStream = this.connection.getErrorStream(); return (errorStream != null ? errorStream : StringUtils.hasLength(this.connection.getContentEncoding()) && this.connection .getContentEncoding().equalsIgnoreCase(GzipClientHttpRequest.ENCODING_GZIP) ? new GZIPInputStream(this.connection.getInputStream()) : this.connection.getInputStream()); }
From source file:fi.solita.phantomrunner.util.FileUtils.java
/** * Extracts the given resource to user's temporary directory (by creating a unique directory underneath * it). Will delete that file and created directories on system exit if deleteOnExit is true. * /*from w w w .j ava 2s .co m*/ * @param resource Resource to be extracted * @param subPath Slash (character '/') separated path of the sub-directories which should be created * @param deleteOnExit If the resource and created sub-directories should be deleted * * @return File handle to the created file in the temporary directory */ public static File extractResourceToTempDirectory(Resource resource, String subPath, boolean deleteOnExit) throws IOException { final File tempDir = Files.createTempDir(); if (deleteOnExit) tempDir.deleteOnExit(); File lastDir = tempDir; for (String subDir : subPath.split("/")) { // if the subPath starts or ends with '/' we'll get empty strings too if (StringUtils.hasLength(subDir)) { lastDir = new File(lastDir, subDir); lastDir.mkdir(); if (deleteOnExit) lastDir.deleteOnExit(); } } final File resFile = new File(lastDir, resource.getFilename()); resFile.createNewFile(); if (deleteOnExit) resFile.deleteOnExit(); IOUtil.copy(resource.getInputStream(), new FileWriter(resFile), "UTF-8"); return resFile; }
From source file:org.jasig.portlet.contacts.model.util.ContactComparator.java
private int compareStrings(String s1, String s2) { if (StringUtils.hasLength(s1)) { return s1.compareToIgnoreCase(s2); } else if (StringUtils.hasLength(s2)) { return -1; }/*from www . ja va 2s . c om*/ return 0; }
From source file:org.springmodules.validation.bean.conf.loader.annotation.handler.ValidationMethodAnnotationHandler.java
protected String extractDefaultMessage(Annotation annotation) { String message = super.extractDefaultMessage(annotation); return (StringUtils.hasLength(message)) ? message : null; }
From source file:org.cloudfoundry.tools.io.local.LocalFolder.java
/** * @return The user home folder//w ww .j av a2 s . co m */ public static LocalFolder home() { String home = System.getProperty("user.home"); Assert.state(StringUtils.hasLength(home), "Unable to locate home folder"); return new LocalFolder(home); }
From source file:org.springmodules.cache.guava.GuavaCacheFactoryBean.java
@Override public void setBeanName(String name) { if (!StringUtils.hasLength(this.name)) { this.name = name; } }
From source file:org.smf4j.spring.JmxExporterBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext context, BeanDefinitionBuilder builder) { String tmp = element.getAttribute(AUTOPUBLISH_ATTR); if (StringUtils.hasLength(tmp)) { builder.addPropertyValue(AUTOPUBLISH_PROP, tmp); }// ww w. java 2 s . c o m tmp = element.getAttribute(DEPENDSON_ATTR); if (StringUtils.hasLength(tmp)) { for (String id : StringUtils.commaDelimitedListToSet(tmp)) { builder.addDependsOn(id); } } else { builder.addDependsOn(RegistrarBeanDefinitionParser.MASTER_REGISTRAR_ID); } builder.setLazyInit(false); }
From source file:com.example.securelogin.app.common.validation.FileExtensionValidator.java
@Override public boolean isValid(MultipartFile value, ConstraintValidatorContext context) { if (value == null) { return true; }//from w w w . j a v a 2s . c om String fileNameExtension = StringUtils.getFilenameExtension(value.getOriginalFilename()); if (!StringUtils.hasLength(fileNameExtension)) { return false; } for (String extension : extensions) { if (fileNameExtension.equals(extension) || ignoreCase && fileNameExtension.equalsIgnoreCase(extension)) { return true; } } return false; }
From source file:org.smf4j.spring.ResolveBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext context, BeanDefinitionBuilder builder) { // The path path.to.node.accumulator to the accumulator we're looking // up.//from w w w . j a va2 s . c o m String path = element.getAttribute(PATH_ATTR); if (!StringUtils.hasLength(path)) { context.getReaderContext().error("'resolve' elements must have a 'path' attribute.", element); } // Set the path builder.addPropertyValue(PATH_ATTR, path); // Make sure that spring knows we depend on the given beans, which are // probably <registrar> nodes. String dependsOn = element.getAttribute(DEPENDSON_ATTR); if (StringUtils.hasLength(dependsOn)) { for (String id : StringUtils.commaDelimitedListToSet(dependsOn)) { // Depend on the indicated registrar name builder.addDependsOn(id); } } else { // Depend on the default registrar name builder.addDependsOn(RegistrarBeanDefinitionParser.MASTER_REGISTRAR_ID); } }
From source file:com.github.springtestdbunit.DatabaseConnections.java
public IDatabaseConnection get(String name) { if (!StringUtils.hasLength(name)) { return this.connections[0]; }// w w w. j av a2 s. c o m for (int i = 0; i < this.names.length; i++) { if (this.names[i].equals(name)) { return this.connections[i]; } } throw new IllegalStateException("Unable to find connection named " + name); }