use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class AbstractJCRTest method setUp.
protected void setUp() throws Exception {
super.setUp();
testRoot = getProperty(RepositoryStub.PROP_TESTROOT);
if (testRoot == null) {
fail("Property '" + RepositoryStub.PROP_TESTROOT + "' is not defined.");
}
// cut off '/' to build testPath
testPath = testRoot.substring(1);
testNodeType = getProperty(RepositoryStub.PROP_NODETYPE);
testNodeTypeTestRoot = getProperty(RepositoryStub.PROP_NODETYPETESTROOT);
if (testNodeTypeTestRoot == null) {
// backwards compatibility
testNodeTypeTestRoot = testNodeType;
}
testNodeTypeNoChildren = getProperty(RepositoryStub.PROP_NODETYPENOCHILDREN);
// setup node names
nodeName1 = getProperty(RepositoryStub.PROP_NODE_NAME1);
if (nodeName1 == null) {
fail("Property '" + RepositoryStub.PROP_NODE_NAME1 + "' is not defined.");
}
nodeName2 = getProperty(RepositoryStub.PROP_NODE_NAME2);
if (nodeName2 == null) {
fail("Property '" + RepositoryStub.PROP_NODE_NAME2 + "' is not defined.");
}
nodeName3 = getProperty(RepositoryStub.PROP_NODE_NAME3);
if (nodeName3 == null) {
fail("Property '" + RepositoryStub.PROP_NODE_NAME3 + "' is not defined.");
}
nodeName4 = getProperty(RepositoryStub.PROP_NODE_NAME4);
if (nodeName4 == null) {
fail("Property '" + RepositoryStub.PROP_NODE_NAME4 + "' is not defined.");
}
propertyName1 = getProperty(RepositoryStub.PROP_PROP_NAME1);
if (propertyName1 == null) {
fail("Property '" + RepositoryStub.PROP_PROP_NAME1 + "' is not defined.");
}
propertyName2 = getProperty(RepositoryStub.PROP_PROP_NAME2);
if (propertyName2 == null) {
fail("Property '" + RepositoryStub.PROP_PROP_NAME2 + "' is not defined.");
}
workspaceName = getProperty(RepositoryStub.PROP_WORKSPACE_NAME);
if (workspaceName == null) {
fail("Property '" + RepositoryStub.PROP_WORKSPACE_NAME + "' is not defined.");
}
superuser = getHelper().getSuperuserSession();
// setup some common names
jcrPrimaryType = superuser.getNamespacePrefix(NS_JCR_URI) + ":primaryType";
jcrMixinTypes = superuser.getNamespacePrefix(NS_JCR_URI) + ":mixinTypes";
jcrPredecessors = superuser.getNamespacePrefix(NS_JCR_URI) + ":predecessors";
jcrSuccessors = superuser.getNamespacePrefix(NS_JCR_URI) + ":successors";
jcrCreated = superuser.getNamespacePrefix(NS_JCR_URI) + ":created";
jcrVersionHistory = superuser.getNamespacePrefix(NS_JCR_URI) + ":versionHistory";
jcrCopiedFrom = superuser.getNamespacePrefix(NS_JCR_URI) + ":copiedFrom";
jcrFrozenNode = superuser.getNamespacePrefix(NS_JCR_URI) + ":frozenNode";
jcrFrozenUuid = superuser.getNamespacePrefix(NS_JCR_URI) + ":frozenUuid";
jcrRootVersion = superuser.getNamespacePrefix(NS_JCR_URI) + ":rootVersion";
jcrBaseVersion = superuser.getNamespacePrefix(NS_JCR_URI) + ":baseVersion";
jcrIsCheckedOut = superuser.getNamespacePrefix(NS_JCR_URI) + ":isCheckedOut";
jcrUUID = superuser.getNamespacePrefix(NS_JCR_URI) + ":uuid";
jcrLockOwner = superuser.getNamespacePrefix(NS_JCR_URI) + ":lockOwner";
jcrlockIsDeep = superuser.getNamespacePrefix(NS_JCR_URI) + ":lockIsDeep";
jcrMergeFailed = superuser.getNamespacePrefix(NS_JCR_URI) + ":mergeFailed";
jcrSystem = superuser.getNamespacePrefix(NS_JCR_URI) + ":system";
ntBase = superuser.getNamespacePrefix(NS_NT_URI) + ":base";
ntUnstructured = superuser.getNamespacePrefix(NS_NT_URI) + ":unstructured";
ntVersion = superuser.getNamespacePrefix(NS_NT_URI) + ":version";
ntVersionHistory = superuser.getNamespacePrefix(NS_NT_URI) + ":versionHistory";
ntVersionLabels = superuser.getNamespacePrefix(NS_NT_URI) + ":versionLabels";
ntFrozenNode = superuser.getNamespacePrefix(NS_NT_URI) + ":frozenNode";
mixReferenceable = superuser.getNamespacePrefix(NS_MIX_URI) + ":referenceable";
mixVersionable = superuser.getNamespacePrefix(NS_MIX_URI) + ":versionable";
mixSimpleVersionable = superuser.getNamespacePrefix(NS_MIX_URI) + ":simpleVersionable";
mixLockable = superuser.getNamespacePrefix(NS_MIX_URI) + ":lockable";
mixShareable = superuser.getNamespacePrefix(NS_MIX_URI) + ":shareable";
mixTitle = superuser.getNamespacePrefix(NS_MIX_URI) + ":title";
ntQuery = superuser.getNamespacePrefix(NS_NT_URI) + ":query";
// setup custom namespaces
if (isSupported(Repository.LEVEL_2_SUPPORTED)) {
NamespaceRegistry nsReg = superuser.getWorkspace().getNamespaceRegistry();
String namespaces = getProperty(RepositoryStub.PROP_NAMESPACES);
if (namespaces != null) {
String[] prefixes = namespaces.split(" ");
for (int i = 0; i < prefixes.length; i++) {
String uri = getProperty(RepositoryStub.PROP_NAMESPACES + "." + prefixes[i]);
if (uri != null) {
try {
nsReg.getPrefix(uri);
} catch (NamespaceException e) {
// not yet registered
nsReg.registerNamespace(prefixes[i], uri);
}
}
}
}
vf = superuser.getValueFactory();
}
if (isReadOnly) {
if (testPath.length() == 0) {
// test root is the root node
testRootNode = superuser.getRootNode();
} else if (!superuser.getRootNode().hasNode(testPath)) {
cleanUp();
fail("Workspace does not contain test data at: " + testRoot);
} else {
testRootNode = superuser.getRootNode().getNode(testPath);
}
} else if (isSupported(Repository.LEVEL_2_SUPPORTED)) {
testRootNode = cleanUpTestRoot(superuser);
// also clean second workspace
Session s = getHelper().getSuperuserSession(workspaceName);
try {
cleanUpTestRoot(s);
} finally {
s.logout();
}
} else {
cleanUp();
fail("Test case requires level 2 support.");
}
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class NodeTypeManagerImpl method unregisterNodeTypes.
/**
* Unregisters the specified set of node types. Used to unregister a set of node types with mutual dependencies.
* <p>
* Throws a <code>NoSuchNodeTypeException</code> if one of the names listed is not a registered node type.
* <p>
* Throws an <code>UnsupportedRepositoryOperationException</code>
* if this implementation does not support node type registration.
*
* @param names a <code>String</code> array
* @throws UnsupportedRepositoryOperationException if this implementation does not support node type registration.
* @throws NoSuchNodeTypeException if one of the names listed is not a registered node type.
* @throws RepositoryException if another error occurs.
* @since JCR 2.0
*/
public void unregisterNodeTypes(String[] names) throws UnsupportedRepositoryOperationException, NoSuchNodeTypeException, RepositoryException {
// make sure the editing session is allowed to un-register node types.
context.getAccessManager().checkRepositoryPermission(Permission.NODE_TYPE_DEF_MNGMT);
Set<Name> ntNames = new HashSet<Name>();
for (String name : names) {
try {
ntNames.add(context.getQName(name));
} catch (NamespaceException e) {
throw new RepositoryException("Invalid name: " + name, e);
} catch (NameException e) {
throw new RepositoryException("Invalid name: " + name, e);
}
}
getNodeTypeRegistry().unregisterNodeTypes(ntNames);
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class JCRSQLQueryBuilder method createPathQuery.
/**
* Creates <code>LocationStepQueryNode</code>s from a <code>path</code>.
*
* @param path the path pattern
* @param operation the type of the parent node
*/
private void createPathQuery(String path, int operation) {
MergingPathQueryNode pathNode = new MergingPathQueryNode(operation, factory.createPathQueryNode(null).getValidJcrSystemNodeTypeNames());
pathNode.setAbsolute(true);
if (path.equals("/")) {
pathNode.addPathStep(factory.createLocationStepQueryNode(pathNode));
pathConstraints.add(pathNode);
return;
}
String[] names = path.split("/");
for (int i = 0; i < names.length; i++) {
if (names[i].length() == 0) {
if (i == 0) {
// root
pathNode.addPathStep(factory.createLocationStepQueryNode(pathNode));
} else {
// descendant '//' -> invalid path
// todo throw or ignore?
// we currently do not throw and add location step for an
// empty name (which is basically the root node)
pathNode.addPathStep(factory.createLocationStepQueryNode(pathNode));
}
} else {
int idx = names[i].indexOf('[');
String name;
int index = LocationStepQueryNode.NONE;
if (idx > -1) {
// contains index
name = names[i].substring(0, idx);
String suffix = names[i].substring(idx);
String indexStr = suffix.substring(1, suffix.length() - 1);
if (indexStr.equals("%")) {
// select all same name siblings
index = LocationStepQueryNode.NONE;
} else {
try {
index = Integer.parseInt(indexStr);
} catch (NumberFormatException e) {
log.warn("Unable to parse index for path element: " + names[i]);
}
}
if (name.equals("%")) {
name = null;
}
} else {
// no index specified
// - index defaults to 1 if there is an explicit name test
// - index defaults to NONE if name test is %
name = names[i];
if (name.equals("%")) {
name = null;
} else {
index = 1;
}
}
Name qName = null;
if (name != null) {
try {
qName = resolver.getQName(name);
} catch (NamespaceException e) {
throw new IllegalArgumentException("Illegal name: " + name);
} catch (NameException e) {
throw new IllegalArgumentException("Illegal name: " + name);
}
}
// if name test is % this means also search descendants
boolean descendant = name == null;
LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode);
step.setNameTest(qName);
step.setIncludeDescendants(descendant);
if (index > 0) {
step.setIndex(index);
}
pathNode.addPathStep(step);
}
}
pathConstraints.add(pathNode);
}
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 propName = new StringBuffer();
PathQueryNode relPath = node.getRelativePath();
if (relPath == null) {
propName.append(".");
} else if (relPath.getPathSteps().length > 1) {
exceptions.add(new InvalidQueryException("Child axis not supported in SQL"));
return data;
} else {
visit(relPath, data);
}
// surround name with property function
node.acceptOperands(this, propName);
if (node.getOperation() == OPERATION_EQ_VALUE || node.getOperation() == OPERATION_EQ_GENERAL) {
sb.append(propName);
sb.append(" = ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_GE_VALUE || node.getOperation() == OPERATION_GE_GENERAL) {
sb.append(propName);
sb.append(" >= ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_GT_VALUE || node.getOperation() == OPERATION_GT_GENERAL) {
sb.append(propName);
sb.append(" > ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_LE_VALUE || node.getOperation() == OPERATION_LE_GENERAL) {
sb.append(propName);
sb.append(" <= ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_LIKE) {
sb.append(propName);
sb.append(" LIKE ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_LT_VALUE || node.getOperation() == OPERATION_LT_GENERAL) {
sb.append(propName);
sb.append(" < ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_NE_VALUE || node.getOperation() == OPERATION_NE_GENERAL) {
sb.append(propName);
sb.append(" <> ");
appendValue(node, sb);
} else if (node.getOperation() == OPERATION_NULL) {
sb.append(propName);
sb.append(" IS NULL");
} else if (node.getOperation() == OPERATION_NOT_NULL) {
sb.append(propName);
sb.append(" IS NOT NULL");
} else if (node.getOperation() == OPERATION_SIMILAR) {
sb.append("SIMILAR(");
sb.append(propName);
sb.append(", ");
appendValue(node, sb);
sb.append(")");
} else if (node.getOperation() == OPERATION_SPELLCHECK) {
sb.append("SPELLCHECK(");
appendValue(node, sb);
sb.append(")");
} else {
exceptions.add(new InvalidQueryException("Invalid operation: " + node.getOperation()));
}
if (node.getOperation() == OPERATION_LIKE && node.getStringValue().indexOf('\\') > -1) {
sb.append(" ESCAPE '\\'");
}
} catch (NamespaceException e) {
exceptions.add(e);
}
return sb;
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class JCRSQLParser method Identifier.
public final Name Identifier() throws ParseException {
/*@bgen(jjtree) Identifier */
ASTIdentifier jjtn000 = new ASTIdentifier(JJTIDENTIFIER);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
Token t = null;
Name name = null;
boolean pseudoProperty = false;
try {
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case REGULAR_IDENTIFIER:
t = jj_consume_token(REGULAR_IDENTIFIER);
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case LEFT_PAREN:
jj_consume_token(LEFT_PAREN);
jj_consume_token(RIGHT_PAREN);
pseudoProperty = true;
break;
default:
jj_la1[29] = jj_gen;
;
}
try {
String jcrName = t.image;
if (pseudoProperty) {
jcrName += "()";
}
jjtn000.setName(resolver.getQName(jcrName));
} catch (NameException e) {
{
if (true)
throw new ParseException(e.getMessage());
}
} catch (NamespaceException e) {
{
if (true)
throw new ParseException(e.getMessage());
}
}
break;
case DELIMITED_IDENTIFIER:
t = jj_consume_token(DELIMITED_IDENTIFIER);
try {
jjtn000.setName(resolver.getQName(t.image.substring(1, t.image.length() - 1)));
} catch (NameException e) {
{
if (true)
throw new ParseException(e.getMessage());
}
} catch (NamespaceException e) {
{
if (true)
throw new ParseException(e.getMessage());
}
}
break;
case BY:
case IN:
case OR:
case IS:
case AND:
case LIKE:
case NULL:
case FROM:
case ORDER:
case WHERE:
case SELECT:
case BETWEEN:
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case BY:
// or any keyword
t = jj_consume_token(BY);
break;
case IN:
t = jj_consume_token(IN);
break;
case OR:
t = jj_consume_token(OR);
break;
case IS:
t = jj_consume_token(IS);
break;
case AND:
t = jj_consume_token(AND);
break;
case LIKE:
t = jj_consume_token(LIKE);
break;
case NULL:
t = jj_consume_token(NULL);
break;
case FROM:
t = jj_consume_token(FROM);
break;
case ORDER:
t = jj_consume_token(ORDER);
break;
case WHERE:
t = jj_consume_token(WHERE);
break;
case SELECT:
t = jj_consume_token(SELECT);
break;
case BETWEEN:
t = jj_consume_token(BETWEEN);
break;
default:
jj_la1[30] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
try {
jjtn000.setName(resolver.getQName(t.image));
} catch (NameException e) {
{
if (true)
throw new ParseException(e.getMessage());
}
} catch (NamespaceException e) {
{
if (true)
throw new ParseException(e.getMessage());
}
}
break;
default:
jj_la1[31] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
{
if (true)
return jjtn000.getName();
}
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
throw new Error("Missing return statement in function");
}
Aggregations