Search in sources :

Example 1 with VariableMapper

use of javax.el.VariableMapper in project muikku by otavanopisto.

the class WidgetSpaceComponentHandler method apply.

@Override
public void apply(FaceletContext context, UIComponent parent) throws IOException {
    StringBuilder jsfBuilder = new StringBuilder();
    jsfBuilder.append("<ui:composition xmlns:m=\"http://www.ofw.fi/xml/2013/muikku/components-taglib.xsd\" xmlns:ui=\"http://java.sun.com/jsf/facelets\">").append("<m:includeWidgets").append(" widgets=").append('"').append('#').append("{widgetsBackingBean.getWidgets('").append(getName(context)).append("')}").append('"').append("/>").append("</ui:composition>");
    VariableMapper orig = context.getVariableMapper();
    context.setVariableMapper(new VariableMapperWrapper(orig));
    try {
        context.includeFacelet(parent, new URL(null, "data://text/plain;base64," + Base64.encodeBase64String(jsfBuilder.toString().getBytes("UTF-8")), new DataStreamHandler()));
    } catch (IOException e) {
        throw new TagException(this.tag, "Failed to include widget space widgets");
    } finally {
        context.setVariableMapper(orig);
    }
    super.apply(context, parent);
}
Also used : TagException(javax.faces.view.facelets.TagException) VariableMapper(javax.el.VariableMapper) VariableMapperWrapper(com.sun.faces.facelets.el.VariableMapperWrapper) IOException(java.io.IOException) URL(java.net.URL)

Example 2 with VariableMapper

use of javax.el.VariableMapper in project muikku by otavanopisto.

the class EmbedJSF method apply.

@Override
public void apply(FaceletContext context, UIComponent uiComponent) throws IOException {
    String unencoded = (String) jsfString.getObject(context, String.class);
    String encoded = Base64.encodeBase64String(unencoded.getBytes());
    VariableMapper orig = context.getVariableMapper();
    context.setVariableMapper(new VariableMapperWrapper(orig));
    try {
        this.nextHandler.apply(context, null);
        context.includeFacelet(uiComponent, new URL(null, "data://text/plain;base64," + encoded, new DataStreamHandler()));
    } catch (IOException e) {
        throw new TagAttributeException(this.tag, this.jsfString, "Invalid embedded JSF: " + unencoded);
    } finally {
        context.setVariableMapper(orig);
    }
}
Also used : TagAttributeException(javax.faces.view.facelets.TagAttributeException) VariableMapper(javax.el.VariableMapper) VariableMapperWrapper(com.sun.faces.facelets.el.VariableMapperWrapper) IOException(java.io.IOException) URL(java.net.URL)

Example 3 with VariableMapper

use of javax.el.VariableMapper in project muikku by otavanopisto.

the class IncludeWidgetsTagHandler method includeWidget.

private void includeWidget(FaceletContext context, UIComponent parent) throws IOException {
    StringBuilder jsfBuilder = new StringBuilder();
    List<LocatedWidget> widgets = getWidgets(context);
    jsfBuilder.append("<ui:composition xmlns:m=\"http://www.ofw.fi/xml/2013/muikku/components-taglib.xsd\" xmlns:ui=\"http://java.sun.com/jsf/facelets\">");
    for (LocatedWidget widget : widgets) {
        appendWidgetJsf(jsfBuilder, widget.getWidget());
    }
    jsfBuilder.append("</ui:composition>");
    VariableMapper orig = context.getVariableMapper();
    context.setVariableMapper(new VariableMapperWrapper(orig));
    try {
        this.nextHandler.apply(context, parent);
        context.includeFacelet(parent, new URL(null, "data://text/plain;base64," + Base64.encodeBase64String(jsfBuilder.toString().getBytes("UTF-8")), new DataStreamHandler()));
    } finally {
        context.setVariableMapper(orig);
    }
}
Also used : LocatedWidget(fi.otavanopisto.muikku.model.widgets.LocatedWidget) VariableMapper(javax.el.VariableMapper) VariableMapperWrapper(com.sun.faces.facelets.el.VariableMapperWrapper) URL(java.net.URL)

Example 4 with VariableMapper

use of javax.el.VariableMapper in project tomcat70 by apache.

the class AstIdentifier method getType.

@Override
public Class<?> getType(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.getType(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    Class<?> result = ctx.getELResolver().getType(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get("error.resolver.unhandled.null", this.image));
    }
    return result;
}
Also used : PropertyNotFoundException(javax.el.PropertyNotFoundException) VariableMapper(javax.el.VariableMapper) ValueExpression(javax.el.ValueExpression)

Example 5 with VariableMapper

use of javax.el.VariableMapper in project tomcat70 by apache.

the class AstIdentifier method getMethodExpression.

private final MethodExpression getMethodExpression(EvaluationContext ctx) throws ELException {
    Object obj = null;
    // case A: ValueExpression exists, getValue which must
    // be a MethodExpression
    VariableMapper varMapper = ctx.getVariableMapper();
    ValueExpression ve = null;
    if (varMapper != null) {
        ve = varMapper.resolveVariable(this.image);
        if (ve != null) {
            obj = ve.getValue(ctx);
        }
    }
    // a MethodExpression to be able to invoke
    if (ve == null) {
        ctx.setPropertyResolved(false);
        obj = ctx.getELResolver().getValue(ctx, null, this.image);
    }
    // finally provide helpful hints
    if (obj instanceof MethodExpression) {
        return (MethodExpression) obj;
    } else if (obj == null) {
        throw new MethodNotFoundException("Identity '" + this.image + "' was null and was unable to invoke");
    } else {
        throw new ELException("Identity '" + this.image + "' does not reference a MethodExpression instance, returned type: " + obj.getClass().getName());
    }
}
Also used : VariableMapper(javax.el.VariableMapper) ValueExpression(javax.el.ValueExpression) ELException(javax.el.ELException) MethodExpression(javax.el.MethodExpression) MethodNotFoundException(javax.el.MethodNotFoundException)

Aggregations

VariableMapper (javax.el.VariableMapper)13 ValueExpression (javax.el.ValueExpression)7 VariableMapperWrapper (com.sun.faces.facelets.el.VariableMapperWrapper)4 PropertyNotFoundException (javax.el.PropertyNotFoundException)4 IOException (java.io.IOException)3 URL (java.net.URL)3 FunctionMapper (javax.el.FunctionMapper)3 BeanELResolver (javax.el.BeanELResolver)2 ELContext (javax.el.ELContext)2 ELResolver (javax.el.ELResolver)2 LocatedWidget (fi.otavanopisto.muikku.model.widgets.LocatedWidget)1 ArrayELResolver (javax.el.ArrayELResolver)1 CompositeELResolver (javax.el.CompositeELResolver)1 ELException (javax.el.ELException)1 ListELResolver (javax.el.ListELResolver)1 MapELResolver (javax.el.MapELResolver)1 MethodExpression (javax.el.MethodExpression)1 MethodNotFoundException (javax.el.MethodNotFoundException)1 ResourceBundleELResolver (javax.el.ResourceBundleELResolver)1 TagAttributeException (javax.faces.view.facelets.TagAttributeException)1