本文整理汇总了Java中org.springframework.expression.ParseException类的典型用法代码示例。如果您正苦于以下问题:Java ParseException类的具体用法?Java ParseException怎么用?Java ParseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParseException类属于org.springframework.expression包,在下文中一共展示了ParseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doParseExpression
import org.springframework.expression.ParseException; //导入依赖的package包/类
@Override
protected SpelExpression doParseExpression(String expressionString, ParserContext context) throws ParseException {
try {
this.expressionString = expressionString;
Tokenizer tokenizer = new Tokenizer(expressionString);
tokenizer.process();
this.tokenStream = tokenizer.getTokens();
this.tokenStreamLength = this.tokenStream.size();
this.tokenStreamPointer = 0;
this.constructedNodes.clear();
SpelNodeImpl ast = eatExpression();
if (moreTokens()) {
throw new SpelParseException(peekToken().startpos,SpelMessage.MORE_INPUT,toString(nextToken()));
}
Assert.isTrue(this.constructedNodes.isEmpty());
return new SpelExpression(expressionString, ast, this.configuration);
}
catch (InternalParseException ipe) {
throw ipe.getCause();
}
}
示例2: isExpressionMatching
import org.springframework.expression.ParseException; //导入依赖的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;
}
示例3: doParseExpression
import org.springframework.expression.ParseException; //导入依赖的package包/类
@Override
protected SpelExpression doParseExpression(String expressionString, ParserContext context) throws ParseException {
try {
this.expressionString = expressionString;
Tokenizer tokenizer = new Tokenizer(expressionString);
tokenizer.process();
this.tokenStream = tokenizer.getTokens();
this.tokenStreamLength = this.tokenStream.size();
this.tokenStreamPointer = 0;
this.constructedNodes.clear();
SpelNodeImpl ast = eatExpression();
if (moreTokens()) {
throw new SpelParseException(peekToken().startPos, SpelMessage.MORE_INPUT, toString(nextToken()));
}
Assert.isTrue(this.constructedNodes.isEmpty());
return new SpelExpression(expressionString, ast, this.configuration);
}
catch (InternalParseException ex) {
throw ex.getCause();
}
}
示例4: testCreateListsOnAttemptToIndexNull01
import org.springframework.expression.ParseException; //导入依赖的package包/类
@Test
public void testCreateListsOnAttemptToIndexNull01() throws EvaluationException, ParseException {
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
Expression expression = parser.parseExpression("list[0]");
TestClass testClass = new TestClass();
Object o = null;
o = expression.getValue(new StandardEvaluationContext(testClass));
assertEquals("", o);
o = parser.parseExpression("list[3]").getValue(new StandardEvaluationContext(testClass));
assertEquals("", o);
assertEquals(4, testClass.list.size());
try {
o = parser.parseExpression("list2[3]").getValue(new StandardEvaluationContext(testClass));
fail();
} catch (EvaluationException ee) {
ee.printStackTrace();
// success!
}
o = parser.parseExpression("foo[3]").getValue(new StandardEvaluationContext(testClass));
assertEquals("", o);
assertEquals(4, testClass.getFoo().size());
}
示例5: booleanOperators
import org.springframework.expression.ParseException; //导入依赖的package包/类
@Test
public void booleanOperators() throws EvaluationException, ParseException {
SpelExpression expr = new SpelExpressionParser().parseRaw("true");
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
expr = new SpelExpressionParser().parseRaw("false");
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
expr = new SpelExpressionParser().parseRaw("false and false");
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
expr = new SpelExpressionParser().parseRaw("true and (true or false)");
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
expr = new SpelExpressionParser().parseRaw("true and true or false");
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
expr = new SpelExpressionParser().parseRaw("!true");
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
expr = new SpelExpressionParser().parseRaw("!(false or true)");
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
}
示例6: booleanOperators_symbolic_spr9614
import org.springframework.expression.ParseException; //导入依赖的package包/类
@Test
public void booleanOperators_symbolic_spr9614() throws EvaluationException, ParseException {
SpelExpression expr = new SpelExpressionParser().parseRaw("true");
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
expr = new SpelExpressionParser().parseRaw("false");
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
expr = new SpelExpressionParser().parseRaw("false && false");
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
expr = new SpelExpressionParser().parseRaw("true && (true || false)");
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
expr = new SpelExpressionParser().parseRaw("true && true || false");
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
expr = new SpelExpressionParser().parseRaw("!true");
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
expr = new SpelExpressionParser().parseRaw("!(false || true)");
assertEquals(Boolean.FALSE, expr.getValue(Boolean.class));
}
示例7: setValueExpectError
import org.springframework.expression.ParseException; //导入依赖的package包/类
/**
* Call setValue() but expect it to fail.
*/
protected void setValueExpectError(String expression, Object value) {
try {
Expression e = parser.parseExpression(expression);
if (e == null) {
fail("Parser returned null for expression");
}
if (DEBUG) {
SpelUtilities.printAbstractSyntaxTree(System.out, e);
}
StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext();
e.setValue(lContext, value);
fail("expected an error");
} catch (ParseException pe) {
pe.printStackTrace();
fail("Unexpected Exception: " + pe.getMessage());
} catch (EvaluationException ee) {
// success!
}
}
示例8: setValue
import org.springframework.expression.ParseException; //导入依赖的package包/类
protected void setValue(String expression, Object value) {
try {
Expression e = parser.parseExpression(expression);
if (e == null) {
fail("Parser returned null for expression");
}
if (DEBUG) {
SpelUtilities.printAbstractSyntaxTree(System.out, e);
}
StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext();
assertTrue("Expression is not writeable but should be", e.isWritable(lContext));
e.setValue(lContext, value);
assertEquals("Retrieved value was not equal to set value", value, e.getValue(lContext,value.getClass()));
} catch (EvaluationException ee) {
ee.printStackTrace();
fail("Unexpected Exception: " + ee.getMessage());
} catch (ParseException pe) {
pe.printStackTrace();
fail("Unexpected Exception: " + pe.getMessage());
}
}
示例9: testScenario_UsingStandardInfrastructure
import org.springframework.expression.ParseException; //导入依赖的package包/类
/**
* Scenario: using the standard infrastructure and running simple expression evaluation.
*/
@Test
public void testScenario_UsingStandardInfrastructure() {
try {
// Create a parser
SpelExpressionParser parser = new SpelExpressionParser();
// Parse an expression
Expression expr = parser.parseRaw("new String('hello world')");
// Evaluate it using a 'standard' context
Object value = expr.getValue();
// They are reusable
value = expr.getValue();
assertEquals("hello world", value);
assertEquals(String.class, value.getClass());
} catch (EvaluationException ee) {
ee.printStackTrace();
fail("Unexpected Exception: " + ee.getMessage());
} catch (ParseException pe) {
pe.printStackTrace();
fail("Unexpected Exception: " + pe.getMessage());
}
}
示例10: testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem
import org.springframework.expression.ParseException; //导入依赖的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());
}
}
示例11: parseCheck
import org.springframework.expression.ParseException; //导入依赖的package包/类
/**
* Parse the supplied expression and then create a string representation of the resultant AST, it should be the
* expected value.
*
* @param expression the expression to parse
* @param expectedStringFormOfAST the expected string form of the AST
*/
public void parseCheck(String expression, String expectedStringFormOfAST) {
try {
SpelExpression e = parser.parseRaw(expression);
if (e != null && !e.toStringAST().equals(expectedStringFormOfAST)) {
SpelUtilities.printAbstractSyntaxTree(System.err, e);
}
if (e == null) {
fail("Parsed exception was null");
}
assertEquals("String form of AST does not match expected output", expectedStringFormOfAST, e.toStringAST());
} catch (ParseException ee) {
ee.printStackTrace();
fail("Unexpected Exception: " + ee.getMessage());
}
}
示例12: getCibetAttributes
import org.springframework.expression.ParseException; //导入依赖的package包/类
protected Collection<ConfigAttribute> getCibetAttributes(
CibetFilterInvocation fi) {
if (fi.getAccessRule() != null) {
// SecurityConfig
return createConfigAttributeList(fi.getAccessRule());
} else {
// Expression
ExpressionParser parser = new SpelExpressionParser();
try {
Expression ex = parser
.parseExpression(fi.getAccessRuleExpression());
Collection<ConfigAttribute> list = new ArrayList<ConfigAttribute>();
list.add(new CibetWebExpressionConfigAttribute(ex));
log.debug("parsed expression: " + ex);
return list;
} catch (ParseException e) {
throw new IllegalArgumentException("Failed to parse expression '"
+ fi.getAccessRuleExpression() + "'");
}
}
}
示例13: createPreInvocationAttribute
import org.springframework.expression.ParseException; //导入依赖的package包/类
protected PreInvocationAttribute createPreInvocationAttribute(String preFilter, String preAuthorize) {
try {
log.debug("createPreInvocationAttribute from " + preFilter + " and " + preAuthorize);
String preAuthValue = parseValueParameter(preAuthorize);
String preFilterValue = parseValueParameter(preFilter);
String preFilterTarget = parseFilterTargetParameter(preFilter);
ExpressionParser parser = new SpelExpressionParser();
Expression preAuthorizeExpression = preAuthorize == null ? parser.parseExpression("permitAll")
: parser.parseExpression(preAuthValue);
log.debug(preAuthorizeExpression);
Expression preFilterExpression = preFilter == null ? null : parser.parseExpression(preFilterValue);
return new PreCibetConfigAttribute(preFilterExpression, preFilterTarget, preAuthorizeExpression);
} catch (ParseException e) {
throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e);
}
}
示例14: createPostInvocationAttribute
import org.springframework.expression.ParseException; //导入依赖的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;
}
示例15: parseExpression
import org.springframework.expression.ParseException; //导入依赖的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;
}
}