예제 #1
0
  // Utility method used by viewId conversion.  Appends the extension
  // if no extension is present.  Otherwise, replaces the extension.
  private void appendOrReplaceExtension(
      String viewId, String ext, int length, int extIdx, StringBuilder buffer) {

    buffer.setLength(0);
    buffer.append(viewId);

    if (extIdx != -1) {
      buffer.replace(extIdx, length, ext);
    } else {
      // no extension in the provided viewId, append the suffix
      buffer.append(ext);
    }
  }
예제 #2
0
  /**
   * if the specified mapping is a prefix mapping, and the provided request URI (usually the value
   * from <code>ExternalContext.getRequestServletPath()</code>) starts with <code>mapping + '/'
   * </code>, prune the mapping from the URI and return it, otherwise, return the original URI.
   *
   * @param uri the servlet request path
   * @param mapping the FacesServlet mapping used for this request
   * @return the URI without additional FacesServlet mappings
   * @since 1.2
   */
  protected String normalizeRequestURI(String uri, String mapping) {

    if (mapping == null || !Util.isPrefixMapped(mapping)) {
      return uri;
    } else {
      int length = mapping.length() + 1;
      StringBuilder builder = new StringBuilder(length);
      builder.append(mapping).append('/');
      String mappingMod = builder.toString();
      boolean logged = false;
      while (uri.startsWith(mappingMod)) {
        if (!logged && logger.isLoggable(Level.WARNING)) {
          logged = true;
          logger.log(
              Level.WARNING, "jsf.viewhandler.requestpath.recursion", new Object[] {uri, mapping});
        }
        uri = uri.substring(length - 1);
      }
      return uri;
    }
  }