public ClasspathResourceHelper() {

    WebConfiguration webconfig = WebConfiguration.getInstance();
    cacheTimestamp = webconfig.isOptionEnabled(CacheResourceModificationTimestamp);
    enableMissingResourceLibraryDetection =
        webconfig.isOptionEnabled(EnableMissingResourceLibraryDetection);
  }
예제 #2
0
  /** Construct a new <code>ServerSideStateHelper</code> instance. */
  public ServerSideStateHelper() {

    numberOfLogicalViews = getIntegerConfigValue(NumberOfLogicalViews);
    numberOfViews = getIntegerConfigValue(NumberOfViews);
    WebConfiguration webConfig = WebConfiguration.getInstance();
    generateUniqueStateIds = webConfig.isOptionEnabled(GenerateUniqueServerStateIds);
    if (generateUniqueStateIds) {
      random = new Random(System.nanoTime() + webConfig.getServletContext().hashCode());
    } else {
      random = null;
    }
    namespaceParameters = webConfig.isOptionEnabled(NamespaceParameters);
  }
예제 #3
0
 private void initScripting() {
   if (webConfig.isOptionEnabled(EnableGroovyScripting)) {
     GroovyHelper helper = GroovyHelperFactory.createHelper();
     if (helper != null) {
       helper.setClassLoader();
     }
   }
 }
예제 #4
0
  public ApplicationAssociate(ApplicationImpl appImpl) {
    app = appImpl;

    propertyEditorHelper = new PropertyEditorHelper(appImpl);

    FacesContext ctx = FacesContext.getCurrentInstance();
    if (ctx == null) {
      throw new IllegalStateException(
          MessageUtils.getExceptionMessageString(
              MessageUtils.APPLICATION_ASSOCIATE_CTOR_WRONG_CALLSTACK_ID));
    }
    ExternalContext externalContext = ctx.getExternalContext();
    if (null != externalContext.getApplicationMap().get(ASSOCIATE_KEY)) {
      throw new IllegalStateException(
          MessageUtils.getExceptionMessageString(MessageUtils.APPLICATION_ASSOCIATE_EXISTS_ID));
    }
    externalContext.getApplicationMap().put(ASSOCIATE_KEY, this);
    //noinspection CollectionWithoutInitialCapacity
    navigationMap = new ConcurrentHashMap<String, Set<NavigationCase>>();
    injectionProvider = InjectionProviderFactory.createInstance(externalContext);
    WebConfiguration webConfig = WebConfiguration.getInstance(externalContext);
    beanManager =
        new BeanManager(injectionProvider, webConfig.isOptionEnabled(EnableLazyBeanValidation));
    // install the bean manager as a system event listener for custom
    // scopes being destoryed.
    app.subscribeToEvent(PreDestroyCustomScopeEvent.class, ScopeContext.class, beanManager);
    annotationManager = new AnnotationManager();

    groovyHelper = GroovyHelper.getCurrentInstance();

    devModeEnabled = (appImpl.getProjectStage() == ProjectStage.Development);
    // initialize Facelets
    if (!webConfig.isOptionEnabled(DisableFaceletJSFViewHandler)) {
      compiler = createCompiler(webConfig);
      faceletFactory = createFaceletFactory(compiler, webConfig);
    }

    if (!devModeEnabled) {
      resourceCache = new ResourceCache();
    }

    resourceManager = new ResourceManager(resourceCache);
    namedEventManager = new NamedEventManager();
    applicationStateInfo = new ApplicationStateInfo();
  }
예제 #5
0
  private boolean shouldInitConfigMonitoring() {

    boolean development = isDevModeEnabled();
    boolean threadingOptionSpecified = webConfig.isSet(EnableThreading);
    if (development && !threadingOptionSpecified) {
      return true;
    }
    boolean threadingOption = webConfig.isOptionEnabled(EnableThreading);
    return (development && threadingOptionSpecified && threadingOption);
  }
예제 #6
0
  public ApplicationAssociate(ApplicationImpl appImpl) {
    app = appImpl;

    propertyEditorHelper = new PropertyEditorHelper(appImpl);

    FacesContext ctx = FacesContext.getCurrentInstance();
    if (ctx == null) {
      throw new IllegalStateException(
          MessageUtils.getExceptionMessageString(
              MessageUtils.APPLICATION_ASSOCIATE_CTOR_WRONG_CALLSTACK_ID));
    }
    ExternalContext externalContext = ctx.getExternalContext();
    if (null != externalContext.getApplicationMap().get(ASSOCIATE_KEY)) {
      throw new IllegalStateException(
          MessageUtils.getExceptionMessageString(MessageUtils.APPLICATION_ASSOCIATE_EXISTS_ID));
    }
    externalContext.getApplicationMap().put(ASSOCIATE_KEY, this);
    //noinspection CollectionWithoutInitialCapacity
    caseListMap = new HashMap<String, List<ConfigNavigationCase>>();
    wildcardMatchList = new TreeSet<String>(new SortIt());
    injectionProvider = InjectionProviderFactory.createInstance(externalContext);
    WebConfiguration webConfig = WebConfiguration.getInstance(externalContext);
    beanManager =
        new BeanManager(
            injectionProvider,
            webConfig.isOptionEnabled(BooleanWebContextInitParameter.EnableLazyBeanValidation));
    annotationManager = new AnnotationManager();

    groovyHelper = GroovyHelper.getCurrentInstance();

    // initialize Facelets
    if (!webConfig.isOptionEnabled(BooleanWebContextInitParameter.DisableFaceletJSFViewHandler)) {
      compiler = createCompiler(webConfig);
      faceletFactory = createFaceletFactory(compiler, webConfig);
      devModeEnabled = (appImpl.getProjectStage() == ProjectStage.Development);
    }

    if (devModeEnabled) {
      resourceCache = new ResourceCache();
    }
    resourceManager = new ResourceManager(resourceCache);
  }
예제 #7
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, FacesConfigInfo 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;
  }
예제 #8
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);
      }
    }
  }
예제 #9
0
  protected Compiler createCompiler(WebConfiguration webConfig) {

    Compiler c = new SAXCompiler();

    // load decorators
    String decParam = webConfig.getOptionValue(FaceletsDecorators);
    if (decParam != null) {
      decParam = decParam.trim();
      String[] decs = Util.split(decParam, ";");
      TagDecorator decObj;
      for (String decorator : decs) {
        try {
          decObj = (TagDecorator) ReflectionUtil.forName(decorator).newInstance();
          c.addTagDecorator(decObj);

          if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.log(Level.FINE, "Successfully Loaded Decorator: {0}", decorator);
          }
        } catch (Exception e) {
          if (LOGGER.isLoggable(Level.SEVERE)) {
            LOGGER.log(Level.SEVERE, "Error Loading Decorator: " + decorator, e);
          }
        }
      }
    }

    // skip params?
    c.setTrimmingComments(
        webConfig.isOptionEnabled(BooleanWebContextInitParameter.FaceletsSkipComments));

    c.addTagLibrary(new CoreLibrary());
    c.addTagLibrary(new HtmlLibrary());
    c.addTagLibrary(new UILibrary());
    c.addTagLibrary(new JstlCoreLibrary());
    c.addTagLibrary(
        new FunctionLibrary(JstlFunction.class, "http://java.sun.com/jsp/jstl/functions"));
    if (isDevModeEnabled()) {
      c.addTagLibrary(
          new FunctionLibrary(DevTools.class, "http://java.sun.com/mojarra/private/functions"));
    }
    c.addTagLibrary(new CompositeLibrary());
    c.addTagLibrary(new XmlLibrary());

    return c;
  }
예제 #10
0
  /**
   * Renders the Javascript necessary to add and remove request parameters to the current form.
   *
   * @param writer the <code>ResponseWriter</code>
   * @param context the <code>FacesContext</code> for the current request
   * @throws java.io.IOException if an error occurs writing to the response
   */
  public static void renderFormInitScript(ResponseWriter writer, FacesContext context)
      throws IOException {
    WebConfiguration webConfig = WebConfiguration.getInstance(context.getExternalContext());

    if (webConfig.isOptionEnabled(BooleanWebContextInitParameter.ExternalizeJavaScript)) {
      // PENDING
      // We need to look into how to make this work in a portlet environment.
      // For the time being, this feature will need to be disabled when running
      // in a portlet.
      /*
      String mapping = Util.getFacesMapping(context);
      String uri;
      if ((mapping != null) && (Util.isPrefixMapped(mapping))) {
          uri = mapping + '/' + RIConstants.SUN_JSF_JS_URI;
      } else {
          uri = '/' + RIConstants.SUN_JSF_JS_URI + mapping;
      }
      writer.write('\n');
      writer.startElement("script", null);
      writer.writeAttribute("type", "text/javascript", null);
      writer.writeAttribute("src",
                            context.getExternalContext()
                                  .getRequestContextPath() + uri,
                            null);
      writer.endElement("script");
      writer.write("\n");
      */
      ResourceHandler handler = context.getApplication().getResourceHandler();
      Resource resource = handler.createResource("scripts/sunjsf.js", "jsfri");
      writer.write('\n');
      writer.startElement("script", null);
      writer.writeAttribute("type", "text/javascript", null);
      writer.writeAttribute("src", ((resource != null) ? resource.getRequestPath() : ""), null);
      writer.endElement("script");
    } else {
      writer.write('\n');
      writer.startElement("script", null);
      writer.writeAttribute("type", "text/javascript", null);
      writer.writeAttribute("language", "Javascript", null);
      writeSunJS(context, writer);
      writer.endElement("script");
      writer.write("\n");
    }
  }
예제 #11
0
  protected Compiler createCompiler(WebConfiguration webConfig) {

    Compiler c = new SAXCompiler();

    // load decorators
    String decParam =
        webConfig.getOptionValue(WebConfiguration.WebContextInitParameter.FaceletsDecorators);
    if (decParam != null) {
      decParam = decParam.trim();
      String[] decs = Util.split(decParam, ";");
      TagDecorator decObj;
      for (int i = 0; i < decs.length; i++) {
        try {
          decObj = (TagDecorator) ReflectionUtil.forName(decs[i]).newInstance();
          c.addTagDecorator(decObj);

          if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.log(Level.FINE, "Successfully Loaded Decorator: {0}", decs[i]);
          }
        } catch (Exception e) {
          if (LOGGER.isLoggable(Level.SEVERE)) {
            LOGGER.log(Level.SEVERE, "Error Loading Decorator: " + decs[i], e);
          }
        }
      }
    }

    // skip params?
    c.setTrimmingComments(
        webConfig.isOptionEnabled(BooleanWebContextInitParameter.FaceletsSkipComments));

    c.addTagLibrary(new CoreLibrary());
    c.addTagLibrary(new HtmlLibrary());
    c.addTagLibrary(new UILibrary());
    c.addTagLibrary(new JstlCoreLibrary());
    c.addTagLibrary(new JstlFnLibrary());
    c.addTagLibrary(new CompositeLibrary());

    return c;
  }
예제 #12
0
  public ExternalContextImpl(ServletContext sc, ServletRequest request, ServletResponse response) {

    // Validate the incoming parameters
    try {
      Util.notNull("sc", sc);
      Util.notNull("request", request);
      Util.notNull("response", response);
    } catch (Exception e) {
      throw new FacesException(
          MessageUtils.getExceptionMessageString(
              MessageUtils.FACES_CONTEXT_CONSTRUCTION_ERROR_MESSAGE_ID));
    }

    // Save references to our context, request, and response
    this.servletContext = sc;
    this.request = request;
    this.response = response;
    WebConfiguration config = WebConfiguration.getInstance(sc);
    if (config.isOptionEnabled(BooleanWebContextInitParameter.SendPoweredByHeader)) {
      ((HttpServletResponse) response).addHeader("X-Powered-By", "JSF/2.0");
    }
  }
예제 #13
0
  /** Initialize the core Facelets runtime. */
  protected void initialize() {

    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("Initializing FaceletViewHandlingStrategy");
    }

    this.initializeMappings();
    WebConfiguration config = WebConfiguration.getInstance();
    partialStateSaving = config.isOptionEnabled(PartialStateSaving);

    if (partialStateSaving) {
      String[] viewIds = config.getOptionValue(FullStateSavingViewIds, ",");
      fullStateViewIds = new HashSet<String>(viewIds.length, 1.0f);
      fullStateViewIds.addAll(Arrays.asList(viewIds));
      this.stateManagementStrategy = new StateManagementStrategyImpl(this);
    }

    groovyAvailable = GroovyHelper.isGroovyAvailable(FacesContext.getCurrentInstance());

    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("Initialization Successful");
    }
  }
예제 #14
0
  /**
   * Constructor sets the <code>ResponseWriter</code> and encoding.
   *
   * <p>The argument configPrefs is a map of configurable prefs that affect this instance's
   * behavior. Supported keys are:
   *
   * <p>BooleanWebContextInitParameter.EnableJSStyleHiding: <code>true</code> if the writer should
   * attempt to hide JS from older browsers
   *
   * @param writer the <code>ResponseWriter</code>
   * @param contentType the content type.
   * @param encoding the character encoding.
   * @throws javax.faces.FacesException the encoding is not recognized.
   */
  public HtmlResponseWriter(
      Writer writer,
      String contentType,
      String encoding,
      Boolean isScriptHidingEnabled,
      Boolean isScriptInAttributeValueEnabled,
      WebConfiguration.DisableUnicodeEscaping disableUnicodeEscaping)
      throws FacesException {

    this.writer = writer;

    if (null != contentType) {
      this.contentType = contentType;
    }

    this.encoding = encoding;

    // init those configuration parameters not yet initialized
    WebConfiguration webConfig = null;
    if (isScriptHidingEnabled == null) {
      webConfig = getWebConfiguration(webConfig);
      isScriptHidingEnabled =
          (null == webConfig)
              ? BooleanWebContextInitParameter.EnableJSStyleHiding.getDefaultValue()
              : webConfig.isOptionEnabled(BooleanWebContextInitParameter.EnableJSStyleHiding);
    }

    if (isScriptInAttributeValueEnabled == null) {
      webConfig = getWebConfiguration(webConfig);
      isScriptInAttributeValueEnabled =
          (null == webConfig)
              ? BooleanWebContextInitParameter.EnableScriptInAttributeValue.getDefaultValue()
              : webConfig.isOptionEnabled(
                  BooleanWebContextInitParameter.EnableScriptInAttributeValue);
    }

    if (disableUnicodeEscaping == null) {
      webConfig = getWebConfiguration(webConfig);
      disableUnicodeEscaping =
          WebConfiguration.DisableUnicodeEscaping.getByValue(
              (null == webConfig)
                  ? WebConfiguration.WebContextInitParameter.DisableUnicodeEscaping
                      .getDefaultValue()
                  : webConfig.getOptionValue(
                      WebConfiguration.WebContextInitParameter.DisableUnicodeEscaping));
      if (disableUnicodeEscaping == null) {
        disableUnicodeEscaping = WebConfiguration.DisableUnicodeEscaping.False;
      }
    }

    // and store them for later use
    this.isScriptHidingEnabled = isScriptHidingEnabled;
    this.isScriptInAttributeValueEnabled = isScriptInAttributeValueEnabled;
    this.disableUnicodeEscaping = disableUnicodeEscaping;

    this.attributesBuffer = new FastStringWriter(128);

    // Check the character encoding
    if (!HtmlUtils.validateEncoding(encoding)) {
      throw new IllegalArgumentException(
          MessageUtils.getExceptionMessageString(MessageUtils.ENCODING_ERROR_MESSAGE_ID));
    }

    String charsetName = encoding.toUpperCase();

    switch (disableUnicodeEscaping) {
      case True:
        // html escape noting (except the dangerous characters like "<>'" etc
        escapeUnicode = false;
        escapeIso = false;
        break;
      case False:
        // html escape any non-ascii character
        escapeUnicode = true;
        escapeIso = true;
        break;
      case Auto:
        // is stream capable of rendering unicode, do not escape
        escapeUnicode = !HtmlUtils.isUTFencoding(charsetName);
        // is stream capable of rendering unicode or iso-8859-1, do not escape
        escapeIso =
            !HtmlUtils.isISO8859_1encoding(charsetName) && !HtmlUtils.isUTFencoding(charsetName);
        break;
    }
  }
예제 #15
0
  public void contextInitialized(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();

    Timer timer = Timer.getInstance();
    if (timer != null) {
      timer.startTiming();
    }

    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.log(
          Level.FINE,
          MessageFormat.format(
              "ConfigureListener.contextInitialized({0})", getServletContextIdentifier(context)));
    }

    webConfig = WebConfiguration.getInstance(context);
    ConfigManager configManager = ConfigManager.getInstance();

    if (configManager.hasBeenInitialized(context)) {
      return;
    }

    // Check to see if the FacesServlet is present in the
    // web.xml.   If it is, perform faces configuration as normal,
    // otherwise, simply return.
    Object mappingsAdded = context.getAttribute(RIConstants.FACES_INITIALIZER_MAPPINGS_ADDED);
    if (mappingsAdded != null) {
      context.removeAttribute(RIConstants.FACES_INITIALIZER_MAPPINGS_ADDED);
    }

    WebXmlProcessor webXmlProcessor = new WebXmlProcessor(context);
    if (mappingsAdded == null) {
      if (!webXmlProcessor.isFacesServletPresent()) {
        if (!webConfig.isOptionEnabled(ForceLoadFacesConfigFiles)) {
          if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.log(
                Level.FINE,
                "No FacesServlet found in deployment descriptor - bypassing configuration");
          }
          WebConfiguration.clear(context);
          return;
        }
      } else {
        if (LOGGER.isLoggable(Level.FINE)) {
          LOGGER.log(
              Level.FINE,
              "FacesServlet found in deployment descriptor - processing configuration.");
        }
      }
    }

    // bootstrap of faces required
    webAppListener = new WebappLifecycleListener(context);
    webAppListener.contextInitialized(sce);
    InitFacesContext initContext = new InitFacesContext(context);
    ReflectionUtils.initCache(Thread.currentThread().getContextClassLoader());
    Throwable caughtThrowable = null;

    try {

      if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.log(Level.INFO, "jsf.config.listener.version", getServletContextIdentifier(context));
      }

      // see if we need to disable our TLValidator
      Util.setHtmlTLVActive(webConfig.isOptionEnabled(EnableHtmlTagLibraryValidator));

      if (webConfig.isOptionEnabled(VerifyFacesConfigObjects)) {
        if (LOGGER.isLoggable(Level.WARNING)) {
          LOGGER.warning("jsf.config.verifyobjects.development_only");
        }
        // if we're verifying, force bean validation to occur at startup as well
        webConfig.overrideContextInitParameter(EnableLazyBeanValidation, false);
        Verifier.setCurrentInstance(new Verifier());
      }
      initScripting();

      configManager.initialize(context);

      if (shouldInitConfigMonitoring()) {
        initConfigMonitoring(context);
      }

      // Step 7, verify that all the configured factories are available
      // and optionall that configured objects can be created.
      Verifier v = Verifier.getCurrentInstance();
      if (v != null && !v.isApplicationValid()) {
        if (LOGGER.isLoggable(Level.SEVERE)) {
          LOGGER.severe("jsf.config.verifyobjects.failures_detected");
          StringBuilder sb = new StringBuilder(128);
          for (String m : v.getMessages()) {
            sb.append(m).append('\n');
          }
          LOGGER.severe(sb.toString());
        }
      }
      registerELResolverAndListenerWithJsp(context, false);
      ELContext elctx = new ELContextImpl(initContext.getApplication().getELResolver());
      elctx.putContext(FacesContext.class, initContext);
      initContext.setELContext(elctx);
      ApplicationAssociate associate = ApplicationAssociate.getInstance(context);
      if (associate != null) {
        associate.setContextName(getServletContextIdentifier(context));
        BeanManager manager = associate.getBeanManager();
        List<String> eagerBeans = manager.getEagerBeanNames();
        if (!eagerBeans.isEmpty()) {
          for (String name : eagerBeans) {
            manager.create(name, initContext);
          }
        }
        boolean isErrorPagePresent = webXmlProcessor.isErrorPagePresent();
        associate.setErrorPagePresent(isErrorPagePresent);
        context.setAttribute(RIConstants.ERROR_PAGE_PRESENT_KEY_NAME, isErrorPagePresent);
      }
      Application app = initContext.getApplication();
      app.subscribeToEvent(PostConstructViewMapEvent.class, UIViewRoot.class, webAppListener);
      app.subscribeToEvent(PreDestroyViewMapEvent.class, UIViewRoot.class, webAppListener);

      webConfig.doPostBringupActions();

    } catch (Throwable t) {
      if (LOGGER.isLoggable(Level.SEVERE)) {
        LOGGER.log(Level.SEVERE, "Critical error during deployment: ", t);
      }
      caughtThrowable = t;

    } finally {
      Verifier.setCurrentInstance(null);
      initContext.release();
      if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(Level.FINE, "jsf.config.listener.version.complete");
      }
      if (timer != null) {
        timer.stopTiming();
        timer.logResult("Initialization of context " + getServletContextIdentifier(context));
      }
      if (null != caughtThrowable) {
        throw new RuntimeException(caughtThrowable);
      }
    }
  }
예제 #16
0
 public boolean shouldBeLogged(WebConfiguration configuration) {
   return !configuration.isOptionEnabled(
       BooleanWebContextInitParameter.DisableFaceletJSFViewHandler);
 }
예제 #17
0
 public AjaxBehaviorRenderer() {
   WebConfiguration webConfig = WebConfiguration.getInstance();
   namespaceParameters =
       webConfig.isOptionEnabled(BooleanWebContextInitParameter.NamespaceParameters);
 }
예제 #18
0
  private static boolean useThreads(ServletContext ctx) {

    WebConfiguration config = WebConfiguration.getInstance(ctx);
    return config.isOptionEnabled(EnableThreading);
  }
예제 #19
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);
      ExecutorService executor = null;
      try {
        WebConfiguration webConfig = WebConfiguration.getInstance(sc);
        boolean validating = webConfig.isOptionEnabled(ValidateFacesConfigFiles);
        if (useThreads(sc)) {
          executor = createExecutorService();
        }

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

        FacesConfigInfo webInfFacesConfigInfo =
            new FacesConfigInfo(facesDocuments[facesDocuments.length - 1]);

        facesDocuments = sortDocuments(facesDocuments, webInfFacesConfigInfo);
        InitFacesContext context = (InitFacesContext) FacesContext.getCurrentInstance();

        InjectionProvider containerConnector =
            InjectionProviderFactory.createInstance(context.getExternalContext());
        context.getAttributes().put(INJECTION_PROVIDER_KEY, containerConnector);

        boolean isFaceletsDisabled = isFaceletsDisabled(webConfig, webInfFacesConfigInfo);
        if (!webInfFacesConfigInfo.isWebInfFacesConfig()
            || !webInfFacesConfigInfo.isMetadataComplete()) {
          // execute the Task responsible for finding annotation classes
          ProvideMetadataToAnnotationScanTask taskMetadata =
              new ProvideMetadataToAnnotationScanTask(facesDocuments, containerConnector);
          Future<Map<Class<? extends Annotation>, Set<Class<?>>>> annotationScan;
          if (executor != null) {
            annotationScan = executor.submit(new AnnotationScanTask(sc, context, taskMetadata));
            pushTaskToContext(sc, annotationScan);
          } else {
            annotationScan =
                new FutureTask<Map<Class<? extends Annotation>, Set<Class<?>>>>(
                    new AnnotationScanTask(sc, context, taskMetadata));
            ((FutureTask) annotationScan).run();
          }
          pushTaskToContext(sc, annotationScan);
        }

        // see if the app is running in a HA enabled env
        if (containerConnector instanceof HighAvailabilityEnabler) {
          ((HighAvailabilityEnabler) containerConnector).enableHighAvailability(sc);
        }
        // process the ordered documents
        FACES_CONFIG_PROCESSOR_CHAIN.process(sc, facesDocuments);
        if (!isFaceletsDisabled) {
          FACELET_TAGLIB_CONFIG_PROCESSOR_CHAIN.process(
              sc,
              getConfigDocuments(sc, getFaceletConfigResourceProviders(), executor, validating));
        }

        publishPostConfigEvent();
      } catch (Exception e) {
        // clear out any configured factories
        releaseFactories();
        Throwable t = e;
        if (!(e instanceof ConfigurationException)) {
          t = new ConfigurationException("CONFIGURATION FAILED! " + t.getMessage(), t);
        }
        throw (ConfigurationException) t;
      } finally {
        if (executor != null) {
          executor.shutdown();
        }
        sc.removeAttribute(ANNOTATIONS_SCAN_TASK_KEY);
      }
    }
  }