This is an automated email from the ASF dual-hosted git repository. ghenzler pushed a commit to branch feature/SLING-9662-Introduce-Resource-Mapping-SPI-v2 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-api.git
commit 2325681b27413d23c8aa841278aaa6e168104cf0 Author: georg.henzler <[email protected]> AuthorDate: Fri Sep 11 11:57:39 2020 +0200 SLING-9662 Javadoc, avoid increasing version of package org.apache.sling.api.resource --- .../resource/mapping/PathToUriMappingService.java | 15 +++++++------ .../apache/sling/api/resource/package-info.java | 2 +- .../sling/api/resource/uri/ResourceUriBuilder.java | 25 +++++++++++++++------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/apache/sling/api/resource/mapping/PathToUriMappingService.java b/src/main/java/org/apache/sling/api/resource/mapping/PathToUriMappingService.java index 8134699..0defbc3 100644 --- a/src/main/java/org/apache/sling/api/resource/mapping/PathToUriMappingService.java +++ b/src/main/java/org/apache/sling/api/resource/mapping/PathToUriMappingService.java @@ -54,16 +54,17 @@ public interface PathToUriMappingService { Map<String, ResourceUri> getIntermediateMappings(); } - /** Resolves a path relative to the given request. + /** Maps a path to a URI * * @param request - * @param path - * @return a @{link PathToUriMappingService.Result} */ - Result resolve(@Nullable HttpServletRequest request, @NotNull String path); - - /** @param request * @param resourcePath * @return a @{link PathToUriMappingService.Result} */ - Result map(@Nullable HttpServletRequest request, @NotNull String resourcePath); + Result map(@Nullable HttpServletRequest exampleRequest, @NotNull String resourcePath); + /** Resolves a path relative to the given request. + * + * @param request + * @param path + * @return a @{link PathToUriMappingService.Result} */ + Result resolve(@Nullable HttpServletRequest request, @Nullable String path); } \ No newline at end of file diff --git a/src/main/java/org/apache/sling/api/resource/package-info.java b/src/main/java/org/apache/sling/api/resource/package-info.java index ac05b61..7bd85e6 100644 --- a/src/main/java/org/apache/sling/api/resource/package-info.java +++ b/src/main/java/org/apache/sling/api/resource/package-info.java @@ -17,7 +17,7 @@ * under the License. */ -@Version("2.13.0") +@Version("2.12.2") package org.apache.sling.api.resource; import org.osgi.annotation.versioning.Version; diff --git a/src/main/java/org/apache/sling/api/resource/uri/ResourceUriBuilder.java b/src/main/java/org/apache/sling/api/resource/uri/ResourceUriBuilder.java index bc9c4c6..4dd3b65 100644 --- a/src/main/java/org/apache/sling/api/resource/uri/ResourceUriBuilder.java +++ b/src/main/java/org/apache/sling/api/resource/uri/ResourceUriBuilder.java @@ -34,6 +34,8 @@ import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.request.RequestPathInfo; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class ResourceUriBuilder { @@ -90,7 +92,9 @@ public class ResourceUriBuilder { * @param requestPathInfo * @return a ResourceUriBuilder */ public static ResourceUriBuilder createFrom(RequestPathInfo requestPathInfo) { + Resource suffixResource = requestPathInfo.getSuffixResource(); return create() + .setResourceResolver(suffixResource != null ? suffixResource.getResourceResolver() : null) .setResourcePath(requestPathInfo.getResourcePath()) .setSelectors(requestPathInfo.getSelectors()) .setExtension(requestPathInfo.getExtension()) @@ -106,14 +110,17 @@ public class ResourceUriBuilder { .setResourceResolver(request.getResourceResolver()) .setScheme(request.getScheme()) .setHost(request.getServerName()) - .setPort(request.getServerPort()); + .setPort(request.getServerPort()) + .setQuery(request.getQueryString()); } - /** Creates a builder from a URI. + /** Creates a builder from an arbitrary URI. * - * @param uri + * @param uri the uri to transform to a ResourceUri + * @param resourceResolver a resource resolver is needed to decide up to what part the path is the resource path (that decision is only + * possible by checking against the underlying repository). If null is passed in, the shortest viable resource path is used. * @return a ResourceUriBuilder */ - public static ResourceUriBuilder createFrom(URI uri, ResourceResolver resourceResolver) { + public static ResourceUriBuilder createFrom(@NotNull URI uri, @Nullable ResourceResolver resourceResolver) { String path = uri.getPath(); boolean pathExists = !StringUtils.isBlank(path); boolean schemeSpecificRelevant = !pathExists && uri.getQuery() == null; @@ -131,15 +138,17 @@ public class ResourceUriBuilder { /** Creates a builder from an arbitrary URI string. * - * @param resourceUriStr + * @param uriStr to uri string to parse + * @param resourceResolver a resource resolver is needed to decide up to what part the path is the resource path (that decision is only + * possible by checking against the underlying repository). If null is passed in, the shortest viable resource path is used. * @return a ResourceUriBuilder */ - public static ResourceUriBuilder parse(String resourceUriStr, ResourceResolver resourceResolver) { + public static ResourceUriBuilder parse(@NotNull String uriStr, @Nullable ResourceResolver resourceResolver) { URI uri; try { - uri = new URI(resourceUriStr); + uri = new URI(uriStr); return createFrom(uri, resourceResolver); } catch (URISyntaxException e) { - throw new IllegalArgumentException("Invalid URI " + resourceUriStr + ": " + e.getMessage(), e); + throw new IllegalArgumentException("Invalid URI " + uriStr + ": " + e.getMessage(), e); } }
