Clean the path in the case of an OData Uri containing a resource identifier (simple or multiple)

@param path The path to clean
@param handleParameters tThe cleaning mode
@return A cleaned path
431814
private static String cleanODataPath(String path, HandleParametersOption handleParameters) {
		String cleanedPath = path;
		
		if (HandleParametersOption.USE_ALL.equals(handleParameters) ) {
			cleanedPath = path;
		} else {

			// check for single ID (unnamed)
			Matcher matcher = patternResourceIdentifierUnquoted.matcher(path);
			if (matcher.find()) {
				String resourceName =  matcher.group(1); 
				String resourceID   =  matcher.group(2);
			
				String subString = resourceName + "(" + resourceID + ")";
				int begin = path.indexOf(subString);
				int end   = begin + subString.length();
				
				String beforeSubstring = path.substring(0,begin);
				String afterSubstring  = path.substring(end);
				
	
				if (HandleParametersOption.IGNORE_COMPLETELY.equals(handleParameters) ||
				    HandleParametersOption.IGNORE_VALUE.equals(handleParameters)	     ) {
					
					StringBuilder sb = new StringBuilder(beforeSubstring);
					sb.append(resourceName).append("()").append(afterSubstring);
					cleanedPath = sb.toString();
				} 
							
			} else {
				
				matcher = patternResourceMultipleIdentifier.matcher(path);
				if (matcher.find()) {
					// We've found a composite identifier. i.e: /Resource(field1=a,field2=3)
					
					String multipleIdentifierSection =   matcher.group(1); 
					
					int begin = path.indexOf(multipleIdentifierSection);
					int end   = begin + multipleIdentifierSection.length();
	
					String beforeSubstring = path.substring(0,begin);
					String afterSubstring  = path.substring(end);

					if (HandleParametersOption.IGNORE_COMPLETELY.equals(handleParameters) ) {
							cleanedPath = beforeSubstring + afterSubstring;
					} else {
						StringBuilder sb = new StringBuilder(beforeSubstring);
						
						matcher = patternResourceMultipleIdentifierDetail.matcher(multipleIdentifierSection);
						int i = 1;
						while (matcher.find()) {
							
							if (i >  1) {
								sb.append(',');
							}
							String paramName       = matcher.group(1);
							sb.append(paramName);
							i++;
						}
					
						sb.append(afterSubstring);
						cleanedPath = sb.toString();
					}
							
				} 
			}		
		}
		
		return cleanedPath;
	}
821056
private Map<String, String> resourceForPath(Path path) {
        return AuthorizationUtil.resource(STORAGE_PATH_AUTH_RES_TYPE, authResForPath(path));
    }
1014286
private String cleanSlashesFromPath(final String path) {
		if (path == null) {
			throw new IllegalArgumentException("createResource must be called with non-null resourceName!");
		}
		String workPath = path;
		if (workPath.charAt(0) == '/') {
			workPath = path.substring(1);
		}
		if (workPath.charAt(path.length() - 1) == '/') {
			workPath = path.substring(0, path.length() - 1);
		}
		return workPath;
	}
700984
public static String cleanPath(String path) {
        if (path.endsWith(SEPARATOR)) {
            path = path.replaceAll(SEPARATOR + "+$", "");
        }
        if (path.startsWith(SEPARATOR)) {
            path = path.replaceAll("^" + SEPARATOR + "+", "");
        }
        return path.replaceAll("/+", SEPARATOR);
    }
995847
private Set<Resource<T>> listStackDirectory(Path path) {
        HashSet<Resource<T>> merge = new HashSet<Resource<T>>();
        if (treeHandlerList.size() > 0) {
            for (SelectiveTree<T> treeHandler : treeHandlerList) {
                if (PathUtil.hasRoot(treeHandler.getSubPath(), path) && !PathUtil.equals(
                    treeHandler.getSubPath(),
                    path
                )) {
                    String relativePath = PathUtil.removePrefix(path.getPath(), treeHandler.getSubPath().getPath());
                    String[] components = PathUtil.componentsFromPathString(relativePath);
                    Path subpath = PathUtil.appendPath(path, components[0]);
                    merge.add(new ResourceBase<T>(subpath, null, true));
                }
            }
        }
        return merge;
    }
684801
public static String normalizePath(String path) {
    String normalizedPath = path.replaceAll("//+", "/").replaceFirst("(.+)/$", "$1");
    PathUtils.validatePath(normalizedPath);
    return normalizedPath;
  }
1248453
function paramsFromStringPath(path, paramsObj) {
        //Get all the parameter names from the path.
        var elements = path.split('/');
        var params = elements.reduce(function(params, element) {
            if (element.charAt(0) === ':') {
                var paramName = element.slice(1);
                params.push(paramsObj[paramName]);
            }
            return params;
        }, []);
        return params;
    }
397352
public static void deletePathRecursively(String path) throws IOException {
    if (!exists(path)) {
      return;
    }
    Path root = Paths.get(path);
    Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
      @Override
      public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
        Files.delete(file);
        return FileVisitResult.CONTINUE;
      }

      @Override
      public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
        if (e == null) {
          Files.delete(dir);
          return FileVisitResult.CONTINUE;
        } else {
          throw e;
        }
      }
    });
  }
23991
protected String normalizePath(String path) {

        if (path.equals("/")) {
            return path;
        } else {
            return CmsFileUtil.removeTrailingSeparator(path);
        }

    }
1119946
public ResolvedRequest withPath( String path ) {
        assert repositoryName != null;
        assert workspaceName != null;
        return new ResolvedRequest(request, repositoryName, workspaceName, path);
    }
555011
public static void get(@NotNull String path, @NotNull Handler handler) {
        staticInstance().get(prefixPath(path), handler);
    }
1342821
@RequestMapping(value = "/api/path/{pathId}", method = RequestMethod.DELETE)
    @ResponseBody
    public HashMap<String, Object> deletePath(Model model, @PathVariable int pathId,
                                              @RequestParam(value = "clientUUID", defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) throws Exception {
        EndpointOverride currentPath = PathOverrideService.getInstance().getPath(pathId);
        int profileId = currentPath.getProfileId();

        // remove the path
        logger.info("Removing path {}", pathId);
        PathOverrideService.getInstance().removePath(pathId);

        // return the remaining data
        List<EndpointOverride> paths = PathOverrideService.getInstance().getPaths(profileId, clientUUID, null);

        return Utils.getJQGridJSON(paths, "paths");
    }
156790
private <TResponse> void callServiceDeleteApi(
            String path, Map<String, String> queryParams) throws AuthleteApiException
    {
        callDeleteApi(mServiceCredentials, path, queryParams);
    }
969431
public static String normalizePath(String path)
    {
        StringBuilder sb = new StringBuilder(path);
        int lastToken = -1;
        for (int i = 0; i < sb.length(); i++)
        {
            if ((sb.charAt(i) == File.separatorChar)
                || (sb.charAt(i) == '/'))
            {
                if (lastToken != -1)
                {
                    if (i < sb.length() - 2)
                        if (sb.charAt(i + 1) == '.')
                            if (sb.charAt(i + 2) == '.')
                    {   // Remove last directory name from path
                        sb.delete(lastToken, i + 3);
                        i = lastToken;
                    }
                }
                lastToken = i;
            }
        }
        return sb.toString();
    }
943663
public static String clean(final String path, final boolean ascii) {
        int len = path.length(), ch;
        final StringBuilder buffer = new StringBuilder(len*3);
        // Change C:/something to /C:/something
        if (len >= 2 && path.charAt(1) == ':') {
            ch = Character.toUpperCase(path.charAt(0));
            if (ch >= 'A' && ch <= 'Z') {
                buffer.append('/');
            }
        }

        // For each character in the path
        int i = 0;
        for (; i < len; i++) {
            ch = path.charAt(i);
            if (ch == '%' && !isPercentEncoded(path.subSequence(i, ((i + 2) < len) ? (i + 3) : len))) {
                buffer.append('%').append('2').append('5');
                continue;
            }
            // If it's not an ASCII character, break here, and use UTF-8 encoding
            if (ch >= 128 && ascii) {
                break;
            }
            if (ch <  gNeedEscaping.length && gNeedEscaping[ch]) {
                buffer.append('%');
                buffer.append(gAfterEscaping1[ch]);
                buffer.append(gAfterEscaping2[ch]);
                // Record the fact that it's escaped
            } else {
                buffer.append((char)ch);
            }
        }

        // We saw some non-ASCII character
        if (i < len && ascii) {
            // Get UTF-8 bytes for the remaining sub-string
            byte[] bytes;
            byte b;
            bytes = path.substring(i).getBytes(StandardCharsets.UTF_8);
            len = bytes.length;

            // For each byte
            for (i = 0; i < len; i++) {
                b = bytes[i];
                // For non-ASCII character: make it positive, then escape
                if (b < 0) {
                    ch = b + 256;
                    buffer.append('%');
                    buffer.append(gHexChs[ch >> 4]);
                    buffer.append(gHexChs[ch & 0xf]);
                } else if (gNeedEscaping[b]) {
                    buffer.append('%');
                    buffer.append(gAfterEscaping1[b]);
                    buffer.append(gAfterEscaping2[b]);
                } else {
                    buffer.append((char)b);
                }
            }
        }
        return buffer.toString();
    }
989737
public Set<String> getResourcePaths(String path) {

		Set<String> result = new HashSet<String>();
		path = path.replace('/', File.separatorChar);
		File resource = new File(baseDir, path);

		// If the path is not valid throw an exception
		String[] resArray = resource.list();
		if (null == resArray)
			return result;

		// Make the returned dirs end with '/', to match a servletcontext
		// behavior.
		for (int i = 0; i < resArray.length; i++) {

			resArray[i] = path + resArray[i];
			if (isDirectory(resArray[i]))
				resArray[i] += '/';
		}
		result.addAll(Arrays.asList(resArray));

		return result;
	}
1187582
public static String getName(final String path) {

		String cleanedPath = clean(path);

		if (cleanedPath != null && cleanedPath.contains(PATH_SEP)) {

			return StringUtils.substringAfterLast(cleanedPath, PATH_SEP);

		} else {

			return cleanedPath;

		}
	}