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 2013/06/03 11:33:57 UTC
git commit: DELTASPIKE-360 JsfSupportedLocaleAwareLocaleResolver added
Updated Branches:
refs/heads/master d7929a405 -> 4ed338e7c
DELTASPIKE-360 JsfSupportedLocaleAwareLocaleResolver added
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/4ed338e7
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/4ed338e7
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/4ed338e7
Branch: refs/heads/master
Commit: 4ed338e7c441d468fa59e2562fd248abda52065d
Parents: d7929a4
Author: gpetracek <gp...@apache.org>
Authored: Sun Jun 2 21:50:59 2013 +0200
Committer: gpetracek <gp...@apache.org>
Committed: Mon Jun 3 11:33:40 2013 +0200
----------------------------------------------------------------------
.../JsfSupportedLocaleAwareLocaleResolver.java | 67 +++++++++++++++
1 files changed, 67 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4ed338e7/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
new file mode 100644
index 0000000..677e217
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfSupportedLocaleAwareLocaleResolver.java
@@ -0,0 +1,67 @@
+/*
+ * 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();
+ }
+}