use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class QueryFormat method visit.
//-------------< QueryNodeVisitor interface >-------------------------------
public Object visit(QueryRootNode node, Object data) throws RepositoryException {
StringBuffer sb = (StringBuffer) data;
try {
sb.append("SELECT");
Name[] selectProps = node.getSelectProperties();
if (selectProps.length == 0) {
sb.append(" *");
} else {
String comma = "";
for (int i = 0; i < selectProps.length; i++) {
sb.append(comma).append(" ");
appendName(selectProps[i], resolver, sb);
comma = ",";
}
}
sb.append(" FROM");
// node type restrictions are within predicates of location nodes
// therefore we write the where clause first to a temp string to
// collect the node types.
StringBuffer tmp = new StringBuffer();
LocationStepQueryNode[] steps = node.getLocationNode().getPathSteps();
QueryNode[] predicates = steps[steps.length - 1].getPredicates();
// are there any relevant predicates?
for (int i = 0; i < predicates.length; i++) {
if (predicates[i].getType() != QueryNode.TYPE_NODETYPE) {
tmp.append(" WHERE ");
}
}
String and = "";
for (int i = 0; i < predicates.length; i++) {
if (predicates[i].getType() != QueryNode.TYPE_NODETYPE) {
tmp.append(and);
and = " AND ";
}
predicates[i].accept(this, tmp);
}
// node types have been collected by now
String comma = "";
int ntCount = 0;
for (Iterator it = nodeTypes.iterator(); it.hasNext(); ntCount++) {
Name nt = (Name) it.next();
sb.append(comma).append(" ");
appendName(nt, resolver, sb);
comma = ",";
}
if (ntCount == 0) {
sb.append(" ");
sb.append(resolver.getJCRName(NameConstants.NT_BASE));
}
// append WHERE clause
sb.append(tmp.toString());
if (steps.length == 2 && steps[1].getIncludeDescendants() && steps[1].getNameTest() == null) {
// then this query selects all paths
} else if (steps.length == 1 && steps[0].getIncludeDescendants() && steps[0].getNameTest() == null) {
// then this query selects all paths
} else {
if (predicates.length > 0) {
sb.append(" AND ");
} else {
sb.append(" WHERE ");
}
node.getLocationNode().accept(this, sb);
}
} catch (NamespaceException e) {
exceptions.add(e);
}
if (node.getOrderNode() != null) {
node.getOrderNode().accept(this, sb);
}
return sb;
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class QueryFormat method visit.
public Object visit(TextsearchQueryNode node, Object data) {
StringBuffer sb = (StringBuffer) data;
// escape quote
String query = node.getQuery().replaceAll("'", "''");
sb.append("CONTAINS(");
if (node.getRelativePath() == null) {
sb.append("*");
} else {
if (node.getRelativePath().getLength() > 1 || !node.getReferencesProperty()) {
exceptions.add(new InvalidQueryException("Child axis not supported in SQL"));
} else {
try {
appendName(node.getRelativePath().getName(), resolver, sb);
} catch (NamespaceException e) {
exceptions.add(e);
}
}
}
sb.append(", '");
sb.append(query).append("')");
return sb;
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class QueryFormat method visit.
public Object visit(ExactQueryNode node, Object data) {
StringBuffer sb = (StringBuffer) data;
sb.append("@");
try {
Name name = encode(node.getPropertyName());
sb.append(resolver.getJCRName(name));
sb.append("='");
sb.append(resolver.getJCRName(node.getValue()));
} catch (NamespaceException e) {
exceptions.add(e);
}
sb.append("'");
return sb;
}
use of javax.jcr.NamespaceException in project jackrabbit-oak by apache.
the class ReadWriteNamespaceRegistry method unregisterNamespace.
@Override
public void unregisterNamespace(String prefix) throws RepositoryException {
if (prefix.isEmpty()) {
throw new NamespaceException("Cannot unregister the default empty namespace");
}
Root root = getWriteRoot();
Tree namespaces = root.getTree(NAMESPACES_PATH);
if (!namespaces.exists() || !namespaces.hasProperty(prefix)) {
throw new NamespaceException("Namespace mapping from " + prefix + " to " + getURI(prefix) + " can not be unregistered");
}
try {
namespaces.removeProperty(prefix);
root.commit();
refresh();
} catch (CommitFailedException e) {
String message = "Failed to unregister namespace mapping for prefix " + prefix;
throw e.asRepositoryException(message);
}
}
use of javax.jcr.NamespaceException in project jackrabbit-oak by apache.
the class ReadWriteNamespaceRegistry method registerNamespace.
//--------------------------------------------------< NamespaceRegistry >---
@Override
public void registerNamespace(String prefix, String uri) throws RepositoryException {
if (prefix.isEmpty() && uri.isEmpty()) {
// the default empty namespace is always registered
return;
} else if (prefix.isEmpty() || uri.isEmpty()) {
throw new NamespaceException("Cannot remap the default empty namespace");
}
PropertyState property = namespaces.getProperty(prefix);
if (property != null && property.getType() == STRING && uri.equals(property.getValue(STRING))) {
// common case: namespace already registered -> do nothing
return;
}
try {
Root root = getWriteRoot();
Tree namespaces = root.getTree(NAMESPACES_PATH);
// remove existing mapping to given URI
for (PropertyState mapping : namespaces.getProperties()) {
if (mapping.getType() == STRING && uri.equals(mapping.getValue(STRING))) {
namespaces.removeProperty(mapping.getName());
}
}
// add this mapping (overrides existing mapping with same prefix)
namespaces.setProperty(prefix, uri);
root.commit();
refresh();
} catch (CommitFailedException e) {
throw e.asRepositoryException("Failed to register namespace mapping " + prefix + " -> " + uri);
}
}
Aggregations