本文整理汇总了Java中org.springframework.expression.Expression.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java Expression.getValue方法的具体用法?Java Expression.getValue怎么用?Java Expression.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.expression.Expression
的用法示例。
在下文中一共展示了Expression.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.springframework.expression.Expression; //导入方法依赖的package包/类
@Override
public Result execute(Object target) {
try {
EvaluationContext ctx = create(target);
Expression exp = parser.parseExpression(expression);
Boolean value = (Boolean) exp.getValue(ctx);
if (value) {
return ok();
} else {
return nok("Expression " + expression + " returned false");
}
} catch (Exception e) {
// TODO - Log me
return nok("Exception : " + e.getMessage());
}
}
示例2: getKeyFilter
import org.springframework.expression.Expression; //导入方法依赖的package包/类
/**
* Creates the key filter lambda which is responsible to decide how the rate limit will be performed. The key
* is the unique identifier like an IP address or a username.
*
* @param url is used to generated a unique cache key
* @param rateLimit the {@link RateLimit} configuration which holds the skip condition string
* @param expressionParser is used to evaluate the expression if the filter key type is EXPRESSION.
* @param beanFactory used to get full access to all java beans in the SpEl
* @return should not been null. If no filter key type is matching a plain 1 is returned so that all requests uses the same key.
*/
public KeyFilter getKeyFilter(String url, RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
switch(rateLimit.getFilterKeyType()) {
case IP:
return (request) -> url + "-" + request.getRemoteAddr();
case EXPRESSION:
String expression = rateLimit.getExpression();
if(StringUtils.isEmpty(expression)) {
throw new MissingKeyFilterExpressionException();
}
StandardEvaluationContext context = new StandardEvaluationContext();
context.setBeanResolver(new BeanFactoryResolver(beanFactory));
return (request) -> {
//TODO performance problem - how can the request object reused in the expression without setting it as a rootObject
Expression expr = expressionParser.parseExpression(rateLimit.getExpression());
final String value = expr.getValue(context, request, String.class);
return url + "-" + value;
};
}
return (request) -> url + "-" + "1";
}
示例3: getEligbleOfferings
import org.springframework.expression.Expression; //导入方法依赖的package包/类
List<CmsCI> getEligbleOfferings(CmsRfcCISimple cmsRfcCISimple, String offeringNS) {
List<CmsCI> offerings = new ArrayList<>();
List<CmsCI> list = cmsCmProcessor.getCiBy3(offeringNS, "cloud.Offering", null);
for (CmsCI ci: list){
CmsCIAttribute criteriaAttribute = ci.getAttribute("criteria");
String criteria = criteriaAttribute.getDfValue();
if (isLikelyElasticExpression(criteria)){
logger.warn("cloud.Offering CI ID:"+ci.getCiId()+" likely still has elastic search criteria. Evaluation may not be successful!");
logger.info("ES criteria:"+criteria);
criteria = convert(criteria);
logger.info("Converted SPEL criteria:"+criteria);
}
Expression expression = exprParser.parseExpression(criteria);
StandardEvaluationContext context = new StandardEvaluationContext();
context.setRootObject(cmsRfcCISimple);
boolean match = (boolean) expression.getValue(context, Boolean.class);
if (match){
offerings.add(ci);
}
}
return offerings;
}
示例4: isExpressionMatching
import org.springframework.expression.Expression; //导入方法依赖的package包/类
public boolean isExpressionMatching(CmsCI complianceCi, CmsWorkOrderBase wo) {
CmsCIAttribute attr = complianceCi.getAttribute(ATTR_NAME_FILTER);
if (attr == null) {
return false;
}
String filter = attr.getDjValue();
try {
if (StringUtils.isNotBlank(filter)) {
Expression expr = exprParser.parseExpression(filter);
EvaluationContext context = getEvaluationContext(wo);
//parse the filter expression and check if it matches this ci/rfc
Boolean match = expr.getValue(context, Boolean.class);
if (logger.isDebugEnabled()) {
logger.debug("Expression " + filter + " provided by compliance ci " + complianceCi.getCiId() + " not matched for ci " + getCiName(wo));
}
return match;
}
} catch (ParseException | EvaluationException e) {
String error = "Error in evaluating expression " + filter +" provided by compliance ci " + complianceCi.getCiId() + ", target ci :" + getCiName(wo);
logger.error(error, e);
}
return false;
}
示例5: getMartinis
import org.springframework.expression.Expression; //导入方法依赖的package包/类
protected Collection<Martini> getMartinis(Expression expression) {
StandardEvaluationContext context = new StandardEvaluationContext();
List<MethodResolver> methodResolvers = context.getMethodResolvers();
ArrayList<MethodResolver> modifiedList = Lists.newArrayList(methodResolvers);
modifiedList.add(new TagResolver(categories));
context.setMethodResolvers(modifiedList);
ImmutableList<Martini> martinis = getMartinis();
List<Martini> matches = Lists.newArrayListWithCapacity(martinis.size());
for (Martini martini : martinis) {
Boolean match = expression.getValue(context, martini, Boolean.class);
if (match) {
matches.add(martini);
}
}
return matches;
}
示例6: elvis
import org.springframework.expression.Expression; //导入方法依赖的package包/类
@Test
public void elvis() throws Exception {
Expression expression = parser.parseExpression("'a'?:'b'");
String resultI = expression.getValue(String.class);
assertCanCompile(expression);
String resultC = expression.getValue(String.class);
assertEquals("a",resultI);
assertEquals("a",resultC);
expression = parser.parseExpression("null?:'a'");
resultI = expression.getValue(String.class);
assertCanCompile(expression);
resultC = expression.getValue(String.class);
assertEquals("a",resultI);
assertEquals("a",resultC);
String s = "abc";
expression = parser.parseExpression("#root?:'b'");
assertCantCompile(expression);
resultI = expression.getValue(s,String.class);
assertEquals("abc",resultI);
assertCanCompile(expression);
}
示例7: SPR10452
import org.springframework.expression.Expression; //导入方法依赖的package包/类
@Test
public void SPR10452() throws Exception {
SpelParserConfiguration configuration = new SpelParserConfiguration(false, false);
ExpressionParser parser = new SpelExpressionParser(configuration);
StandardEvaluationContext context = new StandardEvaluationContext();
Expression spel = parser.parseExpression("#enumType.values()");
context.setVariable("enumType", ABC.class);
Object result = spel.getValue(context);
assertNotNull(result);
assertTrue(result.getClass().isArray());
assertEquals(ABC.A, Array.get(result, 0));
assertEquals(ABC.B, Array.get(result, 1));
assertEquals(ABC.C, Array.get(result, 2));
context.setVariable("enumType", XYZ.class);
result = spel.getValue(context);
assertNotNull(result);
assertTrue(result.getClass().isArray());
assertEquals(XYZ.X, Array.get(result, 0));
assertEquals(XYZ.Y, Array.get(result, 1));
assertEquals(XYZ.Z, Array.get(result, 2));
}
示例8: format
import org.springframework.expression.Expression; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T format(Object formatBean, String expressionString) {
// 解析表达式
Expression expression = createExpression(expressionString);
// 构造上下文
EvaluationContext context = createContext(formatBean);
// 解析
return (T) expression.getValue(context);
}
示例9: encrypt
import org.springframework.expression.Expression; //导入方法依赖的package包/类
public String encrypt(String unencryptedValue) {
if (unencryptedValue==null) {
return null;
}
final ExpressionParser expressionParser = new SpelExpressionParser();
final Expression encryptExpression = expressionParser.parseExpression(encryptorImpl);
final StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("stringToEncrypt", unencryptedValue);
return encryptExpression.getValue(context, String.class);
}
示例10: resolvePrincipal
import org.springframework.expression.Expression; //导入方法依赖的package包/类
String resolvePrincipal(Session session) {
String principalName = session.getAttribute(PRINCIPAL_NAME_INDEX_NAME);
if (principalName != null) {
return principalName;
}
Object auth = session.getAttribute(SPRING_SECURITY_CONTEXT);
if (auth == null) {
return null;
}
Expression expression = SPEL_PARSER.parseExpression("authentication?.name");
return expression.getValue(auth, String.class);
}
示例11: isConditionValid
import org.springframework.expression.Expression; //导入方法依赖的package包/类
private static boolean isConditionValid(Expression expression, StandardEvaluationContext context) {
boolean result;
if (expression == null || StringUtils.isEmpty(expression.getExpressionString())) {
result = true;
} else {
try {
result = expression.getValue(context, Boolean.class);
} catch (Exception e) {
result = false;
log.error("Exception while getting value ", e);
}
}
return result;
}
示例12: executeCondition
import org.springframework.expression.Expression; //导入方法依赖的package包/类
/**
* Creates the lambda for the execute condition which will be evaluated on each request.
*
* @param rateLimit the {@link RateLimit} configuration which holds the execute condition string
* @param expressionParser is used to evaluate the execution expression
* @param beanFactory used to get full access to all java beans in the SpEl
* @return the lamdba condition which will be evaluated lazy - null if there is no condition available.
*/
public Condition executeCondition(RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
StandardEvaluationContext context = new StandardEvaluationContext();
context.setBeanResolver(new BeanFactoryResolver(beanFactory));
if(rateLimit.getExecuteCondition() != null) {
return (request) -> {
Expression expr = expressionParser.parseExpression(rateLimit.getExecuteCondition());
Boolean value = expr.getValue(context, request, Boolean.class);
return value;
};
}
return null;
}
示例13: getValue
import org.springframework.expression.Expression; //导入方法依赖的package包/类
@Override
public String getValue() throws EvaluationException {
StringBuilder sb = new StringBuilder();
for (Expression expression : this.expressions) {
String value = expression.getValue(String.class);
if (value != null) {
sb.append(value);
}
}
return sb.toString();
}
示例14: parseSpelExpression
import org.springframework.expression.Expression; //导入方法依赖的package包/类
public static void parseSpelExpression(String property) {
SpelExpressionParser parser = new SpelExpressionParser();
//Static value not that useful .. but safe
Expression exp1 = parser.parseExpression("'safe expression'");
String constantValue = exp1.getValue(String.class);
System.out.println("exp1="+constantValue);
StandardEvaluationContext testContext = new StandardEvaluationContext(TEST_PERSON);
//Unsafe if the input is control by the user..
Expression exp2 = parser.parseExpression(property+" == 'Benoit'");
String dynamicValue = exp2.getValue(testContext, String.class);
System.out.println("exp2=" + dynamicValue);
}
示例15: encryptUsingPlatformBean
import org.springframework.expression.Expression; //导入方法依赖的package包/类
@Override
public String encryptUsingPlatformBean(String cleartext) {
SpelExpressionParser expressionParser = new SpelExpressionParser();
String encryptExpressionString = ApplicationProperties.get("encryptExpression");
Expression encryptExpression = expressionParser.parseExpression(encryptExpressionString);
StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("stringToEncrypt", cleartext);
return encryptExpression.getValue(context, String.class);
}