1 /*
2    Copyright (C) 2008 Red Hat, Inc.
3 
4 This file is part of IcedTea.
5 
6 IcedTea is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 2.
9 
10 IcedTea is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with IcedTea; see the file COPYING.  If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301 USA.
19 
20 Linking this library statically or dynamically with other modules is
21 making a combined work based on this library.  Thus, the terms and
22 conditions of the GNU General Public License cover the whole
23 combination.
24 
25 As a special exception, the copyright holders of this library give you
26 permission to link this library with independent modules to produce an
27 executable, regardless of the license terms of these independent
28 modules, and to copy and distribute the resulting executable under
29 terms of your choice, provided that you also meet, for each linked
30 independent module, the terms and conditions of the license of that
31 module.  An independent module is a module which is not derived from
32 or based on this library.  If you modify this library, you may extend
33 this exception to your version of the library, but you are not
34 obligated to do so.  If you do not wish to do so, delete this
35 exception statement from your version.
36 */
37 package net.sourceforge.jnlp;
38 
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.List;
42 
43 import static net.sourceforge.jnlp.runtime.Translator.R;
44 
45 public class OptionsDefinitions {
46 
47     public static enum OPTIONS {
48 
49         //javaws undocummented swithces
50         TRUSTALL("-Xtrustall","BOTrustall"),
51         //javaws control-options
52         ABOUT("-about", "BOAbout"),
53         VIEWER("-viewer", "BOViewer"),
54         CLEARCACHE("-Xclearcache", "BXclearcache"),
55         LICENSE("-license", "BOLicense"),
56         HELP1("-help", "BOHelp1"),
57         //javaws run-options
58         VERSION("-version", "BOVersion"),
59         ARG("-arg", "arg", "BOArg", NumberOfArguments.ONE_OR_MORE),
60         PARAM("-param", "name=value", "BOParam", NumberOfArguments.ONE_OR_MORE),
61         PROPERTY("-property", "name=value", "BOProperty", NumberOfArguments.ONE_OR_MORE),
62         UPDATE("-update", "seconds", "BOUpdate", NumberOfArguments.ONE),
63         VERBOSE("-verbose", "BOVerbose"),
64         DETAILS("-details", "BOVerbose"), //backward compatibility for itweb settings
65         NOSEC("-nosecurity", "BONosecurity"),
66         NOUPDATE("-noupdate", "BONoupdate"),
67         HEADLESS("-headless", "BOHeadless"),
68         STRICT("-strict", "BOStrict"),
69         XML("-xml", "BOXml"),
70         REDIRECT("-allowredirect", "BOredirect"),
71         NOFORK("-Xnofork", "BXnofork"),
72         NOHEADERS("-Xignoreheaders", "BXignoreheaders"),
73         OFFLINE("-Xoffline", "BXoffline"),
74         TRUSTNONE("-Xtrustnone","BOTrustnone"),
75         JNLP("-jnlp","BOJnlp", NumberOfArguments.ONE),
76         HTML("-html","BOHtml", NumberOfArguments.ONE_OR_MORE),
77         //itweb settings
78         LIST("-list", "IBOList"),
79         GET("-get", "name", "IBOGet", NumberOfArguments.ONE_OR_MORE),
80         INFO("-info", "name", "IBOInfo", NumberOfArguments.ONE_OR_MORE),
81         SET("-set", "name value", "IBOSet", NumberOfArguments.EVEN_NUMBER_SUPPORTS_EQUALS_CHAR),
82         RESETALL("-reset", "all", "IBOResetAll"),
83         RESET("-reset", "name", "IBOReset", NumberOfArguments.ONE_OR_MORE),
84         CHECK("-check", "name", "IBOCheck"),
85         HELP2("-help", "BOHelp2"),
86         //policyeditor
87         //-help
88         FILE("-file", "policy_file", "PBOFile", NumberOfArguments.ONE),
89         DEFAULTFILE("-defaultfile", "PBODefaultFile"),
90         CODEBASE("-codebase", "url", "PBOCodebase", NumberOfArguments.ONE_OR_MORE),
91         ;
92 
93         public final String option;
94 
95         public final String helperString;
96         public final String decriptionKey;
97         private final NumberOfArguments numberOfArguments;
98 
OPTIONS(String option, String helperString, String decriptionKey, NumberOfArguments numberOfArguments)99         OPTIONS(String option, String helperString, String decriptionKey, NumberOfArguments numberOfArguments) {
100             this.decriptionKey = decriptionKey;
101             this.option = option;
102             this.helperString = helperString;
103             this.numberOfArguments = numberOfArguments;
104         }
105 
OPTIONS(String option, String helperString, String decriptionKey)106         OPTIONS(String option, String helperString, String decriptionKey) {
107             this(option, helperString, decriptionKey, NumberOfArguments.NONE);
108         }
109 
OPTIONS(String option, String decriptionKey, NumberOfArguments numberOfArguments)110         OPTIONS(String option, String decriptionKey, NumberOfArguments numberOfArguments) {
111             this(option, "", decriptionKey, numberOfArguments);
112         }
113 
OPTIONS(String option, String decriptionKey)114         OPTIONS(String option, String decriptionKey) {
115             this(option, "", decriptionKey);
116         }
117 
getLocalizedDescription()118         public String getLocalizedDescription() {
119             return R(decriptionKey);
120         }
121 
hasNoArguments()122         public boolean hasNoArguments() {
123             return numberOfArguments == NumberOfArguments.NONE;
124         }
125 
hasEvenNumberSupportingEqualsChar()126         public boolean hasEvenNumberSupportingEqualsChar() {
127             return numberOfArguments == NumberOfArguments.EVEN_NUMBER_SUPPORTS_EQUALS_CHAR;
128         }
129 
hasOneOrMoreArguments()130         public boolean hasOneOrMoreArguments() {
131             return numberOfArguments == NumberOfArguments.ONE_OR_MORE;
132         }
133 
hasOneArgument()134         public boolean hasOneArgument() {
135             return numberOfArguments == NumberOfArguments.ONE;
136         }
137 
getArgumentExplanation()138         public String getArgumentExplanation() {
139             return numberOfArguments.getMessage();
140         }
141     }
142 
143     private enum NumberOfArguments {
144         NONE("NOAnone"),
145         ONE("NOAone"),
146         ONE_OR_MORE("NOAonemore"),
147         EVEN_NUMBER_SUPPORTS_EQUALS_CHAR("NOAevennumber");
148 
149         String messageKey;
150 
NumberOfArguments(String messageKey)151         NumberOfArguments(String messageKey) {
152             this.messageKey = messageKey;
153         }
154 
getMessage()155         public String getMessage() {
156             return R(messageKey);
157         }
158     }
159 
getItwsettingsCommands()160     public static List<OPTIONS> getItwsettingsCommands() {
161         return Arrays.asList(new OPTIONS[]{
162             OPTIONS.HELP2,
163             OPTIONS.LIST,
164             OPTIONS.GET,
165             OPTIONS.INFO,
166             OPTIONS.SET,
167             OPTIONS.RESET,
168             OPTIONS.RESETALL,
169             OPTIONS.HEADLESS,
170             OPTIONS.CHECK,
171             OPTIONS.VERBOSE
172         });
173     }
174 
getPolicyEditorOptions()175     public static List<OPTIONS> getPolicyEditorOptions() {
176         return Arrays.asList(new OPTIONS[]{
177             OPTIONS.HELP1,
178             OPTIONS.DEFAULTFILE,
179             OPTIONS.FILE,
180             OPTIONS.CODEBASE,
181             OPTIONS.VERBOSE
182             }
183         );
184     }
185 
getJavaWsControlOptions()186     public static List<OPTIONS> getJavaWsControlOptions() {
187         return Arrays.asList(new OPTIONS[]{
188             OPTIONS.ABOUT,
189             OPTIONS.VIEWER,
190             OPTIONS.CLEARCACHE,
191             OPTIONS.LICENSE,
192             OPTIONS.HELP1}
193         );
194     }
195 
getJavaWsRuntimeOptions()196     public static List<OPTIONS> getJavaWsRuntimeOptions() {
197         return Arrays.asList(new OPTIONS[]{
198             OPTIONS.VERSION,
199             OPTIONS.ARG,
200             OPTIONS.PARAM,
201             OPTIONS.PROPERTY,
202             OPTIONS.UPDATE,
203             OPTIONS.VERBOSE,
204             OPTIONS.NOSEC,
205             OPTIONS.NOUPDATE,
206             OPTIONS.HEADLESS,
207             OPTIONS.STRICT,
208             OPTIONS.XML,
209             OPTIONS.REDIRECT,
210             OPTIONS.NOFORK,
211             OPTIONS.NOHEADERS,
212             OPTIONS.OFFLINE,
213             OPTIONS.TRUSTNONE,
214             OPTIONS.JNLP,
215             OPTIONS.HTML
216         });
217     }
218 
getJavaWsOptions()219     public static List<OPTIONS> getJavaWsOptions() {
220         List<OPTIONS> l = new ArrayList<>();
221         l.addAll(getJavaWsRuntimeOptions());
222         l.addAll(getJavaWsControlOptions());
223         //trustall is not returned by getJavaWsRuntimeOptions
224         //or getJavaWsControlOptions, as it is not desired in documentation
225         l.add(OPTIONS.TRUSTALL);
226         return l;
227     }
228 
229 
230 }
231