Get base path. Copy pasted from StandardContext Tomcat class
540256
public String getBasePath() {
        String docBase = null;
        Container container = this;
        while (container != null) {
            if (container instanceof Host)
                break;
            container = container.getParent();
        }
        File file = new File(getDocBase());
        if (!file.isAbsolute()) {
            if (container == null) {
                docBase = (new File(engineBase(), getDocBase())).getPath();
            } else {
                // Use the "appBase" property of this container
                String appBase = ((Host) container).getAppBase();
                file = new File(appBase);
                if (!file.isAbsolute())
                    file = new File(engineBase(), appBase);
                docBase = (new File(file, getDocBase())).getPath();
            }
        } else {
            docBase = file.getPath();
        }
        return docBase;
    }
1095145
def _get_base_command(self):
        
        cd_command = ''.join(['cd ', str(self.WorkingDir), ';'])
        jvm_command = "java"
        jvm_args = self._commandline_join(
            [self.Parameters[k] for k in self._jvm_parameters])
        cp_args = '-cp "%s" %s' % (self._get_jar_fp(), self.TrainingClass)

        command_parts = [cd_command, jvm_command, jvm_args, cp_args]
        return self._commandline_join(command_parts).strip()
1136828
private static String getContextPathOverride(boolean isSslRequest, JawrConfig config) {
		String contextPathOverride = null;
		if (isSslRequest) {
			contextPathOverride = config.getContextPathSslOverride();
		} else {
			contextPathOverride = config.getContextPathOverride();
		}
		return contextPathOverride;
	}
567510
function getMockServerPath(rootPath, mockServerPath) {
    let result = mockServerPath || './src';

    if (!path.isAbsolute(result)) {
        result = path.resolve(rootPath, result);
    }

    return result;
}
255524
function getBasePaths(path, includes, useCaseSensitiveFileNames) {
        // Storage for our results in the form of literal paths (e.g. the paths as written by the user).
        var basePaths = [path];
        if (includes) {
            // Storage for literal base paths amongst the include patterns.
            var includeBasePaths = [];
            for (var _i = 0, includes_1 = includes; _i < includes_1.length; _i++) {
                var include = includes_1[_i];
                // We also need to check the relative paths by converting them to absolute and normalizing
                // in case they escape the base path (e.g "..\somedirectory")
                var absolute = isRootedDiskPath(include) ? include : normalizePath(combinePaths(path, include));
                var wildcardOffset = indexOfAnyCharCode(absolute, wildcardCharCodes);
                var includeBasePath = wildcardOffset < 0
                    ? removeTrailingDirectorySeparator(getDirectoryPath(absolute))
                    : absolute.substring(0, absolute.lastIndexOf(ts.directorySeparator, wildcardOffset));
                // Append the literal and canonical candidate base paths.
                includeBasePaths.push(includeBasePath);
            }
            // Sort the offsets array using either the literal or canonical path representations.
            includeBasePaths.sort(useCaseSensitiveFileNames ? compareStrings : compareStringsCaseInsensitive);
            // Iterate over each include base path and include unique base paths that are not a
            // subpath of an existing base path
            include: for (var i = 0; i < includeBasePaths.length; i++) {
                var includeBasePath = includeBasePaths[i];
                for (var j = 0; j < basePaths.length; j++) {
                    if (containsPath(basePaths[j], includeBasePath, path, !useCaseSensitiveFileNames)) {
                        continue include;
                    }
                }
                basePaths.push(includeBasePath);
            }
        }
        return basePaths;
    }
852415
def base_path(self):
        
        path = UrlPath()

        # Walk up the API to find the base object
        parent = self.parent
        while parent:
            path_prefix = getattr(parent, 'path_prefix', NoPath)
            path = path_prefix + path
            parent = getattr(parent, 'parent', None)

        return path
508542
function (basePath) {
    var fullPath = normalizePath(this.path, basePath) || '/';

    var markdown = '';
    if (this.title) {
      markdown += '# ' + this.title + '\n\n';
    }
    if (this.description) {
      markdown += this.description + '\n\n';
    }

    // Export own request handlers.
    for (var method in this.handlers) {
      var handler = this.handlers[method];
      markdown += '## ' + (handler.title || '(no title)') + '\n\n';
      markdown += '    ' + method.toUpperCase() + ' ' + fullPath + '\n\n';
      if (handler.description) {
        markdown += handler.description + '\n\n';
      }

      if (handler.examples && handler.examples.length > 0) {
        var example = handler.examples[0];

        var request = example.request || {};
        if (request.urlParameters || request.headers || request.body) {
          markdown += '### Example input:\n\n';
          var exampleURL = '    ' + method.toUpperCase() + ' ' + fullPath;
          if (request.urlParameters) {
            exampleURL = replaceUrlParameters(exampleURL,
              request.urlParameters);
          }
          markdown += exampleURL + '\n';
          var requestHeaders = request.headers || {};
          for (var header in requestHeaders) {
            markdown += '    ' + header + ': ' + requestHeaders[header] + '\n';
          }
          if (request.body) {
            var requestBody = '    ' + jsonStringifyIfObject(request.body)
              .trim().replace(/\n/g, '\n    ');
            markdown += '    \n' + requestBody + '\n';
          }
          markdown += '\n';
        }

        var response = example.response || {};
        var hasResponseStatus = isExplicitExample(response.status);
        var hasResponseBody = isExplicitExample(response.body);
        if (hasResponseStatus || response.headers || hasResponseBody) {
          markdown += '### Example response:\n\n';
          if (hasResponseStatus) {
            var message = http.STATUS_CODES[response.status];
            markdown += '    Status: ' + response.status + ' ' + message + '\n';
          }
          var responseHeaders = response.headers || {};
          for (var header in responseHeaders) {
            var value = responseHeaders[header];
            if (isExplicitExample(value)) {
              markdown += '    ' + header + ': ' + value + '\n';
            }
          }
          if (hasResponseBody) {
            if (hasResponseStatus || Object.keys(responseHeaders).length > 0) {
              markdown += '    \n';
            }
            markdown += '    ' + jsonStringifyIfObject(response.body).trim()
              .replace(/\n/g, '\n    ') + '\n';
          }
          markdown += '\n';
        }
        // TODO Document all unique possible status codes?
        // TODO Document all request parameters?
      }
    }

    // Export children's request handlers recursively.
    for (var path in this.children) {
      var child = this.children[path];
      markdown += child.toMarkdown(fullPath);
    }

    return markdown;
  }
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;
    }
269878
private static String getPath(final Object classpath) {
        final Object container = ReflectionUtils.getFieldVal(classpath, "container", false);
        if (container == null) {
            return "";
        }

        final Object delegate = ReflectionUtils.getFieldVal(container, "delegate", false);
        if (delegate == null) {
            return "";
        }

        final String path = (String) ReflectionUtils.getFieldVal(delegate, "path", false);
        if (path != null && path.length() > 0) {
            return path;
        }

        final Object base = ReflectionUtils.getFieldVal(delegate, "base", false);
        if (base == null) {
            // giving up.
            return "";
        }

        final Object archiveFile = ReflectionUtils.getFieldVal(base, "archiveFile", false);
        if (archiveFile != null) {
            final File file = (File) archiveFile;
            return file.getAbsolutePath();
        }
        return "";
    }
859017
public static void contextPath(String context) {
        if (S.blank(context)) ctx = "";
        else {
            E.illegalArgumentIf(!context.startsWith("/"), "context path should start with \"/\"");
            if (context.endsWith("/")) {
                ctx = S.str(context).beforeLast("/").toString();
            }
        }
    }
1287817
public static ArchivePath create(String basePath, String context) {
        return createInstance(new Class<?>[] { String.class, String.class }, new Object[] { basePath, context });
    }
1365858
function copycontext(context) {
    var t = {};
    var keys =  context.keys();
    var i = keys.length;
    var k, v, j;
    while (i--) {
      k = keys[i];
      if (k[0] == '_')
        continue;
      v = context.get(k);
      if (v && {}.toString.call(v) === '[object Function]')
        continue;

      try {
        j = JSON.stringify(v);
        t[k] = JSON.parse(j);
      } catch(err) {
        t[k] = "Exception: " + err;
      }
    }
    
    return t;
  }
440266
protected void setupClasspathJarResourceIfNeeds(WebAppContext context) {
        if (isWarableWorld() || !isValidMetaInfConfiguration()) {
            return;
        }
        // may be local development and uses meta-inf configuration here
        final List<String> classpathList = extractJarClassspathList();
        for (String classpath : classpathList) {
            final String jarPath = convertClasspathToJarPath(classpath);
            final URL url;
            try {
                url = new URL(jarPath);
            } catch (MalformedURLException e) {
                throw new IllegalStateException("Failed to create URL from the jar path: " + jarPath, e);
            }
            context.getMetaData().addContainerResource(new JarResource(url) {
            });
        }
    }
215574
protected String parseRequestUriWithoutContextPath(HttpServletRequest req){
        String requestUri = req.getRequestURI();
        String contextPath = req.getContextPath();
        requestUri = requestUri.substring(contextPath.length());
        if(requestUri.startsWith("/")){
            return requestUri;
        }else {
            return "/"+requestUri;
        }
    }
1163347
@OverrideOnDemand
  protected boolean linkNeedsContextPath (@Nullable final String sHref)
  {
    if (sHref == null)
      return false;

    // If prefix is defined and already present no need to change something
    // Or if the server prefix path is just "/" and the links starts with "/"
    // it's also fine
    if (sHref.startsWith (m_sServerPrefixPath))
      return false;

    // javascript: and mailto: are handled by URLProtocolRegistry
    if (URLProtocolRegistry.getInstance ().hasKnownProtocol (sHref) || sHref.startsWith ("#"))
      return false;

    // Prefix is needed
    return true;
  }
1327920
private static List getTomcatPaths()
    {
        String tomcatPath = System.getProperty("catalina.home");
        if (tomcatPath == null)
        {
            //not running Tomcat
            return null;
        }
        String commonClasspath = System.getProperty("common.loader");
        if (commonClasspath == null)
        {
            //didn't find the common classpath
            return null;
        }
        StringBuffer buffer = new StringBuffer(commonClasspath);
        String pathDeclaration = "${catalina.home}";
        int length = pathDeclaration.length();
        boolean doneReplace = false;
        do
        {
            int start = commonClasspath.indexOf(pathDeclaration);
            if (start >= 0)
            {
                buffer.replace(start, (start + length), tomcatPath);
                commonClasspath = buffer.toString();
            }
            else
            {
                doneReplace = true;
            }
        }
        while (!doneReplace);
        String[] paths = commonClasspath.split(",");

        List pathList = new ArrayList(paths.length);
        for (int i = 0; i < paths.length; i++) {
            String path = paths[i];
            pathList.add(getCanonicalPath(path));
        }
        return pathList;
    }
1293462
def _get_context_path(self, port):
        
        if self.proxy_base:
            return url_path_join(self.base_url, self.proxy_base)
        if self.absolute_url:
            return url_path_join(self.base_url, 'proxy', 'absolute', str(port))
        else:
            return url_path_join(self.base_url, 'proxy', str(port))