[java-support] branch master updated: IDP-1464 Add helper function to return the LanguageRange

Rod Widdowson rdw at steadingsoftware.com
Tue Jun 11 05:04:53 EDT 2019


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository java-support.

View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=1267773a634f6c9160d6628a538ee15bf9caf1aa

The following commit(s) were added to refs/heads/master by this push:
       new  1267773   IDP-1464 Add helper function to return the LanguageRange
1267773 is described below

commit 1267773a634f6c9160d6628a538ee15bf9caf1aa
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Jun 7 13:47:07 2019 +0100

    IDP-1464 Add helper function to return the LanguageRange
    
    https://issues.shibboleth.net/jira/browse/IDP-1464
    
    This shims up the LanguageRange#parse()
---
 .../java/support/net/HttpServletSupport.java       | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/main/java/net/shibboleth/utilities/java/support/net/HttpServletSupport.java b/src/main/java/net/shibboleth/utilities/java/support/net/HttpServletSupport.java
index ecf27e0..5156f70 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/net/HttpServletSupport.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/net/HttpServletSupport.java
@@ -18,14 +18,21 @@
 package net.shibboleth.utilities.java.support.net;
 
 import java.net.URI;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale.LanguageRange;
 import java.util.Set;
 
+import javax.annotation.Nonnull;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableList;
 import com.google.common.net.MediaType;
 
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
 /** Utilities for working with HTTP Servlet requests and responses. */
@@ -135,4 +142,19 @@ public final class HttpServletSupport {
                 noContentTypeIsValid, isOneOfStrategy);
     }
     
+    /** Return the {@link LanguageRange} associated with this request.  This
+     * is more up to date than {@link HttpServletRequest#getLocales()}.
+     * @param request the request to process
+     * @return The range.
+     */
+    @Nonnull @NonnullElements @Unmodifiable
+    public static List<LanguageRange> getLanguageRange(final HttpServletRequest request) {
+        
+        final String languages = StringSupport.trimOrNull(request.getHeader("Accept-Language"));
+        if (languages == null) {
+            return Collections.EMPTY_LIST;
+        }
+        return ImmutableList.copyOf(LanguageRange.parse(languages));
+                
+    }
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list