diff --git a/src/main/java/cn/lihongjie/coal/entity/ResourceEntity.java b/src/main/java/cn/lihongjie/coal/entity/ResourceEntity.java index c119a92c..02f42483 100644 --- a/src/main/java/cn/lihongjie/coal/entity/ResourceEntity.java +++ b/src/main/java/cn/lihongjie/coal/entity/ResourceEntity.java @@ -57,16 +57,10 @@ public class ResourceEntity extends CommonEntity { private Boolean visible; - @Comment("其他数据") private String metadata; - - - - - public void addChildren(ResourceEntity newRs) { // log.info("addChildren1 {} {}", this.getUrl(), newRs.getUrl()); @@ -81,7 +75,7 @@ public class ResourceEntity extends CommonEntity { for (ResourceEntity child : this.children) { - if (newRs.getUrl().startsWith(child.getUrl())) { + if (isChildren(newRs, child)) { child.addChildren(newRs); @@ -119,11 +113,39 @@ public class ResourceEntity extends CommonEntity { } + private boolean isChildren(ResourceEntity c, ResourceEntity p) { + if (!isSamePath(c.getUrl(), p.getUrl())) { + // 判断list是否有相同前缀 + + String[] pl = StringUtils.split(p.getUrl(), "/"); + String[] cl = StringUtils.split(c.getUrl(), "/"); + + for (int i = 0; i < pl.length; i++) { + if (i >= cl.length) { + return false; + } + if (!pl[i].equalsIgnoreCase(cl[i])) { + return false; + } + } + + return true; + + } + return false; + } + + + + + private boolean isSamePath(String a, String b) { return a.equalsIgnoreCase(b) || (a + "/").equalsIgnoreCase(b); } private static String getParent(String path) { + log.info("getParent {}", path); + return "/" + StringUtils.join(Stream.of(StringUtils.split(path, "/")).dropRight(1), "/"); }