List of usage examples for org.apache.commons.lang StringUtils removeStart
public static String removeStart(String str, String remove)
Removes a substring only if it is at the begining of a source string, otherwise returns the source string.
From source file:org.rapidcontext.core.type.Role.java
/** * Checks if the access data matches the specified values. * * @param dict the access data * @param path the object storage path * * @return true if the access path matches, or * false otherwise//from w w w .j a va 2s . c o m */ private boolean matchPath(Dict dict, String path) { String glob = dict.getString(ACCESS_PATH, null); String regex = dict.getString(ACCESS_REGEX, null); Pattern m = (Pattern) dict.get("_" + ACCESS_REGEX); if (m == null && glob != null) { glob = glob.replace("\\", "\\\\").replace(".", "\\."); glob = glob.replace("+", "\\+").replace("|", "\\|"); glob = glob.replace("^", "\\^").replace("$", "\\$"); glob = glob.replace("(", "\\(").replace(")", "\\)"); glob = glob.replace("[", "\\[").replace("]", "\\]"); glob = glob.replace("{", "\\{").replace("}", "\\}"); glob = glob.replace("**", ".+"); glob = glob.replace("*", "[^/]*"); glob = glob.replace(".+", ".*"); glob = glob.replace("?", "."); try { m = Pattern.compile("^" + glob + "$"); } catch (Exception e) { LOG.log(Level.WARNING, "invalid pattern in role " + id(), e); m = Pattern.compile("^invalid-glob-pattern$"); } dict.set("_" + ACCESS_REGEX, m); } else if (m == null && regex != null) { regex = StringUtils.removeStart(regex, "^"); regex = StringUtils.removeStart(regex, "/"); regex = StringUtils.removeEnd(regex, "$"); try { m = Pattern.compile("^" + regex + "$"); } catch (Exception e) { LOG.log(Level.WARNING, "invalid pattern in role " + id(), e); m = Pattern.compile("^invalid-regex-pattern$"); } dict.set("_" + ACCESS_REGEX, m); } return m.matcher(path).matches(); }
From source file:org.rapidcontext.core.type.WebMatcher.java
/** * The base request path to match. Defaults to an empty string, * meaning that any path will match.//from w w w. j a v a 2s. c o m * * @return the base request path to match, or * an empty string to match any request */ public String path() { return StringUtils.removeStart(dict.getString("path", ""), "/"); }
From source file:org.rapidcontext.core.web.Request.java
/** * Returns the local request path with file name. This path has * been shortened to ONLY include the relevant portions of the * path, removing any initial mapping URL portions of the path. * A root path may thus be an empty string. * * @return the local request path/*from ww w . j av a2 s . co m*/ */ public String getPath() { if (requestPath == null) { String path = request.getPathInfo(); path = StringUtils.removeStart(path, "/"); requestPath = (path == null) ? "" : path; } return requestPath; }
From source file:org.rapidcontext.core.web.Request.java
/** * Matches and modifies the request path with the specified path * prefix. If a match is found, the prefix is removed from the * request path and true is returned. If the prefix ends with a / * and the path would match the shorter prefix, a redirect is * sent and false is returned.//from ww w . j av a 2 s . c o m * * @param prefix the path prefix to check * * @return true if the request path matched the prefix, or * false otherwise */ public boolean matchPath(String prefix) { String path = getPath(); prefix = StringUtils.removeStart(prefix, "/"); if (path.startsWith(prefix)) { if (prefix.length() > 0) { setPath(path.substring(prefix.length())); } return true; } else if (path.startsWith(StringUtils.removeEnd(prefix, "/"))) { sendRedirect(getUrl() + "/"); } return false; }
From source file:org.rdfhdt.mrbuilder.HDTBuilderConfiguration.java
private String addBucket(String path) { // If bucket is provided as parameter, and configuration path is // relative, create absolute configuration path if (this.getAwsBucket() != null && !path.startsWith("s3n://")) { path = "s3n://" + this.getAwsBucket() + "/" + StringUtils.removeStart(path, "/"); }//from ww w . j a va 2s . c o m return path; }
From source file:org.renci.ahab.libndl.ndl.ManifestLoader.java
private String getTrueName(Resource r) { if (r == null) return null; return StringUtils.removeStart(r.getURI(), NdlCommons.ORCA_NS); }
From source file:org.renci.ahab.libndl.ndl.RequestLoader.java
public void ndlReservation(Resource i, final OntModel m) { LIBNDL.logger().debug("Reservation: " + i + ", sliceState(Request:ndlReservation) = " + NdlCommons.getGeniSliceStateName(i)); // try to extract the guid out of the URL String u = i.getURI();//from ww w.j ava 2 s. c o m String guid = StringUtils.removeEnd(StringUtils.removeStart(u, NdlCommons.ORCA_NS), "#"); this.sliceGraph.setNsGuid(guid); //this.slice.setState(NdlCommons.getGeniSliceStateName(i)); /*if (i != null) { reservationDomain = RequestSaver.reverseLookupDomain(NdlCommons.getDomain(i)); this.sliceGraph.setOFVersion(NdlCommons.getOpenFlowVersion(i)); }*/ }
From source file:org.renci.ahab.libndl.ndl.UserAbstractionLoader.java
/** * Hacks that should be in ndlcommons//from www. j a v a 2 s .c om */ // sometimes getLocalName is not good enough // so we strip off orca name space and call it a day private String getTrueName(Resource r) { if (r == null) return null; return StringUtils.removeStart(r.getURI(), NdlCommons.ORCA_NS); }
From source file:org.reprap.configuration.store.ConfigurationInitializer.java
private static void copyJarTree(final URL source, final File target) throws IOException { final JarURLConnection jarConnection = (JarURLConnection) source.openConnection(); final String prefix = jarConnection.getEntryName(); final JarFile jarFile = jarConnection.getJarFile(); for (final JarEntry jarEntry : Collections.list(jarFile.entries())) { final String entryName = jarEntry.getName(); if (entryName.startsWith(prefix)) { if (!jarEntry.isDirectory()) { final String fileName = StringUtils.removeStart(entryName, prefix); final InputStream fileStream = jarFile.getInputStream(jarEntry); try { FileUtils.copyInputStreamToFile(fileStream, new File(target, fileName)); } finally { fileStream.close();/* w w w. j a va 2 s . com*/ } } } } }
From source file:org.rhq.enterprise.remoting.cli.ScriptTestRunner.java
private String getTestName(Script script) { String pathExcludingFileName = FilenameUtils.getFullPath(script.srcFile.getAbsolutePath()); String packagePath = StringUtils.difference(scriptDir.getAbsolutePath(), pathExcludingFileName); packagePath = StringUtils.replace(packagePath, File.separator, "."); packagePath = StringUtils.removeStart(packagePath, "."); return packagePath + FilenameUtils.getBaseName(script.srcFile.getName()); }