chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1061804 - in /incubator/chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ chemistry-opencmis-client/chemistry-opencmis-client-bin...
Date Fri, 21 Jan 2011 13:55:04 GMT
Author: fmui
Date: Fri Jan 21 13:55:04 2011
New Revision: 1061804

URL: http://svn.apache.org/viewvc?rev=1061804&view=rev
Log:
added implementation for LOCALE_ISO639_LANGUAGE and LOCALE_ISO3166_COUNTRY … finally

Modified:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/HttpUtils.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/PortProvider.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractService.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/HttpUtils.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/HttpUtils.java?rev=1061804&r1=1061803&r2=1061804&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/HttpUtils.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/HttpUtils.java
Fri Jan 21 13:55:04 2011
@@ -138,6 +138,20 @@ public class HttpUtils {
                 conn.setRequestProperty("Accept-Encoding", "gzip");
             }
 
+            // locale
+            if (session.get(SessionParameter.LOCALE_ISO639_LANGUAGE) instanceof String) {
+                String language = (String) session.get(SessionParameter.LOCALE_ISO639_LANGUAGE);
+                String country = "";
+                if (session.get(SessionParameter.LOCALE_ISO3166_COUNTRY) instanceof String)
{
+                    country = "-" + (String) session.get(SessionParameter.LOCALE_ISO3166_COUNTRY);
+                }
+
+                String acceptLanguage = language + country;
+                if ((acceptLanguage.indexOf('\n') == -1) && (acceptLanguage.indexOf('\r')
== -1)) {
+                    conn.setRequestProperty("Accept-Language", acceptLanguage);
+                }
+            }
+
             // send data
             if (writer != null) {
                 conn.setChunkedStreamingMode(BUFFER_SIZE);

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/PortProvider.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/PortProvider.java?rev=1061804&r1=1061803&r2=1061804&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/PortProvider.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/PortProvider.java
Fri Jan 21 13:55:04 2011
@@ -61,6 +61,7 @@ public class PortProvider extends Abstra
     private static Log log = LogFactory.getLog(PortProvider.class);
 
     private boolean useCompression;
+    private String acceptLanguage;
 
     /**
      * Constructor.
@@ -77,6 +78,19 @@ public class PortProvider extends Abstra
                 && ((Boolean) session.get(SessionParameter.COMPRESSION)).booleanValue())
{
             useCompression = true;
         }
+
+        if (session.get(SessionParameter.LOCALE_ISO639_LANGUAGE) instanceof String) {
+            String language = (String) session.get(SessionParameter.LOCALE_ISO639_LANGUAGE);
+            String country = "";
+            if (session.get(SessionParameter.LOCALE_ISO3166_COUNTRY) instanceof String) {
+                country = "-" + (String) session.get(SessionParameter.LOCALE_ISO3166_COUNTRY);
+            }
+
+            acceptLanguage = language + country;
+            if ((acceptLanguage.indexOf('\n') > -1) || (acceptLanguage.indexOf('\r') >
-1)) {
+                acceptLanguage = null;
+            }
+        }
     }
 
     /**
@@ -135,6 +149,7 @@ public class PortProvider extends Abstra
                 httpHeaders = authProvider.getHTTPHeaders(service.getWSDLDocumentLocation().toString());
             }
 
+            // compression
             if (useCompression) {
                 if (httpHeaders == null) {
                     httpHeaders = new HashMap<String, List<String>>();
@@ -142,6 +157,14 @@ public class PortProvider extends Abstra
                 httpHeaders.put("Accept-Encoding", Collections.singletonList("gzip"));
             }
 
+            // locale
+            if (acceptLanguage != null) {
+                if (httpHeaders == null) {
+                    httpHeaders = new HashMap<String, List<String>>();
+                }
+                httpHeaders.put("Accept-Language", Collections.singletonList(acceptLanguage));
+            }
+
             if (httpHeaders != null) {
                 ((BindingProvider) portObject).getRequestContext()
                         .put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders);

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java?rev=1061804&r1=1061803&r2=1061804&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java
Fri Jan 21 13:55:04 2011
@@ -36,6 +36,8 @@ public interface CallContext {
     String LOCALE = "locale";
     String OFFSET = "offset";
     String LENGTH = "length";
+    String LOCALE_ISO639_LANGUAGE = "language";
+    String LOCALE_ISO3166_COUNTRY = "country";
 
     String SERVLET_CONTEXT = "servletContext";
 

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractService.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractService.java?rev=1061804&r1=1061803&r2=1061804&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractService.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractService.java
Fri Jan 21 13:55:04 2011
@@ -19,6 +19,7 @@
 package org.apache.chemistry.opencmis.server.impl.webservices;
 
 import java.math.BigInteger;
+import java.util.List;
 import java.util.Map;
 
 import javax.servlet.ServletContext;
@@ -92,6 +93,24 @@ public abstract class AbstractService {
                 MessageContext.SERVLET_CONTEXT);
         context.put(CallContext.SERVLET_CONTEXT, servletContext);
 
+        Map<String, List<String>> headers = (Map<String, List<String>>)
wsContext.getMessageContext().get(
+                MessageContext.HTTP_REQUEST_HEADERS);
+        if (headers != null) {
+            for (Map.Entry<String, List<String>> header : headers.entrySet())
{
+                if (header.getKey().equalsIgnoreCase("Accept-Language") && (header.getValue()
!= null)) {
+                    String acceptLanguage = header.getValue().get(0);
+                    if (acceptLanguage != null) {
+                        String[] locale = acceptLanguage.split("-");
+                        context.put(CallContext.LOCALE_ISO639_LANGUAGE, locale[0]);
+                        if (locale.length > 1) {
+                            context.put(CallContext.LOCALE_ISO3166_COUNTRY, locale[1]);
+                        }
+                    }
+                    break;
+                }
+            }
+        }
+
         return context;
     }
 

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java?rev=1061804&r1=1061803&r2=1061804&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
Fri Jan 21 13:55:04 2011
@@ -97,6 +97,16 @@ public class HttpUtils {
             }
         }
 
+        // get locale
+        String acceptLanguage = request.getHeader("Accept-Language");
+        if (acceptLanguage != null) {
+            String[] locale = acceptLanguage.split("-");
+            context.put(CallContext.LOCALE_ISO639_LANGUAGE, locale[0]);
+            if (locale.length > 1) {
+                context.put(CallContext.LOCALE_ISO3166_COUNTRY, locale[1]);
+            }
+        }
+
         return context;
     }
 



Mime
View raw message