You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2020/09/23 04:26:52 UTC

[GitHub] [sling-org-apache-sling-api] ghenzler commented on a change in pull request #23: SLING-9745 Introduce SlingUri (immutable) and SlingUriBuilder

ghenzler commented on a change in pull request #23:
URL: https://github.com/apache/sling-org-apache-sling-api/pull/23#discussion_r492581484



##########
File path: src/main/java/org/apache/sling/api/uri/SlingUriBuilder.java
##########
@@ -0,0 +1,1024 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.api.uri;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+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;
+import org.osgi.annotation.versioning.ProviderType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Builder for SlingUris.
+ * <p>
+ * Example:
+ * 
+ * <pre>
+ * SlingUri testUri = SlingUriBuilder.create()
+ *         .setResourcePath("/test/to/path")
+ *         .setSelectors(new String[] { "sel1", "sel2" })
+ *         .setExtension("html")
+ *         .setSuffix("/suffix/path")
+ *         .setQuery("par1=val1&amp;par2=val2")
+ *         .build();
+ * </pre>
+ * <p>
+ * 
+ * @since 1.0.0 (Sling API Bundle 2.23.0)
+ */
+@ProviderType
+public class SlingUriBuilder {
+    private static final Logger LOG = LoggerFactory.getLogger(SlingUriBuilder.class);
+
+    private static final String HTTPS_SCHEME = "https";
+    private static final int HTTPS_DEFAULT_PORT = 443;
+    private static final String HTTP_SCHEME = "http";
+    private static final int HTTP_DEFAULT_PORT = 80;
+
+    static final char CHAR_HASH = '#';
+    static final char CHAR_QM = '?';
+    static final char CHAR_AT = '@';
+    static final char CHAR_SEMICOLON = ';';
+    static final char CHAR_EQUALS = '=';
+    static final char CHAR_SINGLEQUOTE = '\'';
+    static final String CHAR_COLON = ":";
+    static final String CHAR_DOT = ".";
+    static final String CHAR_SLASH = "/";
+    static final String SELECTOR_DOT_REGEX = "\\.(?!\\.?/)"; // (?!\\.?/) to avoid matching ./ and ../
+    static final String PATH_PARAMETERS_REGEX = ";([a-zA-z0-9]+)=(?:\\'([^']*)\\'|([^/]+))";
+
+    /**
+     * Creates a builder without any URI parameters set.
+     * 
+     * @return a SlingUriBuilder
+     */
+    public static SlingUriBuilder create() {

Review comment:
       All `@Nullable` / `@NotNull` annotations should be added now.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org