Get a URI relative to a given webapp root.

@param contextPath the webapp context path, e.g., "/myWebapp"
@param uri the URI which should be made relative.
182300
public static final String getRelativeURI( String contextPath, String uri )
    {
        String requestUrl = uri;
        int overlap = requestUrl.indexOf( contextPath + '/' );
        assert overlap != -1 : "contextPath: " + contextPath + ", uri: " + uri;
        return requestUrl.substring( overlap + contextPath.length() );
    }
866978
@Override
    public String getContextPath() {
        final HttpServletRequest request = getCurrentRequest();
        String appUri = (String) request.getAttribute(GrailsApplicationAttributes.APP_URI_ATTRIBUTE);
        if (appUri == null) {
            appUri = urlHelper.getContextPath(request);
        }
        return appUri;
    }
824803
@Deprecated
	public static String getContextPath(final WebApplication application)
	{
		final String contextPath = application.getServletContext().getContextPath();
		if ((null != contextPath) && !contextPath.isEmpty())
		{
			return contextPath;
		}
		return "";
	}
969487
static String cleanContextPath(String contextPath) {
        // Special handling so that / can be used for the root context as well
        if (contextPath.equals("/") || contextPath.trim().equals("")) {
            return "";
        } else if (!contextPath.startsWith("/")) {
            return "/" + contextPath;
        } else {
            return contextPath;
        }
    }
1159703
public static URI getRelativePath(final URI relativePath) {
        final StringTokenizer tokenizer = new StringTokenizer(relativePath.toString(), URI_SEPARATOR);
        final StringBuilder buffer = new StringBuilder();
        if (tokenizer.countTokens() == 1) {
            return null;
        } else {
            while(tokenizer.countTokens() > 1) {
                tokenizer.nextToken();
                buffer.append("..");
                buffer.append(URI_SEPARATOR);
            }
            return toURI(buffer.toString());
        }
    }
431117
@NonNull
    public static Uri getUri(@NonNull Context context, @NonNull File outPath) {
        Uri uri;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
            uri = Uri.fromFile(outPath);
        } else {
            uri = CameraFileProvider.getUriForFile(context, CameraFileProvider.getProviderName(context), outPath);
        }
        return uri;
    }
1337097
@SuppressLint("NewApi")
    public static String getPath(final Context context, final Uri uri) {

        final boolean isKitKat = BuildUtils.isKitKat();

        // DocumentProvider
        if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
            // ExternalStorageProvider
            if (isExternalStorageDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                if ("primary".equalsIgnoreCase(type)) {
                    return Environment.getExternalStorageDirectory() + "/" + split[1];
                }

                // TODO handle non-primary volumes
            }
            // DownloadsProvider
            else if (isDownloadsDocument(uri)) {

                final String id = DocumentsContract.getDocumentId(uri);
                final Uri contentUri = ContentUris.withAppendedId(
                        Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

                return getDataColumn(context, contentUri, null, null);
            }
            // MediaProvider
            else if (isMediaDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                Uri contentUri = null;
                if ("image".equals(type)) {
                    contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                } else if ("video".equals(type)) {
                    contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                } else if ("audio".equals(type)) {
                    contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                }

                final String selection = "_id=?";
                final String[] selectionArgs = new String[] {
                        split[1]
                };

                return getDataColumn(context, contentUri, selection, selectionArgs);
            }
        }
        // MediaStore (and general)
        else if ("content".equalsIgnoreCase(uri.getScheme())) {
            return getDataColumn(context, uri, null, null);
        }
        // File
        else if ("file".equalsIgnoreCase(uri.getScheme())) {
            return uri.getPath();
        }

        return null;
    }
199090
public String resolveRelativeUri(String uri) {
        // sometimes we get uri's massaged from File(String), so check for
        // a root directory separator char
        if (uri.startsWith("/") || uri.startsWith(File.separator)) {
            return uri;
        } else {
            return baseURI + uri;
        }
    }
625015
public ServletContext getContext(String uripath) {
        ServletContext theContext = null;
        if (SecurityUtil.isPackageProtectionEnabled()) {
            theContext = (ServletContext)
                doPrivileged("getContext", new Object[]{uripath});
        } else {
            theContext = context.getContext(uripath);
        }
        if ((theContext != null) &&
            (theContext instanceof ConvergedApplicationContext)){
            theContext = ((ConvergedApplicationContext)theContext).getFacade();
        }
        return (theContext);
    }
119966
public static String getContextPath() {
        if (null != contextPath) {
            return contextPath;
        }

        final String contextPathConf = getLatkeProperty("contextPath");
        if (null != contextPathConf) {
            contextPath = contextPathConf;

            return contextPath;
        }

        final ServletContext servletContext = AbstractServletListener.getServletContext();
        contextPath = servletContext.getContextPath();

        return contextPath;
    }
799593
@NonNull
    public static Uri getUriForFile(@NonNull Context context, @NonNull File file) {
        return getUriForFile(context, Directory.ROOT, file.getPath());
    }
196320
private String buildServletPath() {
    String uri = servletPath;
    if (uri == null && null != requestURI) {
      uri = requestURI;
      if (!contextPath.equals("/")) uri = uri.substring(contextPath.length());
    }
    return (null == uri) ? "" : uri;
  }
315209
private String getServletPath(final String relativePath) {

		if (relativePath == null) {
			LOG.error("relativePath must not be null");
		}

		String context = getHostFreeBaseUrl();

		if (!Util.empty(context)) {
			return context + relativePath;
		}

		return relativePath;
	}
1034540
def _relative(self, uri):
        

        if uri.startswith("http:") or \
           uri.startswith("https:") or \
           uri.startswith("file:") or \
           uri.startswith("/"):
            return uri

        elif exists(uri):
            return relpath(uri, self.basedir)

        else:
            return uri
70016
public String getUserResourceUri(final String path){
        if(StringUtils.isEmpty(path)) {
            throw new IllegalArgumentException("Path cannot be null");
        }
        return StringUtils.join(new String[] {getUserUri(), path}, "/");
    }
736127
@Override
    public String getContextPath() {
        ServletRESTRequestImpl ret = castRequest();
        if (ret != null)
            return ret.getContextPath();
        return null;
    }
52128
public HttpLogEntry withRequestUri(String uri, String path) {
    this.requestUri = uri;
    this.path = path;
    return this;
  }