You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/03/12 17:10:23 UTC

svn commit: r636388 - in /incubator/sling/trunk: launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletMoveTest.java sling/ujax/src/main/java/org/apache/sling/ujax/impl/UjaxPostProcessor.java

Author: fmeschbe
Date: Wed Mar 12 09:10:19 2008
New Revision: 636388

URL: http://svn.apache.org/viewvc?rev=636388&view=rev
Log:
SLING-312 Applying patch provided by Tobias Bocanegra. Thanks.

Modified:
    incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletMoveTest.java
    incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/impl/UjaxPostProcessor.java

Modified: incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletMoveTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletMoveTest.java?rev=636388&r1=636387&r2=636388&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletMoveTest.java (original)
+++ incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletMoveTest.java Wed Mar 12 09:10:19 2008
@@ -17,8 +17,8 @@
 package org.apache.sling.launchpad.webapp.integrationtest.ujax;
 
 import java.io.IOException;
-import java.util.Map;
 import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.sling.launchpad.webapp.integrationtest.HttpTestBase;
 
@@ -118,6 +118,38 @@
         testClient.createNode(HTTP_BASE_URL + testPath, props);
         String content = getContent(HTTP_BASE_URL + testPath + "/dest.json", CONTENT_TYPE_JSON);
         assertJavascript("Hello", content, "out.println(data.text)");
+    }
+
+    public void testMoveNodeDeep() throws IOException {
+        final String testPath = TEST_BASE_PATH + "/new/" + System.currentTimeMillis();
+        Map<String, String> props = new HashMap<String, String>();
+        props.put("text", "Hello");
+        testClient.createNode(HTTP_BASE_URL + testPath + "/src", props);
+
+        props.clear();
+        props.put("ujax:moveSrc", testPath + "/src");
+        props.put("ujax:moveDest", "deep/new");
+        String newNode = testClient.createNode(HTTP_BASE_URL + testPath + "/*", props);
+        String content = getContent(newNode + "/deep/new.json", CONTENT_TYPE_JSON);
+        assertJavascript("Hello", content, "out.println(data.text)");
+    }
+
+    public void testMoveNodeDeepFail() throws IOException {
+        final String testPath = TEST_BASE_PATH + "/new_fail/" + System.currentTimeMillis();
+        Map<String, String> props = new HashMap<String, String>();
+        props.put("text", "Hello");
+        testClient.createNode(HTTP_BASE_URL + testPath + "/src", props);
+
+        props.clear();
+        props.put("ujax:moveSrc", testPath + "/src");
+        props.put("ujax:moveDest", "/some/not/existing/structure");
+        try {
+            testClient.createNode(HTTP_BASE_URL + testPath + "/*", props);
+            // not quite correct. should check status response
+            fail("Moving node to a 'forgein' locaition should fail.");
+        } catch (IOException e) {
+            // ignore
+        }
     }
 
  }

Modified: incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/impl/UjaxPostProcessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/impl/UjaxPostProcessor.java?rev=636388&r1=636387&r2=636388&view=diff
==============================================================================
--- incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/impl/UjaxPostProcessor.java (original)
+++ incubator/sling/trunk/sling/ujax/src/main/java/org/apache/sling/ujax/impl/UjaxPostProcessor.java Wed Mar 12 09:10:19 2008
@@ -357,7 +357,22 @@
                 if (isReplace) {
                     session.getItem(dest).remove();
                 } else {
-                    throw new IllegalArgumentException("Unable to process move. destination item already exists " + dest);
+                    throw new IllegalArgumentException(
+                        "Unable to process move. destination item already exists "
+                            + dest);
+                }
+            } else {
+                // check if path to destination exists and create it, but only
+                // if it's a descendant of the current node
+                String dstParent = dest.substring(0, dest.lastIndexOf('/'));
+                if (!dstParent.equals("") && !session.itemExists(dstParent)) {
+                    if (dstParent.startsWith(htmlResponse.getPath() + "/")) {
+                        deepGetOrCreateNode(dstParent);
+                    } else {
+                        throw new IllegalArgumentException(
+                            "Unable to process move. destination's parent does not exist "
+                                + dest);
+                    }
                 }
             }
             session.move(src, dest);