Sergey Shepelevich pushed to branch release/1.0 at cms-community / 
hippo-configuration-management


Commits:
3511af96 by Sergey Shepelevich at 2017-09-19T09:46:17+02:00
HCM-198 Use JcrPath methods instead of String manipulation

- - - - -


1 changed file:

- model/src/main/java/org/onehippo/cm/model/impl/ConfigurationModelImpl.java


Changes:

=====================================
model/src/main/java/org/onehippo/cm/model/impl/ConfigurationModelImpl.java
=====================================
--- a/model/src/main/java/org/onehippo/cm/model/impl/ConfigurationModelImpl.java
+++ b/model/src/main/java/org/onehippo/cm/model/impl/ConfigurationModelImpl.java
@@ -29,7 +29,6 @@ import java.util.Set;
 import java.util.TreeMap;
 import java.util.stream.Stream;
 
-import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
 import org.onehippo.cm.model.ConfigurationModel;
 import org.onehippo.cm.model.Group;
@@ -265,12 +264,11 @@ public class ConfigurationModelImpl implements 
ConfigurationModel {
 
         final ConfigurationNodeImpl deletedRootNode = 
resolveDeletedSubNodeRoot(path);
         if (deletedRootNode != null) {
-            String commonPrefix = StringUtils.getCommonPrefix(path.toString(), 
deletedRootNode.getJcrPath().toString());
-            int commonSegmentsCount = commonPrefix.split("/").length - 1;
-            final JcrPath subpath = path.subpath(commonSegmentsCount, 
path.getSegmentCount());
+            final JcrPath pathDiff = 
deletedRootNode.getJcrPath().relativize(path);
             ConfigurationNodeImpl currentNode = deletedRootNode;
-            for (final JcrPathSegment jcrPathSegment : subpath) {
-                currentNode = currentNode.getNode(jcrPathSegment);
+            for (final JcrPathSegment jcrPathSegment : pathDiff) {
+                currentNode = 
currentNode.getNodes().getOrDefault(jcrPathSegment.toString(),
+                        
currentNode.getNodes().get(jcrPathSegment.forceIndex().toString()));
                 if (currentNode == null) {
                     break; //wrong path
                 } else if (currentNode.getJcrPath().equals(path)) {



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-configuration-management/commit/3511af963894ff334fae0505263ec705fc89f024

---
View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-configuration-management/commit/3511af963894ff334fae0505263ec705fc89f024
You're receiving this email because of your account on code.onehippo.org.
_______________________________________________
Hippocms-svn mailing list
[email protected]
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to