incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r619348 - in /incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax: NodeNameGenerator.java UjaxPropertyValueHandler.java
Date Thu, 07 Feb 2008 10:23:22 GMT
Author: fmeschbe
Date: Thu Feb  7 02:23:22 2008
New Revision: 619348

URL: http://svn.apache.org/viewvc?rev=619348&view=rev
Log:
SLING-229 Apply provided patch

Modified:
    incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/NodeNameGenerator.java
    incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPropertyValueHandler.java

Modified: incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/NodeNameGenerator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/NodeNameGenerator.java?rev=619348&r1=619347&r2=619348&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/NodeNameGenerator.java
(original)
+++ incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/NodeNameGenerator.java
Thu Feb  7 02:23:22 2008
@@ -41,8 +41,10 @@
         if(parameterNames == null) {
             this.parameterNames = new LinkedList<String>();
             this.parameterNames.add("title");
+            this.parameterNames.add("jcr:title");
             this.parameterNames.add("name");
             this.parameterNames.add("description");
+            this.parameterNames.add("jcr:description");
             this.parameterNames.add("abstract");
         } else {
             this.parameterNames = parameterNames;

Modified: incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPropertyValueHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPropertyValueHandler.java?rev=619348&r1=619347&r2=619348&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPropertyValueHandler.java
(original)
+++ incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPropertyValueHandler.java
Thu Feb  7 02:23:22 2008
@@ -18,6 +18,8 @@
 package org.apache.sling.ujax;
 
 import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.jcr.Node;
 import javax.jcr.Property;
@@ -31,10 +33,20 @@
  */
 class UjaxPropertyValueHandler {
 
-    public static final String CREATED_FIELD = "created";
-    public static final String CREATED_BY_FIELD = "createdBy";
-    public static final String LAST_MODIFIED_FIELD = "lastModified";
-    public static final String LAST_MODIFIED_BY_FIELD = "lastModifiedBy";
+    /**
+     * Defins a map of auto properties
+     */
+    private static final Map<String, AutoType> AUTO_PROPS = new HashMap<String,
AutoType>();
+    static {
+        AUTO_PROPS.put("created", AutoType.CREATED);
+        AUTO_PROPS.put("createdBy", AutoType.CREATED_BY);
+        AUTO_PROPS.put("jcr:created", AutoType.CREATED);
+        AUTO_PROPS.put("jcr:createdBy", AutoType.CREATED_BY);
+        AUTO_PROPS.put("lastModified", AutoType.MODIFIED);
+        AUTO_PROPS.put("lastModifiedBy", AutoType.MODIFIED_BY);
+        AUTO_PROPS.put("jcr:lastModified", AutoType.MODIFIED);
+        AUTO_PROPS.put("jcr:lastModifiedBy", AutoType.MODIFIED_BY);
+    }
 
     /**
      * the post processor
@@ -61,7 +73,7 @@
      * 
      * html example for testing:
      * <xmp>
-     *   <input type="hidden" name="dateCreated"/>
+     *   <input type="hidden" name="created"/>
      *   <input type="hidden" name="lastModified"/>
      *   <input type="hidden" name="createdBy" />
      *   <input type="hidden" name="lastModifiedBy"/>
@@ -79,22 +91,26 @@
             // if user provided a value, don't mess with it
             setPropertyAsIs(parent, prop);
 
-        } else if (CREATED_FIELD.equals(name)) {
-            if (parent.isNew()) {
-                setCurrentDate(parent, name);
+        } else if (AUTO_PROPS.containsKey(name)) {
+            // avoid collision with protected properties
+            switch (AUTO_PROPS.get(name)) {
+                case CREATED:
+                    if (parent.isNew()) {
+                        setCurrentDate(parent, name);
+                    }
+                    break;
+                case CREATED_BY:
+                    if (parent.isNew()) {
+                        setCurrentUser(parent, name);
+                    }
+                    break;
+                case MODIFIED:
+                    setCurrentDate(parent, name);
+                    break;
+                case MODIFIED_BY:
+                    setCurrentUser(parent, name);
+                    break;
             }
-
-        } else if (CREATED_BY_FIELD.equals(name)) {
-            if (parent.isNew()) {
-                setCurrentUser(parent, name);
-            }
-
-        } else if (LAST_MODIFIED_FIELD.equals(name)) {
-            setCurrentDate(parent, name);
-
-        } else if (LAST_MODIFIED_BY_FIELD.equals(name)) {
-            setCurrentUser(parent, name);
-
         } else {
             // no magic field, set value as provided
             setPropertyAsIs(parent, prop);
@@ -198,4 +214,13 @@
         }
     }
 
+    /**
+     * Defines an auto property behavior
+     */
+    private enum AutoType {
+        CREATED,
+        CREATED_BY,
+        MODIFIED,
+        MODIFIED_BY
+    }
 }



Mime
View raw message