jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1382054 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint: Constraints.java PathConstraint.java
Date Fri, 07 Sep 2012 14:42:52 GMT
Author: mduerig
Date: Fri Sep  7 14:42:52 2012
New Revision: 1382054

URL: http://svn.apache.org/viewvc?rev=1382054&view=rev
Log:
OAK-66: JCR Node Type Management
value constraints for Path

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/PathConstraint.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/Constraints.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/Constraints.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/Constraints.java?rev=1382054&r1=1382053&r2=1382054&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/Constraints.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/Constraints.java
Fri Sep  7 14:42:52 2012
@@ -92,7 +92,7 @@ public class Constraints {
     }
 
     private static Predicate<Value> pathConstraint(String constraint) {
-        return Predicates.alwaysTrue(); // todo implement pathConstraint
+        return new PathConstraint(constraint);
     }
 
     private static Predicate<Value> referenceConstraint(String constraint) {

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/PathConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/PathConstraint.java?rev=1382054&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/PathConstraint.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/PathConstraint.java
Fri Sep  7 14:42:52 2012
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.type.constraint;
+
+import javax.annotation.Nullable;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
+import com.google.common.base.Predicate;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PathConstraint implements Predicate<Value> {
+    private static final Logger log = LoggerFactory.getLogger(PathConstraint.class);
+
+    private final String requiredValue;
+
+    public PathConstraint(String definition) {
+        this.requiredValue = definition;
+    }
+
+    @Override
+    public boolean apply(@Nullable Value value) {
+        try {
+            if (value == null || requiredValue == null) {
+                return false;
+            }
+
+            if ("*".equals(requiredValue)) {
+                return true;
+            }
+
+            String actual = value.getString();
+            String required = requiredValue;
+            if (required.endsWith("/*")) {
+                required = required.substring(0, required.length() - 2);
+                if (PathUtils.isAncestor(required, actual)) {
+                    return true;
+                }
+            }
+
+            return required.equals(actual);
+        }
+        catch (RepositoryException e) {
+            log.warn("Error checking path constraint " + this, e);
+            return false;
+        }
+    }
+
+    @Override
+    public String toString() {
+        return '\'' + requiredValue + '\'';
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/PathConstraint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/PathConstraint.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message