private String parse_attr() { skipWhiteSpace(); int begin = pos; int end = pos; char c = filterChars[pos]; while (c != '~' && c != '<' && c != '>' && c != '=' && c != '(' && c != ')') { pos++; if (!Character.isWhitespace(c)) { end = pos; } c = filterChars[pos]; } int length = end - begin; if (length == 0) { throw new IllegalArgumentException("Missing attr in: " + filterstring); } return new String(filterChars, begin, length); }
private FilterImpl parse_or() { int lookahead = pos; skipWhiteSpace(); if (filterChars[pos] != '(') { pos = lookahead - 1; return parse_item(); } List<FilterImpl> operands = new ArrayList<FilterImpl>(10); while (filterChars[pos] == '(') { FilterImpl child = parse_filter(); operands.add(child); } return new FilterImpl(FilterImpl.OR, null, operands.toArray(new FilterImpl[operands.size()])); }
private FilterImpl parse_and() { int lookahead = pos; skipWhiteSpace(); if (filterChars[pos] != '(') { pos = lookahead - 1; return parse_item(); } List<FilterImpl> operands = new ArrayList<FilterImpl>(10); while (filterChars[pos] == '(') { FilterImpl child = parse_filter(); operands.add(child); } return new FilterImpl(FilterImpl.AND, null, operands.toArray(new FilterImpl[operands.size()])); }
private FilterImpl parse_item() { String attr = parse_attr(); skipWhiteSpace(); int oldpos = pos; pos += 2; skipWhiteSpace(); if (filterChars[pos] == ')') { return new FilterImpl(FilterImpl.PRESENT, attr, null);
private FilterImpl parse_filtercomp() { skipWhiteSpace(); char c = filterChars[pos]; switch (c) { case '&' : { pos++; return parse_and(); } case '|' : { pos++; return parse_or(); } case '!' : { pos++; return parse_not(); } } return parse_item(); }
private FilterImpl parse_filter() { FilterImpl filter; skipWhiteSpace(); if (filterChars[pos] != '(') { throw new IllegalArgumentException("Missing '(' in: " + filterstring); } pos++; filter = parse_filtercomp(); skipWhiteSpace(); if (filterChars[pos] != ')') { throw new IllegalArgumentException("Missing ')' in: " + filterstring); } pos++; skipWhiteSpace(); return filter; }
private FilterImpl parse_not() { int lookahead = pos; skipWhiteSpace(); if (filterChars[pos] != '(') { pos = lookahead - 1; return parse_item(); } FilterImpl child = parse_filter(); return new FilterImpl(FilterImpl.NOT, null, child); }