use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class QueryFormat method visit.
public Object visit(OrderQueryNode node, Object data) {
StringBuffer sb = (StringBuffer) data;
sb.append(" order by");
OrderQueryNode.OrderSpec[] specs = node.getOrderSpecs();
String comma = "";
try {
for (int i = 0; i < specs.length; i++) {
sb.append(comma);
Path propPath = specs[i].getPropertyPath();
Path.Element[] elements = propPath.getElements();
sb.append(" ");
String slash = "";
for (int j = 0; j < elements.length; j++) {
sb.append(slash);
slash = "/";
Path.Element element = elements[j];
Name name = encode(element.getName());
if (j == elements.length - 1) {
// last
sb.append("@");
}
sb.append(resolver.getJCRName(name));
}
if (!specs[i].isAscending()) {
sb.append(" descending");
}
comma = ",";
}
} catch (NamespaceException e) {
exceptions.add(e);
}
return data;
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class QueryFormat method visit.
public Object visit(RelationQueryNode node, Object data) throws RepositoryException {
StringBuffer sb = (StringBuffer) data;
try {
StringBuffer propPath = new StringBuffer();
// only encode if not position function
PathQueryNode relPath = node.getRelativePath();
if (relPath == null) {
propPath.append(".");
} else if (relPath.getNumOperands() > 0 && XPathQueryBuilder.FN_POSITION_FULL.equals(relPath.getPathSteps()[0].getNameTest())) {
propPath.append(resolver.getJCRName(XPathQueryBuilder.FN_POSITION_FULL));
} else {
LocationStepQueryNode[] steps = relPath.getPathSteps();
String slash = "";
for (int i = 0; i < steps.length; i++) {
propPath.append(slash);
slash = "/";
if (i == steps.length - 1 && node.getOperation() != OPERATION_SIMILAR) {
// last step
propPath.append("@");
}
visit(steps[i], propPath);
}
}
// surround name with property function
node.acceptOperands(this, propPath);
if (node.getOperation() == OPERATION_EQ_VALUE) {
sb.append(propPath).append(" eq ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_EQ_GENERAL) {
sb.append(propPath).append(" = ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_GE_GENERAL) {
sb.append(propPath).append(" >= ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_GE_VALUE) {
sb.append(propPath).append(" ge ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_GT_GENERAL) {
sb.append(propPath).append(" > ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_GT_VALUE) {
sb.append(propPath).append(" gt ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_LE_GENERAL) {
sb.append(propPath).append(" <= ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_LE_VALUE) {
sb.append(propPath).append(" le ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_LIKE) {
sb.append(resolver.getJCRName(XPathQueryBuilder.JCR_LIKE));
sb.append("(").append(propPath).append(", ");
appendValue(node, sb);
sb.append(")");
} else if (node.getOperation() == OPERATION_LT_GENERAL) {
sb.append(propPath).append(" < ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_LT_VALUE) {
sb.append(propPath).append(" lt ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_NE_GENERAL) {
sb.append(propPath).append(" != ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_NE_VALUE) {
sb.append(propPath).append(" ne ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_NULL) {
sb.append(resolver.getJCRName(XPathQueryBuilder.FN_NOT));
sb.append("(").append(propPath).append(")");
} else if (node.getOperation() == OPERATION_NOT_NULL) {
sb.append(propPath);
} else if (node.getOperation() == OPERATION_SIMILAR) {
sb.append(resolver.getJCRName(XPathQueryBuilder.REP_SIMILAR));
sb.append("(").append(propPath).append(", ");
appendValue(node, sb);
sb.append(")");
} else if (node.getOperation() == OPERATION_SPELLCHECK) {
sb.append(resolver.getJCRName(XPathQueryBuilder.REP_SPELLCHECK));
sb.append("(");
appendValue(node, sb);
sb.append(")");
} else {
exceptions.add(new InvalidQueryException("Invalid operation: " + node.getOperation()));
}
} catch (NamespaceException e) {
exceptions.add(e);
}
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;
try {
sb.append(resolver.getJCRName(XPathQueryBuilder.JCR_CONTAINS));
sb.append("(");
Path relPath = node.getRelativePath();
if (relPath == null) {
sb.append(".");
} else {
Path.Element[] elements = relPath.getElements();
String slash = "";
for (int i = 0; i < elements.length; i++) {
sb.append(slash);
slash = "/";
if (node.getReferencesProperty() && i == elements.length - 1) {
sb.append("@");
}
if (elements[i].getName().equals(RelationQueryNode.STAR_NAME_TEST)) {
sb.append("*");
} else {
Name n = encode(elements[i].getName());
sb.append(resolver.getJCRName(n));
}
if (elements[i].getIndex() != 0) {
sb.append("[").append(elements[i].getIndex()).append("]");
}
}
}
sb.append(", '");
sb.append(node.getQuery().replaceAll("'", "''"));
sb.append("')");
} catch (NamespaceException e) {
exceptions.add(e);
}
return sb;
}
use of javax.jcr.NamespaceException in project jackrabbit-oak by apache.
the class RepositoryTest method registryRemappedNamespace.
@Test
public void registryRemappedNamespace() throws RepositoryException {
NamespaceRegistry nsReg = getAdminSession().getWorkspace().getNamespaceRegistry();
nsReg.registerNamespace("foo", "file:///foo");
getAdminSession().getRootNode().addNode("foo:test");
getAdminSession().save();
try {
nsReg.registerNamespace("bar", "file:///foo");
fail("Remapping namespace through NamespaceRegistry must not be allowed");
} catch (NamespaceException e) {
// expected
} finally {
getAdminSession().getRootNode().getNode("foo:test").remove();
getAdminSession().save();
nsReg.unregisterNamespace("foo");
}
}
use of javax.jcr.NamespaceException in project jackrabbit-oak by apache.
the class SessionNamespaces method setNamespacePrefix.
// The code below was initially copied from JCR Commons AbstractSession,
// but has since been radically modified
/**
* @see Session#setNamespacePrefix(String, String)
*/
synchronized void setNamespacePrefix(String prefix, String uri) throws NamespaceException {
if (prefix == null) {
throw new IllegalArgumentException("Prefix must not be null");
} else if (uri == null) {
throw new IllegalArgumentException("Namespace must not be null");
} else if (prefix.isEmpty()) {
throw new NamespaceException("Empty prefix is reserved and can not be remapped");
} else if (uri.isEmpty()) {
throw new NamespaceException("Default namespace is reserved and can not be remapped");
} else if (prefix.toLowerCase(Locale.ENGLISH).startsWith("xml")) {
throw new NamespaceException("XML prefixes are reserved: " + prefix);
} else if (!XMLChar.isValidNCName(prefix)) {
throw new NamespaceException("Prefix is not a valid XML NCName: " + prefix);
}
// remove the possible existing mapping for the given prefix
local.remove(prefix);
// remove the possible existing mapping(s) for the given URI
Set<String> prefixes = new HashSet<String>();
for (Map.Entry<String, String> entry : local.entrySet()) {
if (entry.getValue().equals(uri)) {
prefixes.add(entry.getKey());
}
}
local.keySet().removeAll(prefixes);
// add the new mapping
local.put(prefix, uri);
}
Aggregations