incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r586631 - in /incubator/sling/whiteboard/microsling/src: main/java/org/apache/sling/microsling/request/helpers/ main/java/org/apache/sling/microsling/scripting/ main/java/org/apache/sling/microsling/servlet/ main/java/org/apache/sling/micro...
Date Fri, 19 Oct 2007 22:23:08 GMT
Author: bdelacretaz
Date: Fri Oct 19 15:23:06 2007
New Revision: 586631

URL: http://svn.apache.org/viewvc?rev=586631&view=rev
Log:
SLING-72 - scripts work again, adapt examples and remove homepage warning

Modified:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/ScriptEngine.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
    incubator/sling/whiteboard/microsling/src/main/webapp/content-creation-forms.html
    incubator/sling/whiteboard/microsling/src/main/webapp/index.html
    incubator/sling/whiteboard/microsling/src/main/webapp/velocity-scripts.html
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java?rev=586631&r1=586630&r2=586631&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
Fri Oct 19 15:23:06 2007
@@ -76,9 +76,14 @@
         if(pathToParse == null) {
             pathToParse = "";
         }
-        resourcePath = r.getURI();
-        if(pathToParse.length() >= resourcePath.length()) {
-            pathToParse = pathToParse.substring(resourcePath.length());
+        
+        if(r==null) {
+            resourcePath = null;
+        } else {
+            resourcePath = r.getURI();
+            if(pathToParse.length() >= resourcePath.length()) {
+                pathToParse = pathToParse.substring(resourcePath.length());
+            }
         }
         
         Matcher m = splitInThreePattern.matcher(pathToParse);

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/ScriptEngine.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/ScriptEngine.java?rev=586631&r1=586630&r2=586631&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/ScriptEngine.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/ScriptEngine.java
Fri Oct 19 15:23:06 2007
@@ -30,6 +30,7 @@
     static final String REQUEST = "request";
     static final String RESPONSE = "response";
     static final String RESOURCE = "resource";
+    static final String OUT = "out";
 
     String[] getExtensions();
 

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java?rev=586631&r1=586630&r2=586631&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
Fri Oct 19 15:23:06 2007
@@ -34,6 +34,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.sling.microsling.api.Resource;
 import org.apache.sling.microsling.api.ServiceLocator;
 import org.apache.sling.microsling.api.SlingRequestContext;
 import org.apache.sling.microsling.api.exceptions.HttpStatusCodeException;
@@ -162,7 +163,8 @@
             throws Exception {
 
         // use the resource type to select a servlet
-        String type = SlingRequestContext.Accessor.getSlingRequestContext(req).getResource().getResourceType();
+        final Resource r = SlingRequestContext.Accessor.getSlingRequestContext(req).getResource();

+        String type = (r == null ? null : r.getResourceType());
         return (type != null) ? servlets.get(type) : null;
     }
 

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java?rev=586631&r1=586630&r2=586631&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
Fri Oct 19 15:23:06 2007
@@ -88,13 +88,14 @@
 
         // Create or update node under current path
         final String nodePath = ctx.getRequestPathInfo().getResourcePath();
-
+        String redirectPath = req.getPathInfo();
+        
         Session s = null;
         try {
             s = ctx.getSession();
             Node current = null;
             boolean createNewNode = false;
-            if (s.itemExists(nodePath)) {
+            if (nodePath != null && s.itemExists(nodePath)) {
                 current = (Node) s.getItem(nodePath);
                 // TODO this is simplistic...if the node has children we assume
                 // it's a folder,
@@ -113,6 +114,7 @@
             // Copy request parameters to node properties and save
             setPropertiesFromRequest(current, req);
             s.save();
+            redirectPath = current.getPath();
         } catch (RepositoryException re) {
             throw new ServletException("Failed modifying content: "
                 + re.getMessage(), re);
@@ -126,13 +128,19 @@
             }
         }
 
-        final String redirectPath = req.getServletPath() + req.getPathInfo();
-        resp.sendRedirect(redirectPath);
+        // redirect to the created node, so that it is displayed using a user-supplied extension
+        String redirectExtension = req.getParameter("slingDisplayExtension");
+        final String redirectUrl = 
+            req.getServletPath() + redirectPath 
+            + (redirectExtension == null ? "" : "." + redirectExtension)
+        ;
+        resp.sendRedirect(redirectUrl);
     }
 
     /** Set node properties from current request (only handles Strings for now) */
     protected void setPropertiesFromRequest(Node n, HttpServletRequest req)
             throws RepositoryException {
+        // TODO ignore sling-specific properties like slingDisplayExtension
         for (Enumeration e = req.getParameterNames(); e.hasMoreElements();) {
             final String name = (String) e.nextElement();
             final String value = req.getParameter(name);

Modified: incubator/sling/whiteboard/microsling/src/main/webapp/content-creation-forms.html
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/webapp/content-creation-forms.html?rev=586631&r1=586630&r2=586631&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/webapp/content-creation-forms.html (original)
+++ incubator/sling/whiteboard/microsling/src/main/webapp/content-creation-forms.html Fri
Oct 19 15:23:06 2007
@@ -16,6 +16,8 @@
   
   <div>
     <form class="testbox" action="microsling/content/testing.sling" method="POST">
+      <input type="hidden" name="slingDisplayExtension" value="html"/>
+      
       <h1>SlingPostServlet content creation form</h1>
       <p>
         Submitting this form creates an <em>nt:unstructured</em> node under content/testing,


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=586631&r1=586630&r2=586631&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/webapp/index.html (original)
+++ incubator/sling/whiteboard/microsling/src/main/webapp/index.html Fri Oct 19 15:23:06 2007
@@ -18,16 +18,6 @@
 	module.
   </p>
   
-  <div>
-    <div style="color:red; font-weight: bold">
-      The microsling scripting module is currently BROKEN, see 
-      <a href="https://issues.apache.org/jira/browse/SLING-72">SLING-72</a>.
-    </div>
-    <div>
-      Use an older revision if you want to test that (Early Friday October 19th should work).
-    </div>
-  </div>
-  
   <h2>microsling test links</h2>
   <ul>
     <li>

Modified: incubator/sling/whiteboard/microsling/src/main/webapp/velocity-scripts.html
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/webapp/velocity-scripts.html?rev=586631&r1=586630&r2=586631&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/webapp/velocity-scripts.html (original)
+++ incubator/sling/whiteboard/microsling/src/main/webapp/velocity-scripts.html Fri Oct 19
15:23:06 2007
@@ -43,22 +43,20 @@
   <p>
     Here's the example HTML template. See the <a href="http://velocity.apache.org">Velocity
website</a> for 
     more info about the syntax.
-    <pre>
-&lt;html>
+    <pre>&lt;html>
 &lt;body>
-&lt;h1>This is generated from a Velocity template&lt;/h1> 
-&lt;p> 
+&lt;h1>This is generated from a Velocity template&lt;/h1>
+&lt;p>
   The current resource URI is &lt;b>$resource.URI&lt;/b>
 &lt;/p>
 
-&lt;h2>$node.getProperty("title").getString()&lt;/h2>
+&lt;h2>$resource.getItem().getProperty("title").getString()&lt;/h2>
 &lt;p>
-  $node.getProperty("text").getString()
+  $resource.getItem().getProperty("text").getString()
 &lt;/p>
 
 &lt;/body>
-&lt;/html></pre>
-  </p>
+&lt;/html></pre>  </p>
   <p>
     To deactivate the Velocity-based rendering of nodes, rename or delete the corresponding
rendering
     scripts. 

Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java?rev=586631&r1=586630&r2=586631&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
(original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
Fri Oct 19 15:23:06 2007
@@ -58,6 +58,12 @@
         assertEquals("",p.getResourcePath());
     }
     
+    public void testNullResource() {
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(null,"/some/path.print.a4.html/some/suffix");
+        assertEquals("/some/path",p.getUnusedContentPath());
+        assertEquals(null,p.getResourcePath());
+    }
+    
     public void testSimpleSuffix() {
         SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource(""),"/some/path.print.a4.html/some/suffix");
         assertEquals("/some/suffix",p.getSuffix());
@@ -168,4 +174,5 @@
         assertEquals("",p.getSuffix());
         assertEquals("/some/suffix",p.getUnusedContentPath());
     }
+    
 }



Mime
View raw message