1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.wcm.ui.granite.pathfield.impl.predicate;
21
22 import java.util.Set;
23 import java.util.regex.Pattern;
24
25 import org.apache.commons.collections4.Predicate;
26 import org.apache.commons.lang3.Strings;
27 import org.apache.sling.api.resource.Resource;
28
29
30
31
32 public class HideInternalContentPathsPredicate implements Predicate<Resource> {
33
34
35
36
37
38 private static final Set<String> HIDE_CONTENT_PATHS = Set.of(
39 "/content/catalogs",
40 "/content/cq:tags",
41 "/content/campaigns",
42 "/content/communities",
43 "/content/community",
44 "/content/community-components",
45 "/content/community-templates",
46 "/content/dam",
47 "/content/dam/catalogs",
48 "/content/dam/collections",
49 "/content/dam/formsanddocuments",
50 "/content/dam/formsanddocuments-themes",
51 "/content/dam/templates",
52 "/content/entities",
53 "/content/experience-fragments",
54 "/content/forms",
55 "/content/launches",
56 "/content/mac",
57 "/content/mobileapps",
58 "/content/publications",
59 "/content/usergenerated",
60 "/content/phonegap",
61 "/content/projects",
62 "/content/screens",
63 "/content/sites",
64 "/content/versionhistory");
65
66 private static final Pattern FIRST_LEVEL_PATH = Pattern.compile("^/[^/]+$");
67 private static final String CONTENT_ROOT_PATH = "/content";
68
69 @Override
70 public boolean evaluate(Resource resource) {
71
72 String path = resource.getPath();
73 if (FIRST_LEVEL_PATH.matcher(path).matches()) {
74 return Strings.CS.equals(path, CONTENT_ROOT_PATH);
75 }
76
77 return !HIDE_CONTENT_PATHS.contains(path);
78 }
79
80 }