Example #1
0
  /**
   * Utility method to check if JSF 2.0 Facelets should be disabled. If it's not explicitly disabled
   * by the context init parameter, then check the version of the WEB-INF/faces-config.xml document.
   * If the version is less than 2.0, then override the default value for the context init parameter
   * so that other parts of the system that use that config option will know it has been disabled.
   *
   * <p>NOTE: Since this method overrides a configuration value, it should be called before *any*
   * document parsing is performed the configuration value may be queried by the <code>ConfigParser
   * </code>s.
   *
   * @param webconfig configuration for this application
   * @param facesConfigInfo object representing WEB-INF/faces-config.xml
   * @return <code>true</code> if Facelets should be disabled
   */
  private boolean isFaceletsDisabled(
      WebConfiguration webconfig, WebInfFacesConfigInfo facesConfigInfo) {

    boolean isFaceletsDisabled = webconfig.isOptionEnabled(DisableFaceletJSFViewHandler);
    if (!isFaceletsDisabled) {
      // if not explicitly disabled, make a sanity check against
      // /WEB-INF/faces-config.xml
      isFaceletsDisabled = !facesConfigInfo.isVersionGreaterOrEqual(2.0);
      webconfig.overrideContextInitParameter(DisableFaceletJSFViewHandler, isFaceletsDisabled);
    }
    return isFaceletsDisabled;
  }
Example #2
0
  /**
   * This method bootstraps JSF based on the parsed configuration resources.
   *
   * @param sc the <code>ServletContext</code> for the application that requires initialization
   */
  public void initialize(ServletContext sc) {

    if (!hasBeenInitialized(sc)) {
      initializedContexts.add(sc);
      try {
        WebConfiguration webConfig = WebConfiguration.getInstance(sc);
        boolean validating = webConfig.isOptionEnabled(ValidateFacesConfigFiles);
        ExecutorService executor = createExecutorService();

        Document[] facesDocuments =
            getConfigDocuments(sc, getFacesConfigResourceProviders(), executor, validating);

        WebInfFacesConfigInfo facesConfigInfo =
            new WebInfFacesConfigInfo(facesDocuments[facesDocuments.length - 1]);

        facesDocuments = sortDocuments(facesDocuments, facesConfigInfo);

        boolean isFaceletsDisabled = isFaceletsDisabled(webConfig, facesConfigInfo);
        if (!facesConfigInfo.isMetadataComplete()) {
          // execute the Task responsible for finding annotation classes
          Future<Map<Class<? extends Annotation>, Set<Class<?>>>> annotationScan =
              executor.submit(new AnnotationScanTask(sc));
          pushTaskToContext(sc, annotationScan);
        }

        // process the ordered documents
        FACES_CONFIG_PROCESSOR_CHAIN.process(facesDocuments);
        if (!isFaceletsDisabled) {
          FACELET_TAGLIB_CONFIG_PROCESSOR_CHAIN.process(
              getConfigDocuments(sc, getFaceletConfigResourceProviders(), executor, validating));
        }

        executor.shutdown();
        publishPostConfigEvent();
      } catch (Exception e) {
        // clear out any configured factories
        releaseFactories();
        if (LOGGER.isLoggable(Level.INFO)) {
          LOGGER.log(Level.INFO, "Unsanitized stacktrace from failed start...", e);
        }
        Throwable t = unwind(e);
        throw new ConfigurationException("CONFIGURATION FAILED! " + t.getMessage(), t);
      } finally {
        sc.removeAttribute(ANNOTATIONS_SCAN_TASK_KEY);
      }
    }
  }