resolveLocale(javax.servlet.http.HttpServletRequest request);
+
+ /**
+ * Return a non-null
but possibly empty list of
+ * Locale
instances to consider for localization of the current
+ * request. The list returned is assumed to be ordered by preference where
+ * the first entry is the preferred Locale
and the last entry is
+ * the least preferred Locale
.
+ *
+ * Returning an empty list is equivalent to returning a singleton list whose
+ * single entry is the {@link ResourceBundleProvider#getDefaultLocale()}.
+ *
+ * @param request The HttpServletRequest
providing hints
+ * and information for the Locale
resolution.
+ * @return The list of Locale
s to use for internationalization
+ * of request processing
+ * @since 2.3
+ */
+ default List resolveLocale(jakarta.servlet.http.HttpServletRequest request) {
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/src/main/java/org/apache/sling/i18n/package-info.java b/src/main/java/org/apache/sling/i18n/package-info.java
index c729ae7..f286a8c 100644
--- a/src/main/java/org/apache/sling/i18n/package-info.java
+++ b/src/main/java/org/apache/sling/i18n/package-info.java
@@ -17,7 +17,7 @@
* under the License.
*/
-@org.osgi.annotation.versioning.Version("2.2.1")
+@org.osgi.annotation.versioning.Version("2.3.0")
package org.apache.sling.i18n;
diff --git a/src/test/java/org/apache/sling/i18n/DefaultLocaleResolverTest.java b/src/test/java/org/apache/sling/i18n/DefaultLocaleResolverTest.java
new file mode 100644
index 0000000..1bf14e6
--- /dev/null
+++ b/src/test/java/org/apache/sling/i18n/DefaultLocaleResolverTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.i18n;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ *
+ */
+public class DefaultLocaleResolverTest {
+
+ private DefaultLocaleResolver localeResolver = new DefaultLocaleResolver();
+
+ /**
+ * Test method for {@link org.apache.sling.i18n.DefaultLocaleResolver#resolveLocale(org.apache.sling.api.SlingHttpServletRequest)}.
+ */
+ @Test
+ public void testResolveLocaleSlingHttpServletRequest() {
+ SlingHttpServletRequest req = Mockito.mock(SlingHttpServletRequest.class);
+ Mockito.doReturn(Collections.enumeration(Arrays.asList(Locale.ENGLISH, Locale.GERMAN)))
+ .when(req).getLocales();
+ List locales = localeResolver.resolveLocale(req);
+ assertNotNull(locales);
+ assertEquals(2, locales.size());
+ }
+
+ /**
+ * Test method for {@link org.apache.sling.i18n.DefaultLocaleResolver#resolveLocale(javax.servlet.http.HttpServletRequest)}.
+ */
+ @Test
+ public void testResolveLocaleHttpServletRequest() {
+ javax.servlet.http.HttpServletRequest req = Mockito.mock(javax.servlet.http.HttpServletRequest.class);
+ Mockito.doReturn(Collections.enumeration(Arrays.asList(Locale.ENGLISH, Locale.GERMAN)))
+ .when(req).getLocales();
+ List locales = localeResolver.resolveLocale(req);
+ assertNotNull(locales);
+ assertEquals(2, locales.size());
+ }
+
+ /**
+ * Test method for {@link org.apache.sling.i18n.DefaultLocaleResolver#resolveLocale(jakarta.servlet.http.HttpServletRequest)}.
+ */
+ @Test
+ public void testResolveLocaleHttpServletRequest1() {
+ jakarta.servlet.http.HttpServletRequest req = Mockito.mock(jakarta.servlet.http.HttpServletRequest.class);
+ Mockito.doReturn(Collections.enumeration(Arrays.asList(Locale.ENGLISH, Locale.GERMAN)))
+ .when(req).getLocales();
+ List locales = localeResolver.resolveLocale(req);
+ assertNotNull(locales);
+ assertEquals(2, locales.size());
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/i18n/RequestLocaleResolverTest.java b/src/test/java/org/apache/sling/i18n/RequestLocaleResolverTest.java
new file mode 100644
index 0000000..d9bdd47
--- /dev/null
+++ b/src/test/java/org/apache/sling/i18n/RequestLocaleResolverTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.i18n;
+
+import static org.junit.Assert.assertThrows;
+
+import java.util.List;
+import java.util.Locale;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ *
+ */
+public class RequestLocaleResolverTest {
+
+ /**
+ * Test method for {@link org.apache.sling.i18n.RequestLocaleResolver#resolveLocale(jakarta.servlet.http.HttpServletRequest)}.
+ */
+ @Test
+ public void testResolveLocaleHttpServletRequest() {
+ RequestLocaleResolver requestLocaleResolver = new RequestLocaleResolver() {
+ @Override
+ public List resolveLocale(javax.servlet.http.HttpServletRequest request) {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ jakarta.servlet.http.HttpServletRequest jakartaReq = Mockito.mock(jakarta.servlet.http.HttpServletRequest.class);
+ assertThrows(UnsupportedOperationException.class, () -> requestLocaleResolver.resolveLocale(jakartaReq));
+ }
+
+}