List of usage examples for org.springframework.util StringUtils hasLength
public static boolean hasLength(@Nullable String str)
From source file:com.vmware.appfactory.datastore.DsDatastoreCifs.java
/** * Get a server path in xxx.xxx.xxx/share/path format. * * @return a server path string.//from w w w . jav a 2s.co m */ private String getServerPath() { String serverPath = null; if (StringUtils.hasLength(getShare())) { serverPath = getServer() + AfUtil.appendIfNotExist(DsUtil.FILE_SEPARATOR, getShare().replace("\\", "/"), null); } else { serverPath = getServer() + DsUtil.FILE_SEPARATOR; } /* Trim any leading \\ or // */ serverPath = StringUtils.trimLeadingCharacter(serverPath, '\\'); serverPath = StringUtils.trimLeadingCharacter(serverPath, '/'); /* Replace "\" with "/" because Samba format uses / */ serverPath = serverPath.replace("\\", "/"); return serverPath; }
From source file:com.vmware.appfactory.datastore.DsDatastoreCifs.java
private boolean requiresAuth() { return StringUtils.hasLength(getUsername()); }
From source file:com.vmware.appfactory.file.controllers.FileUploadController.java
/** * This method provides with the status of an ongoing upload. * * @param uploadId - Unique Id represents the upload. * @param request//from w w w . ja va 2 s.com * @return ProgressListenerImpl contains progress. * @throws AfBadRequestException */ @ResponseBody @RequestMapping(method = RequestMethod.GET, value = "/upload/{uploadId}/progress") public ProgressListener fetchUploadProgress(@PathVariable String uploadId, HttpServletRequest request) throws AfBadRequestException { if (StringUtils.hasLength(uploadId)) { ProgressListener pl = ProgressReporter.getProgressListener(request, uploadId); return pl; } /* * This can happen if the uploadId was a bogus, or if the client is * requesting status on something that has already finished since the * last time they requested. */ throw new AfBadRequestException("Invalid upload Id: " + uploadId); }
From source file:com.vmware.appfactory.fileshare.dto.ApplicationInfoDelta.java
/** * Copy non-empty instance variables to a * given application instance.//w w w . j a v a 2 s . c o m * @param app - an application instance. */ public void copyToApplication(Application app) { if (app == null) { return; } if (StringUtils.hasLength(_name)) { app.setName(_name); } if (StringUtils.hasLength(_version)) { app.setVersion(_version); } if (StringUtils.hasLength(_vendor)) { app.setVendor(_vendor); } if (StringUtils.hasLength(_revision)) { app.setInstallerRevision(_revision); } if (StringUtils.hasLength(_lang)) { app.setLocale(_lang); } if (StringUtils.hasLength(_installCommand)) { app.setInstalls(new AppInstall(_installCommand)); } // note: if we don't set lastModified, then the value // will be 0 for all Applications in the table. // If the user later adds a second feed without making // any other changes, the second feed will also have // timestamps of 0. The timestamp here didn't change. // Since the frontend uses the most recent modified timestamp // to tell when it has more AJAX data to load, this means // the user won't see it. // app.setModified(AfCalendar.Now()); }
From source file:com.vmware.appfactory.fileshare.dto.ApplicationInfoDelta.java
/** * Copy fields of given application to this instance * variables./*from w ww. ja va 2 s . co m*/ * @param app - an application instance. */ public void copyFromApplication(Application app) { if (app == null) { return; } if (StringUtils.hasLength(app.getName())) { _name = app.getName(); } if (StringUtils.hasLength(app.getVersion())) { _version = app.getVersion(); } if (StringUtils.hasLength(app.getVendor())) { _vendor = app.getVendor(); } if (StringUtils.hasLength(app.getInstallerRevision())) { _revision = app.getInstallerRevision(); } if (StringUtils.hasLength(app.getLocale())) { _lang = app.getLocale(); } }
From source file:com.vmware.appfactory.fileshare.dto.FileShareRequest.java
/** * * @throws InvalidDataException/*from w ww . ja v a2 s.com*/ */ public void validate() throws InvalidDataException { /* Name and URL are required */ if (!StringUtils.hasLength(_name)) { throw new InvalidDataException("Required field missing."); } /* Authorization user and pass are required */ // XXX empty password should be OK if (_authRequired) { if (AfUtil.anyEmpty(_authUsername)) { throw new InvalidDataException("Required field missing."); } } if (!StringUtils.hasLength(_serverPath)) { throw new InvalidDataException("Share Location field is required."); } /* Trim any leading \\ or // */ _serverPath = StringUtils.trimLeadingCharacter(_serverPath, '\\'); _serverPath = StringUtils.trimLeadingCharacter(_serverPath, '/'); /* Replace "\" with "/" because Samba format uses / */ _serverPath = _serverPath.replace("\\", "/"); }
From source file:com.vmware.thinapp.common.util.AfUtil.java
/** * Return true if any of the given strings are null or empty. * * @param strings/*from w ww . j a v a 2 s . c om*/ * @return True if any string is null or empty. */ public static boolean anyEmpty(String... strings) { /* strings is null -> true */ if (strings == null) { return true; } for (String string : strings) { if (!StringUtils.hasLength(string)) { return true; } } return false; }
From source file:com.vmware.thinapp.common.util.AfUtil.java
/** * Checks whether the given URL string begins with a protocol (http://, * ftp://, etc.) If it does, the string is returned unchanged. If it does * not, full URL is returned and is constructed as parentUrl "/" url. * * @param url input URL string in absolute or relative form * @param parentUrl base URL to use if the given URL is in relative form * @return an absolute URL//from w w w. jav a 2 s . co m */ public static URI relToAbs(String url, URI parentUrl) throws URISyntaxException { if (!StringUtils.hasLength(url)) { throw new URISyntaxException(url, "The input url was empty!"); } URI parent2 = new URI(parentUrl.getScheme(), parentUrl.getUserInfo(), parentUrl.getAuthority(), parentUrl.getPort(), parentUrl.getPath() + "/", // Parent URL path must end with "/" for // this to work. resolve() removes any // duplicates. parentUrl.getQuery(), parentUrl.getFragment()); return parent2.resolve(url.trim()); }
From source file:com.vmware.thinapp.common.util.AfUtil.java
/** * Given a URI, return the last uri token. * * @param uri Last token/*w w w . j a v a 2 s . c o m*/ * @return */ public static String extractLastURIToken(URI uri) { if (uri == null || !StringUtils.hasLength(uri.getPath())) { return null; } String tokens[] = uri.getPath().split("/"); return tokens[tokens.length - 1]; }
From source file:com.vmware.thinapp.common.util.AfUtil.java
/** * Given a URI, return a new URI with the query, fragment, and top level of * the path removed.//from w w w.j a va 2 s .c om * * @param uri the input URI * @return the base URI */ public static URI parentUri(URI uri) throws URISyntaxException { if (uri == null) { return null; } String protocol = uri.getScheme(); String host = uri.getHost(); // Process the port number, if any int port = uri.getPort(); // Process the path, if any String path = uri.getPath(); if (!StringUtils.hasLength(path)) { path = ""; } else { if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } if (!path.contains("/")) { path = ""; } else { int lastSlash = path.lastIndexOf('/'); path = path.substring(0, lastSlash); } } // Build the final URL and return it return new URI(protocol, null, host, port, path, null, null); }