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


Java SpelExpressionParser类代码示例

本文整理汇总了Java中org.springframework.expression.spel.standard.SpelExpressionParser的典型用法代码示例。如果您正苦于以下问题:Java SpelExpressionParser类的具体用法?Java SpelExpressionParser怎么用?Java SpelExpressionParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SpelExpressionParser类属于org.springframework.expression.spel.standard包,在下文中一共展示了SpelExpressionParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getUserInfos

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的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: getSpringExpressionParser

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的package包/类
/**
 * Gets spring expression parser.
 *
 * @return the spring expression parser
 */
protected SpringELExpressionParser getSpringExpressionParser() {
    final SpelParserConfiguration configuration = new SpelParserConfiguration();
    final SpelExpressionParser spelExpressionParser = new SpelExpressionParser(configuration);
    final SpringELExpressionParser parser = new SpringELExpressionParser(spelExpressionParser,
            this.flowBuilderServices.getConversionService());

    parser.addPropertyAccessor(new ActionPropertyAccessor());
    parser.addPropertyAccessor(new BeanFactoryPropertyAccessor());
    parser.addPropertyAccessor(new FlowVariablePropertyAccessor());
    parser.addPropertyAccessor(new MapAdaptablePropertyAccessor());
    parser.addPropertyAccessor(new MessageSourcePropertyAccessor());
    parser.addPropertyAccessor(new ScopeSearchingPropertyAccessor());
    parser.addPropertyAccessor(new BeanExpressionContextAccessor());
    parser.addPropertyAccessor(new MapAccessor());
    parser.addPropertyAccessor(new MapAdaptablePropertyAccessor());
    parser.addPropertyAccessor(new EnvironmentAccessor());
    parser.addPropertyAccessor(new ReflectivePropertyAccessor());
    return parser;

}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:26,代码来源:AbstractCasWebflowConfigurer.java

示例3: NativeEbeanQuery

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的package包/类
/**
 * Creates a new {@link NativeEbeanQuery} encapsulating the query annotated on the given {@link EbeanQueryMethod}.
 *
 * @param method                    must not be {@literal null}.
 * @param ebeanServer               must not be {@literal null}.
 * @param queryString               must not be {@literal null} or empty.
 * @param evaluationContextProvider
 */
public NativeEbeanQuery(EbeanQueryMethod method, EbeanServer ebeanServer, String queryString,
                        EvaluationContextProvider evaluationContextProvider, SpelExpressionParser parser) {

  super(method, ebeanServer, queryString, evaluationContextProvider, parser);

  Parameters<?, ?> parameters = method.getParameters();
  boolean hasPagingOrSortingParameter = parameters.hasPageableParameter() || parameters.hasSortParameter();
  boolean containsPageableOrSortInQueryExpression = queryString.contains("#pageable")
      || queryString.contains("#sort");

  if (hasPagingOrSortingParameter && !containsPageableOrSortInQueryExpression) {
    throw new InvalidEbeanQueryMethodException(
        "Cannot use native queries with dynamic sorting and/or pagination in method " + method);
  }
}
 
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:24,代码来源:NativeEbeanQuery.java

示例4: NativeEbeanUpdate

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的package包/类
/**
 * Creates a new {@link NativeEbeanUpdate} encapsulating the query annotated on the given {@link EbeanQueryMethod}.
 *
 * @param method                    must not be {@literal null}.
 * @param ebeanServer               must not be {@literal null}.
 * @param queryString               must not be {@literal null} or empty.
 * @param evaluationContextProvider
 */
public NativeEbeanUpdate(EbeanQueryMethod method, EbeanServer ebeanServer, String queryString,
                         EvaluationContextProvider evaluationContextProvider, SpelExpressionParser parser) {

  super(method, ebeanServer, queryString, evaluationContextProvider, parser);

  Parameters<?, ?> parameters = method.getParameters();
  boolean hasPagingOrSortingParameter = parameters.hasPageableParameter() || parameters.hasSortParameter();
  boolean containsPageableOrSortInQueryExpression = queryString.contains("#pageable")
      || queryString.contains("#sort");

  if (hasPagingOrSortingParameter && !containsPageableOrSortInQueryExpression) {
    throw new InvalidEbeanQueryMethodException(
        "Cannot use native queries with dynamic sorting and/or pagination in method " + method);
  }
}
 
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:24,代码来源:NativeEbeanUpdate.java

示例5: ProducerConfigurationMessageHandler

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的package包/类
ProducerConfigurationMessageHandler(KafkaTemplate<byte[], byte[]> kafkaTemplate, String topic,
		ExtendedProducerProperties<KafkaProducerProperties> producerProperties,
		ProducerFactory<byte[], byte[]> producerFactory) {
	super(kafkaTemplate);
	setTopicExpression(new LiteralExpression(topic));
	setMessageKeyExpression(producerProperties.getExtension().getMessageKeyExpression());
	setBeanFactory(KafkaMessageChannelBinder.this.getBeanFactory());
	if (producerProperties.isPartitioned()) {
		SpelExpressionParser parser = new SpelExpressionParser();
		setPartitionIdExpression(parser.parseExpression("headers." + BinderHeaders.PARTITION_HEADER));
	}
	if (producerProperties.getExtension().isSync()) {
		setSync(true);
	}
	this.producerFactory = producerFactory;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:17,代码来源:KafkaMessageChannelBinder.java

示例6: mapOfMap_SPR7244

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的package包/类
@Test
public void mapOfMap_SPR7244() throws Exception {
	Map<String, Object> map = new LinkedHashMap<String, Object>();
	map.put("uri", "http:");
	Map<String, String> nameMap = new LinkedHashMap<String, String>();
	nameMap.put("givenName", "Arthur");
	map.put("value", nameMap);

	StandardEvaluationContext ctx = new StandardEvaluationContext(map);
	ExpressionParser parser = new SpelExpressionParser();
	String el1 = "#root['value'].get('givenName')";
	Expression exp = parser.parseExpression(el1);
	Object evaluated = exp.getValue(ctx);
	assertEquals("Arthur", evaluated);

	String el2 = "#root['value']['givenName']";
	exp = parser.parseExpression(el2);
	evaluated = exp.getValue(ctx);
	assertEquals("Arthur", evaluated);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:SpelReproTests.java

示例7: testLiterals

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的package包/类
@Test
public void testLiterals() throws Exception {
	ExpressionParser parser = new SpelExpressionParser();

	String helloWorld = (String) parser.parseExpression("'Hello World'").getValue(); // evals to "Hello World"
	assertEquals("Hello World",helloWorld);

	double avogadrosNumber  = (Double) parser.parseExpression("6.0221415E+23").getValue();
	assertEquals(6.0221415E+23, avogadrosNumber, 0);

	int maxValue = (Integer) parser.parseExpression("0x7FFFFFFF").getValue();  // evals to 2147483647
	assertEquals(Integer.MAX_VALUE,maxValue);

	boolean trueValue = (Boolean) parser.parseExpression("true").getValue();
	assertTrue(trueValue);

	Object nullValue = parser.parseExpression("null").getValue();
	assertNull(nullValue);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:SpelDocumentationTests.java

示例8: indexerMapAccessor_12045

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的package包/类
@Test
public void indexerMapAccessor_12045() throws Exception {
	SpelParserConfiguration spc = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE,this.getClass().getClassLoader());
	SpelExpressionParser sep = new SpelExpressionParser(spc);
	expression=sep.parseExpression("headers[command]");
	MyMessage root = new MyMessage();
	assertEquals("wibble",expression.getValue(root));
	// This next call was failing because the isCompilable check in Indexer did not check on the key being compilable
	// (and also generateCode in the Indexer was missing the optimization that it didn't need necessarily need to call
	// generateCode for that accessor)
	assertEquals("wibble",expression.getValue(root));
	assertCanCompile(expression);

	// What about a map key that is an expression - ensure the getKey() is evaluated in the right scope
	expression=sep.parseExpression("headers[getKey()]");
	assertEquals("wobble",expression.getValue(root));
	assertEquals("wobble",expression.getValue(root));

	expression=sep.parseExpression("list[getKey2()]");
	assertEquals("wobble",expression.getValue(root));
	assertEquals("wobble",expression.getValue(root));

	expression = sep.parseExpression("ia[getKey2()]");
	assertEquals(3,expression.getValue(root));
	assertEquals(3,expression.getValue(root));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:SpelCompilationCoverageTests.java

示例9: testSpecialVariables

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testSpecialVariables() throws Exception {
	// create an array of integers
	List<Integer> primes = new ArrayList<Integer>();
	primes.addAll(Arrays.asList(2,3,5,7,11,13,17));

	// create parser and set variable 'primes' as the array of integers
	ExpressionParser parser = new SpelExpressionParser();
	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setVariable("primes",primes);

	// all prime numbers > 10 from the list (using selection ?{...})
	List<Integer> primesGreaterThanTen = (List<Integer>) parser.parseExpression("#primes.?[#this>10]").getValue(context);
	assertEquals("[11, 13, 17]",primesGreaterThanTen.toString());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:SpelDocumentationTests.java

示例10: indexIntoGenericPropertyContainingMapObject

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的package包/类
@Test
public void indexIntoGenericPropertyContainingMapObject() {
	Map<String, Map<String, String>> property = new HashMap<String, Map<String, String>>();
	Map<String, String> map =  new HashMap<String, String>();
	map.put("foo", "bar");
	property.put("property", map);
	SpelExpressionParser parser = new SpelExpressionParser();
	StandardEvaluationContext context = new StandardEvaluationContext();
	context.addPropertyAccessor(new MapAccessor());
	context.setRootObject(property);
	Expression expression = parser.parseExpression("property");
	assertEquals("java.util.HashMap<?, ?>", expression.getValueTypeDescriptor(context).toString());
	assertEquals(map, expression.getValue(context));
	assertEquals(map, expression.getValue(context, Map.class));
	expression = parser.parseExpression("property['foo']");
	assertEquals("bar", expression.getValue(context));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:IndexingTests.java

示例11: testScenario_AddingYourOwnPropertyResolvers_1

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的package包/类
/**
 * Scenario: add a property resolver that will get called in the resolver chain, this one only supports reading.
 */
@Test
public void testScenario_AddingYourOwnPropertyResolvers_1() throws Exception {
	// Create a parser
	SpelExpressionParser parser = new SpelExpressionParser();
	// Use the standard evaluation context
	StandardEvaluationContext ctx = new StandardEvaluationContext();

	ctx.addPropertyAccessor(new FruitColourAccessor());
	Expression expr = parser.parseRaw("orange");
	Object value = expr.getValue(ctx);
	assertEquals(Color.orange, value);

	try {
		expr.setValue(ctx, Color.blue);
		fail("Should not be allowed to set oranges to be blue !");
	} catch (SpelEvaluationException ee) {
		assertEquals(ee.getMessageCode(), SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:ExpressionLanguageScenarioTests.java

示例12: testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的package包/类
/**
 * Scenario: using your own java methods and calling them from the expression
 */
@Test
public void testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem() throws SecurityException, NoSuchMethodException {
	try {
		// Create a parser
		SpelExpressionParser parser = new SpelExpressionParser();
		// Use the standard evaluation context
		StandardEvaluationContext ctx = new StandardEvaluationContext();
		ctx.registerFunction("repeat",ExpressionLanguageScenarioTests.class.getDeclaredMethod("repeat",String.class));

		Expression expr = parser.parseRaw("#repeat('hello')");
		Object value = expr.getValue(ctx);
		assertEquals("hellohello", value);

	} catch (EvaluationException ee) {
		ee.printStackTrace();
		fail("Unexpected Exception: " + ee.getMessage());
	} catch (ParseException pe) {
		pe.printStackTrace();
		fail("Unexpected Exception: " + pe.getMessage());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:ExpressionLanguageScenarioTests.java

示例13: indexIntoGenericPropertyContainingGrowingList

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的package包/类
@Test
public void indexIntoGenericPropertyContainingGrowingList() {
	List<String> property = new ArrayList<String>();
	this.property = property;
	SpelParserConfiguration configuration = new SpelParserConfiguration(true, true);
	SpelExpressionParser parser = new SpelExpressionParser(configuration);
	Expression expression = parser.parseExpression("property");
	assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
	assertEquals(property, expression.getValue(this));
	expression = parser.parseExpression("property[0]");
	try {
		assertEquals("bar", expression.getValue(this));
	} catch (EvaluationException e) {
		assertTrue(e.getMessage().startsWith("EL1053E"));
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:IndexingTests.java

示例14: indexIntoGenericPropertyContainingGrowingList2

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的package包/类
@Test
public void indexIntoGenericPropertyContainingGrowingList2() {
	List<String> property2 = new ArrayList<String>();
	this.property2 = property2;
	SpelParserConfiguration configuration = new SpelParserConfiguration(true, true);
	SpelExpressionParser parser = new SpelExpressionParser(configuration);
	Expression expression = parser.parseExpression("property2");
	assertEquals("java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
	assertEquals(property2, expression.getValue(this));
	expression = parser.parseExpression("property2[0]");
	try {
		assertEquals("bar", expression.getValue(this));
	} catch (EvaluationException e) {
		assertTrue(e.getMessage().startsWith("EL1053E"));
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:IndexingTests.java

示例15: testSpel

import org.springframework.expression.spel.standard.SpelExpressionParser; //导入依赖的package包/类
@Test
	public void testSpel(){
		 //使用SPEL进行key的解析
        ExpressionParser parser = new SpelExpressionParser(); 
        //SPEL上下文
        StandardEvaluationContext context = new StandardEvaluationContext();
        //把方法参数放入SPEL上下文中
        List<Model> list = MyBatisUtil.parseBase("username,=,leiyong","password,=,asssd","loginName,=,ray");
        context.setVariable("objs", list);
        System.out.println(parser.parseExpression("#objs[0].column").getValue(context,String.class));
        System.out.println(parser.parseExpression("#objs?.![column]").getValue(context,String.class));
        System.out.println(parser.parseExpression("#objs?.![column+operate]").getValue(context,String.class));
        context.setVariable("obj", list.get(0));
//        System.out.println(parser.parseExpression("#orgPk+#userName").getValue(context,String.class));
        System.out.println(parser.parseExpression("#obj?.column+#obj?.operate").getValue(context,String.class));
        System.out.println(parser.parseExpression("#obj?.column+{':'}+#obj?.operate").getValue(context,String.class));
        System.out.println(parser.parseExpression("#obj?.operate").getValue(context,String.class));
        System.out.println(parser.parseExpression("#obj?.value").getValue(context,String.class));
        System.out.println(parser.parseExpression("#obj?.value").getValue(context,String.class));
        System.out.println(parser.parseExpression("'test'").getValue(context,String.class));
        System.out.println(parser.parseExpression("#objs?.!['1']").getValue(context,String.class));
	}
 
开发者ID:leiyong0326,项目名称:phone,代码行数:23,代码来源:SpringSpelTest.java


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