Esempio n. 1
0
  /**
   * Adjust the viewID per the requirements of {@link #renderView}.
   *
   * @param context current {@link javax.faces.context.FacesContext}
   * @param viewId incoming view ID
   * @return the view ID with an altered suffix mapping (if necessary)
   */
  protected String convertViewId(FacesContext context, String viewId) {

    // if the viewId doesn't already use the above suffix,
    // replace or append.
    int extIdx = viewId.lastIndexOf('.');
    int length = viewId.length();
    StringBuilder buffer = new StringBuilder(length);

    for (String ext : configuredExtensions) {
      if (viewId.endsWith(ext)) {
        return viewId;
      }

      appendOrReplaceExtension(viewId, ext, length, extIdx, buffer);

      String convertedViewId = buffer.toString();
      try {
        if (context.getExternalContext().getResource(convertedViewId) != null) {
          // RELEASE_PENDING (rlubke,driscoll) cache the lookup
          return convertedViewId;
        }
      } catch (MalformedURLException e) {
        if (logger.isLoggable(Level.SEVERE)) {
          logger.log(Level.SEVERE, e.toString(), e);
        }
      }
    }

    // unable to find any resource match that the default ViewHandler
    // can deal with.  Fall back to legacy (JSF 1.2) id conversion.
    return legacyConvertViewId(viewId, length, extIdx, buffer);
  }
Esempio n. 2
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);
    }
  }
Esempio n. 3
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;
    }
  }
Esempio n. 4
0
  private String legacyConvertViewId(String viewId, int length, int extIdx, StringBuilder buffer) {

    // In 1.2, the viewId was converted by replacing the extension
    // with the single extension specified by javax.faces.DEFAULT_SUFFIX,
    // which defaulted to ".jsp".  In 2.0, javax.faces.DEFAULT_SUFFIX
    // may specify multiple extensions.  If javax.faces.DEFAULT_SUFFIX is
    // explicitly set, we honor it and pick off the first specified
    // extension.  If javax.faces.DEFAULT_SUFFIX is not explicitly set,
    // we honor the default 1.2 behavior and use ".jsp" as the suffix.

    String ext =
        (extensionsSet && !(configuredExtensions.length == 0)) ? configuredExtensions[0] : ".jsp";

    if (viewId.endsWith(ext)) {
      return viewId;
    }

    appendOrReplaceExtension(viewId, ext, length, extIdx, buffer);

    return buffer.toString();
  }