ChecklistExporter { static void ensureNamespaces(final @NotNull Session session, final @NotNull NamespaceMapping namespaces) throws RepositoryException { NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry(); List<String> registered = Arrays.asList(registry.getURIs()); namespaces.getURIToPrefixMapping().entrySet().stream() .filter(entry -> !entry.getKey().isEmpty() && !entry.getValue().isEmpty()) .forEachOrdered(uncheckVoid1(entry -> { if (registered.contains(entry.getKey())) { session.setNamespacePrefix(entry.getValue(), entry.getKey()); } else { registry.registerNamespace(entry.getValue(), entry.getKey()); } })); } private  ChecklistExporter(final List<Op> operations,
                              final List<String> exportTypeDefs,
                              final List<Rule> pathScopes,
                              final List<Rule> nodeTypeFilters,
                              final List<JcrNs> jcrNamespaces); void updateChecklist(final WriterOpener writerOpener,
                                final Session session,
                                final Checklist checklist,
                                final ForcedRootUpdatePolicy updatePolicy); List<ForcedRoot> findRoots(final Session session); static final ForcedRootUpdatePolicy DEFAULT_UPDATE_POLICY; static final String COVARIANT_PREFIX; }
@Test public void testEnsureNamespaces() throws Exception { final NamespaceMapping mapping = JsonCnd.toNamespaceMapping(Arrays.asList( JcrNs.create("", ""), JcrNs.create("foo", "http: JcrNs.create("bar", "http: new OakMachine.Builder() .withInitStage( new InitStage.Builder() .withNs("bar", "http: .build()) .build() .adminInitAndInspect(session -> { final NamespaceRegistry registry = session.getWorkspace() .getNamespaceRegistry(); assertEquals("bar already registered", "bar", registry.getPrefix("http: assertFalse("foo not registered", Arrays.asList(registry.getPrefixes()).contains("foo")); ChecklistExporter.ensureNamespaces(session, mapping); assertTrue("foo registered now", Arrays.asList(registry.getPrefixes()).contains("foo")); assertEquals("bar still registered", "bar", registry.getPrefix("http: assertEquals("foo uri is", "http: }); }