Author: cziegeler
Date: Sun Jun 15 23:47:54 2008
New Revision: 668063

URL: http://svn.apache.org/viewvc?rev=668063&view=rev
Log:
SLING-533: Support multi-value type hints (eg. @TypeHint=String[])

Modified:
    
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/RequestProperty.java
    
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java
    
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java

Modified: 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/RequestProperty.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/RequestProperty.java?rev=668063&r1=668062&r2=668063&view=diff
==============================================================================
--- 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/RequestProperty.java
 (original)
+++ 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/RequestProperty.java
 Sun Jun 15 23:47:54 2008
@@ -46,6 +46,8 @@
 
     private String typeHint;
 
+    private boolean hasMultiValueTypeHint;
+
     private RequestParameter[] defaultValues = EMPTY_PARAM_ARRAY;
 
     private boolean isDelete;
@@ -65,8 +67,18 @@
         return typeHint;
     }
 
-    public void setTypeHint(String typeHint) {
-        this.typeHint = typeHint;
+    public boolean hasMultiValueTypeHint() {
+        return this.hasMultiValueTypeHint;
+    }
+
+    public void setTypeHintValue(String typeHint) {
+        if ( typeHint != null && typeHint.endsWith("[]") ) {
+            this.typeHint = typeHint.substring(0, typeHint.length() - 2);
+            this.hasMultiValueTypeHint = true;
+        } else {
+            this.typeHint = typeHint;
+            this.hasMultiValueTypeHint = false;
+        }
     }
 
     public String getPath() {

Modified: 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java?rev=668063&r1=668062&r2=668063&view=diff
==============================================================================
--- 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java
 (original)
+++ 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingPropertyValueHandler.java
 Sun Jun 15 23:47:54 2008
@@ -220,9 +220,17 @@
                     // try conversion
                     Calendar c = dateParser.parse(values[0]);
                     if (c != null) {
-                        response.onModified(
-                            parent.setProperty(prop.getName(), c).getPath()
-                        );
+                        if ( prop.hasMultiValueTypeHint() ) {
+                            final Value[] array = new Value[1];
+                            array[0] = 
parent.getSession().getValueFactory().createValue(c);
+                            response.onModified(
+                                parent.setProperty(prop.getName(), 
array).getPath()
+                            );
+                        } else {
+                            response.onModified(
+                                    parent.setProperty(prop.getName(), 
c).getPath()
+                                );
+                        }
                         return;
                     }
                     // fall back to default behaviour
@@ -231,7 +239,13 @@
                 if ( type == PropertyType.UNDEFINED ) {
                     p = parent.setProperty(prop.getName(), values[0]);
                 } else {
-                    p = parent.setProperty(prop.getName(), values[0], type);
+                    if ( prop.hasMultiValueTypeHint() ) {
+                        final Value[] array = new Value[1];
+                        array[0] = 
parent.getSession().getValueFactory().createValue(values[0], type);
+                        p = parent.setProperty(prop.getName(), array);
+                    } else {
+                        p = parent.setProperty(prop.getName(), values[0], 
type);
+                    }
                 }
                 response.onModified(p.getPath());
             }

Modified: 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java?rev=668063&r1=668062&r2=668063&view=diff
==============================================================================
--- 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java
 (original)
+++ 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java
 Sun Jun 15 23:47:54 2008
@@ -27,6 +27,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
 
 import org.apache.sling.api.SlingException;
 import org.apache.sling.api.SlingHttpServletRequest;
@@ -200,7 +201,7 @@
 
     /**
      * Create node(s) according to current request
-     * 
+     *
      * @throws RepositoryException if a repository error occurs
      */
     private void processCreate(Session session,
@@ -256,7 +257,7 @@
      * Any intermediary nodes to the destination as indicated by the
      * <code>property</code> path are created using the
      * <code>reqProperties</code> as indications for required node types.
-     * 
+     *
      * @param property The [EMAIL PROTECTED] RequestProperty} identifying the 
source
      *            content of the operation.
      * @param isMove <code>true</code> if the source item is to be moved.
@@ -322,7 +323,7 @@
             // make sure the property is not deleted even in case for a given
             // property both @MoveFrom and @Delete is set
             property.setDelete(false);
-            
+
             // record successful move
             if (isMove) {
                 response.onMoved(source, propPath);
@@ -335,7 +336,7 @@
     /**
      * Removes all properties listed as [EMAIL PROTECTED] 
RequestProperty#isDelete()} from
      * the repository.
-     * 
+     *
      * @param session The <code>javax.jcr.Session</code> used to access the
      *            repository to delete the properties.
      * @param reqProperties The map of request properties to check for
@@ -363,7 +364,7 @@
 
     /**
      * Writes back the content
-     * 
+     *
      * @throws RepositoryException if a repository error occurs
      * @throws ServletException if an internal error occurs
      */
@@ -395,7 +396,7 @@
     /**
      * Collects the properties that form the content to be written back to the
      * repository.
-     * 
+     *
      * @throws RepositoryException if a repository error occurs
      * @throws ServletException if an internal error occurs
      */
@@ -436,7 +437,7 @@
 
                 final RequestParameter[] rp = e.getValue();
                 if (rp.length > 0) {
-                    prop.setTypeHint(rp[0].getString());
+                    prop.setTypeHintValue(rp[0].getString());
                 }
 
                 continue;
@@ -553,7 +554,7 @@
      * Returns the request property for the given property path. If such a
      * request property does not exist yet it is created and stored in the
      * <code>props</code>.
-     * 
+     *
      * @param props The map of already seen request properties.
      * @param paramName The absolute path of the property including the
      *            <code>suffix</code> to be looked up.
@@ -580,7 +581,7 @@
     /**
      * Checks the collected content for a jcr:primaryType property at the
      * specified path.
-     * 
+     *
      * @param path path to check
      * @return the primary type or <code>null</code>
      */
@@ -593,7 +594,7 @@
     /**
      * Checks the collected content for a jcr:mixinTypes property at the
      * specified path.
-     * 
+     *
      * @param path path to check
      * @return the mixin types or <code>null</code>
      */
@@ -606,7 +607,7 @@
     /**
      * Deep gets or creates a node, parent-padding with default nodes nodes. If
      * the path is empty, the given parent node is returned.
-     * 
+     *
      * @param path path to node that needs to be deep-created
      * @return node at path
      * @throws RepositoryException if an error occurs


Reply via email to