Search in sources :

Example 6 with WebConfiguration

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

the class FacesContextFactoryImpl method getFacesContext.

// ---------------------------------------- Methods from FacesContextFactory
@Override
public FacesContext getFacesContext(Object sc, Object request, Object response, Lifecycle lifecycle) throws FacesException {
    Util.notNull("sc", sc);
    Util.notNull("request", request);
    Util.notNull("response", response);
    Util.notNull("lifecycle", lifecycle);
    ExternalContext extContext;
    FacesContext ctx = new FacesContextImpl(extContext = externalContextFactory.getExternalContext(sc, request, response), lifecycle);
    ctx.setExceptionHandler(exceptionHandlerFactory.getExceptionHandler());
    WebConfiguration webConfig = WebConfiguration.getInstance(extContext);
    savePerRequestInitParams(ctx, webConfig);
    return ctx;
}
Also used : FacesContext(jakarta.faces.context.FacesContext) ExternalContext(jakarta.faces.context.ExternalContext) WebConfiguration(com.sun.faces.config.WebConfiguration)

Example 7 with WebConfiguration

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

the class CompositeComponentTagLibrary method init.

private void init() {
    WebConfiguration webconfig = WebConfiguration.getInstance();
    enableMissingResourceLibraryDetection = webconfig.isOptionEnabled(EnableMissingResourceLibraryDetection);
}
Also used : WebConfiguration(com.sun.faces.config.WebConfiguration)

Example 8 with WebConfiguration

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

the class IncludeHandler method apply.

/*
     * (non-Javadoc)
     *
     * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext, jakarta.faces.component.UIComponent)
     */
@Override
public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
    String path = src.getValue(ctx);
    if (path == null || path.length() == 0) {
        return;
    }
    VariableMapper orig = ctx.getVariableMapper();
    ctx.setVariableMapper(new VariableMapperWrapper(orig));
    try {
        nextHandler.apply(ctx, null);
        WebConfiguration webConfig = WebConfiguration.getInstance();
        if (path.startsWith(webConfig.getOptionValue(WebConfiguration.WebContextInitParameter.WebAppContractsDirectory))) {
            throw new TagAttributeException(tag, src, "Invalid src, 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, src, "Invalid path : " + path);
    } finally {
        ctx.setVariableMapper(orig);
    }
}
Also used : TagAttributeException(jakarta.faces.view.facelets.TagAttributeException) VariableMapper(jakarta.el.VariableMapper) VariableMapperWrapper(com.sun.faces.facelets.el.VariableMapperWrapper) IOException(java.io.IOException) WebConfiguration(com.sun.faces.config.WebConfiguration)

Example 9 with WebConfiguration

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

the class CompositionHandler 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;
    if (template != null) {
        FacesContext facesContext = ctx.getFacesContext();
        Integer compositionCount = (Integer) facesContext.getAttributes().get("com.sun.faces.uiCompositionCount");
        if (compositionCount == null) {
            compositionCount = 1;
        } else {
            compositionCount++;
        }
        facesContext.getAttributes().put("com.sun.faces.uiCompositionCount", compositionCount);
        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.extendClient(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.popClient(this);
            ctx.setVariableMapper(orig);
            compositionCount = (Integer) facesContext.getAttributes().get("com.sun.faces.uiCompositionCount");
            compositionCount--;
            if (compositionCount == 0) {
                facesContext.getAttributes().remove("com.sun.faces.uiCompositionCount");
            } else {
                facesContext.getAttributes().put("com.sun.faces.uiCompositionCount", compositionCount);
            }
        }
    } else {
        nextHandler.apply(ctx, parent);
    }
}
Also used : FacesContext(jakarta.faces.context.FacesContext) 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)

Example 10 with WebConfiguration

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

the class Util method checkIdUniqueness.

/**
 * Utility method to validate ID uniqueness for the tree represented by <code>component</code>.
 */
public static void checkIdUniqueness(FacesContext context, UIComponent component, Set<String> componentIds) {
    boolean uniquenessCheckDisabled = false;
    if (context.isProjectStage(ProjectStage.Production)) {
        WebConfiguration config = WebConfiguration.getInstance(context.getExternalContext());
        uniquenessCheckDisabled = config.isOptionEnabled(WebConfiguration.BooleanWebContextInitParameter.DisableIdUniquenessCheck);
    }
    if (!uniquenessCheckDisabled) {
        // deal with children/facets that are marked transient.
        for (Iterator<UIComponent> kids = component.getFacetsAndChildren(); kids.hasNext(); ) {
            UIComponent kid = kids.next();
            // check for id uniqueness
            String id = kid.getClientId(context);
            if (componentIds.add(id)) {
                checkIdUniqueness(context, kid, componentIds);
            } else {
                if (LOGGER.isLoggable(Level.SEVERE)) {
                    LOGGER.log(Level.SEVERE, "faces.duplicate_component_id_error", id);
                    FastStringWriter writer = new FastStringWriter(128);
                    DebugUtil.simplePrintTree(context.getViewRoot(), id, writer);
                    LOGGER.severe(writer.toString());
                }
                String message = MessageUtils.getExceptionMessageString(MessageUtils.DUPLICATE_COMPONENT_ID_ERROR_ID, id);
                throw new IllegalStateException(message);
            }
        }
    }
}
Also used : FastStringWriter(com.sun.faces.io.FastStringWriter) UIComponent(jakarta.faces.component.UIComponent) MessageUtils.getExceptionMessageString(com.sun.faces.util.MessageUtils.getExceptionMessageString) 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