You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2008/01/24 14:49:42 UTC

svn commit: r614875 - in /incubator/sling/trunk: ./ launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/ launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ launchpad/launchpad-webapp/src/test/java/o...

Author: bdelacretaz
Date: Thu Jan 24 05:49:39 2008
New Revision: 614875

URL: http://svn.apache.org/viewvc?rev=614875&view=rev
Log:
SLING-180 - @DefaultValue hints for UjaxPostServlet, contributed by Tobias Bocanegra, thanks!

Added:
    incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/RequestProperty.java   (with props)
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxDefaultValuesTest.java   (with props)
Modified:
    incubator/sling/trunk/   (props changed)
    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/UjaxFileUploadHandler.java
    incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostServlet.java
    incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPropertyValueSetter.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/GeneratedNodeNameTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/IncludeTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/NodetypeRenderingTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PostRedirectTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PropertyRenderingTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBuiltinObjectsTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/SlingResourceTypeRenderingTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/UploadFileTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ValueFromTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletCreateTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletDeleteTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletOrderTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletUpdateTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxAutoPropertiesTest.java

Propchange: incubator/sling/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Jan 24 05:49:39 2008
@@ -2,3 +2,5 @@
 .project
 target
 bin
+derby.log
+sling

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=614875&r1=614874&r2=614875&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 Jan 24 05:49:39 2008
@@ -51,7 +51,7 @@
     }
     
     /** Get a "nice" node name, if possible, based on given request 
-     *  @param savePrefix if provided, added in front of our parameterNames
+     *  @param prefix if provided, added in front of our parameterNames
      *  when looking for request parameters
      */
     public String getNodeName(RequestParameterMap parameters, String prefix) {

Added: incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/RequestProperty.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/RequestProperty.java?rev=614875&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/RequestProperty.java (added)
+++ incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/RequestProperty.java Thu Jan 24 05:49:39 2008
@@ -0,0 +1,163 @@
+/*
+ * 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.sling.ujax;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.request.RequestParameter;
+
+/**
+ * Encapsulates all infos from the respective request parameters that are needed
+ * to create the repository property
+ */
+public class RequestProperty {
+
+    private static final RequestParameter[] EMPTY_PARAM_ARRAY = new RequestParameter[0];
+
+    public static final String DEFAULT_IGNORE = UjaxPostServlet.RP_PREFIX + "ignore";
+
+    public static final String DEFAULT_NULL = UjaxPostServlet.RP_PREFIX + "null";
+
+    private final String typeHint;
+
+    private final String keyName;
+
+    private final String propName;
+
+    private final String parentPath;
+
+    private final RequestParameter[] values;
+
+    private RequestParameter[] defaultValues;
+
+    public RequestProperty(SlingHttpServletRequest req, String savePrefix,
+                           String keyName, RequestParameter[] values) {
+        this.keyName = keyName;
+        this.values = values;
+        if (savePrefix == null) {
+            savePrefix = "";
+        }
+
+        // split the relative path identifying the property to be saved
+        if (keyName.indexOf("/")>=0) {
+            parentPath = keyName.substring(0, keyName.lastIndexOf("/"));
+            propName = keyName.substring(keyName.lastIndexOf("/") + 1);
+        } else {
+            parentPath = "";
+            propName = keyName;
+        }
+
+        // @TypeHint example
+        // <input type="text" name="./age" />
+        // <input type="hidden" name="./age@TypeHint" value="long" />
+        // causes the setProperty using the 'long' property type
+        final String thName = savePrefix + keyName + UjaxPostServlet.TYPE_HINT_SUFFIX;
+        final RequestParameter rp = req.getRequestParameter(thName);
+        typeHint = rp == null ? null : rp.getString();
+
+        // @DefaultValue
+        final String dvName = savePrefix + keyName + UjaxPostServlet.DEFAULT_VALUE_SUFFIX;
+        defaultValues = req.getRequestParameters(dvName);
+        if (defaultValues == null) {
+            defaultValues = EMPTY_PARAM_ARRAY;
+        }
+
+    }
+
+    public String getTypeHint() {
+        return typeHint;
+    }
+
+    public String getKeyName() {
+        return keyName;
+    }
+
+    public String getName() {
+        return propName;
+    }
+
+    public String getParentPath() {
+        return parentPath;
+    }
+
+    public RequestParameter[] getValues() {
+        return values;
+    }
+
+    public RequestParameter[] getDefaultValues() {
+        return defaultValues;
+    }
+
+    public boolean isFileUpload() {
+        return !values[0].isFormField();
+    }
+
+    /**
+     * Checks if this property provides any values. this is the case if
+     * one of the values is not empty or if the default handling is not
+     * 'ignore'
+     * @return <code>true</code> if this property provides values
+     */
+    public boolean providesValue() {
+        // should void double creation of string values
+        String[] sv = getStringValues();
+        if (sv == null) {
+            // is missleading return type. but means that property should not
+            // get auto-create values
+            return true;
+        } else {
+            for (String s: sv) {
+                if (!s.equals("")) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+    /**
+     * Returns the assembled string array out of the provided request values
+     * and default values.
+     * @return a String array or <code>null</code> if the property needs to be
+     *         removed.
+     */
+    public String[] getStringValues() {
+        if (values.length > 1) {
+            // TODO: how the default values work for MV props is not very clear
+            String[] ret = new String[values.length];
+            for (int i=0; i<ret.length; i++) {
+                ret[i] = values[i].getString();
+            }
+            return ret;
+        } else {
+            String value = values[0].getString();
+            if (value.equals("")) {
+                if (defaultValues.length == 1) {
+                    String defValue = defaultValues[0].getString();
+                    if (defValue.equals(DEFAULT_IGNORE)) {
+                        // ignore means, do not create empty values
+                        return new String[0];
+                    } else if (defValue.equals(DEFAULT_NULL)) {
+                        // null means, remove property if exist
+                        return null;
+                    }
+                    value = defValue;
+                }
+            }
+            return new String[]{value};
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/RequestProperty.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/RequestProperty.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxFileUploadHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxFileUploadHandler.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxFileUploadHandler.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxFileUploadHandler.java Thu Jan 24 05:49:39 2008
@@ -96,15 +96,12 @@
      *
      * @param request the servlet request
      * @param parent the parent node
-     * @param name the name of the file/resource node or '*'
-     * @param values the request values
-     * @param typeHint a hint for the node type
+     * @param prop the assembled property info
      * @throws RepositoryException if an error occurs
      */
-    void setFile(SlingHttpServletRequest request, Node parent, String name,
-                 RequestParameter[] values, String typeHint)
+    void setFile(SlingHttpServletRequest request, Node parent, RequestProperty prop)
             throws RepositoryException {
-        RequestParameter value = values[0];
+        RequestParameter value = prop.getValues()[0];
         assert !value.isFormField();
 
         // ignore if empty
@@ -113,6 +110,7 @@
         }
 
         // get node name
+        String name = prop.getName();
         if (name.equals("*")) {
             name = value.getFileName();
             // strip of possible path (some browsers include the entire path)
@@ -125,6 +123,7 @@
         // create an nt:file with that type. if it's invalid, drop it and let
         // the parent node type decide.
         boolean createNtFile = parent.isNodeType(NT_FOLDER);
+        String typeHint = prop.getTypeHint();
         if (typeHint != null) {
             try {
                 NodeTypeManager ntMgr = parent.getSession().getWorkspace().getNodeTypeManager();

Modified: incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostServlet.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostServlet.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostServlet.java Thu Jan 24 05:49:39 2008
@@ -16,9 +16,18 @@
  */
 package org.apache.sling.ujax;
 
+import org.apache.sling.api.SlingException;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.request.RequestParameter;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.apache.sling.api.wrappers.SlingRequestPaths;
+import org.apache.sling.core.CoreConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
@@ -30,17 +39,6 @@
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.sling.api.SlingException;
-import org.apache.sling.api.SlingHttpServletRequest;
-import org.apache.sling.api.SlingHttpServletResponse;
-import org.apache.sling.api.request.RequestParameter;
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.servlets.SlingAllMethodsServlet;
-import org.apache.sling.api.wrappers.SlingRequestPaths;
-import org.apache.sling.core.CoreConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /** POST servlet that implements the ujax "protocol" */
 public class UjaxPostServlet extends SlingAllMethodsServlet {
     private static final long serialVersionUID = 1837674988291697074L;
@@ -55,12 +53,19 @@
      */
     public static final String RP_PREFIX = "ujax:";
 
+    /** suffix that indicates node creation */
+    public static final String DEFAULT_CREATE_SUFFIX = "/*";
+
     /** Optional request parameter: redirect to the specified URL after POST */
     public static final String RP_REDIRECT_TO =  RP_PREFIX + "redirect";
 
     /** Optional request parameter: delete the specified content paths */
     public static final String RP_DELETE_PATH = RP_PREFIX + "delete";
 
+    /** Optional request parameter: move the specified content paths */
+    public static final String RP_MOVE_SRC = RP_PREFIX + "moveSrc";
+    public static final String RP_MOVE_DEST = RP_PREFIX + "moveDest";
+
     /** 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 {@link #DEFAULT_SAVE_PARAM_PREFIX}.
@@ -88,6 +93,8 @@
 
     public static final String TYPE_HINT_SUFFIX = "@TypeHint";
 
+    public static final String DEFAULT_VALUE_SUFFIX = "@DefaultValue";
+
     @Override
     protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
             throws ServletException, IOException {
@@ -100,7 +107,7 @@
             Node currentNode = currentResource.adaptTo(Node.class);
 
             // need a Node, path and Session
-            String currentPath = null;
+            final String currentPath;
             if(currentNode != null) {
                 currentPath = currentNode.getPath();
                 s = currentNode.getSession();
@@ -113,14 +120,10 @@
                 throw new ServletException("No JCR Session available, currentNode=" + currentNode);
             }
 
-            final String [] pathsToDelete = request.getParameterValues(RP_DELETE_PATH);
-            if(pathsToDelete!=null) {
-                // process deletes if any, and if so don't do anything else
-                deleteNodes(s, pathsToDelete, currentPath, response);
-            } else {
-                // if no deletes, create or update nodes
-                createOrUpdateNodesFromRequest(request, response, s);
-            }
+            // process changes
+            processDeletes(request, s, currentPath);
+            processMoves(request, s, currentPath);
+            createOrUpdateNodesFromRequest(request, response, s);
 
         } catch(RepositoryException re) {
             throw new SlingException(re.toString(), re);
@@ -136,23 +139,9 @@
         }
     }
 
-    /** Delete specified nodes, and send response */
-    protected void deleteNodes(Session s, String [] pathsToDelete, String currentPath, SlingHttpServletResponse response)
-    throws RepositoryException, IOException {
-        processDeletes(s, pathsToDelete, currentPath);
-        s.save();
-        response.setContentType(getServletContext().getMimeType("dummy.txt"));
-        final PrintWriter pw = new PrintWriter(new OutputStreamWriter(response.getOutputStream()));
-        pw.println("Nodes have been deleted(if they existed):");
-        for(String path : pathsToDelete) {
-            pw.println(path);
-        }
-        pw.flush();
-    }
-
     /** Create or update node(s) according to current request , and send response */
     protected void createOrUpdateNodesFromRequest(SlingHttpServletRequest request, SlingHttpServletResponse response, Session s)
-    throws RepositoryException, IOException {
+            throws RepositoryException, IOException {
 
         // find out the actual "save prefix" to use - only parameters starting with
         // this prefix are saved as Properties, when creating nodes, see setPropertiesFromRequest()
@@ -167,8 +156,7 @@
             currentPath = currentPath.substring(0,dotPos);
         }
 
-        // TODO in microsling this was /* but that causes problems as * is not a valid JCR path - temp fix for now
-        final String starSuffix = "/UJAX_create";
+        final String starSuffix = DEFAULT_CREATE_SUFFIX;
         if(currentPath.endsWith(starSuffix)) {
             // If the path ends with a *, create a node under its parent, with
             // a generated node name
@@ -177,9 +165,8 @@
             
             // if resulting path exists, add a suffix until it's not the case anymore
             if(s.itemExists(currentPath)) {
-                String newPath = currentPath;
                 for(int suffix = 0; suffix < 100; suffix++) {
-                    newPath = currentPath + "_" + suffix;
+                    String newPath = currentPath + "_" + suffix;
                     if(!s.itemExists(newPath)) {
                         currentPath = newPath;
                         break;
@@ -291,11 +278,16 @@
                 propertyName = paramName.substring(savePrefix.length());
             }
 
-            // ignore field with a '@TypeHint' suffix. this is dealt in setProperty()
+            // ignore field with a '@TypeHint' suffix. this is dealt in RequestProperty
             if (propertyName.endsWith(TYPE_HINT_SUFFIX)) {
                 continue;
             }
 
+            // ignore field with a '@DefaultValue' suffix. this is dealt in RequestProperty
+            if (propertyName.endsWith(DEFAULT_VALUE_SUFFIX)) {
+                continue;
+            }
+
             // SLING-130: VALUE_FROM_SUFFIX means take the value of this
             // property from a different field
             RequestParameter[] values = e.getValue();
@@ -318,71 +310,45 @@
                 }
             }
 
-            // @TypeHint example
-            // <input type="text" name="./age" />
-            // <input type="hidden" name="./age@TypeHint" value="long" />
-            // causes the setProperty using the 'long' property type
-            final String thName = e.getKey() + TYPE_HINT_SUFFIX;
-            final RequestParameter rp = request.getRequestParameter(thName);
-            final String typeHint = rp == null ? null : rp.getString();
-            setProperty(n, request, propertyName, values, createdNodes, typeHint);
+            RequestProperty prop = new RequestProperty(request, savePrefix, propertyName, values);
+            
+            setProperty(n, request, createdNodes, prop);
         }
     }
 
-    /** Set a single Property on node N
-     * @throws RepositoryException */
+    /**
+     * Set a single Property on node N
+     *
+     * @throws RepositoryException if a repository error occurs
+     */
     private void setProperty(Node n, SlingHttpServletRequest request,
-                             String name, RequestParameter[] values,
-                             Set<Node> createdNodes, String typeHint)
+                             Set<Node> createdNodes, RequestProperty prop)
             throws RepositoryException {
 
-        // split the relative path identifying the property to be saved
-        String proppath = name;
-
-        // @ValueFrom can be used to define mappings between form fields and JCR properties
-// TODO
-//        final int vfIndex = name.indexOf("@ValueFrom");
-//        if (vfIndex >= 0) {
-//            // Indirect
-//            proppath = name.substring(0, vfIndex);
-//        } else if (name.indexOf("@") >= 0) {
-//            // skip "Hints"
-//            return;
-//        }
-
-        final String path = n.getPath();
-        String parentpath = "";
-        String propname=name;
-
-        if (propname.indexOf("/")>=0) {
-            parentpath=proppath.substring(0, name.lastIndexOf("/"));
-            propname = proppath.substring(name.lastIndexOf("/") + 1);
-        }
-
-        // if the whole thing ended in a slash -> skip
-        if (propname.equals("")) {
+        if (prop.getName().equals("")) {
             return;
         }
 
         // get or create the parent node
+        final String path = n.getPath();
         final Session s = n.getSession();
         Node parent;
-        if(name.startsWith("/")) {
-            parent = deepCreateNode(s, parentpath, createdNodes);
-
-        } else if (!parentpath.equals("")) {
-            parent = (Node) s.getItem(path + "/" + parentpath);
+        if(prop.getKeyName().startsWith("/")) {
+            parent = deepCreateNode(s, prop.getParentPath(), createdNodes);
+        } else if (!prop.getParentPath().equals("")) {
+            parent = (Node) s.getItem(path + "/" + prop.getParentPath());
         } else {
             parent = (Node) s.getItem(path);
         }
 
-        if (values[0].isFormField()) {
-            final boolean nodeIsNew = createdNodes.contains(parent);
-            propertyValueSetter.setProperty(parent, propname, values, typeHint, nodeIsNew);
+        // call setter
+        if (prop.isFileUpload()) {
+            uploadHandler.setFile(request, parent, prop);
         } else {
-            uploadHandler.setFile(request, parent, propname, values, typeHint);
+            final boolean nodeIsNew = createdNodes.contains(parent);
+            propertyValueSetter.setProperty(parent, prop, nodeIsNew);
         }
-}
+    }
 
     /**
      * Deep creates a node, parent-padding with nt:unstructured nodes
@@ -411,46 +377,84 @@
         return (parent);
     }
 
-    /** Delete Items at the provided paths
-     *  @param pathsToDelete each path that does not start with / is
-     *      prepended with currentPath
+    /**
+     * Delete Items at the provided paths
+     * @param request the servlet request
+     * @param s the session
+     * @param currentPath the current path
+     * @throws RepositoryException if a repository error occurs
      */
-    private void processDeletes(Session s, String [] pathsToDelete, String currentPath)
-    throws RepositoryException {
-        for(String path : pathsToDelete) {
-            if(!path.startsWith("/")) {
-                path = currentPath + "/" + path;
-            }
-            if(s.itemExists(path)) {
-                s.getItem(path).remove();
-                if(log.isDebugEnabled()) {
-                    log.debug("Deleted item " + path);
+    private void processDeletes(SlingHttpServletRequest request, Session s,
+                                String currentPath)
+            throws RepositoryException {
+        final String [] pathsToDelete = request.getParameterValues(RP_DELETE_PATH);
+        if (pathsToDelete != null) {
+            for(String path : pathsToDelete) {
+                if(!path.startsWith("/")) {
+                    path = currentPath + "/" + path;
                 }
-            } else {
-                if(log.isDebugEnabled()) {
-                    log.debug("Item '" + path + "' not found for deletion, ignored");
+                if(s.itemExists(path)) {
+                    s.getItem(path).remove();
+                    if(log.isDebugEnabled()) {
+                        log.debug("Deleted item " + path);
+                    }
+                } else {
+                    if(log.isDebugEnabled()) {
+                        log.debug("Item '" + path + "' not found for deletion, ignored");
+                    }
                 }
             }
         }
     }
 
+    /**
+     * Move nodes at the provided paths
+     * @param request the servlet request
+     * @param s the session
+     * @param currentPath the current path
+     * @throws RepositoryException if a repository error occurs
+     */
+    private void processMoves(SlingHttpServletRequest request, Session s,
+                                String currentPath)
+            throws RepositoryException {
+        final String [] moveSrc = request.getParameterValues(RP_MOVE_SRC);
+        final String [] moveDest = request.getParameterValues(RP_MOVE_DEST);
+        if (moveSrc == null || moveDest == null) {
+            return;
+        }
+        if (moveSrc.length != moveDest.length) {
+            return;
+        }
+        for (int i=0; i<moveSrc.length; i++) {
+            String src = moveSrc[i];
+            if (!src.startsWith("/")) {
+                src = currentPath + "/" + src;
+            }
+            String dest = moveDest[i];
+            if (!dest.startsWith("/")) {
+                dest = currentPath + "/" + dest;
+            }
+            s.move(src, dest);
+            if (log.isDebugEnabled()) {
+                log.debug("moved {} to {}", src, dest);
+            }
+        }
+    }
+
     /** Return the "save prefix" to use, null if none */
     private String getSavePrefix(SlingHttpServletRequest request) {
         String prefix = request.getParameter(RP_SAVE_PARAM_PREFIX);
-        if(prefix==null) {
+        if (prefix==null) {
             prefix = DEFAULT_SAVE_PARAM_PREFIX;
         }
 
         // if no parameters start with this prefix, it is not used
-        String result = null;
-        for(String name : request.getRequestParameterMap().keySet()) {
-            if(name.startsWith(prefix)) {
-                result = prefix;
-                break;
+        for (String name : request.getRequestParameterMap().keySet()) {
+            if (name.startsWith(prefix)) {
+                return prefix;
             }
         }
-
-        return result;
+        return null;
     }
 
     /** If orderCode is ORDER_ZERO, move n so that it is the first

Modified: incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPropertyValueSetter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPropertyValueSetter.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPropertyValueSetter.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPropertyValueSetter.java Thu Jan 24 05:49:39 2008
@@ -45,15 +45,16 @@
      * <input type="hidden" name="lastModified"/> <input type="hidden"
      * name="createdBy"/> <input type="hidden" name="lastModifiedBy"/>
      */
-    void setProperty(Node parent, String name, RequestParameter[] values, String typehint, boolean nodeWasJustCreated)
+    void setProperty(Node parent, RequestProperty prop, boolean nodeWasJustCreated)
             throws RepositoryException {
 
         // set the same timestamp for all values, to ease testing
         final Calendar now = Calendar.getInstance();
-        
-        if (valueProvided(values)) {
+
+        final String name = prop.getName();
+        if (prop.providesValue()) {
             // if user provided a value, don't mess with it
-            setPropertyAsIs(parent, name, values, typehint);
+            setPropertyAsIs(parent, prop);
 
         } else if (CREATED_FIELD.equals(name)) {
             if (nodeWasJustCreated) {
@@ -73,71 +74,74 @@
 
         } else {
             // no magic field, set value as provided
-            setPropertyAsIs(parent, name, values, typehint);
+            setPropertyAsIs(parent, prop);
         }
     }
 
     /** set property to the current Date */
-    private void setCurrentDate(Node parent, String name, Calendar now) throws RepositoryException {
+    private void setCurrentDate(Node parent, String name, Calendar now)
+            throws RepositoryException {
         removePropertyIfExists(parent, name);
         parent.setProperty(name, now);
     }
 
     /** set property to the current User id */
-    private void setCurrentUser(Node parent, String name) throws RepositoryException {
+    private void setCurrentUser(Node parent, String name)
+            throws RepositoryException {
         removePropertyIfExists(parent, name);
         parent.setProperty(name, parent.getSession().getUserID());
     }
 
-    private void removePropertyIfExists(Node parent, String name) throws RepositoryException {
+    /**
+     * Removes the property with the given name from the parent node if it
+     * exists and if it's not a mandatory property.
+     *
+     * @param parent the parent node
+     * @param name the name of the property to remove
+     * @throws RepositoryException if a repository error occurs.
+     */
+    private void removePropertyIfExists(Node parent, String name)
+            throws RepositoryException {
         if (parent.hasProperty(name)) {
             Property prop = parent.getProperty(name);
-            prop.remove();
+            if (!prop.getDefinition().isMandatory()) {
+                prop.remove();
+            }
         }
     }
 
     /** set property without processing, except for type hints */
-    private void setPropertyAsIs(Node parent, String name, RequestParameter[] values, String typehint) throws RepositoryException {
-        removePropertyIfExists(parent, name);
+    private void setPropertyAsIs(Node parent, RequestProperty prop)
+            throws RepositoryException {
+
+        removePropertyIfExists(parent, prop.getName());
 
         // no explicit typehint
-        if (typehint == null) {
-            // guess type based on mvp information from property
-            // TODO: use old property definition to guess aswell
-            if (values.length > 1) {
-                final String [] stringValues = new String[values.length];
-                int i = 0;
-                for(RequestParameter p : values) {
-                    stringValues[i++] = p.getString();
-                }
-                parent.setProperty(name, stringValues);
-            } else {
-                parent.setProperty(name, values[0].getString());
+        int type = PropertyType.STRING;
+        if (prop.getTypeHint() != null) {
+            try {
+                type = PropertyType.valueFromName(prop.getTypeHint());
+            } catch (Exception e) {
+                // ignore
             }
         }
 
-        // explicit typehint Date
-        if ("Date".equals(typehint)) {
-            parent.setProperty(name, values[0].getString(), PropertyType.DATE);
-        }
-
-        // TODO: accept more typehints including mvp
-        // TODO: binary support
-    }
-
-    /** true if values contains at least one non-empty value */
-    private boolean valueProvided(RequestParameter[] values) {
-        boolean result = false;
-
-        for (RequestParameter p : values) {
-            final String val = p.getString();
-            if(val!=null && val.length() > 0) {
-                result = true;
-                break;
+        String[] values = prop.getStringValues();
+        if (values == null) {
+            // remove property
+            removePropertyIfExists(parent, prop.getName());
+        } else if (values.length == 0) {
+            // do not create new prop here, but clear existing
+            if (parent.hasProperty(prop.getName())) {
+                parent.setProperty(prop.getName(), "");
             }
+        } else if (values.length == 1) {
+            removePropertyIfExists(parent, prop.getName());
+            parent.setProperty(prop.getName(), values[0], type);
+        } else {
+            removePropertyIfExists(parent, prop.getName());
+            parent.setProperty(prop.getName(), values, type);
         }
-
-        return result;
     }
 
 }

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/GeneratedNodeNameTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/GeneratedNodeNameTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/GeneratedNodeNameTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/GeneratedNodeNameTest.java Thu Jan 24 05:49:39 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.sling.launchpad.webapp.integrationtest;
 
+import org.apache.sling.ujax.UjaxPostServlet;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
@@ -25,7 +27,7 @@
  */
 public class GeneratedNodeNameTest extends HttpTestBase {
     
-    private final String postUrl = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + "/UJAX_create";
+    private final String postUrl = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + UjaxPostServlet.DEFAULT_CREATE_SUFFIX;
 
     public void testTitle() throws IOException {
         final Map<String,String> props = new HashMap<String,String>();

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java Thu Jan 24 05:49:39 2008
@@ -58,7 +58,7 @@
     public static final String CONTENT_TYPE_JSON = "application/json";
     public static final String CONTENT_TYPE_JS = "application/x-javascript";
     public static final String CONTENT_TYPE_CSS = "text/css";
-    
+
     protected UslingIntegrationTestClient testClient;
     protected HttpClient httpClient;
     

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/IncludeTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/IncludeTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/IncludeTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/IncludeTest.java Thu Jan 24 05:49:39 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.sling.launchpad.webapp.integrationtest;
 
+import org.apache.sling.ujax.UjaxPostServlet;
+
 import java.io.IOException;
 import java.net.URL;
 import java.util.HashMap;
@@ -40,7 +42,7 @@
         
         // Create the test nodes under a path that's specific to this class to
         // allow collisions
-        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + "/UJAX_create";
+        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + UjaxPostServlet.DEFAULT_CREATE_SUFFIX;
         final Map<String,String> props = new HashMap<String,String>();
         
         // Create two test nodes and store their paths

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java Thu Jan 24 05:49:39 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.sling.launchpad.webapp.integrationtest;
 
+import org.apache.sling.ujax.UjaxPostServlet;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
@@ -38,7 +40,7 @@
         testText = "This is a test " + System.currentTimeMillis();
         
         // create the test node, under a path that's specific to this class to allow collisions
-        postUrl = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "_" + System.currentTimeMillis() + "/UJAX_create";
+        postUrl = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "_" + System.currentTimeMillis() + UjaxPostServlet.DEFAULT_CREATE_SUFFIX;
         final Map<String,String> props = new HashMap<String,String>();
         props.put("text", testText);
         createdNodeUrl = testClient.createNode(postUrl, props);

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/NodetypeRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/NodetypeRenderingTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/NodetypeRenderingTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/NodetypeRenderingTest.java Thu Jan 24 05:49:39 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.sling.launchpad.webapp.integrationtest;
 
+import org.apache.sling.ujax.UjaxPostServlet;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
@@ -37,7 +39,7 @@
 
         // create the test node, under a path that's specific to this class to allow collisions
         secondFolderOfContentPath = "" + System.currentTimeMillis();
-        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + secondFolderOfContentPath + "/UJAX_create";
+        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + secondFolderOfContentPath + UjaxPostServlet.DEFAULT_CREATE_SUFFIX;
         final Map<String,String> props = new HashMap<String,String>();
         props.put("text", testText);
         displayUrl = testClient.createNode(url, props);

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PostRedirectTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PostRedirectTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PostRedirectTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PostRedirectTest.java Thu Jan 24 05:49:39 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.sling.launchpad.webapp.integrationtest;
 
+import org.apache.sling.ujax.UjaxPostServlet;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
@@ -25,7 +27,7 @@
 public class PostRedirectTest extends HttpTestBase {
 
     private String postPath = "CreateNodeTest/" + System.currentTimeMillis();
-    private String postUrl = HTTP_BASE_URL + "/" + postPath + "/UJAX_create";
+    private String postUrl = HTTP_BASE_URL + "/" + postPath + UjaxPostServlet.DEFAULT_CREATE_SUFFIX;
     
     public void testForcedRedirect() throws IOException {
         final Map<String,String> params = new HashMap<String,String>();

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PropertyRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PropertyRenderingTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PropertyRenderingTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PropertyRenderingTest.java Thu Jan 24 05:49:39 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.sling.launchpad.webapp.integrationtest;
 
+import org.apache.sling.ujax.UjaxPostServlet;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
@@ -36,7 +38,7 @@
         slingResourceType = getClass().getName();
 
         // create the test node, under a path that's specific to this class to allow collisions
-        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + "/UJAX_create";
+        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + UjaxPostServlet.DEFAULT_CREATE_SUFFIX;
         final Map<String,String> props = new HashMap<String,String>();
         props.put("sling:resourceType", slingResourceType);
         props.put("text", testText);

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBuiltinObjectsTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBuiltinObjectsTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBuiltinObjectsTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBuiltinObjectsTest.java Thu Jan 24 05:49:39 2008
@@ -1,5 +1,7 @@
 package org.apache.sling.launchpad.webapp.integrationtest;
 
+import org.apache.sling.ujax.UjaxPostServlet;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
@@ -17,7 +19,7 @@
         testText = "This is a test " + System.currentTimeMillis();
 
         // create the test node, under a path that's specific to this class to allow collisions
-        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + "/UJAX_create";
+        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + UjaxPostServlet.DEFAULT_CREATE_SUFFIX;
         final Map<String,String> props = new HashMap<String,String>();
         props.put("sling:resourceType", slingResourceType);
         props.put("text", testText);

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/SlingResourceTypeRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/SlingResourceTypeRenderingTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/SlingResourceTypeRenderingTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/SlingResourceTypeRenderingTest.java Thu Jan 24 05:49:39 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.sling.launchpad.webapp.integrationtest;
 
+import org.apache.sling.ujax.UjaxPostServlet;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
@@ -39,7 +41,7 @@
 
         // create the test node, under a path that's specific to this class to allow collisions
         secondFolderOfContentPath = "" + System.currentTimeMillis();
-        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + secondFolderOfContentPath + "/UJAX_create";
+        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + secondFolderOfContentPath + UjaxPostServlet.DEFAULT_CREATE_SUFFIX;
         final Map<String,String> props = new HashMap<String,String>();
         props.put("sling:resourceType", slingResourceType);
         props.put("text", testText);

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/UploadFileTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/UploadFileTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/UploadFileTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/UploadFileTest.java Thu Jan 24 05:49:39 2008
@@ -99,7 +99,8 @@
         assertTrue("checking for content", data.contains("http://www.apache.org/licenses/LICENSE-2.0"));
 
         // download structure
-        String json = getContent(urlOfFileNode + ".json", CONTENT_TYPE_JSON);
+        String json = getContent(urlOfFileNode + ".100.json", CONTENT_TYPE_JSON);
+
         // just check for some strings
         assertTrue("checking primary type", json.contains("\"jcr:primaryType\":\"nt:unstructured\""));
         assertTrue("checking mime type", json.contains("\"jcr:mimeType\":\"text/plain\""));

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ValueFromTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ValueFromTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ValueFromTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ValueFromTest.java Thu Jan 24 05:49:39 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.sling.launchpad.webapp.integrationtest;
 
+import org.apache.sling.ujax.UjaxPostServlet;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
@@ -34,7 +36,7 @@
         testText = "This is a test " + System.currentTimeMillis();
         
         // create the test node, under a path that's specific to this class to allow collisions
-        postUrl = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + "/UJAX_create";
+        postUrl = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + UjaxPostServlet.DEFAULT_CREATE_SUFFIX;
         final Map<String,String> props = new HashMap<String,String>();
         props.put("text", testText);
     }

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletCreateTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletCreateTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletCreateTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletCreateTest.java Thu Jan 24 05:49:39 2008
@@ -23,6 +23,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.sling.launchpad.webapp.integrationtest.HttpTestBase;
+import org.apache.sling.ujax.UjaxPostServlet;
 
 /** Test node creation via the MicrojaxPostServlet */
 public class PostServletCreateTest extends HttpTestBase {
@@ -42,7 +43,7 @@
     }
 
     public void testCreateNode() throws IOException {
-        final String location = testClient.createNode(postUrl + "/UJAX_create", null);
+        final String location = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, null);
         assertHttpStatus(location, HttpServletResponse.SC_OK,
                 "POST must redirect to created resource (" + location + ")");
         assertTrue("Node (" + location + ") must have generated name",
@@ -76,7 +77,7 @@
         props.put("a","123");
         props.put("b","456");
         props.put("c","some words");
-        final String createdNodeUrl = testClient.createNode(postUrl + "/UJAX_create", props);
+        final String createdNodeUrl = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
         final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
         assertJavascript("123456", content, "out.println(data.a + data.b)");
         assertJavascript("some words", content, "out.println(data.c)");
@@ -90,7 +91,7 @@
         props.put("./a","123");
         props.put("./b","456");
         props.put("c","not saved");
-        final String createdNodeUrl = testClient.createNode(postUrl + "/UJAX_create", props);
+        final String createdNodeUrl = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
         final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
         assertJavascript("123456", content, "out.println(data.a + data.b)");
         assertJavascript("undefined", content, "out.println(typeof data.c)");
@@ -105,7 +106,7 @@
         props.put("STUFF_b","456");
         props.put("c","not saved");
         props.put("ujax:saveParamPrefix","STUFF_");
-        final String createdNodeUrl = testClient.createNode(postUrl + "/UJAX_create", props,null,false);
+        final String createdNodeUrl = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props,null,false);
         final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
         assertJavascript("123456", content, "out.println(data.a + data.b)");
         assertJavascript("undefined", content, "out.println(typeof data.c)");
@@ -119,7 +120,7 @@
         props.put("++b","456");
         props.put("c","not saved");
         props.put("ujax:saveParamPrefix","++");
-        final String createdNodeUrl = testClient.createNode(postUrl + "/UJAX_create", props,null,false);
+        final String createdNodeUrl = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props,null,false);
         final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
         assertJavascript("123456", content, "out.println(data.a + data.b)");
         assertJavascript("undefined", content, "out.println(typeof data.c)");

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletDeleteTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletDeleteTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletDeleteTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletDeleteTest.java Thu Jan 24 05:49:39 2008
@@ -24,6 +24,7 @@
 
 import org.apache.commons.httpclient.NameValuePair;
 import org.apache.sling.launchpad.webapp.integrationtest.HttpTestBase;
+import org.apache.sling.ujax.UjaxPostServlet;
 
 /** Test node deletion via the MicrojaxPostServlet */
 public class PostServletDeleteTest extends HttpTestBase {
@@ -45,9 +46,9 @@
     }
 
     public void TODO_FAILS_testDelete() throws IOException {
-        final String urlA = testClient.createNode(postUrl + "/UJAX_create", null);
-        final String urlB = testClient.createNode(postUrl + "/UJAX_create", null);
-        final String urlC = testClient.createNode(postUrl + "/UJAX_create", null);
+        final String urlA = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, null);
+        final String urlB = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, null);
+        final String urlC = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, null);
         final String urlD = testClient.createNode(postUrl + "/specific-location/for-delete", null);
         
         // initially all nodes must be found

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletOrderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletOrderTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletOrderTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletOrderTest.java Thu Jan 24 05:49:39 2008
@@ -23,6 +23,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.sling.launchpad.webapp.integrationtest.HttpTestBase;
+import org.apache.sling.ujax.UjaxPostServlet;
 
 /** Test the order option for node creation via the MicrojaxPostServlet */
 public class PostServletOrderTest extends HttpTestBase {
@@ -44,10 +45,10 @@
     /** Create several nodes without the order option, and check ordering */
     public void testStandardOrder() throws IOException {
         final String [] nodeUrl = new String[4];
-        nodeUrl[0] = testClient.createNode(postUrl + "/UJAX_create", null);
-        nodeUrl[1] = testClient.createNode(postUrl + "/UJAX_create", null);
-        nodeUrl[2] = testClient.createNode(postUrl + "/UJAX_create", null);
-        nodeUrl[3] = testClient.createNode(postUrl + "/UJAX_create", null);
+        nodeUrl[0] = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, null);
+        nodeUrl[1] = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, null);
+        nodeUrl[2] = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, null);
+        nodeUrl[3] = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, null);
         
         final String [] nodeName = new String[nodeUrl.length];
         for(int i = 0;  i < nodeUrl.length; i++) {
@@ -71,10 +72,10 @@
         props.put("ujax:order","0");
         
         final String [] nodeUrl = new String[4];
-        nodeUrl[0] = testClient.createNode(postUrl + "/UJAX_create", props);
-        nodeUrl[1] = testClient.createNode(postUrl + "/UJAX_create", props);
-        nodeUrl[2] = testClient.createNode(postUrl + "/UJAX_create", props);
-        nodeUrl[3] = testClient.createNode(postUrl + "/UJAX_create", props);
+        nodeUrl[0] = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
+        nodeUrl[1] = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
+        nodeUrl[2] = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
+        nodeUrl[3] = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
         
         final String [] nodeName = new String[nodeUrl.length];
         for(int i = 0;  i < nodeUrl.length; i++) {

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletUpdateTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletUpdateTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletUpdateTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletUpdateTest.java Thu Jan 24 05:49:39 2008
@@ -23,6 +23,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.sling.launchpad.webapp.integrationtest.HttpTestBase;
+import org.apache.sling.ujax.UjaxPostServlet;
 
 /** Test node updates via the MicrojaxPostServlet */
 public class PostServletUpdateTest extends HttpTestBase {
@@ -46,7 +47,7 @@
         props.put("./a","123");
         props.put("./b","456");
         
-        final String location = testClient.createNode(postUrl + "/UJAX_create", props);
+        final String location = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
         String content = getContent(location + ".json", CONTENT_TYPE_JSON);
         assertJavascript("123456", content, "out.println(data.a + data.b)");
         
@@ -64,7 +65,7 @@
         props.put("./a","123");
         props.put("./b","456");
         
-        final String location = testClient.createNode(postUrl + "/UJAX_create", props);
+        final String location = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
         String content = getContent(location + ".json", CONTENT_TYPE_JSON);
         assertJavascript("123456", content, "out.println(data.a + data.b)");
         
@@ -83,7 +84,7 @@
         props.put("./b","456");
         props.put("C","not stored");
         
-        final String location = testClient.createNode(postUrl + "/UJAX_create", props);
+        final String location = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
         String content = getContent(location + ".json", CONTENT_TYPE_JSON);
         assertJavascript("123456", content, "out.println(data.a + data.b)");
         

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxAutoPropertiesTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxAutoPropertiesTest.java?rev=614875&r1=614874&r2=614875&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxAutoPropertiesTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxAutoPropertiesTest.java Thu Jan 24 05:49:39 2008
@@ -23,6 +23,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.sling.launchpad.webapp.integrationtest.HttpTestBase;
+import org.apache.sling.ujax.UjaxPostServlet;
 
 /** {#link MicrojaxPropertyValueSetter} sets the value of some properties
  *  automatically if they are empty. This is tested here with various cases.
@@ -54,7 +55,7 @@
         props.put("lastModified","");
         props.put("lastModifiedBy","");
         
-        final String createdNodeUrl = testClient.createNode(postUrl + "/UJAX_create", props);
+        final String createdNodeUrl = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
         String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
         
         assertJavascript("123", content, "out.println(data.a)");
@@ -91,7 +92,7 @@
         props.put("lastModified","c");
         props.put("lastModifiedBy","d");
         
-        final String createdNodeUrl = testClient.createNode(postUrl + "/UJAX_create", props);
+        final String createdNodeUrl = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
         final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
         
         assertJavascript("123", content, "out.println(data.a)");

Added: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxDefaultValuesTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxDefaultValuesTest.java?rev=614875&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxDefaultValuesTest.java (added)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxDefaultValuesTest.java Thu Jan 24 05:49:39 2008
@@ -0,0 +1,105 @@
+/*
+ * 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.sling.launchpad.webapp.integrationtest.ujax;
+
+import org.apache.sling.launchpad.webapp.integrationtest.HttpTestBase;
+import org.apache.sling.ujax.UjaxPostServlet;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/** {#link UjaxPropertyValueSetter} sets the value of some properties
+ *  with default values if they are empty. This is tested here with various cases.
+ */
+
+public class UjaxDefaultValuesTest extends HttpTestBase {
+
+    public static final String TEST_BASE_PATH = "/ujax-tests";
+    private String postUrl;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + System.currentTimeMillis();
+    }
+
+    public void testDefaultBehaviour() throws IOException {
+        final Map<String, String> props = new HashMap<String, String>();
+        props.put("a","");
+
+        final String createdNodeUrl = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
+        String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
+
+        // default behaviour writes empty string
+        assertJavascript("", content, "out.println(data.a)");
+
+        // overwrite with "123"
+        props.put("a", "123");
+        testClient.createNode(createdNodeUrl, props);
+        content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
+
+        assertJavascript("123", content, "out.println(data.a)");
+
+        // and clear again
+        props.put("a", "");
+        testClient.createNode(createdNodeUrl, props);
+        content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
+
+        assertJavascript("", content, "out.println(data.a)");
+    }
+
+    public void testWithSpecificDefault() throws IOException {
+        final Map <String, String> props = new HashMap <String, String> ();
+        props.put("a","");
+        props.put("a@DefaultValue","123");
+
+        final String createdNodeUrl = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
+        final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
+
+        assertJavascript("123", content, "out.println(data.a)");
+    }
+
+    public void testWithIgnore() throws IOException {
+        final Map <String, String> props = new HashMap <String, String> ();
+        props.put("a","");
+        props.put("a@DefaultValue","ujax:ignore");
+
+        final String createdNodeUrl = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
+        final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
+
+        assertJavascript("undefined", content, "out.println(typeof(data.a))");
+    }
+
+    public void testWithNull() throws IOException {
+        final Map <String, String> props = new HashMap <String, String> ();
+        props.put("a","123");
+
+        final String createdNodeUrl = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
+        String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
+
+        assertJavascript("123", content, "out.println(data.a)");
+
+        // now try to delete prop by sending empty string
+        props.put("a","");
+        props.put("a@DefaultValue","ujax:null");
+        testClient.createNode(createdNodeUrl, props);
+        content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
+
+        assertJavascript("undefined", content, "out.println(typeof(data.a))");
+    }
+}
\ No newline at end of file

Propchange: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxDefaultValuesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxDefaultValuesTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL