agave-files/files-core/src/main/java/org/iplantc/service/io/util/PathResolver.java
/**
	 * Extracts the virtual path on a remote file system from the original
	 * URL request path made to the Files API. 
	 * 
	 * @param owner the system owner
	 * @param originalPath the full url path of the request made to the files api.
	 * @return resolved agave path for the url
	 * @throws IOException if the path cannot be parsed
	 */
Extracts the virtual path on a remote file system from the original
URL request path made to the Files API.

@param owner the system owner
@param originalPath the full url path of the request made to the files api.
@return resolved agave path for the url
@throws IOException if the path cannot be parsed
Extracts the virtual path on a remote file system from the original URL request path made to the Files API . @param owner the system owner @param originalPath the full url path of the request made to the files api . @return resolved agave path for the url @throws IOException if the path cannot be parsed
public static String resolve(String owner, String originalPath) throws IOException 
	{
		String path = originalPath;
		if (!path.startsWith("/files")) path = "/files" + path;
		String[] endpoints = { "listings", "media", "pems", "meta", "history", "index" };
		String[] segments = path.substring(1).split("/", -1);
		if (segments.length > 3 && segments[0].equals("files") &&
				ArrayUtils.contains(endpoints, segments[1]) &&
				segments[2].equals("system")) 
		{	
			if (segments.length == 4)
			{
				path = "";
			}
			else
			{
				List<String> segmentList = new ArrayList<>(Arrays.asList(segments).subList(4, segments.length));
				path = ServiceUtils.explode("/", segmentList);
			}
		} 
		else if (segments.length > 1 && segments[0].equals("files") && 
				ArrayUtils.contains(endpoints, segments[1])) 
		{
			if (segments.length == 2) 
			{
				path = "";
			} 
			else 
			{
				List<String> segmentList = new ArrayList<String>(Arrays.asList(segments).subList(2, segments.length));
				path = ServiceUtils.explode("/", segmentList);
			}
		} else {
			throw new IOException("Unrecognized URL structure for path " + path);
		}
		if (path.equals(" ")) {
			path = "/";
		} else {
			path = StringUtils.replace(path, "/ /",  "//");
		}
        Pattern regexDriveLetter = Pattern.compile("^[a-zA-Z]:");
        Pattern regexSlash = Pattern.compile("\\\\");
        path = regexDriveLetter.matcher(path).replaceAll("");
        path = regexSlash.matcher(path).replaceAll("/");
		return path; 
	}
public static String resolve ( String owner , String originalPath ) throws IOException { String path = originalPath ; if ( ! path . startsWith ( "/files" ) ) path = "/files" + path ; String [ ] endpoints = { "listings" , "media" , "pems" , "meta" , "history" , "index" } ; String [ ] segments = path . substring ( 1 ) . split ( "/" , - 1 ) ; if ( segments . length > 3 && segments [ 0 ] . equals ( "files" ) && ArrayUtils . contains ( endpoints , segments [ 1 ] ) && segments [ 2 ] . equals ( "system" ) ) { if ( segments . length == 4 ) { path = "" ; } else { List < String > segmentList = new ArrayList < > ( Arrays . asList ( segments ) . subList ( 4 , segments . length ) ) ; path = ServiceUtils . explode ( "/" , segmentList ) ; } } else if ( segments . length > 1 && segments [ 0 ] . equals ( "files" ) && ArrayUtils . contains ( endpoints , segments [ 1 ] ) ) { if ( segments . length == 2 ) { path = "" ; } else { List < String > segmentList = new ArrayList < String > ( Arrays . asList ( segments ) . subList ( 2 , segments . length ) ) ; path = ServiceUtils . explode ( "/" , segmentList ) ; } } else { throw new IOException ( "Unrecognized URL structure for path " + path ) ; } if ( path . equals ( " " ) ) { path = "/" ; } else { path = StringUtils . replace ( path , "/ /" , "//" ) ; } Pattern regexDriveLetter = Pattern . compile ( "^[a-zA-Z]:" ) ; Pattern regexSlash = Pattern . compile ( "\\\\" ) ; path = regexDriveLetter . matcher ( path ) . replaceAll ( "" ) ; path = regexSlash . matcher ( path ) . replaceAll ( "/" ) ; return path ; }
Extracts the virtual path on a remote file system from the original
 URL request path made to the Files API.
Extracts the virtual path on a remote file system from the original URL request path made to the Files API .
// this will drop the webapp name which probably won't match the IO service route // adjust for calling service natively without loadbalancer in front //FileUtils.getPathStack(path); // they specified the system id as the next token. drop it. // their default system is implied. the structure is /files/$media[$path] // Convert Windows-format paths to sensible paths