You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2007/12/07 17:30:20 UTC

svn commit: r602141 - in /incubator/sling/trunk/microsling/microsling-core/src: main/java/org/apache/sling/microsling/helpers/nodenames/ main/java/org/apache/sling/microsling/slingservlets/ test/java/org/apache/sling/microsling/helpers/ test/java/org/a...

Author: bdelacretaz
Date: Fri Dec  7 08:30:18 2007
New Revision: 602141

URL: http://svn.apache.org/viewvc?rev=602141&view=rev
Log:
SLING-128, generate nicer content-based node names when creating nodes

Added:
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/NodeNameFilter.java   (with props)
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/NodeNameGenerator.java   (with props)
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/NodeNameFilterTest.java   (with props)
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/NodeNameGeneratorTest.java   (with props)
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/GeneratedNodeNameTest.java   (with props)
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/MockRequestParameter.java   (with props)
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/MockRequestParameterMap.java   (with props)
Modified:
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/MicrojaxPostServlet.java

Added: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/NodeNameFilter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/NodeNameFilter.java?rev=602141&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/NodeNameFilter.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/NodeNameFilter.java Fri Dec  7 08:30:18 2007
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.microsling.helpers.nodenames;
+
+/** Filter a String so that it can be used as a NodeName */
+public class NodeNameFilter {
+    
+    public static final String ALLOWED_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789_";
+    public static final char REPLACEMENT_CHAR = '_';
+    
+    public String filter(String nodeName) {
+      final StringBuffer sb  = new StringBuffer();
+      char lastAdded = 0;
+      
+      nodeName = nodeName.toLowerCase();
+      for(int i=0; i < nodeName.length(); i++) {
+        final char c = nodeName.charAt(i);
+        char toAdd = c;
+        
+        if(ALLOWED_CHARS.indexOf(c)< 0) {
+          if(lastAdded == REPLACEMENT_CHAR) {
+            // do not add several _ in a row
+            continue;
+          }
+          toAdd = REPLACEMENT_CHAR;
+        }
+        
+        sb.append(toAdd);
+        lastAdded = toAdd;
+      }
+      
+      if(sb.length()==0) {
+        sb.append(REPLACEMENT_CHAR);
+      }
+      
+      return sb.toString();
+    }
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/NodeNameFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/NodeNameFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/NodeNameGenerator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/NodeNameGenerator.java?rev=602141&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/NodeNameGenerator.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/NodeNameGenerator.java Fri Dec  7 08:30:18 2007
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.microsling.helpers.nodenames;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.sling.api.request.RequestParameter;
+import org.apache.sling.api.request.RequestParameterMap;
+
+/** Generates a node name based on a set of well-known request parameters
+ *  like title, description, etc.
+ *  See SLING-128.
+ */
+public class NodeNameGenerator {
+    private List<String> parameterNames;
+    private final NodeNameFilter filter = new NodeNameFilter();
+    public static final int DEFAULT_MAX_NAME_LENGTH = 20;
+    private int maxLength = DEFAULT_MAX_NAME_LENGTH;
+    private int counter;
+    
+    public NodeNameGenerator() {
+        this(null);
+    }
+    
+    public NodeNameGenerator(List<String> parameterNames) {
+        if(parameterNames == null) {
+            this.parameterNames = new LinkedList<String>();
+            this.parameterNames.add("title");
+            this.parameterNames.add("name");
+            this.parameterNames.add("description");
+            this.parameterNames.add("abstract");
+        } else {
+            this.parameterNames = parameterNames;
+        }
+        
+    }
+    
+    /** Get a "nice" node name, if possible, based on given request 
+     *  @param savePrefix if provided, added in front of our parameterNames
+     *  when looking for request parameters
+     */
+    public String getNodeName(RequestParameterMap parameters, String prefix) {
+        String result = null;
+        if(prefix==null) {
+            prefix = "";
+        }
+        
+        // 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;
+                }
+                
+                final RequestParameter[] pp = parameters.get(prefix + param);
+                if(pp!=null) {
+                    for(RequestParameter p : pp) {
+                        valueToUse = p.getString();
+                        if(valueToUse != null && valueToUse.length() > 0) {
+                            break;
+                        } else {
+                            valueToUse = null;
+                        }
+                    }
+                }
+            }
+        }
+        
+        // default value if none provided
+        if(result==null) {
+            result = (++counter) + "_" + System.currentTimeMillis();
+        }
+        
+        // filter value so that it works as a node name
+        if(valueToUse != null) {
+            result = filter.filter(valueToUse);
+        }
+
+        // max length
+        if(result.length() > maxLength) {
+            result = result.substring(0,maxLength);
+        }
+        
+        return result;
+    }
+
+    public int getMaxLength() {
+        return maxLength;
+    }
+
+    public void setMaxLength(int maxLength) {
+        this.maxLength = maxLength;
+    }
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/NodeNameGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/nodenames/NodeNameGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/MicrojaxPostServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/MicrojaxPostServlet.java?rev=602141&r1=602140&r2=602141&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/MicrojaxPostServlet.java (original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/MicrojaxPostServlet.java Fri Dec  7 08:30:18 2007
@@ -37,6 +37,7 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.servlets.SlingAllMethodsServlet;
 import org.apache.sling.api.wrappers.SlingRequestPaths;
+import org.apache.sling.microsling.helpers.nodenames.NodeNameGenerator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -47,6 +48,7 @@
     private static final Logger log = LoggerFactory.getLogger(MicrojaxPostServlet.class);
     private final MicrojaxPropertyValueSetter propertyValueSetter = new MicrojaxPropertyValueSetter();
     private int createNodeCounter;
+    private final NodeNameGenerator nodeNameGenerator = new NodeNameGenerator();
 
     /** Prefix for parameter names which control this POST
      *  (ujax stands for "microjax", RP_ stands for "request param")
@@ -161,7 +163,24 @@
             // If the path ends with a *, create a node under its parent, with
             // a generated node name
             currentPath = currentPath.substring(0, currentPath.length() - starSuffix.length());
-            currentPath += "/" + (createNodeCounter++) + System.currentTimeMillis();
+            currentPath += "/" + nodeNameGenerator.getNodeName(request.getRequestParameterMap(), savePrefix);
+            
+            // if resulting path exists, add a suffix until it's not the case anymore
+            if(s.itemExists(currentPath)) {
+                String newPath = currentPath;
+                for(int suffix = 0; suffix < 100; suffix++) {
+                    newPath = currentPath + "_" + suffix;
+                    if(!s.itemExists(newPath)) {
+                        currentPath = newPath;
+                        break;
+                    }
+                }
+            }
+            
+            if(s.itemExists(currentPath)) {
+                throw new HttpStatusCodeException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                        "Collision in generated node names for path=" + currentPath);
+            }
 
         } else if(s.itemExists(currentPath)) {
             // update to an existing node

Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/NodeNameFilterTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/NodeNameFilterTest.java?rev=602141&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/NodeNameFilterTest.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/NodeNameFilterTest.java Fri Dec  7 08:30:18 2007
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.microsling.helpers.nodenames;
+
+import junit.framework.TestCase;
+
+/** Test the NodeNameFilter */
+public class NodeNameFilterTest extends TestCase {
+    
+    private final NodeNameFilter nnf = new NodeNameFilter();
+    
+    public void testNoChange() {
+        assertEquals("abcde_12345",nnf.filter("abcde_12345"));
+    }
+    
+    public void testLowercase() {
+        assertEquals("abcde_12345",nnf.filter("ABcdE_12345"));
+    }
+    
+    public void testOtherChars() {
+        assertEquals("1_2_3_4_5_",nnf.filter("1/2(3)4 5\n"));
+    }
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/NodeNameFilterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/NodeNameFilterTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/NodeNameGeneratorTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/NodeNameGeneratorTest.java?rev=602141&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/NodeNameGeneratorTest.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/NodeNameGeneratorTest.java Fri Dec  7 08:30:18 2007
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.microsling.helpers.nodenames;
+
+import junit.framework.TestCase;
+
+import org.apache.sling.microsling.mocks.MockRequestParameter;
+import org.apache.sling.microsling.mocks.MockRequestParameterMap;
+
+/** Test the NodeNameGenerator */
+public class NodeNameGeneratorTest extends TestCase {
+    
+    private final NodeNameGenerator nng = new NodeNameGenerator();
+    
+    public void testNoParams() {
+        final String result = nng.getNodeName(null, null);
+        assertTrue("Node name contains a _ at char 1",result.charAt(1) == '_');
+    }
+    
+    public void testTitle() {
+        final MockRequestParameterMap map = new MockRequestParameterMap();
+        map.addValue("title", new MockRequestParameter("Hello there"));
+        final String result = nng.getNodeName(map, null);
+        assertEquals("hello_there", result);
+    }
+    
+    public void testPrefix() {
+        final MockRequestParameterMap map = new MockRequestParameterMap();
+        map.addValue("PR_title", new MockRequestParameter("Hello there"));
+        final String result = nng.getNodeName(map, "PR_");
+        assertEquals("hello_there", result);
+    }
+    
+    public void testTitlePriority() {
+        final MockRequestParameterMap map = new MockRequestParameterMap();
+        map.addValue("title", new MockRequestParameter("Hello there"));
+        map.addValue("description", new MockRequestParameter("desct"));
+        final String result = nng.getNodeName(map, null);
+        assertEquals("hello_there", result);
+    }
+    
+    public void testDescriptionAbstract() {
+        final MockRequestParameterMap map = new MockRequestParameterMap();
+        map.addValue("description", new MockRequestParameter("desc"));
+        map.addValue("abstract", new MockRequestParameter("abs"));
+        final String result = nng.getNodeName(map, null);
+        assertEquals("desc", result);
+    }
+    
+    public void testStandardMaxLength() {
+        final MockRequestParameterMap map = new MockRequestParameterMap();
+        map.addValue("name", new MockRequestParameter("1234567890123456789012345678901234567890"));
+        final String result = nng.getNodeName(map, null);
+        assertEquals(NodeNameGenerator.DEFAULT_MAX_NAME_LENGTH,result.length());
+    }
+    
+    public void testCustomMaxLength() {
+        final NodeNameGenerator custom = new NodeNameGenerator();
+        custom.setMaxLength(2);
+        final MockRequestParameterMap map = new MockRequestParameterMap();
+        map.addValue("name", new MockRequestParameter("1234567890123456789012345678901234567890"));
+        final String result = custom.getNodeName(map, null);
+        assertEquals(2,result.length());
+    }
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/NodeNameGeneratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/helpers/nodenames/NodeNameGeneratorTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/GeneratedNodeNameTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/GeneratedNodeNameTest.java?rev=602141&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/GeneratedNodeNameTest.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/GeneratedNodeNameTest.java Fri Dec  7 08:30:18 2007
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.microsling.integration;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Test the generation of node names for POST requests to URLS
+ *  ending in / *
+ */
+public class GeneratedNodeNameTest extends MicroslingHttpTestBase {
+    
+    private final String postUrl = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + "/*";
+
+    public void testTitle() throws IOException {
+        final Map<String,String> props = new HashMap<String,String>();
+        props.put("title", "Hello There");
+        final String location = testClient.createNode(postUrl, props);
+        final String expect = "hello_there";
+        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");
+        props.put("title", "not this one");
+        final String location = testClient.createNode(postUrl, props);
+        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)));
+    }
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/GeneratedNodeNameTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/GeneratedNodeNameTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/MockRequestParameter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/MockRequestParameter.java?rev=602141&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/MockRequestParameter.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/MockRequestParameter.java Fri Dec  7 08:30:18 2007
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.microsling.mocks;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.sling.api.request.RequestParameter;
+
+public class MockRequestParameter implements RequestParameter {
+
+    private final String value;
+    
+    public MockRequestParameter(String value) {
+        this.value = value;
+    }
+    
+    public byte[] get() {
+        throw new Error("Not implemented in MockRequestParameter");
+    }
+
+    public String getContentType() {
+        throw new Error("Not implemented in MockRequestParameter");
+    }
+
+    public String getFileName() {
+        throw new Error("Not implemented in MockRequestParameter");
+    }
+
+    public InputStream getInputStream() throws IOException {
+        throw new Error("Not implemented in MockRequestParameter");
+    }
+
+    public long getSize() {
+        throw new Error("Not implemented in MockRequestParameter");
+    }
+
+    public String getString() {
+        return value;
+    }
+
+    public String getString(String encoding)
+            throws UnsupportedEncodingException {
+        throw new Error("Not implemented in MockRequestParameter");
+    }
+
+    public boolean isFormField() {
+        throw new Error("Not implemented in MockRequestParameter");
+    }
+
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/MockRequestParameter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/MockRequestParameter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/MockRequestParameterMap.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/MockRequestParameterMap.java?rev=602141&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/MockRequestParameterMap.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/MockRequestParameterMap.java Fri Dec  7 08:30:18 2007
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.microsling.mocks;
+
+import java.util.HashMap;
+
+import org.apache.sling.api.request.RequestParameter;
+import org.apache.sling.api.request.RequestParameterMap;
+
+public class MockRequestParameterMap 
+    extends HashMap<String, RequestParameter[]> 
+    implements RequestParameterMap {
+
+    public RequestParameter[] getValues(String name) {
+        return get(name);
+    }
+
+    public RequestParameter getValue(String name) {
+        RequestParameter[] values = get(name);
+        return (values != null && values.length > 0) ? values[0] : null;
+    }
+    
+    public void addValue(String name,RequestParameter value) {
+        put(name, new RequestParameter[] { value });
+    }
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/MockRequestParameterMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/mocks/MockRequestParameterMap.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL