abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r607814 - in /incubator/abdera/java/trunk: client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java dependencies/i18n/src/main/java/org/apache/abdera/i18n/rfc4646/Lang.java
Date Tue, 01 Jan 2008 07:27:26 GMT
Author: jmsnell
Date: Mon Dec 31 23:27:26 2007
New Revision: 607814

URL: http://svn.apache.org/viewvc?rev=607814&view=rev
Log:
Allow setting the Accept-Language request header using a Locale object

Modified:
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/rfc4646/Lang.java

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java?rev=607814&r1=607813&r2=607814&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java
Mon Dec 31 23:27:26 2007
@@ -21,11 +21,13 @@
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
 import javax.activation.MimeType;
 
+import org.apache.abdera.i18n.rfc4646.Lang;
 import org.apache.abdera.i18n.text.Localizer;
 import org.apache.abdera.i18n.text.UrlEncoding;
 import org.apache.abdera.i18n.text.CharUtils.Profile;
@@ -373,6 +375,18 @@
    */
   public RequestOptions setAccept(String... accept) {
     return setHeader("Accept", combine(accept));
+  }
+  
+  public RequestOptions setAcceptLanguage(Locale locale) {
+    return setAcceptLanguage(Lang.fromLocale(locale));
+  }
+  
+  public RequestOptions setAcceptLanguage(Locale...locales) {
+    String[] langs = new String[locales.length];
+    for (int n = 0; n < locales.length; n++)
+      langs[n] = Lang.fromLocale(locales[n]);
+    setAcceptLanguage(langs);
+    return this;
   }
   
   /**

Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/rfc4646/Lang.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/rfc4646/Lang.java?rev=607814&r1=607813&r2=607814&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/rfc4646/Lang.java
(original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/rfc4646/Lang.java
Mon Dec 31 23:27:26 2007
@@ -396,4 +396,8 @@
     }
     throw new IllegalArgumentException();
   }
+  
+  public static String fromLocale(Locale locale) {
+    return new Lang(locale).toString();
+  }
 }



Mime
View raw message