@NotNull @Override public String map(@NotNull String resourcePath) { return wrapped.map(resourcePath); }
@Override public String map(@NotNull HttpServletRequest request, @NotNull String resourcePath) { return wrapped.map(request, resourcePath); }
public final String getAction(final String path, final String formSelector) { String actionPath = path; try (ResourceResolver serviceResourceResolver = resourceResolverFactory.getServiceResourceResolver(AUTH_INFO)){ actionPath = serviceResourceResolver.map(path); } catch (LoginException e) { log.error("Could not attain an admin ResourceResolver to map the Form's Action URI"); // Use the unmapped ActionPath } actionPath += FormHelper.EXTENSION + this.getSuffix(); if (StringUtils.isNotBlank(formSelector)) { actionPath += "/" + formSelector; } return actionPath; }
@Test public void testMapContext() throws Exception { String path = rootNode.getPath(); String mapped = resResolver.map(path); assertEquals(path, mapped); Node child = rootNode.addNode("child"); session.save(); try { // absolute path, expect rootPath segment to be // cut off the mapped path because we map the rootPath // onto root path = "/child"; mapped = resResolver.map(child.getPath()); assertEquals(path, mapped); } finally { child.remove(); session.save(); } }
@Test public void testMapExtensionSuffix() throws Exception { String path = rootNode.getPath(); String mapped = resResolver.map(path); assertEquals(path, mapped); Node child = rootNode.addNode("child"); session.save(); try { // absolute path, expect rootPath segment to be // cut off the mapped path because we map the rootPath // onto root final String selExt = ".html/some/suffx.pdf"; path = "/child" + selExt; mapped = resResolver.map(child.getPath() + selExt); assertEquals(path, mapped); } finally { child.remove(); session.save(); } }
@Test public void testMapQuery() throws Exception { String path = rootNode.getPath(); String mapped = resResolver.map(path); assertEquals(path, mapped); Node child = rootNode.addNode("child"); session.save(); try { // absolute path, expect rootPath segment to be // cut off the mapped path because we map the rootPath // onto root final String selExt = "?a:b=2"; path = "/child" + selExt; mapped = resResolver.map(child.getPath() + selExt); assertEquals(path, mapped); } finally { child.remove(); session.save(); } }
@Test public void testMapFragmentQuery() throws Exception { String path = rootNode.getPath(); String mapped = resResolver.map(path); assertEquals(path, mapped); Node child = rootNode.addNode("child"); session.save(); try { // absolute path, expect rootPath segment to be // cut off the mapped path because we map the rootPath // onto root final String selExt = "#sec:1?a:b=1"; path = "/child" + selExt; mapped = resResolver.map(child.getPath() + selExt); assertEquals(path, mapped); } finally { child.remove(); session.save(); } }
@Test public void testMapExtension() throws Exception { String path = rootNode.getPath(); String mapped = resResolver.map(path); assertEquals(path, mapped); Node child = rootNode.addNode("child"); session.save(); try { // absolute path, expect rootPath segment to be // cut off the mapped path because we map the rootPath // onto root final String selExt = ".html"; path = "/child" + selExt; mapped = resResolver.map(child.getPath() + selExt); assertEquals(path, mapped); } finally { child.remove(); session.save(); } }
@Test public void testMap() throws Exception { String path = rootNode.getPath(); String mapped = resResolver.map(path); assertEquals(path, mapped); Node child = rootNode.addNode("child"); session.save(); try { // absolute path, expect rootPath segment to be // cut off the mapped path because we map the rootPath // onto root path = "/child"; mapped = resResolver.map(child.getPath()); assertEquals(path, mapped); } finally { child.remove(); session.save(); } }
@Test public void testMapSelectorsExtension() throws Exception { String path = rootNode.getPath(); String mapped = resResolver.map(path); assertEquals(path, mapped); Node child = rootNode.addNode("child"); session.save(); try { // absolute path, expect rootPath segment to be // cut off the mapped path because we map the rootPath // onto root final String selExt = ".sel1.sel2.html"; path = "/child" + selExt; mapped = resResolver.map(child.getPath() + selExt); assertEquals(path, mapped); } finally { child.remove(); session.save(); } }
@Test public void testMapExtensionFragmentQuery() throws Exception { String path = rootNode.getPath(); String mapped = resResolver.map(path); assertEquals(path, mapped); Node child = rootNode.addNode("child"); session.save(); try { // absolute path, expect rootPath segment to be // cut off the mapped path because we map the rootPath // onto root final String selExt = ".html#sec:1?a:b=1"; path = "/child" + selExt; mapped = resResolver.map(child.getPath() + selExt); assertEquals(path, mapped); } finally { child.remove(); session.save(); } }
@Test public void testMapFragment() throws Exception { String path = rootNode.getPath(); String mapped = resResolver.map(path); assertEquals(path, mapped); Node child = rootNode.addNode("child"); session.save(); try { // absolute path, expect rootPath segment to be // cut off the mapped path because we map the rootPath // onto root final String selExt = "#sec:1"; path = "/child" + selExt; mapped = resResolver.map(child.getPath() + selExt); assertEquals(path, mapped); } finally { child.remove(); session.save(); } }
private boolean isRootResourceRequest(Resource resource) { return ("/".equals(resource.getPath())) || ("/".equals(resource.getResourceResolver().map(resource.getPath()))); }
@Test public void testMapEmptyPath() throws Exception { String mapped = resResolver.map(""); assertEquals("/", mapped); }
/** * Get a builder instance for a resource using the mapped path on the returned builder. * * @param resource resource * @param mapped if true, link path will be mapped through resource resolver * @return builder containing the mapped path of the given resource */ public static LinkBuilder forResource(final Resource resource, final boolean mapped) { checkNotNull(resource); final String path = resource.getPath(); final String mappedPath = mapped ? resource.getResourceResolver().map(path) : path; return new DefaultLinkBuilder(mappedPath); }
private String getUrl(Configuration config, SlingHttpServletRequest request) { String url = buildUrl(config, request); if (config.isRewritePath()) { url = removeQuestionMark(url); url = request.getResourceResolver().map(request, url); } else { url = encodeJcrContentPart(url); try { url = new URI(null, null, url, null).toASCIIString(); } catch (URISyntaxException e) { LOG.error("Include url is in the wrong format", e); return null; } } return url; }
@Test public void test_resolve_extension_suffix() throws Exception { final String selExt = ".html/some/suffx.pdf"; Node child = rootNode.addNode("child"); session.save(); try { // expect kind due to alias and no parent due to mapping // the rootPath onto root String path = "/child" + selExt; String mapped = resResolver.map(child.getPath() + selExt); assertEquals(path, mapped); Resource res = resResolver.resolve(null, path); Node resNode = res.adaptTo(Node.class); assertNotNull(resNode); assertEquals(child.getPath(), resNode.getPath()); } finally { child.remove(); session.save(); } }
private static String getPagePath(final Page page, final boolean mapped) { final String redirect = page.getProperties().get(REDIRECT_TARGET, ""); final String path = redirect.isEmpty() ? page.getPath() : redirect; final String result; if (mapped) { result = page.adaptTo(Resource.class).getResourceResolver().map(path); } else { result = path; } return result; } }
@Override protected final void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); bulkWorkflowEngine.stopping(request.getResource().adaptTo(Config.class)); response.sendRedirect(request.getResourceResolver().map(request, request.getResource().getPath()) + ".status.json"); } }
@Override protected final void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); bulkWorkflowEngine.stopping(request.getResource().adaptTo(Config.class)); response.sendRedirect(request.getResourceResolver().map(request, request.getResource().getPath()) + ".status.json"); } }