code: public static Map<String, String> getNamespaces(final Session session) {
          final NamespaceRegistry registry = getNamespaceRegistry(session);
          final Map<String, String> namespaces = new HashMap<>();
  
          try {
              stream(registry.getPrefixes()).filter(internalPrefix.negate()).forEach(x -> {
                  try {
                      namespaces.put(x, registry.getURI(x));
                  } catch (final RepositoryException e) {
                      throw new RepositoryRuntimeException(e);
                  }
              });
          } catch (final RepositoryException e) {
              throw new RepositoryRuntimeException(e);
          }
          return namespaces;
      }
docs: Retrieve the namespaces as a Map
  
  @param session the JCR session to use
  @return a mapping of the prefix to URI