本文整理汇总了Java中org.springframework.expression.ExpressionParser.parseExpression方法的典型用法代码示例。如果您正苦于以下问题:Java ExpressionParser.parseExpression方法的具体用法?Java ExpressionParser.parseExpression怎么用?Java ExpressionParser.parseExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.expression.ExpressionParser
的用法示例。
在下文中一共展示了ExpressionParser.parseExpression方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserInfos
import org.springframework.expression.ExpressionParser; //导入方法依赖的package包/类
@Override
public Map<String, String> getUserInfos(User user, HttpServletRequest request, final Map<String, String> userInfosInComputing) {
Map<String, String> userInfos = new HashMap<String, String>();
for(String name: sgcParam2spelExp.keySet()) {
String expression = sgcParam2spelExp.get(name);
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(expression);
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("user", user);
context.setVariable("request", request);
context.setVariable("userInfosInComputing", userInfosInComputing);
context.setVariable("dateUtils", dateUtils);
String value = (String) exp.getValue(context);
userInfos.put(name, value);
}
return userInfos;
}
示例2: skipCondition
import org.springframework.expression.ExpressionParser; //导入方法依赖的package包/类
/**
* Creates the lambda for the skip condition which will be evaluated on each request
*
* @param rateLimit the {@link RateLimit} configuration which holds the skip condition string
* @param expressionParser is used to evaluate the skip 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 skipCondition(RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
StandardEvaluationContext context = new StandardEvaluationContext();
context.setBeanResolver(new BeanFactoryResolver(beanFactory));
if(rateLimit.getSkipCondition() != null) {
return (request) -> {
Expression expr = expressionParser.parseExpression(rateLimit.getSkipCondition());
Boolean value = expr.getValue(context, request, Boolean.class);
return value;
};
}
return null;
}
示例3: getKeyFilter
import org.springframework.expression.ExpressionParser; //导入方法依赖的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";
}
示例4: SPR9735
import org.springframework.expression.ExpressionParser; //导入方法依赖的package包/类
@Test
public void SPR9735() {
Item item = new Item();
item.setName("parent");
Item item1 = new Item();
item1.setName("child1");
Item item2 = new Item();
item2.setName("child2");
item.add(item1);
item.add(item2);
ExpressionParser parser = new SpelExpressionParser();
EvaluationContext context = new StandardEvaluationContext();
Expression exp = parser.parseExpression("#item[0].name");
context.setVariable("item", item);
assertEquals("child1", exp.getValue(context));
}
示例5: createPostInvocationAttribute
import org.springframework.expression.ExpressionParser; //导入方法依赖的package包/类
protected PostInvocationAttribute createPostInvocationAttribute(String postFilter, String postAuthorize) {
try {
log.debug("createPostInvocationAttribute from filter " + postFilter + " and rule " + postAuthorize);
String postAuthValue = parseValueParameter(postAuthorize);
String postFilterValue = parseValueParameter(postFilter);
ExpressionParser parser = new SpelExpressionParser();
Expression postAuthorizeExpression = postAuthorize == null ? null : parser.parseExpression(postAuthValue);
Expression postFilterExpression = postFilter == null ? null : parser.parseExpression(postFilterValue);
if (postFilterExpression != null || postAuthorizeExpression != null) {
return new PostCibetConfigAttribute(postFilterExpression, postAuthorizeExpression);
}
} catch (ParseException e) {
throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e);
}
return null;
}
示例6: calculateQuestionScore
import org.springframework.expression.ExpressionParser; //导入方法依赖的package包/类
public int calculateQuestionScore(QuestionEntity questionEntity,ResponseEntity responseEntity) {
int score=0;
boolean result;
EvaluationContext context = new StandardEvaluationContext(responseEntity);
ExpressionParser parser = new SpelExpressionParser();
if(questionEntity.getCorrectValueForAssessment()!=null) {
try{
Expression expression = parser.parseExpression(questionEntity.getCorrectValueForAssessment());
result = expression.getValue(context,boolean.class);
if(result) {
score = questionEntity.getQuestionWeight();
}
}catch (Exception e) {
}
}
return score;
}
示例7: testGetValuePerformance
import org.springframework.expression.ExpressionParser; //导入方法依赖的package包/类
@Test
public void testGetValuePerformance() throws Exception {
Assume.group(TestGroup.PERFORMANCE);
Map<String, String> map = new HashMap<String, String>();
map.put("key", "value");
EvaluationContext context = new StandardEvaluationContext(map);
ExpressionParser spelExpressionParser = new SpelExpressionParser();
Expression expr = spelExpressionParser.parseExpression("#root['key']");
StopWatch s = new StopWatch();
s.start();
for (int i = 0; i < 10000; i++) {
expr.getValue(context);
}
s.stop();
assertThat(s.getTotalTimeMillis(), lessThan(200L));
}
示例8: parseExpression
import org.springframework.expression.ExpressionParser; //导入方法依赖的package包/类
private Expression parseExpression(String input) {
if (StringUtils.hasText(input)) {
ExpressionParser parser = new SpelExpressionParser();
try {
return parser.parseExpression(input);
} catch (ParseException e) {
throw new IllegalArgumentException("Cannot parse expression: " + input, e);
}
} else {
return null;
}
}
示例9: validate_spring_expression
import org.springframework.expression.ExpressionParser; //导入方法依赖的package包/类
@Ignore
@Test
public void validate_spring_expression ()
throws Exception {
// String url = "http://csaptools.yourcompany.com/admin/api/clusters";
String url = "http://testhost.yourcompany.com:8011/CsAgent/api/collection/application/CsAgent_8011/30/10";
ObjectNode restResponse = analyticsTemplate.getForObject( url, ObjectNode.class );
logger.info( "Url: {} response: {}", url, jacksonMapper.writerWithDefaultPrettyPrinter()
.writeValueAsString( restResponse ) );
ArrayList<Integer> publishvals = jacksonMapper.readValue(
restResponse.at( "/data/publishEvents" )
.traverse(),
new TypeReference<ArrayList<Integer>>() {
} );
int total = publishvals.stream().mapToInt( Integer::intValue ).sum();
logger.info( "Total: {} publishvals: {}", total, publishvals );
EvaluationContext context = new StandardEvaluationContext();
context.setVariable( "total", total );
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression( "#total.toString()" );
logger.info( "SPEL evalutation: {}", (String) exp.getValue( context ) );
exp = parser.parseExpression( "#total > 99" );
logger.info( "#total > 99 SPEL evalutation: {}", (Boolean) exp.getValue( context ) );
exp = parser.parseExpression( "#total > 3" );
logger.info( "#total > 3 SPEL evalutation: {}", (Boolean) exp.getValue( context ) );
}
示例10: executeCondition
import org.springframework.expression.ExpressionParser; //导入方法依赖的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;
}
示例11: doGetSearch
import org.springframework.expression.ExpressionParser; //导入方法依赖的package包/类
@RequestMapping(value = "/search/user", method = RequestMethod.GET)
public String doGetSearch(@RequestParam String foo, HttpServletResponse response, HttpServletRequest request) {
java.lang.Object message = new Object();
try {
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(foo);
message = (Object) exp.getValue();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
return message.toString();
}
示例12: decrypt
import org.springframework.expression.ExpressionParser; //导入方法依赖的package包/类
public String decrypt(String encryptedValue) {
if (encryptedValue==null) {
return null;
}
final ExpressionParser expressionParser = new SpelExpressionParser();
final Expression decryptExpression = expressionParser.parseExpression(decryptorImpl);
final StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("stringToDecrypt", encryptedValue);
return decryptExpression.getValue(context, String.class);
}
示例13: encrypt
import org.springframework.expression.ExpressionParser; //导入方法依赖的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);
}
示例14: parseExpressionInterface
import org.springframework.expression.ExpressionParser; //导入方法依赖的package包/类
public static void parseExpressionInterface(String property) {
ExpressionParser 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: format
import org.springframework.expression.ExpressionParser; //导入方法依赖的package包/类
public static String format(ExpressionParser ep, String pattern, Object dataModel) {
if (ep == null) {
ep = SpringelFormat.elParser;
}
StandardEvaluationContext context = createEvaluationContext(dataModel);
// raw return
if (context == null) {
return pattern;
}
Expression expression = ep.parseExpression(pattern, parserContext);
String result = expression.getValue(context, String.class);
return result;
}