KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > codegen > internal > WebAppGenerator


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

24 package org.enhydra.tool.codegen.internal;
25
26 // Toolbox imports
27
import org.enhydra.tool.codegen.GeneratorException;
28 import org.enhydra.tool.common.PathHandle;
29 import org.enhydra.tool.common.Replacement;
30 import org.enhydra.tool.common.ToolException;
31
32 // Standard imports
33
import java.io.File JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.Arrays JavaDoc;
36 import java.util.ResourceBundle JavaDoc;
37
38 /**
39  * A generator for Servlet 2.2 style Web Applications.
40  */

41 public class WebAppGenerator extends AppGenerator {
42
43     /**
44      * Name to use specify at the command line.
45      */

46     public static final String JavaDoc COMMAND_NAME = "webapp"; // nores
47

48     /**
49      * Descriptive name for generator.
50      */

51     public static final String JavaDoc displayName = res.getString("Web_Application");
52     public static final String JavaDoc wizardTitle =
53         res.getString("Web_Application1");
54
55     /**
56      * Create an instance of the Web Application generator.
57      */

58     public WebAppGenerator() {
59       super();
60     }
61
62     /**
63      * Implements AppGenerator
64      */

65     public String JavaDoc[] getOutputExcludes() {
66         String JavaDoc[] ex = new String JavaDoc[0];
67         ArrayList JavaDoc list = null;
68
69         list = new ArrayList JavaDoc(Arrays.asList(super.getOutputExcludes()));
70
71         // not to be resourced
72
if (getClient().equalsIgnoreCase("chtml") // nores
73
|| getClient().equalsIgnoreCase("wml")) { // nores
74
list.add("index.jsp"); // nores
75
list.add("RedirectServlet.java"); // nores
76
list.add("options.xmlc"); // nores
77
list.add("media" + File.separator + "makefile"); // nores
78
list.add(".gif"); // nores
79
}
80         list.trimToSize();
81         ex = new String JavaDoc[list.size()];
82         ex = (String JavaDoc[]) list.toArray(ex);
83         list.clear();
84         return ex;
85     }
86
87     /**
88      * Overrides AppGenerator
89      */

90     public Replacement[] createReplacementsForDirectory(PathHandle path)
91             throws GeneratorException {
92         Replacement[] reps = new Replacement[0];
93
94         reps = super.createReplacementsForDirectory(path);
95         if (path.endsWith("/presentation")) { // nores
96
ArrayList JavaDoc list = null;
97             String JavaDoc[] targets = new String JavaDoc[1];
98             String JavaDoc[] rules = new String JavaDoc[1];
99             Replacement targetRep = null;
100             Replacement ruleRep = null;
101
102             targets[0] = new String JavaDoc();
103             rules[0] = new String JavaDoc();
104             list = new ArrayList JavaDoc(Arrays.asList(reps));
105             if (getClient().equalsIgnoreCase("chtml")) { // nores
106

107                 // defaults OK
108
} else if (getClient().equalsIgnoreCase("wml")) { // nores
109
targets = new String JavaDoc[2];
110                 rules = new String JavaDoc[1];
111                 targets[0] = new String JavaDoc();
112                 targets[1] = "XMLC_" + getClient().toUpperCase() // nores
113
+ "_OPTS_FILE = options.xmlc"; // nores
114
rules[0] = new String JavaDoc();
115             } else {
116
117                 // HTML 4 Browser
118
targets = new String JavaDoc[5];
119                 rules = new String JavaDoc[4];
120                 targets[0] = "RedirectServlet"; // nores
121
targets[1] = new String JavaDoc();
122                 targets[2] = "SUBDIRS = media"; // nores
123
targets[3] = "XMLC_" + getClient().toUpperCase() // nores
124
+ "_OPTS_FILE = options.xmlc"; // nores
125
targets[4] = "MISC_BUILD = content"; // nores
126
rules[0] = new String JavaDoc();
127                 rules[1] = "content::"; // nores
128
rules[2] = "\t" // nores
129
+ "cp ../resources/index.jsp ${ROOT}/output/content/index.jsp"; // nores
130
rules[3] = new String JavaDoc();
131             }
132             try {
133                 targetRep = new Replacement("@PRESENTATION_TARGETS@", // nores
134
targets);
135                 ruleRep = new Replacement("@PRESENTATION_RULES@",
136                                           rules); // nores
137
list.add(targetRep);
138                 list.add(ruleRep);
139             } catch (ToolException e) {
140                 throw new GeneratorException(e,
141                                              res.getString("Unable_to_create1"));
142             }
143             reps = new Replacement[list.size()];
144             reps = (Replacement[]) list.toArray(reps);
145             list.clear();
146         }
147         return reps;
148     }
149
150     /**
151      * Get short name used in command line. May also be used
152      * to locate template directory.
153      *
154      * @return
155      * Command line identifier.
156      */

157     public String JavaDoc getCommandName() {
158         return COMMAND_NAME;
159     }
160
161     /**
162      * Name to display in command line messages and in the wizard.
163      *
164      * @return
165      * Display name for generator.
166      */

167     public String JavaDoc getDisplayName() {
168         return WebAppGenerator.displayName;
169     }
170
171     public String JavaDoc getWizardTitle() {
172         return WebAppGenerator.wizardTitle;
173     }
174
175     /**
176      * Get text that breifly explains the application that
177      * the generator creates.
178      *
179      * @return
180      * Descriptive text to display in a wizard or in a command
181      * line help response.
182      */

183     public String JavaDoc getDescription() {
184         return res.getString("WebDescript");
185     }
186
187 }
188
Popular Tags