incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1365645 - in /sling/trunk: bundles/api/src/main/java/org/apache/sling/api/resource/ bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/imp...
Date Wed, 25 Jul 2012 15:57:06 GMT
Author: cziegeler
Date: Wed Jul 25 15:57:05 2012
New Revision: 1365645

URL: http://svn.apache.org/viewvc?rev=1365645&view=rev
Log:
SLING-2530 : Implement CRUD based on resources

Added:
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/crud/
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/crud/CrudTest.java
  (with props)
    sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/crud/
    sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/crud/crud-test.jsp
  (with props)
Modified:
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntry.java

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java?rev=1365645&r1=1365644&r2=1365645&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
(original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
Wed Jul 25 15:57:05 2012
@@ -506,7 +506,7 @@ public interface ResourceResolver extend
      * Delete the resource
      * @param resource The resource to delete
      *
-     * @throws PersistenceException, NullPointerException
+     * @throws PersistenceException, NullPointerException, UnsupportedOperationException
      */
     void delete(Resource resource)
     throws PersistenceException;
@@ -518,7 +518,7 @@ public interface ResourceResolver extend
      * @param properties Optional properties for the resource
      * @return The new resource
      *
-     * @throws PersistenceException, NullPointerException
+     * @throws PersistenceException, NullPointerException, UnsupportedOperationException
      */
     Resource addChild(Resource parent, String name, ValueMap properties)
     throws PersistenceException;

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java?rev=1365645&r1=1365644&r2=1365645&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
Wed Jul 25 15:57:05 2012
@@ -1007,6 +1007,9 @@ public class ResourceResolverImpl extend
         final ModifyingResourceProvider mrp = this.factory.getRootProviderEntry().getModifyingProvider(this.context,
                         this,
                         path);
+        if ( mrp == null ) {
+            throw new UnsupportedOperationException("delete at '" + path + "'");
+        }
         mrp.delete(this, path);
     }
 
@@ -1019,10 +1022,18 @@ public class ResourceResolverImpl extend
         if ( name == null ) {
             throw new NullPointerException("name");
         }
-        final String path = parent.getPath() + '/' + name;
+        final String path;
+        if ( parent.getPath().equals("/") ) {
+            path = parent.getPath() + name;
+        } else {
+            path = parent.getPath() + "/" + name;
+        }
         final ModifyingResourceProvider mrp = this.factory.getRootProviderEntry().getModifyingProvider(this.context,
                         this,
                         path);
+        if ( mrp == null ) {
+            throw new UnsupportedOperationException("addChild '" + name + "' at " + parent.getPath());
+        }
         return mrp.create(this, path, properties);
     }
 

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntry.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntry.java?rev=1365645&r1=1365644&r2=1365645&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntry.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntry.java
Wed Jul 25 15:57:05 2012
@@ -347,11 +347,18 @@ public class ResourceProviderEntry imple
                     return (ModifyingResourceProvider) provider;
                 }
                 if ( rp.ownsRoots() ) {
-                    throw new UnsupportedOperationException();
+                    return null;
                 }
             }
         }
-        throw new UnsupportedOperationException();
+        // try this one
+        for(final ProviderHandler rp : this.providers) {
+            final ResourceProvider provider = rp.getResourceProvider(ctx);
+            if ( provider instanceof ModifyingResourceProvider) {
+                return (ModifyingResourceProvider) provider;
+            }
+        }
+        return null;
     }
 
     private static final char SPLIT_SEP = '/';

Added: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/crud/CrudTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/crud/CrudTest.java?rev=1365645&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/crud/CrudTest.java
(added)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/crud/CrudTest.java
Wed Jul 25 15:57:05 2012
@@ -0,0 +1,75 @@
+/*
+ * 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.launchpad.webapp.integrationtest.crud;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.sling.commons.testing.integration.NameValuePairList;
+import org.apache.sling.launchpad.webapp.integrationtest.RenderingTestBase;
+import org.apache.sling.servlets.post.SlingPostConstants;
+
+public class CrudTest extends RenderingTestBase {
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        final String slingResourceType = getClass().getName();
+
+        this.scriptPath = "/apps/" + slingResourceType;
+        this.testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
+
+        // create the test node, under a path that's specific to this class to allow collisions
+        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis()
+ SlingPostConstants.DEFAULT_CREATE_SUFFIX;
+
+        final NameValuePairList list = new NameValuePairList();
+        list.add("sling:resourceType", slingResourceType);
+
+        this.displayUrl = testClient.createNode(url, list, null, true);
+
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        testClient.delete(this.displayUrl);
+        super.tearDown();
+    }
+
+    public void testCreate() throws Exception {
+        final String testScriptPath = this.uploadTestScript("crud/crud-test.jsp", "html.jsp");
+
+        final String name = getClass().getSimpleName() + System.currentTimeMillis();
+        final List<NameValuePair> params = new ArrayList<NameValuePair>();
+        params.add(new NameValuePair("name", name));
+        params.add(new NameValuePair("a", "100"));
+        params.add(new NameValuePair("b", "200"));
+        try {
+            final String content = getContent(displayUrl + ".html", CONTENT_TYPE_PLAIN, params);
+            assertTrue("Content should included created marker: " + content, content.contains("created"));
+
+            final String json = getContent(HTTP_BASE_URL + "/" + name + ".json", CONTENT_TYPE_JSON);
+            assertJavascript("100", json, "out.print(data.a)");
+            assertJavascript("200", json, "out.print(data.b)");
+
+        } finally {
+            testClient.delete(testScriptPath);
+        }
+
+    }
+}

Propchange: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/crud/CrudTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/crud/CrudTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/crud/CrudTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/crud/crud-test.jsp
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/crud/crud-test.jsp?rev=1365645&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/crud/crud-test.jsp
(added)
+++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/crud/crud-test.jsp
Wed Jul 25 15:57:05 2012
@@ -0,0 +1,48 @@
+<%--
+/*
+ * 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.
+ */
+--%>
+<%@page 
+  session="false"
+  contentType="text/plain"
+  import="org.apache.sling.api.resource.Resource,
+          org.apache.sling.api.resource.ResourceResolver,
+          org.apache.sling.api.resource.ValueMap,
+          org.apache.sling.api.wrappers.ValueMapDecorator"
+%><%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0"%><%
+%><sling:defineObjects/><%
+
+    final ResourceResolver resolver = slingRequest.getResourceResolver();
+    final String name = request.getParameter("name");
+
+    try {
+        final ValueMap vm = new ValueMapDecorator(new java.util.HashMap<String, Object>());
+        vm.put("a", request.getParameter("a"));
+        vm.put("b", request.getParameter("b"));
+        
+        final Resource rsrc = resolver.addChild(resolver.getResource("/"), name, vm);
+        
+        resolver.commit();
+        %>Resource created at <%= rsrc.getPath() %><%
+    } catch (final Exception e) {
+        final java.io.StringWriter sw = new java.io.StringWriter();
+        e.printStackTrace(new java.io.PrintWriter(sw));
+        %>Unable to create resource '<%= name %>' : <%= sw %>.<%
+    }
+%>
\ No newline at end of file

Propchange: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/crud/crud-test.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/crud/crud-test.jsp
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/crud/crud-test.jsp
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message