From commits-return-66641-archive-asf-public=cust-asf.ponee.io@sling.apache.org Tue Apr 24 09:44:56 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id B0EC7180671 for ; Tue, 24 Apr 2018 09:44:55 +0200 (CEST) Received: (qmail 56749 invoked by uid 500); 24 Apr 2018 07:44:54 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 56740 invoked by uid 99); 24 Apr 2018 07:44:54 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Apr 2018 07:44:54 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id CBBDF809DC; Tue, 24 Apr 2018 07:44:53 +0000 (UTC) Date: Tue, 24 Apr 2018 07:44:53 +0000 To: "commits@sling.apache.org" Subject: [sling-org-apache-sling-scripting-sightly] branch master updated: SLING-7589 - HTL doesn't correctly handle synthetic resource inclusions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <152455589379.1214.688912694190970532@gitbox.apache.org> From: radu@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: sling-org-apache-sling-scripting-sightly X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 36bbbc1d47670f23933160a2eb95e4135d88f12f X-Git-Newrev: f46ff4d97b96d21da521651fe9f789f89253452f X-Git-Rev: f46ff4d97b96d21da521651fe9f789f89253452f X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. radu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly.git The following commit(s) were added to refs/heads/master by this push: new f46ff4d SLING-7589 - HTL doesn't correctly handle synthetic resource inclusions f46ff4d is described below commit f46ff4d97b96d21da521651fe9f789f89253452f Author: Radu Cotescu <170911+raducotescu@users.noreply.github.com> AuthorDate: Tue Apr 24 09:44:51 2018 +0200 SLING-7589 - HTL doesn't correctly handle synthetic resource inclusions * fall back to the request's resource type if the resourceType option doesn't provide any information --- .../engine/extension/ResourceRuntimeExtension.java | 41 ++++++++++++---------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java index 924f9ea..2450637 100644 --- a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java +++ b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java @@ -62,7 +62,6 @@ public class ResourceRuntimeExtension implements RuntimeExtension { private static final String OPTION_SELECTORS = "selectors"; private static final String OPTION_REMOVE_SELECTORS = "removeSelectors"; private static final String OPTION_ADD_SELECTORS = "addSelectors"; - private static final String OPTION_REPLACE_SELECTORS = "replaceSelectors"; private static final String OPTION_REQUEST_ATTRIBUTES = "requestAttributes"; @Override @@ -77,13 +76,12 @@ public class ResourceRuntimeExtension implements RuntimeExtension { SlingHttpServletRequest request = BindingsUtils.getRequest(bindings); Map originalAttributes = ExtensionUtils.setRequestAttributes(request, (Map)options.remove(OPTION_REQUEST_ATTRIBUTES)); RuntimeObjectModel runtimeObjectModel = renderContext.getObjectModel(); - String resourceType = runtimeObjectModel.toString(getAndRemoveOption(opts, OPTION_RESOURCE_TYPE)); StringWriter writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); if (pathObj instanceof Resource) { Resource includedResource = (Resource) pathObj; - RequestDispatcherOptions requestDispatcherOptions = handleSelectors(request, new LinkedHashSet(), opts, runtimeObjectModel); - includeResource(bindings, printWriter, includedResource, requestDispatcherOptions, resourceType); + RequestDispatcherOptions requestDispatcherOptions = handleDispatcherOptions(request, new LinkedHashSet(), opts, runtimeObjectModel); + includeResource(bindings, printWriter, includedResource, requestDispatcherOptions); } else { String includePath = runtimeObjectModel.toString(pathObj); // build path completely @@ -94,26 +92,26 @@ public class ResourceRuntimeExtension implements RuntimeExtension { PathInfo pathInfo; if (includedResource != null) { RequestDispatcherOptions requestDispatcherOptions = - handleSelectors(request, new LinkedHashSet(), opts, runtimeObjectModel); - includeResource(bindings, printWriter, includedResource, requestDispatcherOptions, resourceType); + handleDispatcherOptions(request, new LinkedHashSet(), opts, runtimeObjectModel); + includeResource(bindings, printWriter, includedResource, requestDispatcherOptions); } else { // analyse path and decompose potential selectors from the path pathInfo = new PathInfo(includePath); - RequestDispatcherOptions requestDispatcherOptions = handleSelectors(request, pathInfo.selectors, opts, runtimeObjectModel); - includeResource(bindings, printWriter, pathInfo.path, requestDispatcherOptions, resourceType); + RequestDispatcherOptions requestDispatcherOptions = handleDispatcherOptions(request, pathInfo.selectors, opts, runtimeObjectModel); + includeResource(bindings, printWriter, pathInfo.path, requestDispatcherOptions); } } else { // use the current resource - RequestDispatcherOptions requestDispatcherOptions = handleSelectors(request, new LinkedHashSet(), opts, runtimeObjectModel); - includeResource(bindings, printWriter, request.getResource(), requestDispatcherOptions, resourceType); + RequestDispatcherOptions requestDispatcherOptions = handleDispatcherOptions(request, new LinkedHashSet(), opts, runtimeObjectModel); + includeResource(bindings, printWriter, request.getResource(), requestDispatcherOptions); } } ExtensionUtils.setRequestAttributes(request, originalAttributes); return writer.toString(); } - private RequestDispatcherOptions handleSelectors(SlingHttpServletRequest request, Set selectors, Map options, - RuntimeObjectModel runtimeObjectModel) { + private RequestDispatcherOptions handleDispatcherOptions(SlingHttpServletRequest request, Set selectors, Map options, + RuntimeObjectModel runtimeObjectModel) { RequestDispatcherOptions requestDispatcherOptions = new RequestDispatcherOptions(); if (selectors.isEmpty()) { selectors.addAll(Arrays.asList(request.getRequestPathInfo().getSelectors())); @@ -159,6 +157,12 @@ public class ResourceRuntimeExtension implements RuntimeExtension { requestDispatcherOptions.setReplaceSelectors(""); } } + if (options.containsKey(OPTION_RESOURCE_TYPE)) { + String resourceType = runtimeObjectModel.toString(getAndRemoveOption(options, OPTION_RESOURCE_TYPE)); + if (StringUtils.isNotEmpty(resourceType)) { + requestDispatcherOptions.setForceResourceType(resourceType); + } + } return requestDispatcherOptions; } @@ -232,28 +236,29 @@ public class ResourceRuntimeExtension implements RuntimeExtension { return StringUtils.isNotEmpty(selectorString) ? selectorString : null; } - private void includeResource(final Bindings bindings, PrintWriter out, String path, RequestDispatcherOptions requestDispatcherOptions, String resourceType) { + private void includeResource(final Bindings bindings, PrintWriter out, String path, RequestDispatcherOptions requestDispatcherOptions) { if (StringUtils.isEmpty(path)) { throw new SightlyException("Resource path cannot be empty"); } else { SlingHttpServletRequest request = BindingsUtils.getRequest(bindings); Resource includeRes = request.getResourceResolver().resolve(path); if (ResourceUtil.isNonExistingResource(includeRes)) { + String resourceType = request.getResource().getResourceType(); + if (requestDispatcherOptions.containsKey(RequestDispatcherOptions.OPT_FORCE_RESOURCE_TYPE)) { + resourceType = requestDispatcherOptions.getForceResourceType(); + } includeRes = new SyntheticResource(request.getResourceResolver(), path, resourceType); } - includeResource(bindings, out, includeRes, requestDispatcherOptions, resourceType); + includeResource(bindings, out, includeRes, requestDispatcherOptions); } } - private void includeResource(final Bindings bindings, PrintWriter out, Resource includeRes, RequestDispatcherOptions requestDispatcherOptions, String resourceType) { + private void includeResource(final Bindings bindings, PrintWriter out, Resource includeRes, RequestDispatcherOptions requestDispatcherOptions) { if (includeRes == null) { throw new SightlyException("Resource cannot be null"); } else { SlingHttpServletResponse customResponse = new PrintWriterResponseWrapper(out, BindingsUtils.getResponse(bindings)); SlingHttpServletRequest request = BindingsUtils.getRequest(bindings); - if (StringUtils.isNotEmpty(resourceType)) { - requestDispatcherOptions.setForceResourceType(resourceType); - } RequestDispatcher dispatcher = request.getRequestDispatcher(includeRes, requestDispatcherOptions); try { if (dispatcher != null) { -- To stop receiving notification emails like this one, please contact radu@apache.org.