jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1344600 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: core/ContentRepositoryImpl.java plugins/name/NameValidator.java plugins/name/NameValidatorProvider.java
Date Thu, 31 May 2012 08:55:05 GMT
Author: mduerig
Date: Thu May 31 08:55:04 2012
New Revision: 1344600

URL: http://svn.apache.org/viewvc?rev=1344600&view=rev
Log:
OAK-68 - Extension point for commit validation
Wire commit hooks and validators into ContentRepository

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorProvider.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java?rev=1344600&r1=1344599&r2=1344600&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
Thu May 31 08:55:04 2012
@@ -23,10 +23,16 @@ import org.apache.jackrabbit.oak.api.Con
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
+import org.apache.jackrabbit.oak.plugins.name.NameValidatorProvider;
+import org.apache.jackrabbit.oak.plugins.type.TypeValidatorProvider;
 import org.apache.jackrabbit.oak.query.QueryEngineImpl;
 import org.apache.jackrabbit.oak.security.authentication.LoginContextProviderImpl;
 import org.apache.jackrabbit.oak.spi.QueryIndexProvider;
-import org.apache.jackrabbit.oak.spi.commit.EmptyCommitHook;
+import org.apache.jackrabbit.oak.spi.commit.CommitHook;
+import org.apache.jackrabbit.oak.spi.commit.CompositeCommitHook;
+import org.apache.jackrabbit.oak.spi.commit.CompositeValidatorProvider;
+import org.apache.jackrabbit.oak.spi.commit.ValidatingCommitHook;
+import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
 import org.apache.jackrabbit.oak.spi.security.authentication.LoginContextProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
@@ -37,6 +43,8 @@ import javax.jcr.Credentials;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * {@link MicroKernel}-based implementation of
@@ -72,7 +80,16 @@ public class ContentRepositoryImpl imple
      * @param indexProvider index provider
      */
     public ContentRepositoryImpl(MicroKernel microKernel, QueryIndexProvider indexProvider)
{
-        nodeStore = new KernelNodeStore(microKernel, new EmptyCommitHook());
+        List<ValidatorProvider> providers = new ArrayList<ValidatorProvider>();
+        providers.add(new NameValidatorProvider());
+        providers.add(new TypeValidatorProvider());
+        CompositeValidatorProvider compositeProvider = new CompositeValidatorProvider(providers);
+
+        List<CommitHook> hooks = new ArrayList<CommitHook>();
+        hooks.add(new ValidatingCommitHook(compositeProvider));
+        CompositeCommitHook compositeHook = new CompositeCommitHook(hooks);
+
+        nodeStore = new KernelNodeStore(microKernel, compositeHook);
         QueryIndexProvider qip = (indexProvider == null) ? getDefaultIndexProvider(microKernel)
: indexProvider;
         queryEngine = new QueryEngineImpl(nodeStore, microKernel, qip);
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java?rev=1344600&r1=1344599&r2=1344600&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
Thu May 31 08:55:04 2012
@@ -44,8 +44,7 @@ class NameValidator implements Validator
             local = name.substring(colon + 1);
         }
 
-        if (!(prefix == null || !prefixes.contains(prefix))
-                || !isValidLocalName(local)) {
+        if ((prefix != null && !prefixes.contains(prefix)) || !isValidLocalName(local))
{
             throw new CommitFailedException("Invalid name: " + name);
         }
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorProvider.java?rev=1344600&r1=1344599&r2=1344600&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorProvider.java
Thu May 31 08:55:04 2012
@@ -16,20 +16,21 @@
  */
 package org.apache.jackrabbit.oak.plugins.name;
 
-import java.util.HashSet;
-import java.util.Set;
-
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.spi.commit.Validator;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
+import java.util.HashSet;
+import java.util.Set;
+
 public class NameValidatorProvider implements ValidatorProvider {
 
     @Override
     public Validator getRootValidator(NodeState before, NodeState after) {
         Set<String> prefixes = new HashSet<String>();
 
+        // FIXME don't hardcode these here but fetch them from the ns registry
         // Default JCR prefixes are always available
         prefixes.add("jcr");
         prefixes.add("nt");
@@ -39,6 +40,9 @@ public class NameValidatorProvider imple
         // Jackrabbit 2.x prefixes are always available
         prefixes.add("rep");
 
+        prefixes.add("tst");
+        prefixes.add("test");
+
         // Find any extra prefixes from /jcr:system/jcr:namespaces
         NodeState system = after.getChildNode("jcr:system");
         if (system != null) {



Mime
View raw message