Search in sources :

Example 1 with MCRParseException

use of org.mycore.parsers.bool.MCRParseException in project mycore by MyCoRe-Org.

the class MCRWorkflowRuleParser method parseString.

/* (non-Javadoc)
     * @see org.mycore.access.mcrimpl.MCRRuleParser#parseString(java.lang.String)
     */
@Override
protected MCRCondition<?> parseString(String s) {
    if (s.startsWith(STATUS)) {
        s = s.substring(STATUS.length()).trim();
        boolean not;
        String value;
        if (s.startsWith(EQUALS_NOT)) {
            not = true;
            value = s.substring(EQUALS_NOT.length()).trim();
        } else if (s.startsWith(EQUALS)) {
            not = false;
            value = s.substring(EQUALS.length()).trim();
        } else {
            throw new MCRParseException("syntax error: " + s);
        }
        return new MCRCategoryCondition(STATUS, new MCRCategoryID(statusClassId.getRootID(), value), not);
    }
    return super.parseString(s);
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRParseException(org.mycore.parsers.bool.MCRParseException)

Example 2 with MCRParseException

use of org.mycore.parsers.bool.MCRParseException in project mycore by MyCoRe-Org.

the class MCRQueryParser method parseSimpleCondition.

/**
 * Parses a String containing a simple query condition, for example: (title
 * contains "Java") and (creatorID = "122132131")
 *
 * @param s
 *            the condition as a String
 * @return the parsed MCRQueryCondition object
 */
@Override
protected MCRCondition<Void> parseSimpleCondition(String s) throws MCRParseException {
    Matcher m = pattern.matcher(s);
    if (!m.find()) {
        throw new MCRParseException("Not a valid condition: " + s);
    }
    String field = m.group(1);
    String operator = m.group(2);
    String value = m.group(3);
    if (value.startsWith("\"") && value.endsWith("\"")) {
        value = value.substring(1, value.length() - 1);
    }
    return buildConditions(field, operator, value);
}
Also used : Matcher(java.util.regex.Matcher) MCRParseException(org.mycore.parsers.bool.MCRParseException)

Aggregations

MCRParseException (org.mycore.parsers.bool.MCRParseException)2 Matcher (java.util.regex.Matcher)1 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)1