Search in sources :

Example 21 with WebConfiguration

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

the class InjectionProviderFactory method findProviderClass.

/**
 * <p>
 * Attempt to find an <code>InjectionProvider</code> based on the following algorithm:
 * </p>
 * <ul>
 * <li>Check for an explicit configuration within the web.xml using the key
 * <code>com.sun.faces.injectionProvider</code>. If found, return the value.</li>
 * <li>Check for a system property keyed by <code>com.sun.faces.InjectionProvider</code>. If found, return the
 * value.</li>
 * <li>Check for entries within <code>META-INF/services/com.sun.faces.injectionprovider</code>. If entries are found and
 * the entries extend <code>DiscoverableInjectionProvider</code>, invoke
 * <code>isInjectionFeatureAvailable(String)</code> passing in the configured delegate. If
 * <code>isInjectionFeatureAvailable(String)</code> returns <code>true</code> return the service entry.</li>
 * <li>If no <code>InjectionProviders are found, return <code>null</code></li> 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.
 * <ul>
 *
 * @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.InjectionProviderClass);
    if (provider != null) {
        return provider;
    } else {
        provider = System.getProperty(INJECTION_PROVIDER_PROPERTY);
    }
    if (provider != null) {
        return provider;
    } else {
        String[] serviceEntries = getServiceEntries();
        if (serviceEntries.length > 0) {
            for (int i = 0; i < serviceEntries.length; i++) {
                provider = getProviderFromEntry(extContext.getApplicationMap(), serviceEntries[i]);
                if (provider != null) {
                    break;
                }
            }
        } else {
            return provider;
        }
    }
    return provider;
}
Also used : WebConfiguration(com.sun.faces.config.WebConfiguration)

Example 22 with WebConfiguration

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

the class ResourceManager method initCompressableTypes.

/**
 * Init <code>compressableTypes</code> from the configuration.
 */
private void initCompressableTypes(Map<String, Object> appMap) {
    WebConfiguration config = WebConfiguration.getInstance();
    String value = config.getOptionValue(WebConfiguration.WebContextInitParameter.CompressableMimeTypes);
    if (value != null && value.length() > 0) {
        String[] values = Util.split(appMap, value, ",");
        if (values != null) {
            for (String s : values) {
                String pattern = s.trim();
                if (!isPatternValid(pattern)) {
                    continue;
                }
                if (pattern.endsWith("/*")) {
                    pattern = pattern.substring(0, pattern.indexOf("/*"));
                    pattern += "/[a-z0-9.-]*";
                }
                if (compressableTypes == null) {
                    compressableTypes = new ArrayList<>(values.length);
                }
                try {
                    compressableTypes.add(Pattern.compile(pattern));
                } catch (PatternSyntaxException pse) {
                    if (LOGGER.isLoggable(Level.WARNING)) {
                        // PENDING i18n
                        LOGGER.log(Level.WARNING, "faces.resource.mime.type.configration.invalid", new Object[] { pattern, pse.getPattern() });
                    }
                }
            }
        }
    }
}
Also used : WebConfiguration(com.sun.faces.config.WebConfiguration) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 23 with WebConfiguration

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

the class JavaFlowLoaderHelper method loadFlows.

synchronized void loadFlows(FacesContext context, FlowHandler flowHandler) throws IOException {
    BeanManager beanManager = getCdiBeanManager(context);
    FlowDiscoveryCDIExtension flowDiscoveryCDIExtension = CdiUtils.getBeanReference(beanManager, FlowDiscoveryCDIExtension.class);
    if (flowDiscoveryCDIExtension == null) {
        if (LOGGER.isLoggable(SEVERE)) {
            LOGGER.log(SEVERE, "Unable to obtain {0} from CDI implementation.  Flows described with {1} are unavailable.", new String[] { FlowDiscoveryCDIExtension.class.getName(), FlowDefinition.class.getName() });
        }
        return;
    }
    List<Producer<Flow>> flowProducers = flowDiscoveryCDIExtension.getFlowProducers();
    if (!flowProducers.isEmpty()) {
        enableClientWindowModeIfNecessary(context);
    }
    WebConfiguration config = WebConfiguration.getInstance();
    for (Producer<Flow> flowProducer : flowProducers) {
        Flow toAdd = flowProducer.produce(beanManager.<Flow>createCreationalContext(null));
        if (toAdd == null) {
            LOGGER.log(SEVERE, "Flow producer method {0}() returned null.  Ignoring.", flowProducer.toString());
        } else {
            flowHandler.addFlow(context, toAdd);
            config.setHasFlows(true);
        }
    }
}
Also used : Producer(jakarta.enterprise.inject.spi.Producer) FlowDiscoveryCDIExtension(com.sun.faces.flow.FlowDiscoveryCDIExtension) Util.getCdiBeanManager(com.sun.faces.util.Util.getCdiBeanManager) BeanManager(jakarta.enterprise.inject.spi.BeanManager) FlowDefinition(jakarta.faces.flow.builder.FlowDefinition) WebConfiguration(com.sun.faces.config.WebConfiguration) Flow(jakarta.faces.flow.Flow)

Example 24 with WebConfiguration

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

the class RenderKitUtils method getImageSource.

/**
 * <p>
 * Determine the path value of an image value for a component such as UIGraphic or UICommand.
 * </p>
 *
 * @param context the {@link FacesContext} for the current request.
 * @param component the component to obtain the image information from
 * @param attrName the attribute name that needs to be queried if the name and library attributes are not specified
 *
 * @return the encoded path to the image source
 */
public static String getImageSource(FacesContext context, UIComponent component, String attrName) {
    String resName = (String) component.getAttributes().get("name");
    ResourceHandler handler = context.getApplication().getResourceHandler();
    if (resName != null) {
        String libName = (String) component.getAttributes().get("library");
        WebConfiguration webConfig = WebConfiguration.getInstance();
        if (libName == null && resName.startsWith(webConfig.getOptionValue(WebConfiguration.WebContextInitParameter.WebAppContractsDirectory))) {
            if (context.isProjectStage(ProjectStage.Development)) {
                String msg = "Illegal path, direct contract references are not allowed: " + resName;
                context.addMessage(component.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
            }
            return "RES_NOT_FOUND";
        }
        Resource res = handler.createResource(resName, libName);
        if (res == null) {
            if (context.isProjectStage(ProjectStage.Development)) {
                String msg = "Unable to find resource " + (libName == null ? "" : libName + ", ") + resName;
                context.addMessage(component.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
            }
            return "RES_NOT_FOUND";
        } else {
            String requestPath = res.getRequestPath();
            return context.getExternalContext().encodeResourceURL(requestPath);
        }
    } else {
        String value = (String) component.getAttributes().get(attrName);
        if (value == null || value.length() == 0) {
            return "";
        }
        WebConfiguration webConfig = WebConfiguration.getInstance();
        if (value.startsWith(webConfig.getOptionValue(WebConfiguration.WebContextInitParameter.WebAppContractsDirectory))) {
            if (context.isProjectStage(ProjectStage.Development)) {
                String msg = "Illegal path, direct contract references are not allowed: " + value;
                context.addMessage(component.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
            }
            return "RES_NOT_FOUND";
        }
        if (handler.isResourceURL(value)) {
            return value;
        } else {
            value = context.getApplication().getViewHandler().getResourceURL(context, value);
            return context.getExternalContext().encodeResourceURL(value);
        }
    }
}
Also used : Resource(jakarta.faces.application.Resource) ResourceHandler(jakarta.faces.application.ResourceHandler) FacesMessage(jakarta.faces.application.FacesMessage) WebConfiguration(com.sun.faces.config.WebConfiguration)

Example 25 with WebConfiguration

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

the class DecorateHandler method apply.

/*
     * (non-Javadoc)
     *
     * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext, jakarta.faces.component.UIComponent)
     */
@Override
public void apply(FaceletContext ctxObj, UIComponent parent) throws IOException {
    FaceletContextImplBase ctx = (FaceletContextImplBase) ctxObj;
    VariableMapper orig = ctx.getVariableMapper();
    if (params != null) {
        VariableMapper vm = new VariableMapperWrapper(orig);
        ctx.setVariableMapper(vm);
        for (int i = 0; i < params.length; i++) {
            params[i].apply(ctx, parent);
        }
    }
    ctx.pushClient(this);
    String path = null;
    try {
        path = template.getValue(ctx);
        if (path.trim().length() == 0) {
            throw new TagAttributeException(tag, template, "Invalid path : " + path);
        }
        WebConfiguration webConfig = WebConfiguration.getInstance();
        if (path.startsWith(webConfig.getOptionValue(WebConfiguration.WebContextInitParameter.WebAppContractsDirectory))) {
            throw new TagAttributeException(tag, template, "Invalid path, contract resources cannot be accessed this way : " + path);
        }
        ctx.includeFacelet(parent, path);
    } catch (IOException e) {
        if (log.isLoggable(Level.FINE)) {
            log.log(Level.FINE, e.toString(), e);
        }
        throw new TagAttributeException(tag, template, "Invalid path : " + path);
    } finally {
        ctx.setVariableMapper(orig);
        ctx.popClient(this);
    }
}
Also used : TagAttributeException(jakarta.faces.view.facelets.TagAttributeException) FaceletContextImplBase(com.sun.faces.facelets.FaceletContextImplBase) VariableMapper(jakarta.el.VariableMapper) VariableMapperWrapper(com.sun.faces.facelets.el.VariableMapperWrapper) IOException(java.io.IOException) 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