KickJava   Java API By Example, From Geeks To Geeks.

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


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: ParserCmdOptions.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.BooleanOption;
29 import org.enhydra.xml.xmlc.commands.options.Option;
30 import org.enhydra.xml.xmlc.commands.options.OptionSet;
31 import org.enhydra.xml.xmlc.metadata.MetaData;
32 import org.enhydra.xml.xmlc.metadata.ParserType;
33 import org.enhydra.xml.xmlc.metadata.XCatalog;
34
35 /**
36  * Command line options parsing parser options.
37  */

38 class ParserCmdOptions extends BaseCmdOptions {
39     /**
40      * Class for the -parser option.
41      */

42     private class ParserOption extends Option {
43         /**
44          * Constructor.
45          */

46         public ParserOption() {
47             super("-parser", 1, false,
48                   "type - Specify the parser to use (tidy, swing, xerces).");
49         }
50
51         /**
52          * Parse an instance of the option.
53          */

54         protected void parse(String JavaDoc[] args,
55                              ErrorReporter errorReporter,
56                              Object JavaDoc clientData) throws XMLCException {
57             ParserType parser;
58             try {
59                 parser = ParserType.getType(args[0].toLowerCase());
60             } catch (IllegalArgumentException JavaDoc except) {
61                 throw new XMLCException(except.getMessage(),
62                                         except);
63             }
64             ((MetaData)clientData).getParser().setName(parser);
65         }
66     }
67
68     /**
69      * Class for the -xcatalog option.
70      */

71     private class XCatalogOption extends Option {
72         /**
73          * Constructor.
74          */

75         public XCatalogOption() {
76             super("-xcatalog", 1, true,
77                   "catalog - XCatalog file to resolve external entities.");
78         }
79
80         /**
81          * Parse an instance of the option.
82          */

83         protected void parse(String JavaDoc[] args,
84                              ErrorReporter errorReporter,
85                              Object JavaDoc clientData) throws XMLCException {
86             XCatalog xCatalog = ((MetaData)clientData).getParser().addXCatalog();
87             xCatalog.setUrl(args[0]);
88         }
89     }
90
91     /**
92      * Class for the -validate option.
93      */

94     private class ValidateOption extends BooleanOption {
95         /**
96          * Constructor.
97          */

98         public ValidateOption() {
99             super("-validate",
100                   "yes|no|true|false - Changes the default document validation mode of the parser");
101         }
102
103         /**
104          * Set the value.
105          */

106         protected void set(boolean value,
107                            Object JavaDoc clientData) throws XMLCException {
108             ((MetaData)clientData).getParser().setValidate(value ? Boolean.TRUE : Boolean.FALSE);
109         }
110     }
111
112     /**
113      * Constructor. Add options to option set.
114      */

115     public ParserCmdOptions(OptionSet optionSet) {
116         super(optionSet);
117         optionSet.addOption(new ParserOption());
118         optionSet.addOption(new XCatalogOption());
119         optionSet.addOption(new ValidateOption());
120     }
121 }
122
Popular Tags