javax.el.ELResolver Java Examples

The following examples show how to use javax.el.ELResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExpressionManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected ELResolver createElResolver(Map<String, Object> variables) {
  CompositeELResolver elResolver = new CompositeELResolver();
  elResolver.add(new VariableElResolver(variables));

  if (beans != null) {
    // ACT-1102: Also expose all beans in configuration when using
    // standalone activiti, not
    // in spring-context
    elResolver.add(new ReadOnlyMapELResolver(beans));
  }

  elResolver.add(new ArrayELResolver());
  elResolver.add(new ListELResolver());
  elResolver.add(new MapELResolver());
  elResolver.add(new JsonNodeELResolver());
  elResolver.add(new BeanELResolver());
  return elResolver;
}
 
Example #2
Source File: AstValue.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void setValue(EvaluationContext ctx, Object value)
        throws ELException {
    Target t = getTarget(ctx);
    ctx.setPropertyResolved(false);
    ELResolver resolver = ctx.getELResolver();

    // coerce to the expected type
    Class<?> targetClass = resolver.getType(ctx, t.base, t.property);
    resolver.setValue(ctx, t.base, t.property,
            ELSupport.coerceToType(ctx, value, targetClass));
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled", t.base, t.property));
    }
}
 
Example #3
Source File: JasperELResolver.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public JasperELResolver(List<ELResolver> appResolvers) {
    appResolversSize = appResolvers.size();
    resolvers = new ELResolver[appResolversSize + 7];
    size = 0;

    add(new ImplicitObjectELResolver());
    for (ELResolver appResolver : appResolvers) {
        add(appResolver);
    }
    add(new MapELResolver());
    add(new ResourceBundleELResolver());
    add(new ListELResolver());
    add(new ArrayELResolver());
    add(new BeanELResolver());
    add(new ScopedAttributeELResolver());
}
 
Example #4
Source File: ExpressionManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected ELResolver createElResolver(VariableScope variableScope) {
  CompositeELResolver elResolver = new CompositeELResolver();
  elResolver.add(new VariableScopeElResolver(variableScope));

  if (beans != null) {
    // ACT-1102: Also expose all beans in configuration when using
    // standalone activiti, not
    // in spring-context
    elResolver.add(new ReadOnlyMapELResolver(beans));
  }

  elResolver.add(new ArrayELResolver());
  elResolver.add(new ListELResolver());
  elResolver.add(new MapELResolver());
  elResolver.add(new JsonNodeELResolver());
  elResolver.add(new DynamicBeanPropertyELResolver(ItemInstance.class, "getFieldValue", "setFieldValue")); // TODO: needs verification
  elResolver.add(new BeanELResolver());
  return elResolver;
}
 
Example #5
Source File: AstValue.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(EvaluationContext ctx, Object value)
        throws ELException {
    Target t = getTarget(ctx);
    ctx.setPropertyResolved(false);
    ELResolver resolver = ctx.getELResolver();

    // coerce to the expected type
    Class<?> targetClass = resolver.getType(ctx, t.base, t.property);
    if (COERCE_TO_ZERO == true
            || !isAssignable(value, targetClass)) {
        resolver.setValue(ctx, t.base, t.property,
                ELSupport.coerceToType(value, targetClass));
    } else {
        resolver.setValue(ctx, t.base, t.property, value);
    }
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled", t.base, t.property));            
    }
}
 
Example #6
Source File: AstValue.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(EvaluationContext ctx, Object value)
        throws ELException {
    Target t = getTarget(ctx);
    ctx.setPropertyResolved(false);
    ELResolver resolver = ctx.getELResolver();

    // coerce to the expected type
    Class<?> targetClass = resolver.getType(ctx, t.base, t.property);
    if (COERCE_TO_ZERO == true
            || !isAssignable(value, targetClass)) {
        resolver.setValue(ctx, t.base, t.property,
                ELSupport.coerceToType(value, targetClass));
    } else {
        resolver.setValue(ctx, t.base, t.property, value);
    }
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled", t.base, t.property));            
    }
}
 
Example #7
Source File: JasperELResolver.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
public JasperELResolver(List<ELResolver> appResolvers) {
    appResolversSize = appResolvers.size();
    resolvers = new ELResolver[appResolversSize + 7];
    size = 0;

    add(new ImplicitObjectELResolver());
    for (ELResolver appResolver : appResolvers) {
        add(appResolver);
    }
    add(new MapELResolver());
    add(new ResourceBundleELResolver());
    add(new ListELResolver());
    add(new ArrayELResolver());
    add(new BeanELResolver());
    add(new ScopedAttributeELResolver());
}
 
Example #8
Source File: OpenEJBLifecycle.java    From tomee with Apache License 2.0 6 votes vote down vote up
public static void initializeServletContext(final ServletContext servletContext, final WebBeansContext context) {
    if (context == null || !context.getBeanManagerImpl().isInUse()) {
        return;
    }

    final ELAdaptor elAdaptor = context.getService(ELAdaptor.class);
    final ELResolver resolver = elAdaptor.getOwbELResolver();
    //Application is configured as JSP
    if (context.getOpenWebBeansConfiguration().isJspApplication()) {
        logger.debug("Application is configured as JSP. Adding EL Resolver.");

        setJspELFactory(servletContext, resolver);
    }

    // Add BeanManager to the 'javax.enterprise.inject.spi.BeanManager' servlet context attribute
    servletContext.setAttribute(BeanManager.class.getName(), context.getBeanManagerImpl());
}
 
Example #9
Source File: RuleEvaluator.java    From proctor with Apache License 2.0 6 votes vote down vote up
@Nonnull
ELContext createELContext(@Nonnull final VariableMapper variableMapper) {
    return new ELContext() {
        @Nonnull
        @Override
        public ELResolver getELResolver() {
            return elResolver;
        }

        @Nonnull
        @Override
        public FunctionMapper getFunctionMapper() {
            return functionMapper;
        }

        @Nonnull
        @Override
        public VariableMapper getVariableMapper() {
            return variableMapper;
        }
    };
}
 
Example #10
Source File: CdiResolver.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public CdiResolver() {
  context = new javax.el.ELContext() {

    @Override
    public VariableMapper getVariableMapper() {
      return null;
    }

    @Override
    public FunctionMapper getFunctionMapper() {
      return null;
    }

    @Override
    public javax.el.ELResolver getELResolver() {
      return getWrappedResolver();
    }
  };
}
 
Example #11
Source File: JasperELResolver.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public JasperELResolver(List<ELResolver> appResolvers,
        ELResolver streamResolver) {
    appResolversSize = appResolvers.size();
    resolvers = new ELResolver[appResolversSize + STANDARD_RESOLVERS_COUNT];

    add(new ImplicitObjectELResolver());
    for (ELResolver appResolver : appResolvers) {
        add(appResolver);
    }
    add(streamResolver);
    add(new StaticFieldELResolver());
    add(new MapELResolver());
    add(new ResourceBundleELResolver());
    add(new ListELResolver());
    add(new ArrayELResolver());
    add(new BeanELResolver());
    add(new ScopedAttributeELResolver());
}
 
Example #12
Source File: JasperELResolver.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public synchronized void add(ELResolver elResolver) {
    super.add(elResolver);

    int size = resolversSize.get();

    if (resolvers.length > size) {
        resolvers[size] = elResolver;
    } else {
        ELResolver[] nr = new ELResolver[size + 1];
        System.arraycopy(resolvers, 0, nr, 0, size);
        nr[size] = elResolver;

        resolvers = nr;
    }
    resolversSize.incrementAndGet();
}
 
Example #13
Source File: TestJasperELResolver.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private void doTestConstructor(int count) throws Exception {

        List<ELResolver> list = new ArrayList<ELResolver>();
        for (int i = 0; i < count; i++) {
            list.add(new ImplicitObjectELResolver());
        }

        JasperELResolver resolver = new JasperELResolver(list);


        Assert.assertEquals(Integer.valueOf(count),
                getField("appResolversSize", resolver));
        Assert.assertEquals(7 + count,
                ((ELResolver[])getField("resolvers", resolver)).length);
        Assert.assertEquals(Integer.valueOf(7 + count),
                getField("size", resolver));
    }
 
Example #14
Source File: TestJasperELResolver.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private void doTestConstructor(int count) throws Exception {

        List<ELResolver> list = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            list.add(new ImplicitObjectELResolver());
        }

        JasperELResolver resolver =
                new JasperELResolver(list, new StreamELResolverImpl());


        Assert.assertEquals(Integer.valueOf(count),
                getField("appResolversSize", resolver));
        Assert.assertEquals(9 + count,
                ((ELResolver[])getField("resolvers", resolver)).length);
        Assert.assertEquals(Integer.valueOf(9 + count),
                Integer.valueOf(((AtomicInteger) getField("resolversSize", resolver)).get()));
    }
 
Example #15
Source File: ElMetricName.java    From metrics-cdi with Apache License 2.0 5 votes vote down vote up
ElMetricName(ELResolver resolver, ExpressionFactory expressionFactory, MetricsExtension extension) {
    super(extension);
    CompositeELResolver composite = new CompositeELResolver();
    composite.add(resolver);
    composite.add(new MapELResolver());
    composite.add(new ListELResolver());
    composite.add(new ArrayELResolver());
    composite.add(new ResourceBundleELResolver());
    composite.add(new BeanELResolver(true));
    this.elResolver = composite;
    this.expressionFactory = expressionFactory;
}
 
Example #16
Source File: FeelElContextFactory.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public ELContext createContext(ExpressionFactory expressionFactory, VariableContext variableContext) {
  ELResolver elResolver = createElResolver();
  FunctionMapper functionMapper = createFunctionMapper();
  VariableMapper variableMapper = createVariableMapper(expressionFactory, variableContext);

  return new FeelElContext(elResolver, functionMapper, variableMapper);
}
 
Example #17
Source File: ELContextImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public static ELResolver getDefaultResolver(ExpressionFactory factory) {
    if (Constants.IS_SECURITY_ENABLED) {
        CompositeELResolver defaultResolver = new CompositeELResolver();
        defaultResolver.add(factory.getStreamELResolver());
        defaultResolver.add(new StaticFieldELResolver());
        defaultResolver.add(new MapELResolver());
        defaultResolver.add(new ResourceBundleELResolver());
        defaultResolver.add(new ListELResolver());
        defaultResolver.add(new ArrayELResolver());
        defaultResolver.add(new BeanELResolver());
        return defaultResolver;
    } else {
        return DefaultResolver;
    }
}
 
Example #18
Source File: OpenEJBLifecycle.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * On Tomcat we need to sometimes force a class load to get our hands on the JspFactory
 */
private static void setJspELFactory(ServletContext startupObject, ELResolver resolver)
{
    JspFactory factory = JspFactory.getDefaultFactory();
    if (factory == null)
    {
        try
        {
            try {
                Class.forName("org.apache.jasper.servlet.JasperInitializer");
            } catch (final Throwable th) {
                Class.forName("org.apache.jasper.compiler.JspRuntimeContext");
            }
            factory = JspFactory.getDefaultFactory();
        }
        catch (Exception e)
        {
            // ignore
        }

    }

    if (factory != null)
    {
        JspApplicationContext applicationCtx = factory.getJspApplicationContext(startupObject);
        applicationCtx.addELResolver(resolver);
    }
    else
    {
        logger.debug("Default JSPFactroy instance has not found. Skipping OWB JSP handling");
    }
}
 
Example #19
Source File: JspApplicationContextImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private ELResolver createELResolver() {
    this.instantiated = true;
    if (this.resolver == null) {
        CompositeELResolver r = new JasperELResolver(this.resolvers,
                expressionFactory.getStreamELResolver());
        this.resolver = r;
    }
    return this.resolver;
}
 
Example #20
Source File: JspApplicationContextImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void addELResolver(ELResolver resolver) throws IllegalStateException {
    if (resolver == null) {
        throw new IllegalArgumentException("ELResolver was null");
    }
    if (this.instantiated) {
        throw new IllegalStateException(
                "cannot call addELResolver after the first request has been made");
    }
    this.resolvers.add(resolver);
}
 
Example #21
Source File: FeelElContextFactory.java    From camunda-engine-dmn with Apache License 2.0 5 votes vote down vote up
public ELContext createContext(ExpressionFactory expressionFactory, VariableContext variableContext) {
  ELResolver elResolver = createElResolver();
  FunctionMapper functionMapper = createFunctionMapper();
  VariableMapper variableMapper = createVariableMapper(expressionFactory, variableContext);

  return new FeelElContext(elResolver, functionMapper, variableMapper);
}
 
Example #22
Source File: JuelScriptEngine.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private ELResolver createElResolver() {
  CompositeELResolver compositeResolver = new CompositeELResolver();
  compositeResolver.add(new ArrayELResolver());
  compositeResolver.add(new ListELResolver());
  compositeResolver.add(new MapELResolver());
  compositeResolver.add(new JsonNodeELResolver());
  compositeResolver.add(new ResourceBundleELResolver());
  compositeResolver.add(new DynamicBeanPropertyELResolver(ItemInstance.class, "getFieldValue", "setFieldValue"));
  compositeResolver.add(new BeanELResolver());
  return new SimpleResolver(compositeResolver);
}
 
Example #23
Source File: JspApplicationContextImpl.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private ELResolver createELResolver() {
    this.instantiated = true;
    if (this.resolver == null) {
        CompositeELResolver r = new JasperELResolver(this.resolvers);
        this.resolver = r;
    }
    return this.resolver;
}
 
Example #24
Source File: CdiExpressionManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ELResolver createElResolver(VariableScope variableScope) {
  CompositeELResolver compositeElResolver = new CompositeELResolver();
  compositeElResolver.add(new VariableScopeElResolver(variableScope));

  compositeElResolver.add(new CdiResolver());

  compositeElResolver.add(new ArrayELResolver());
  compositeElResolver.add(new ListELResolver());
  compositeElResolver.add(new MapELResolver());
  compositeElResolver.add(new BeanELResolver());
  return compositeElResolver;
}
 
Example #25
Source File: AstValue.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public Object getValue(EvaluationContext ctx) throws ELException {
    Object base = this.children[0].getValue(ctx);
    int propCount = this.jjtGetNumChildren();
    int i = 1;
    Object suffix = null;
    ELResolver resolver = ctx.getELResolver();
    while (base != null && i < propCount) {
        suffix = this.children[i].getValue(ctx);
        if (i + 1 < propCount &&
                (this.children[i+1] instanceof AstMethodParameters)) {
            AstMethodParameters mps =
                (AstMethodParameters) this.children[i+1];
            // This is a method
            Object[] paramValues = mps.getParameters(ctx);
            base = resolver.invoke(ctx, base, suffix,
                    getTypesFromValues(paramValues), paramValues);
            i+=2;
        } else {
            // This is a property
            if (suffix == null) {
                return null;
            }
            
            ctx.setPropertyResolved(false);
            base = resolver.getValue(ctx, base, suffix);
            i++;
        }
    }
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled", base, suffix));            
    }
    return base;
}
 
Example #26
Source File: ProcessEngineFactoryWithELResolver.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ELResolver createElResolver(VariableScope variableScope) {
  CompositeELResolver compositeElResolver = new CompositeELResolver();
  compositeElResolver.add(new VariableScopeElResolver(variableScope));
  if (blueprintContextELResolver != null) {
    compositeElResolver.add(blueprintContextELResolver);
  }
  compositeElResolver.add(blueprintELResolver);
  compositeElResolver.add(new BeanELResolver());
  compositeElResolver.add(new ArrayELResolver());
  compositeElResolver.add(new ListELResolver());
  compositeElResolver.add(new MapELResolver());
  return compositeElResolver;
}
 
Example #27
Source File: AstValue.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public Object getValue(EvaluationContext ctx) throws ELException {
    Object base = this.children[0].getValue(ctx);
    int propCount = this.jjtGetNumChildren();
    int i = 1;
    Object suffix = null;
    ELResolver resolver = ctx.getELResolver();
    while (base != null && i < propCount) {
        suffix = this.children[i].getValue(ctx);
        if (i + 1 < propCount &&
                (this.children[i+1] instanceof AstMethodParameters)) {
            AstMethodParameters mps =
                (AstMethodParameters) this.children[i+1];
            // This is a method
            Object[] paramValues = mps.getParameters(ctx);
            base = resolver.invoke(ctx, base, suffix,
                    getTypesFromValues(paramValues), paramValues);
            i+=2;
        } else {
            // This is a property
            if (suffix == null) {
                return null;
            }
            
            ctx.setPropertyResolved(false);
            base = resolver.getValue(ctx, base, suffix);
            i++;
        }
    }
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled", base, suffix));            
    }
    return base;
}
 
Example #28
Source File: RuleAnalyzer.java    From proctor with Apache License 2.0 5 votes vote down vote up
/**
 * @return variables contained in the expression
 */
public static Set<String> getReferencedVariables(final String elString) {
    final NameGatheringVariableMapper variableMapper = new NameGatheringVariableMapper();
    // instances are not thread-safe, so creating new ones on every call.
    final ELResolver elResolver = new CompositeELResolver();
    final FunctionMapper functionMapper = RuleEvaluator.defaultFunctionMapperBuilder().build();
    ExpressionFactory.newInstance().createValueExpression(
            new ELContext() {
                @Override
                public ELResolver getELResolver() {
                    return elResolver;
                }

                @Override
                public FunctionMapper getFunctionMapper() {
                    return functionMapper;
                }

                @Override
                public VariableMapper getVariableMapper() {
                    return variableMapper;
                }
            },
            elString,
            Void.class
    );
    return variableMapper.getGatheredVariables();
}
 
Example #29
Source File: JasperELResolver.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void add(ELResolver elResolver) {
    super.add(elResolver);

    if (resolvers.length > size) {
        resolvers[size] = elResolver;
    } else {
        ELResolver[] nr = new ELResolver[size + 1];
        System.arraycopy(resolvers, 0, nr, 0, size);
        nr[size] = elResolver;

        resolvers = nr;
    }
    size ++;
}
 
Example #30
Source File: ELContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public static ELResolver getDefaultResolver() {
    if (Constants.IS_SECURITY_ENABLED) {
        CompositeELResolver defaultResolver = new CompositeELResolver();
        defaultResolver.add(new MapELResolver());
        defaultResolver.add(new ResourceBundleELResolver());
        defaultResolver.add(new ListELResolver());
        defaultResolver.add(new ArrayELResolver());
        defaultResolver.add(new BeanELResolver());
        return defaultResolver;
    } else {
        return DefaultResolver;
    }
}