You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2014/07/03 17:38:12 UTC
svn commit: r1607680 - in /sling/trunk/tooling/ide:
api-test/src/test/java/org/apache/sling/ide/transport/ResourceProxyTest.java
api/src/org/apache/sling/ide/transport/ResourceProxy.java
Author: rombert
Date: Thu Jul 3 15:38:11 2014
New Revision: 1607680
URL: http://svn.apache.org/r1607680
Log:
SLING-3710 - Incorrect handling of nt:hierarchyNode instances nested
within jcr:content nodes of other nt:hieararchyNode node
ResourceProxy - validate paths when adding a child
Modified:
sling/trunk/tooling/ide/api-test/src/test/java/org/apache/sling/ide/transport/ResourceProxyTest.java
sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/ResourceProxy.java
Modified: sling/trunk/tooling/ide/api-test/src/test/java/org/apache/sling/ide/transport/ResourceProxyTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api-test/src/test/java/org/apache/sling/ide/transport/ResourceProxyTest.java?rev=1607680&r1=1607679&r2=1607680&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api-test/src/test/java/org/apache/sling/ide/transport/ResourceProxyTest.java (original)
+++ sling/trunk/tooling/ide/api-test/src/test/java/org/apache/sling/ide/transport/ResourceProxyTest.java Thu Jul 3 15:38:11 2014
@@ -88,4 +88,29 @@ public class ResourceProxyTest {
child.addProperty("jcr:primaryType", primaryType);
return child;
}
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addChild_IllegalChildRejected() {
+
+ new ResourceProxy("/content").addChild(new ResourceProxy("/var"));
+ }
+
+ @Test
+ public void addChild_childOfRootNode() {
+
+ new ResourceProxy("/").addChild(new ResourceProxy("/var"));
+ }
+
+ @Test
+ public void addChild_childOfRegularNode() {
+
+ new ResourceProxy("/content").addChild(new ResourceProxy("/content/test"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addChild_deeplyNested() {
+
+ new ResourceProxy("/content").addChild(new ResourceProxy("/content/test/en"));
+ }
+
}
Modified: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/ResourceProxy.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/ResourceProxy.java?rev=1607680&r1=1607679&r2=1607680&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/ResourceProxy.java (original)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/ResourceProxy.java Thu Jul 3 15:38:11 2014
@@ -57,6 +57,12 @@ public class ResourceProxy {
public void addChild(ResourceProxy child) {
+ // TODO - should validate for direct parent
+ if (!isParent(path, child.getPath())) {
+ throw new IllegalArgumentException("Resource at path " + child.getPath() + " is not a direct child of "
+ + path);
+ }
+
this.children.add(child);
}
@@ -109,7 +115,7 @@ public class ResourceProxy {
for (ResourceProxy child : getCoveredChildren()) {
if (child.getPath().equals(path)) {
return true;
- } else if (path.startsWith(child.getPath())) {
+ } else if (isParent(child.getPath(), path)) {
return child.covers(path);
}
}
@@ -117,12 +123,35 @@ public class ResourceProxy {
return false;
}
- // TODO - unit test
+ private boolean isParent(String parentPath, String childPath) {
+
+ boolean isDescendent;
+
+ if (parentPath.equals("/")) {
+ isDescendent = childPath.length() > 1;
+ } else {
+ isDescendent = parentPath.length() < childPath.length() && childPath.charAt(parentPath.length()) == '/'
+ && childPath.startsWith(parentPath);
+ }
+
+ if (!isDescendent) {
+ return false;
+ }
+
+ for (int i = parentPath.length() + 1; i < childPath.length(); i++) {
+ if (childPath.charAt(i) == '/') {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
public ResourceProxy getChild(String path) {
for (ResourceProxy child : getChildren()) {
if (child.getPath().equals(path)) {
return child;
- } else if (path.startsWith(child.getPath())) {
+ } else if (isParent(child.getPath(), path)) {
return child.getChild(path);
}
}