1 package fr.ifremer.coser.web;
2
3 /*
4 * #%L
5 * Coser :: Web
6 * %%
7 * Copyright (C) 2010 - 2014 Ifremer, Codelutin
8 * %%
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * #L%
22 */
23
24 import com.google.common.base.Preconditions;
25 import fr.ifremer.coser.DefaultCoserApplicationContext;
26 import org.nuiton.i18n.I18n;
27 import org.nuiton.i18n.init.DefaultI18nInitializer;
28
29 /**
30 * Created on 3/11/14.
31 *
32 * @author Tony Chemit <chemit@codelutin.com>
33 * @since 1.5
34 */
35 public class CoserWebApplicationContext extends DefaultCoserApplicationContext {
36
37 /**
38 * Shared application context.
39 */
40 protected static CoserWebApplicationContext context;
41
42 public static CoserWebApplicationContext get() {
43 Preconditions.checkState(context != null, "Application was not initialized!");
44 return context;
45 }
46
47 public static void init() {
48
49 DefaultI18nInitializer i18nInitializer = new DefaultI18nInitializer("coser-i18n");
50 // To see on screen none translated sentences
51 i18nInitializer.setMissingKeyReturnNull(true);
52 I18n.init(i18nInitializer, null);
53
54 context = new CoserWebApplicationContext();
55 }
56
57 public static void close() {
58 context = null;
59 }
60
61 public CoserWebApplicationContext() {
62 super(new CoserWebConfig());
63 }
64
65 @Override
66 public CoserWebConfig getConfig() {
67 return (CoserWebConfig) config;
68 }
69 }