incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r644724 - in /incubator/sling/trunk: launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/GeneratedNodeNameTest.java sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/NodeNameGenerator.java
Date Fri, 04 Apr 2008 14:37:00 GMT
Author: cziegeler
Date: Fri Apr  4 07:36:55 2008
New Revision: 644724

URL: http://svn.apache.org/viewvc?rev=644724&view=rev
Log:
SLING-354: Added sling:post:nodeName request parameter and use exactly this value for the
node name.

Modified:
    incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/GeneratedNodeNameTest.java
    incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/NodeNameGenerator.java

Modified: incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/GeneratedNodeNameTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/GeneratedNodeNameTest.java?rev=644724&r1=644723&r2=644724&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/GeneratedNodeNameTest.java
(original)
+++ incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/GeneratedNodeNameTest.java
Fri Apr  4 07:36:55 2008
@@ -26,7 +26,7 @@
  *  ending in / *
  */
 public class GeneratedNodeNameTest extends HttpTestBase {
-    
+
     private final String postUrl = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/"
+ System.currentTimeMillis() + SlingPostServlet.DEFAULT_CREATE_SUFFIX;
 
     public void testTitle() throws IOException {
@@ -36,7 +36,15 @@
         final String expect = "hello_there";
         assertTrue("Location " + location + " ends with " + expect,location.endsWith(expect));
     }
-    
+
+    public void testSlingPostNodeNameParam() throws IOException {
+        final Map<String,String> props = new HashMap<String,String>();
+        props.put("sling:post:nodeName", "MyNodeName");
+        final String location = testClient.createNode(postUrl, props);
+        final String expect = "MyNodeName";
+        assertTrue("Location " + location + " ends with " + expect,location.endsWith(expect));
+    }
+
     public void testTitleWithSavePrefix() throws IOException {
         final Map<String,String> props = new HashMap<String,String>();
         props.put("./title", "Hello There 2");
@@ -45,19 +53,19 @@
         final String expect = "hello_there_2";
         assertTrue("Location " + location + " ends with " + expect,location.endsWith(expect));
     }
-    
+
     public void testCollision() throws IOException {
         final Map<String,String> props = new HashMap<String,String>();
         props.put("title", "Hello There");
-        
+
         // posting twice with the same title must work, and return different locations
         final String locationA = testClient.createNode(postUrl, props);
         final String locationB = testClient.createNode(postUrl, props);
-        
+
         assertFalse("Locations A and B must be different (" + locationA + "," + locationB
+ ")",
                 locationA.equals(locationB));
     }
-    
+
     public void testNoParams() throws IOException {
         final String location = testClient.createNode(postUrl, null);
         assertTrue("Location end with a digit",Character.isDigit(location.charAt(location.length()
- 1)));

Modified: incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/NodeNameGenerator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/NodeNameGenerator.java?rev=644724&r1=644723&r2=644724&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/NodeNameGenerator.java
(original)
+++ incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/NodeNameGenerator.java
Fri Apr  4 07:36:55 2008
@@ -30,7 +30,6 @@
 
     private static final List<String> DEFAULT_NAMES = new LinkedList<String>();
     static {
-        DEFAULT_NAMES.add(SlingPostServlet.RP_NODE_NAME);
         DEFAULT_NAMES.add("title");
         DEFAULT_NAMES.add("jcr:title");
         DEFAULT_NAMES.add("name");
@@ -73,42 +72,58 @@
             prefix = "";
         }
 
+        String valueToUse = null;
+        boolean doFilter = true;
+
         // find the first request parameter that matches one of
         // our parameterNames, in order, and has a value
-        String valueToUse = null;
-        if(parameters!=null) {
-            for(String param : parameterNames) {
-                if(valueToUse != null) {
-                    break;
+        if (parameters!=null) {
+            // we first check for the special sling parameter
+            final RequestParameter specialParam = parameters.getValue(SlingPostServlet.RP_NODE_NAME);
+            if ( specialParam != null ) {
+                if ( specialParam.getString() != null && specialParam.getString().length()
> 0 ) {
+                    valueToUse = specialParam.getString();
+                    doFilter = false;
                 }
-                RequestParameter[] pp = parameters.get(prefix + param);
-                // check without prefix for exact match, like everything staring with sling:post:
-                if ( pp == null ) {
-                    pp = parameters.get(param);
-                }
-                if (pp!=null) {
-                    for(RequestParameter p : pp) {
-                        valueToUse = p.getString();
-                        if(valueToUse != null && valueToUse.length() > 0) {
-                            break;
+            }
+
+            if ( valueToUse == null ) {
+                for(String param : parameterNames) {
+                    if(valueToUse != null) {
+                        break;
+                    }
+                    final RequestParameter[] pp = parameters.get(prefix + param);
+                    if (pp!=null) {
+                        for(RequestParameter p : pp) {
+                            valueToUse = p.getString();
+                            if(valueToUse != null && valueToUse.length() > 0)
{
+                                break;
+                            }
+                            valueToUse = null;
                         }
-                        valueToUse = null;
                     }
                 }
             }
         }
         String result;
-        if(valueToUse != null) {
-            // filter value so that it works as a node name
-            result = filter.filter(valueToUse);
+        if (valueToUse != null) {
+            // should we filter?
+            if ( doFilter ) {
+                // filter value so that it works as a node name
+                result = filter.filter(valueToUse);
+            } else {
+                result = valueToUse;
+            }
         } else {
             // default value if none provided
             result = nextCounter() + "_" + System.currentTimeMillis();
         }
 
-        // max length
-        if(result.length() > maxLength) {
-            result = result.substring(0,maxLength);
+        if ( doFilter ) {
+            // max length
+            if (result.length() > maxLength) {
+                result = result.substring(0,maxLength);
+            }
         }
 
         return result;



Mime
View raw message