Return-Path: X-Original-To: apmail-deltaspike-commits-archive@www.apache.org Delivered-To: apmail-deltaspike-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2233D1125A for ; Fri, 6 Jun 2014 17:37:22 +0000 (UTC) Received: (qmail 32682 invoked by uid 500); 6 Jun 2014 17:37:22 -0000 Delivered-To: apmail-deltaspike-commits-archive@deltaspike.apache.org Received: (qmail 32655 invoked by uid 500); 6 Jun 2014 17:37:22 -0000 Mailing-List: contact commits-help@deltaspike.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@deltaspike.apache.org Delivered-To: mailing list commits@deltaspike.apache.org Received: (qmail 32648 invoked by uid 99); 6 Jun 2014 17:37:22 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Jun 2014 17:37:22 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id BB5878BA82D; Fri, 6 Jun 2014 17:37:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gpetracek@apache.org To: commits@deltaspike.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: DELTASPIKE-630 changed default locale-resolver Date: Fri, 6 Jun 2014 17:37:21 +0000 (UTC) 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 Authored: Fri Jun 6 19:34:38 2014 +0200 Committer: gpetracek 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 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 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(); - } -}