KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > commands > xmlc > HTMLCmdOptions


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: HTMLCmdOptions.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.commands.xmlc;
25
26 import org.enhydra.xml.io.ErrorReporter;
27 import org.enhydra.xml.xmlc.XMLCException;
28 import org.enhydra.xml.xmlc.commands.options.Option;
29 import org.enhydra.xml.xmlc.commands.options.OptionSet;
30 import org.enhydra.xml.xmlc.metadata.HTMLAttr;
31 import org.enhydra.xml.xmlc.metadata.HTMLCompatibility;
32 import org.enhydra.xml.xmlc.metadata.HTMLTag;
33 import org.enhydra.xml.xmlc.metadata.HTMLTagSet;
34 import org.enhydra.xml.xmlc.metadata.HTMLTagSetType;
35 import org.enhydra.xml.xmlc.metadata.MetaData;
36
37 /**
38  * Command line options parsing for -html:* options.
39  */

40 class HTMLCmdOptions extends BaseCmdOptions {
41     /**
42      * Class for the -html:encoding option.
43      */

44     private class HTMLEncodingOption extends Option {
45         /**
46          * Construct a new object.
47          */

48         public HTMLEncodingOption() {
49             super("-html:encoding", 1, false,
50                   "encoding - Specify the encoding to use when reading a HTML document.");
51         }
52
53         /**
54          * Parse the option.
55          */

56         public void parse(String JavaDoc[] args,
57                           ErrorReporter errorReporter,
58                           Object JavaDoc clientData) throws XMLCException {
59             ((MetaData)clientData).getHTMLSection().setEncoding(args[0]);
60         }
61     }
62
63     /**
64      * Parser for deprecated -html:frameset option.
65      */

66     private class HTMLFrameSetOption extends Option {
67         /**
68          * Constructor.
69          */

70         public HTMLFrameSetOption() {
71             super("-html:frameset", 0, false,
72                   "- Deprecated and ignored.");
73         }
74
75         /**
76          * Parse an instance of the option.
77          */

78         protected void parse(String JavaDoc[] args,
79                              ErrorReporter errorReporter,
80                              Object JavaDoc clientData) throws XMLCException {
81             errorReporter.warning("The -html:frameset option is deprecated and ignored");
82         }
83     }
84
85     /**
86      * Class for -html:old-class-constants option
87      */

88     private class HTMLOldClassConstantsOption extends Option {
89         /**
90          * Constructor.
91          */

92         public HTMLOldClassConstantsOption() {
93             super("-html:old-class-constants", 0, false,
94                   "- Generate old-style, all upper-case class constants");
95         }
96
97         /**
98          * Parse an instance of the option.
99          */

100         protected void parse(String JavaDoc[] args,
101                              ErrorReporter errorReporter,
102                              Object JavaDoc clientData) throws XMLCException {
103             HTMLCompatibility compat = ((MetaData)clientData).getHTMLSection().getCreateCompatibility();
104             compat.setOldClassConstants(true);
105             errorReporter.warning("The " + getName()
106                                   + " option will be deprecated in a future release, please update your code");
107         }
108     }
109
110     /**
111      * Class for -html:old-name-constants option
112      */

113     private class HTMLOldNameConstantsOption extends Option {
114         /**
115          * Constructor.
116          */

117         public HTMLOldNameConstantsOption() {
118             super("-html:old-name-constants", 0, false,
119                   "- Generate old-style, all upper-case name constants");
120         }
121
122         /**
123          * Parse an instance of the option.
124          */

125         protected void parse(String JavaDoc[] args,
126                              ErrorReporter errorReporter,
127                              Object JavaDoc clientData) throws XMLCException {
128             HTMLCompatibility compat
129                 = ((MetaData)clientData).getHTMLSection().getCreateCompatibility();
130             compat.setOldNameConstants(true);
131             errorReporter.warning("The " + getName()
132                                   + " option will be deprecated in a future release, please update your code");
133         }
134     }
135
136     /**
137      * Class for the -html:addtagset option.
138      */

139     private class HTMLAddTagSetOption extends Option {
140         /**
141          * Construct a new object.
142          */

143         public HTMLAddTagSetOption() {
144             super("-html:addtagset", 1, true,
145                   "tagsetname - Add a predefined set of proprietary tags to the list of valid HTML tags.");
146         }
147
148         /**
149          * Parse an instance of the option and set the field in the Options
150          * object using Java reflection.
151          *
152          * @param args The option's arguments. Should have one.
153          */

154         public void parse(String JavaDoc[] args,
155                           ErrorReporter errorReporter,
156                           Object JavaDoc clientData) throws XMLCException {
157             HTMLTagSet tagSet = ((MetaData)clientData).getHTMLSection().addHTMLTagSet();
158             try {
159                 tagSet.setTagSet(HTMLTagSetType.getType(args[0]));
160             } catch (IllegalArgumentException JavaDoc except) {
161                 throw new XMLCException(except.getMessage(),
162                                         except);
163             }
164         }
165     }
166
167     /**
168      * Class for the -html:addtag option.
169      */

170     private class HTMLAddTagOption extends Option {
171         /**
172          * Construct a new object.
173          */

174         public HTMLAddTagOption() {
175             super("-html:addtag", 2, true,
176                 "tagname flags - Add a proprietary tag to the list of valid HTML tags.");
177         }
178
179         /**
180          * Parse the flags representing the content model.
181          */

182         private void parseFlags(String JavaDoc flagsStr,
183                                 HTMLTag tag) throws XMLCException {
184             // Split list at commas and convert to bit set.
185
int startIdx = 0;
186             while (startIdx < flagsStr.length()) {
187                 int nextIdx = flagsStr.indexOf(',', startIdx);
188                 if (nextIdx < 0) {
189                     nextIdx = flagsStr.length(); // End of string
190
}
191                 String JavaDoc flagStr = flagsStr.substring(startIdx, nextIdx);
192                 if (flagStr.equalsIgnoreCase("inline")) {
193                     tag.setInline(true);
194                 } else if (flagStr.equalsIgnoreCase("block")) {
195                     tag.setBlock(true);
196                 } else if (flagStr.equalsIgnoreCase("empty")) {
197                     tag.setEmpty(true);
198                 } else if (flagStr.equalsIgnoreCase("opt")) {
199                     tag.setOptclose(true);
200                 } else {
201                     throw new XMLCException("Invaild flag for " + name
202                                             + " \"" + flagStr + "\"");
203                 }
204                 startIdx = nextIdx+1;
205             }
206         }
207
208         /**
209          * Parse an instance of the option and set the field in the Options
210          * object using Java reflection.
211          *
212          * @param args The option's arguments. Should have one.
213          */

214         public void parse(String JavaDoc[] args,
215                           ErrorReporter errorReporter,
216                           Object JavaDoc clientData) throws XMLCException {
217             HTMLTag tag = ((MetaData)clientData).getHTMLSection().addHTMLTag();
218             tag.setName(args[0]);
219             parseFlags(args[1], tag);
220         }
221     }
222
223     /**
224      * Class for the -html:addattr option.
225      */

226     private class HTMLAddAttrOption extends Option {
227         /**
228          * Construct a new object.
229          */

230         public HTMLAddAttrOption() {
231             super("-html:addattr", 1, true,
232                 "attrname - Add a proprietary attribute the list of valid HTML attributes.");
233         }
234
235         /**
236          * Parse an instance of the option and set the field in the Options
237          * object using Java reflection.
238          *
239          * @param args The option's arguments. Should have one.
240          */

241         public void parse(String JavaDoc[] args,
242                           ErrorReporter errorReporter,
243                           Object JavaDoc clientData) throws XMLCException {
244             HTMLAttr attr = ((MetaData)clientData).getHTMLSection().addHTMLAttr();
245             attr.setName(args[0]);
246         }
247     }
248
249     /**
250      * Constructor. Add options to option set.
251      */

252     public HTMLCmdOptions(OptionSet optionSet) {
253         super(optionSet);
254         optionSet.addOption(new HTMLFrameSetOption());
255         optionSet.addOption(new HTMLEncodingOption());
256         optionSet.addOption(new HTMLAddTagSetOption());
257         optionSet.addOption(new HTMLAddTagOption());
258         optionSet.addOption(new HTMLAddAttrOption());
259         optionSet.addOption(new HTMLOldClassConstantsOption());
260         optionSet.addOption(new HTMLOldNameConstantsOption());
261     }
262 }
263
Popular Tags