List of usage examples for org.apache.commons.lang3 StringUtils removeStart
public static String removeStart(final String str, final String remove)
Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.
A null source string will return null .
From source file:org.pepstock.jem.gwt.server.services.GfsManager.java
/** * Checks if the user has got the authorization to scan GFS * /*from w w w . j av a 2 s . c om*/ * @param file * files to check * @return true if authorized otherwise false */ private boolean match(GfsFile file) { // gets user Subject currentUser = SecurityUtils.getSubject(); User userPrincipal = (User) currentUser.getPrincipal(); // if administrator, always true if (currentUser.hasRole(Roles.ADMINISTRATOR)) { return true; } // checks if it has read. If yes OK! String filesPermission = Permissions.FILES_READ + file.getLongName(); if (currentUser.isPermitted(new StringPermission(filesPermission))) { return true; } // check if it has write. If yes, OK! filesPermission = Permissions.FILES_WRITE + file.getLongName(); if (currentUser.isPermitted(new StringPermission(filesPermission))) { return true; } // checks all file permissions // because it depends on path asked from user for (Permission permission : userPrincipal.getPermissions()) { String permString = permission.toString(); if (permission instanceof RegExpPermission) { RegExpPermission regex = (RegExpPermission) permission; permString = regex.getPermissionPattern(); } // for any general permissions to files, OK! if (permString.startsWith(Permissions.FILES)) { if (permString.equals(Permissions.FILES_STAR) || permString.equals(Permissions.FILES_READ_ALL) || permString.equals(Permissions.FILES_WRITE_ALL)) { return true; } else { // extract the permission pattern to check with path String filePattern = null; if (permString.startsWith(Permissions.FILES_READ)) { filePattern = StringUtils.removeStart(permString, Permissions.FILES_READ); } else if (permString.startsWith(Permissions.FILES_WRITE)) { filePattern = StringUtils.removeStart(permString, Permissions.FILES_WRITE); } // if permission pattern is longer than path, checks if // pattern start with path. if yes, means user can read if (filePattern != null && filePattern.length() > file.getLongName().length() && filePattern.startsWith(file.getLongName())) { return true; } } } } // doesn't match! Not authorized return false; }
From source file:org.pepstock.jem.node.executors.gfs.GetFilesList.java
/** * Extracts all files from a folder// w w w.j a va2 s. c o m * @param parentPath parentPath is path define as mount poit * @param parent parent requisted from user, to add to the mount point * @return lsit of files of folder */ private Collection<GfsFile> getFilesList(String parentPath, File parent) { // creates the collection of files and reads them Collection<GfsFile> list = new ArrayList<GfsFile>(); File[] files = parent.listFiles(); if (files != null && files.length > 0) { // scans all files and loads them into a collection, normalizing the names for (int i = 0; i < files.length; i++) { // checks if is sub folder boolean isDirectory = files[i].isDirectory(); String name = files[i].getName(); // gets the long name of file String longName = StringUtils.removeStart(FilenameUtils.normalize(files[i].getAbsolutePath(), true), FilenameUtils.normalize(parentPath, true)).substring(1); // creates a bean with of file information GfsFile file = new GfsFile(); file.setDirectory(isDirectory); file.setName(name); file.setLongName(longName); file.setLength((isDirectory) ? -1 : files[i].length()); file.setLastModified(files[i].lastModified()); // sets the data path name to be showed on user interface file.setDataPathName(Main.DATA_PATHS_MANAGER.getAbsoluteDataPathName(files[i].getAbsolutePath())); // adds to the collection to be returned list.add(file); } } return list; }
From source file:org.phenotips.data.internal.PhenoTipsDisorder.java
@Override public String getValue() { if (StringUtils.isEmpty(getId())) { return getName(); }//from ww w . j a va 2 s.c om String id = StringUtils.removeStart(getId(), MIM_PREFIX); return id; }
From source file:org.phenotips.ontology.internal.GeneNomenclature.java
/** * Generate a Lucene query from a map of parameters, to be used in the "q" parameter for Solr. * * @param fieldValues a map with term meta-property values that must be matched by the returned terms; the keys are * property names, like {@code id}, {@code description}, {@code is_a}, and the values can be either a * single value, or a collection of values that can (OR) be matched by the term; * @return the String representation of the equivalent Lucene query *//* w w w . j a v a2 s. c om*/ private String generateQuery(Map<String, ?> fieldValues) { StringBuilder query = new StringBuilder(); for (Map.Entry<String, ?> field : fieldValues.entrySet()) { processQueryPart(query, field, true); } return StringUtils.removeStart(query.toString().trim(), DEFAULT_OPERATOR); }
From source file:org.phenotips.security.encryption.internal.EncryptedProperty.java
/** * Removes {@link #ENCRYPTED_IDENTIFIER encryption identifier prefix}, if present. * * @param value the text from which to remove the prefix * @return the text with the prefix removed, or the original text if no prefix was present *//*www . j a v a2 s. com*/ private String getRawValue(String value) { return StringUtils.removeStart(value, ENCRYPTED_IDENTIFIER); }
From source file:org.sakaiproject.archiver.impl.IndexBuilder.java
/** * Determines a relative path to the file from the top level index.html file * * @param file// w w w . jav a 2 s . c om * @return relative path */ private String getRelativePath(final File file) { return StringUtils.removeStart( StringUtils.removeStart(file.getAbsolutePath(), this.archiveBase.getAbsolutePath()), "/"); }
From source file:org.settings4j.connector.PropertyFileConnector.java
private static URL getParentFolderUrlFromFile(final String propertyPath) { final File propertyFile = new File( StringUtils.removeStart(propertyPath, FSContentResolver.FILE_URL_PREFIX)); try {//ww w .j a va2 s .c om return propertyFile.getParentFile().toURI().toURL(); } catch (final IOException e) { throw new IllegalArgumentException(e); } }
From source file:org.settings4j.connector.PropertyFileConnector.java
private void resolveRelativePaths() { if (!this.resolveRelativePaths) { return;//from ww w .ja v a 2 s.c o m } if (this.propertyFileFolderUrl == null) { return; } final Set<Entry<Object, Object>> entrySet = this.property.entrySet(); for (final Entry<Object, Object> entry : entrySet) { final String propValue = entry.getValue().toString(); if (propValue.startsWith(FSContentResolver.FILE_URL_PREFIX + ".")) { final String valuePath = StringUtils.removeStart(propValue, FSContentResolver.FILE_URL_PREFIX); final String newPath = createURL(this.propertyFileFolderUrl, valuePath).toString(); this.property.setProperty(entry.getKey().toString(), newPath); } } }
From source file:org.squashtest.tm.web.internal.util.PathUtils.java
public static String shortPath(String absolutePath) { return StringUtils.removeStart(absolutePath, APPLICATION_PATH); }
From source file:org.structr.module.JarConfigurationProvider.java
private void importResource(Module module) throws IOException { final Set<String> classes = module.getClasses(); for (final String name : classes) { String className = StringUtils.removeStart(name, "."); logger.log(Level.FINE, "Instantiating class {0} ", className); try {// w w w . ja va 2s .c om // instantiate class.. Class clazz = Class.forName(className); int modifiers = clazz.getModifiers(); logger.log(Level.FINE, "Class {0} instantiated: {1}", new Object[] { className, clazz }); // register node entity classes if (NodeInterface.class.isAssignableFrom(clazz)) { registerEntityType(clazz); } // register entity classes if (AbstractRelationship.class.isAssignableFrom(clazz) && !(Modifier.isAbstract(modifiers))) { registerEntityType(clazz); } // register services if (Service.class.isAssignableFrom(clazz) && !(Modifier.isAbstract(modifiers))) { Services.getInstance().registerServiceClass(clazz); } // register agents if (Agent.class.isAssignableFrom(clazz) && !(Modifier.isAbstract(modifiers))) { String simpleName = clazz.getSimpleName(); String fullName = clazz.getName(); agentClassCache.put(simpleName, clazz); agentPackages.add(fullName.substring(0, fullName.lastIndexOf("."))); } } catch (Throwable t) { } } }