KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > context > ContextForm


1 /*
2  * Copyright 2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.webapp.admin.context;
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import org.apache.struts.action.ActionError;
22 import org.apache.struts.action.ActionErrors;
23 import org.apache.struts.action.ActionForm;
24 import org.apache.struts.action.ActionMapping;
25 import java.util.List JavaDoc;
26
27 /**
28  * Form bean for the context page.
29  *
30  * @author Manveen Kaur
31  * @version $Revision: 1.8 $ $Date: 2005/01/14 23:55:41 $
32  */

33
34 public final class ContextForm extends ActionForm {
35     
36     // ----------------------------------------------------- Instance Variables
37

38    /**
39      * The administrative action represented by this form.
40      */

41     private String JavaDoc adminAction = "Edit";
42
43     /**
44      * The object name of the Context this bean refers to.
45      */

46     private String JavaDoc objectName = null;
47    
48     /**
49      * The object name of the parent of this Context.
50      */

51     private String JavaDoc parentObjectName = null;
52    
53    /**
54      * The object name of the loader of this Context.
55      */

56     private String JavaDoc loaderObjectName = null;
57    
58     /**
59      * The object name of the manager of this Context.
60      */

61     private String JavaDoc managerObjectName = null;
62    
63     /**
64      * The text for the node label.
65      */

66     private String JavaDoc nodeLabel = null;
67     
68     /**
69      * The value of cookies.
70      */

71     private String JavaDoc cookies = "false";
72     
73     /**
74      * The value of cross context.
75      */

76     private String JavaDoc crossContext = "false";
77     
78     /**
79      * The text for the document Base.
80      */

81     private String JavaDoc docBase = null;
82     
83     /**
84      * The text for override boolean.
85      */

86     private String JavaDoc override = "false";
87     
88     /**
89      * The text for privileged boolean.
90      */

91     private String JavaDoc privileged = "false";
92     
93     /**
94      * The text for the context path for this context.
95      */

96     private String JavaDoc path = null;
97     
98     /**
99      * The text for reloadable boolean.
100      */

101     private String JavaDoc reloadable = "false";
102
103     /**
104      * The text for swallowOutput boolean.
105      */

106     private String JavaDoc swallowOutput = "false";
107
108     /**
109      * The text for use naming boolean.
110      */

111     private String JavaDoc useNaming = "false";
112     
113     /**
114      * The text for the working directory for this context.
115      */

116     private String JavaDoc workDir = null;
117     
118     /**
119      * The text for the loader check interval.
120      */

121     private String JavaDoc ldrCheckInterval = "15";
122     
123     /**
124      * The text for the boolean value of loader reloadable.
125      */

126     private String JavaDoc ldrReloadable = "false";
127     
128     /**
129      * The text for the session manager check interval.
130      */

131     private String JavaDoc mgrCheckInterval = "60";
132     
133     
134     /**
135      * The text for the session mgr session ID initializer.
136      */

137     private String JavaDoc mgrSessionIDInit = "";
138     
139     /**
140      * The text for the session mgr max active sessions.
141      */

142     private String JavaDoc mgrMaxSessions = "0";
143     
144     /**
145      * The text for the anti resource locking flag.
146      */

147     private String JavaDoc antiResourceLocking = "false";
148
149     /**
150      * The text for the anti jar locking flag.
151      */

152     private String JavaDoc antiJarLocking = "false";
153
154     /*
155      * Represent boolean (true, false) values for cookies etc.
156      */

157     private List JavaDoc booleanVals = null;
158     
159     // ------------------------------------------------------------- Properties
160

161    /**
162      * Return the administrative action represented by this form.
163      */

164     public String JavaDoc getAdminAction() {
165
166         return this.adminAction;
167
168     }
169
170
171     /**
172      * Set the administrative action represented by this form.
173      */

174     public void setAdminAction(String JavaDoc adminAction) {
175
176         this.adminAction = adminAction;
177
178     }
179
180     /**
181      * Return the object name of the Context this bean refers to.
182      */

183     public String JavaDoc getObjectName() {
184
185         return this.objectName;
186
187     }
188
189     /**
190      * Set the object name of the Context this bean refers to.
191      */

192     public void setObjectName(String JavaDoc objectName) {
193
194         this.objectName = objectName;
195
196     }
197     
198     /**
199      * Return the parent object name of the Context this bean refers to.
200      */

201     public String JavaDoc getParentObjectName() {
202
203         return this.parentObjectName;
204
205     }
206
207     /**
208      * Set the parent object name of the Context this bean refers to.
209      */

210     public void setParentObjectName(String JavaDoc parentObjectName) {
211
212         this.parentObjectName = parentObjectName;
213
214     }
215     
216       /**
217      * Return the loader object name of the Context this bean refers to.
218      */

219     public String JavaDoc getLoaderObjectName() {
220
221         return this.loaderObjectName;
222
223     }
224
225     /**
226      * Set the loader object name of the Context this bean refers to.
227      */

228     public void setLoaderObjectName(String JavaDoc loaderObjectName) {
229
230         this.loaderObjectName = loaderObjectName;
231
232     }
233     
234       /**
235      * Return the manager object name of the Context this bean refers to.
236      */

237     public String JavaDoc getManagerObjectName() {
238
239         return this.managerObjectName;
240
241     }
242
243     /**
244      * Set the manager object name of the Context this bean refers to.
245      */

246     public void setManagerObjectName(String JavaDoc managerObjectName) {
247
248         this.managerObjectName = managerObjectName;
249
250     }
251     
252     /**
253      * Return the label of the node that was clicked.
254      */

255     public String JavaDoc getNodeLabel() {
256         
257         return this.nodeLabel;
258         
259     }
260     
261     /**
262      * Set the node label.
263      */

264     public void setNodeLabel(String JavaDoc nodeLabel) {
265         
266         this.nodeLabel = nodeLabel;
267         
268     }
269     
270     
271     /**
272      * Return the booleanVals.
273      */

274     public List JavaDoc getBooleanVals() {
275         
276         return this.booleanVals;
277         
278     }
279     
280     /**
281      * Set the debugVals.
282      */

283     public void setBooleanVals(List JavaDoc booleanVals) {
284         
285         this.booleanVals = booleanVals;
286         
287     }
288     
289     
290     /**
291      * Return the Cookies.
292      */

293     
294     public String JavaDoc getCookies() {
295         
296         return this.cookies;
297         
298     }
299     
300     /**
301      * Set the Cookies.
302      */

303     public void setCookies(String JavaDoc cookies) {
304         
305         this.cookies = cookies;
306         
307     }
308     
309     /**
310      * Return the Cross Context.
311      */

312     
313     public String JavaDoc getCrossContext() {
314         
315         return this.crossContext;
316         
317     }
318     
319     /**
320      * Set the Cross Context.
321      */

322     public void setCrossContext(String JavaDoc crossContext) {
323         
324         this.crossContext = crossContext;
325         
326     }
327     
328     
329     /**
330      * Return the Document Base Text.
331      */

332     
333     public String JavaDoc getDocBase() {
334         
335         return this.docBase;
336         
337     }
338     
339     /**
340      * Set the document Base text.
341      */

342     public void setDocBase(String JavaDoc docBase) {
343         
344         this.docBase = docBase;
345         
346     }
347     
348     
349     /**
350      * Return the Override boolean value.
351      */

352     
353     public String JavaDoc getOverride() {
354         
355         return this.override;
356         
357     }
358     
359     /**
360      * Set the override value.
361      */

362     public void setOverride(String JavaDoc override) {
363         
364         this.override = override;
365         
366     }
367     
368     
369     /**
370      * Return the privileged boolean value.
371      */

372     
373     public String JavaDoc getPrivileged() {
374         
375         return this.privileged;
376         
377     }
378     
379     /**
380      * Set the privileged value.
381      */

382     public void setPrivileged(String JavaDoc privileged) {
383         
384         this.privileged = privileged;
385         
386     }
387     
388     
389     /**
390      * Return the context path.
391      */

392     
393     public String JavaDoc getPath() {
394         
395         return this.path;
396         
397     }
398     
399     /**
400      * Set the context path text.
401      */

402     public void setPath(String JavaDoc path) {
403         
404         this.path = path;
405         
406     }
407     
408     
409     /**
410      * Return the reloadable boolean value.
411      */

412     
413     public String JavaDoc getReloadable() {
414         
415         return this.reloadable;
416         
417     }
418     
419     /**
420      * Set the reloadable value.
421      */

422     public void setReloadable(String JavaDoc reloadable) {
423         
424         this.reloadable = reloadable;
425         
426     }
427     
428     /**
429      * Return the swallowOutput boolean value.
430      */

431
432     public String JavaDoc getSwallowOutput() {
433
434         return this.swallowOutput;
435
436     }
437
438     /**
439      * Set the swallowOutput value.
440      */

441     public void setSwallowOutput(String JavaDoc swallowOutput) {
442
443         this.swallowOutput = swallowOutput;
444
445     }
446
447     /**
448      * Return the use naming boolean value.
449      */

450     
451     public String JavaDoc getUseNaming() {
452         
453         return this.useNaming;
454         
455     }
456     
457     /**
458      * Set the useNaming value.
459      */

460     public void setUseNaming(String JavaDoc useNaming) {
461         
462         this.useNaming = useNaming;
463         
464     }
465     
466     /**
467      * Return the Working Directory.
468      */

469     public String JavaDoc getWorkDir() {
470         
471         return this.workDir;
472         
473     }
474     
475     /**
476      * Set the working directory.
477      */

478     public void setWorkDir(String JavaDoc workDir) {
479         
480         this.workDir = workDir;
481         
482     }
483     
484     
485     /**
486      * Return the loader check interval.
487      */

488     public String JavaDoc getLdrCheckInterval() {
489         
490         return this.ldrCheckInterval;
491         
492     }
493     
494     /**
495      * Set the loader Check Interval.
496      */

497     public void setLdrCheckInterval(String JavaDoc ldrCheckInterval) {
498         
499         this.ldrCheckInterval = ldrCheckInterval;
500         
501     }
502     
503     
504     /**
505      * Return the loader reloadable boolean value.
506      */

507     public String JavaDoc getLdrReloadable() {
508         
509         return this.ldrReloadable;
510         
511     }
512     
513     /**
514      * Set the loader reloadable value.
515      */

516     public void setLdrReloadable(String JavaDoc ldrReloadable) {
517         
518         this.ldrReloadable = ldrReloadable;
519         
520     }
521     
522     /**
523      * Return the session manager check interval.
524      */

525     public String JavaDoc getMgrCheckInterval() {
526         
527         return this.mgrCheckInterval;
528         
529     }
530     
531     /**
532      * Set the session manager Check Interval.
533      */

534     public void setMgrCheckInterval(String JavaDoc mgrCheckInterval) {
535         
536         this.mgrCheckInterval = mgrCheckInterval;
537         
538     }
539     
540     /**
541      * Return the session ID initializer.
542      */

543     public String JavaDoc getMgrSessionIDInit() {
544         
545         return this.mgrSessionIDInit;
546         
547     }
548     
549     /**
550      * Set the mgr Session ID Initizializer.
551      */

552     public void setMgrSessionIDInit(String JavaDoc mgrSessionIDInit) {
553         
554         this.mgrSessionIDInit = mgrSessionIDInit;
555         
556     }
557     
558     /**
559      * Return the Session mgr maximum active sessions.
560      */

561     
562     public String JavaDoc getMgrMaxSessions() {
563         
564         return this.mgrMaxSessions;
565         
566     }
567     
568     /**
569      * Set the Session mgr maximum active sessions.
570      */

571     public void setMgrMaxSessions(String JavaDoc mgrMaxSessions) {
572         
573         this.mgrMaxSessions = mgrMaxSessions;
574         
575     }
576
577     /**
578      * Get the anti resouce locking flag
579      */

580     public String JavaDoc getAntiResourceLocking() {
581         return antiResourceLocking;
582     }
583
584     /**
585      * Set the anti resource locking flag
586      */

587     public void setAntiResourceLocking(String JavaDoc arl) {
588     antiResourceLocking = arl;
589     }
590
591
592     /**
593      * Get the anti jar locking flag
594      */

595     public String JavaDoc getAntiJarLocking() {
596         return antiJarLocking;
597     }
598
599     /**
600      * Set the anti jar locking flag
601      */

602     public void setAntiJarLocking(String JavaDoc ajl) {
603         antiJarLocking = ajl;
604     }
605
606     // --------------------------------------------------------- Public Methods
607

608     /**
609      * Reset all properties to their default values.
610      *
611      * @param mapping The mapping used to select this instance
612      * @param request The servlet request we are processing
613      */

614     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
615         
616         this.objectName = null;
617         this.parentObjectName = null;
618         this.loaderObjectName = null;
619         this.managerObjectName = null;
620         
621         // context properties
622
this.cookies = "false";
623         this.crossContext = "false";
624         this.docBase = null;
625         this.override= "false";
626         this.path = null;
627         this.reloadable = "false";
628         this.swallowOutput = "false";
629         this.antiResourceLocking = "false";
630         this.antiJarLocking = "false";
631
632         // loader properties
633
this.ldrCheckInterval = "15";
634         this.ldrReloadable = "true";
635         
636         // session manager properties
637
this.mgrCheckInterval = "60";
638         this.mgrSessionIDInit = "0";
639         this.mgrMaxSessions = "-1";
640     }
641     
642     /**
643      * Render this object as a String.
644      */

645     public String JavaDoc toString() {
646
647         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("ContextForm[adminAction=");
648         sb.append(adminAction);
649         sb.append(",docBase=");
650         sb.append(docBase);
651         sb.append(",path=");
652         sb.append(path);
653         sb.append(",cookies=");
654         sb.append(cookies);
655         sb.append(",crossContext=");
656         sb.append(crossContext);
657         sb.append(",override=");
658         sb.append(override);
659         sb.append(",reloadable=");
660         sb.append(reloadable);
661         sb.append(",swallowOutput=");
662         sb.append(swallowOutput);
663
664         // loader properties
665
sb.append(",ldrCheckInterval=");
666         sb.append(ldrCheckInterval);
667         sb.append(",ldrReloadable=");
668         sb.append(ldrReloadable);
669         // manager properties
670
sb.append(",mgrCheckInterval=");
671         sb.append(mgrCheckInterval);
672         sb.append(",mgrSessionIDInit=");
673         sb.append(mgrSessionIDInit);
674         sb.append(",mgrMaxSessions=");
675         sb.append(mgrMaxSessions);
676         // object names
677
sb.append("',objectName='");
678         sb.append(objectName);
679         sb.append("',parentObjectName=");
680         sb.append(parentObjectName);
681         sb.append("',loaderObjectName=");
682         sb.append(loaderObjectName);
683         sb.append("',managerObjectName=");
684         sb.append(managerObjectName);
685         sb.append("]");
686         return (sb.toString());
687
688     }
689     /**
690      * Validate the properties that have been set from this HTTP request,
691      * and return an <code>ActionErrors</code> object that encapsulates any
692      * validation errors that have been found. If no errors are found, return
693      * <code>null</code> or an <code>ActionErrors</code> object with no
694      * recorded error messages.
695      *
696      * @param mapping The mapping used to select this instance
697      * @param request The servlet request we are processing
698      */

699     
700     private ActionErrors errors;
701     
702     public ActionErrors validate(ActionMapping mapping,
703     HttpServletRequest JavaDoc request) {
704         
705         errors = new ActionErrors();
706         
707         String JavaDoc submit = request.getParameter("submit");
708         
709         // front end validation when save is clicked.
710
//if (submit != null) {
711

712             // docBase cannot be null
713
if ((docBase == null) || (docBase.length() < 1)) {
714                 errors.add("docBase", new ActionError("error.docBase.required"));
715             }
716             
717             // if path is empty, it's root context
718
// validate context starting with "/" only at the time of context creation.
719
if ("Create".equalsIgnoreCase(adminAction) && !path.startsWith("/")) {
720                 errors.add("path", new ActionError("error.path.prefix"));
721             }
722                         
723             //if ((workDir == null) || (workDir.length() < 1)) {
724
// errors.add("workDir", new ActionError("error.workDir.required"));
725
//}
726

727             // loader properties
728
// FIXME-- verify if these ranges are ok.
729
numberCheck("ldrCheckInterval", ldrCheckInterval , true, 0, 10000);
730             
731             // session manager properties
732
numberCheck("mgrCheckInterval", mgrCheckInterval, true, 0, 10000);
733             numberCheck("mgrMaxSessions", mgrMaxSessions, false, -1, 100);
734             
735             //if ((mgrSessionIDInit == null) || (mgrSessionIDInit.length() < 1)) {
736
// errors.add("mgrSessionIDInit", new ActionError("error.mgrSessionIDInit.required"));
737
//}
738
//}
739

740         return errors;
741     }
742     
743     /*
744      * Helper method to check that it is a required number and
745      * is a valid integer within the given range. (min, max).
746      *
747      * @param field The field name in the form for which this error occured.
748      * @param numText The string representation of the number.
749      * @param rangeCheck Boolean value set to true of reange check should be performed.
750      *
751      * @param min The lower limit of the range
752      * @param max The upper limit of the range
753      *
754      */

755     
756     private void numberCheck(String JavaDoc field, String JavaDoc numText, boolean rangeCheck,
757     int min, int max) {
758         
759         // Check for 'is required'
760
if ((numText == null) || (numText.length() < 1)) {
761             errors.add(field, new ActionError("error."+field+".required"));
762         } else {
763             
764             // check for 'must be a number' in the 'valid range'
765
try {
766                 int num = Integer.parseInt(numText);
767                 // perform range check only if required
768
if (rangeCheck) {
769                     if ((num < min) || (num > max ))
770                         errors.add( field,
771                         new ActionError("error."+ field +".range"));
772                 }
773             } catch (NumberFormatException JavaDoc e) {
774                 errors.add(field,
775                 new ActionError("error."+ field + ".format"));
776             }
777         }
778     }
779     
780 }
781
Popular Tags