View Javadoc
1   /*
2    * #%L
3    * JRst :: Api
4    * %%
5    * Copyright (C) 2011 CodeLutin, Chatellier Eric
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 3 of the 
10   * License, or (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 Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20   * #L%
21   */
22  
23  package org.nuiton.jrst;
24  
25  import static org.nuiton.i18n.I18n.t;
26  import static org.nuiton.i18n.I18n.n;
27  
28  import java.io.File;
29  
30  import org.nuiton.config.ApplicationConfig;
31  import org.nuiton.config.ConfigOptionDef;
32  
33  /**
34   * JRST options enum.
35   * 
36   * @author chatellier
37   */
38  public enum JRSTConfigOption implements ConfigOptionDef {
39  
40      FORCE("force", n("jrst.option.force"), "false", String.class, true, false),
41      SIMPLE("simple", n("jrst.option.simple"), "false", String.class, true, false),
42      OUT_FILE("outFile", n("jrst.option.outfile"), null, String.class, true, false),
43      OUT_TYPE("outType", n("jrst.option.outtype"), null, String.class, true, false),
44      XSL_FILE("xslFile", n("jrst.option.xslfile"), null, String.class, true, false),
45      INTERMEDIATE_FILE("intermediateFile", n("jrst.option.intermediatefile"), JRST.TYPE_XHTML,
46              String.class, true, false);
47  
48      public String key;
49      public String description;
50      public String defaultValue;
51      public Class<?> type;
52      public boolean isTransient;
53      public boolean isFinal;
54      public String[] alias;
55  
56      private JRSTConfigOption(String key, String description,
57              String defaultValue, Class<?> type, boolean isTransient, boolean isFinal, String... alias) {
58          this.key = key;
59          this.description = description;
60          this.defaultValue = defaultValue;
61          this.type = type;
62          this.isTransient = isTransient;
63          this.isFinal = isFinal;
64          this.alias = alias;
65      }
66  
67      @Override
68      public boolean isFinal() {
69          return isFinal;
70      }
71  
72      @Override
73      public boolean isTransient() {
74          return isTransient;
75      }
76  
77      @Override
78      public String getDefaultValue() {
79          return defaultValue;
80      }
81  
82      @Override
83      public String getDescription() {
84          return t(description);
85      }
86  
87      @Override
88      public String getKey() {
89          return key;
90      }
91  
92      @Override
93      public Class<?> getType() {
94          return type;
95      }
96  
97      @Override
98      public void setDefaultValue(String defaultValue) {
99          this.defaultValue = defaultValue;
100     }
101 
102     @Override
103     public void setTransient(boolean isTransient) {
104         this.isTransient = isTransient;
105     }
106 
107     @Override
108     public void setFinal(boolean isFinal) {
109         this.isFinal = isFinal;
110     }
111 
112     public String[] getAlias() {
113         return alias;
114     }
115     
116     public String getOption(ApplicationConfig config) {
117         String result = config.getOption(getKey());
118         return result;
119     }
120     
121     public File getOptionAsFile(ApplicationConfig config) {
122         File result = config.getOptionAsFile(getKey());
123         return result;
124     }
125     
126     public boolean getOptionAsBoolean(ApplicationConfig config) {
127         boolean result = config.getOptionAsBoolean(getKey());
128         return result;
129     }
130 }