incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r585135 - in /incubator/sling/whiteboard/microsling/src: main/java/org/apache/sling/microsling/etc/ main/java/org/apache/sling/microsling/scripting/helpers/ main/java/org/apache/sling/microsling/slingservlets/ main/webapp/ test/java/org/apa...
Date Tue, 16 Oct 2007 12:55:40 GMT
Author: bdelacretaz
Date: Tue Oct 16 05:55:22 2007
New Revision: 585135

URL: http://svn.apache.org/viewvc?rev=585135&view=rev
Log:
SLING-58 - move EspReader to the scripting.helpers package, and give more importance to ESP
in the server-side-javascript.html explanations page

Added:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/helpers/
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/helpers/EspReader.java
      - copied, changed from r585126, incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/EspReader.java
Removed:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/EspReader.java
Modified:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/RhinoJavascriptServlet.java
    incubator/sling/whiteboard/microsling/src/main/webapp/index.html
    incubator/sling/whiteboard/microsling/src/main/webapp/microsling.css
    incubator/sling/whiteboard/microsling/src/main/webapp/server-side-javascript.html
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/etc/EspReaderTest.java

Copied: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/helpers/EspReader.java
(from r585126, incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/EspReader.java)
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/helpers/EspReader.java?p2=incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/helpers/EspReader.java&p1=incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/EspReader.java&r1=585126&r2=585135&rev=585135&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/etc/EspReader.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/helpers/EspReader.java
Tue Oct 16 05:55:22 2007
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.microsling.etc;
+package org.apache.sling.microsling.scripting.helpers;
 
 import java.io.FilterReader;
 import java.io.IOException;

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/RhinoJavascriptServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/RhinoJavascriptServlet.java?rev=585135&r1=585134&r2=585135&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/RhinoJavascriptServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/RhinoJavascriptServlet.java
Tue Oct 16 05:55:22 2007
@@ -27,16 +27,20 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.sling.microsling.etc.AbstractSlingServlet;
-import org.apache.sling.microsling.etc.EspReader;
 import org.apache.sling.microsling.requestcontext.SlingRequestContext;
 import org.apache.sling.microsling.scripting.FileNodeRequestAttribute;
 import org.apache.sling.microsling.scripting.SlingScriptResolver;
+import org.apache.sling.microsling.scripting.helpers.EspReader;
 import org.mozilla.javascript.Context;
 import org.mozilla.javascript.ScriptableObject;
 
 /**
- * A SlingServlet that uses the Rhino interpreter to process Sling request with
- * server-side javascript.
+ *  A SlingServlet that uses the Rhino interpreter to process a Sling request 
+ *  with server-side javascript.
+ *  
+ *  A script with an "esp" extension (Ecmascript Server Pages) is read using
+ *  an EspReader, which converts the ESP template format to javascript code,
+ *  to implement a simple javascript-based templating mechanism.  
  */
 public class RhinoJavascriptServlet extends AbstractSlingServlet {
 
@@ -46,6 +50,20 @@
 
     public final static String ESP_SCRIPT_EXTENSION = "esp";
 
+    /** A FileNodeRequestAttribute that uses an EspReader to convert ESP templates */ 
+    static class EspTemplateFileNodeRequestAttribute extends FileNodeRequestAttribute {
+        EspTemplateFileNodeRequestAttribute(Node scriptNode, HttpServletRequest req) {
+            super(scriptNode,req);
+        }
+        
+        @Override
+        public Reader getReader() throws RepositoryException {
+            return new EspReader(new BufferedReader(
+                super.getReader()));
+        }
+        
+    };
+    
     /** True if we have a js script to handle the current request */
     public boolean canProcess(HttpServletRequest req) throws Exception {
         boolean result = false;
@@ -59,17 +77,9 @@
             final Node espScript = scriptResolver.resolveScript(req,
                 ESP_SCRIPT_EXTENSION);
             if (espScript != null) {
-                new FileNodeRequestAttribute(espScript, req) {
-                    @Override
-                    public Reader getReader() throws RepositoryException {
-                        return new EspReader(new BufferedReader(
-                            super.getReader()));
-                    }
-                };
-
+                new EspTemplateFileNodeRequestAttribute(espScript,req);
                 result = true;
             }
-
         }
 
         return result;

Modified: incubator/sling/whiteboard/microsling/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/webapp/index.html?rev=585135&r1=585134&r2=585135&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/webapp/index.html (original)
+++ incubator/sling/whiteboard/microsling/src/main/webapp/index.html Tue Oct 16 05:55:22 2007
@@ -32,8 +32,8 @@
     </li>
     <li>
       <a href="server-side-javascript.html">
-        Server-side javascript
-      </a>: explains how to use server-side javascript to process requests.
+        Server-side javascript and ESP templates
+      </a>: explains how to use server-side javascript and javascript-based ESP templates
to process requests.
     </li>
   </ul>
   

Modified: incubator/sling/whiteboard/microsling/src/main/webapp/microsling.css
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/webapp/microsling.css?rev=585135&r1=585134&r2=585135&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/webapp/microsling.css (original)
+++ incubator/sling/whiteboard/microsling/src/main/webapp/microsling.css Tue Oct 16 05:55:22
2007
@@ -23,6 +23,7 @@
 
 h3 {
 	font-weight:900;
+	font-size:100%;
 }
 
 .testbox {

Modified: incubator/sling/whiteboard/microsling/src/main/webapp/server-side-javascript.html
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/webapp/server-side-javascript.html?rev=585135&r1=585134&r2=585135&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/webapp/server-side-javascript.html (original)
+++ incubator/sling/whiteboard/microsling/src/main/webapp/server-side-javascript.html Tue
Oct 16 05:55:22 2007
@@ -1,76 +1,113 @@
 <html>
 <head>
-  <title>microsling server-side javascript</title>
+  <title>microsling server-side javascript and ESP templates</title>
   <link rel="stylesheet" href="microsling.css"/>
 </head>
 <body>
-  <h1>microsling server-side javascript</h1>
+  <h1>microsling server-side javascript and ESP templates</h1>
   
   <div class="note">
     <a href="../">back to homepage</a>
   </div>
   
   <p>
-    Server-side javascript can be used by microsling to process requests. The scripts are
located by the
-    <em>SlingScriptResolver</em>, as used by the <a href="velocity-scripts.html">Velocity
templates</a> (see that
-    page for more details about this).  
+    Server-side javascript code and javascript-based ESP templates can be used by microsling
to process requests. 
+    The scripts are located by the
+    <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java?view=markup">SlingScriptResolver</a>
+    , as for the <a href="velocity-scripts.html">Velocity templates</a> (see
that
+    page for more details about how this resolution works).  
+  </p>
+  <p>
+  	Scripts can either:
+  	<ul>
+  	  <li>
+  	  	Have the <em>.esp</em> extension to use the microsling <em>ECMAscript
Server Pages</em> syntax
+  	  	described below.
+  	  </li>
+  	  <li>
+  	  	Have the <em>.js</em> extension to use "raw" javascript.
+  	  </li>
+  	</ul>
   </p>
   <p>
-    See the (very simple) <em>RhinoJavascriptServlet</em> for implementation
details.
+    Server-side javascript support is implemented by the 
+    <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/RhinoJavascriptServlet.java?revision=585096&view=markup">RhinoJavascriptServlet</a>.
   </p>
   <p>
   	To test this, remove or rename <a href="velocity-scripts.html">Velocity templates</a>
     if you played with them before (Velocity has priority due to the order in which the SlingServlet
classes
-    are setup),  and store the script shown
-  	below under <em>/sling/scripts/microsling/example/get.text_html.js</em>
-  	or <em>/sling/scripts/microsling/example/get.text_html.esp</em> in the repository.
+    are setup),  and store one of the scripts shown
+  	below under <em>/sling/scripts/microsling/example/</em>, using the filename
shown in the example comments.
   </p>
   <p>
   	Content nodes created with the <a href="content-creation-forms.html">Content creation
forms</a>
-    should then be displayed in HTML,with a <em>This page is generated from a rhino
script</em> note at the top of the 
-    page.
+    should then be displayed in HTML, with a layout defined by the example scripts.
   </p>
   <p>
-    As for the Velocity templates, other output formats can be generated, for example by
renaming the script 
-    to <em>get.text_plain.js</em>, modifying it to output plain text and using
a <em>.txt</em> extension
+    As for the Velocity templates, other output formats can be generated, for example by
renaming the ESP template 
+    to <em>get.text_plain.esp</em>, modifying it to output plain text and using
a <em>.txt</em> extension
     in the request.
   </p>
+  
+  <h2>ECMAscript Server Pages (ESP)</h2>
   <p>
-    Server-side javascript comes in two flavors: Raw javascript identified by the script
file
-    extension <em>.js</em> and templated javascript, which we call <em>ECMA
Server Pages</em>,
-    identified by the script file extension <em>.esp</em>. Templated javascript
works
-    much like JSP in that template text and javascript code may be mixed using the
-    <em>&lt;% ... %&gt;</em> tag to enclose code or the <em>&lt;%=
... %&gt;</em>
-    tag to include the result of evaluating the enclosed expression in the output. 
-  <p>
-  	Raw server-side javascript is probably better suited for handling POST and PUT requests
(that would be
-  	the <em>post.js</em> and <em>put.js</em> scripts), unless a suitable
templating library is used. 
+    <em>ECMAscript Server Pages</em> work much like JSP:
+    <ul>
+      <li>
+      	A template mixes javascript code with litteral text that is copied to the output.
+      </li>
+      <li>
+      	<em>&lt;% ... %&gt;</em> tags enclose code blocks.
+      </li>
+      <li>
+      	<em>&lt;%= ... %&gt;</em> tags include the result of a javascript
expression in the output.
+      </li>
+      <li>
+      	Several standard objects are available in javascript to access microsling data
+      	(TODO: document these objects - for now see the RhinoJavascriptServlet source code)
+      </li>
+    </ul>
   </p>
+  <h3>ESP template example</h3>
+    <pre>
+&lt;%-- microsling ESP template example, store this as get.text_html.esp --%>
+&lt;html>
+&lt;body>
+&lt;p>This page is generated from an ESP template!&lt;/p>
+&lt;h1>&lt;%= resource.getURI() %>&lt;/h1>
+&lt;% 
+  var it = resource.item.properties;
+  while(it.hasNext()) {
+    var p = it.next();
+    %>
+      &lt;p>
+        &lt;%= p.name %>
+        =
+        &lt;strong>&lt;%= p.string %>&lt;/strong>
+      &lt;/p>
+    &lt;%
+  }
+%> 
+&lt;/body>
+&lt;/html></pre>
+    
+  <h2>Raw javascript</h2>
   <p>
-    <strong>get.js - An example of raw javascript</strong>
-  <p>
+  	Raw javascript is probably more useful to handle the POST, PUT or DELETE methods.
+  </p>
+  
+  <h3>Javascript example</h3>
     <pre>
-// Not the best way of rendering output, of course...
+// store this as get.text_html.js in the repository    
+// TODO this is not very useful, rewrite this example
 out.println("&lt;html>&lt;body>");
 out.println("&lt;p>This page is generated from a rhino script&lt;/p>");
 out.println("&lt;h1>" + resource.getURI() + "&lt;/h1>");
 out.println("&lt;p>Title: " + resource.getItem().getProperty('title').getString()
+ "&lt;/p>");
 out.println("&lt;p>Text: " + resource.getItem().getProperty('text').getString() +
"&lt;/p>");
-out.println("&lt;/body>&lt;/html>");
-    </pre>
-  <p>
-    <strong>get.esp - An example of templated javascript</strong>
-  <p>
-    <pre>
-&lt;%-- ESP rendering of JavaScript --%&gt;
-&lt;html&gt;&lt;body&gt;
-&lt;p&gt;This page is generated from a rhino script&lt;/p&gt;
-&lt;h1&gt;&lt;%= resource.getURI() %&gt;&lt;/h1&gt;
-&lt;p&gt;Title: &lt;%= resource.getItem().getProperty('title').getString() %&gt;&lt;/p&gt;
-&lt;p&gt;Text: &lt;%= resource.getItem().getProperty('text').getString() %&gt;&lt;/p&gt;
-&lt;/body&gt;&lt;/html&gt;
-    </pre>
+out.println("&lt;/body>&lt;/html>");</pre>
   </p>
+  </div>
   
 </body>
 </html>

Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/etc/EspReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/etc/EspReaderTest.java?rev=585135&r1=585134&r2=585135&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/etc/EspReaderTest.java
(original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/etc/EspReaderTest.java
Tue Oct 16 05:55:22 2007
@@ -20,6 +20,8 @@
 
 import junit.framework.TestCase;
 
+import org.apache.sling.microsling.scripting.helpers.EspReader;
+
 /**
  * The <code>EspReaderTest</code> contains some simple test cases for the
  * <code>EspReader</code> class which processes ESP (ECMA Server Page) templated



Mime
View raw message