NamePathMapperImpl implements NamePathMapper { @Override @NotNull public String getJcrPath(final String oakPath) { if ("/".equals(oakPath)) { return "/"; } else if (oakPath.isEmpty()) { return "."; } else if (nameMapper.getSessionLocalMappings().isEmpty()) { return oakPath; } PathListener listener = new PathListener() { @Override public boolean current() { return false; } @Override public void error(String message) { throw new IllegalArgumentException(message); } @Override public boolean name(String name, int index) { String p = nameMapper.getJcrName(name); if (index == 0) { elements.add(p); } else { elements.add(p + '[' + index + ']'); } return true; } }; JcrPathParser.parse(oakPath, listener); StringBuilder jcrPath = new StringBuilder(); for (String element : listener.elements) { if (element.isEmpty()) { jcrPath.append('/'); } else { jcrPath.append(element); jcrPath.append('/'); } } jcrPath.deleteCharAt(jcrPath.length() - 1); return jcrPath.toString(); } NamePathMapperImpl(NameMapper nameMapper);  NamePathMapperImpl(NameMapper nameMapper, IdentifierManager idManager); @Override String getOakNameOrNull(@NotNull String jcrName); @NotNull @Override String getOakName(@NotNull String jcrName); @NotNull @Override String getJcrName(@NotNull String oakName); @Override @NotNull Map<String, String> getSessionLocalMappings(); @Override String getOakPath(String jcrPath); @Override @NotNull String getJcrPath(final String oakPath);  }
@Test public void testOakToJcr() { assertEquals("/foo:bar", npMapper.getJcrPath("/oak-foo:bar")); assertEquals("/foo:bar/quu:qux", npMapper.getJcrPath("/oak-foo:bar/oak-quu:qux")); assertEquals("foo:bar", npMapper.getJcrPath("oak-foo:bar")); assertEquals(".", npMapper.getJcrPath("")); try { npMapper.getJcrPath("{http: fail("expanded name should not be accepted"); } catch (IllegalArgumentException expected) { } try { npMapper.getJcrPath("foobar/{http: fail("expanded name should not be accepted"); } catch (IllegalArgumentException expected) { } }
@Test public void testInvalidOakPaths() { getJcrPath(" getJcrPath("/foo getJcrPath("/.. getJcrPath("/.."); getJcrPath("/foo/../.."); }