incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r602954 - in /incubator/sling/trunk/microsling/microsling-core: ./ src/main/java/org/apache/sling/microsling/experimental/ src/main/java/org/apache/sling/microsling/resource/ src/test/java/org/apache/sling/microsling/integration/
Date Mon, 10 Dec 2007 15:59:39 GMT
Author: bdelacretaz
Date: Mon Dec 10 07:59:38 2007
New Revision: 602954

URL: http://svn.apache.org/viewvc?rev=602954&view=rev
Log:
SLING-129 - EctScriptEngine now supports SyntheticResource

Modified:
    incubator/sling/trunk/microsling/microsling-core/pom.xml
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/experimental/EctScriptEngine.java
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResource.java
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResourceProvider.java
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SyntheticResourceTest.java

Modified: incubator/sling/trunk/microsling/microsling-core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/pom.xml?rev=602954&r1=602953&r2=602954&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/pom.xml (original)
+++ incubator/sling/trunk/microsling/microsling-core/pom.xml Mon Dec 10 07:59:38 2007
@@ -58,6 +58,13 @@
       -->
       <sling.log.level>info</sling.log.level>
       <root.log.level>info</root.log.level>
+      
+      <!-- 
+        Set this to 0 to disable automatic Jetty reloading
+        (which gets in the way when running integration tests
+        that touch target resources)
+       -->
+       <jetty.scan.interval.seconds>10</jetty.scan.interval.seconds>
   </properties>
 
   <dependencies>
@@ -191,7 +198,7 @@
         <version>6.1.5</version>
         <configuration>
           <contextPath>/</contextPath>
-          <scanIntervalSeconds>10</scanIntervalSeconds>
+          <scanIntervalSeconds>${jetty.scan.interval.seconds}</scanIntervalSeconds>
           <connectors>
             <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
               <port>8080</port>

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/experimental/EctScriptEngine.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/experimental/EctScriptEngine.java?rev=602954&r1=602953&r2=602954&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/experimental/EctScriptEngine.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/experimental/EctScriptEngine.java
Mon Dec 10 07:59:38 2007
@@ -39,6 +39,7 @@
 import org.apache.sling.api.wrappers.SlingRequestPaths;
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.microsling.helpers.json.JsonItemWriter;
+import org.apache.sling.microsling.resource.SyntheticResourceData;
 import org.apache.sling.microsling.slingservlets.renderers.DefaultHtmlRenderer;
 import org.apache.sling.scripting.javascript.EspReader;
 
@@ -72,15 +73,19 @@
         try {
             // access our data (need a Node)
             final Resource r = (Resource)props.get(SlingScriptEngine.RESOURCE);
+            
+            // to render we must have either a Node or a SyntheticResourceData
             final Node n = r.adaptTo(Node.class);
-            if(n == null) {
+            final SyntheticResourceData srd = r.adaptTo(SyntheticResourceData.class);
+            if(srd==null && n == null) {
                 throw new HttpStatusCodeException(
-                        HttpServletResponse.SC_NOT_FOUND,"Resource does not provide a Node,
cannot render");
+                        HttpServletResponse.SC_NOT_FOUND,
+                        "Resource does not provide a Node or a SyntheticResourceData, cannot
render");
             }
             
             // output HEAD with javascript initializations
             w.println("<html><head><title id=\"EctPageTitle\">");
-            w.println("ECT rendering of " + n.getPath());
+            w.println("ECT rendering of " + r.getURI());
             w.println("</title>");
             
             // library scripts
@@ -99,12 +104,16 @@
             w.println("function ectOnLoad() { if(typeof onLoad == \"function\") { onLoad();
} }");
             w.println("</script>");
             
-            // node data in JSON format
+            // data in JSON format
             final JsonItemWriter j = new JsonItemWriter(null);
             final int maxRecursionLevels = 1;
             w.println("<script language='javascript'>");
             w.print("var currentNode=");
-            j.dump(n, w, maxRecursionLevels);
+            if(n!=null) {
+                j.dump(n, w, maxRecursionLevels);
+            } else {
+                w.print("{}");
+            }
             w.println(";");
             w.println("</script>");
             w.println("</head><body onLoad=\"ectOnLoad()\">");
@@ -117,7 +126,11 @@
             // default rendering, turned off automatically from the javascript that 
             // follows, if javascript is enabled
             w.println("<div id=\"EctDefaultRendering\">");
-            htmlRenderer.render(w, r, n);
+            if(n!=null) {
+                htmlRenderer.render(w, r, n);
+            } else {
+                htmlRenderer.render(w, r, srd);
+            }
             w.println("</div>");
             w.println("<script language=\"javascript\">");
             w.println("document.getElementById(\"EctDefaultRendering\").setAttribute(\"style\",\"display:none\");");

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResource.java?rev=602954&r1=602953&r2=602954&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResource.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResource.java
Mon Dec 10 07:59:38 2007
@@ -43,7 +43,7 @@
     private ResourceMetadata resourceMetadata;
     
     /** default resource type for these resources */
-    public static String DEFAULT_RESOURCE_TYPE = "/sling/synthetic-resource";
+    public static String DEFAULT_RESOURCE_TYPE = "sling/synthetic-resource";
 
     /**
      * Creates a synthetic content with the given path and component Id.

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResourceProvider.java?rev=602954&r1=602953&r2=602954&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResourceProvider.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResourceProvider.java
Mon Dec 10 07:59:38 2007
@@ -41,7 +41,7 @@
      *  created if the given path matches one of these.
      */
     public static String [] DEFAULT_PATH_REGEXP = {
-        "/search(/.*)?",   // everything under /search
+        "/search(/[^\\.]*)?",   // everything under /search, path=up to last dot
         ".*\\*$"          // everything ending with *
     };
     

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SyntheticResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SyntheticResourceTest.java?rev=602954&r1=602953&r2=602954&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SyntheticResourceTest.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SyntheticResourceTest.java
Mon Dec 10 07:59:38 2007
@@ -20,6 +20,7 @@
 
 import java.io.IOException;
 
+import org.apache.sling.microsling.resource.SyntheticResource;
 import org.apache.sling.microsling.resource.SyntheticResourceProvider;
 
 /** Test the SLING-129 {@link SyntheticResources}, by requesting
@@ -74,4 +75,23 @@
         final String basePath = "/" + getClass().getSimpleName() + "_" + System.currentTimeMillis()
+ "/" + (int)(Math.random() * Integer.MAX_VALUE);
         assertDeepGetStatus(basePath,10,404,"");
     }
+    
+    public void testSyntheticResourceWithEctTemplate() throws IOException {
+        final String synthResourceUrl = HTTP_BASE_URL + "/search/something.html";
+        {
+            final String content = getContent(synthResourceUrl, CONTENT_TYPE_HTML);
+            assertFalse("Content must not include ECT marker before test",content.contains("ECT
template"));
+        }
+        
+        final String scriptPath = "/apps/" + SyntheticResource.DEFAULT_RESOURCE_TYPE;
+        final String toDelete = uploadTestScript(scriptPath,"rendering-test.ect","html.ect");
+        try {
+            final String content = getContent(synthResourceUrl, CONTENT_TYPE_HTML);
+            assertTrue("Content includes ECT marker: " + content,content.contains("ECT template"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+
+
 }



Mime
View raw message