incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r946216 - in /sling/trunk: bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/ bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/ bundles/servlets/post/src/main/java/org/apache/sling/servlets/pos...
Date Wed, 19 May 2010 15:18:11 GMT
Author: justin
Date: Wed May 19 15:18:11 2010
New Revision: 946216

URL: http://svn.apache.org/viewvc?rev=946216&view=rev
Log:
SLING-649 - adding support for @UseDefaultWhenMissing

Modified:
    sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
    sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/RequestProperty.java
    sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java
    sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/SlingDefaultValuesTest.java

Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java?rev=946216&r1=946215&r2=946216&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
(original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
Wed May 19 15:18:11 2010
@@ -340,4 +340,10 @@ public interface SlingPostConstants {
      * ignored.
      */
     public static final String SUFFIX_IGNORE_BLANKS = "@IgnoreBlanks";
+
+    /**
+     * Suffix indicating that the default value should be used when the property
+     * is not defined. By default the default value is only used when
+     */
+    public static final String SUFFIX_USE_DEFAULT_WHEN_MISSING = "@UseDefaultWhenMissing";
 }

Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/RequestProperty.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/RequestProperty.java?rev=946216&r1=946215&r2=946216&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/RequestProperty.java
(original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/RequestProperty.java
Wed May 19 15:18:11 2010
@@ -17,7 +17,6 @@
 package org.apache.sling.servlets.post.impl.helper;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 import org.apache.sling.api.request.RequestParameter;
@@ -62,6 +61,8 @@ public class RequestProperty {
 
     private boolean ignoreBlanks;
 
+    private boolean useDefaultWhenMissing;
+
     public RequestProperty(String path) {
         assert path.startsWith("/");
         this.path = ResourceUtil.normalize(path);
@@ -100,10 +101,14 @@ public class RequestProperty {
     }
 
     public boolean hasValues() {
-        if (ignoreBlanks) {
-            return values != null && getStringValues().length > 0;
+        if (useDefaultWhenMissing && defaultValues != null && defaultValues.length
> 0) {
+            return true;
         } else {
-            return values != null;
+            if (ignoreBlanks) {
+                return (values != null && getStringValues().length > 0);
+            } else {
+                return values != null;
+            }
         }
     }
 
@@ -128,7 +133,7 @@ public class RequestProperty {
     }
 
     public boolean isFileUpload() {
-        return !values[0].isFormField();
+        return values != null && !values[0].isFormField();
     }
 
     /**
@@ -162,7 +167,9 @@ public class RequestProperty {
      */
     public String[] getStringValues() {
         if (stringValues == null) {
-            if (values.length > 1) {
+            if (values == null && useDefaultWhenMissing) {
+                stringValues = new String[] { defaultValues[0].getString() };
+            } else if (values.length > 1) {
                 // TODO: how the default values work for MV props is not very
                 // clear
                 List<String> stringValueList = new ArrayList<String>(values.length);
@@ -274,4 +281,8 @@ public class RequestProperty {
     public void setIgnoreBlanks(boolean b) {
         ignoreBlanks = b;
     }
+
+    public void setUseDefaultWhenMissing(boolean b) {
+        useDefaultWhenMissing = b;
+    }
 }
\ No newline at end of file

Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java?rev=946216&r1=946215&r2=946216&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java
(original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java
Wed May 19 15:18:11 2010
@@ -611,6 +611,18 @@ public class ModifyOperation extends Abs
                 continue;
             }
 
+            if (propPath.endsWith(SlingPostConstants.SUFFIX_USE_DEFAULT_WHEN_MISSING)) {
+                RequestProperty prop = getOrCreateRequestProperty(
+                    reqProperties, propPath,
+                    SlingPostConstants.SUFFIX_USE_DEFAULT_WHEN_MISSING);
+
+                if (e.getValue().length == 1) {
+                    prop.setUseDefaultWhenMissing(true);
+                }
+
+                continue;
+            }
+
             // plain property, create from values
             RequestProperty prop = getOrCreateRequestProperty(reqProperties,
                 propPath, null);

Modified: sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/SlingDefaultValuesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/SlingDefaultValuesTest.java?rev=946216&r1=946215&r2=946216&view=diff
==============================================================================
--- sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/SlingDefaultValuesTest.java
(original)
+++ sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/SlingDefaultValuesTest.java
Wed May 19 15:18:11 2010
@@ -74,6 +74,17 @@ public class SlingDefaultValuesTest exte
         assertJavascript("123", content, "out.println(data.a)");
     }
 
+    public void testWithSpecificDefaultAndNoValueField() throws IOException {
+        final Map <String, String> props = new HashMap <String, String> ();
+        props.put("a@DefaultValue","123");
+        props.put("a@UseDefaultWhenMissing","yes");
+
+        final String createdNodeUrl = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX,
props);
+        final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
+
+        assertJavascript("123", content, "out.println(data.a)");
+    }
+
     public void testWithIgnore() throws IOException {
         final Map <String, String> props = new HashMap <String, String> ();
         props.put("a","");



Mime
View raw message