Package org.springframework.expression

Examples of org.springframework.expression.Expression


  public Object evaluate(String value, BeanExpressionContext evalContext) throws BeansException {
    if (!StringUtils.hasLength(value)) {
      return value;
    }
    try {
      Expression expr = this.expressionCache.get(value);
      if (expr == null) {
        expr = this.expressionParser.parseExpression(value, this.beanExpressionParserContext);
        this.expressionCache.put(value, expr);
      }
      StandardEvaluationContext sec = this.evaluationCache.get(evalContext);
      if (sec == null) {
        sec = new StandardEvaluationContext();
        sec.setRootObject(evalContext);
        sec.addPropertyAccessor(new BeanExpressionContextAccessor());
        sec.addPropertyAccessor(new BeanFactoryAccessor());
        sec.addPropertyAccessor(new MapAccessor());
        sec.addPropertyAccessor(new EnvironmentAccessor());
        sec.setBeanResolver(new BeanFactoryResolver(evalContext.getBeanFactory()));
        sec.setTypeLocator(new StandardTypeLocator(evalContext.getBeanFactory().getBeanClassLoader()));
        ConversionService conversionService = evalContext.getBeanFactory().getConversionService();
        if (conversionService != null) {
          sec.setTypeConverter(new StandardTypeConverter(conversionService));
        }
        customizeEvaluationContext(sec);
        this.evaluationCache.put(evalContext, sec);
      }
      return expr.getValue(sec);
    }
    catch (Exception ex) {
      throw new BeanExpressionException("Expression parsing failed", ex);
    }
  }
View Full Code Here


        this.paramNameDiscoverer, method, args, targetClass, this.targetMethodCache);
  }

  public boolean condition(String conditionExpression, Method method, EvaluationContext evalContext) {
    String key = toString(method, conditionExpression);
    Expression condExp = this.conditionCache.get(key);
    if (condExp == null) {
      condExp = this.parser.parseExpression(conditionExpression);
      this.conditionCache.put(key, condExp);
    }
    return condExp.getValue(evalContext, boolean.class);
  }
View Full Code Here

    return condExp.getValue(evalContext, boolean.class);
  }

  public Object key(String keyExpression, Method method, EvaluationContext evalContext) {
    String key = toString(method, keyExpression);
    Expression keyExp = this.keyCache.get(key);
    if (keyExp == null) {
      keyExp = this.parser.parseExpression(keyExpression);
      this.keyCache.put(key, keyExp);
    }
    return keyExp.getValue(evalContext);
  }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public Object evaluate(String expression, Map<String, Object> evaluationContext, Object root) throws ExpressionEvaluationException {
        try {
            Expression parsedExpression = this.expressionCache.get(expression);
            if (parsedExpression == null) {
                parsedExpression = parser.parseExpression(expression, this.parserContext);
                expressionCache.put(expression, parsedExpression);
            }
            StandardEvaluationContext context = new StandardEvaluationContext(root);
            context.setVariables(evaluationContext);
            context.registerFunction("cGet", CONVERSATION_ACCESSOR);
            context.registerFunction("cBeg", CONVERSATION_INITIATOR);
            context.registerFunction("cEnd", CONVERSATION_TERMINATOR);
            context.registerFunction("cCon", CONVERSATION_CONTINUATOR);
            return parsedExpression.getValue(context);
        } catch (Exception e) {
            throw new ExpressionEvaluationException(expression, e);
        }
    }
View Full Code Here

        this.paramNameDiscoverer, method, args, targetClass, this.targetMethodCache);
  }

  public boolean condition(String conditionExpression, Method method, EvaluationContext evalContext) {
    String key = toString(method, conditionExpression);
    Expression condExp = this.conditionCache.get(key);
    if (condExp == null) {
      condExp = this.parser.parseExpression(conditionExpression);
      this.conditionCache.put(key, condExp);
    }
    return condExp.getValue(evalContext, boolean.class);
  }
View Full Code Here

    return condExp.getValue(evalContext, boolean.class);
  }

  public Object key(String keyExpression, Method method, EvaluationContext evalContext) {
    String key = toString(method, keyExpression);
    Expression keyExp = this.keyCache.get(key);
    if (keyExp == null) {
      keyExp = this.parser.parseExpression(keyExpression);
      this.keyCache.put(key, keyExp);
    }
    return keyExp.getValue(evalContext);
  }
View Full Code Here

    }
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    HttpServletRequest request = ServletActionContext.getRequest();
    CustomWebSecurityExpressionHandler filterSecurityInterceptor = (CustomWebSecurityExpressionHandler)StorageService.ctx.getBean("customExpressionHandler");
    EvaluationContext ctx = filterSecurityInterceptor.createEvaluationContext(authentication, request);
    Expression expr = new SpelExpressionParser().parseExpression(expression);
    if(ExpressionUtils.evaluateAsBoolean(expr, ctx))
    {
      result = true;
    }
    return result;
View Full Code Here

        String expression = (String)bean.get("expression");       
        if(expression==null||expression.equals(""))//表达式为空,默认为denyAll
          expression="denyAll";
       
        //表达式不为空,则由authentication来判断       
        Expression expr = new SpelExpressionParser().parseExpression(expression);
        if(ExpressionUtils.evaluateAsBoolean(expr, ctx))
          UIs.add(path);       
      }
    }
    return UIs;
View Full Code Here

      Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
      CustomWebSecurityExpressionHandler filterSecurityInterceptor = (CustomWebSecurityExpressionHandler)StorageService.ctx.getBean("customExpressionHandler");
      EvaluationContext ctx = filterSecurityInterceptor.createEvaluationContext(authentication, request);
      for(String function:functions){
        String expression = "hasRole('ROLE_USER') and hasIpAddress('localhost')";
        Expression expr = PARSER.parseExpression(expression);
            LazyDynaBean bean = new LazyDynaBean();
            bean.set(function, ExpressionUtils.evaluateAsBoolean(expr, ctx));
            beans.add(bean);
      }
      resultInfo.setSucceed();
View Full Code Here

    }

    public int vote(Authentication authentication, State object, Collection<ConfigAttribute> attributes) {
        EvaluationContext ctx = expressionHandler.createEvaluationContext(authentication, object);
        ExpressionParser parser = new SpelExpressionParser();
        Expression exp = parser.parseExpression(attributes.iterator().next().getAttribute());
        return ExpressionUtils.evaluateAsBoolean(exp, ctx) ? ACCESS_GRANTED : ACCESS_DENIED;
    }
View Full Code Here

TOP

Related Classes of org.springframework.expression.Expression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.