Search in sources :

Example 16 with ExpressionParserException

use of com.pogeyan.cmis.api.uri.expression.ExpressionParserException in project copper-cms by PogeyanOSS.

the class FilterParserImpl method parseFilterString.

public FilterExpression parseFilterString(final String filterExpression, final boolean allowOnlyBinary) throws ExpressionParserException {
    CommonExpression node = null;
    curExpression = filterExpression;
    try {
        // Throws TokenizerException and FilterParserException.
        // FilterParserException is caught somewhere above
        tokenList = new Tokenizer(filterExpression).tokenize();
        if (!tokenList.hasTokens()) {
            return new FilterExpressionImpl(filterExpression);
        }
    } catch (TokenizerException tokenizerException) {
        // Tested with TestParserExceptions.TestPMparseFilterString
        throw FilterParserExceptionImpl.createERROR_IN_TOKENIZER(tokenizerException, curExpression);
    }
    try {
        CommonExpression nodeLeft = readElement(null);
        node = readElements(nodeLeft, 0);
    } catch (ExpressionParserException filterParserException) {
        // Add empty filterTree to Exception
        // Tested for original throw point
        filterParserException.setFilterTree(new FilterExpressionImpl(filterExpression));
        throw filterParserException;
    } catch (ExpressionParserInternalError ex) {
        // throw FilterParserExceptionImpl.COMMON_ERROR(ex, curExpression);
        ex.printStackTrace();
    }
    // Post check
    if (// this indicates
    tokenList.tokenCount() > tokenList.currentToken) // that not all
    // tokens have
    // been read
    {
        // Tested with TestParserExceptions.TestPMparseFilterString
        throw FilterParserExceptionImpl.createINVALID_TRAILING_TOKEN_DETECTED_AFTER_PARSING(tokenList.elementAt(tokenList.currentToken), filterExpression);
    }
    return new FilterExpressionImpl(filterExpression, node);
}
Also used : CommonExpression(com.pogeyan.cmis.api.uri.expression.CommonExpression) ExpressionParserException(com.pogeyan.cmis.api.uri.expression.ExpressionParserException)

Example 17 with ExpressionParserException

use of com.pogeyan.cmis.api.uri.expression.ExpressionParserException in project copper-cms by PogeyanOSS.

the class OrderByParserImpl method parseOrderByString.

@Override
public OrderByExpression parseOrderByString(final String orderByExpression) throws ExpressionParserException {
    curExpression = orderByExpression;
    OrderByExpressionImpl orderCollection = new OrderByExpressionImpl(curExpression);
    try {
        // throws
        tokenList = new Tokenizer(orderByExpression).tokenize();
    // TokenizerMessage
    } catch (TokenizerException tokenizerException) {
        throw FilterParserExceptionImpl.createERROR_IN_TOKENIZER(tokenizerException, curExpression);
    }
    while (true) {
        CommonExpression node = null;
        try {
            CommonExpression nodeLeft = readElement(null);
            node = readElements(nodeLeft, 0);
        } catch (ExpressionParserException expressionException) {
            expressionException.setFilterTree(orderCollection);
            throw expressionException;
        } catch (ExpressionParserInternalError ex) {
            ex.printStackTrace();
        }
        OrderExpressionImpl orderNode = new OrderExpressionImpl(node);
        // read the sort order
        Token token = tokenList.lookToken();
        if (token == null) {
            orderNode.setSortOrder(SortOrder.asc);
        } else if ((token.getKind() == TokenKind.LITERAL) && ("asc".equals(token.getUriLiteral()))) {
            orderNode.setSortOrder(SortOrder.asc);
            tokenList.next();
            token = tokenList.lookToken();
        } else if ((token.getKind() == TokenKind.LITERAL) && ("desc".equals(token.getUriLiteral()))) {
            orderNode.setSortOrder(SortOrder.desc);
            tokenList.next();
            token = tokenList.lookToken();
        } else if (token.getKind() == TokenKind.COMMA) {
            orderNode.setSortOrder(SortOrder.asc);
        } else {
            // CASE 1
            throw FilterParserExceptionImpl.createINVALID_SORT_ORDER(token, curExpression);
        }
        orderCollection.addOrder(orderNode);
        // ls_token may be a ',' or empty.
        if (token == null) {
            break;
        } else if (token.getKind() == TokenKind.COMMA) {
            Token oldToken = token;
            tokenList.next();
            token = tokenList.lookToken();
            if (token == null) {
                // TestParserExceptions.TestOPMparseOrderByString CASE 2
                throw FilterParserExceptionImpl.createEXPRESSION_EXPECTED_AFTER_POS(oldToken, curExpression);
            }
        } else {
            throw FilterParserExceptionImpl.createCOMMA_OR_END_EXPECTED_AT_POS(token, curExpression);
        }
    }
    return orderCollection;
}
Also used : CommonExpression(com.pogeyan.cmis.api.uri.expression.CommonExpression) ExpressionParserException(com.pogeyan.cmis.api.uri.expression.ExpressionParserException)

Aggregations

ExpressionParserException (com.pogeyan.cmis.api.uri.expression.ExpressionParserException)17 MessageReference (com.pogeyan.cmis.api.uri.exception.MessageReference)13 CommonExpression (com.pogeyan.cmis.api.uri.expression.CommonExpression)2 ExceptionVisitExpression (com.pogeyan.cmis.api.uri.expression.ExceptionVisitExpression)2 FilterExpression (com.pogeyan.cmis.api.uri.expression.FilterExpression)2 MBaseObject (com.pogeyan.cmis.data.mongo.MBaseObject)2 OrderByExpression (com.pogeyan.cmis.api.uri.expression.OrderByExpression)1 Pattern (java.util.regex.Pattern)1