Author: fmeschbe
Date: Mon May 19 01:26:45 2008
New Revision: 657754

URL: http://svn.apache.org/viewvc?rev=657754&view=rev
Log:
SLING-394 Remove support for the :savePrefix parameter and enhance
the RequestProperty to resolve the property path name for relative
path elements.

Modified:
    
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/AbstractSlingPostOperation.java
    
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
    
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/NodeNameGenerator.java
    
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/operations/ModifyOperation.java

Modified: 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/AbstractSlingPostOperation.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/AbstractSlingPostOperation.java?rev=657754&r1=657753&r2=657754&view=diff
==============================================================================
--- 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/AbstractSlingPostOperation.java
 (original)
+++ 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/AbstractSlingPostOperation.java
 Mon May 19 01:26:45 2008
@@ -149,33 +149,41 @@
     }
 
     /**
-     * Return the "save prefix" to use. the names of request properties must
-     * start with that prefix in order to be regarded as input values.
-     * 
-     * @return the save prefix
+     * Returns true if any of the request parameters starts with
+     * [EMAIL PROTECTED] SlingPostConstants#ITEM_PREFIX_RELATIVE_CURRENT 
<code>./</code>}.
+     * In this case only parameters starting with either of the prefixes
+     * [EMAIL PROTECTED] SlingPostConstants#ITEM_PREFIX_RELATIVE_CURRENT 
<code>./</code>},
+     * [EMAIL PROTECTED] SlingPostConstants#ITEM_PREFIX_RELATIVE_PARENT 
<code>../</code>}
+     * and [EMAIL PROTECTED] SlingPostConstants#ITEM_PREFIX_ABSOLUTE 
<code>/</code>} are
+     * considered as providing content to be stored. Otherwise all parameters
+     * not starting with the command prefix <code>:</code> are considered as
+     * parameters to be stored.
      */
-    protected final String getSavePrefix(SlingHttpServletRequest request) {
-        String savePrefix = 
request.getParameter(SlingPostConstants.RP_SAVE_PARAM_PREFIX);
+    protected final boolean requireItemPathPrefix(
+            SlingHttpServletRequest request) {
 
-        if (savePrefix == null) {
-            savePrefix = SlingPostConstants.DEFAULT_SAVE_PARAM_PREFIX;
-        }
+        boolean requirePrefix = false;
 
-        if (savePrefix.length() > 0) {
-            String prefix = "";
-            // if no parameters start with this prefix, it is not used
-            Enumeration<?> names = request.getParameterNames();
-            while (names.hasMoreElements()) {
-                String name = (String) names.nextElement();
-                if (name.startsWith(savePrefix)) {
-                    prefix = savePrefix;
-                    break;
-                }
-            }
-            savePrefix = prefix;
+        Enumeration<?> names = request.getParameterNames();
+        while (names.hasMoreElements() && !requirePrefix) {
+            String name = (String) names.nextElement();
+            requirePrefix = 
name.startsWith(SlingPostConstants.ITEM_PREFIX_RELATIVE_CURRENT);
         }
 
-        return savePrefix;
+        return requirePrefix;
+    }
+
+    /**
+     * Returns <code>true</code> if the <code>name</code> starts with either
+     * of the prefixes
+     * [EMAIL PROTECTED] SlingPostConstants#ITEM_PREFIX_RELATIVE_CURRENT 
<code>./</code>},
+     * [EMAIL PROTECTED] SlingPostConstants#ITEM_PREFIX_RELATIVE_PARENT 
<code>../</code>}
+     * and [EMAIL PROTECTED] SlingPostConstants#ITEM_PREFIX_ABSOLUTE 
<code>/</code>}.
+     */
+    protected boolean hasItemPathPrefix(String name) {
+        return name.startsWith(SlingPostConstants.ITEM_PREFIX_ABSOLUTE)
+            || name.startsWith(SlingPostConstants.ITEM_PREFIX_ABSOLUTE)
+            || name.startsWith(SlingPostConstants.ITEM_PREFIX_ABSOLUTE);
     }
 
     /**

Modified: 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java?rev=657754&r1=657753&r2=657754&view=diff
==============================================================================
--- 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
 (original)
+++ 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
 Mon May 19 01:26:45 2008
@@ -144,30 +144,49 @@
     public static final String ORDER_LAST = "last";
 
     /**
-     * Optional request paramter specifying a node name for a newly created
-     * node.
+     * Optional request paramter specifying a node name for a newly created 
node
+     * (value is ":name").
      */
     public static final String RP_NODE_NAME = RP_PREFIX + "name";
 
     /**
      * Optional request paramter specifying a node name hint for a newly 
created
-     * node.
+     * node (value is ":nameHint").
      */
     public static final String RP_NODE_NAME_HINT = RP_PREFIX + "nameHint";
 
     /**
-     * Optional request parameter: only request parameters starting with this
-     * prefix are saved as Properties when creating a Node. Active only if at
-     * least one parameter starts with this prefix, and defaults to
-     * [EMAIL PROTECTED] #DEFAULT_SAVE_PARAM_PREFIX}.
+     * Prefix for properties addressing repository items with an absolute path
+     * (value is "/").
+     * 
+     * @see #ITEM_PREFIX_RELATIVE_CURRENT
      */
-    public static final String RP_SAVE_PARAM_PREFIX = RP_PREFIX
-        + "saveParamPrefix";
+    public static final String ITEM_PREFIX_ABSOLUTE = "/";
 
     /**
-     * Default value for [EMAIL PROTECTED] #RP_SAVE_PARAM_PREFIX}
+     * Prefix for properties addressing repository items with a path relative 
to
+     * the current request item (value is "./").
+     * <p>
+     * When collecting parameters addressing repository items for modification,
+     * the parameters are first scanned to see whether there is a parameter 
with
+     * this relative path prefix. If such a parameter exists, the modification
+     * operations only assumes parameters whose name is prefixes with this
+     * prefix or the [EMAIL PROTECTED] #ITEM_PREFIX_ABSOLUTE} or the
+     * [EMAIL PROTECTED] #ITEM_PREFIX_RELATIVE_PARENT} to be parameters 
addressing
+     * properties to modify. Otherwise, that is if no parameter starts with 
this
+     * prefix, all parameters not starting with the
+     * [EMAIL PROTECTED] #RP_PREFIX command prefix} are considered addressing 
properties to
+     * modify.
+     */
+    public static final String ITEM_PREFIX_RELATIVE_CURRENT = "./";
+
+    /**
+     * Prefix for properties addressing repository items with a path relative 
to
+     * the parent of the request item (value is "../").
+     * 
+     * @see #ITEM_PREFIX_RELATIVE_CURRENT
      */
-    public static final String DEFAULT_SAVE_PARAM_PREFIX = "./";
+    public static final String ITEM_PREFIX_RELATIVE_PARENT = "../";
 
     /**
      * Optional request parameter: redirect to the specified URL after POST

Modified: 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/NodeNameGenerator.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/NodeNameGenerator.java?rev=657754&r1=657753&r2=657754&view=diff
==============================================================================
--- 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/NodeNameGenerator.java
 (original)
+++ 
incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/NodeNameGenerator.java
 Mon May 19 01:26:45 2008
@@ -51,15 +51,9 @@
      * Get a "nice" node name, if possible, based on given request
      *
      * @param parameters the request parameters
-     * @param prefix if provided, added in front of our parameterNames
-     *        when looking for request parameters
      * @return a nice node name
      */
-    public String getNodeName(RequestParameterMap parameters, String prefix) {
-        if (prefix==null) {
-            prefix = "";
-        }
-
+    public String getNodeName(RequestParameterMap parameters) {
         String valueToUse = null;
         boolean doFilter = true;
 
@@ -88,7 +82,10 @@
                     if(valueToUse != null) {
                         break;
                     }
-                    final RequestParameter[] pp = parameters.get(prefix + 
param);
+                    RequestParameter[] pp = parameters.get(param);
+                    if (pp == null) {
+                        pp = 
parameters.get(SlingPostConstants.ITEM_PREFIX_RELATIVE_CURRENT + param);
+                    }
                     if (pp!=null) {
                         for(RequestParameter p : pp) {
                             valueToUse = p.getString();
@@ -102,8 +99,8 @@
             }
         }
         String result;
+        // should we filter?
         if (valueToUse != null) {
-            // should we filter?
             if ( doFilter ) {
                 // filter value so that it works as a node name
                 result = filter.filter(valueToUse);

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=657754&r1=657753&r2=657754&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
 Mon May 19 01:26:45 2008
@@ -17,6 +17,7 @@
 package org.apache.sling.servlets.post.impl.helper;
 
 import org.apache.sling.api.request.RequestParameter;
+import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.servlets.post.SlingPostConstants;
 
 /**
@@ -47,10 +48,10 @@
 
     public RequestProperty(String path, RequestParameter[] values) {
         assert path.startsWith("/");
-        this.path = path;
+        this.path = ResourceUtil.normalize(path);
         this.values = values;
-        this.parentPath = path.substring(0, path.lastIndexOf("/"));
-        this.name = path.substring(path.lastIndexOf("/") + 1);
+        this.parentPath = ResourceUtil.getParent(path);
+        this.name = ResourceUtil.getName(path);
     }
 
     public String getTypeHint() {

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=657754&r1=657753&r2=657754&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
 Mon May 19 01:26:45 2008
@@ -157,8 +157,7 @@
         // If the path ends with a *, create a node under its parent, with
         // a generated node name
         basePath += "/"
-            + nodeNameGenerator.getNodeName(request.getRequestParameterMap(),
-                getSavePrefix(request));
+            + nodeNameGenerator.getNodeName(request.getRequestParameterMap());
 
         // if resulting path exists, add a suffix until it's not the case
         // anymore
@@ -242,7 +241,7 @@
     private Map<String, RequestProperty> collectContent(
             SlingHttpServletRequest request, HtmlResponse response) {
 
-        String savePrefix = getSavePrefix(request);
+        boolean requireItemPrefix = requireItemPathPrefix(request);
 
         // walk the request parameters and collect the properties
         Map<String, RequestProperty> reqProperties = new HashMap<String, 
RequestProperty>();
@@ -267,13 +266,10 @@
                 continue;
             }
             // skip parameters that do not start with the save prefix
-            if (!paramName.startsWith(savePrefix)) {
-                continue;
-            }
-            String propertyName = paramName.substring(savePrefix.length());
-            if (propertyName.length() == 0) {
+            if (requireItemPrefix && !hasItemPathPrefix(paramName)) {
                 continue;
             }
+            String propertyName = paramName;
             // SLING-130: VALUE_FROM_SUFFIX means take the value of this
             // property from a different field
             RequestParameter[] values = e.getValue();
@@ -310,7 +306,7 @@
             // <input type="text" name="./age" />
             // <input type="hidden" name="./[EMAIL PROTECTED]" value="long" />
             // causes the setProperty using the 'long' property type
-            final String thName = savePrefix + propertyName
+            final String thName = propertyName
                 + SlingPostConstants.TYPE_HINT_SUFFIX;
             final RequestParameter rp = request.getRequestParameter(thName);
             if (rp != null) {
@@ -318,7 +314,7 @@
             }
 
             // @DefaultValue
-            final String dvName = savePrefix + propertyName
+            final String dvName = propertyName
                 + SlingPostConstants.DEFAULT_VALUE_SUFFIX;
             prop.setDefaultValues(request.getRequestParameters(dvName));
 


Reply via email to