Author: fmeschbe
Date: Sun Aug 29 18:00:17 2010
New Revision: 990610

URL: http://svn.apache.org/viewvc?rev=990610&view=rev
Log:
SLING-1705 proactively set the content length property in the resource metadata 
instead of only setting it when the resource is first adapted to an InputStream

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/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.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=990610&r1=990609&r2=990610&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
 Sun Aug 29 18:00:17 2010
@@ -185,6 +185,13 @@ class JcrNodeResource extends JcrItemRes
                             item = ((Node) item).getPrimaryItem();
                         }
                         data = ((Property) item);
+
+                        // set the content lenght property as a side effect
+                        // for resources which are not nt:file based and whose
+                        // data is not in jcr:content/jcr:data this will lazily
+                        // set the correct content length
+                        
getResourceMetadata().setContentLength(data.getLength());
+
                     } catch (ItemNotFoundException infe) {
                         // we don't actually care, but log for completeness
                         LOGGER.debug("getInputStream: No primary items for "
@@ -194,15 +201,7 @@ class JcrNodeResource extends JcrItemRes
                 }
 
                 if (data != null) {
-                    // we set the content length only if the input stream is
-                    // fetched. otherwise the repository needs to load the
-                    // binary property which could cause performance loss
-                    // for all resources that do need to provide the stream
-                    long length = data.getLength();
-                    InputStream stream = data.getStream();
-
-                    getResourceMetadata().setContentLength(length);
-                    return stream;
+                    return data.getStream();
                 }
 
             } catch (RepositoryException re) {
@@ -272,6 +271,17 @@ class JcrNodeResource extends JcrItemRes
                             prop.getPath(), vfe);
                 }
             }
+
+            if (node.hasProperty(JCR_DATA)) {
+                final Property prop = node.getProperty(JCR_DATA);
+                try {
+                    metadata.setContentLength(prop.getLength());
+                } catch (ValueFormatException vfe) {
+                    LOGGER.debug(
+                        "Length of Property {} cannot be retrieved, ignored 
({})",
+                        prop.getPath(), vfe);
+                }
+            }
         } catch (RepositoryException re) {
             LOGGER.info(
                 "setMetaData: Problem extracting metadata information for "

Modified: 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java?rev=990610&r1=990609&r2=990610&view=diff
==============================================================================
--- 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
 (original)
+++ 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
 Sun Aug 29 18:00:17 2010
@@ -52,6 +52,7 @@ class JcrPropertyResource extends JcrIte
         this.property = property;
         this.resourceType = getResourceTypeForNode(property.getParent())
             + "/" + property.getName();
+        this.getResourceMetadata().setContentLength(property.getLength());
     }
 
     public String getResourceType() {
@@ -186,15 +187,7 @@ class JcrPropertyResource extends JcrIte
         Property prop = getProperty();
 
         try {
-            // we set the content length only if the input stream is
-            // fetched. otherwise the repository needs to load the
-            // binary property which could cause performance loss
-            // for all resources that do need to provide the stream
-            long length = prop.getLength();
-            InputStream stream =  prop.getStream();
-
-            getResourceMetadata().setContentLength(length);
-            return stream;
+            return prop.getStream();
         } catch (RepositoryException re) {
             LOGGER.error("getInputStream: Problem accessing the property "
                 + getPath() + " stream", re);


Reply via email to