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 2008/03/27 15:34:00 UTC

svn commit: r641828 - in /incubator/sling/trunk: jcr/default-rtp/ jcr/default-rtp/src/ jcr/default-rtp/src/main/ jcr/default-rtp/src/main/java/ jcr/default-rtp/src/main/java/org/ jcr/default-rtp/src/main/java/org/apache/ jcr/default-rtp/src/main/java/o...

Author: bdelacretaz
Date: Thu Mar 27 07:33:54 2008
New Revision: 641828

URL: http://svn.apache.org/viewvc?rev=641828&view=rev
Log:
SLING-340 - JcrDefaultResourceTypeProvider and default implementation (jcr/default-rtp) added

Added:
    incubator/sling/trunk/jcr/default-rtp/   (with props)
    incubator/sling/trunk/jcr/default-rtp/pom.xml   (with props)
    incubator/sling/trunk/jcr/default-rtp/src/
    incubator/sling/trunk/jcr/default-rtp/src/main/
    incubator/sling/trunk/jcr/default-rtp/src/main/java/
    incubator/sling/trunk/jcr/default-rtp/src/main/java/org/
    incubator/sling/trunk/jcr/default-rtp/src/main/java/org/apache/
    incubator/sling/trunk/jcr/default-rtp/src/main/java/org/apache/sling/
    incubator/sling/trunk/jcr/default-rtp/src/main/java/org/apache/sling/jcr/
    incubator/sling/trunk/jcr/default-rtp/src/main/java/org/apache/sling/jcr/rtp/
    incubator/sling/trunk/jcr/default-rtp/src/main/java/org/apache/sling/jcr/rtp/DefaultResourceTypeProvider.java   (with props)
    incubator/sling/trunk/jcr/default-rtp/src/main/resources/
    incubator/sling/trunk/jcr/default-rtp/src/main/resources/OSGI-INF/
    incubator/sling/trunk/jcr/default-rtp/src/main/resources/OSGI-INF/metatype/
    incubator/sling/trunk/jcr/default-rtp/src/main/resources/OSGI-INF/metatype/metatype.properties   (with props)
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrDefaultResourceTypeProvider.java   (with props)
    incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PathBasedResourceTypeTest.java   (with props)
Modified:
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/MockResourceResolver.java
    incubator/sling/trunk/launchpad/app/pom.xml
    incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java

Propchange: incubator/sling/trunk/jcr/default-rtp/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Mar 27 07:33:54 2008
@@ -0,0 +1,9 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders

Added: incubator/sling/trunk/jcr/default-rtp/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/default-rtp/pom.xml?rev=641828&view=auto
==============================================================================
--- incubator/sling/trunk/jcr/default-rtp/pom.xml (added)
+++ incubator/sling/trunk/jcr/default-rtp/pom.xml Thu Mar 27 07:33:54 2008
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>1-incubator-SNAPSHOT</version>
+        <relativePath>../../parent/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.sling.jcr.default.rtp</artifactId>
+    <packaging>bundle</packaging>
+    <version>2.0.0-incubator-SNAPSHOT</version>
+
+    <name>Sling - Default Resource Type Provider</name>
+    <description>
+        Provides a configurable path-based default resource type
+        for Resources which do not have an explicit one.
+        RMI
+    </description>
+
+    <scm>
+        <connection>
+            scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/jcr/default-rtp
+        </connection>
+        <developerConnection>
+            scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/jcr/default-rtp
+        </developerConnection>
+        <url>
+            http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/default-rtp
+        </url>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-Category>
+                            sling,jcr
+                        </Bundle-Category>
+                        <!-- No Export-Package -->
+                        <Private-Package>
+                            org.apache.sling.jcr.rtp
+                        </Private-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.jcr.resource</artifactId>
+            <version>2.0.0-incubator-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+
+        <!-- OSGi Libraries -->
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+    </dependencies>
+</project>

Propchange: incubator/sling/trunk/jcr/default-rtp/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/jcr/default-rtp/src/main/java/org/apache/sling/jcr/rtp/DefaultResourceTypeProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/default-rtp/src/main/java/org/apache/sling/jcr/rtp/DefaultResourceTypeProvider.java?rev=641828&view=auto
==============================================================================
--- incubator/sling/trunk/jcr/default-rtp/src/main/java/org/apache/sling/jcr/rtp/DefaultResourceTypeProvider.java (added)
+++ incubator/sling/trunk/jcr/default-rtp/src/main/java/org/apache/sling/jcr/rtp/DefaultResourceTypeProvider.java Thu Mar 27 07:33:54 2008
@@ -0,0 +1,132 @@
+/*
+ * 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.jcr.rtp;
+
+import java.util.Dictionary;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.sling.jcr.resource.JcrDefaultResourceTypeProvider;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *  Default resource type provider that uses a component of the node path
+ *  to define the default resource type.
+ *  
+ *  A number of mappings can be configured, for example "/content:2" would 
+ *  cause a node at /content/foo/bar to get the "foo" resource type if it 
+ *  doesn't have a default one: "/content" is used to select nodes to which the
+ *  mapping applies, and "2" is the (1-based) index of the path component to
+ *  use as the resource type.
+ *  
+ * @scr.component immediate="true" label="%defaultRtp.name"
+ *                description="%defaultRtp.description"
+ * @scr.property name="service.vendor" value="The Apache Software Foundation"
+ * @scr.property name="service.description" value="Sling Default Resource Type Provider"
+ * @scr.service
+ */
+public class DefaultResourceTypeProvider implements JcrDefaultResourceTypeProvider {
+
+    /**
+     *  Name of the configurable property name that defines mappings. The default values
+     *  specify the use of path component 2 for the /content path, and add a similar
+     *  definition for the /sling-test-pbrt path that is used in integration testing.     
+     *  
+     * @scr.property 
+     *  values.1="/content:2" 
+     *  values.2="/sling-test-pbrt:2"
+     */
+    private static final String PROP_PATH_MAPPING = "path.mapping";
+    
+    private static final Logger log = LoggerFactory.getLogger(DefaultResourceTypeProvider.class);
+    
+    /** Map a path prefix to a (1-based) index in the path components */
+    static class Mapping {
+        String path;
+        int resourceTypeIndex;
+        
+        Mapping(String definition) {
+            final String [] parts = definition.split(":");
+            if(parts.length != 2) {
+                log.debug("Invalid Mapping definition ignored: {}", definition);
+            } else {
+                path = parts[0];
+                try {
+                    resourceTypeIndex = Integer.parseInt(parts[1]);
+                } catch(Exception e) {
+                    log.warn("Invalid path index in Mapping {}", definition);
+                }
+            }
+        }
+        
+        @Override
+        public String toString() {
+           return "Mapping: path=" + path + ", resource type index=" + resourceTypeIndex; 
+        }
+    }
+    
+    private Mapping [] mappings;
+    
+    /** Return a resource type for given node, if we have a mapping that applies */
+    public String getResourceTypeForNode(Node node) throws RepositoryException {
+        String result = null;
+        
+        if(mappings!=null) {
+            final String nt = node.getPrimaryNodeType().getName();
+            final String path = node.getPath();
+            for(Mapping m : mappings) {
+                if(path.startsWith(m.path) && "nt:unstructured".equals(nt)) {
+                    final String [] paths = node.getPath().split("/");
+                    if(paths.length >= m.resourceTypeIndex+1) {
+                        result = paths[m.resourceTypeIndex];
+                        log.debug("Default resource type {} used for Node {}", 
+                                result, path);
+                        break;
+                    }
+                }
+            }
+        }
+        
+        if(result==null) {
+            log.debug("No Mapping applies to node {}, no resource type provided", node.getPath());
+        }
+        
+        return result;
+    }
+    
+    /** Activates this component, called by SCR before registering as a service */
+    protected void activate(ComponentContext componentContext) {
+        final Dictionary<?, ?> properties = componentContext.getProperties();
+        final String[] mappingList = (String[]) properties.get(PROP_PATH_MAPPING);
+        
+        if(mappingList== null || mappingList.length == 0) {
+            mappings = null;
+        } else {
+            mappings = new Mapping[mappingList.length];
+            for(int i=0; i < mappingList.length; i++) {
+                mappings[i] = new Mapping(mappingList[i]);
+                log.debug("Added {}", mappings[i]);
+            }
+        }
+    }
+
+}

Propchange: incubator/sling/trunk/jcr/default-rtp/src/main/java/org/apache/sling/jcr/rtp/DefaultResourceTypeProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/jcr/default-rtp/src/main/java/org/apache/sling/jcr/rtp/DefaultResourceTypeProvider.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/jcr/default-rtp/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/default-rtp/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=641828&view=auto
==============================================================================
--- incubator/sling/trunk/jcr/default-rtp/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ incubator/sling/trunk/jcr/default-rtp/src/main/resources/OSGI-INF/metatype/metatype.properties Thu Mar 27 07:33:54 2008
@@ -0,0 +1,33 @@
+#
+#  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.
+#
+
+
+#
+# This file contains localization strings for configuration labels and
+# descriptions as used in the metatype.xml descriptor generated by the
+# the Sling SCR plugin
+
+defaultRtp.name = Sling default resource type provider
+defaultRtp.description = Defines the resource type for Nodes which do not \
+have an explicit sling:resourceType property
+
+path.mapping.name = Path mappings
+path.mapping.description = List of paths for which path-based default resource \
+types are active. For example, /content:2 means "use the second path component \
+as the default resource type for nodes stored under /content".
\ No newline at end of file

Propchange: incubator/sling/trunk/jcr/default-rtp/src/main/resources/OSGI-INF/metatype/metatype.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrDefaultResourceTypeProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrDefaultResourceTypeProvider.java?rev=641828&view=auto
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrDefaultResourceTypeProvider.java (added)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrDefaultResourceTypeProvider.java Thu Mar 27 07:33:54 2008
@@ -0,0 +1,33 @@
+/*
+ * 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.jcr.resource;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/** Provide a resourceType for JCR Nodes which do not have
+ *  a sling:resourceType property.
+ */ 
+public interface JcrDefaultResourceTypeProvider {
+    
+    /** Return the default resource type to use for Node n, when
+     *  n has not sling:resourceType property  
+     */
+    String getResourceTypeForNode(Node n) throws RepositoryException;
+}

Propchange: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrDefaultResourceTypeProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrDefaultResourceTypeProvider.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java?rev=641828&r1=641827&r2=641828&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java Thu Mar 27 07:33:54 2008
@@ -181,7 +181,7 @@
         try {
             QueryResult res = JcrResourceUtil.query(getSession(), query,
                 language);
-            return new JcrNodeResourceIterator(this, res.getNodes());
+            return new JcrNodeResourceIterator(this, res.getNodes(), rootProvider.getDefaultResourceTypeProvider());
         } catch (javax.jcr.query.InvalidQueryException iqe) {
             throw new QuerySyntaxException(iqe.getMessage(), query, language,
                 iqe);

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java?rev=641828&r1=641827&r2=641828&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java Thu Mar 27 07:33:54 2008
@@ -35,6 +35,7 @@
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.jcr.resource.JcrDefaultResourceTypeProvider;
 import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
 import org.apache.sling.jcr.resource.internal.helper.Mapping;
 import org.apache.sling.jcr.resource.internal.helper.ResourceProviderEntry;
@@ -122,6 +123,12 @@
      * @scr.reference cardinality="0..1" policy="dynamic"
      */
     private EventAdmin eventAdmin;
+    
+    /** The (optional) default resource type provider
+     * 
+     * @scr.reference cardinality="0..1" policy="dynamic"
+     */
+    private JcrDefaultResourceTypeProvider defaultResourceTypeProvider;
 
     // list of ResourceProvider services bound before activation of the
     // component
@@ -163,7 +170,7 @@
      */
     public ResourceResolver getResourceResolver(Session session) {
         JcrResourceProviderEntry sessionRoot = new JcrResourceProviderEntry(
-            session, rootProviderEntry.getEntries());
+            session, rootProviderEntry.getEntries(), defaultResourceTypeProvider);
         return new JcrResourceResolver(sessionRoot, this);
     }
 

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java?rev=641828&r1=641827&r2=641828&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java Thu Mar 27 07:33:54 2008
@@ -30,6 +30,7 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.jcr.resource.JcrDefaultResourceTypeProvider;
 import org.apache.sling.jcr.resource.JcrResourceUtil;
 
 abstract class JcrItemResource extends SlingAdaptable implements Resource {
@@ -44,11 +45,15 @@
     private final ResourceMetadata metadata;
 
     private String resourceSuperType;
-
-    protected JcrItemResource(ResourceResolver resourceResolver, String path) {
+    
+    protected final JcrDefaultResourceTypeProvider defaultResourceTypeProvider;
+    
+    protected JcrItemResource(ResourceResolver resourceResolver, 
+            String path, JcrDefaultResourceTypeProvider defaultResourceTypeProvider) {
 
         this.resourceResolver = resourceResolver;
         this.path = path;
+        this.defaultResourceTypeProvider = defaultResourceTypeProvider;
 
         metadata = new ResourceMetadata();
         metadata.setResolutionPath(path);
@@ -108,6 +113,10 @@
 
         if (node.hasProperty(SLING_RESOURCE_TYPE_PROPERTY)) {
             result = node.getProperty(SLING_RESOURCE_TYPE_PROPERTY).getValue().getString();
+        }
+        
+        if (result == null && defaultResourceTypeProvider != null) {
+            result = defaultResourceTypeProvider.getResourceTypeForNode(node);
         }
 
         if (result == null || result.length() == 0) {

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java?rev=641828&r1=641827&r2=641828&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java Thu Mar 27 07:33:54 2008
@@ -39,6 +39,7 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.jcr.resource.JcrDefaultResourceTypeProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -52,9 +53,9 @@
 
     private final String resourceType;
 
-    JcrNodeResource(ResourceResolver resourceResolver, Node node)
+    JcrNodeResource(ResourceResolver resourceResolver, Node node, JcrDefaultResourceTypeProvider defaultResourceTypeProvider)
             throws RepositoryException {
-        super(resourceResolver, node.getPath());
+        super(resourceResolver, node.getPath(), defaultResourceTypeProvider);
         this.node = node;
         resourceType = getResourceTypeForNode(node);
 
@@ -170,7 +171,7 @@
         try {
             if (getNode().hasNodes()) {
                 return new JcrNodeResourceIterator(getResourceResolver(),
-                    getNode().getNodes());
+                    getNode().getNodes(), defaultResourceTypeProvider);
             }
         } catch (RepositoryException re) {
             log.error("listChildren: Cannot get children of " + this, re);

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java?rev=641828&r1=641827&r2=641828&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java Thu Mar 27 07:33:54 2008
@@ -25,6 +25,7 @@
 
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.jcr.resource.JcrDefaultResourceTypeProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -47,15 +48,18 @@
 
     /** The prefetched next iterator entry, null at the end of iterating */
     private Resource nextResult;
+    
+    private final JcrDefaultResourceTypeProvider defaultResourceTypeProvider;
 
     /**
      * Creates an instance using the given resource manager and the nodes
      * provided as a node iterator.
      */
     public JcrNodeResourceIterator(ResourceResolver resourceResolver,
-            NodeIterator nodes) {
+            NodeIterator nodes, JcrDefaultResourceTypeProvider defaultResourceTypeProvider) {
         this.resourceResolver = resourceResolver;
         this.nodes = nodes;
+        this.defaultResourceTypeProvider = defaultResourceTypeProvider;
         this.nextResult = seek();
     }
 
@@ -84,7 +88,7 @@
     private Resource seek() {
         while (nodes.hasNext()) {
             try {
-                return new JcrNodeResource(resourceResolver, nodes.nextNode());
+                return new JcrNodeResource(resourceResolver, nodes.nextNode(), defaultResourceTypeProvider);
             } catch (Throwable t) {
                 log.error(
                     "seek: Problem creating Resource for next node, skipping",

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java?rev=641828&r1=641827&r2=641828&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java Thu Mar 27 07:33:54 2008
@@ -32,6 +32,7 @@
 
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.jcr.resource.JcrDefaultResourceTypeProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,8 +46,8 @@
     private final String resourceType;
 
     public JcrPropertyResource(ResourceResolver resourceResolver, String path,
-            Property property) throws RepositoryException {
-        super(resourceResolver, path);
+            Property property, JcrDefaultResourceTypeProvider defaultResourceTypeProvider) throws RepositoryException {
+        super(resourceResolver, path, defaultResourceTypeProvider);
         this.property = property;
         this.resourceType = getResourceTypeForNode(property.getParent())
             + "/" + property.getName();

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java?rev=641828&r1=641827&r2=641828&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java Thu Mar 27 07:33:54 2008
@@ -31,6 +31,7 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.jcr.resource.JcrDefaultResourceTypeProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,9 +47,11 @@
     private final Logger log = LoggerFactory.getLogger(getClass());
 
     private final Session session;
+    private final JcrDefaultResourceTypeProvider defaultResourceTypeProvider;
 
-    public JcrResourceProvider(Session session) {
+    public JcrResourceProvider(Session session, JcrDefaultResourceTypeProvider defaultResourceTypeProvider) {
         this.session = session;
+        this.defaultResourceTypeProvider = defaultResourceTypeProvider;
     }
 
     // ---------- ResourceProvider interface ----------------------------------
@@ -127,14 +130,14 @@
                 log.debug(
                     "createResource: Found JCR Node Resource at path '{}'",
                     path);
-                return new JcrNodeResource(resourceResolver, (Node) item);
+                return new JcrNodeResource(resourceResolver, (Node) item, defaultResourceTypeProvider);
             }
 
             log.debug(
                 "createResource: Found JCR Property Resource at path '{}'",
                 path);
             return new JcrPropertyResource(resourceResolver, path,
-                (Property) item);
+                (Property) item, defaultResourceTypeProvider);
         }
 
         log.debug("createResource: No JCR Item exists at path '{}'", path);

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java?rev=641828&r1=641827&r2=641828&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java Thu Mar 27 07:33:54 2008
@@ -20,20 +20,28 @@
 
 import javax.jcr.Session;
 
+import org.apache.sling.jcr.resource.JcrDefaultResourceTypeProvider;
 import org.apache.sling.jcr.resource.internal.helper.ResourceProviderEntry;
 
 public class JcrResourceProviderEntry extends ResourceProviderEntry {
 
     private final Session session;
+    
+    private final JcrDefaultResourceTypeProvider defaultResourceTypeProvider;
 
     public JcrResourceProviderEntry(Session session,
-            ResourceProviderEntry[] entries) {
-        super("/", new JcrResourceProvider(session), entries);
+            ResourceProviderEntry[] entries, JcrDefaultResourceTypeProvider defaultResourceTypeProvider) {
+        super("/", new JcrResourceProvider(session, defaultResourceTypeProvider), entries);
 
         this.session = session;
+        this.defaultResourceTypeProvider = defaultResourceTypeProvider;
     }
 
     public Session getSession() {
         return session;
+    }
+    
+    public JcrDefaultResourceTypeProvider getDefaultResourceTypeProvider() {
+        return defaultResourceTypeProvider;
     }
 }

Modified: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java?rev=641828&r1=641827&r2=641828&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java (original)
+++ incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java Thu Mar 27 07:33:54 2008
@@ -35,7 +35,7 @@
 
     public void testEmpty() {
         NodeIterator ni = new MockNodeIterator(null);
-        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni);
+        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni, null);
 
         assertFalse(ri.hasNext());
 
@@ -51,7 +51,7 @@
         String path = "/parent/path/node";
         Node node = new MockNode(path);
         NodeIterator ni = new MockNodeIterator(new Node[] { node });
-        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni);
+        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni, null);
 
         assertTrue(ri.hasNext());
         Resource res = ri.next();
@@ -76,7 +76,7 @@
             nodes[i] = new MockNode(pathBase + i, "some:type" + i);
         }
         NodeIterator ni = new MockNodeIterator(nodes);
-        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni);
+        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni, null);
 
         for (int i=0; i < nodes.length; i++) {
             assertTrue(ri.hasNext());

Modified: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java?rev=641828&r1=641827&r2=641828&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java (original)
+++ incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java Thu Mar 27 07:33:54 2008
@@ -41,7 +41,7 @@
         getSession().save();
 
         file = rootNode.getNode(name);
-        JcrNodeResource jnr = new JcrNodeResource(null, file);
+        JcrNodeResource jnr = new JcrNodeResource(null, file, null);
 
         assertEquals(file.getPath(), jnr.getPath());
 
@@ -59,7 +59,7 @@
         getSession().save();
 
         file = rootNode.getNode(name);
-        JcrNodeResource jnr = new JcrNodeResource(null, file);
+        JcrNodeResource jnr = new JcrNodeResource(null, file, null);
 
         assertEquals(file.getPath(), jnr.getPath());
 
@@ -75,7 +75,7 @@
         getSession().save();
 
         res = rootNode.getNode(name);
-        JcrNodeResource jnr = new JcrNodeResource(null, res);
+        JcrNodeResource jnr = new JcrNodeResource(null, res, null);
 
         assertEquals(res.getPath(), jnr.getPath());
 
@@ -91,7 +91,7 @@
         getSession().save();
 
         res = rootNode.getNode(name);
-        JcrNodeResource jnr = new JcrNodeResource(null, res);
+        JcrNodeResource jnr = new JcrNodeResource(null, res, null);
 
         assertEquals(res.getPath(), jnr.getPath());
 
@@ -104,14 +104,14 @@
         Node node = rootNode.addNode(name, JcrConstants.NT_UNSTRUCTURED);
         getSession().save();
 
-        JcrNodeResource jnr = new JcrNodeResource(null, node);
+        JcrNodeResource jnr = new JcrNodeResource(null, node, null);
         assertEquals(JcrConstants.NT_UNSTRUCTURED, jnr.getResourceType());
 
         String typeName = "some/resource/type";
         node.setProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, typeName);
         getSession().save();
 
-        jnr = new JcrNodeResource(null, node);
+        jnr = new JcrNodeResource(null, node, null);
         assertEquals(typeName, jnr.getResourceType());
     }
 
@@ -123,7 +123,7 @@
         node.setProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, typeName);
         getSession().save();
 
-        Resource jnr = new JcrNodeResource(resourceResolver, node);
+        Resource jnr = new JcrNodeResource(resourceResolver, node, null);
         assertEquals(typeName, jnr.getResourceType());
 
         // default super type is super type of node type
@@ -134,7 +134,7 @@
         typeNode.setProperty(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, superTypeName);
         getSession().save();
 
-        jnr = new JcrNodeResource(resourceResolver, node);
+        jnr = new JcrNodeResource(resourceResolver, node, null);
         assertEquals(typeName, jnr.getResourceType());
         assertEquals(superTypeName, jnr.getResourceSuperType());
 
@@ -143,7 +143,7 @@
         node.setProperty(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, otherSuperTypeName);
         getSession().save();
 
-        jnr = new JcrNodeResource(resourceResolver, node);
+        jnr = new JcrNodeResource(resourceResolver, node, null);
         assertEquals(typeName, jnr.getResourceType());
         assertEquals(otherSuperTypeName, jnr.getResourceSuperType());
 
@@ -151,7 +151,7 @@
         node.getProperty(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY).remove();
         getSession().save();
 
-        jnr = new JcrNodeResource(resourceResolver, node);
+        jnr = new JcrNodeResource(resourceResolver, node, null);
         assertEquals(typeName, jnr.getResourceType());
         assertEquals(superTypeName, jnr.getResourceSuperType());
     }

Modified: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/MockResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/MockResourceResolver.java?rev=641828&r1=641827&r2=641828&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/MockResourceResolver.java (original)
+++ incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/MockResourceResolver.java Thu Mar 27 07:33:54 2008
@@ -48,10 +48,10 @@
             Item item = session.getItem(path);
             
             if (item.isNode()) {
-                return new JcrNodeResource(this, (Node) item);
+                return new JcrNodeResource(this, (Node) item, null);
             }
             
-            return new JcrPropertyResource(this, path, (Property) item);
+            return new JcrPropertyResource(this, path, (Property) item, null);
         } catch (Exception e) {
             // don't care
         }

Modified: incubator/sling/trunk/launchpad/app/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/app/pom.xml?rev=641828&r1=641827&r2=641828&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/app/pom.xml (original)
+++ incubator/sling/trunk/launchpad/app/pom.xml Thu Mar 27 07:33:54 2008
@@ -291,6 +291,14 @@
             <version>2.0.0-incubator-SNAPSHOT</version>
             <optional>true</optional>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>
+                org.apache.sling.jcr.default.rtp
+            </artifactId>
+            <version>2.0.0-incubator-SNAPSHOT</version>
+            <optional>true</optional>
+        </dependency>
 <!--
         <dependency>
             <groupId>org.apache.sling</groupId>

Modified: incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java?rev=641828&r1=641827&r2=641828&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java (original)
+++ incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java Thu Mar 27 07:33:54 2008
@@ -65,6 +65,9 @@
 
     private static Boolean slingStartupOk;
 
+    /** URLs stored here are deleted in tearDown */
+    protected final List<String> urlsToDelete = new LinkedList<String>();
+
     /** Class that creates a test node under the given parentPath, and
      *  stores useful values for testing. Created for JspScriptingTest,
      *  older test classes do not use it, but it might simplify them.
@@ -121,6 +124,15 @@
         testClient = new UslingIntegrationTestClient(httpClient);
 
         waitForSlingStartup();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        
+        for(String url : urlsToDelete) {
+            testClient.delete(url);
+        }
     }
 
     /** On the server side, initialization of Sling bundles is done

Added: incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PathBasedResourceTypeTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PathBasedResourceTypeTest.java?rev=641828&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PathBasedResourceTypeTest.java (added)
+++ incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PathBasedResourceTypeTest.java Thu Mar 27 07:33:54 2008
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Test the SLING-340 way of deriving the resource type from
+ *  the content path.
+ */
+
+public class PathBasedResourceTypeTest extends HttpTestBase {
+    
+    public static final String testPath = "sling-integration-test-" + System.currentTimeMillis();
+    public static final String contentPath = "/sling-test-pbrt/" + testPath;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        urlsToDelete.add(WEBDAV_BASE_URL + contentPath);
+    }
+
+    public void testDefaultResourceType() throws IOException {
+        final TestNode tn = new TestNode(HTTP_BASE_URL + contentPath, null);
+        
+        // without script -> default rendering
+        String content = getContent(tn.nodeUrl + ".html", CONTENT_TYPE_HTML);
+        assertTrue("Content contains default rendering",content.contains("Node dumped by DefaultHtmlRenderer"));
+        
+        // check default resource type
+        final String scriptPath = "/apps/" + testPath;
+        testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
+        urlsToDelete.add(WEBDAV_BASE_URL + scriptPath);
+        final String urlsToDelete = uploadTestScript(scriptPath, "rendering-test.esp", "html.esp");
+        try {
+            content = getContent(tn.nodeUrl + ".html", CONTENT_TYPE_HTML);
+            assertTrue("Test script marker found in content",content.contains("ESP template"));
+        } finally {
+            testClient.delete(urlsToDelete);
+        }
+    }
+    
+    public void testExplicitResourceType() throws IOException {
+        
+        final String resourceType = getClass().getSimpleName();
+        final Map<String, String> properties = new HashMap<String, String>();
+        properties.put(SLING_RESOURCE_TYPE, resourceType);
+        final TestNode tn = new TestNode(HTTP_BASE_URL + contentPath, properties);
+        
+        urlsToDelete.add(uploadTestScript(tn.scriptPath, "rendering-test-2.esp", "html.esp"));
+        final String content = getContent(tn.nodeUrl + ".html", CONTENT_TYPE_HTML);
+        assertTrue("Test script marker found in content",content.contains("Template #2 for ESP tests"));
+    }
+}

Propchange: incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PathBasedResourceTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PathBasedResourceTypeTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL