jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1384681 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ oak-jcr/
Date Fri, 14 Sep 2012 08:12:45 GMT
Author: mduerig
Date: Fri Sep 14 08:12:44 2012
New Revision: 1384681

URL: http://svn.apache.org/viewvc?rev=1384681&view=rev
Log:
OAK-66: JCR Node Type Management
Check for valid JCR names in NodeTypeTemplate and friends

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrNameParser.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionTemplateImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeTemplateImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionTemplateImpl.java
    jackrabbit/oak/trunk/oak-jcr/pom.xml

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrNameParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrNameParser.java?rev=1384681&r1=1384680&r2=1384681&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrNameParser.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrNameParser.java
Fri Sep 14 08:12:44 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.namepath;
 
+import javax.jcr.nodetype.ConstraintViolationException;
+
 import org.apache.jackrabbit.util.XMLChar;
 
 /**
@@ -222,4 +224,10 @@ public class JcrNameParser {
         };
         return parse(jcrName, listener, 0);
     }
+
+    public static void checkName(String jcrName, boolean allowResidual) throws ConstraintViolationException
{
+        if (jcrName == null || !(allowResidual && "*".equals(jcrName) || validate(jcrName)))
{
+            throw new ConstraintViolationException("Not a valid JCR name '" + jcrName + '\'');
+        }
+    }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionTemplateImpl.java?rev=1384681&r1=1384680&r2=1384681&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionTemplateImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionTemplateImpl.java
Fri Sep 14 08:12:44 2012
@@ -21,12 +21,14 @@ import java.util.List;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NodeDefinitionTemplate;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeTemplate;
 import javax.jcr.version.OnParentVersionAction;
 
 import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory.AbstractNodeDefinitionBuilder;
+import org.apache.jackrabbit.oak.namepath.JcrNameParser;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -65,7 +67,8 @@ class NodeDefinitionTemplateImpl
     }
 
     @Override
-    public void setName(String name) {
+    public void setName(String name) throws ConstraintViolationException {
+        JcrNameParser.checkName(name, true);
         this.name = name;
     }
 
@@ -143,12 +146,13 @@ class NodeDefinitionTemplateImpl
     }
 
     @Override
-    public void setDefaultPrimaryTypeName(String name) {
+    public void setDefaultPrimaryTypeName(String name) throws ConstraintViolationException
{
+        JcrNameParser.checkName(name, false);
         this.defaultPrimaryTypeName  = name;
     }
 
     @Override
-    public void setDefaultPrimaryType(String name) {
+    public void setDefaultPrimaryType(String name) throws ConstraintViolationException {
         setDefaultPrimaryTypeName(name);
     }
 
@@ -178,12 +182,16 @@ class NodeDefinitionTemplateImpl
     }
 
     @Override
-    public void setRequiredPrimaryTypeNames(String[] names) {
+    public void setRequiredPrimaryTypeNames(String[] names) throws ConstraintViolationException
{
+        for (String name : names) {
+            JcrNameParser.checkName(name, false);
+        }
         this.requiredPrimaryTypeNames = names;
     }
 
     @Override
-    public void addRequiredPrimaryType(String name) {
+    public void addRequiredPrimaryType(String name) throws ConstraintViolationException {
+        JcrNameParser.checkName(name, false);
         if (requiredPrimaryTypeNames == null) {
             requiredPrimaryTypeNames = new String[] { name };
         } else {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeTemplateImpl.java?rev=1384681&r1=1384680&r2=1384681&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeTemplateImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeTemplateImpl.java
Fri Sep 14 08:12:44 2012
@@ -22,6 +22,7 @@ import java.util.List;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
+import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeDefinitionTemplate;
 import javax.jcr.nodetype.NodeType;
@@ -32,9 +33,10 @@ import javax.jcr.nodetype.PropertyDefini
 import javax.jcr.nodetype.PropertyDefinitionTemplate;
 
 import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory.AbstractNodeTypeDefinitionBuilder;
+import org.apache.jackrabbit.oak.namepath.JcrNameParser;
 import org.apache.jackrabbit.value.ValueFactoryImpl;
 
-class NodeTypeTemplateImpl
+final class NodeTypeTemplateImpl
     extends AbstractNodeTypeDefinitionBuilder<NodeTypeTemplate>
     implements NodeTypeTemplate {
 
@@ -63,7 +65,7 @@ class NodeTypeTemplateImpl
 
     public NodeTypeTemplateImpl(
             NodeTypeManager manager, ValueFactory factory,
-            NodeTypeDefinition ntd) {
+            NodeTypeDefinition ntd) throws ConstraintViolationException {
         this(manager, factory);
 
         setName(ntd.getName());
@@ -71,7 +73,10 @@ class NodeTypeTemplateImpl
         setMixin(ntd.isMixin());
         setOrderableChildNodes(ntd.hasOrderableChildNodes());
         setQueryable(ntd.isQueryable());
-        setPrimaryItemName(ntd.getPrimaryItemName());
+        String name = ntd.getPrimaryItemName();
+        if (name != null) {
+            setPrimaryItemName(name);
+        }
         setDeclaredSuperTypeNames(ntd.getDeclaredSupertypeNames());
 
         for (PropertyDefinition pd : ntd.getDeclaredPropertyDefinitions()) {
@@ -116,8 +121,7 @@ class NodeTypeTemplateImpl
     public PropertyDefinitionTemplateImpl newPropertyDefinitionBuilder() {
         return new PropertyDefinitionTemplateImpl() {
             @Override
-            protected Value createValue(String value)
-                    throws RepositoryException {
+            protected Value createValue(String value) {
                 return factory.createValue(value);
             }
             @Override
@@ -152,7 +156,8 @@ class NodeTypeTemplateImpl
     }
 
     @Override
-    public void setName(String name) {
+    public void setName(String name) throws ConstraintViolationException {
+        JcrNameParser.checkName(name, false);
         this.name = name;
     }
 
@@ -202,7 +207,8 @@ class NodeTypeTemplateImpl
     }
 
     @Override
-    public void setPrimaryItemName(String name) {
+    public void setPrimaryItemName(String name) throws ConstraintViolationException {
+        JcrNameParser.checkName(name, false);
         this.primaryItemName = name;
     }
 
@@ -212,12 +218,16 @@ class NodeTypeTemplateImpl
     }
 
     @Override
-    public void setDeclaredSuperTypeNames(String[] names) {
+    public void setDeclaredSuperTypeNames(String[] names) throws ConstraintViolationException
{
+        for (String name : names) {
+            JcrNameParser.checkName(name, false);
+        }
         this.superTypeNames = names;
     }
 
     @Override
     public void addSupertype(String name) throws RepositoryException {
+        JcrNameParser.checkName(name, false);
         String[] names = new String[superTypeNames.length + 1];
         System.arraycopy(superTypeNames, 0, names, 0, superTypeNames.length);
         names[superTypeNames.length] = name;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionTemplateImpl.java?rev=1384681&r1=1384680&r2=1384681&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionTemplateImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionTemplateImpl.java
Fri Sep 14 08:12:44 2012
@@ -20,12 +20,14 @@ import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
+import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeTemplate;
 import javax.jcr.nodetype.PropertyDefinitionTemplate;
 import javax.jcr.version.OnParentVersionAction;
 
 import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory.AbstractPropertyDefinitionBuilder;
+import org.apache.jackrabbit.oak.namepath.JcrNameParser;
 
 class PropertyDefinitionTemplateImpl
         extends AbstractPropertyDefinitionBuilder<NodeTypeTemplate>
@@ -60,7 +62,8 @@ class PropertyDefinitionTemplateImpl
     }
 
     @Override
-    public void setName(String name) {
+    public void setName(String name) throws ConstraintViolationException {
+        JcrNameParser.checkName(name, true);
         this.name = name;
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1384681&r1=1384680&r2=1384681&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Fri Sep 14 08:12:44 2012
@@ -73,7 +73,6 @@ org.apache.jackrabbit.test.api.nodetype.
 org.apache.jackrabbit.test.api.nodetype.NodeTypeCreationTest#testNewNodeTypeTemplate    
 <!-- OAK-66 -->
 org.apache.jackrabbit.test.api.nodetype.NodeTypeCreationTest#testPropertyDefinitionTemplate
      <!-- OAK-66 -->
 org.apache.jackrabbit.test.api.nodetype.NodeTypeCreationTest#testNodeDefinitionTemplate 
 <!-- OAK-66 -->
-org.apache.jackrabbit.test.api.nodetype.NodeTypeCreationTest#testInvalidJCRNames        
 <!-- OAK-66 -->
 org.apache.jackrabbit.test.api.SetPropertyAssumeTypeTest#testValueConstraintViolationExceptionBecauseOfInvalidTypeParameter
 org.apache.jackrabbit.test.api.SetPropertyAssumeTypeTest#testValuesConstraintViolationExceptionBecauseOfInvalidTypeParameter
 org.apache.jackrabbit.test.api.SetPropertyAssumeTypeTest#testStringConstraintViolationExceptionBecauseOfInvalidTypeParameter



Mime
View raw message