incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r618915 - /incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostProcessor.java
Date Wed, 06 Feb 2008 07:42:36 GMT
Author: fmeschbe
Date: Tue Feb  5 23:42:33 2008
New Revision: 618915

URL: http://svn.apache.org/viewvc?rev=618915&view=rev
Log:
SLING-223 Fix intermediary node creation issue by applying supplied patch

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

Modified: incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostProcessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostProcessor.java?rev=618915&r1=618914&r2=618915&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostProcessor.java
(original)
+++ incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostProcessor.java
Tue Feb  5 23:42:33 2008
@@ -16,22 +16,20 @@
  */
 package org.apache.sling.ujax;
 
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.servlet.ServletException;
+
 import org.apache.sling.api.SlingHttpServletRequest;
-import org.apache.sling.api.resource.NonExistingResource;
+import org.apache.sling.api.request.RequestParameter;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.wrappers.SlingRequestPaths;
-import org.apache.sling.api.request.RequestParameter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Map;
-
-import javax.jcr.Session;
-import javax.jcr.RepositoryException;
-import javax.jcr.Node;
-import javax.servlet.ServletException;
-import javax.swing.RootPaneContainer;
-
 /**
  * Holds various states and encapsulates method that are neede to handle a
  * ujax post request.
@@ -401,7 +399,7 @@
 
         }
         // create or get node
-        currentNode = deepCreateNode(nodePath);
+        currentNode = deepGetOrCreateNode(null, nodePath);
         currentPath = currentNode.getPath();
 
         // process the "order" command if any
@@ -457,14 +455,8 @@
             }
             // create property helper and get parent node
             RequestProperty prop = new RequestProperty(this, propertyName, values);
-            Node parent;
-            if(prop.getRelPath().startsWith("/")) {
-                parent = deepCreateNode(prop.getParentPath());
-            } else if (!prop.getParentPath().equals("")) {
-                parent = currentNode.getNode(prop.getParentPath());
-            } else {
-                parent = currentNode;
-            }
+            Node parent = deepGetOrCreateNode(currentNode, prop.getParentPath());
+
             // call handler
             if (prop.isFileUpload()) {
                 uploadHandler.setFile(parent, prop);
@@ -475,19 +467,36 @@
     }
 
     /**
-     * Deep creates a node, parent-padding with nt:unstructured nodes
+     * Deep gets or creates a node, parent-padding with default nodes nodes.
+     * If the path is empty, the given parent node is returned.
      *
+     * @param parent parent node for relative paths
      * @param path absolute path to node that needs to be deep-created
      * @return node at path
      * @throws RepositoryException if an error occurs
+     * @throws IllegalArgumentException if the path is relative and parent
+     *         is <code>null</code>
      */
-    private Node deepCreateNode(String path) throws RepositoryException {
+    private Node deepGetOrCreateNode(Node parent, String path)
+            throws RepositoryException {
         if(log.isDebugEnabled()) {
             log.debug("Deep-creating Node '{}'", path);
         }
-
-        String[] pathelems = path.substring(1).split("/");
-        Node node = session.getRootNode();
+        if (path.equals("")) {
+            return parent;
+        }
+        String[] pathelems;
+        Node node;
+        if (path.charAt(0) == '/') {
+            pathelems = path.substring(1).split("/");
+            node = session.getRootNode();
+        } else {
+            pathelems = path.split("/");
+            node = parent;
+            if (node == null) {
+                throw new IllegalArgumentException("parent node must not be NULL for relative
paths.");
+            }
+        }
         for (String name: pathelems) {
             if (node.hasNode(name)) {
                 node = node.getNode(name);



Mime
View raw message