001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Sun Seng David TAN (a.k.a. sunix) <stan@nuxeo.com> 016 * Stephane Lacoin at Nuxeo (aka matic) <slacoin@nuxeo.com> 017 */ 018package org.nuxeo.ecm.platform.web.common.locale; 019 020import org.nuxeo.runtime.model.ComponentInstance; 021import org.nuxeo.runtime.model.DefaultComponent; 022 023/** 024 * Allow external components to provide locale and timezone to be used in the application. 025 * 026 * @since 5.6 027 */ 028public class LocaleComponent extends DefaultComponent { 029 030 protected LocaleProvider provider; 031 032 @Override 033 public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { 034 if ("providers".equals(extensionPoint)) { 035 provider = ((LocaleProviderDescriptor) contribution).newProvider(); 036 } 037 } 038 039 public LocaleProvider getProvider() { 040 return provider; 041 } 042 043 @Override 044 public <T> T getAdapter(Class<T> adapter) { 045 if (LocaleProvider.class.equals(adapter)) { 046 return adapter.cast(provider); 047 } 048 return super.getAdapter(adapter); 049 } 050 051}