use of com.pogeyan.cmis.api.uri.expression.CommonExpression in project copper-cms by PogeyanOSS.
the class FilterParserImpl method readElement.
/**
* Reads: Unary operators, Methods, Properties, ... but not binary operators
* which are handelt in {@link #readElements(CommonExpression, int)}
*
* @param leftExpression
* Used while parsing properties. In this case ( e.g. parsing
* "a/b") the property "a" ( as leftExpression of "/") is
* relevant to verify whether the property "b" exists inside the
* edm
* @return a CommonExpression
* @throws ExpressionParserException
* @throws ExpressionParserInternalError
* @throws TokenizerMessage
*/
protected CommonExpression readElement(final CommonExpression leftExpression, final ActualBinaryOperator leftOperator) throws ExpressionParserException, ExpressionParserInternalError {
CommonExpression node = null;
Token token;
Token lookToken;
lookToken = tokenList.lookToken();
if (lookToken == null) {
return null;
}
switch(lookToken.getKind()) {
case OPENPAREN:
node = readParenthesis();
return node;
// ')' finishes a parenthesis (it is no extra token)" +
case CLOSEPAREN:
case // . " ',' is a separator for function parameters (it is no
COMMA:
// extra token)" +
return null;
default:
}
// -->Check if the token is a unary operator
InfoUnaryOperator unaryOperator = isUnaryOperator(lookToken);
if (unaryOperator != null) {
return readUnaryoperator(lookToken, unaryOperator);
}
// ---expect the look ahead token
token = tokenList.expectToken(lookToken.getUriLiteral(), true);
lookToken = tokenList.lookToken();
// -->Check if the token is a method
// To avoid name clashes between method names and property names we
// accept here only method names if a "(" follows.
// Hence the parser accepts a property named "concat"
InfoMethod methodOperator = isMethod(token, lookToken);
if (methodOperator != null) {
return readMethod(token, methodOperator);
}
// 1.25D"
if (token.getKind() == TokenKind.SIMPLE_TYPE) {
LiteralExpression literal = new LiteralExpressionImpl(token.getUriLiteral(), token.getJavaLiteral());
return literal;
}
// -->Check if token is a property, e.g. "name" or "address"
if (token.getKind() == TokenKind.LITERAL) {
PropertyExpressionImpl property = new PropertyExpressionImpl(token.getUriLiteral());
// leftOperator);
return property;
}
// not Tested, should not occur
throw ExpressionParserInternalError.createCOMMON();
}
use of com.pogeyan.cmis.api.uri.expression.CommonExpression in project copper-cms by PogeyanOSS.
the class FilterParserImpl method readParameters.
/**
* Read the parameters of a method expression
*
* @param methodInfo
* Signature information about the method whose parameters should
* be read
* @param methodExpression
* Method expression to which the read parameters are added
* @return The method expression input parameter
* @throws ExpressionParserException
* @throws ExpressionParserInternalError
* @throws TokenizerExpectError
* The next token did not match the expected token
*/
protected MethodExpression readParameters(final InfoMethod methodInfo, final MethodExpressionImpl methodExpression, final Token methodToken) throws ExpressionParserException, ExpressionParserInternalError {
CommonExpression expression;
boolean expectAnotherExpression = false;
boolean readComma = true;
// The existing of a '(' is verified BEFORE this method is called --> so
// it's a internal error
// throws
Token openParenthesis = tokenList.expectToken(TokenKind.OPENPAREN, true);
// FilterParserInternalError
Token token = tokenList.lookToken();
if (token == null) {
// "$filter=concat("
throw FilterParserExceptionImpl.createEXPRESSION_EXPECTED_AFTER_POS(openParenthesis, curExpression);
}
while (token.getKind() != TokenKind.CLOSEPAREN) {
if (readComma == false) {
// e.g. "$filter=concat('a' 'b')"
throw FilterParserExceptionImpl.createCOMMA_OR_CLOSING_PARENTHESIS_EXPECTED_AFTER_POS(tokenList.lookPrevToken(), curExpression);
}
expression = readElement(null);
if (expression != null) {
expression = readElements(expression, 0);
}
if ((expression == null) && (expectAnotherExpression == true)) {
// e.g. "$filter=concat(,"
throw FilterParserExceptionImpl.createEXPRESSION_EXPECTED_AFTER_POS(token, curExpression);
} else if (expression != null) {
// parameter list may be empty
methodExpression.appendParameter(expression);
}
token = tokenList.lookToken();
if (token == null) {
// e.g. "$filter=concat(123"
throw FilterParserExceptionImpl.createCOMMA_OR_CLOSING_PARENTHESIS_EXPECTED_AFTER_POS(tokenList.lookPrevToken(), curExpression);
}
if (token.getKind() == TokenKind.COMMA) {
expectAnotherExpression = true;
if (expression == null) {
// CASE 3 e.g. "$filter=concat(,"
throw FilterParserExceptionImpl.createEXPRESSION_EXPECTED_AT_POS(token, curExpression);
}
tokenList.expectToken(",", true);
readComma = true;
} else {
readComma = false;
}
}
// because the while loop above only exits if a ')' has been found it is
// an
// internal error if there is not ')'
tokenList.expectToken(TokenKind.CLOSEPAREN, true);
// ---check parameter count
int count = methodExpression.getParameters().size();
if ((methodInfo.getMinParameter() > -1) && (count < methodInfo.getMinParameter())) {
// Tested with TestParserExceptions.TestPMreadParameters CASE 12
throw FilterParserExceptionImpl.createMETHOD_WRONG_ARG_COUNT(methodExpression, methodToken, curExpression);
}
if ((methodInfo.getMaxParameter() > -1) && (count > methodInfo.getMaxParameter())) {
// Tested with TestParserExceptions.TestPMreadParameters CASE 15
throw FilterParserExceptionImpl.createMETHOD_WRONG_ARG_COUNT(methodExpression, methodToken, curExpression);
}
return methodExpression;
}
use of com.pogeyan.cmis.api.uri.expression.CommonExpression 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