Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 33093 invoked from network); 6 Feb 2008 07:42:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Feb 2008 07:42:58 -0000 Received: (qmail 32484 invoked by uid 500); 6 Feb 2008 07:42:50 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 32471 invoked by uid 500); 6 Feb 2008 07:42:50 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 32457 invoked by uid 99); 6 Feb 2008 07:42:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Feb 2008 23:42:50 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Feb 2008 07:42:29 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0CF841A9832; Tue, 5 Feb 2008 23:42:36 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: sling-commits@incubator.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080206074237.0CF841A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 null */ - 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);