Package org.fcrepo.server.errors

Examples of org.fcrepo.server.errors.QueryParseException


    public Condition(String property, Operator operator, String value)
            throws QueryParseException {
        m_property = property;
        m_operator = operator;
        if (value.indexOf("'") != -1) {
            throw new QueryParseException("Query cannot contain the ' character.");
        }
        m_value = value;
    }
View Full Code Here


    public Condition(String property, String operator, String value)
            throws InvalidOperatorException, QueryParseException {
        m_property = property;
        m_operator = Operator.fromAbbreviation(operator);
        if (value.indexOf("'") != -1) {
            throw new QueryParseException("Query cannot contain the ' character.");
        }
        m_value = value;
    }
View Full Code Here

                        }
                        inProp = false;
                        inValue = true;
                        firstValueChar = true;
                    } else {
                        throw new QueryParseException("Found <end-of-string> "
                                + "immediately following '>' operator, but "
                                + "expected a value.");
                    }
                } else if (c == '<') {
                    if (i + 1 < query.length()) {
                        char d = query.charAt(i + 1);
                        if (d == '=') {
                            i++;
                            oper = Operator.LESS_OR_EQUAL;
                        } else {
                            oper = Operator.LESS_THAN;
                        }
                        inProp = false;
                        inValue = true;
                        firstValueChar = true;
                    } else {
                        throw new QueryParseException("Found <end-of-string> "
                                + "immediately following '<' operator, but "
                                + "expected a value.");
                    }
                } else if ((c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A)) {
                    prop.append(c);
                } else {
                    throw new QueryParseException("Found ' " + c
                            + "' at character " + i
                            + " but expected operator");
                }
            } else if (inValue) {
                if (prop.toString().length() == 0) {
                    throw new QueryParseException("Found "
                            + "operator but expected a non-zero length "
                            + "property.");
                }
                if (firstValueChar) {
                    // allow ', and mark it if it's there, add one to i
                    if (c == '\'') {
                        i++;
                        if (i >= query.length()) {
                            throw new QueryParseException("Found <end-of-string> "
                                    + "immediately following start quote, but "
                                    + "expected a value.");
                        }
                        c = query.charAt(i);
                        valueStartsWithQuote = true;
                    }
                    firstValueChar = false;
                }
                if (c == '\'') {
                    if (!valueStartsWithQuote) {
                        throw new QueryParseException("Found ' character in "
                                + "value at position " + i + ", but the value "
                                + "did not start with a string, so this can't "
                                + " be a value terminator.");
                    }
                    // end of value part
                    // next must be space or empty... check
                    i++;
                    if (i < query.length()) {
                        if (query.charAt(i) != ' ') {
                            throw new QueryParseException("Found value-terminator "
                                    + "' but it was not followed by <end-of-string> "
                                    + "or <space>.");
                        }
                    }
                    ret
                            .add(new Condition(prop.toString(), oper, val
                                    .toString()));
                    prop = new StringBuffer();
                    oper = null;
                    val = new StringBuffer();
                    inValue = false;
                    inProp = true;
                    valueStartsWithQuote = false;
                } else if (c == '\\') {
                    i++;
                    if (i >= query.length()) {
                        throw new QueryParseException("Found character-escaping "
                                + "character as last item in string.");
                    }
                    val.append(query.charAt(i));
                } else if (c == ' ') {
                    // end of value part... or inside string?
                    if (valueStartsWithQuote) {
                        // was inside string..ok
                        val.append(c);
                    } else {
                        // end of value part...cuz not quotes
                        ret.add(new Condition(prop.toString(), oper, val
                                .toString()));
                        prop = new StringBuffer();
                        oper = null;
                        val = new StringBuffer();
                        inValue = false;
                        inProp = true;
                    }
                } else if (c == '=') {
                    throw new QueryParseException("Found <operator> at position "
                            + i + ", but expected <value>");
                } else if (c == '~') {
                    throw new QueryParseException("Found <operator> at position "
                            + i + ", but expected <value>");
                } else if (c == '>') {
                    throw new QueryParseException("Found <operator> at position "
                            + i + ", but expected <value>");
                } else if (c == '<') {
                    throw new QueryParseException("Found <operator> at position "
                            + i + ", but expected <value>");
                } else {
                    val.append(c);
                }
            }
        }
        if (inProp) {
            if (prop.toString().length() > 0) {
                throw new QueryParseException("String ended before operator "
                        + "was found");
            }
        }
        if (inValue) {
            if (valueStartsWithQuote) {
                throw new QueryParseException("String ended before quoted value"
                        + "'s ending quote.");
            }
            ret.add(new Condition(prop.toString(), oper, val.toString()));
        }
        return ret;
View Full Code Here

                            } else {
                                whereClause.append(' ');
                            }
                            whereClause.append(sqlPart);
                        } else {
                            throw new QueryParseException("The ~ operator "
                                    + "cannot be used with cDate, mDate, "
                                    + "or dcmDate because they are not "
                                    + "string-valued fields.");
                        }
                    } else { // =, <, <=, >, >=
                        // property must be parsable as a date... if ok,
                        // do (cDate, mDate, dcmDate)
                        // or (date) <- dcDate from dcDates table
                        Date dt;
                        try {
                            dt = DateUtility.parseDateStrict(cond.getValue());
                        } catch (ParseException e) {
                            throw new QueryParseException("When using "
                                    + "equality or inequality operators "
                                    + "with a date-based value, the date "
                                    + "must be in yyyy-MM-DD[THH:mm:ss[.SSS][Z]] "
                                    + "form.");
                        }
                        if (prop.equals("date")) {
                            // do a left join on the dcDates table...dcDate
                            // query will be of form:
                            // select pid
                            // from doFields
                            // left join dcDates on doFields.pid=dcDates.pid
                            // where...
                            if (!willJoin) {
                                willJoin = true;
                                whereClause.insert(0, " LEFT JOIN dcDates "
                                        + "ON doFields.pid=dcDates.pid");
                            }
                            whereClause.append(" dcDates.dcDate" + op
                                    + dt.getTime());
                        } else {
                            whereClause.append(" doFields." + prop + op
                                    + dt.getTime());
                        }
                    }
                } else {
                    if (op.equals("=")) {
                        if (isDCProp(prop)) {
                            throw new QueryParseException("The = operator "
                                    + "can only be used with dates and "
                                    + "non-repeating fields.");
                        } else {
                            // do a real equals check... do a toSql but
                            // reject it if it uses "LIKE"
                            String sqlPart =
                                    toSql("doFields." + prop, cond.getValue());
                            if (sqlPart.indexOf("LIKE ") != -1) {
                                throw new QueryParseException("The = "
                                        + "operator cannot be used with "
                                        + "wildcards.");
                            }
                            if (sqlPart.startsWith(" ")) {
                                needsEscape = true;
                            } else {
                                whereClause.append(' ');
                            }
                            whereClause.append(sqlPart);
                        }
                    } else if (op.equals("~")) {
                        if (isDCProp(prop)) {
                            // prepend dc and caps the first char first...
                            prop =
                                    "dc" + prop.substring(0, 1).toUpperCase()
                                            + prop.substring(1);
                        }
                        // the field name is ok, so toSql it
                        String sqlPart =
                                toSql("doFields." + prop, cond.getValue());
                        if (sqlPart.startsWith(" ")) {
                            needsEscape = true;
                        } else {
                            whereClause.append(' ');
                        }
                        whereClause.append(sqlPart);
                    } else {
                        throw new QueryParseException("Can't use >, >=, <, "
                                + "or <= operator on a string-based field.");
                    }
                }
            }
            if (needsEscape) {
View Full Code Here

TOP

Related Classes of org.fcrepo.server.errors.QueryParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.