org.springframework.expression.spel.SpelParseException Java Examples
The following examples show how to use
org.springframework.expression.spel.SpelParseException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InternalSpelExpressionParser.java From spring-analysis-note with MIT License | 6 votes |
@Override protected SpelExpression doParseExpression(String expressionString, @Nullable ParserContext context) throws ParseException { try { this.expressionString = expressionString; Tokenizer tokenizer = new Tokenizer(expressionString); this.tokenStream = tokenizer.process(); this.tokenStreamLength = this.tokenStream.size(); this.tokenStreamPointer = 0; this.constructedNodes.clear(); SpelNodeImpl ast = eatExpression(); Assert.state(ast != null, "No node"); Token t = peekToken(); if (t != null) { throw new SpelParseException(t.startPos, SpelMessage.MORE_INPUT, toString(nextToken())); } Assert.isTrue(this.constructedNodes.isEmpty(), "At least one node expected"); return new SpelExpression(expressionString, ast, this.configuration); } catch (InternalParseException ex) { throw ex.getCause(); } }
Example #2
Source File: InternalSpelExpressionParser.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected SpelExpression doParseExpression(String expressionString, ParserContext context) throws ParseException { try { this.expressionString = expressionString; Tokenizer tokenizer = new Tokenizer(expressionString); this.tokenStream = tokenizer.process(); 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(), "At least one node expected"); return new SpelExpression(expressionString, ast, this.configuration); } catch (InternalParseException ex) { throw ex.getCause(); } }
Example #3
Source File: Tokenizer.java From spring4-understanding with Apache License 2.0 | 6 votes |
private void pushHexIntToken(char[] data, boolean isLong, int start, int end) { if (data.length == 0) { if (isLong) { throw new InternalParseException(new SpelParseException(this.expressionString, start, SpelMessage.NOT_A_LONG, this.expressionString.substring(start, end + 1))); } else { throw new InternalParseException(new SpelParseException(this.expressionString, start, SpelMessage.NOT_AN_INTEGER, this.expressionString.substring( start, end))); } } if (isLong) { this.tokens.add(new Token(TokenKind.LITERAL_HEXLONG, data, start, end)); } else { this.tokens.add(new Token(TokenKind.LITERAL_HEXINT, data, start, end)); } }
Example #4
Source File: Tokenizer.java From spring4-understanding with Apache License 2.0 | 6 votes |
private void lexDoubleQuotedStringLiteral() { int start = this.pos; boolean terminated = false; while (!terminated) { this.pos++; char ch = this.toProcess[this.pos]; if (ch == '"') { // may not be the end if the char after is also a " if (this.toProcess[this.pos + 1] == '"') { this.pos++; // skip over that too, and continue } else { terminated = true; } } if (ch == 0) { throw new InternalParseException(new SpelParseException(this.expressionString, start, SpelMessage.NON_TERMINATING_DOUBLE_QUOTED_STRING)); } } this.pos++; this.tokens.add(new Token(TokenKind.LITERAL_STRING, subarray(start, this.pos), start, this.pos)); }
Example #5
Source File: Tokenizer.java From spring4-understanding with Apache License 2.0 | 6 votes |
private void lexQuotedStringLiteral() { int start = this.pos; boolean terminated = false; while (!terminated) { this.pos++; char ch = this.toProcess[this.pos]; if (ch == '\'') { // may not be the end if the char after is also a ' if (this.toProcess[this.pos + 1] == '\'') { this.pos++; // skip over that too, and continue } else { terminated = true; } } if (ch == 0) { throw new InternalParseException(new SpelParseException(this.expressionString, start, SpelMessage.NON_TERMINATING_QUOTED_STRING)); } } this.pos++; this.tokens.add(new Token(TokenKind.LITERAL_STRING, subarray(start, this.pos), start, this.pos)); }
Example #6
Source File: InternalSpelExpressionParser.java From java-technology-stack with MIT License | 6 votes |
@Override protected SpelExpression doParseExpression(String expressionString, @Nullable ParserContext context) throws ParseException { try { this.expressionString = expressionString; Tokenizer tokenizer = new Tokenizer(expressionString); this.tokenStream = tokenizer.process(); this.tokenStreamLength = this.tokenStream.size(); this.tokenStreamPointer = 0; this.constructedNodes.clear(); SpelNodeImpl ast = eatExpression(); Assert.state(ast != null, "No node"); Token t = peekToken(); if (t != null) { throw new SpelParseException(t.startPos, SpelMessage.MORE_INPUT, toString(nextToken())); } Assert.isTrue(this.constructedNodes.isEmpty(), "At least one node expected"); return new SpelExpression(expressionString, ast, this.configuration); } catch (InternalParseException ex) { throw ex.getCause(); } }
Example #7
Source File: InternalSpelExpressionParser.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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(); } }
Example #8
Source File: Literal.java From spring-analysis-note with MIT License | 5 votes |
/** * Process the string form of a number, using the specified base if supplied * and return an appropriate literal to hold it. Any suffix to indicate a * long will be taken into account (either 'l' or 'L' is supported). * @param numberToken the token holding the number as its payload (eg. 1234 or 0xCAFE) * @param radix the base of number * @return a subtype of Literal that can represent it */ public static Literal getIntLiteral(String numberToken, int startPos, int endPos, int radix) { try { int value = Integer.parseInt(numberToken, radix); return new IntLiteral(numberToken, startPos, endPos, value); } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(startPos, ex, SpelMessage.NOT_AN_INTEGER, numberToken)); } }
Example #9
Source File: Literal.java From lams with GNU General Public License v2.0 | 5 votes |
public static Literal getLongLiteral(String numberToken, int pos, int radix) { try { long value = Long.parseLong(numberToken, radix); return new LongLiteral(numberToken, pos, value); } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_A_LONG, numberToken)); } }
Example #10
Source File: InternalSpelExpressionParser.java From lams with GNU General Public License v2.0 | 5 votes |
private void eatConstructorArgs(List<SpelNodeImpl> accumulatedArguments) { if (!peekToken(TokenKind.LPAREN)) { throw new InternalParseException(new SpelParseException(this.expressionString, positionOf(peekToken()), SpelMessage.MISSING_CONSTRUCTOR_ARGS)); } consumeArguments(accumulatedArguments); eatToken(TokenKind.RPAREN); }
Example #11
Source File: Literal.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Process the string form of a number, using the specified base if supplied * and return an appropriate literal to hold it. Any suffix to indicate a * long will be taken into account (either 'l' or 'L' is supported). * @param numberToken the token holding the number as its payload (eg. 1234 or 0xCAFE) * @param radix the base of number * @return a subtype of Literal that can represent it */ public static Literal getIntLiteral(String numberToken, int pos, int radix) { try { int value = Integer.parseInt(numberToken, radix); return new IntLiteral(numberToken, pos, value); } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_AN_INTEGER, numberToken)); } }
Example #12
Source File: Literal.java From spring4-understanding with Apache License 2.0 | 5 votes |
public static Literal getLongLiteral(String numberToken, int pos, int radix) { try { long value = Long.parseLong(numberToken, radix); return new LongLiteral(numberToken, pos, value); } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_A_LONG, numberToken)); } }
Example #13
Source File: InternalSpelExpressionParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void eatConstructorArgs(List<SpelNodeImpl> accumulatedArguments) { if (!peekToken(TokenKind.LPAREN)) { throw new InternalParseException(new SpelParseException(this.expressionString,positionOf(peekToken()),SpelMessage.MISSING_CONSTRUCTOR_ARGS)); } consumeArguments(accumulatedArguments); eatToken(TokenKind.RPAREN); }
Example #14
Source File: SpelParserTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testStringLiterals_DoubleQuotes_spr9620_2() throws Exception { try { new SpelExpressionParser().parseRaw("\"double quote: \\\"\\\".\""); fail("Should have failed"); } catch (SpelParseException spe) { assertEquals(17, spe.getPosition()); assertEquals(SpelMessage.UNEXPECTED_ESCAPE_CHAR, spe.getMessageCode()); } }
Example #15
Source File: SpelParserTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void checkNumberError(String expression, SpelMessage expectedMessage) { try { SpelExpressionParser parser = new SpelExpressionParser(); parser.parseRaw(expression); fail(); } catch (ParseException e) { assertTrue(e instanceof SpelParseException); SpelParseException spe = (SpelParseException) e; assertEquals(expectedMessage, spe.getMessageCode()); } }
Example #16
Source File: DefaultIriExpressionProcessor.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Override public IRI processExpression(String expression, IriExpressionContext context) throws SemanticTranslationException { try { final Expression compiledExpression = PARSER.parseExpression(expression); String result = compiledExpression.getValue(new StandardEvaluationContext(context), String.class); LOG.debug("IRI expression resulted in '{}' with context of type {}", result, context.getClass().getName()); return valueFactory.createIRI(result); } catch (SpelEvaluationException | SpelParseException | IllegalArgumentException e) { throw new SemanticTranslationException("Issue processing IRI expression for expression '" + expression + "' with context of type: " + context.getClass().getName(), e); } }
Example #17
Source File: HdfsDatasetSinkConfiguration.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
private static PartitionStrategy parsePartitionExpression(String expression) { List<String> expressions = Arrays.asList(expression.split("/")); ExpressionParser parser = new SpelExpressionParser(); PartitionStrategy.Builder psb = new PartitionStrategy.Builder(); StandardEvaluationContext ctx = new StandardEvaluationContext(psb); for (String expr : expressions) { try { Expression e = parser.parseExpression(expr); psb = e.getValue(ctx, PartitionStrategy.Builder.class); } catch (SpelParseException spe) { if (!expr.trim().endsWith(")")) { throw new StoreException("Invalid partitioning expression '" + expr + "' - did you forget the closing parenthesis?", spe); } else { throw new StoreException("Invalid partitioning expression '" + expr + "'!", spe); } } catch (SpelEvaluationException see) { throw new StoreException("Invalid partitioning expression '" + expr + "' - failed evaluation!", see); } catch (NullPointerException npe) { throw new StoreException("Invalid partitioning expression '" + expr + "' - was evaluated to null!", npe); } } return psb.build(); }
Example #18
Source File: Literal.java From java-technology-stack with MIT License | 5 votes |
public static Literal getLongLiteral(String numberToken, int pos, int radix) { try { long value = Long.parseLong(numberToken, radix); return new LongLiteral(numberToken, pos, value); } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_A_LONG, numberToken)); } }
Example #19
Source File: Literal.java From spring-analysis-note with MIT License | 5 votes |
public static Literal getLongLiteral(String numberToken, int startPos, int endPos, int radix) { try { long value = Long.parseLong(numberToken, radix); return new LongLiteral(numberToken, startPos, endPos, value); } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(startPos, ex, SpelMessage.NOT_A_LONG, numberToken)); } }
Example #20
Source File: InternalSpelExpressionParser.java From spring-analysis-note with MIT License | 5 votes |
private void eatConstructorArgs(List<SpelNodeImpl> accumulatedArguments) { if (!peekToken(TokenKind.LPAREN)) { throw new InternalParseException(new SpelParseException(this.expressionString, positionOf(peekToken()), SpelMessage.MISSING_CONSTRUCTOR_ARGS)); } consumeArguments(accumulatedArguments); eatToken(TokenKind.RPAREN); }
Example #21
Source File: SpelParserTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testStringLiterals_DoubleQuotes_spr9620_2() { try { new SpelExpressionParser().parseRaw("\"double quote: \\\"\\\".\""); fail("Should have failed"); } catch (SpelParseException spe) { assertEquals(17, spe.getPosition()); assertEquals(SpelMessage.UNEXPECTED_ESCAPE_CHAR, spe.getMessageCode()); } }
Example #22
Source File: SpelParserTests.java From spring-analysis-note with MIT License | 5 votes |
private void checkNumberError(String expression, SpelMessage expectedMessage) { try { SpelExpressionParser parser = new SpelExpressionParser(); parser.parseRaw(expression); fail(); } catch (ParseException ex) { assertTrue(ex instanceof SpelParseException); SpelParseException spe = (SpelParseException) ex; assertEquals(expectedMessage, spe.getMessageCode()); } }
Example #23
Source File: Literal.java From java-technology-stack with MIT License | 5 votes |
/** * Process the string form of a number, using the specified base if supplied * and return an appropriate literal to hold it. Any suffix to indicate a * long will be taken into account (either 'l' or 'L' is supported). * @param numberToken the token holding the number as its payload (eg. 1234 or 0xCAFE) * @param radix the base of number * @return a subtype of Literal that can represent it */ public static Literal getIntLiteral(String numberToken, int pos, int radix) { try { int value = Integer.parseInt(numberToken, radix); return new IntLiteral(numberToken, pos, value); } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_AN_INTEGER, numberToken)); } }
Example #24
Source File: Literal.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Process the string form of a number, using the specified base if supplied * and return an appropriate literal to hold it. Any suffix to indicate a * long will be taken into account (either 'l' or 'L' is supported). * @param numberToken the token holding the number as its payload (eg. 1234 or 0xCAFE) * @param radix the base of number * @return a subtype of Literal that can represent it */ public static Literal getIntLiteral(String numberToken, int pos, int radix) { try { int value = Integer.parseInt(numberToken, radix); return new IntLiteral(numberToken, pos, value); } catch (NumberFormatException ex) { throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_AN_INTEGER, numberToken)); } }
Example #25
Source File: InternalSpelExpressionParser.java From java-technology-stack with MIT License | 5 votes |
private void eatConstructorArgs(List<SpelNodeImpl> accumulatedArguments) { if (!peekToken(TokenKind.LPAREN)) { throw new InternalParseException(new SpelParseException(this.expressionString, positionOf(peekToken()), SpelMessage.MISSING_CONSTRUCTOR_ARGS)); } consumeArguments(accumulatedArguments); eatToken(TokenKind.RPAREN); }
Example #26
Source File: SpelParserTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testStringLiterals_DoubleQuotes_spr9620_2() { try { new SpelExpressionParser().parseRaw("\"double quote: \\\"\\\".\""); fail("Should have failed"); } catch (SpelParseException spe) { assertEquals(17, spe.getPosition()); assertEquals(SpelMessage.UNEXPECTED_ESCAPE_CHAR, spe.getMessageCode()); } }
Example #27
Source File: SpelParserTests.java From java-technology-stack with MIT License | 5 votes |
private void checkNumberError(String expression, SpelMessage expectedMessage) { try { SpelExpressionParser parser = new SpelExpressionParser(); parser.parseRaw(expression); fail(); } catch (ParseException ex) { assertTrue(ex instanceof SpelParseException); SpelParseException spe = (SpelParseException) ex; assertEquals(expectedMessage, spe.getMessageCode()); } }
Example #28
Source File: InternalSpelExpressionParser.java From java-technology-stack with MIT License | 4 votes |
private InternalParseException internalException(int pos, SpelMessage message, Object... inserts) { return new InternalParseException(new SpelParseException(this.expressionString, pos, message, inserts)); }
Example #29
Source File: InternalSpelExpressionParser.java From spring4-understanding with Apache License 2.0 | 4 votes |
private void raiseInternalException(int pos, SpelMessage message, Object... inserts) { throw new InternalParseException(new SpelParseException(this.expressionString, pos, message, inserts)); }
Example #30
Source File: Tokenizer.java From java-technology-stack with MIT License | 4 votes |
private void raiseParseException(int start, SpelMessage msg, Object... inserts) { throw new InternalParseException(new SpelParseException(this.expressionString, start, msg, inserts)); }