Java 类javax.el.ELContext 实例源码

项目:tomcat7    文件:JspContextWrapper.java   
@Override
public ELContext getELContext() {
    if (elContext == null) {
        elContext = new ELContextWrapper(rootJspCtxt.getELContext(), this);
    }
    return elContext;
}
项目:tomcat7    文件:TestELParser.java   
@Test
public void bug56185() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    TesterBeanC beanC = new TesterBeanC();
    ValueExpression var =
        factory.createValueExpression(beanC, TesterBeanC.class);
    context.getVariableMapper().setVariable("myBean", var);

    ValueExpression ve = factory.createValueExpression(context,
        "${(myBean.int1 > 1 and myBean.myBool) or "+
        "((myBean.myBool or myBean.myBool1) and myBean.int1 > 1)}",
        Boolean.class);
    assertEquals(Boolean.FALSE, ve.getValue(context));
    beanC.setInt1(2);
    beanC.setMyBool1(true);
    assertEquals(Boolean.TRUE, ve.getValue(context));
}
项目:myfaces-trinidad    文件:UIXComponentBase.java   
@Override
public void setValueExpression(String name,
                               ValueExpression expression)
{
  if (name == null)
    throw new NullPointerException();

  if ((expression != null) && expression.isLiteralText())
  {
    ELContext context =
        FacesContext.getCurrentInstance().getELContext();
    getAttributes().put(name, expression.getValue(context));
  }
  else
  {
    PropertyKey key = getPropertyKey(name);
    getFacesBean().setValueExpression(key, expression);
  }
}
项目:apache-tomcat-7.0.73-with-comment    文件:ScopedAttributeELResolver.java   
@Override
public void setValue(ELContext context, Object base, Object property,
        Object value) throws NullPointerException,
        PropertyNotFoundException, PropertyNotWritableException,
        ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context
                    .getContext(JspContext.class);
            int scope = page.getAttributesScope(key);
            if (scope != 0) {
                page.setAttribute(key, value, scope);
            } else {
                page.setAttribute(key, value);
            }
        }
    }
}
项目:lams    文件:ELResolverImpl.java   
public void setValue(ELContext context, Object base, Object property,
        Object value) throws NullPointerException,
        PropertyNotFoundException, PropertyNotWritableException,
        ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        throw new PropertyNotWritableException(
                "Legacy VariableResolver wrapped, not writable");
    }

    if (!context.isPropertyResolved()) {
        getDefaultResolver().setValue(context, base, property, value);
    }
}
项目:myfaces-trinidad    文件:SortableModel.java   
public Comp(
  ELResolver   resolver,
  ELContext    context,
  Locale       locale,
  String       property,
  SortStrength sortStrength)
{
  _resolver = resolver;
  _context  = context;

  // use Collator as comparator whenever locale or strength is available,
  // so sorting is natural to that locale.
  if (locale != null || sortStrength != null)
  {
    if (locale != null)
      _collator = Collator.getInstance(locale);
    else
      _collator = Collator.getInstance();

    if (sortStrength != null)
      _collator.setStrength(sortStrength.getStrength());
  }
  else
  {
    _collator = null;
  }

  _prop = property;
}
项目:myfaces-trinidad    文件:ImmutableItemNode.java   
public String doAction()
{
  String value = _action;

  if (value != null)
  {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExpressionFactory expressionFactory =
        facesContext.getApplication().getExpressionFactory();
    ELContext context = facesContext.getELContext();
    MethodExpression methodExpression =
        expressionFactory.createMethodExpression(context, value,
            String.class, new Class<?>[]
            {});
    value = (String) methodExpression.invoke(context, null);
  }

  // Post me as the selected Node for the request
  postSelectedNode(this);

  return value;
}
项目:lams    文件:Node.java   
/**
 * Allow node to validate itself
 * 
 * @param ef
 * @param ctx
 * @throws ELException
 */
public void validateEL(ExpressionFactory ef, ELContext ctx)
        throws ELException {
    if (this.el != null) {
        // determine exact type
        ValueExpression ve = ef.createValueExpression(ctx, this.value,
                String.class);
    }
}
项目:tomcat7    文件:ELResolverImpl.java   
@Override
public boolean isReadOnly(ELContext context, Object base, Object property)
        throws NullPointerException, PropertyNotFoundException, ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        return true;
    }

    return elResolver.isReadOnly(context, base, property);
}
项目:myfaces-trinidad    文件:MELResolver.java   
@Override
public Class<?> getType(ELContext context, Object base, 
                        Object property)
{
  if (base == null)
  {
    Object o = getValue(context, base, property);
    if (o == null)
      return null;
    return o.getClass();
  }
  else
  {
    if (_isIndexed(base))
      return _pr.getType(base, _getIndex(property));
    else
      return _pr.getType(base, property);
  }
}
项目:lams    文件:JspContextWrapper.java   
public ELContext getELContext() {
       // instead decorate!!!

       return this.invokingJspCtxt.getELContext();

       /*
    if (this.elContext != null) {
        JspFactory jspFact = JspFactory.getDefaultFactory();
        ServletContext servletContext = this.getServletContext();
        JspApplicationContextImpl jspCtx = (JspApplicationContextImpl) jspFact
                .getJspApplicationContext(servletContext);
        this.elContext = jspCtx.createELContext(this);
    }
    return this.elContext;
       */
}
项目:myfaces-trinidad    文件:ImmutableItemNode.java   
public void actionListener(ActionEvent event)
{
  String value = _actionListener;
  if (value != null)
  {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExpressionFactory expressionFactory =
        facesContext.getApplication().getExpressionFactory();
    ELContext context = facesContext.getELContext();

    MethodExpression methodExpression =
        expressionFactory.createMethodExpression(context, value, Void.TYPE,
            new Class<?>[]
            { ActionEvent.class });
    methodExpression.invoke(context, new Object[]
    { event });
  }

}
项目:myfaces-trinidad    文件:MockELResolver.java   
public boolean isReadOnly(ELContext context, Object base, Object property)
{
  FacesContext fc = FacesContext.getCurrentInstance();
  if (base == null)
  {
    // Can't handle this case - don't set "property resolved"
    return false;
  }
  else
  {
    if (property != null)
    {
      context.setPropertyResolved(true);
      if (property instanceof Number)
        return _pr.isReadOnly(base, ((Number) property).intValue());
      return _pr.isReadOnly(base, property);
    }
  }

  return false;
}
项目:tomcat7    文件:ImplicitObjectELResolver.java   
@Override
public boolean isReadOnly(ELContext context, Object base, Object property)
        throws NullPointerException, PropertyNotFoundException, ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null && property != null) {
        int idx = Arrays.binarySearch(SCOPE_NAMES, property.toString());
        if (idx >= 0) {
            context.setPropertyResolved(true);
            return true;
        }
    }
    return false;
}
项目:tomcat7    文件:TestELParser.java   
@Test
public void testJavaKeyWordIdentifier() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    TesterBeanA beanA = new TesterBeanA();
    beanA.setInt("five");
    ValueExpression var =
        factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("this", var);

    // Should fail
    Exception e = null;
    try {
        factory.createValueExpression(context, "${this}", String.class);
    } catch (ELException ele) {
        e = ele;
    }
    assertNotNull(e);
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestELParser.java   
@Test
public void testJavaKeyWordIdentifier() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    TesterBeanA beanA = new TesterBeanA();
    beanA.setInt("five");
    ValueExpression var =
        factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("this", var);

    // Should fail
    Exception e = null;
    try {
        factory.createValueExpression(context, "${this}", String.class);
    } catch (ELException ele) {
        e = ele;
    }
    assertNotNull(e);
}
项目:tomcat7    文件:TestValueExpressionImpl.java   
@Test
public void testBug51177ObjectMap() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);

    Map<Object,Object> map = new HashMap<Object,Object>();
    map.put("key1", o1);
    map.put("key2", o2);

    ValueExpression var =
        factory.createValueExpression(map, Map.class);
    context.getVariableMapper().setVariable("map", var);

    ValueExpression ve1 = factory.createValueExpression(
            context, "${map.key1}", Object.class);
    ve1.setValue(context, o2);
    assertEquals(o2, ve1.getValue(context));

    ValueExpression ve2 = factory.createValueExpression(
            context, "${map.key2}", Object.class);
    ve2.setValue(context, o1);
    assertEquals(o1, ve2.getValue(context));
}
项目:tomcat7    文件:TestValueExpressionImpl.java   
@Test
public void testBug51177ObjectList() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);

    List<Object> list = new ArrayList<Object>();
    list.add(0, o1);
    list.add(1, o2);

    ValueExpression var =
        factory.createValueExpression(list, List.class);
    context.getVariableMapper().setVariable("list", var);

    ValueExpression ve1 = factory.createValueExpression(
            context, "${list[0]}", Object.class);
    ve1.setValue(context, o2);
    assertEquals(o2, ve1.getValue(context));

    ValueExpression ve2 = factory.createValueExpression(
            context, "${list[1]}", Object.class);
    ve2.setValue(context, o1);
    assertEquals(o1, ve2.getValue(context));
}
项目:myfaces-trinidad    文件:ForEachTag.java   
@Override
public void setValue(ELContext context, Object value)
{
  Object items = _itemsExpression.getValue(context);

  if (items != null)
  {
    if (items instanceof CollectionModel)
    {
      // There is no support for setting row data on the collection model
      throw new PropertyNotWritableException();
    }

    context.setPropertyResolved(false);
    context.getELResolver().setValue(context, items, _key, value);
  }
}
项目:lazycat    文件:ELResolverImpl.java   
@Override
public Object getValue(ELContext context, Object base, Object property)
        throws NullPointerException, PropertyNotFoundException, ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        if (property != null) {
            try {
                return this.variableResolver.resolveVariable(property.toString());
            } catch (javax.servlet.jsp.el.ELException e) {
                throw new ELException(e.getMessage(), e.getCause());
            }
        }
    }

    if (!context.isPropertyResolved()) {
        return elResolver.getValue(context, base, property);
    }
    return null;
}
项目:myfaces-trinidad    文件:ImmutableItemNode.java   
public String doAction()
{
  String value = _action;

  if (value != null)
  {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExpressionFactory expressionFactory =
        facesContext.getApplication().getExpressionFactory();
    ELContext context = facesContext.getELContext();
    MethodExpression methodExpression =
        expressionFactory.createMethodExpression(context, value,
            String.class, new Class<?>[]
            {});
    value = (String) methodExpression.invoke(context, null);
  }

  // Post me as the selected Node for the request
  postSelectedNode(this);

  return value;
}
项目:myfaces-trinidad    文件:TrinidadELResolver.java   
public Object getValue(ELContext elContext, Object base, 
                       Object property)
{
  if (base == null)
  {
    if (RequestContext.VARIABLE_NAME.equals(property))
    {
      elContext.setPropertyResolved(true);
      return RequestContext.getCurrentInstance();
    }
    // Support both "pageFlowScope" and "processScope"
    // as EL variables to give developers a time to migrate
    else if (PAGE_FLOW_SCOPE_VARIABLE_NAME.equals(property) ||
           "processScope".equals(property))
    {
      elContext.setPropertyResolved(true);
      return RequestContext.getCurrentInstance().getPageFlowScope();
    }
  }

  return null;
}
项目:apache-tomcat-7.0.73-with-comment    文件:ELResolverImpl.java   
@Override
public void setValue(ELContext context, Object base, Object property,
        Object value) throws NullPointerException,
        PropertyNotFoundException, PropertyNotWritableException,
        ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        throw new PropertyNotWritableException(
                "Legacy VariableResolver wrapped, not writable");
    }

    if (!context.isPropertyResolved()) {
        elResolver.setValue(context, base, property, value);
    }
}
项目:ysoserial-modified    文件:Myfaces1.java   
public static Object makeExpressionPayload ( String expr ) throws IllegalArgumentException, IllegalAccessException, Exception  {
    FacesContextImpl fc = new FacesContextImpl((ServletContext) null, (ServletRequest) null, (ServletResponse) null);
    ELContext elContext = new FacesELContext(new CompositeELResolver(), fc);
    Reflections.getField(FacesContextImplBase.class, "_elContext").set(fc, elContext);
    ExpressionFactory expressionFactory = ExpressionFactory.newInstance();

    ValueExpression ve1 = expressionFactory.createValueExpression(elContext, expr, Object.class);
    ValueExpressionMethodExpression e = new ValueExpressionMethodExpression(ve1);
    ValueExpression ve2 = expressionFactory.createValueExpression(elContext, "${true}", Object.class);
    ValueExpressionMethodExpression e2 = new ValueExpressionMethodExpression(ve2);

    return Gadgets.makeMap(e2, e);
}
项目:APacheSynapseSimplePOC    文件:MyfacesTest.java   
@Override
public Object getValue ( ELContext context, Object base, Object property ) {
    if ( base == null && "request".equals(property)) {
        context.setPropertyResolved(true);
        return this.request;
    }

    return null;
}
项目:APacheSynapseSimplePOC    文件:MyfacesTest.java   
@Override
public Class<?> getType ( ELContext context, Object base, Object property ) {
    if ( base == null && "request".equals(property)) {
        context.setPropertyResolved(true);
        return ServletRequest.class;
    }
    return null;
}
项目:lams    文件:ExpressionFactoryImpl.java   
public MethodExpression createMethodExpression(ELContext context,
        String expression, Class<?> expectedReturnType,
        Class<?>[] expectedParamTypes) {
    if (expectedParamTypes == null) {
        throw new NullPointerException(MessageFactory
                .get("error.method.nullParms"));
    }
    ExpressionBuilder builder = new ExpressionBuilder(expression, context);
    return builder.createMethodExpression(expectedReturnType,
            expectedParamTypes);
}
项目:lazycat    文件:ValueExpressionLiteral.java   
@Override
public Object getValue(ELContext context) {
    if (this.expectedType != null) {
        return ELSupport.coerceToType(this.value, this.expectedType);
    }
    return this.value;
}
项目:myfaces-trinidad    文件:SortableModel.java   
static private ELContext _getELContext(
  FacesContext context, ELResolver resolver)
{
  // Hopefully, we have a FacesContext.  If not, we're
  // going to have to synthesize one!
  if (context != null)
    return context.getELContext();

  return new ELContextImpl(resolver);
}
项目:myfaces-trinidad    文件:ValueBindingValueExpression.java   
@SuppressWarnings("deprecation")
public boolean isReadOnly(ELContext elContext)
{
  try
  {
    return _binding.isReadOnly(FacesContext.getCurrentInstance());
  }
  // Convert EvaluationExceptions into ELExceptions
  catch (EvaluationException ee)
  {
    throw new ELException(ee.getMessage(), ee.getCause());
  }
}
项目:tomcat7    文件:ValueExpressionImpl.java   
@Override
public Object getValue(ELContext context) throws PropertyNotFoundException,
        ELException {
    EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
            this.varMapper);
    Object value = this.getNode().getValue(ctx);
    if (this.expectedType != null) {
        return ELSupport.coerceToType(value, this.expectedType);
    }
    return value;
}
项目:tomcat7    文件:ValueExpressionImpl.java   
@Override
public boolean isReadOnly(ELContext context)
        throws PropertyNotFoundException, ELException {
    EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
            this.varMapper);
    return this.getNode().isReadOnly(ctx);
}
项目:tomcat7    文件:MethodExpressionLiteral.java   
@Override
public Object invoke(ELContext context, Object[] params) throws ELException {
    if (this.expectedType != null) {
        return ELSupport.coerceToType(this.expr, this.expectedType);
    } else {
        return this.expr;
    }
}
项目:lams    文件:ELResolverImpl.java   
public boolean isReadOnly(ELContext context, Object base, Object property)
        throws NullPointerException, PropertyNotFoundException, ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        return true;
    }

    return getDefaultResolver().isReadOnly(context, base, property);
}
项目:apache-tomcat-7.0.73-with-comment    文件:ImplicitObjectELResolver.java   
@Override
public Class<String> getCommonPropertyType(ELContext context, Object base) {
    if (base == null) {
        return String.class;
    }
    return null;
}
项目:tomcat7    文件:Node.java   
/**
 * Allow node to validate itself
 * 
 * @param ef
 * @param ctx
 * @throws ELException
 */
public void validateEL(ExpressionFactory ef, ELContext ctx)
        throws ELException {
    if (this.el != null) {
        // determine exact type
        ef.createValueExpression(ctx, this.value, String.class);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:ValueExpressionImpl.java   
@Override
public boolean isReadOnly(ELContext context)
        throws PropertyNotFoundException, ELException {
    EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
            this.varMapper);
    return this.getNode().isReadOnly(ctx);
}
项目:tomcat7    文件:ScopedAttributeELResolver.java   
@Override
public Class<String> getCommonPropertyType(ELContext context, Object base) {
    if (base == null) {
        return String.class;
    }
    return null;
}
项目:apache-tomcat-7.0.73-with-comment    文件:MethodExpressionLiteral.java   
@Override
public Object invoke(ELContext context, Object[] params) throws ELException {
    if (this.expectedType != null) {
        return ELSupport.coerceToType(this.expr, this.expectedType);
    } else {
        return this.expr;
    }
}
项目:tomcat7    文件:ImplicitObjectELResolver.java   
@Override
public Class<String> getCommonPropertyType(ELContext context, Object base) {
    if (base == null) {
        return String.class;
    }
    return null;
}