public String getResourcePath() { return requestPathInfo.getResourcePath(); }
@Override public String getResourcePath() { return info.getResourcePath(); }
public String getPath() { String resPath; if (replacePath != null) { resPath = replacePath; } else { resPath = originalPathInfo.getResourcePath(); } // According to // http://sling.apache.org/apidocs/sling5/org/apache/sling/api/request/RequestPathInfo.html // it shouldn't contain dot or slash. Unfortunately, sometimes contains - especially if the resource // doesn't exist. if (resPath.contains(".")) { resPath = resPath.substring(0, resPath.indexOf('.')); } return resPath; }
@Override public String getResourcePath() { return isResourcePathOverridden ? resourcePath : getOriginal().getResourcePath(); }
@Override public String getResourcePath() { return isResourcePathOverridden ? resourcePath : getOriginal().getResourcePath(); }
@Override public String getServletPath() { final RequestPathInfo pathInfo = getRequestPathInfo(); return pathInfo.getResourcePath() + "." + pathInfo.getExtension(); } }
url.append(info.getResourcePath()); if (info.getSelectorString() != null) { url.append('.').append(info.getSelectorString());
private String buildUrl(Configuration config, SlingHttpServletRequest request) { final boolean synthetic = ResourceUtil.isSyntheticResource(request.getResource()); final Resource resource = request.getResource(); final StringBuilder builder = new StringBuilder(); final RequestPathInfo pathInfo = request.getRequestPathInfo(); final String resourcePath = pathInfo.getResourcePath(); builder.append(resourcePath); if (pathInfo.getSelectorString() != null) { builder.append('.').append(sanitize(pathInfo.getSelectorString())); } builder.append('.').append(config.getIncludeSelector()); builder.append('.').append(pathInfo.getExtension()); if (synthetic) { builder.append('/').append(resource.getResourceType()); } else { builder.append(sanitize(pathInfo.getSuffix())); } return builder.toString(); }
public boolean dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException, RepositoryException { if (request.getAttribute(VANITY_DISPATCH_CHECK_ATTR) != null) { log.trace("Processing a previously vanity dispatched request. Skipping..."); return false; } request.setAttribute(VANITY_DISPATCH_CHECK_ATTR, true); final String requestURI = request.getRequestURI(); final RequestPathInfo mappedPathInfo = new PathInfo(request.getResourceResolver(), requestURI); final String candidateVanity = mappedPathInfo.getResourcePath(); final String pathScope = StringUtils.removeEnd(requestURI, candidateVanity); log.debug("Candidate vanity URL to check and dispatch: [ {} ]", candidateVanity); // Check if... // 1) the candidateVanity and the requestURI are the same; If they are it means the request has already // gone through resource resolution and failed so there is no sense in sending it through again. // 2) the candidate is in at least 1 sling:vanityPath under /content if (!StringUtils.equals(candidateVanity, requestURI) && isVanityPath(pathScope, candidateVanity, request)) { log.debug("Forwarding request to vanity resource [ {} ]", candidateVanity); final RequestDispatcher requestDispatcher = request.getRequestDispatcher(candidateVanity); requestDispatcher.forward(new ExtensionlessRequestWrapper(request), response); return true; } return false; }
private boolean isEnabled(Configuration config, SlingHttpServletRequest request) { final String requestPath = request.getRequestPathInfo().getResourcePath(); return config.isEnabled() && StringUtils.startsWith(requestPath, config.getBasePath()); }
@Nullable private String getRedirectLocation(SlingHttpServletRequest request, long lastModifiedEpoch) { RequestPathInfo requestPathInfo = request.getRequestPathInfo(); if (request.getResource().isResourceType(IMAGE_RESOURCE_TYPE)) { return Joiner.on('.').join(Text.escapePath(request.getContextPath() + requestPathInfo.getResourcePath()), requestPathInfo.getSelectorString(), requestPathInfo.getExtension() + "/" + lastModifiedEpoch, requestPathInfo.getExtension()); } long lastModifiedSuffix = getRequestLastModifiedSuffix(request.getPathInfo()); String resourcePath = lastModifiedSuffix > 0 ? ResourceUtil.getParent(request.getPathInfo()) : request.getPathInfo(); String extension = FilenameUtils.getExtension(resourcePath); if (StringUtils.isNotEmpty(resourcePath)) { if (StringUtils.isNotEmpty(extension)) { resourcePath = resourcePath.substring(0, resourcePath.length() - extension.length() - 1); } return request.getContextPath() + Text.escapePath(resourcePath) + "/" + lastModifiedEpoch + "." + requestPathInfo.getExtension(); } return null; }
pw.println("<dt>Path</dt>"); pw.print("<dd>"); pw.print(ResponseUtil.escapeXml(requestPathInfo.getResourcePath())); pw.print("<br/>"); pw.print(CONSOLE_PATH_WARNING); if (StringUtils.isNotBlank(requestPathInfo.getResourcePath())) { final Collection<Resource> servlets; Resource resource = resourceResolver.resolve(requestPathInfo.getResourcePath()); if (resource.adaptTo(Servlet.class) != null) { servlets = Collections.singleton(resource);
/** * The externally provided key may be wrapped to add more key elements in order * to restrict the cached object's scope to a specific component when safe mode is enabled. * * @return A request-state sensitive key in {@link Configuration#safeMode()}, the original key otherwise. */ private Object createSafeModeKey(Object key) { // Create a request-state sensitive key to scope the cached model to a request with specific parameters. final SlingHttpServletRequest request = this.requestHolder.get(); if (request == null) { return key; } final RequestPathInfo requestPathInfo = request.getRequestPathInfo(); return new Key(key, new Key(substringBefore(requestPathInfo.getResourcePath(), "/jcr:content"), requestPathInfo.getSelectorString(), requestPathInfo.getExtension(), requestPathInfo.getSuffix(), request.getQueryString())); }