Search in sources :

Example 1 with FaceletContextImplBase

use of com.sun.faces.facelets.FaceletContextImplBase 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 2 with FaceletContextImplBase

use of com.sun.faces.facelets.FaceletContextImplBase in project mojarra by eclipse-ee4j.

the class UserTagHandler method apply.

/**
 * Iterate over all TagAttributes and set them on the FaceletContext's VariableMapper, then include the target Facelet.
 * Finally, replace the old VariableMapper.
 *
 * @see TagAttribute#getValueExpression(FaceletContext, Class)
 * @see VariableMapper
 * @see jakarta.faces.view.facelets.FaceletHandler#apply(jakarta.faces.view.facelets.FaceletContext,
 * jakarta.faces.component.UIComponent)
 */
@Override
public void apply(FaceletContext ctxObj, UIComponent parent) throws IOException {
    FaceletContextImplBase ctx = (FaceletContextImplBase) ctxObj;
    VariableMapper orig = ctx.getVariableMapper();
    // setup a variable map
    if (vars.length > 0) {
        VariableMapper varMapper = new VariableMapperWrapper(orig);
        for (int i = 0; i < vars.length; i++) {
            varMapper.setVariable(vars[i].getLocalName(), vars[i].getValueExpression(ctx, Object.class));
        }
        ctx.setVariableMapper(varMapper);
    }
    // eval include
    try {
        ctx.pushClient(this);
        ctx.includeFacelet(parent, location);
    } catch (FileNotFoundException e) {
        throw new TagException(tag, e.getMessage());
    } finally {
        // make sure we undo our changes
        ctx.popClient(this);
        ctx.setVariableMapper(orig);
    }
}
Also used : FaceletContextImplBase(com.sun.faces.facelets.FaceletContextImplBase) TagException(jakarta.faces.view.facelets.TagException) VariableMapper(jakarta.el.VariableMapper) FileNotFoundException(java.io.FileNotFoundException) VariableMapperWrapper(com.sun.faces.facelets.el.VariableMapperWrapper)

Example 3 with FaceletContextImplBase

use of com.sun.faces.facelets.FaceletContextImplBase in project mojarra by eclipse-ee4j.

the class InsertHandler 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;
    ctx.extendClient(this);
    boolean found = false;
    try {
        found = ctx.includeDefinition(parent, name);
    } finally {
        ctx.popClient(this);
    }
    if (!found) {
        nextHandler.apply(ctx, parent);
    }
}
Also used : FaceletContextImplBase(com.sun.faces.facelets.FaceletContextImplBase)

Example 4 with FaceletContextImplBase

use of com.sun.faces.facelets.FaceletContextImplBase 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

FaceletContextImplBase (com.sun.faces.facelets.FaceletContextImplBase)4 VariableMapperWrapper (com.sun.faces.facelets.el.VariableMapperWrapper)3 VariableMapper (jakarta.el.VariableMapper)3 WebConfiguration (com.sun.faces.config.WebConfiguration)2 TagAttributeException (jakarta.faces.view.facelets.TagAttributeException)2 IOException (java.io.IOException)2 FacesContext (jakarta.faces.context.FacesContext)1 TagException (jakarta.faces.view.facelets.TagException)1 FileNotFoundException (java.io.FileNotFoundException)1