Search in sources :

Example 11 with WebConfiguration

use of com.sun.faces.config.WebConfiguration in project mojarra by eclipse-ee4j.

the class SerializationProviderFactory method findProviderClass.

/**
 * Tries to find a provider class in a web context parameter. If not present it tries to find it as a System property.
 * If still not found returns null.
 *
 * @param extContext The ExternalContext for this request
 * @return The provider class name specified in the container configuration, or <code>null</code> if not found.
 */
private static String findProviderClass(ExternalContext extContext) {
    WebConfiguration webConfig = WebConfiguration.getInstance(extContext);
    String provider = webConfig.getOptionValue(WebContextInitParameter.SerializationProviderClass);
    if (provider != null) {
        return provider;
    } else {
        return System.getProperty(SERIALIZATION_PROVIDER_PROPERTY);
    }
}
Also used : WebConfiguration(com.sun.faces.config.WebConfiguration)

Example 12 with WebConfiguration

use of com.sun.faces.config.WebConfiguration in project mojarra by eclipse-ee4j.

the class SAXCompiler method writeXmlDecl.

protected static void writeXmlDecl(InputStream is, String encoding, CompilationManager mngr) throws IOException {
    is.mark(128);
    try {
        byte[] b = new byte[128];
        if (is.read(b) > 0) {
            String r = new String(b, encoding);
            Matcher m = XmlDeclaration.matcher(r);
            if (m.find()) {
                WebConfiguration config = mngr.getWebConfiguration();
                FaceletsConfiguration faceletsConfig = config.getFaceletsConfiguration();
                boolean currentModeIsXhtml = faceletsConfig.isProcessCurrentDocumentAsFaceletsXhtml(mngr.getAlias());
                // with the value of XHTML
                if (currentModeIsXhtml) {
                    Util.saveXMLDECLToFacesContextAttributes(m.group(0) + "\n");
                }
            }
        }
    } finally {
        is.reset();
    }
}
Also used : Matcher(java.util.regex.Matcher) FaceletsConfiguration(com.sun.faces.config.FaceletsConfiguration) WebConfiguration(com.sun.faces.config.WebConfiguration)

Example 13 with WebConfiguration

use of com.sun.faces.config.WebConfiguration 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 14 with WebConfiguration

use of com.sun.faces.config.WebConfiguration in project mojarra by eclipse-ee4j.

the class FaceletCacheFactoryImpl method getFaceletCache.

@Override
public FaceletCache getFaceletCache() {
    WebConfiguration webConfig = WebConfiguration.getInstance();
    String refreshPeriod = webConfig.getOptionValue(WebConfiguration.WebContextInitParameter.FaceletsDefaultRefreshPeriod);
    long period = Long.parseLong(refreshPeriod) * 1000;
    FaceletCache<DefaultFacelet> result = new DefaultFaceletCache(period);
    return result;
}
Also used : WebConfiguration(com.sun.faces.config.WebConfiguration)

Example 15 with WebConfiguration

use of com.sun.faces.config.WebConfiguration in project mojarra by eclipse-ee4j.

the class ProtectedViewsConfigProcessor method processProtectedViews.

// --------------------------------------------------------- Private Methods
private void processProtectedViews(FacesContext context, NodeList protectedViews, String namespace, DocumentInfo info) {
    WebConfiguration config = null;
    ViewHandler viewHandler = null;
    for (int i = 0, size = protectedViews.getLength(); i < size; i++) {
        Node urlPatterns = protectedViews.item(i);
        NodeList children = ((Element) urlPatterns).getElementsByTagNameNS(namespace, "*");
        for (int c = 0, csize = children.getLength(); c < csize; c++) {
            Node n = children.item(c);
            String urlPattern = null;
            if (URL_PATTERN.equals(n.getLocalName())) {
                urlPattern = getNodeText(n);
            } else {
                if (LOGGER.isLoggable(Level.WARNING)) {
                    LOGGER.log(Level.WARNING, MessageFormat.format("Processing protected-views elements for document: ''{0}'', encountered unexpected configuration ''{1}'', ignoring and continuing", info.getSourceURI(), getNodeText(n)));
                }
            }
            if (urlPattern != null) {
                if (config == null) {
                    config = WebConfiguration.getInstance();
                }
                if (viewHandler == null) {
                    viewHandler = context.getApplication().getViewHandler();
                }
                viewHandler.addProtectedView(urlPattern);
            } else {
                if (LOGGER.isLoggable(WARNING)) {
                    LOGGER.log(WARNING, format("Processing protected-views elements for document: ''{0}'', encountered <url-pattern> element without expected children", info.getSourceURI()));
                }
            }
        }
    }
}
Also used : ViewHandler(jakarta.faces.application.ViewHandler) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) WebConfiguration(com.sun.faces.config.WebConfiguration)

Aggregations

WebConfiguration (com.sun.faces.config.WebConfiguration)25 IOException (java.io.IOException)4 URI (java.net.URI)4 VariableMapperWrapper (com.sun.faces.facelets.el.VariableMapperWrapper)3 VariableMapper (jakarta.el.VariableMapper)3 TagAttributeException (jakarta.faces.view.facelets.TagAttributeException)3 FaceletContextImplBase (com.sun.faces.facelets.FaceletContextImplBase)2 FacesMessage (jakarta.faces.application.FacesMessage)2 Resource (jakarta.faces.application.Resource)2 ResourceHandler (jakarta.faces.application.ResourceHandler)2 ExternalContext (jakarta.faces.context.ExternalContext)2 FacesContext (jakarta.faces.context.FacesContext)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 Matcher (java.util.regex.Matcher)2 NodeList (org.w3c.dom.NodeList)2 ANNOTATED_CLASSES (com.sun.faces.RIConstants.ANNOTATED_CLASSES)1 FaceletsConfiguration (com.sun.faces.config.FaceletsConfiguration)1 AnnotationScanPackages (com.sun.faces.config.WebConfiguration.WebContextInitParameter.AnnotationScanPackages)1