KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > webadmin > main > ConfigHTMLWriter


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "OpenEJB" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of The OpenEJB Group. For written permission,
18  * please contact dev@openejb.org.
19  *
20  * 4. Products derived from this Software may not be called "OpenEJB"
21  * nor may "OpenEJB" appear in their names without prior written
22  * permission of The OpenEJB Group. OpenEJB is a registered
23  * trademark of The OpenEJB Group.
24  *
25  * 5. Due credit should be given to the OpenEJB Project
26  * (http://www.openejb.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
42  *
43  * $Id: ConfigHTMLWriter.java 1921 2005-06-19 22:40:34Z jlaskowski $
44  */

45 package org.openejb.webadmin.main;
46
47 import java.io.ByteArrayInputStream JavaDoc;
48 import java.io.IOException JavaDoc;
49 import java.io.PrintWriter JavaDoc;
50 import java.util.Properties JavaDoc;
51
52 import org.openejb.alt.config.Bean;
53 import org.openejb.alt.config.Service;
54 import org.openejb.alt.config.sys.ConnectionManager;
55 import org.openejb.alt.config.sys.Connector;
56 import org.openejb.alt.config.sys.Container;
57 import org.openejb.alt.config.sys.Deployments;
58 import org.openejb.alt.config.sys.JndiProvider;
59 import org.openejb.alt.config.sys.Openejb;
60 import org.openejb.alt.config.sys.ProxyFactory;
61 import org.openejb.alt.config.sys.Resource;
62 import org.openejb.alt.config.sys.SecurityService;
63 import org.openejb.alt.config.sys.TransactionService;
64 import org.openejb.core.EnvProps;
65 import org.openejb.util.HtmlUtilities;
66 import org.openejb.util.StringUtilities;
67
68 /**
69  * This class is a utility for the ConfigBean. It takes care of printing
70  * out all the HTML for the bean.
71  *
72  * @see org.openejb.webadmin.main.ConfigBean
73  * @author <a HREF="mailto:tim_urberg@yahoo.com">Tim Urberg</a>
74  */

75 public class ConfigHTMLWriter {
76     /** create url type */
77     public static final String JavaDoc CREATE = "Create";
78     /** edit url type */
79     public static final String JavaDoc EDIT = "Edit";
80     /** delete url type */
81     public static final String JavaDoc DELETE = "Delete";
82     /** Connector object type */
83     public static final String JavaDoc TYPE_CONNECTOR = "Connector";
84     /** Container object type */
85     public static final String JavaDoc TYPE_CONTAINER = "Container";
86     /** Deployments object type */
87     public static final String JavaDoc TYPE_DEPLOYMENTS = "Deployments";
88     /** JndiProvider object type */
89     public static final String JavaDoc TYPE_JNDI_PROVIDER = "JndiProvider";
90     /** Resource object type */
91     public static final String JavaDoc TYPE_RESOURCE = "Resource";
92     /** Connection Manager object type */
93     public static final String JavaDoc TYPE_CONNECTION_MANAGER = "ConnectionManager";
94     /** Proxy Factory object type */
95     public static final String JavaDoc TYPE_PROXY_FACTORY = "ProxyFactory";
96     /** Securty Service object type */
97     public static final String JavaDoc TYPE_SECURITY_SERVICE = "SecurityService";
98     /** Transaction Service object type */
99     public static final String JavaDoc TYPE_TRANSACTION_SERVICE = "TransactionService";
100     /** type query parameter */
101     public static final String JavaDoc QUERY_PARAMETER_TYPE = "type";
102     /** method query parameter */
103     public static final String JavaDoc QUERY_PARAMETER_METHOD = "method";
104     /** handle file form field name */
105     public static final String JavaDoc FORM_FIELD_HANDLE_FILE = "handleFile";
106     /** id form field name */
107     public static final String JavaDoc FORM_FIELD_ID = "id";
108     /** jar form field name */
109     public static final String JavaDoc FORM_FIELD_JAR = "jar";
110     /** provider form field name */
111     public static final String JavaDoc FORM_FIELD_PROVIDER = "provider";
112     /** container type form field name */
113     public static final String JavaDoc FORM_FIELD_CONTAINER_TYPE = "containerType";
114     /** index form field name */
115     public static final String JavaDoc FORM_FIELD_INDEX = "index";
116     /** deployment type form field name */
117     public static final String JavaDoc FORM_FIELD_DEPLOYMENT_TYPE = "deploymentType";
118     /** deployment text form field name */
119     public static final String JavaDoc FORM_FIELD_DEPLOYMENT_TEXT = "deploymentText";
120     /** JNDI Parameters form field name */
121     public static final String JavaDoc FORM_FIELD_JNDI_PARAMETERS = "jndiParameters";
122     /** content form field name */
123     public static final String JavaDoc FORM_FIELD_CONTENT = "content";
124     /** submit button name for a service page */
125     public static final String JavaDoc FORM_FIELD_SUBMIT_SERVICE = "submitService";
126     /** submit button name for the main openejb page */
127     public static final String JavaDoc FORM_FIELD_SUBMIT_OPENEJB = "submitOpenejb";
128     /** submit button value and label for a connector */
129     public static final String JavaDoc FORM_VALUE_SUBMIT_CONNECTOR = "Submit Connector";
130     /** submit button value and label for a container */
131     public static final String JavaDoc FORM_VALUE_SUBMIT_CONTAINER = "Submit Container";
132     /** submit button value and label for deployments */
133     public static final String JavaDoc FORM_VALUE_SUBMIT_DEPLOYMENTS = "Submit Deployments";
134     /** submit button value and label for a JNDI provider */
135     public static final String JavaDoc FORM_VALUE_SUBMIT_JNDI_PROVIDER = "Submit JNDI Provider";
136     /** submit button value and label for a resource */
137     public static final String JavaDoc FORM_VALUE_SUBMIT_RESOURCE = "Submit Resource";
138     /** submit button value and label for a connection manager */
139     public static final String JavaDoc FORM_VALUE_SUBMIT_CONNECTION_MANAGER = "Submit Connection Manager";
140     /** submit button value and label for a proxy factory */
141     public static final String JavaDoc FORM_VALUE_SUBMIT_PROXY_FACTORY = "Submit Proxy Factory";
142     /** submit button value and label for a security service */
143     public static final String JavaDoc FORM_VALUE_SUBMIT_SECURITY_SERVICE = "Submit Security Service";
144     /** submit button value and label for a transaction service */
145     public static final String JavaDoc FORM_VALUE_SUBMIT_TRANSACTION_SERVICE = "Submit Transaction Service";
146     /** drop down value for a jar deployment type */
147     public static final String JavaDoc DEPLOYMENT_TYPE_JAR = "jar";
148     /** drop down value for a directory deployment type */
149     public static final String JavaDoc DEPLOYMENT_TYPE_DIR = "dir";
150     //link and display for the pop up help
151
private static final String JavaDoc HELP_LINK_HREF = "javascript:popUpHelp('help/config/help.html')";
152     private static final String JavaDoc HELP_LINK_DISPLAY = "(?)";
153
154     private ConfigHTMLWriter() {} //no one should instantate this class
155

156     /**
157      * This method takes care of writing the contents of the Openejb configuration object to
158      * the browser. It takes in an Openejb object, gets all the parts and constructs the HTML
159      *
160      * @see org.openejb.alt.config.sys.Openejb
161      * @param body writes the HTML to the browser
162      * @param openejb the openejb object to write the contents of
163      * @param handle the location of the handle file string
164      * @param configLocation the location of the configuration file
165      */

166     public static void writeOpenejb(PrintWriter JavaDoc body, Openejb openejb, String JavaDoc handle, String JavaDoc configLocation) {
167         //get all the parts of the configuration
168
Connector[] connectors = openejb.getConnector();
169         Container[] containers = openejb.getContainer();
170         Deployments[] deploymentsArray = openejb.getDeployments();
171         JndiProvider[] jndiProviders = openejb.getJndiProvider();
172         Resource[] resources = openejb.getResource();
173         ConnectionManager connectionManager = openejb.getConnectionManager();
174         ProxyFactory proxyFactory = openejb.getProxyFactory();
175         SecurityService securityService = openejb.getSecurityService();
176         TransactionService transactionService = openejb.getTransactionService();
177
178         //print instructions
179
body.println("This page allows you to configure your system. The configuration file being used is:");
180         body.print(configLocation);
181         body.println(". Please pick one of the fields below to continue. If you need help, click on the");
182         body.println("question mark (?) next to the field.<br>");
183
184         body.println(createTableHTMLDecleration());
185         body.println(createTableHTML("Connector", "Container", true));
186
187         //create the connectors
188
if (connectors != null && connectors.length > 0) {
189             body.println(HtmlUtilities.createSelectFormField(TYPE_CONNECTOR, null));
190             for (int i = 0; i < connectors.length; i++) {
191                 body.println(HtmlUtilities.createSelectOption(connectors[i].getId(), connectors[i].getId(), false));
192             }
193             body.println("</select>");
194         } else {
195             body.println("No Connectors");
196         }
197         body.println("</td>\n<td>");
198
199         //create the container list
200
if (containers != null && containers.length > 0) {
201             body.println(HtmlUtilities.createSelectFormField(TYPE_CONTAINER, null));
202             for (int i = 0; i < containers.length; i++) {
203                 body.println(HtmlUtilities.createSelectOption(containers[i].getId(), containers[i].getId(), false));
204             }
205             body.println("</select>");
206         } else {
207             body.println("No Containers");
208         }
209
210         body.println("</td>\n</tr>\n<tr>\n<td>");
211
212         //print the create, edit and delete urls
213
body.println(createCEDUrl(TYPE_CONNECTOR, CREATE));
214         if (connectors != null && connectors.length > 0) {
215             body.println(createCEDUrl(TYPE_CONNECTOR, EDIT));
216             body.println(createCEDUrl(TYPE_CONNECTOR, DELETE));
217         }
218
219         body.println("</td>\n<td>");
220
221         //print the create, edit and delete urls
222
body.println(createCEDUrl(TYPE_CONTAINER, CREATE));
223         if (containers != null && containers.length > 0) {
224             body.println(createCEDUrl(TYPE_CONTAINER, EDIT));
225             body.println(createCEDUrl(TYPE_CONTAINER, DELETE));
226         }
227
228         body.println(createTableHTML("Deployments", "JNDI Provider", false));
229
230         //print the deployments
231
if (deploymentsArray != null & deploymentsArray.length > 0) {
232             body.println(HtmlUtilities.createSelectFormField(TYPE_DEPLOYMENTS, null));
233             String JavaDoc deployment;
234             for (int i = 0; i < deploymentsArray.length; i++) {
235                 if (deploymentsArray[i].getDir() != null) {
236                     deployment = deploymentsArray[i].getDir();
237                 } else {
238                     deployment = deploymentsArray[i].getJar();
239                 }
240                 body.println(HtmlUtilities.createSelectOption(deployment, deployment, false));
241             }
242             body.println("</select>");
243         } else {
244             body.println("No Deployments");
245         }
246         body.println("</td>\n<td>");
247
248         //print the jndi provider list
249
if (jndiProviders != null && jndiProviders.length > 0) {
250             body.println(HtmlUtilities.createSelectFormField(TYPE_JNDI_PROVIDER, null));
251             for (int i = 0; i < jndiProviders.length; i++) {
252                 body.println(HtmlUtilities.createSelectOption(jndiProviders[i].getId(), jndiProviders[i].getId(), false));
253             }
254         } else {
255             body.println("No JNDI Providers");
256         }
257
258         body.println("</td>\n</tr>\n<tr>\n<td>");
259
260         //print the create, edit and delete urls
261
body.println(createCEDUrl(TYPE_DEPLOYMENTS, CREATE));
262         if (deploymentsArray != null & deploymentsArray.length > 0) {
263             body.println(createCEDUrl(TYPE_DEPLOYMENTS, EDIT));
264             body.println(createCEDUrl(TYPE_DEPLOYMENTS, DELETE));
265         }
266
267         body.println("</td>\n<td>");
268
269         //print the create, edit and delete urls
270
body.println(createCEDUrl(TYPE_JNDI_PROVIDER, CREATE));
271         if (jndiProviders != null && jndiProviders.length > 0) {
272             body.println(createCEDUrl(TYPE_JNDI_PROVIDER, EDIT));
273             body.println(createCEDUrl(TYPE_JNDI_PROVIDER, DELETE));
274         }
275
276         body.println(createTableHTML("Resource", "Connection Manager", false));
277
278         //print the resources
279
if (resources != null && resources.length > 0) {
280             body.println(HtmlUtilities.createSelectFormField(TYPE_RESOURCE, null));
281             for (int i = 0; i < resources.length; i++) {
282                 body.println(HtmlUtilities.createSelectOption(resources[i].getId(), resources[i].getId(), false));
283             }
284             body.println("</select>");
285         } else {
286             body.println("No Resources");
287         }
288         body.println("</td>\n<td>");
289
290         if (connectionManager != null) {
291             body.println(connectionManager.getId());
292         } else {
293             body.println("No Connection Manager");
294         }
295
296         //print the create, edit and delete urls
297
body.println("</td>\n</tr>\n<tr>\n<td>");
298         body.println(createCEDUrl(TYPE_RESOURCE, CREATE));
299         if (resources != null && resources.length > 0) {
300             body.println(createCEDUrl(TYPE_RESOURCE, EDIT));
301             body.println(createCEDUrl(TYPE_RESOURCE, DELETE));
302         }
303
304         body.println("</td>\n<td>");
305
306         //print the create, edit and delete urls
307
if (connectionManager == null) {
308             body.println(createCEDUrl(TYPE_CONNECTION_MANAGER, CREATE));
309         } else {
310             body.println(createCEDUrl(TYPE_CONNECTION_MANAGER, EDIT));
311             body.println(createCEDUrl(TYPE_CONNECTION_MANAGER, DELETE));
312         }
313
314         body.println(createTableHTML("Proxy Factory", "Security Service", false));
315
316         if (proxyFactory != null) {
317             body.println(proxyFactory.getId());
318         } else {
319             body.println("No Proxy Factory");
320         }
321
322         body.println("</td>\n<td>");
323
324         if (securityService != null) {
325             body.println(securityService.getId());
326         } else {
327             body.println("No Security Service");
328         }
329
330         body.println("</td>\n</tr>\n<tr>\n<td>");
331
332         //print the create, edit and delete urls
333
if (proxyFactory == null) {
334             body.println(createCEDUrl(TYPE_PROXY_FACTORY, CREATE));
335         } else {
336             body.println(createCEDUrl(TYPE_PROXY_FACTORY, EDIT));
337             body.println(createCEDUrl(TYPE_PROXY_FACTORY, DELETE));
338         }
339
340         //print the create, edit and delete urls
341
body.println("</td>\n<td>");
342         if (securityService == null) {
343             body.println(createCEDUrl(TYPE_SECURITY_SERVICE, CREATE));
344         } else {
345             body.println(createCEDUrl(TYPE_SECURITY_SERVICE, EDIT));
346             body.println(createCEDUrl(TYPE_SECURITY_SERVICE, DELETE));
347         }
348
349         body.println(createTableHTML("Transaction Service", "&nbsp;", false));
350
351         if (transactionService != null) {
352             body.println(transactionService.getId());
353         } else {
354             body.println("No Transaction Service");
355         }
356
357         //print the create, edit and delete urls
358
body.println("</td>\n<td>&nbsp;</td>\n</tr>\n<tr>\n<td>");
359         if (transactionService == null) {
360             body.println(createCEDUrl(TYPE_TRANSACTION_SERVICE, CREATE));
361         } else {
362             body.println(createCEDUrl(TYPE_TRANSACTION_SERVICE, EDIT));
363             body.println(createCEDUrl(TYPE_TRANSACTION_SERVICE, DELETE));
364         }
365
366         //print the buttons and hidden form fields
367
body.println("</td><td>&nbsp;</td></tr>\n<tr>\n<td colspan=\"2\">&nbsp;</td>\n</tr>");
368         body.println("<tr>\n<td colspan=\"2\">");
369         body.println(HtmlUtilities.createSubmitFormButton(FORM_FIELD_SUBMIT_OPENEJB, "Write Changes"));
370         body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_HANDLE_FILE, handle));
371         body.println("</td>\n</tr>\n</table>\n</form>");
372     }
373
374     /**
375      * This method writes out the contents of the Connector object to the
376      * browser
377      *
378      * @see org.openejb.alt.config.sys.Connector
379      * @param body writes the HTML to the browser
380      * @param connector the connector object to write the contents of
381      * @param handle the location of the handle file string
382      * @param index the index of the connector array
383      */

384     public static void writeConnector(PrintWriter JavaDoc body, Connector connector, String JavaDoc handle, int index) throws IOException JavaDoc {
385         String JavaDoc id = "";
386         String JavaDoc jar = "";
387         String JavaDoc provider = "";
388         String JavaDoc jdbcDriver = "";
389         String JavaDoc jdbcUrl = "";
390         String JavaDoc username = "";
391         String JavaDoc password = "";
392         Properties JavaDoc contentProps = new Properties JavaDoc();
393
394         //set the variables to the connector contents if the connector is
395
//not null
396
if (connector != null) {
397             id = StringUtilities.nullToBlankString(connector.getId());
398             jar = StringUtilities.nullToBlankString(connector.getJar());
399             provider = StringUtilities.nullToBlankString(connector.getProvider());
400
401             if (connector.getContent() != null) {
402                 ByteArrayInputStream JavaDoc in =
403                     new ByteArrayInputStream JavaDoc(StringUtilities.nullToBlankString(connector.getContent()).getBytes());
404                 contentProps.load(in);
405             }
406
407             jdbcDriver = contentProps.getProperty(EnvProps.JDBC_DRIVER, "");
408             jdbcUrl = contentProps.getProperty(EnvProps.JDBC_URL, "");
409             username = contentProps.getProperty(EnvProps.USER_NAME, "");
410             password = contentProps.getProperty(EnvProps.PASSWORD, "");
411         }
412
413         //print instructions
414
body.println("Please enter the fields below for a connector. If you need help, click on the question");
415         body.println("mark beside the field. The bold fields are required.<br>");
416
417         //write out the table rows and the fields
418
body.println(createTableHTMLDecleration());
419         body.println(printFormRow("Id", FORM_FIELD_ID, id, 30, true));
420         body.println(printFormRow("Jar", FORM_FIELD_JAR, jar, 30, false));
421         body.println(printFormRow("Provider", FORM_FIELD_PROVIDER, provider, 30, false));
422         body.println(printFormRow("JDBC Driver", EnvProps.JDBC_DRIVER, jdbcDriver, 30, false));
423         body.println(printFormRow("JDBC URL", EnvProps.JDBC_URL, jdbcUrl, 30, false));
424         body.println(printFormRow("Username", EnvProps.USER_NAME, username, 30, false));
425         body.println(printFormRow("Password", EnvProps.PASSWORD, password, 30, false));
426
427         //write out the buttons and hidden form fields
428
body.println("<tr>\n<td colspan=\"2\">&nbsp;</td>\n</tr>");
429         body.print("<tr>\n<td colspan=\"2\">");
430         body.println(HtmlUtilities.createSubmitFormButton(FORM_FIELD_SUBMIT_SERVICE, FORM_VALUE_SUBMIT_CONNECTOR));
431         body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_HANDLE_FILE, handle));
432         body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_INDEX, String.valueOf(index)));
433         body.println("</td>\n</tr>\n</table>\n</form>");
434     }
435
436     /**
437      * This method writes out the contents of the Container object to the
438      * browser
439      *
440      * @see org.openejb.alt.config.sys.Container
441      * @param body writes the HTML to the browser
442      * @param containerData the container to write the contents of
443      * @param handle the location of the handle file string
444      */

445     public static void writeContainer(PrintWriter JavaDoc body, ContainerData containerData, String JavaDoc handle) throws IOException JavaDoc {
446         Properties JavaDoc properties = new Properties JavaDoc();
447         String JavaDoc[] containerTypes = { Bean.CMP_ENTITY, Bean.BMP_ENTITY, Bean.STATEFUL, Bean.STATELESS };
448         String JavaDoc containerType = containerData.getContainerType();
449
450         //print instructions
451
body.println("Please enter the fields below for a container. If you need help, click on the question");
452         body.println("mark beside the field. The bold fields are required.<br>");
453         body.println(createTableHTMLDecleration());
454         body.print("<tr>\n<td><b>Container</b> ");
455         body.print(HtmlUtilities.createAnchor(HELP_LINK_HREF, HELP_LINK_DISPLAY, HtmlUtilities.ANCHOR_HREF_TYPE));
456         body.println("</td>\n<td>");
457
458         //check to see if we're editing or creating a container
459
if (containerData.isEdit()) {
460             //hard code the container type, it can't be changed
461
body.println(containerType);
462             body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_CONTAINER_TYPE, containerType));
463         } else {
464             //create a drop down of container types
465
body.println(
466                 HtmlUtilities.createSelectFormField(FORM_FIELD_CONTAINER_TYPE, "submitForm(this.form, 'Configuration')"));
467             for (int i = 0; i < containerTypes.length; i++) {
468                 body.println(
469                     HtmlUtilities.createSelectOption(
470                         containerTypes[i],
471                         containerTypes[i],
472                         containerTypes[i].equals(containerType)));
473             }
474             body.println("</select>");
475             if ("".equals(containerType))
476                 containerType = Bean.CMP_ENTITY;
477         }
478         body.println("</td>\n</tr>");
479
480         //print the standard service types
481
body.println(printFormRow("Id", FORM_FIELD_ID, containerData.getId(), 30, true));
482         body.println(printFormRow("Jar", FORM_FIELD_JAR, containerData.getJar(), 30, false));
483         body.println(printFormRow("Provider", FORM_FIELD_PROVIDER, containerData.getProvider(), 30, false));
484
485         //check for which type of container we're writing and print out the field types for each one
486
if (Bean.CMP_ENTITY.equals(containerType)) {
487             body.println(
488                 printFormRow(
489                     "Global Database File",
490                     EnvProps.GLOBAL_TX_DATABASE,
491                     containerData.getGlobalTxDatabase(),
492                     35,
493                     true));
494             body.println(
495                 printFormRow(
496                     "Local Database File",
497                     EnvProps.LOCAL_TX_DATABASE,
498                     containerData.getLocalTxDatabase(),
499                     35,
500                     true));
501             body.println(printFormRow("Pool Size", EnvProps.IM_POOL_SIZE, containerData.getPoolSize(), 5, false));
502         } else if (Bean.STATEFUL.equals(containerType)) {
503             body.println(printFormRow("Passivator", EnvProps.IM_PASSIVATOR, containerData.getPassivator(), 35, false));
504             body.println(printFormRow("Time Out", EnvProps.IM_TIME_OUT, containerData.getTimeOut(), 5, false));
505             body.println(printFormRow("Pool Size", EnvProps.IM_POOL_SIZE, containerData.getPoolSize(), 5, false));
506             body.println(
507                 printFormRow("Bulk Passivate", EnvProps.IM_PASSIVATE_SIZE, containerData.getBulkPassivate(), 5, false));
508         } else if (Bean.STATELESS.equals(containerType)) {
509             body.println(printFormRow("Time Out", EnvProps.IM_TIME_OUT, containerData.getTimeOut(), 5, false));
510             body.println(printFormRow("Pool Size", EnvProps.IM_POOL_SIZE, containerData.getPoolSize(), 5, false));
511             body.print("<tr>\n<td>Strict Pooling ");
512             body.print(HtmlUtilities.createAnchor(HELP_LINK_HREF, HELP_LINK_DISPLAY, HtmlUtilities.ANCHOR_HREF_TYPE));
513             body.println("</td>\n<td>");
514             body.println(HtmlUtilities.createSelectFormField(EnvProps.IM_STRICT_POOLING, null));
515             body.println(HtmlUtilities.createSelectOption("true", "true", "true".equals(containerData.getStrictPooling())));
516             body.println(
517                 HtmlUtilities.createSelectOption("false", "false", "false".equals(containerData.getStrictPooling())));
518             body.println("</select>\n</td>\n</tr>");
519         }
520
521         //print out the buttons and hidden form fields
522
body.println("<tr>\n<td colspan=\"2\">&nbsp;</td>\n</tr>");
523         body.print("<tr>\n<td colspan=\"2\">");
524         body.println(HtmlUtilities.createSubmitFormButton(FORM_FIELD_SUBMIT_SERVICE, FORM_VALUE_SUBMIT_CONTAINER));
525         body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_HANDLE_FILE, handle));
526         body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_INDEX, String.valueOf(containerData.getIndex())));
527         body.println("</table>\n</form>");
528     }
529
530     /**
531      * This method writes out the contents of the Resource object to the
532      * browser
533      *
534      * @see org.openejb.alt.config.sys.Container
535      * @param body writes the HTML to the browser
536      * @param resource the resource to write the contents of
537      * @param handle the location of the handle file string
538      * @param index the index of the connector array
539      */

540     public static void writeResource(PrintWriter JavaDoc body, Resource resource, String JavaDoc handle, int index) {
541         String JavaDoc id = "";
542         String JavaDoc jar = "";
543         String JavaDoc provider = "";
544         String JavaDoc jndi = "";
545         String JavaDoc content = "";
546
547         if (resource != null) {
548             id = StringUtilities.nullToBlankString(resource.getId());
549             jar = StringUtilities.nullToBlankString(resource.getJar());
550             provider = StringUtilities.nullToBlankString(resource.getProvider());
551             jndi = StringUtilities.nullToBlankString(resource.getJndi());
552             content = StringUtilities.nullToBlankString(resource.getContent());
553         }
554
555         //print instructions and form fields
556
body.println("Please enter the fields below for a resource. If you need help, click on the question");
557         body.println("mark beside the field. The bold fields are required.<br>");
558         body.println(createTableHTMLDecleration());
559         body.println(printFormRow("Id", FORM_FIELD_ID, id, 30, true));
560         body.println(printFormRow("Jar", FORM_FIELD_JAR, jar, 30, false));
561         body.println(printFormRow("Provider", FORM_FIELD_PROVIDER, provider, 30, false));
562         body.println(printFormRow("JNDI", FORM_FIELD_JNDI_PARAMETERS, jndi, 30, false));
563         body.print("<tr>\n<td valign=\"top\">Content ");
564         body.print(HtmlUtilities.createAnchor(HELP_LINK_HREF, HELP_LINK_DISPLAY, HtmlUtilities.ANCHOR_HREF_TYPE));
565         body.println("</td>\n<td>");
566         body.println(HtmlUtilities.createTextArea(FORM_FIELD_CONTENT, content, 5, 40, null, null, null));
567         body.println("</td>\n</tr>\n<tr>\n<td colspan\"2\">&nbsp;</td>\n</tr>\n<tr>\n<td colspan=\"2\">");
568         body.println(HtmlUtilities.createSubmitFormButton(FORM_FIELD_SUBMIT_SERVICE, FORM_VALUE_SUBMIT_RESOURCE));
569         body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_HANDLE_FILE, handle));
570         body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_INDEX, String.valueOf(index)));
571         body.println("</table>\n</form>");
572
573     }
574
575     /**
576      * This method writes out the contents of the Deployments object to the
577      * browser
578      *
579      * @see org.openejb.alt.config.sys.Deployments
580      * @param body writes the HTML to the browser
581      * @param deployments the deployment info to write to the browser
582      * @param handle the location of the handle file string
583      * @param index the index of the connector array
584      */

585     public static void writeDeployments(PrintWriter JavaDoc body, Deployments deployments, String JavaDoc handle, int index)
586         throws IOException JavaDoc {
587         String JavaDoc jarOrDir = null;
588         boolean isDir = true;
589
590         //loop through the deployments and see if we're printing
591
//a jar or directory
592
if (deployments != null) {
593             if (deployments.getDir() != null) {
594                 jarOrDir = deployments.getDir();
595                 isDir = true;
596             } else if (deployments.getJar() != null) {
597                 jarOrDir = deployments.getJar();
598                 isDir = false;
599             }
600         }
601
602         jarOrDir = StringUtilities.nullToBlankString(jarOrDir);
603
604         //print instructions and deployments information
605
body.println("Please select a Jar or Directory below. This field is required.<br><br>");
606         body.println(createTableHTMLDecleration());
607
608         body.println("<tr>\n<td>");
609         body.println(HtmlUtilities.createSelectFormField(FORM_FIELD_DEPLOYMENT_TYPE, null));
610         body.println(HtmlUtilities.createSelectOption(DEPLOYMENT_TYPE_JAR, "Jar File", !isDir));
611         body.println(HtmlUtilities.createSelectOption(DEPLOYMENT_TYPE_DIR, "Directory", isDir));
612         body.println("</select>\n</td>\n<td>");
613         body.println(HtmlUtilities.createTextFormField(FORM_FIELD_DEPLOYMENT_TEXT, jarOrDir, 30, 0));
614         body.println("</td>\n<tr>\n<td colspan=\"2\">&nbsp;</td>\n</tr>");
615         body.println("</td>\n<tr>\n<td colspan=\"2\">");
616         body.println(HtmlUtilities.createSubmitFormButton(FORM_FIELD_SUBMIT_SERVICE, FORM_VALUE_SUBMIT_DEPLOYMENTS));
617         body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_HANDLE_FILE, handle));
618         body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_INDEX, String.valueOf(index)));
619         body.println("</td>\n</tr>\n</table>\n</form>");
620     }
621
622     /**
623      * This method writes out the contents of a generic service object to the
624      * browser
625      *
626      * @see org.openejb.alt.config.Service
627      * @param body writes the HTML to the browser
628      * @param service the service to write to the browser
629      * @param handle the location of the handle file string
630      * @param submitValue the value/display for the submit button
631      * @param index the index of the connector array
632      */

633     public static void writeService(PrintWriter JavaDoc body, Service service, String JavaDoc handle, String JavaDoc submitValue, int index) {
634         String JavaDoc id = "";
635         String JavaDoc jar = "";
636         String JavaDoc provider = "";
637         String JavaDoc content = "";
638         if (service != null) {
639             id = StringUtilities.nullToBlankString(service.getId());
640             jar = StringUtilities.nullToBlankString(service.getJar());
641             provider = StringUtilities.nullToBlankString(service.getProvider());
642             content = StringUtilities.nullToBlankString(service.getContent());
643         }
644
645         //print instructions and information to the browser
646
body.println("Please enter the fields below. If you need help, click on the question");
647         body.println("mark beside the field. The bold fields are required.<br>");
648         body.println(createTableHTMLDecleration());
649         body.println(printFormRow("Id", FORM_FIELD_ID, id, 30, true));
650         body.println(printFormRow("Jar", FORM_FIELD_JAR, jar, 30, false));
651         body.println(printFormRow("Provider", FORM_FIELD_PROVIDER, provider, 30, false));
652         body.print("<tr>\n<td valign=\"top\">Content ");
653         body.print(HtmlUtilities.createAnchor(HELP_LINK_HREF, HELP_LINK_DISPLAY, HtmlUtilities.ANCHOR_HREF_TYPE));
654         body.println("</td>\n<td>");
655         body.println(HtmlUtilities.createTextArea(FORM_FIELD_CONTENT, content, 5, 40, null, null, null));
656         body.println("</td>\n</tr>\n<tr>\n<td colspan\"2\">&nbsp;</td>\n</tr>\n<tr>\n<td colspan=\"2\">");
657         body.println(HtmlUtilities.createSubmitFormButton(FORM_FIELD_SUBMIT_SERVICE, submitValue));
658         body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_HANDLE_FILE, handle));
659         body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_INDEX, String.valueOf(index)));
660         body.println("</table>\n</form>");
661     }
662
663     /**
664      * This method prints a two column table row with a label in the first
665      * column and a text form field in the second column
666      *
667      * @param label the label for the first column
668      * @param name the name of the text form field
669      * @param value the value of the text form field
670      * @param size the size of the text form field
671      * @param required true if this form field is required
672      * @return the construted HTML table row
673      */

674     private static String JavaDoc printFormRow(String JavaDoc label, String JavaDoc name, String JavaDoc value, int size, boolean required) {
675         StringBuffer JavaDoc temp = new StringBuffer JavaDoc(125).append("<tr>\n<td>");
676
677         if (required) {
678             temp.append("<b>").append(label).append("</b>");
679         } else {
680             temp.append(label);
681         }
682
683         return temp
684             .append(HtmlUtilities.createAnchor(HELP_LINK_HREF, HELP_LINK_DISPLAY, HtmlUtilities.ANCHOR_HREF_TYPE))
685             .append("</td>\n<td>")
686             .append(HtmlUtilities.createTextFormField(name, value, size, 0))
687             .append("</td>\n</tr>\n")
688             .toString();
689     }
690
691     /**
692      * This method creates a url for create, edit or delete.
693      *
694      * @param type the type of url (object type)
695      * @param method the method of the url (create, edit or delete)
696      * @return a HTML url string
697      */

698     private static String JavaDoc createCEDUrl(String JavaDoc type, String JavaDoc method) {
699         StringBuffer JavaDoc temp = new StringBuffer JavaDoc(150);
700
701         //if we're deleting we want to confirm the delete with a Javascript confirm box
702
if (DELETE.equals(method)) {
703             temp
704                 .append("javascript:confirmSubmitForm(document.configForm, 'Configuration?")
705                 .append(QUERY_PARAMETER_TYPE)
706                 .append("=")
707                 .append(type)
708                 .append("&")
709                 .append(QUERY_PARAMETER_METHOD)
710                 .append("=")
711                 .append(method)
712                 .append("', 'Are you sure you want to delete this ")
713                 .append(type)
714                 .append("?\\nNote: changes will not be written until you click the Write Changes button.')");
715         } else {
716             temp
717                 .append("javascript:submitForm(document.configForm, 'Configuration?")
718                 .append(QUERY_PARAMETER_TYPE)
719                 .append("=")
720                 .append(type)
721                 .append("&")
722                 .append(QUERY_PARAMETER_METHOD)
723                 .append("=")
724                 .append(method)
725                 .append("')");
726         }
727
728         return HtmlUtilities.createAnchor(temp.toString(), method, HtmlUtilities.ANCHOR_HREF_TYPE);
729     }
730
731     /**
732      * This is a "helper" method for writing the main Openejb config section
733      * it creates HTML for the "in between" and label sections of the table
734      *
735      * @param label1 the label of the first column
736      * @param label2 the label for the second column
737      * @param isTop this is only true for the first call to this method
738      * @return an HTML string for this table
739      */

740     private static String JavaDoc createTableHTML(String JavaDoc label1, String JavaDoc label2, boolean isTop) {
741         StringBuffer JavaDoc temp = new StringBuffer JavaDoc(225);
742
743         //don't append this for the first call to this method
744
if (!isTop) {
745             temp.append("</td>\n</tr>\n");
746         }
747
748         temp.append("<tr>\n<td colspan=\"2\">&nbsp;</td>\n</tr>\n<tr>\n<td>");
749
750         //we want a blank table cell
751
if ("&nbsp;".equals(label1)) {
752             temp.append(label1);
753         } else {
754             temp.append("<b>").append(label1).append("</b>").append(
755                 HtmlUtilities.createAnchor(HELP_LINK_HREF, HELP_LINK_DISPLAY, HtmlUtilities.ANCHOR_HREF_TYPE));
756         }
757
758         temp.append("</td>\n<td>");
759         //we want a blank table cell
760
if ("&nbsp;".equals(label2)) {
761             temp.append(label2);
762         } else {
763             temp.append("<b>").append(label2).append("</b>").append(
764                 HtmlUtilities.createAnchor(HELP_LINK_HREF, HELP_LINK_DISPLAY, HtmlUtilities.ANCHOR_HREF_TYPE));
765         }
766         temp.append("</td>\n</tr>\n<tr>\n<td>");
767
768         return temp.toString();
769     }
770
771     /**
772      * This method returns the table and form decleration
773      * @return the table and form decleration
774      */

775     private static String JavaDoc createTableHTMLDecleration() {
776         return "<form action=\"Configuration\" method=\"post\" name=\"configForm\">\n"
777             + "<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"430\">";
778     }
779 }
Popular Tags