KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > core > controller > ExpressoActionServlet


1 /* ====================================================================
2 * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3 *
4 * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. The end-user documentation included with the redistribution,
19 * if any, must include the following acknowledgment:
20 * "This product includes software developed by Jcorporate Ltd.
21 * (http://www.jcorporate.com/)."
22 * Alternately, this acknowledgment may appear in the software itself,
23 * if and wherever such third-party acknowledgments normally appear.
24 *
25 * 4. "Jcorporate" and product names such as "Expresso" must
26 * not be used to endorse or promote products derived from this
27 * software without prior written permission. For written permission,
28 * please contact info@jcorporate.com.
29 *
30 * 5. Products derived from this software may not be called "Expresso",
31 * or other Jcorporate product names; nor may "Expresso" or other
32 * Jcorporate product names appear in their name, without prior
33 * written permission of Jcorporate Ltd.
34 *
35 * 6. No product derived from this software may compete in the same
36 * market space, i.e. framework, without prior written permission
37 * of Jcorporate Ltd. For written permission, please contact
38 * partners@jcorporate.com.
39 *
40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43 * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This software consists of voluntary contributions made by many
55 * individuals on behalf of the Jcorporate Ltd. Contributions back
56 * to the project(s) are encouraged when you make modifications.
57 * Please send them to support@jcorporate.com. For more information
58 * on Jcorporate Ltd. and its products, please see
59 * <http://www.jcorporate.com/>.
60 *
61 * Portions of this software are based upon other open source
62 * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.core.controller;
66
67 import com.jcorporate.expresso.core.misc.ConfigManager;
68 import com.jcorporate.expresso.core.misc.ConfigurationException;
69 import com.jcorporate.expresso.core.misc.SystemMacros;
70 import org.apache.commons.digester.Digester;
71 import org.apache.struts.Globals;
72 import org.apache.struts.action.Action;
73 import org.apache.struts.action.ActionFormBean;
74 import org.apache.struts.action.ActionFormBeans;
75 import org.apache.struts.action.ActionForward;
76 import org.apache.struts.action.ActionForwards;
77 import org.apache.struts.action.ActionMapping;
78 import org.apache.struts.action.ActionMappings;
79 import org.apache.struts.action.ActionServlet;
80 import org.apache.struts.action.DynaActionFormClass;
81 import org.apache.struts.config.ActionConfig;
82 import org.apache.struts.config.ControllerConfig;
83 import org.apache.struts.config.FormBeanConfig;
84 import org.apache.struts.config.ForwardConfig;
85 import org.apache.struts.config.MessageResourcesConfig;
86 import org.apache.struts.config.ModuleConfig;
87 import org.apache.struts.config.ModuleConfigFactory;
88 import org.xml.sax.InputSource JavaDoc;
89
90 import javax.servlet.ServletException JavaDoc;
91 import javax.servlet.UnavailableException JavaDoc;
92 import java.io.IOException JavaDoc;
93 import java.io.InputStream JavaDoc;
94 import java.net.URL JavaDoc;
95 import java.util.Enumeration JavaDoc;
96 import java.util.HashMap JavaDoc;
97 import java.util.Iterator JavaDoc;
98 import java.util.Map JavaDoc;
99
100
101 /**
102  * Title: Expresso Project
103  * Description:
104  * Copyright: Copyright (c) 2001, 2002, 2003
105  * Company: Jcorporate
106  *
107  * @author Michael Rimov, Extended by Peter Pilgrim
108  * @author Michael Rimov, Peter Pilgrim, Portions created by the Struts development
109  * team
110  * @version 2.0
111  * @see ExpressoPlugin
112  * @see ExpressoRequestProcessor
113  */

114 public class ExpressoActionServlet extends ActionServlet
115         implements ControllerFactory {
116
117     protected Map JavaDoc mapModuleConfig = new HashMap JavaDoc();
118
119     /**
120      * Default constructor
121      */

122     public ExpressoActionServlet() {
123     }
124
125     /**
126      * <p>Initialize the application configuration information for the
127      * specified module.</p>
128      * <p/>
129      * <p/>
130      * <p><font color="red">Additional notes by Peter Pilgrim Sun Feb 16 13:53:07 GMT 2003</font></p>
131      * <p/>
132      * <p/>
133      * We require the <em>interception</em> of the implementation of the
134      * <code>ActionServlet.initModuleConfig</code> method in this
135      * class, because we need to keep a record of all the defined
136      * modules and their configurations. It makes easy to implement
137      * controller factory interface.
138      * </p>
139      *
140      * @param prefix Module prefix for this module
141      * @param paths Comma-separated list of context-relative resource path(s)
142      * for this modules's configuration resource(s)
143      * @return Constructed Module Config
144      * @throws ServletException if initialization cannot be performed
145      * @since Struts 1.1
146      */

147     protected ModuleConfig initModuleConfig(String JavaDoc prefix, String JavaDoc paths)
148             throws ServletException JavaDoc {
149         //
150
//Try loading config directory first. If not, then we load from
151
//classpaths
152
//
153
ModuleConfig config = initExpressoFromConfigDirectory(prefix, paths);
154         if (config != null) {
155             // Store the configuration inside our private map collection
156
// *PP* Sun Feb 16 14:18:02 GMT 2003
157
synchronized (mapModuleConfig) {
158                 mapModuleConfig.put(prefix, config);
159             }
160             return config;
161         }
162
163         //
164
//If we got here, we failed to load the configuration from the config
165
//directory. We now need to initialize it from the classpath.
166
//
167

168         config = super.initModuleConfig(prefix, paths);
169
170         // Store the configuration inside our private map collection
171
// *PP* Sun Feb 16 14:18:02 GMT 2003
172
synchronized (mapModuleConfig) {
173             mapModuleConfig.put(prefix, config);
174         }
175
176         if (prefix.length() < 1) {
177
178             //
179
//Load all modules defined in the web.xml
180
//
181
Enumeration JavaDoc names = getServletConfig().getInitParameterNames();
182             while (names.hasMoreElements()) {
183                 String JavaDoc name = (String JavaDoc) names.nextElement();
184                 if (log.isDebugEnabled()) {
185                     log.debug("init parameter name=`" + name + "'");
186                 }
187                 if (name.startsWith("expresso/")) {
188                     // Read the rest of the sub application
189
String JavaDoc subapp = name.substring(8);
190                     String JavaDoc configPath = getServletConfig().getInitParameter(name);
191                     initExpressoSubapplication(subapp, config, configPath);
192                 }
193             }
194
195         }
196
197
198         // Return the completed configuration object
199
//config.freeze(); // Now done after plugins init
200
return (config);
201     }
202
203
204     /**
205      * Initialize the configuration based upon the context ConfigDir parameter
206      * typical in the older style Expresso [pre 6 :)]
207      *
208      * @param prefix the prefix for the module
209      * @param paths the Module config to add to
210      * @return true if succesfully initialized from config directory, false
211      * otherwize, indicating that the configuration system should continue and
212      * try to load from the classpath.
213      * @throws ServletException upon error
214      */

215     protected ModuleConfig initExpressoFromConfigDirectory(String JavaDoc prefix, String JavaDoc paths)
216             throws ServletException JavaDoc {
217
218         // Parse the configuration for this module
219
//@todo & FIXME replace with a FactoryMethod
220
ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
221         ModuleConfig config = factoryObject.createModuleConfig(prefix);
222         config.setPrefix("");
223
224         // Support for module-wide ActionMapping type override
225
String JavaDoc mapping = getServletConfig().getInitParameter("mapping");
226         if (mapping != null) {
227             config.setActionMappingClass(mapping);
228         }
229
230         // Configure the Digester instance we will use
231
Digester digester = initConfigDigester();
232
233
234         if (log.isDebugEnabled()) {
235             log.debug("initExpressoFromConfigDirectory()");
236         }
237         //
238
//Override the default if config dir is supplied, and struts-config is stitting
239
//in the configuration directory
240
//
241
String JavaDoc expressoConfigDir = this.getServletContext().getInitParameter("configDir");
242         if (expressoConfigDir != null &&
243                 expressoConfigDir.length() > 0 && prefix.length() == 0) {
244             expressoConfigDir = SystemMacros.getInstance().expandValue(expressoConfigDir);
245             if (expressoConfigDir.startsWith("WEB-INF")) {
246                 expressoConfigDir = SystemMacros.getInstance().getWebAppDir() + "/" + expressoConfigDir;
247             }
248
249             java.io.File JavaDoc f = new java.io.File JavaDoc(expressoConfigDir + "/struts-config.xml");
250             if (f != null && f.exists()) {
251                 paths = expressoConfigDir + "/struts-config.xml";
252             } else {
253                 //
254
//We're probably supposed to configure through classpath rather than
255
//config directory
256
//
257
return null;
258             }
259         } else {
260             //
261
//We're probably supposed to configure through classpath rather than
262
//config directory
263
//
264
return null;
265         }
266
267         //
268
//Load all modules defined in the configuration directory
269
//
270
HashMap JavaDoc inputMap = null;
271
272         try {
273             inputMap = ConfigManager.getConfigInputSources("struts-config");
274         } catch (ConfigurationException ce) {
275             log.info("Unable to load struts-config doctypes. Relying on web.xml parameters", ce);
276             return null;
277         }
278
279         if (inputMap == null) {
280             log.info("Unable to load struts-config doctypes. Relying on web.xml parameters");
281             return null;
282         }
283
284         if (!inputMap.containsKey("struts-config.xml")) {
285             log.info("Unable to load struts-config.xml. Relying on web.xml parameters");
286             return null;
287         }
288
289         //
290
//First load the expresso configurations
291
//
292
InputSource JavaDoc is = (InputSource JavaDoc) inputMap.get("struts-config.xml");
293         // Configure the Digester instance we will use
294
digester.push(config);
295         loadOneConfigFile(digester, is);
296
297
298         //
299
//Now load the rest.
300
//
301
for (Iterator JavaDoc i = inputMap.keySet().iterator(); i.hasNext();) {
302             String JavaDoc key = (String JavaDoc) i.next();
303             if (log.isInfoEnabled()) {
304                 log.info("Loading struts configuration file: " + key);
305             }
306             if (!("struts-config.xml".equals(key))) {
307                 digester = null;
308                 digester = initConfigDigester();
309                 digester.push(config);
310                 is = (InputSource JavaDoc) inputMap.get(key);
311                 loadOneConfigFile(digester, is);
312             }
313         }
314
315
316         // Force creation and registration of DynaActionFormClass instances
317
// for all dynamic form beans we wil be using
318
FormBeanConfig fbs[] = config.findFormBeanConfigs();
319         for (int i = 0; i < fbs.length; i++) {
320             if (fbs[i].getDynamic()) {
321                 DynaActionFormClass.createDynaActionFormClass(fbs[i]);
322             }
323         }
324
325         getServletContext().setAttribute(Globals.MODULE_KEY + prefix, config);
326
327         // Special handling for the default module (for
328
// backwards compatibility only, will be removed later)
329
if (prefix.length() < 1) {
330             defaultControllerConfig(config);
331             defaultMessageResourcesConfig(config);
332             defaultFormBeansConfig(config);
333             defaultForwardsConfig(config);
334             defaultMappingsConfig(config);
335         }
336
337
338         // Return the completed configuration object
339
return config;
340
341     }
342
343     /**
344      * Load one configuration file
345      *
346      * @param digester the digester to parse
347      * @param is the input source to parse
348      * @throws ServletException upon error
349      */

350     protected void loadOneConfigFile(Digester digester, InputSource JavaDoc is)
351             throws ServletException JavaDoc {
352         try {
353             digester.parse(is);
354         } catch (Exception JavaDoc ex) {
355             log.error(internal.getMessage("configParse", ex));
356             throw new UnavailableException JavaDoc
357                     (internal.getMessage("configParse", ex));
358         }
359
360     }
361
362
363     /**
364      * Initialise Expresso sub application, merge the separate configuration
365      * into suppliced Struts config XML, normally default.
366      *
367      * @param prefix the sub application prefix
368      * @param config the module configuration
369      * @param configPath the module path to load to
370      * @throws ServletException upon error
371      */

372     protected void initExpressoSubapplication(String JavaDoc prefix, ModuleConfig config, String JavaDoc configPath)
373             throws ServletException JavaDoc {
374         if (log.isDebugEnabled()) {
375             log.debug("initExpressoSubapplication()");
376         }
377
378         InputStream JavaDoc input = null;
379         try {
380             // Configure the Digester instance we will use
381
Digester digester = initConfigDigester();
382
383             if (log.isDebugEnabled()) {
384                 log.debug("prefix=`" + prefix + "'");
385                 log.debug("config=`" + config + "'");
386                 log.debug("configPath=`" + configPath + "'");
387             }
388
389             // Process each specified resource path
390
digester.push(config);
391             URL JavaDoc url = getServletContext().getResource(configPath);
392             if (log.isDebugEnabled()) {
393                 log.debug("url=`" + url + "'");
394             }
395             InputSource JavaDoc is = null;
396             if (url == null) {
397                 //Try a file-type parameter instead
398
} else {
399                 is = new InputSource JavaDoc(url.toExternalForm());
400                 input = getServletContext().getResourceAsStream(configPath);
401                 is.setByteStream(input);
402             }
403
404             digester.parse(is);
405         } catch (Throwable JavaDoc t) {
406             log.error(internal.getMessage("configParse", configPath, t));
407             throw new UnavailableException JavaDoc
408                     (internal.getMessage("configParse", configPath));
409         } finally {
410             if (input != null) {
411                 try {
412                     input.close();
413                 } catch (IOException JavaDoc e) {
414                     ;
415                 }
416             }
417         }
418     }
419
420     /**
421      * Struts compatible version of the controller factory. Adds the created class
422      * to the actions list if it doesn't exist already.
423      *
424      * @param className The className of the controller to get/instantiate
425      * @return an instantiated Controller object
426      * @throws ControllerException upon error
427      */

428     public synchronized Controller getController(String JavaDoc className)
429             throws ControllerException {
430         return getController("", className);
431     }
432
433
434     /**
435      * Struts compatible version of the controller factory. Adds the created class
436      * to the actions list if it doesn't exist already.
437      *
438      * @param moduleName The Struts 1.1 module name
439      * @param className The className of the controller to get/instantiate
440      * @return an instantiated Controller object
441      * @throws ControllerException upon error
442      */

443     public synchronized Controller getController(String JavaDoc moduleName, String JavaDoc className)
444             throws ControllerException {
445         // Store the configuration inside our private map collection
446
// *PP* Sun Feb 16 14:18:02 GMT 2003
447
ModuleConfig config = null;
448
449         synchronized (mapModuleConfig) {
450             config = (ModuleConfig) mapModuleConfig.get(moduleName);
451         }
452         if (config == null) {
453             throw new ControllerException("unable to find specified Struts module 1.1 prefix:`" + moduleName + "'");
454         }
455
456         ExpressoRequestProcessor processor = null;
457         try {
458             processor = (ExpressoRequestProcessor) getRequestProcessor(config);
459         }
460         catch (ServletException JavaDoc se) {
461             throw new ControllerException( "Unable to retrieve request processor from module config.", se );
462         } catch (ClassCastException JavaDoc ex) {
463             throw new ControllerException("You need to set the request processor in your configuration for module: "
464                 + moduleName + " to point to a derivative of " + ExpressoRequestProcessor.class.getName()
465                 + " instead we got: " + ex.getMessage());
466         }
467
468         Action action = processor.createAction(className);
469         if (!(action instanceof Controller)) {
470             throw new ControllerException(
471                     "className:`" + className + "' is not a subclass of `"
472                     + Controller.class.getName() + "'");
473         }
474         Controller controller = (Controller) action;
475         return controller;
476     }
477
478     /**
479      * This method is similar to getController(className) except that it may try
480      * to route the construction call to the appropriate controlling servlet
481      *
482      * @param request The ControllerRequest that has all the parameters we
483      * need to construct the appropriate controller.
484      * @return an instantiated Controller object
485      * @throws ControllerException if there's an error instantiating the
486      * controller
487      */

488     public Controller getController(ControllerRequest request)
489             throws ControllerException {
490         // We have to get a HttpServletRequest and from this object
491
// get the module context.
492

493         // We can then load the ModuleConfig object and then instantiate
494
// a request processor and create the action class
495

496
497         String JavaDoc className = request.getParameter(Controller.CONTROLLER_PARAM_KEY);
498
499         if (className == null || className.length() == 0) {
500             throw new IllegalArgumentException JavaDoc("You must define your controller " +
501                     "parameter in your controller request");
502         }
503         if (request instanceof ServletControllerRequest) {
504             ServletControllerRequest scr = (ServletControllerRequest) request;
505             javax.servlet.Servlet JavaDoc as = scr.getCallingServlet();
506
507             if (as instanceof ControllerFactory) {
508                 if (as != this) {
509                     return ((ControllerFactory) as).getController(className);
510                 } else {
511                     return this.getController(className);
512                 }
513             } else {
514
515                 //They can't handle it anyway.
516
return this.getController(className);
517             }
518         }
519
520         return this.getController(className);
521     }
522
523     /**
524      * Initialization Code
525      *
526      * @throws ServletException upon error
527      */

528     public void init()
529             throws javax.servlet.ServletException JavaDoc {
530         ConfigManager.setControllerFactory(this);
531         super.init();
532     }
533
534     /**
535      * Remove myself as a controller factory
536      */

537     public void destroy() {
538         ConfigManager.setControllerFactory(null);
539         super.destroy();
540     }
541
542     /**
543      * subclass in order to allow ExpressoActionServlet to be a dispatcher
544      * for any finite-state-machine request which includes parameters for controller &
545      * state. if ExpressoActionServlet does not play this role, URLs must have
546      * a known controller embedded, which is not good for a JSP, for example,
547      * that isn't supposed to know about controllers. instead,
548      * ExpressoServletAction can be the "universal dispatcher"
549      *
550      * Identify and return the path component (from the request URI) that
551      * we will use to select an ActionMapping to dispatch with. If no such
552      * path can be identified, return <code>null</code>.
553      *
554      * @param request The servlet request we are processing
555      * @return String
556      */

557     /**
558      protected String processPath(HttpServletRequest request) {
559      String path = super.processPath(request);
560
561      String controller = request.getParameter(Controller.CONTROLLER_PARAM_KEY);
562      if ( controller != null ) {
563      // do reverse-lookup from controller class to mapping
564      ActionMapping mapping = ConfigManager.getMapping(
565      controller,
566      request.getParameter(STATE_PARAM_KEY));
567      if ( mapping != null ) {
568      path = mapping.getPath();
569      }
570      }
571
572      return path;
573      }
574      */

575
576     /**
577      * Perform backwards-compatible configuration of the default module's
578      * controller configuration from servlet initialization parameters (as
579      * were used in Struts 1.0).
580      *
581      * @param config The ModuleConfig object for the default module
582      * @since Struts 1.1
583      * @deprecated Will be removed in a release after Struts 1.1.
584      */

585     private void defaultControllerConfig(ModuleConfig config) {
586
587         String JavaDoc value = null;
588         ControllerConfig cc = config.getControllerConfig();
589
590         value = getServletConfig().getInitParameter("bufferSize");
591         if (value != null) {
592             cc.setBufferSize(Integer.parseInt(value));
593         }
594
595         value = getServletConfig().getInitParameter("content");
596         if (value != null) {
597             cc.setContentType(value);
598         }
599
600         value = getServletConfig().getInitParameter("locale");
601         // must check for null here
602
if (value != null) {
603             if ("true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value)) {
604                 cc.setLocale(true);
605             } else {
606                 cc.setLocale(false);
607             }
608         }
609
610         value = getServletConfig().getInitParameter("maxFileSize");
611         if (value != null) {
612             cc.setMaxFileSize(value);
613         }
614
615         value = getServletConfig().getInitParameter("nocache");
616         if (value != null) {
617             if ("true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value)) {
618                 cc.setNocache(true);
619             } else {
620                 cc.setNocache(false);
621             }
622         }
623
624         value = getServletConfig().getInitParameter("multipartClass");
625         if (value != null) {
626             cc.setMultipartClass(value);
627         }
628
629         value = getServletConfig().getInitParameter("tempDir");
630         if (value != null) {
631             cc.setTempDir(value);
632         }
633
634     }
635
636
637     /**
638      * Perform backwards-compatible configuration of an ActionFormBeans
639      * collection, and expose it as a servlet context attribute (as was
640      * used in Struts 1.0). Note that the current controller code does
641      * not (and should not) reference this attribute for any reason.
642      *
643      * @param config The ModuleConfig object for the default app
644      * @since Struts 1.1
645      * @deprecated Will be removed in a release after Struts 1.1.
646      */

647     private void defaultFormBeansConfig(ModuleConfig config) {
648
649         FormBeanConfig fbcs[] = config.findFormBeanConfigs();
650         ActionFormBeans afb = new ActionFormBeans();
651         afb.setFast(false);
652         for (int i = 0; i < fbcs.length; i++) {
653             afb.addFormBean((ActionFormBean) fbcs[i]);
654         }
655         afb.setFast(true);
656         getServletContext().setAttribute(Globals.FORM_BEANS_KEY, afb);
657
658     }
659
660
661     /**
662      * Perform backwards-compatible configuration of an ActionForwards
663      * collection, and expose it as a servlet context attribute (as was
664      * used in Struts 1.0). Note that the current controller code does
665      * not (and should not) reference this attribute for any reason.
666      *
667      * @param config The ModuleConfig object for the default app
668      * @since Struts 1.1
669      * @deprecated Will be removed in a release after Struts 1.1.
670      */

671     private void defaultForwardsConfig(ModuleConfig config) {
672
673         ForwardConfig fcs[] = config.findForwardConfigs();
674         ActionForwards af = new ActionForwards();
675         af.setFast(false);
676         for (int i = 0; i < fcs.length; i++) {
677             af.addForward((ActionForward) fcs[i]);
678         }
679         af.setFast(true);
680         getServletContext().setAttribute(Globals.FORWARDS_KEY, af);
681
682     }
683
684
685     /**
686      * Perform backwards-compatible configuration of an ActionMappings
687      * collection, and expose it as a servlet context attribute (as was
688      * used in Struts 1.0). Note that the current controller code does
689      * not (and should not) reference this attribute for any reason.
690      *
691      * @param config The ModuleConfig object for the default app
692      * @since Struts 1.1
693      * @deprecated Will be removed in a release after Struts 1.1.
694      */

695     private void defaultMappingsConfig(ModuleConfig config) {
696
697         ActionConfig acs[] = config.findActionConfigs();
698         ActionMappings am = new ActionMappings();
699         am.setServlet(this);
700         am.setFast(false);
701         for (int i = 0; i < acs.length; i++) {
702             am.addMapping((ActionMapping) acs[i]);
703         }
704         am.setFast(true);
705         getServletContext().setAttribute(Globals.MAPPINGS_KEY, am);
706
707     }
708
709
710     /**
711      * Perform backwards-compatible configuration of the default module's
712      * message resources configuration from servlet initialization parameters
713      * (as were used in Struts 1.0).
714      *
715      * @param config The ModuleConfig object for the default module
716      * @since Struts 1.1
717      * @deprecated Will be removed in a release after Struts 1.1.
718      */

719     private void defaultMessageResourcesConfig(ModuleConfig config) {
720
721         String JavaDoc value = null;
722
723         MessageResourcesConfig mrc =
724                 config.findMessageResourcesConfig(Globals.MESSAGES_KEY);
725         if (mrc == null) {
726             mrc = new MessageResourcesConfig();
727             mrc.setKey(Globals.MESSAGES_KEY);
728             config.addMessageResourcesConfig(mrc);
729         }
730         value = getServletConfig().getInitParameter("application");
731         if (value != null) {
732             mrc.setParameter(value);
733         }
734         value = getServletConfig().getInitParameter("factory");
735         if (value != null) {
736             mrc.setFactory(value);
737         }
738         value = getServletConfig().getInitParameter("null");
739         if (value != null) {
740             if (value.equalsIgnoreCase("true") ||
741                     value.equalsIgnoreCase("yes")) {
742                 mrc.setNull(true);
743             } else {
744                 mrc.setNull(false);
745             }
746         }
747
748     }
749
750 }
751
Popular Tags