You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2022/03/18 05:55:08 UTC

[sling-org-apache-sling-api] branch master updated: SLING-11214 : Add method to remove a selector to SlingUriBuilder

This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-api.git


The following commit(s) were added to refs/heads/master by this push:
     new 704dfc9  SLING-11214 : Add method to remove a selector to SlingUriBuilder
704dfc9 is described below

commit 704dfc9ce57ef47ca011951c9aea3033fc4bfd43
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Mar 18 06:55:01 2022 +0100

    SLING-11214 : Add method to remove a selector to SlingUriBuilder
---
 .../java/org/apache/sling/api/uri/SlingUriBuilder.java   | 16 ++++++++++++++++
 src/main/java/org/apache/sling/api/uri/package-info.java |  2 +-
 .../org/apache/sling/api/uri/SlingUriBuilderTest.java    | 14 ++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/api/uri/SlingUriBuilder.java b/src/main/java/org/apache/sling/api/uri/SlingUriBuilder.java
index 0a4f603..f5cb76d 100644
--- a/src/main/java/org/apache/sling/api/uri/SlingUriBuilder.java
+++ b/src/main/java/org/apache/sling/api/uri/SlingUriBuilder.java
@@ -459,6 +459,22 @@ public class SlingUriBuilder {
     }
 
     /**
+     * Remove a selector from the URI.
+     *
+     * @param selector the selector to remove
+     * @return the builder for method chaining
+     * @since 1.3 (Sling API Bundle 2.25.0)
+     */
+    @NotNull
+    public SlingUriBuilder removeSelector(@NotNull String selector) {
+        if (schemeSpecificPart != null || resourcePath == null) {
+            return this;
+        }
+        this.selectors.remove(selector);
+        return this;
+    }
+
+    /**
      * Set the extension of the URI.
      * 
      * @param extension the extension
diff --git a/src/main/java/org/apache/sling/api/uri/package-info.java b/src/main/java/org/apache/sling/api/uri/package-info.java
index 7e1e38e..36befcc 100644
--- a/src/main/java/org/apache/sling/api/uri/package-info.java
+++ b/src/main/java/org/apache/sling/api/uri/package-info.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-@Version("1.2.0")
+@Version("1.3.0")
 package org.apache.sling.api.uri;
 
 import org.osgi.annotation.versioning.Version;
diff --git a/src/test/java/org/apache/sling/api/uri/SlingUriBuilderTest.java b/src/test/java/org/apache/sling/api/uri/SlingUriBuilderTest.java
index 2fb984f..2f4bc92 100644
--- a/src/test/java/org/apache/sling/api/uri/SlingUriBuilderTest.java
+++ b/src/test/java/org/apache/sling/api/uri/SlingUriBuilderTest.java
@@ -222,4 +222,18 @@ public class SlingUriBuilderTest {
         assertEquals(0, u1.getSelectors().length);
         assertNull(u1.getSelectorString());
     }
+
+    @Test
+    public void testRemoveSelector() {
+        SlingUri u1 = SlingUriBuilder.parse("/content", null).setSelectors(new String[] {"a","b"}).removeSelector("b").removeSelector("c").build();
+        assertArrayEquals(new String[] {"a"}, u1.getSelectors());
+        assertEquals("a", u1.getSelectorString());
+    }
+
+    @Test
+    public void testAddSelector() {
+        SlingUri u1 = SlingUriBuilder.parse("/content", null).setSelectors(new String[] {"a","b"}).addSelector("c").build();
+        assertArrayEquals(new String[] {"a", "b", "c"}, u1.getSelectors());
+        assertEquals("a.b.c", u1.getSelectorString());
+    }
 }