rombert commented on a change in pull request #18:
URL: 
https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18#discussion_r740103514



##########
File path: 
src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
##########
@@ -478,6 +479,44 @@ public Resource create(final @NotNull 
ResolveContext<JcrProviderState> ctx, fina
         }
     }
 
+    @Override
+    public boolean orderBefore(@NotNull ResolveContext<JcrProviderState> ctx, 
@NotNull Resource parent, @NotNull String name,
+            @Nullable String followingSiblingName) throws PersistenceException 
{
+        Node node = parent.adaptTo(Node.class);
+        try {
+            if (node == null) {
+                throw new PersistenceException("The resource " + 
parent.getPath() + " cannot be adapted to Node. It is probably not provided by 
the JcrResourceProvider");
+            }
+            // check if reordering necessary
+            NodeIterator nodeIterator = node.getNodes();
+            long existingNodePosition = -1;
+            long index = 0;
+            while (nodeIterator.hasNext()) {
+                Node childNode = nodeIterator.nextNode();
+                if (childNode.getName().equals(name)) {
+                    existingNodePosition = index;
+                }
+                if (existingNodePosition >= 0) {

Review comment:
       Does this loop assume that the node named `name` comes first in the 
children list? I am having a bit of a hard time following it.

##########
File path: 
src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
##########
@@ -478,6 +479,44 @@ public Resource create(final @NotNull 
ResolveContext<JcrProviderState> ctx, fina
         }
     }
 
+    @Override
+    public boolean orderBefore(@NotNull ResolveContext<JcrProviderState> ctx, 
@NotNull Resource parent, @NotNull String name,
+            @Nullable String followingSiblingName) throws PersistenceException 
{
+        Node node = parent.adaptTo(Node.class);
+        try {
+            if (node == null) {

Review comment:
       This could be moved outside the try/catch block.




-- 
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