/** Returns the root object. */ public static Object getRoot(XelContext ctx) { final VariableResolver resolver = ctx.getVariableResolver(); return resolver != null ? resolver: Expressions.EMPTY_RESOLVER; }
public VariableResolver getVariableResolver() { return _bResolver ? _resolver: _ctx.getVariableResolver(); } public FunctionMapper getFunctionMapper() {
/*package*/ XelELContext(XelContext xelc) { _xelc = xelc; _resolver = new XelELResolver(xelc.getVariableResolver()); }
public Object resolve(XelContext ctx, Object base, Object name) { Object o = ctx.getVariableResolver(); return (o instanceof VariableResolverX) ? ((VariableResolverX)o).resolveVariable(ctx, base, name): o != null && base == null && name != null ? ((VariableResolver)o).resolveVariable(name.toString()): null; } };
public Object evaluate(XelContext ctx) { //Test case: B30-1957661.zul where a function mapper is created //by zscript so it is different from one page to page return _expr.evaluate(ctx.getVariableResolver(), ctx.getFunctionMapper()); }
public Object evaluate(XelContext xelc, String expression, Class expectedType) throws XelException { return _eval.evaluate(expression, expectedType, xelc != null ? xelc.getVariableResolver(): null, xelc != null ? xelc.getFunctionMapper(): null); }
/** Resolves the variable based on the specified context. * If the variable resolver ({@link XelContext#getVariableResolver} * is an instance of {@link VariableResolverX}, then * {@link VariableResolverX#resolveVariable(XelContext,Object,Object)} * will be invoked. * @param ctx the context. If null, null will be returned. * @since 5.0.0 */ public static Object resolveVariable(XelContext ctx, Object base, Object name) { if (ctx != null) { VariableResolver resolver = ctx.getVariableResolver(); if (resolver instanceof VariableResolverX) return ((VariableResolverX)resolver).resolveVariable(ctx, base, name); else if (resolver != null && base == null && name != null) return resolver.resolveVariable(name.toString()); } return null; } /** Resolves the variable based on the specified resolver.
private Context(String content, XelContext xelc, Locator loc) { this.content = content; _resolver = xelc != null ? xelc.getVariableResolver() : null; _mapper = new SimpleMapper(xelc != null ? xelc.getFunctionMapper() : null); _xelf = Expressions.newExpressionFactory(); _locator = loc; this.nLines = 1; }
public Object evaluate(XelContext ctx) { final XelMVELResolver resolver = new XelMVELResolver(ctx.getVariableResolver()); if (_frags.length == 1) { //optimize this most common case return Classes.coerce(_expected, _frags[0] instanceof String ? _frags[0]: MVEL.executeExpression(_frags[0], resolver)); } final StringBuffer sb = new StringBuffer(256); for (int j = 0; j < _frags.length; ++j) { if (_frags[j] instanceof String) { sb.append(_frags[j]); } else { Object val = MVEL.executeExpression(_frags[j], resolver); if (val != null) sb.append(val); } } return Classes.coerce(_expected, sb.toString()); } }
protected Object resolve(ELContext ctx, Object base, Object property) { VariableResolver resolver = _ctx.getVariableResolver(); if (resolver != null) { if (resolver instanceof VariableResolverX) { final Object o = ((VariableResolverX)resolver) .resolveVariable(_ctx, base, property); //in order to call static method, we can't set property as resolved if (o != null) ctx.setPropertyResolved(true); // Bug ZK-3021 if (REFERENCE_BINDING != null && o != null) { if (REFERENCE_BINDING.isAssignableFrom(o.getClass())) { try { return GET_VALUE.invoke(o, new Object[]{null}); } catch (Exception e) { // do nothing. } } } return o; } else if (base == null && property != null) { final Object o = resolver.resolveVariable(property.toString()); //in order to call static method, we can't set property as resolved if (o != null) ctx.setPropertyResolved(true); return o; } } return null; } public Class<?> getType(ELContext ctx, Object base, Object property)
public Object evaluate(XelContext ctx, String expression, Class expectedType) throws XelException { final XelMVELResolver resolver = new XelMVELResolver(ctx.getVariableResolver()); final ParserContext pctx = getParserContext(ctx); final List frags = ExpressionFragment.parse(expression); if (frags.size() == 1) { //optimize this most common case final Object o = frags.get(0); return Classes.coerce(expectedType, o instanceof String ? o: eval(((ExpressionFragment)o).getExpression(), resolver, pctx)); } final StringBuffer sb = new StringBuffer(256); for (Iterator it = frags.iterator(); it.hasNext();) { final Object o = it.next(); if (o instanceof String) { sb.append(o); } else { Object val = eval(((ExpressionFragment)o).getExpression(), resolver, pctx); if (val != null) sb.append(val); } } return Classes.coerce(expectedType, sb.toString()); } private
public Object evaluate(XelContext ctx) { //Test case: B30-1957661.zul where a function mapper is created //by zscript so it is different from one page to page //In this case, we cannot reuse parsed expression. final FunctionMapper nfm = ctx.getFunctionMapper(); if (!Objects.equals(_mapper, nfm)) return new ELFactory().evaluate(ctx, _rawexpr, _expected); return _expr.evaluate(ctx.getVariableResolver()); }
public Object evaluate(XelContext xelc, String expression, Class expectedType) throws XelException { try { return _eval.evaluate(expression, expectedType, xelc != null ? new XelELResolver(xelc.getVariableResolver()): null, xelc != null ? new XelELMapper(xelc.getFunctionMapper()): null); } catch (ELException ex) { throw new XelException("Failed to evaluate "+expression, ex); } }
public Object evaluate(XelContext ctx) { //Test case: B30-1957661.zul where a function mapper is created //by zscript so it is different from one page to page //In this case, we cannot reuse parsed expression. // //Note: if nfm is null, we consider it as not-change since DSP //doesn't save function mapper when evaluating try { final FunctionMapper nfm = ctx.getFunctionMapper(); if (nfm != null && _mapper != nfm) return new ApacheELFactory().evaluate(ctx, _rawexpr, _expected); final VariableResolver resolver = ctx.getVariableResolver(); return _expr.evaluate( resolver != null ? new XelELResolver(resolver): null); } catch (ELException ex) { throw new XelException(ex); } }