Returns the contextPath of the ServletContext or <code>null</code> for portlets

@param ec the current external context
@return a String containing the servletContextPath
437021
public static String getServletContextPath(ExternalContext ec)
    {
        if (!isPortlet(ec))
        {
            return ((ServletContext) ec.getContext()).getContextPath();
        }
        else
        {
            return null;
        }
    }
966045
public String getContextPath()
    {
        if (parentContext!=null && _useParent)
            return parentContext.getContextPath();
        String cp =null;
        if (_contextPath!=null)
            cp=_contextPath;
        else
            cp = getWebApp().getContextPath();
        if (cp.equals("/"))
        {
            return "";
        }
        else
        {
            return cp;
        }
    }
558830
public static ServletContextCache getCache(ServletContext servletContext) {
		ServletContextCache cache = (ServletContextCache)servletContext.getAttribute(ATTRIBUTE_KEY);
		if(cache == null) {
			// It is possible this is called during context initialization before the listener
			cache = new ServletContextCache(servletContext);
			servletContext.setAttribute(ATTRIBUTE_KEY, cache);
			//throw new IllegalStateException("ServletContextCache not active in the provided ServletContext.  Add context listener to web.xml?");
		} else {
			assert cache.servletContext == servletContext;
		}
		return cache;
	}
1193207
public String getContentResourcePath() {
        if (contentResourcePath != null && context != null) {
            return context.replaceDynamicContentInString(contentResourcePath);
        } else {
            return contentResourcePath;
        }
    }
1201703
public static ServletRequest getContextRequest()
    {
        ServiceContext context = (ServiceContext) _localContext.get();

        if (context != null)
            return context._request;
        else
            return null;
    }
526252
protected String getContextPath(){

        if(context != null) return context;

        if(get("context_path") == null){
            throw new ViewException("context_path missing - red alarm!");
        }
        return  get("context_path").toString();
    }
934152
public String getContextPath() {
        final Object contextPath = getHeader(HttpMessageHeaders.HTTP_CONTEXT_PATH);

        if (contextPath != null) {
            return contextPath.toString();
        }

        return null;
    }
685295
public static String getContextRequestUri(HttpServletRequest request) {
		String requestUri = request.getRequestURI();
		String contextPath = request.getContextPath();
		int cpLen = contextPath.length();
		if(cpLen > 0) {
			assert requestUri.startsWith(contextPath);
			return requestUri.substring(cpLen);
		} else {
			return requestUri;
		}
	}
745316
protected String getResourceServerContextPath() {
        final String resourceContextPath = this.servletContext.getInitParameter(RESOURCE_CONTEXT_INIT_PARAM);
        if (resourceContextPath == null) {
            // if no resource context path was defined in the web.xml, use the
            // default
            return DEFAULT_RESOURCE_CONTEXT;
        } 

        if (!resourceContextPath.startsWith("/")) {
            // ensure that our context starts with a slash
            return "/".concat(resourceContextPath);
        }
        
        return resourceContextPath;
    }
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;
        }
    }
824803
@Deprecated
	public static String getContextPath(final WebApplication application)
	{
		final String contextPath = application.getServletContext().getContextPath();
		if ((null != contextPath) && !contextPath.isEmpty())
		{
			return contextPath;
		}
		return "";
	}
30817
@Override
    public String getPath() {
        final String fullPath = request.getRequestURI();
        // it shouldn't be null, but in case it is, it's better to return empty string
        if (fullPath == null) {
            return "";
        }
        final String context = request.getContextPath();
        // this one shouldn't be null either, but in case it is, then let's consider it is empty
        if (context != null) {
            return fullPath.substring(context.length());
        }
        return fullPath;
    }
714360
final protected ServletBeanContext getServletBeanContext()
    {
        if (_beanContext == null)
        {
            ControlContainerContext ccc = ControlThreadContext.getContext();
            if (! (ccc instanceof ServletBeanContext))
                throw new IllegalStateException("No ServletBeanContext available");

            _beanContext = (ServletBeanContext)ccc;
        }
        return _beanContext;
    }
182938
public void setContextPath(String contextPathSpec)
    {
        if (_httpServer!=null)
            _httpServer.removeMappings(this);

        contextPathSpec=canonicalContextPathSpec(contextPathSpec);

        if (contextPathSpec.length()>1)
            _contextPath=contextPathSpec.substring(0,contextPathSpec.length()-2);
        else
            _contextPath="/";

        _contextName=null;

        if (_httpServer!=null)
            _httpServer.addMappings(this);
    }
568207
protected String getResourcePath(ParserContext parserContext) {
        if (parserContext != null) {
            try {
                Resource resource = parserContext.getReaderContext().getResource();
                return resource == null ? null : resource.getURL().getPath();
            } catch (IOException e) {}
        }
        
        return null;
    }
1081235
public static String getContextPath(ServletContext servletContext) {
		String contextPath = DEFAULT_CONTEXT_PATH;

		// Get the context path
		if (servletContext != null) {
			contextPath = servletContext.getContextPath();
			if (StringUtils.isEmpty(contextPath)) {
				contextPath = DEFAULT_CONTEXT_PATH;
			}
		}

		return contextPath;
	}
425036
public static WebApp get(ServletContext context) {
        Object o = context.getAttribute(WebApp.class.getName());
        if(o==null) {
            synchronized (WebApp.class) {
                o = context.getAttribute(WebApp.class.getName());
                if(o==null) {
                    o = new WebApp(context);
                    context.setAttribute(WebApp.class.getName(),o);
                }
            }
        }
        return (WebApp)o;
    }