use of org.apache.jackrabbit.core.security.user.XPathQueryBuilder.Condition in project jackrabbit by apache.
the class XPathQueryEvaluator method visit.
public void visit(XPathQueryBuilder.OrCondition condition) throws RepositoryException {
int pos = xPath.length();
int count = 0;
for (Condition c : condition) {
xPath.append(count++ > 0 ? " or " : "");
c.accept(this);
}
// Surround or clause with parentheses if it contains more than one term
if (count > 1) {
xPath.insert(pos, '(');
xPath.append(')');
}
}
use of org.apache.jackrabbit.core.security.user.XPathQueryBuilder.Condition in project jackrabbit by apache.
the class XPathQueryEvaluator method visit.
public void visit(XPathQueryBuilder.AndCondition condition) throws RepositoryException {
int count = 0;
for (Condition c : condition) {
xPath.append(count++ > 0 ? " and " : "");
c.accept(this);
}
}
use of org.apache.jackrabbit.core.security.user.XPathQueryBuilder.Condition in project jackrabbit by apache.
the class XPathQueryEvaluator method eval.
public Iterator<Authorizable> eval() throws RepositoryException {
xPath.append("//element(*,").append(getNtName(builder.getSelector())).append(')');
Value bound = builder.getBound();
long offset = builder.getOffset();
if (bound != null && offset > 0) {
log.warn("Found bound {} and offset {} in limit. Discarding offset.", bound, offset);
offset = 0;
}
Condition condition = builder.getCondition();
String sortCol = builder.getSortProperty();
Direction sortDir = builder.getSortDirection();
if (bound != null) {
if (sortCol == null) {
log.warn("Ignoring bound {} since no sort order is specified");
} else {
Condition boundCondition = builder.property(sortCol, getCollation(sortDir), bound);
condition = condition == null ? boundCondition : builder.and(condition, boundCondition);
}
}
if (condition != null) {
xPath.append('[');
condition.accept(this);
xPath.append(']');
}
if (sortCol != null) {
boolean ignoreCase = builder.getSortIgnoreCase();
xPath.append(" order by ").append(ignoreCase ? "" : "fn:lower-case(").append(sortCol).append(ignoreCase ? " " : ") ").append(sortDir.getDirection());
}
QueryManager queryManager = session.getWorkspace().getQueryManager();
Query query = queryManager.createQuery(xPath.toString(), Query.XPATH);
long maxCount = builder.getMaxCount();
if (maxCount == 0) {
return Iterators.empty();
}
// here (inefficient!) otherwise we can apply the limit in the query
if (builder.getGroupName() == null) {
if (offset > 0) {
query.setOffset(offset);
}
if (maxCount > 0) {
query.setLimit(maxCount);
}
return toAuthorizables(execute(query));
} else {
Iterator<Authorizable> result = toAuthorizables(execute(query));
Iterator<Authorizable> filtered = filter(result, builder.getGroupName(), builder.isDeclaredMembersOnly());
return BoundedIterator.create(offset, maxCount, filtered);
}
}
Aggregations