incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r591084 - in /incubator/sling/trunk/microsling/microsling-core/src: main/java/org/apache/sling/microsling/slingservlets/ test/java/org/apache/sling/microsling/integration/
Date Thu, 01 Nov 2007 16:56:08 GMT
Author: bdelacretaz
Date: Thu Nov  1 09:56:07 2007
New Revision: 591084

URL: http://svn.apache.org/viewvc?rev=591084&view=rev
Log:
SLING-92 - all tests pass

Modified:
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/StreamServlet.java
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StreamServletTest.java

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/StreamServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/StreamServlet.java?rev=591084&r1=591083&r2=591084&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/StreamServlet.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/StreamServlet.java
Thu Nov  1 09:56:07 2007
@@ -102,10 +102,9 @@
                 }
             }
 
-            // just spool, the property to which the item resolves through
-            // the primary item trail
-            // the item is a property, spool and forget
-            spool(response, findDefaultProperty(node), null, null, -1);
+            // spool the property which contains the file data
+            // TODO get mime-type etc.
+            spool(response, findDataProperty(node), null, null, -1);
 
         } catch (ItemNotFoundException infe) {
             response.sendError(HttpServletResponse.SC_NOT_FOUND);
@@ -167,14 +166,38 @@
         }
     }
 
-    /** Follow the primary item trail of item until a property is found */
-    Property findDefaultProperty(Item item) throws ItemNotFoundException,
-            RepositoryException {
-        while (item.isNode()) {
-            // will throw if there is none defined or existsing
-            item = ((Node) item).getPrimaryItem();
+    /** Find the Property that contains the data to spool, under parent */ 
+    private Property findDataProperty(final Item parent) throws RepositoryException, HttpStatusCodeException
{
+        Property result = null;
+        
+        // Following the path of primary items until we find a property
+        // should provide us with the file data of the parent
+        try {
+            Item item = parent;
+            while(item!=null && item.isNode()) {
+                item = ((Node) item).getPrimaryItem();
+            }
+            result = (Property)item;
+        } catch(ItemNotFoundException ignored) {
+            // TODO: for now we use an alternate method if this fails,
+            // there might be a better way (see jackrabbit WebDAV server code?)
+        }
+        
+        if(result==null && parent.isNode()) {
+            // primary path didn't work, try the "usual" path to the data Property
+            try {
+                final Node parentNode = (Node)parent;
+                result = parentNode.getNode("jcr:content").getProperty("jcr:data");
+            } catch(ItemNotFoundException e) {
+                throw new HttpStatusCodeException(404,parent.getPath() + "/jcr:content" +
"/jcr:data");
+            }
+        }
+        
+        if(result==null) {
+            throw new HttpStatusCodeException(500, "Unable to find data property for parent
item " + parent.getPath());
         }
-        return (Property) item;
+        
+        return result;
     }
 
     /** return the jcr:lastModified property value or null if property is missing */

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java?rev=591084&r1=591083&r2=591084&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
Thu Nov  1 09:56:07 2007
@@ -26,7 +26,7 @@
 public class CreateNodeTest extends MicroslingHttpTestBase {
     
     public void testCreateNode() throws IOException {
-        final String url = HTTP_BASE_URL + TEST_PATH + ".sling";
+        final String url = HTTP_BASE_URL + "/CreateNodeTest." + System.currentTimeMillis()
+ ".sling";
         
         // add some properties to the node
         final Map<String,String> props = new HashMap<String,String>();

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StreamServletTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StreamServletTest.java?rev=591084&r1=591083&r2=591084&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StreamServletTest.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StreamServletTest.java
Thu Nov  1 09:56:07 2007
@@ -41,7 +41,7 @@
                     content.contains("This is just some text in an ASCII file.")
             );
         } finally {
-            // TODO testClient.delete(toDelete);
+            testClient.delete(toDelete);
         }
     }
 
@@ -58,7 +58,7 @@
                     content.contains("This is <em>testfile.html</em>.")
             );
         } finally {
-            // TODO testClient.delete(toDelete);
+            testClient.delete(toDelete);
         }
     }
 }



Mime
View raw message