sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1690028 - in /sling/trunk/bundles: jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/ jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/ servlets/get/src/main/java/org/apache/sling/serv...
Date Thu, 09 Jul 2015 08:47:39 GMT
Author: radu
Date: Thu Jul  9 08:47:39 2015
New Revision: 1690028

URL: http://svn.apache.org/r1690028
Log:
SLING-4865 - Add support for nt:linkedFile nodes

* return the correct InputStream when calling Resource#adapTo(InpuStream.class) on a nt:linkedFile
based resource
* added support for streaming the correct InputStream for nt:linkedFile based resources in
the StreamRendererServlet
* added nt:linkedFile test in JcrNodeResourceTest

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
    sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java?rev=1690028&r1=1690027&r2=1690028&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
Thu Jul  9 08:47:39 2015
@@ -19,6 +19,7 @@ package org.apache.sling.jcr.resource.in
 import static org.apache.jackrabbit.JcrConstants.JCR_CONTENT;
 import static org.apache.jackrabbit.JcrConstants.JCR_DATA;
 import static org.apache.jackrabbit.JcrConstants.NT_FILE;
+import static org.apache.jackrabbit.JcrConstants.NT_LINKEDFILE;
 
 import java.io.InputStream;
 import java.security.AccessControlException;
@@ -196,7 +197,7 @@ class JcrNodeResource extends JcrItemRes
                 // otherwise it is the node of this resource
                 Node content = node.isNodeType(NT_FILE)
                         ? node.getNode(JCR_CONTENT)
-                        : node;
+                        : node.isNodeType(NT_LINKEDFILE) ? node.getProperty(JCR_CONTENT).getNode()
: node;
 
                 Property data;
 

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java?rev=1690028&r1=1690027&r2=1690028&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
Thu Jul  9 08:47:39 2015
@@ -23,9 +23,9 @@ import java.io.InputStream;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.sling.api.resource.Resource;
@@ -40,6 +40,26 @@ public class JcrNodeResourceTest extends
         return new HelperData(null, new PathMapperImpl());
     }
 
+    public void testLinkedFile() throws Exception {
+        String fileName = "file";
+        String linkedFileName = "linkedFile";
+
+        Session session = getSession();
+        Node file = rootNode.addNode(fileName, JcrConstants.NT_FILE);
+        Node res = file.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
+        setupResource(res);
+        file.addMixin(JcrConstants.MIX_REFERENCEABLE);
+        session.save();
+
+        Node linkedFile = rootNode.addNode(linkedFileName, JcrConstants.NT_LINKEDFILE);
+        linkedFile.setProperty(JcrConstants.JCR_CONTENT, file);
+        session.save();
+
+        JcrNodeResource linkedFileResource = new JcrNodeResource(null, linkedFile.getPath(),
null, linkedFile, getHelperData());
+        assertEquals(TEST_DATA, linkedFileResource.adaptTo(InputStream.class));
+
+    }
+
     public void testNtFileNtResource() throws Exception {
 
         String name = "file";

Modified: sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java?rev=1690028&r1=1690027&r2=1690028&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
(original)
+++ sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
Thu Jul  9 08:47:39 2015
@@ -31,12 +31,16 @@ import java.util.Date;
 import java.util.Iterator;
 import java.util.StringTokenizer;
 
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletException;
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
@@ -110,7 +114,7 @@ public class StreamRendererServlet exten
             return;
         }
 
-        final Resource resource = request.getResource();
+        Resource resource = request.getResource();
         if (ResourceUtil.isNonExistingResource(resource)) {
             throw new ResourceNotFoundException("No data to render.");
         }
@@ -132,6 +136,16 @@ public class StreamRendererServlet exten
         }
 
         // fall back to plain text rendering if the resource has no stream
+        if (resource.getResourceType().equals(JcrConstants.NT_LINKEDFILE)) {
+            try {
+                String actualResourcePath = resource.adaptTo(Node.class).getProperty(JcrConstants.JCR_CONTENT).getNode().getPath();
+                resource = request.getResourceResolver().getResource(actualResourcePath);
+            } catch (PathNotFoundException e) {
+                throw new ResourceNotFoundException("No data to render");
+            } catch (RepositoryException e) {
+                throw new IOException(e);
+            }
+        }
         InputStream stream = resource.adaptTo(InputStream.class);
         if (stream != null) {
 
@@ -310,7 +324,6 @@ public class StreamRendererServlet exten
 
     /**
      * @param resource
-     * @param request
      * @param response
      */
     private void setHeaders(Resource resource,
@@ -453,7 +466,6 @@ public class StreamRendererServlet exten
      * @param resource The resource from which to send ranges
      * @param ostream The output stream to write to
      * @param ranges Iterator of the ranges the client wanted to retrieve
-     * @param contentType Content type of the resource
      * @exception IOException if an input/output error occurs
      */
     private void copy(Resource resource, ServletOutputStream ostream,



Mime
View raw message