You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2007/11/18 00:27:58 UTC

svn commit: r596022 - in /incubator/sling/trunk/microsling/microsling-core/src: main/java/org/apache/sling/microsling/resource/ main/webapp/ test/java/org/apache/sling/microsling/integration/ test/java/org/apache/sling/microsling/resource/

Author: fmeschbe
Date: Sat Nov 17 15:27:57 2007
New Revision: 596022

URL: http://svn.apache.org/viewvc?rev=596022&view=rev
Log:
SLING-106 Change name of resource type property to sling:resourceType to make it compatible
with real Sling. Additionally enhance the resource resolver to verify the correct mapping
of the sling namespace.

Modified:
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java
    incubator/sling/trunk/microsling/microsling-core/src/main/webapp/content-creation-forms.html
    incubator/sling/trunk/microsling/microsling-core/src/main/webapp/velocity-scripts.html
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/MicroslingResourceResolverTest.java

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java?rev=596022&r1=596021&r2=596022&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java (original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java Sat Nov 17 15:27:57 2007
@@ -47,10 +47,8 @@
     private Object object;
     private final ResourceMetadata metadata;
 
-    /** JCR Property that defines the resource type of this node
-     *  (TODO: use a sling:namespaced property name)
-     */
-    public static final String SLING_RESOURCE_TYPE_PROPERTY = "slingResourceType";
+    /** JCR Property that defines the resource type of this node */
+    public static final String SLING_RESOURCE_TYPE_PROPERTY = "sling:resourceType";
 
     /** The relative path name of the data property of an nt:file node */
     private static final String FILE_DATA_PROP = JCR_CONTENT + "/" + JCR_DATA;

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java?rev=596022&r1=596021&r2=596022&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java (original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java Sat Nov 17 15:27:57 2007
@@ -24,6 +24,8 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.jcr.NamespaceException;
+import javax.jcr.NamespaceRegistry;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.PropertyType;
@@ -36,6 +38,7 @@
 import javax.servlet.ServletRequest;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.SlingException;
 import org.apache.sling.api.resource.NonExistingResource;
 import org.apache.sling.api.resource.Resource;
@@ -54,10 +57,45 @@
 
     private final Logger log = LoggerFactory.getLogger(MicroslingResourceResolver.class);
 
+    /** The URI we require to be mapped to the sling prefix for microsling */
+    private static final String REQUIRED_NAMESPACE_URI = SlingConstants.NAMESPACE_URI_ROOT
+        + "jcr/sling/1.0";
+
     private Session session;
 
+    // package private default constructor for unit tests, DO NOT USE
+    MicroslingResourceResolver() {
+    }
+
     public MicroslingResourceResolver(Session session) {
         this.session = session;
+
+        // ensure session name space mapping for sling:
+        try {
+            String uri = session.getNamespaceURI(SlingConstants.NAMESPACE_PREFIX);
+            if (!REQUIRED_NAMESPACE_URI.equals(uri)) {
+                log.info("<init> Remapping sling prefix to {}, was {}",
+                    REQUIRED_NAMESPACE_URI, uri);
+                session.setNamespacePrefix(SlingConstants.NAMESPACE_PREFIX,
+                    REQUIRED_NAMESPACE_URI);
+            } else {
+                log.debug("<init> sling prefix mapped correctly to {}", uri);
+            }
+        } catch (NamespaceException ne) {
+            // need to define the namespace
+            try {
+                log.info(
+                    "<init> Registering missing mapping for sling prefix to {}",
+                    REQUIRED_NAMESPACE_URI);
+                NamespaceRegistry nsr = session.getWorkspace().getNamespaceRegistry();
+                nsr.registerNamespace(SlingConstants.NAMESPACE_PREFIX,
+                    REQUIRED_NAMESPACE_URI);
+            } catch (RepositoryException re) {
+                log.error("<init>: Cannot register namespace mapping", re);
+            }
+        } catch (RepositoryException re) {
+            log.error("<init>: Cannot check namespace mapping", re);
+        }
     }
 
     /**

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/content-creation-forms.html
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/content-creation-forms.html?rev=596022&r1=596021&r2=596022&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/content-creation-forms.html (original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/content-creation-forms.html Sat Nov 17 15:27:57 2007
@@ -36,10 +36,10 @@
 	      <br/>
 	      <input name="text" type="text" size="80" value="Default text of the test node"/>
 	      <br/>
-          slingResourceType:
+          sling:resourceType:
           <span class="note">(leave this empty to use the JCR node type for script resolution)</span>
           <br/>
-          <input name="slingResourceType" type="text" size="80" value="microsling/example"/>
+          <input name="sling:resourceType" type="text" size="80" value="microsling/example"/>
           <br/>
 	      <input type="submit" value="Create and display node"/> 
       </p>

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/velocity-scripts.html
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/velocity-scripts.html?rev=596022&r1=596021&r2=596022&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/velocity-scripts.html (original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/velocity-scripts.html Sat Nov 17 15:27:57 2007
@@ -21,7 +21,7 @@
   	To test this, try storing (via WebDAV, see mount point URL on the microsling homepage) the following script in your 
   	repository under <em> /sling/scripts/microsling/example/html.vlt</em> . 
     Doing so will cause microsling to use that script
-  	to render nodes having <em>slingResourceType=microsling/example</em>. 
+  	to render nodes having <em>sling:resourceType=microsling/example</em>. 
   </p>
   <p>
     To try that rendering, use the <a href="content-creation-forms.html">content creation</a> page to create

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java?rev=596022&r1=596021&r2=596022&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java (original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java Sat Nov 17 15:27:57 2007
@@ -20,44 +20,44 @@
 import java.util.HashMap;
 import java.util.Map;
 
-/** Test creating a Node and rendering it using scripts in 
+/** Test creating a Node and rendering it using scripts in
  *  various supported languages, using slingResourceType-based
  *  script resolution
  */
 public class SlingResourceTypeRenderingTest extends RenderingTestBase {
 
     private String slingResourceType;
-    
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        
+
         // set test values
         slingResourceType = "integration-test/srt." + System.currentTimeMillis();
         testText = "This is a test " + System.currentTimeMillis();
-        
+
         // 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();
         final Map<String,String> props = new HashMap<String,String>();
-        props.put("slingResourceType", slingResourceType);
+        props.put("sling:resourceType", slingResourceType);
         props.put("text", testText);
         displayUrl = testClient.createNode(url, props);
-        
+
         // the rendering script goes under /sling/scripts in the repository
         scriptPath = "/sling/scripts/" + slingResourceType;
         testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
     }
-    
+
     public void testWithoutScriptTxt() throws IOException {
         final String content = getContent(displayUrl + ".txt", CONTENT_TYPE_PLAIN);
         assertTrue("Content includes PlainTextRendererServlet marker",content.contains("dumped by PlainTextRendererServlet"));
     }
-    
+
     public void testWithoutScriptHtml() throws IOException {
         final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
         assertTrue("Content includes DefaultHtmlRendererServlet marker",content.contains("dumped by DefaultHtmlRendererServlet"));
     }
-    
+
     public void testEspHtml() throws IOException {
         final String toDelete = uploadTestScript("rendering-test.esp","html.esp");
         try {
@@ -68,7 +68,7 @@
             testClient.delete(toDelete);
         }
     }
-    
+
     public void testEspXml() throws IOException {
         final String toDelete = uploadTestScript("rendering-test.esp","xml.esp");
         try {
@@ -79,7 +79,7 @@
             testClient.delete(toDelete);
         }
     }
-    
+
     public void testEspPlain() throws IOException {
         final String toDelete = uploadTestScript("rendering-test.esp","plain.esp");
         try {
@@ -90,7 +90,7 @@
             testClient.delete(toDelete);
         }
     }
-    
+
     public void testVltHtml() throws IOException {
         final String toDelete = uploadTestScript("rendering-test.vlt","html.vlt");
         try {
@@ -101,7 +101,7 @@
             testClient.delete(toDelete);
         }
     }
-    
+
     public void testJsHtml() throws IOException {
         final String toDelete = uploadTestScript("rendering-test.js","html.js");
         try {
@@ -112,7 +112,7 @@
             testClient.delete(toDelete);
         }
     }
-    
+
     public void testFtlHtml() throws IOException {
         final String toDelete = uploadTestScript("rendering-test.ftl","html.ftl");
         try {
@@ -123,7 +123,7 @@
             testClient.delete(toDelete);
         }
     }
-    
+
     public void testErbHtml() throws IOException {
         final String toDelete = uploadTestScript("rendering-test.erb","html.erb");
         try {

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/MicroslingResourceResolverTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/MicroslingResourceResolverTest.java?rev=596022&r1=596021&r2=596022&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/MicroslingResourceResolverTest.java (original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/MicroslingResourceResolverTest.java Sat Nov 17 15:27:57 2007
@@ -43,7 +43,7 @@
         LogManager.getRootLogger().addAppender(ca);
 
         // may call with null, don't need repository for now
-        resolver = new MicroslingResourceResolver(null);
+        resolver = new MicroslingResourceResolver();
     }
 
     public void testResolveRelativeSegments() {