Java Code Examples for com.vaadin.server.VaadinRequest#getPathInfo()

The following examples show how to use com.vaadin.server.VaadinRequest#getPathInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VertxVaadinService.java    From vertx-vaadin with MIT License 6 votes vote down vote up
@Override
public String getMainDivId(VaadinSession session, VaadinRequest request, Class<? extends UI> uiClass) {
    String appId = request.getPathInfo();
    if (appId == null || "".equals(appId) || "/".equals(appId)) {
        appId = "ROOT";
    }
    appId = appId.replaceAll("[^a-zA-Z0-9]", "");
    // Add hashCode to the end, so that it is still (sort of)
    // predictable, but indicates that it should not be used in CSS
    // and
    // such:
    int hashCode = appId.hashCode();
    if (hashCode < 0) {
        hashCode = -hashCode;
    }
    appId = appId + "-" + hashCode;
    return appId;
}
 
Example 2
Source File: SchemeRequestHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean hasPathPrefix(VaadinRequest request, String prefix) {
  String pathInfo = request.getPathInfo();

  if (pathInfo == null) {
    return false;
  }

  if (!prefix.startsWith("/")) {
    prefix = '/' + prefix;
  }

  if (pathInfo.startsWith(prefix)) {
    return true;
  }

  return false;
}
 
Example 3
Source File: VaadinAccessDeniedHandler.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * Test if current request is an UIDL request
 * @return true if in UIDL request, false otherwise
 */
private boolean isUidlRequest() {
	VaadinRequest request = VaadinService.getCurrentRequest();
	
	if (request == null)
		return false;
	
	 String pathInfo = request.getPathInfo();

	 if (pathInfo == null) {
            return false;
	 }
	 
	 if (pathInfo.startsWith("/" + ApplicationConstants.UIDL_PATH)) {
            return true;
        }

        return false;
}
 
Example 4
Source File: UrlBeanNameUiMapping.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * Try to match a ant url pattern in url mapping and return the UI bean name
 * @param request vaadin request
 * @return the bean name for request, null if none.
 */
protected String getBeanNameFromRequest(VaadinRequest request) {
	String beanName = null;
	String pathInfo = request.getPathInfo();
	
	if (this.pathMatcher == null)
		this.pathMatcher = new AntPathMatcher();
	
	for (String pattern : this.urlMap.keySet())  {
		if (log.isDebugEnabled())
			log.debug("Matching pattern [" + pattern + "] over path info [" + pathInfo + "]");
		
		if (this.pathMatcher.match(pattern, request.getPathInfo())) {
			beanName = this.urlMap.get(pattern);
			if (log.isDebugEnabled())
				log.debug("Matching success. Using bean name  [" + beanName + "]");
			
			break;
		}
	}
		
	if (beanName == null)
		beanName = request.getPathInfo();
	
	return beanName;
}
 
Example 5
Source File: CubaWebJarsHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException {
    String path = request.getPathInfo();
    if (StringUtils.isEmpty(path)
            || !path.startsWith(VAADIN_WEBJARS_PATH_PREFIX)) {
        return false;
    }

    log.trace("WebJar resource requested: {}", path.replace(VAADIN_WEBJARS_PATH_PREFIX, ""));

    String errorMessage = checkResourcePath(path);
    if (StringUtils.isNotEmpty(errorMessage)) {
        log.warn(errorMessage);
        response.sendError(HttpServletResponse.SC_FORBIDDEN, errorMessage);
        return false;
    }

    URL resourceUrl = getStaticResourceUrl(path);

    if (resourceUrl == null) {
        resourceUrl = getClassPathResourceUrl(path);
    }

    if (resourceUrl == null) {
        String msg = String.format("Requested WebJar resource is not found: %s", path);
        response.sendError(HttpServletResponse.SC_NOT_FOUND, msg);
        log.warn(msg);
        return false;
    }

    String resourceName = getResourceName(path);
    String mimeType = servletContext.getMimeType(resourceName);
    response.setContentType(mimeType != null ? mimeType : FileTypesHelper.DEFAULT_MIME_TYPE);

    long resourceCacheTime = getCacheTime();

    String cacheControl = resourceCacheTime > 0
            ? "max-age=" + String.valueOf(resourceCacheTime)
            : "public, max-age=0, no-cache, no-store, must-revalidate";
    response.setHeader("Cache-Control", cacheControl);

    long expires = resourceCacheTime > 0
            ? System.currentTimeMillis() + (resourceCacheTime * 1000)
            : 0;
    response.setDateHeader("Expires", expires);

    InputStream inputStream = null;
    try {
        URLConnection connection = resourceUrl.openConnection();
        long lastModifiedTime = connection.getLastModified();
        // Remove milliseconds to avoid comparison problems (milliseconds
        // are not returned by the browser in the "If-Modified-Since"
        // header).
        lastModifiedTime = lastModifiedTime - lastModifiedTime % 1000;
        response.setDateHeader("Last-Modified", lastModifiedTime);

        if (browserHasNewestVersion(request, lastModifiedTime)) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            return true;
        }

        inputStream = connection.getInputStream();

        copy(inputStream, response.getOutputStream());

        return true;
    } finally {
        if (inputStream != null) {
            inputStream.close();
        }
    }
}