当前位置: 首页>>代码示例>>Java>>正文


Java StandardEvaluationContext.setVariables方法代码示例

本文整理汇总了Java中org.springframework.expression.spel.support.StandardEvaluationContext.setVariables方法的典型用法代码示例。如果您正苦于以下问题:Java StandardEvaluationContext.setVariables方法的具体用法?Java StandardEvaluationContext.setVariables怎么用?Java StandardEvaluationContext.setVariables使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.expression.spel.support.StandardEvaluationContext的用法示例。


在下文中一共展示了StandardEvaluationContext.setVariables方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: evaluateTemplate

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@Override
public String evaluateTemplate(String expressionTemplate, Map<String, Object> evaluationContext) {
    Optional.ofNullable(expressionTemplate)
        .filter(template -> !template.isEmpty())
        .orElseThrow(() -> new IllegalArgumentException("Expression template cannot be null or empty"));

    Optional.ofNullable(evaluationContext)
        .orElseThrow(() -> new IllegalArgumentException("Evaluation context cannot be null"));

    Expression expression = new SpelExpressionParser().parseExpression(expressionTemplate
            ,new TemplateParserContext("@{","}"));

    StandardEvaluationContext standardEvaluationContext = new StandardEvaluationContext();
    try {
        standardEvaluationContext.registerFunction("urlEncode",
                Functions.class.getDeclaredMethod("urlEncode", new Class[] {String.class}));
    } catch (NoSuchMethodException e) {
        throw new EvaluationException("Fail to register function to evaluation context", e);
    }
    standardEvaluationContext.addPropertyAccessor(new MapAccessor());
    standardEvaluationContext.setVariables(evaluationContext);

    return expression.getValue(standardEvaluationContext,String.class);
}
 
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:25,代码来源:ExpressionEvaluationServiceImpl.java

示例2: evaluateConditional

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@Override
public boolean evaluateConditional(String conditionalExpression, Map<String, Object> evaluationContext) {
    Optional.ofNullable(conditionalExpression)
            .filter(template -> !template.isEmpty())
            .orElseThrow(() -> new IllegalArgumentException("Conditional expression cannot be null or empty"));

    Optional.ofNullable(evaluationContext)
            .orElseThrow(() -> new IllegalArgumentException("Evaluation context cannot be null"));

    Expression expression = new SpelExpressionParser().parseExpression(conditionalExpression);

    StandardEvaluationContext standardEvaluationContext = new StandardEvaluationContext();
    standardEvaluationContext.addPropertyAccessor(new MapAccessor());
    standardEvaluationContext.setVariables(evaluationContext);

    return expression.getValue(standardEvaluationContext,Boolean.class);
}
 
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:18,代码来源:ExpressionEvaluationServiceImpl.java

示例3: isValid

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
public boolean isValid(Object[] values, ConstraintValidatorContext context) {
	StandardEvaluationContext spelContext = new StandardEvaluationContext(values);
	Map<String, Object> spelVars = IntStream.range(0, values.length).boxed()
			.collect(Collectors.toMap(i -> "arg" + i, i -> values[i]));
	spelContext.setVariables(spelVars);
	return (Boolean) parsedExpression.getValue(spelContext);
}
 
开发者ID:Javatar81,项目名称:code-examples,代码行数:8,代码来源:SpELParameterValidator.java

示例4: checkPermission

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@SneakyThrows
private boolean checkPermission(Authentication authentication,
                                Object resource,
                                Object privilegeKey,
                                boolean checkCondition,
                                boolean logPermission) {
    String roleKey = getRoleKey(authentication);
    Map<String, Object> resources = new HashMap<>();

    if (resource != null) {
        resources.putAll((Map<String, Object>) resource);
    }
    resources.put("subject", getSubject(roleKey));

    Map<String, String> env = new HashMap<>();
    env.put(EnvironmentVariable.IP.getName(), xmAuthenticationContextHolder
        .getContext().getRemoteAddress().orElse(null));
    resources.put("env", env);//put some env variables in this map

    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setVariables(resources);

    Permission permission = getPermission(roleKey, privilegeKey);

    if (!isPermissionValid(permission)) {
        log(logPermission, Level.ERROR,
            "access denied: privilege={}, role={}, userKey={} due to privilege is not permitted",
            privilegeKey, roleKey, getUserKey());
        return false;
    }
    boolean validCondition = true;
    if (!isConditionValid(permission.getEnvCondition(), context)) {
        log(logPermission, Level.ERROR,
            "access denied: privilege={}, role={}, userKey={} due to env condition: [{}] with context [{}]",
            privilegeKey, roleKey, getUserKey(), permission.getEnvCondition().getExpressionString(), resources);
        validCondition = false;
    }
    if (checkCondition && !isConditionValid(permission.getResourceCondition(), context)) {
        log(logPermission, Level.ERROR,
            "access denied: privilege={}, role={}, userKey={} due to env condition: [{}] with context [{}] "
                + "with context [{}]",
            privilegeKey, roleKey, getUserKey(), permission.getResourceCondition().getExpressionString(),
            resources);
        validCondition = false;
    }
    if (!validCondition && ReactionStrategy.SKIP.equals(permission.getReactionStrategy())) {
        throw new SkipPermissionException("Skip permission", permission.getRoleKey() + ":"
            + permission.getPrivilegeKey());
    } else if (!validCondition) {
        return false;
    }
    log(logPermission, Level.INFO,
        "access granted: privilege={}, role={}, userKey={}",
        privilegeKey, roleKey, getUserKey());
    return true;
}
 
开发者ID:xm-online,项目名称:xm-commons,代码行数:58,代码来源:PermissionCheckService.java


注:本文中的org.springframework.expression.spel.support.StandardEvaluationContext.setVariables方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。