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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations