You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2006/01/17 18:28:45 UTC
svn commit: r369843 - in /incubator/jackrabbit/trunk/jackrabbit:
applications/test/repository/namespaces/
applications/test/repository/namespaces/ns_reg.properties
src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
Author: stefan
Date: Tue Jan 17 09:28:35 2006
New Revision: 369843
URL: http://svn.apache.org/viewcvs?rev=369843&view=rev
Log:
JCR-290: NodeTypeRegistry.registerNodeType(NodeTypeDef) does not verify that the referenced namespaces are registered
Added:
incubator/jackrabbit/trunk/jackrabbit/applications/test/repository/namespaces/
incubator/jackrabbit/trunk/jackrabbit/applications/test/repository/namespaces/ns_reg.properties (with props)
Modified:
incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
Added: incubator/jackrabbit/trunk/jackrabbit/applications/test/repository/namespaces/ns_reg.properties
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/applications/test/repository/namespaces/ns_reg.properties?rev=369843&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/applications/test/repository/namespaces/ns_reg.properties (added)
+++ incubator/jackrabbit/trunk/jackrabbit/applications/test/repository/namespaces/ns_reg.properties Tue Jan 17 09:28:35 2006
@@ -0,0 +1,16 @@
+#Tue Jan 17 18:27:06 CET 2006
+tst=www.apache.org/jackrabbit/test/namespaceRegistryTest
+xs=http\://www.w3.org/2001/XMLSchema
+docview=www.apache.org/jackrabbit/test/namespaceImportTest
+docview2=www.apache.org/jackrabbit/test/namespaceImportTest2
+docview1=www.apache.org/jackrabbit/test/namespaceImportTest1
+docview0=www.apache.org/jackrabbit/test/namespaceImportTest0
+xml=http\://www.w3.org/XML/1998/namespace
+test=http\://www.apache.org/jackrabbit/test
+jcr=http\://www.jcp.org/jcr/1.0
+nt=http\://www.jcp.org/jcr/nt/1.0
+fn=http\://www.w3.org/2004/10/xpath-functions
+rep=internal
+sv=http\://www.jcp.org/jcr/sv/1.0
+mix=http\://www.jcp.org/jcr/mix/1.0
+=
Propchange: incubator/jackrabbit/trunk/jackrabbit/applications/test/repository/namespaces/ns_reg.properties
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java?rev=369843&r1=369842&r2=369843&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java (original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java Tue Jan 17 09:28:35 2006
@@ -53,13 +53,6 @@
private static Logger log = Logger.getLogger(NodeTypeRegistry.class);
- /**
- * The empty name used as the name of the declaring node type of the
- * root node definion.
- * TODO: Is it proper to use an invalid QName for this.
- */
- private static final QName EMPTY_NAME = new QName("", "");
-
private static final String BUILTIN_NODETYPES_RESOURCE_PATH =
"org/apache/jackrabbit/core/nodetype/builtin_nodetypes.xml";
private static final String CUSTOM_NODETYPES_RESOURCE_NAME =
@@ -210,8 +203,9 @@
private static NodeDef createRootNodeDef() {
NodeDefImpl def = new NodeDefImpl();
- // FIXME need a fake declaring node type
- def.setDeclaringNodeType(EMPTY_NAME);
+ // FIXME need a fake declaring node type:
+ // rep:root is not quite correct but better than a non-existing node type
+ def.setDeclaringNodeType(QName.REP_ROOT);
def.setRequiredPrimaryTypes(new QName[] { QName.REP_ROOT });
def.setDefaultPrimaryType(QName.REP_ROOT);
def.setMandatory(true);
@@ -428,6 +422,20 @@
}
}
+ /**
+ * Utility method for verifying that the namespace of a <code>QName</code>
+ * is registered; a <code>null</code> argument is silently ignored.
+ * @param name name whose namespace is to be checked
+ * @throws RepositoryException if the namespace of the given name is not
+ * registered or if an unspecified error occured
+ */
+ private void checkNamespace(QName name) throws RepositoryException {
+ if (name != null) {
+ // make sure namespace uri denotes a registered namespace
+ nsReg.getPrefix(name.getNamespaceURI());
+ }
+ }
+
private EffectiveNodeType validateNodeTypeDef(NodeTypeDef ntd)
throws InvalidNodeTypeDefException, RepositoryException {
@@ -447,11 +455,13 @@
log.debug(msg);
throw new InvalidNodeTypeDefException(msg);
}
+ checkNamespace(name);
// validate supertypes
QName[] supertypes = ntd.getSupertypes();
if (supertypes != null && supertypes.length > 0) {
for (int i = 0; i < supertypes.length; i++) {
+ checkNamespace(supertypes[i]);
/**
* simple check for infinite recursion
* (won't trap recursion on a deeper inheritance level)
@@ -482,7 +492,7 @@
/**
* note that infinite recursion through inheritance is automatically
* being checked by the following call to getEffectiveNodeType()
- * as it's impossible to register an node type definition which
+ * as it's impossible to register a node type definition which
* references a supertype that isn't registered yet...
*/
@@ -520,6 +530,8 @@
}
}
+ checkNamespace(ntd.getPrimaryItemName());
+
// validate property definitions
PropDef[] pda = ntd.getPropertyDefs();
for (int i = 0; i < pda.length; i++) {
@@ -534,6 +546,7 @@
log.debug(msg);
throw new InvalidNodeTypeDefException(msg);
}
+ checkNamespace(pd.getName());
// check that auto-created properties specify a name
if (pd.definesResidual() && pd.isAutoCreated()) {
String msg = "[" + name + "#" + pd.getName()
@@ -646,6 +659,7 @@
log.debug(msg);
throw new InvalidNodeTypeDefException(msg);
}
+ checkNamespace(cnd.getName());
// check that auto-created child-nodes specify a name
if (cnd.definesResidual() && cnd.isAutoCreated()) {
String msg = "[" + name + "#" + cnd.getName()
@@ -663,6 +677,7 @@
}
// check default primary type
QName dpt = cnd.getDefaultPrimaryType();
+ checkNamespace(dpt);
boolean referenceToSelf = false;
EffectiveNodeType defaultENT = null;
if (dpt != null) {
@@ -724,6 +739,7 @@
if (reqTypes != null && reqTypes.length > 0) {
for (int n = 0; n < reqTypes.length; n++) {
QName rpt = reqTypes[n];
+ checkNamespace(rpt);
referenceToSelf = false;
/**
* check if this node type specifies itself as required
@@ -1650,7 +1666,7 @@
* A <code>WeightedKey</code> uniquely identifies
* a combination (i.e. an aggregation) of one or more node types.
* The weight is an indicator for the cost involved in building such an
- * aggregate (an aggregation multiple complex node types with deep
+ * aggregate (e.g. an aggregation of multiple complex node types with deep
* inheritance trees is more costly to build/validate than an agreggation
* of two very simple node types with just one property definition each).
* <p/>