KickJava   Java API By Example, From Geeks To Geeks.

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


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: DOMEditCmdOptions.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.DeleteElement;
31 import org.enhydra.xml.xmlc.metadata.MetaData;
32 import org.enhydra.xml.xmlc.metadata.URLMapping;
33 import org.enhydra.xml.xmlc.metadata.URLRegExpMapping;
34
35 /**
36  * Command line options parsing DOM editing options.
37  */

38 class DOMEditCmdOptions extends BaseCmdOptions {
39     /**
40      * Class for -urlmapping option.
41      */

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

46         public UrlMappingOption() {
47             super("-urlmapping", 2, true,
48                   "orgURL newURL - Specify a URL to modify and its new value");
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             URLMapping urlMapping
58                 = ((MetaData)clientData).getDOMEdits().addURLMapping();
59
60             urlMapping.setUrl(args[0]);
61             urlMapping.setNewUrl(args[1]);
62         }
63     }
64
65     /**
66      * Class for -urlsetting option.
67      */

68     private class UrlSettingOption extends Option {
69         /**
70          * Constructor.
71          */

72         public UrlSettingOption() {
73             super("-urlsetting", 2, true,
74                   "id newURL - Specify a URL to set given a tag id");
75         }
76
77         /**
78          * Parse an instance of the option.
79          */

80         protected void parse(String JavaDoc[] args,
81                              ErrorReporter errorReporter,
82                              Object JavaDoc clientData) throws XMLCException {
83             URLMapping urlMapping
84                 = ((MetaData)clientData).getDOMEdits().addURLMapping();
85
86             urlMapping.addElementId(args[0]);
87             urlMapping.setNewUrl(args[1]);
88         }
89     }
90
91     /**
92      * Class for -urlregexpmapping option.
93      */

94     private class UrlRegExpMappingOption extends Option {
95         /**
96          * Constructor.
97          */

98         public UrlRegExpMappingOption () {
99             super("-urlregexpmapping", 2, true,
100                   "regexp replace - Specify a regular expression to match URLs and a replacement pattern");
101         }
102
103         /**
104          * Parse an instance of the option.
105          */

106         protected void parse(String JavaDoc[] args,
107                              ErrorReporter errorReporter,
108                              Object JavaDoc clientData) throws XMLCException {
109             URLRegExpMapping urlRegExpMapping
110                 = ((MetaData)clientData).getDOMEdits().addURLRegExpMapping();
111             urlRegExpMapping.setRegexp(args[0]);
112             urlRegExpMapping.setSubst(args[1]);
113         }
114     }
115
116     /**
117      * Class for -delete-class option.
118      */

119     private class DeleteClassOption extends Option {
120         /**
121          * Constructor.
122          */

123         public DeleteClassOption() {
124             super("-delete-class", 1, true,
125                   "classname - Delete all elements are in the specified class (element class attribute, not Java class)");
126         }
127
128         /**
129          * Parse an instance of the option.
130          */

131         protected void parse(String JavaDoc[] args,
132                              ErrorReporter errorReporter,
133                              Object JavaDoc clientData) throws XMLCException {
134             DeleteElement deleteElement
135                 = ((MetaData)clientData).getDOMEdits().addDeleteElement();
136             deleteElement.addElementClass(args[0]);
137         }
138     }
139
140     /**
141      * Constructor. Add options to option set.
142      */

143     public DOMEditCmdOptions(OptionSet optionSet) {
144         super(optionSet);
145         optionSet.addOption(new UrlMappingOption());
146         optionSet.addOption(new UrlSettingOption());
147     optionSet.addOption(new UrlRegExpMappingOption());
148     optionSet.addOption(new DeleteClassOption());
149     }
150 }
151
Popular Tags