Search in sources :

Example 1 with FaceletCache

use of jakarta.faces.view.facelets.FaceletCache in project mojarra by eclipse-ee4j.

the class DefaultFaceletFactory method init.

public final void init(FacesContext facesContext, Compiler compiler, DefaultResourceResolver resolver, long refreshPeriod, FaceletCache cache) {
    notNull("compiler", compiler);
    notNull("resolver", resolver);
    ExternalContext externalContext = facesContext.getExternalContext();
    WebConfiguration config = WebConfiguration.getInstance(externalContext);
    this.compiler = compiler;
    cachePerContract = new ConcurrentHashMap<>();
    this.resolver = resolver;
    baseUrl = resolver.resolveUrl("/");
    this.idMappers = config.isOptionEnabled(UseFaceletsID) ? null : new Cache<>(new IdMapperFactory());
    refreshPeriod = refreshPeriod >= 0 ? refreshPeriod * 1000 : -1;
    this.refreshPeriod = refreshPeriod;
    if (log.isLoggable(Level.FINE)) {
        log.log(Level.FINE, "Using ResourceResolver: {0}", resolver);
        log.log(Level.FINE, "Using Refresh Period: {0}", refreshPeriod);
    }
    // We can cast to the FaceletCache<DefaultFacelet> here because we know
    // that the Generics information is only used at compile time, and all cache
    // implementations will be using instance factories provided by us and returning DefaultFacelet
    this.cache = initCache(cache);
}
Also used : ExternalContext(jakarta.faces.context.ExternalContext) WebConfiguration(com.sun.faces.config.WebConfiguration) Cache(com.sun.faces.util.Cache) FaceletCache(jakarta.faces.view.facelets.FaceletCache)

Example 2 with FaceletCache

use of jakarta.faces.view.facelets.FaceletCache in project mojarra by eclipse-ee4j.

the class DefaultFaceletFactory method initCache.

// ---------------------------------------------------------- Private Methods
private FaceletCache<DefaultFacelet> initCache(FaceletCache<DefaultFacelet> cache) {
    if (cache == null) {
        FaceletCacheFactory cacheFactory = (FaceletCacheFactory) FactoryFinder.getFactory(FactoryFinder.FACELET_CACHE_FACTORY);
        cache = cacheFactory.getFaceletCache();
    }
    // Create instance factories for the cache, so that the cache can
    // create Facelets and Metadata Facelets
    FaceletCache.MemberFactory<DefaultFacelet> faceletFactory = key -> createFacelet(key);
    FaceletCache.MemberFactory<DefaultFacelet> metadataFaceletFactory = key -> createMetadataFacelet(key);
    cache.setCacheFactories(faceletFactory, metadataFaceletFactory);
    return cache;
}
Also used : FacesFileNotFoundException(com.sun.faces.context.FacesFileNotFoundException) CdiUtils.getBeanReference(com.sun.faces.cdi.CdiUtils.getBeanReference) WebConfiguration(com.sun.faces.config.WebConfiguration) Util.saveDOCTYPEToFacesContextAttributes(com.sun.faces.util.Util.saveDOCTYPEToFacesContextAttributes) Cache(com.sun.faces.util.Cache) URL(java.net.URL) Compiler(com.sun.faces.facelets.compiler.Compiler) FacesContext(jakarta.faces.context.FacesContext) Util.saveXMLDECLToFacesContextAttributes(com.sun.faces.util.Util.saveXMLDECLToFacesContextAttributes) CHAR_ENCODING(com.sun.faces.RIConstants.CHAR_ENCODING) ELException(jakarta.el.ELException) ConcurrentMap(java.util.concurrent.ConcurrentMap) Level(java.util.logging.Level) FacesException(jakarta.faces.FacesException) Pattern.quote(java.util.regex.Pattern.quote) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) OutputStreamWriter(java.io.OutputStreamWriter) Application(jakarta.faces.application.Application) FaceletException(jakarta.faces.view.facelets.FaceletException) Util.notNull(com.sun.faces.util.Util.notNull) Util.isEmpty(com.sun.faces.util.Util.isEmpty) MalformedURLException(java.net.MalformedURLException) View(jakarta.faces.annotation.View) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) UseFaceletsID(com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.UseFaceletsID) Doctype(jakarta.faces.component.Doctype) Logger(java.util.logging.Logger) UIComponent(jakarta.faces.component.UIComponent) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) FacesLogger(com.sun.faces.util.FacesLogger) FactoryFinder(jakarta.faces.FactoryFinder) FaceletHandler(jakarta.faces.view.facelets.FaceletHandler) RIConstants(com.sun.faces.RIConstants) ExternalContext(jakarta.faces.context.ExternalContext) Pattern(java.util.regex.Pattern) FaceletCacheFactory(jakarta.faces.view.facelets.FaceletCacheFactory) FINEST(java.util.logging.Level.FINEST) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Facelet(jakarta.faces.view.facelets.Facelet) FaceletCache(jakarta.faces.view.facelets.FaceletCache) FaceletCache(jakarta.faces.view.facelets.FaceletCache) FaceletCacheFactory(jakarta.faces.view.facelets.FaceletCacheFactory)

Aggregations

WebConfiguration (com.sun.faces.config.WebConfiguration)2 Cache (com.sun.faces.util.Cache)2 ExternalContext (jakarta.faces.context.ExternalContext)2 FaceletCache (jakarta.faces.view.facelets.FaceletCache)2 RIConstants (com.sun.faces.RIConstants)1 CHAR_ENCODING (com.sun.faces.RIConstants.CHAR_ENCODING)1 CdiUtils.getBeanReference (com.sun.faces.cdi.CdiUtils.getBeanReference)1 UseFaceletsID (com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.UseFaceletsID)1 FacesFileNotFoundException (com.sun.faces.context.FacesFileNotFoundException)1 Compiler (com.sun.faces.facelets.compiler.Compiler)1 FacesLogger (com.sun.faces.util.FacesLogger)1 Util.isEmpty (com.sun.faces.util.Util.isEmpty)1 Util.notNull (com.sun.faces.util.Util.notNull)1 Util.saveDOCTYPEToFacesContextAttributes (com.sun.faces.util.Util.saveDOCTYPEToFacesContextAttributes)1 Util.saveXMLDECLToFacesContextAttributes (com.sun.faces.util.Util.saveXMLDECLToFacesContextAttributes)1 ELException (jakarta.el.ELException)1 FacesException (jakarta.faces.FacesException)1 FactoryFinder (jakarta.faces.FactoryFinder)1 View (jakarta.faces.annotation.View)1 Application (jakarta.faces.application.Application)1