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);
}
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;
}
Aggregations