You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2014/06/06 19:37:21 UTC

git commit: DELTASPIKE-630 changed default locale-resolver

Repository: deltaspike
Updated Branches:
  refs/heads/master ef7d358a0 -> e24517ea0


DELTASPIKE-630 changed default locale-resolver


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/e24517ea
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/e24517ea
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/e24517ea

Branch: refs/heads/master
Commit: e24517ea02f4fd0221662a8597db8972ef31e476
Parents: ef7d358
Author: gpetracek <gp...@apache.org>
Authored: Fri Jun 6 19:34:38 2014 +0200
Committer: gpetracek <gp...@apache.org>
Committed: Fri Jun 6 19:34:38 2014 +0200

----------------------------------------------------------------------
 .../impl/message/JsfAwareLocaleResolver.java    | 74 ++++++++++++++++++++
 .../jsf/impl/message/JsfLocaleResolver.java     | 66 -----------------
 .../JsfSupportedLocaleAwareLocaleResolver.java  | 67 ------------------
 3 files changed, 74 insertions(+), 133 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e24517ea/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfAwareLocaleResolver.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfAwareLocaleResolver.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfAwareLocaleResolver.java
new file mode 100644
index 0000000..c7ad93b
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfAwareLocaleResolver.java
@@ -0,0 +1,74 @@
+/*
+ * 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.deltaspike.jsf.impl.message;
+
+import org.apache.deltaspike.core.impl.message.DefaultLocaleResolver;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Specializes;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import java.util.Iterator;
+import java.util.Locale;
+
+@ApplicationScoped
+@Specializes
+public class JsfAwareLocaleResolver extends DefaultLocaleResolver
+{
+    private static final long serialVersionUID = -8776583393262804931L;
+
+    @Override
+    public Locale getLocale()
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        if (facesContext != null)
+        {
+            UIViewRoot viewRoot = facesContext.getViewRoot();
+            Locale result = null;
+            if (viewRoot != null)
+            {
+                // if a ViewRoot is present we return the Locale from there
+                result = viewRoot.getLocale();
+            }
+
+            if (result != null)
+            {
+                Iterator<Locale> supportedLocale = facesContext.getApplication().getSupportedLocales();
+
+                while (supportedLocale.hasNext())
+                {
+                    if (result.equals(supportedLocale.next()))
+                    {
+                        return result;
+                    }
+                }
+            }
+
+            result = facesContext.getApplication().getDefaultLocale();
+
+            if (result != null)
+            {
+                return result;
+            }
+        }
+
+        // return the default Locale, if no Locale was found
+        return super.getLocale();
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e24517ea/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfLocaleResolver.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfLocaleResolver.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfLocaleResolver.java
deleted file mode 100644
index f99b975..0000000
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfLocaleResolver.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.deltaspike.jsf.impl.message;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Specializes;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-
-import java.util.Locale;
-
-import org.apache.deltaspike.core.impl.message.DefaultLocaleResolver;
-
-/**
- * A {@link org.apache.deltaspike.core.api.message.LocaleResolver} which
- * evaluates the {@link UIViewRoot} as well as the default locale configured for JSF as a fallback.
- */
-@ApplicationScoped
-@Specializes
-public class JsfLocaleResolver extends DefaultLocaleResolver
-{
-    @Override
-    public Locale getLocale()
-    {
-        FacesContext facesContext = FacesContext.getCurrentInstance();
-        if (facesContext != null)
-        {
-            UIViewRoot viewRoot = facesContext.getViewRoot();
-            Locale result = null;
-            if (viewRoot != null)
-            {
-                // if a ViewRoot is present we return the Locale from there
-                result = viewRoot.getLocale();
-            }
-
-            if (result == null)
-            {
-                result = facesContext.getApplication().getDefaultLocale();
-            }
-
-            if (result != null)
-            {
-                return result;
-            }
-        }
-
-        // return the default Locale, if no Locale was found
-        return super.getLocale();
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e24517ea/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfSupportedLocaleAwareLocaleResolver.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfSupportedLocaleAwareLocaleResolver.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfSupportedLocaleAwareLocaleResolver.java
deleted file mode 100644
index 677e217..0000000
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfSupportedLocaleAwareLocaleResolver.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.deltaspike.jsf.impl.message;
-
-import org.apache.deltaspike.core.impl.message.DefaultLocaleResolver;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Alternative;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-import java.util.Iterator;
-import java.util.Locale;
-
-@ApplicationScoped
-@Alternative
-public class JsfSupportedLocaleAwareLocaleResolver extends DefaultLocaleResolver
-{
-    @Override
-    public Locale getLocale()
-    {
-        FacesContext facesContext = FacesContext.getCurrentInstance();
-        if (facesContext != null)
-        {
-            UIViewRoot viewRoot = facesContext.getViewRoot();
-            Locale result = null;
-            if (viewRoot != null)
-            {
-                // if a ViewRoot is present we return the Locale from there
-                result = viewRoot.getLocale();
-            }
-
-            if (result != null)
-            {
-                Iterator<Locale> supportedLocale = facesContext.getApplication().getSupportedLocales();
-
-                while (supportedLocale.hasNext())
-                {
-                    if (result.equals(supportedLocale.next()))
-                    {
-                        return result;
-                    }
-                }
-
-                return facesContext.getApplication().getDefaultLocale();
-            }
-        }
-
-        // return the default Locale, if no Locale was found
-        return super.getLocale();
-    }
-}