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


Java ExpressionParser.parseExpression方法代码示例

本文整理汇总了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;
}
 
开发者ID:EsupPortail,项目名称:esup-sgc,代码行数:21,代码来源:SpelUserInfoService.java

示例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;
}
 
开发者ID:MarcGiffing,项目名称:bucket4j-spring-boot-starter,代码行数:22,代码来源:Bucket4JBaseConfiguration.java

示例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";
}
 
开发者ID:MarcGiffing,项目名称:bucket4j-spring-boot-starter,代码行数:33,代码来源:Bucket4JBaseConfiguration.java

示例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));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:SpelReproTests.java

示例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;
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:20,代码来源:SetpointExpressionSecurityMetadataSource.java

示例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;		
}
 
开发者ID:hserv,项目名称:coordinated-entry,代码行数:19,代码来源:SectionScoreServiceImplV3.java

示例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));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:MapAccessTests.java

示例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;
    }
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:14,代码来源:GenericScope.java

示例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 ) );

}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:37,代码来源:Boot_Container_Test.java

示例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;
}
 
开发者ID:MarcGiffing,项目名称:bucket4j-spring-boot-starter,代码行数:22,代码来源:Bucket4JBaseConfiguration.java

示例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();
}
 
开发者ID:ShiftLeftSecurity,项目名称:HelloShiftLeft,代码行数:13,代码来源:SearchController.java

示例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);
}
 
开发者ID:cerner,项目名称:jwala,代码行数:13,代码来源:DecryptPassword.java

示例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);
}
 
开发者ID:cerner,项目名称:jwala,代码行数:14,代码来源:DecryptPassword.java

示例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);
    }
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:16,代码来源:SpelSample.java

示例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;
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:16,代码来源:SpringelFormat.java


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