View Javadoc
1   /*
2    * #%L
3    * Coser :: Web
4    * %%
5    * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric, Chemit Tony
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Affero General Public License as published by
9    * the Free Software Foundation, either version 3 of the License, or
10   * (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   * 
17   * You should have received a copy of the GNU Affero General Public License
18   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19   * #L%
20   */
21  
22  package fr.ifremer.coser.web;
23  
24  import fr.ifremer.coser.CoserBusinessConfig;
25  import org.nuiton.config.ConfigOptionDef;
26  import org.nuiton.util.Version;
27  
28  import static org.nuiton.i18n.I18n.n;
29  
30  /**
31   * Coser web configuration.
32   *
33   * @author chatellier
34   * @version $Revision$
35   *          <p/>
36   *          Last update : $Date$
37   *          By : $Author$
38   */
39  public class CoserWebConfig extends CoserBusinessConfig {
40  
41      public CoserWebConfig() {
42          // init configuration with default options
43          loadDefaultOptions(CoserWebOption.values());
44      }
45  
46      public String getApplicationVersion() {
47          String result = getOption(CoserWebOption.APPLICATION_VERSION.key);
48          return result;
49      }
50  
51      /**
52       * Get administrator email.
53       *
54       * @return admin email
55       */
56      public String getAdminEmail() {
57          String result = getOption(CoserWebOption.ADMIN_EMAIL.key);
58          return result;
59      }
60  
61      /**
62       * Get admin login.
63       *
64       * @return admin login
65       */
66      public String getAdminLogin() {
67          String result = getOption(CoserWebOption.ADMIN_LOGIN.key);
68          return result;
69      }
70  
71      /**
72       * Get admin password.
73       *
74       * @return admin password
75       */
76      public String getAdminPassword() {
77          String result = getOption(CoserWebOption.ADMIN_PASSWORD.key);
78          return result;
79      }
80  
81      /**
82       * Get analytics id.
83       *
84       * @return analytics id
85       */
86      public String getAnalyticsId() {
87          String result = getOption(CoserWebOption.ANALYTICS_ID.key);
88          return result;
89      }
90  
91      public enum CoserWebOption implements ConfigOptionDef {
92  
93          /** Context name for multiple deployment. */
94          CONTEXT_NAME(APP_NAME, null, String.class, "coser"),
95          // see : http://www.nuiton.org/issues/1862
96          ENCODING_HACK(CONTEXT_NAME.getDefaultValue() + "." + CONFIG_ENCODING, null, String.class, "UTF-8"),
97          CONFIG_FILE(CONTEXT_NAME.defaultValue + "." + CONFIG_FILE_NAME, n("coser.config.config.file.description"), String.class, "coserweb.properties"),
98          APPLICATION_VERSION("coser.application.version", n("coser.config.application.version.description"), Version.class, null),
99          ADMIN_EMAIL("coser.admin.email", n("coser.config.config.file.description"), String.class, "harmonie@ifremer.fr"),
100         ADMIN_LOGIN("coser.admin.login", n("coser.config.admin.login.description"), String.class, null),
101         ADMIN_PASSWORD("coser.admin.password", n("coser.config.admin.password.description"), String.class, null),
102         ANALYTICS_ID("coser.analytics.id", n("coser.config.analytics.id.description"), String.class, "UA-27739588-1");
103 
104         private final String key;
105 
106         private final String description;
107 
108         private final String defaultValue;
109 
110         private final Class<?> type;
111 
112         private CoserWebOption(String key, String description, Class<?> type, String defaultValue) {
113             this.key = key;
114             this.description = description;
115             this.defaultValue = defaultValue;
116             this.type = type;
117         }
118 
119         public String getDefaultValue() {
120             return defaultValue;
121         }
122 
123         @Override
124         public boolean isTransient() {
125             return false;
126         }
127 
128         @Override
129         public boolean isFinal() {
130             return false;
131         }
132 
133         @Override
134         public void setDefaultValue(String defaultValue) {
135             // not used
136         }
137 
138         @Override
139         public void setTransient(boolean isTransient) {
140             // not used
141         }
142 
143         @Override
144         public void setFinal(boolean isFinal) {
145             // not used
146         }
147 
148         public String getDescription() {
149             return description;
150         }
151 
152         public String getKey() {
153             return key;
154         }
155 
156         @Override
157         public Class<?> getType() {
158             return type;
159         }
160     }
161 }