/** * Gets a relative path you can use to refer to the context root. * * @param request * the request for which the location should be determined * @return A relative path to the context root. Never ends with a slash (/). * * @since 8.0.3 */ public static String getContextRootRelativePath(VaadinRequest request) { VaadinServletRequest servletRequest = (VaadinServletRequest) request; // Generate location from the request by finding how many "../" should // be added to the servlet path before we get to the context root String servletPath = servletRequest.getServletPath(); if (servletPath == null) { // Not allowed by the spec but servers are servers... servletPath = ""; } String pathInfo = servletRequest.getPathInfo(); if (pathInfo != null && !pathInfo.isEmpty()) { servletPath += pathInfo; } return getCancelingRelativePath(servletPath); }
@Override public String getStaticFileLocation(VaadinRequest request) { VaadinServletRequest servletRequest = (VaadinServletRequest) request; String staticFileLocation; // if property is defined in configurations, use that staticFileLocation = getDeploymentConfiguration().getResourcesPath(); if (staticFileLocation != null) { return staticFileLocation; } // the last (but most common) option is to generate default location // from request by finding how many "../" should be added to the // requested path before we get to the context root String requestedPath = servletRequest.getServletPath(); String pathInfo = servletRequest.getPathInfo(); if (pathInfo != null) { requestedPath += pathInfo; } return getCancelingRelativePath(requestedPath); }
/** * Gets a relative path you can use to refer to the context root. * * @param request * the request for which the location should be determined * @return A relative path to the context root. Never ends with a slash (/). */ public static String getContextRootRelativePath(VaadinRequest request) { VaadinServletRequest servletRequest = (VaadinServletRequest) request; // Generate location from the request by finding how many "../" should // be added to the servlet path before we get to the context root // Should not take pathinfo into account because the base URI refers to // the servlet path String servletPath = servletRequest.getServletPath(); assert servletPath != null; if (!servletPath.endsWith("/")) { servletPath += "/"; } return ServletHelper.getCancelingRelativePath(servletPath); }