FileVaultNameFinder { public Set<QName> search(final Archive archive) throws Exception { archive.open(false); PrivilegeDefinitions defs = archive.getMetaInf().getPrivileges(); if (defs != null && !defs.getDefinitions().isEmpty()) { NamespaceMapping mapping = defs.getNamespaceMapping(); defs.getDefinitions().forEach(def -> collectPrivilegeDefinition(mapping, def)); } Collection<NodeTypeSet> nodeTypeSets = archive.getMetaInf().getNodeTypes(); for (NodeTypeSet nodeTypeSet : nodeTypeSets) { NamespaceMapping names = nodeTypeSet.getNamespaceMapping(); nodeTypeSet.getNodeTypes().values().forEach(def -> collectNodeTypeNames(names, def)); } Archive.Entry rootEntry = archive.getJcrRoot(); if (rootEntry != null) { this.search(archive, rootEntry); } Set<QName> subtracted = new LinkedHashSet<>(); references.stream() .filter(((Predicate<QName>) definitions::contains).negate()) .forEachOrdered(subtracted::add); return subtracted; } FileVaultNameFinder(); Set<QName> search(final Archive archive);  }
@Test public void test_zip_noReferences() throws Exception { File p = TestPackageUtil.prepareTestPackage("subtest_with_nodetypes.zip"); ZipArchive archive = new ZipArchive(p); FileVaultNameFinder finder = new FileVaultNameFinder(); Set<QName> names = finder.search(archive); LOGGER.info("names: {}", names); assertTrue("name search should be empty", names.isEmpty()); }
@Test public void test_file_oneNtRef() throws Exception { File p = new File("src/test/resources/filevault/oneNtRef"); FileArchive archive = new FileArchive(p); FileVaultNameFinder finder = new FileVaultNameFinder(); Set<QName> names = finder.search(archive); LOGGER.info("names: {}", names); assertEquals("name search should return a single reference", 1, names.size()); }
@Test public void test_file_noReferences() throws Exception { File p = new File("src/test/resources/filevault/noReferences"); FileArchive archive = new FileArchive(p); FileVaultNameFinder finder = new FileVaultNameFinder(); Set<QName> names = finder.search(archive); LOGGER.info("names: {}", names); assertTrue("name search should return no references", names.isEmpty()); }
@Test public void test_file_oneNtRefAndDef() throws Exception { File p = new File("src/test/resources/filevault/oneNtRefAndDef"); FileArchive archive = new FileArchive(p); FileVaultNameFinder finder = new FileVaultNameFinder(); Set<String> names = toStrings(finder.search(archive)); LOGGER.info("names: {}", names); assertEquals("name search should return one nodetype reference", Collections.singleton("foo:mix"), names); }
@Test public void test_file_onePrivRef() throws Exception { File p = new File("src/test/resources/filevault/onePrivRef"); FileArchive archive = new FileArchive(p); FileVaultNameFinder finder = new FileVaultNameFinder(); Set<String> names = toStrings(finder.search(archive)); LOGGER.info("names: {}", names); assertEquals("name search should return one privilege reference", Collections.singleton("foo:canBar"), names); }
@Test public void test_file_onePrivRefAndDef() throws Exception { File p = new File("src/test/resources/filevault/onePrivRefAndDef"); FileArchive archive = new FileArchive(p); FileVaultNameFinder finder = new FileVaultNameFinder(); Set<String> names = toStrings(finder.search(archive)); LOGGER.info("names: {}", names); assertEquals("name search should return one privilege reference", Collections.singleton("crx:replicate"), names); }