incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r620437 - in /incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax: ChangeLog.java UjaxPostProcessor.java
Date Mon, 11 Feb 2008 08:08:31 GMT
Author: fmeschbe
Date: Mon Feb 11 00:08:30 2008
New Revision: 620437

URL: http://svn.apache.org/viewvc?rev=620437&view=rev
Log:
SLING-239 Apply path SLING-239.patch

Modified:
    incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/ChangeLog.java
    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/ChangeLog.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/ChangeLog.java?rev=620437&r1=620436&r2=620437&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/ChangeLog.java
(original)
+++ incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/ChangeLog.java
Mon Feb 11 00:08:30 2008
@@ -81,23 +81,4 @@
         }
     }
 
-    /**
-     * Look if item is prepared for deletion.
-     *
-     * @param path item path
-     * @return true if prepared for deletion
-     */
-    public boolean isDeleted(String path) {
-        for (Change c: changes) {
-            if (c.getType() == Change.Type.DELETED) {
-                if (c.getArguments().length > 0) {
-                    String delPath = c.getArguments()[0];
-                    if (delPath.equals(path)) {
-                        return true;
-                    }
-                }
-            }
-        }
-        return false;
-    }
 }

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=620437&r1=620436&r2=620437&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
Mon Feb 11 00:08:30 2008
@@ -375,7 +375,6 @@
     private void processContent() throws RepositoryException, ServletException {
         // get desired path.
         String nodePath = rootPath;
-        Node currentNode;
         // check for star suffix in request
         if (isCreateRequest) {
             // If the path ends with a *, create a node under its parent, with
@@ -398,18 +397,12 @@
             }
 
         }
-        // create or get node
-        if (changeLog.isDeleted(nodePath)) {
-            // TODO: correct?
-            return;
-        }
-        currentNode = deepGetOrCreateNode(null, nodePath);
-        currentPath = currentNode.getPath();
+        currentPath = nodePath;
 
         // process the "order" command if any
         final String order = request.getParameter(UjaxPostServlet.RP_ORDER);
         if  (order!=null) {
-            processNodeOrder(currentNode, order);
+            processNodeOrder(currentPath, order);
         }
 
         // walk the request parameters, create and save nodes and properties
@@ -459,7 +452,7 @@
             }
             // create property helper and get parent node
             RequestProperty prop = new RequestProperty(this, propertyName, values);
-            Node parent = deepGetOrCreateNode(currentNode, prop.getParentPath());
+            Node parent = deepGetOrCreateNode(currentPath, prop.getParentPath());
 
             // call handler
             if (prop.isFileUpload()) {
@@ -474,6 +467,53 @@
      * 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 path to the parent node, may be null if path is absolute
+     * @param path 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 deepGetOrCreateNode(String parent, String path)
+            throws RepositoryException {
+        if(log.isDebugEnabled()) {
+            log.debug("Deep-creating Node '{}'", path);
+        }
+        if (path.equals("")) {
+            return (Node) session.getItem(parent);
+        }
+        
+        // prepend parent path if path is relative
+        if (path.charAt(0) != '/') {
+            if (parent == null || !parent.startsWith("/")) {
+                throw new IllegalArgumentException("parent must be an absolute path for relative
paths.");
+            }
+
+            if (!parent.endsWith("/")) {
+                path = "/" + path;
+            }
+            
+            path = parent + path;
+        }
+        
+        String[] pathelems = path.substring(1).split("/");
+        Node node = session.getRootNode();
+        
+        for (String name: pathelems) {
+            if (node.hasNode(name)) {
+                node = node.getNode(name);
+            } else {
+                node = node.addNode(name);
+                changeLog.onCreated(node.getPath());
+            }
+        }
+        return node;
+    }
+    
+    /**
+     * 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
@@ -546,9 +586,10 @@
      * @param orderCode code that specifies how to order
      * @throws RepositoryException if a repository error occurs
      */
-    private void processNodeOrder(Node n, String orderCode)
+    private void processNodeOrder(String nodePath, String orderCode)
             throws RepositoryException {
         if (UjaxPostServlet.ORDER_ZERO.equals(orderCode)) {
+            final Node n = deepGetOrCreateNode((String) null, nodePath);
             final Node parent = n.getParent();
             final String beforename=parent.getNodes().nextNode().getName();
             parent.orderBefore(n.getName(), beforename);



Mime
View raw message