Search in sources :

Example 1 with SpelParseException

use of org.springframework.expression.spel.SpelParseException in project spring-framework by spring-projects.

the class Tokenizer method lexDoubleQuotedStringLiteral.

// DQ_STRING_LITERAL: '"'! (~'"')* '"'!;
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] == '"') {
                // skip over that too, and continue
                this.pos++;
            } 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));
}
Also used : InternalParseException(org.springframework.expression.spel.InternalParseException) SpelParseException(org.springframework.expression.spel.SpelParseException)

Example 2 with SpelParseException

use of org.springframework.expression.spel.SpelParseException in project spring-framework by spring-projects.

the class Tokenizer method lexQuotedStringLiteral.

// STRING_LITERAL: '\''! (APOS|~'\'')* '\''!;
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] == '\'') {
                // skip over that too, and continue
                this.pos++;
            } 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));
}
Also used : InternalParseException(org.springframework.expression.spel.InternalParseException) SpelParseException(org.springframework.expression.spel.SpelParseException)

Example 3 with SpelParseException

use of org.springframework.expression.spel.SpelParseException in project spring-framework by spring-projects.

the class Tokenizer method lexNumericLiteral.

// REAL_LITERAL :
// ('.' (DECIMAL_DIGIT)+ (EXPONENT_PART)? (REAL_TYPE_SUFFIX)?) |
// ((DECIMAL_DIGIT)+ '.' (DECIMAL_DIGIT)+ (EXPONENT_PART)? (REAL_TYPE_SUFFIX)?) |
// ((DECIMAL_DIGIT)+ (EXPONENT_PART) (REAL_TYPE_SUFFIX)?) |
// ((DECIMAL_DIGIT)+ (REAL_TYPE_SUFFIX));
// fragment INTEGER_TYPE_SUFFIX : ( 'L' | 'l' );
// fragment HEX_DIGIT :
// '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'|'A'|'B'|'C'|'D'|'E'|'F'|'a'|'b'|'c'|'d'|'e'|'f';
//
// fragment EXPONENT_PART : 'e' (SIGN)* (DECIMAL_DIGIT)+ | 'E' (SIGN)*
// (DECIMAL_DIGIT)+ ;
// fragment SIGN : '+' | '-' ;
// fragment REAL_TYPE_SUFFIX : 'F' | 'f' | 'D' | 'd';
// INTEGER_LITERAL
// : (DECIMAL_DIGIT)+ (INTEGER_TYPE_SUFFIX)?;
private void lexNumericLiteral(boolean firstCharIsZero) {
    boolean isReal = false;
    int start = this.pos;
    char ch = this.toProcess[this.pos + 1];
    boolean isHex = ch == 'x' || ch == 'X';
    // deal with hexadecimal
    if (firstCharIsZero && isHex) {
        this.pos = this.pos + 1;
        do {
            this.pos++;
        } while (isHexadecimalDigit(this.toProcess[this.pos]));
        if (isChar('L', 'l')) {
            pushHexIntToken(subarray(start + 2, this.pos), true, start, this.pos);
            this.pos++;
        } else {
            pushHexIntToken(subarray(start + 2, this.pos), false, start, this.pos);
        }
        return;
    }
    // Consume first part of number
    do {
        this.pos++;
    } while (isDigit(this.toProcess[this.pos]));
    // a '.' indicates this number is a real
    ch = this.toProcess[this.pos];
    if (ch == '.') {
        isReal = true;
        int dotpos = this.pos;
        // carry on consuming digits
        do {
            this.pos++;
        } while (isDigit(this.toProcess[this.pos]));
        if (this.pos == dotpos + 1) {
            // the number is something like '3.'. It is really an int but may be
            // part of something like '3.toString()'. In this case process it as
            // an int and leave the dot as a separate token.
            this.pos = dotpos;
            pushIntToken(subarray(start, this.pos), false, start, this.pos);
            return;
        }
    }
    int endOfNumber = this.pos;
    // is it a long ?
    if (isChar('L', 'l')) {
        if (isReal) {
            // 3.4L - not allowed
            throw new InternalParseException(new SpelParseException(this.expressionString, start, SpelMessage.REAL_CANNOT_BE_LONG));
        }
        pushIntToken(subarray(start, endOfNumber), true, start, endOfNumber);
        this.pos++;
    } else if (isExponentChar(this.toProcess[this.pos])) {
        // if it wasn't before, it is now
        isReal = true;
        this.pos++;
        char possibleSign = this.toProcess[this.pos];
        if (isSign(possibleSign)) {
            this.pos++;
        }
        // exponent digits
        do {
            this.pos++;
        } while (isDigit(this.toProcess[this.pos]));
        boolean isFloat = false;
        if (isFloatSuffix(this.toProcess[this.pos])) {
            isFloat = true;
            endOfNumber = ++this.pos;
        } else if (isDoubleSuffix(this.toProcess[this.pos])) {
            endOfNumber = ++this.pos;
        }
        pushRealToken(subarray(start, this.pos), isFloat, start, this.pos);
    } else {
        ch = this.toProcess[this.pos];
        boolean isFloat = false;
        if (isFloatSuffix(ch)) {
            isReal = true;
            isFloat = true;
            endOfNumber = ++this.pos;
        } else if (isDoubleSuffix(ch)) {
            isReal = true;
            endOfNumber = ++this.pos;
        }
        if (isReal) {
            pushRealToken(subarray(start, endOfNumber), isFloat, start, endOfNumber);
        } else {
            pushIntToken(subarray(start, endOfNumber), false, start, endOfNumber);
        }
    }
}
Also used : InternalParseException(org.springframework.expression.spel.InternalParseException) SpelParseException(org.springframework.expression.spel.SpelParseException)

Example 4 with SpelParseException

use of org.springframework.expression.spel.SpelParseException in project uPortal by Jasig.

the class SearchPortletController method modifySearchResultLinkTitle.

/**
 * Since portlets don't have access to the portlet definition to create a useful search results
 * link using something like the portlet definition's title, post-process the link text and for
 * those portlets whose type is present in the substitution set, replace the title with the
 * portlet definition's title.
 *
 * @param result Search results object (may be modified)
 * @param httpServletRequest HttpServletRequest
 * @param portletWindowId Portlet Window ID
 */
protected void modifySearchResultLinkTitle(SearchResult result, final HttpServletRequest httpServletRequest, final IPortletWindowId portletWindowId) {
    // evaluation context.
    if (result.getType().size() > 0 && result.getTitle().contains("${")) {
        final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpServletRequest, portletWindowId);
        final IPortletEntity portletEntity = portletWindow.getPortletEntity();
        final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
        final SpELEnvironmentRoot spelEnvironment = new SpELEnvironmentRoot(portletDefinition);
        try {
            result.setTitle(spELService.getValue(result.getTitle(), spelEnvironment));
        } catch (SpelParseException | SpelEvaluationException e) {
            result.setTitle("(Invalid portlet title) - see details in log file");
            logger.error("Invalid Spring EL expression {} in search result portlet title", result.getTitle(), e);
        }
    }
}
Also used : SpelParseException(org.springframework.expression.spel.SpelParseException) SpelEvaluationException(org.springframework.expression.spel.SpelEvaluationException) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 5 with SpelParseException

use of org.springframework.expression.spel.SpelParseException in project spring-framework by spring-projects.

the class InternalSpelExpressionParser method doParseExpression.

@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();
    }
}
Also used : SpelParseException(org.springframework.expression.spel.SpelParseException) InternalParseException(org.springframework.expression.spel.InternalParseException) SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl)

Aggregations

SpelParseException (org.springframework.expression.spel.SpelParseException)6 InternalParseException (org.springframework.expression.spel.InternalParseException)5 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)1 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)1 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)1 SpelEvaluationException (org.springframework.expression.spel.SpelEvaluationException)1 SpelNodeImpl (org.springframework.expression.spel.ast.SpelNodeImpl)1