BundlorUtils { public static Map<String, PropertyState> getMatchingProperties(Map<String, PropertyState> props, Matcher matcher){ if (!matcher.isMatch()){ return Collections.emptyMap(); } Map<String, PropertyState> result = Maps.newHashMap(); for (Map.Entry<String, PropertyState> e : props.entrySet()){ String propertyPath = e.getKey(); int depth = PathUtils.getDepth(propertyPath) - 1; if (!propertyPath.startsWith(matcher.getMatchedPath())){ continue; } if (depth != matcher.depth()){ continue; } final String newKey = PathUtils.getName(propertyPath); PropertyState value = e.getValue(); if (depth > 0){ value = new PropertyStateWrapper(value){ @NotNull @Override public String getName() { return newKey; } }; } result.put(newKey, value); } return result; }  static Map<String, PropertyState> getMatchingProperties(Map<String, PropertyState> props, Matcher matcher); static Set<String> getChildNodeNames(Collection<String> keys, Matcher matcher); static final Predicate<PropertyState> NOT_BUNDLOR_PROPS; }
@Test public void matchingProperties_Simple() throws Exception{ Map<String, PropertyState> result = BundlorUtils.getMatchingProperties( create("a", "b", "c"), Matcher.NON_MATCHING ); assertTrue(result.isEmpty()); }
@Test public void matchingProperties_BaseLevel() throws Exception{ Matcher m = new Include("jcr:content").createMatcher(); Map<String, PropertyState> result = BundlorUtils.getMatchingProperties( create("a", concat("jcr:content", META_PROP_BUNDLING_PATH), "jcr:content/jcr:data", "jcr:primaryType", META_PROP_PATTERN ), m ); assertThat(result.keySet(), hasItems("a", "jcr:primaryType", META_PROP_PATTERN)); }
@Test public void matchingProperties_FirstLevel() throws Exception{ Matcher m = new Include("jcr:content").createMatcher().next("jcr:content"); Map<String, PropertyState> result = BundlorUtils.getMatchingProperties( create("a", concat("jcr:content", META_PROP_BUNDLING_PATH), "jcr:content/jcr:data", "jcr:content/metadata/format", "jcr:primaryType", META_PROP_PATTERN ), m ); assertThat(result.keySet(), hasItems("jcr:data")); assertEquals("jcr:data", result.get("jcr:data").getName()); }