ieb commented on a change in pull request #19:
URL: 
https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/19#discussion_r784854708



##########
File path: 
src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/BinaryDownloadUriProvider.java
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.jcr.resource.internal.helper.jcr;
+
+import java.net.URI;
+
+import javax.jcr.Binary;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFormatException;
+
+import org.apache.jackrabbit.api.binary.BinaryDownload;
+import org.apache.jackrabbit.api.binary.BinaryDownloadOptions;
+import 
org.apache.jackrabbit.api.binary.BinaryDownloadOptions.BinaryDownloadOptionsBuilder;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.external.URIProvider;
+import 
org.apache.sling.jcr.resource.internal.helper.jcr.BinaryDownloadUriProvider.Configuration.ContentDisposition;
+import org.jetbrains.annotations.NotNull;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+
+/**
+ * Provides URIs for direct binary read-access based on the Jackrabbit API 
{@link BinaryDownload}.
+ * 
+ * @see <a 
href="https://jackrabbit.apache.org/oak/docs/features/direct-binary-access.html";>Oak
 Direct Binary Access</a>
+ *
+ */
+@Component(service = URIProvider.class, configurationPolicy = 
ConfigurationPolicy.REQUIRE)
+@Designate(ocd = BinaryDownloadUriProvider.Configuration.class)
+public class BinaryDownloadUriProvider implements URIProvider {

Review comment:
       IIRC the URIProvider interface was exported with the intention that it 
would be implemented in other bundles ensuring that anyone could adapt how 
binaries are downloaded to their needs. There was a lot of discussion at the 
time it was introduced. 
   
   I think it would be better to put this class in its own bundle so that it 
can have a life of its own and does not bind this bundle too tightly to the 
APIs it depends on.   
   
   For example. The BinaryDownloadOptions class is relatively new and has gone 
through a few changes. I would expect it to go through more as more edge cases 
are discovered from real usage. I am expecting it to change in the future.
   
   On ballance, I think this class is better in its own bundle. Is that 
possible ?

##########
File path: 
src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
##########
@@ -227,6 +212,31 @@ private InputStream getInputStream() {
         return null;
     }
 
+    static @NotNull Property getPrimaryProperty(@NotNull Node node) throws 
RepositoryException {

Review comment:
       This code is cleaner than before patch, but for the purposes of 
introducing a URIProvider implementation I dont think its is necessary, unless 
I missed something.
   
   I would recommend that these changes are done in a separate PR if they are 
considered to have benefit worthy of making the change.

##########
File path: 
src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
##########
@@ -181,34 +185,15 @@ private InputStream getInputStream() {
         final Node node = getNode();
         if (node != null) {
             try {
-                // find the content node: for nt:file it is jcr:content
-                // otherwise it is the node of this resource
-                Node content = (node.isNodeType(NT_FILE) ||
-                                (node.isNodeType(NT_FROZEN_NODE) &&
-                                 
node.getProperty(JCR_FROZEN_PRIMARY_TYPE).getString().equals(NT_FILE)))
-                        ? node.getNode(JCR_CONTENT)
-                        : node.isNodeType(NT_LINKED_FILE) ? 
node.getProperty(JCR_CONTENT).getNode() : node;
-
                 Property data;
-
-                // if the node has a jcr:data property, use that property
-                if (content.hasProperty(JCR_DATA)) {
-                    data = content.getProperty(JCR_DATA);
-                } else {
-                    // otherwise try to follow default item trail
-                    try {
-                        Item item = content.getPrimaryItem();
-                        while (item.isNode()) {
-                            item = ((Node) item).getPrimaryItem();
-                        }
-                        data = (Property) item;
-
-                    } catch (ItemNotFoundException infe) {
-                        // we don't actually care, but log for completeness
-                        LOGGER.debug("getInputStream: No primary items for 
{}", toString(), infe);
-                        data = null;
-                    }
+                try {
+                    data = getPrimaryProperty(node);
+                } catch (ItemNotFoundException infe) {
+                    // we don't actually care, but log for completeness
+                    LOGGER.debug("getInputStream: No primary items for {}", 
toString(), infe);
+                    data = null;

Review comment:
       This makes sure that `data` can be passed as null to all URIProvider 
implementations. 
   
   Does the URIProvider API allow nulls in data. I suspect that other 
implementations will throw NPE after this change ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to