Source Code Cross Referenced for ExpressoActionServlet.java in  » J2EE » Expresso » com » jcorporate » expresso » core » controller » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Expresso » com.jcorporate.expresso.core.controller 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:         * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
003:         *
004:         * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * 1. Redistributions of source code must retain the above copyright
011:         *    notice, this list of conditions and the following disclaimer.
012:         *
013:         * 2. Redistributions in binary form must reproduce the above copyright
014:         *    notice, this list of conditions and the following disclaimer in
015:         *    the documentation and/or other materials provided with the
016:         *    distribution.
017:         *
018:         * 3. The end-user documentation included with the redistribution,
019:         *    if any, must include the following acknowledgment:
020:         *       "This product includes software developed by Jcorporate Ltd.
021:         *        (http://www.jcorporate.com/)."
022:         *    Alternately, this acknowledgment may appear in the software itself,
023:         *    if and wherever such third-party acknowledgments normally appear.
024:         *
025:         * 4. "Jcorporate" and product names such as "Expresso" must
026:         *    not be used to endorse or promote products derived from this
027:         *    software without prior written permission. For written permission,
028:         *    please contact info@jcorporate.com.
029:         *
030:         * 5. Products derived from this software may not be called "Expresso",
031:         *    or other Jcorporate product names; nor may "Expresso" or other
032:         *    Jcorporate product names appear in their name, without prior
033:         *    written permission of Jcorporate Ltd.
034:         *
035:         * 6. No product derived from this software may compete in the same
036:         *    market space, i.e. framework, without prior written permission
037:         *    of Jcorporate Ltd. For written permission, please contact
038:         *    partners@jcorporate.com.
039:         *
040:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
041:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
042:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
043:         * DISCLAIMED.  IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
044:         * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
045:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
046:         * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
047:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
048:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
049:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
050:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
051:         * SUCH DAMAGE.
052:         * ====================================================================
053:         *
054:         * This software consists of voluntary contributions made by many
055:         * individuals on behalf of the Jcorporate Ltd. Contributions back
056:         * to the project(s) are encouraged when you make modifications.
057:         * Please send them to support@jcorporate.com. For more information
058:         * on Jcorporate Ltd. and its products, please see
059:         * <http://www.jcorporate.com/>.
060:         *
061:         * Portions of this software are based upon other open source
062:         * products and are subject to their respective licenses.
063:         */
064:
065:        package com.jcorporate.expresso.core.controller;
066:
067:        import com.jcorporate.expresso.core.misc.ConfigManager;
068:        import com.jcorporate.expresso.core.misc.ConfigurationException;
069:        import com.jcorporate.expresso.core.misc.SystemMacros;
070:        import org.apache.commons.digester.Digester;
071:        import org.apache.struts.Globals;
072:        import org.apache.struts.action.Action;
073:        import org.apache.struts.action.ActionFormBean;
074:        import org.apache.struts.action.ActionFormBeans;
075:        import org.apache.struts.action.ActionForward;
076:        import org.apache.struts.action.ActionForwards;
077:        import org.apache.struts.action.ActionMapping;
078:        import org.apache.struts.action.ActionMappings;
079:        import org.apache.struts.action.ActionServlet;
080:        import org.apache.struts.action.DynaActionFormClass;
081:        import org.apache.struts.config.ActionConfig;
082:        import org.apache.struts.config.ControllerConfig;
083:        import org.apache.struts.config.FormBeanConfig;
084:        import org.apache.struts.config.ForwardConfig;
085:        import org.apache.struts.config.MessageResourcesConfig;
086:        import org.apache.struts.config.ModuleConfig;
087:        import org.apache.struts.config.ModuleConfigFactory;
088:        import org.xml.sax.InputSource;
089:
090:        import javax.servlet.ServletException;
091:        import javax.servlet.UnavailableException;
092:        import java.io.IOException;
093:        import java.io.InputStream;
094:        import java.net.URL;
095:        import java.util.Enumeration;
096:        import java.util.HashMap;
097:        import java.util.Iterator;
098:        import java.util.Map;
099:
100:        /**
101:         * Title:        Expresso Project
102:         * Description:
103:         * Copyright:    Copyright (c) 2001, 2002, 2003
104:         * Company:      Jcorporate
105:         *
106:         * @author Michael Rimov, Extended by Peter Pilgrim
107:         * @author Michael Rimov, Peter Pilgrim, Portions created by the Struts development
108:         *         team
109:         * @version 2.0
110:         * @see ExpressoPlugin
111:         * @see ExpressoRequestProcessor
112:         */
113:        public class ExpressoActionServlet extends ActionServlet implements 
114:                ControllerFactory {
115:
116:            protected Map mapModuleConfig = new HashMap();
117:
118:            /**
119:             * Default constructor
120:             */
121:            public ExpressoActionServlet() {
122:            }
123:
124:            /**
125:             * <p>Initialize the application configuration information for the
126:             * specified module.</p>
127:             * <p/>
128:             * <p/>
129:             * <p><font color="red">Additional notes by Peter Pilgrim Sun Feb 16 13:53:07 GMT 2003</font></p>
130:             * <p/>
131:             * <p/>
132:             * We require the <em>interception</em> of the implementation of the
133:             * <code>ActionServlet.initModuleConfig</code> method in this
134:             * class, because we need to keep a record of all the defined
135:             * modules and their configurations. It makes easy to implement
136:             * controller factory interface.
137:             * </p>
138:             *
139:             * @param prefix Module prefix for this module
140:             * @param paths  Comma-separated list of context-relative resource path(s)
141:             *               for this modules's configuration resource(s)
142:             * @return Constructed Module Config
143:             * @throws ServletException if initialization cannot be performed
144:             * @since Struts 1.1
145:             */
146:            protected ModuleConfig initModuleConfig(String prefix, String paths)
147:                    throws ServletException {
148:                //
149:                //Try loading config directory first.  If not, then we load from
150:                //classpaths
151:                //
152:                ModuleConfig config = initExpressoFromConfigDirectory(prefix,
153:                        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 names = getServletConfig()
182:                            .getInitParameterNames();
183:                    while (names.hasMoreElements()) {
184:                        String name = (String) names.nextElement();
185:                        if (log.isDebugEnabled()) {
186:                            log.debug("init parameter name=`" + name + "'");
187:                        }
188:                        if (name.startsWith("expresso/")) {
189:                            // Read the rest of the sub application
190:                            String subapp = name.substring(8);
191:                            String configPath = getServletConfig()
192:                                    .getInitParameter(name);
193:                            initExpressoSubapplication(subapp, config,
194:                                    configPath);
195:                        }
196:                    }
197:
198:                }
199:
200:                // Return the completed configuration object
201:                //config.freeze();  // Now done after plugins init
202:                return (config);
203:            }
204:
205:            /**
206:             * Initialize the configuration based upon the context ConfigDir parameter
207:             * typical in the older style Expresso [pre 6 :)]
208:             *
209:             * @param prefix the prefix for the module
210:             * @param paths  the Module config to add to
211:             * @return true if succesfully initialized from config directory, false
212:             *         otherwize, indicating that the configuration system should continue and
213:             *         try to load from the classpath.
214:             * @throws ServletException upon error
215:             */
216:            protected ModuleConfig initExpressoFromConfigDirectory(
217:                    String prefix, String paths) throws ServletException {
218:
219:                // Parse the configuration for this module
220:                //@todo & FIXME replace with a FactoryMethod
221:                ModuleConfigFactory factoryObject = ModuleConfigFactory
222:                        .createFactory();
223:                ModuleConfig config = factoryObject.createModuleConfig(prefix);
224:                config.setPrefix("");
225:
226:                // Support for module-wide ActionMapping type override
227:                String mapping = getServletConfig().getInitParameter("mapping");
228:                if (mapping != null) {
229:                    config.setActionMappingClass(mapping);
230:                }
231:
232:                // Configure the Digester instance we will use
233:                Digester digester = initConfigDigester();
234:
235:                if (log.isDebugEnabled()) {
236:                    log.debug("initExpressoFromConfigDirectory()");
237:                }
238:                //
239:                //Override the default if config dir is supplied, and struts-config is stitting
240:                //in the configuration directory
241:                //
242:                String expressoConfigDir = this .getServletContext()
243:                        .getInitParameter("configDir");
244:                if (expressoConfigDir != null && expressoConfigDir.length() > 0
245:                        && prefix.length() == 0) {
246:                    expressoConfigDir = SystemMacros.getInstance().expandValue(
247:                            expressoConfigDir);
248:                    if (expressoConfigDir.startsWith("WEB-INF")) {
249:                        expressoConfigDir = SystemMacros.getInstance()
250:                                .getWebAppDir()
251:                                + "/" + expressoConfigDir;
252:                    }
253:
254:                    java.io.File f = new java.io.File(expressoConfigDir
255:                            + "/struts-config.xml");
256:                    if (f != null && f.exists()) {
257:                        paths = expressoConfigDir + "/struts-config.xml";
258:                    } else {
259:                        //
260:                        //We're probably supposed to configure through classpath rather than
261:                        //config directory
262:                        //
263:                        return null;
264:                    }
265:                } else {
266:                    //
267:                    //We're probably supposed to configure through classpath rather than
268:                    //config directory
269:                    //
270:                    return null;
271:                }
272:
273:                //
274:                //Load all modules defined in the configuration directory
275:                //
276:                HashMap inputMap = null;
277:
278:                try {
279:                    inputMap = ConfigManager
280:                            .getConfigInputSources("struts-config");
281:                } catch (ConfigurationException ce) {
282:                    log
283:                            .info(
284:                                    "Unable to load struts-config doctypes.  Relying on web.xml parameters",
285:                                    ce);
286:                    return null;
287:                }
288:
289:                if (inputMap == null) {
290:                    log
291:                            .info("Unable to load struts-config doctypes.  Relying on web.xml parameters");
292:                    return null;
293:                }
294:
295:                if (!inputMap.containsKey("struts-config.xml")) {
296:                    log
297:                            .info("Unable to load struts-config.xml.  Relying on web.xml parameters");
298:                    return null;
299:                }
300:
301:                //
302:                //First load the expresso configurations
303:                //
304:                InputSource is = (InputSource) inputMap
305:                        .get("struts-config.xml");
306:                // Configure the Digester instance we will use
307:                digester.push(config);
308:                loadOneConfigFile(digester, is);
309:
310:                //
311:                //Now load the rest.
312:                //
313:                for (Iterator i = inputMap.keySet().iterator(); i.hasNext();) {
314:                    String key = (String) i.next();
315:                    if (log.isInfoEnabled()) {
316:                        log.info("Loading struts configuration file: " + key);
317:                    }
318:                    if (!("struts-config.xml".equals(key))) {
319:                        digester = null;
320:                        digester = initConfigDigester();
321:                        digester.push(config);
322:                        is = (InputSource) inputMap.get(key);
323:                        loadOneConfigFile(digester, is);
324:                    }
325:                }
326:
327:                // Force creation and registration of DynaActionFormClass instances
328:                // for all dynamic form beans we wil be using
329:                FormBeanConfig fbs[] = config.findFormBeanConfigs();
330:                for (int i = 0; i < fbs.length; i++) {
331:                    if (fbs[i].getDynamic()) {
332:                        DynaActionFormClass.createDynaActionFormClass(fbs[i]);
333:                    }
334:                }
335:
336:                getServletContext().setAttribute(Globals.MODULE_KEY + prefix,
337:                        config);
338:
339:                // Special handling for the default module (for
340:                // backwards compatibility only, will be removed later)
341:                if (prefix.length() < 1) {
342:                    defaultControllerConfig(config);
343:                    defaultMessageResourcesConfig(config);
344:                    defaultFormBeansConfig(config);
345:                    defaultForwardsConfig(config);
346:                    defaultMappingsConfig(config);
347:                }
348:
349:                // Return the completed configuration object
350:                return config;
351:
352:            }
353:
354:            /**
355:             * Load one configuration file
356:             *
357:             * @param digester the digester to parse
358:             * @param is       the input source to parse
359:             * @throws ServletException upon error
360:             */
361:            protected void loadOneConfigFile(Digester digester, InputSource is)
362:                    throws ServletException {
363:                try {
364:                    digester.parse(is);
365:                } catch (Exception ex) {
366:                    log.error(internal.getMessage("configParse", ex));
367:                    throw new UnavailableException(internal.getMessage(
368:                            "configParse", ex));
369:                }
370:
371:            }
372:
373:            /**
374:             * Initialise Expresso sub application, merge the separate configuration
375:             * into suppliced Struts config XML, normally default.
376:             *
377:             * @param prefix     the sub application prefix
378:             * @param config     the module configuration
379:             * @param configPath the module path to load to
380:             * @throws ServletException upon error
381:             */
382:            protected void initExpressoSubapplication(String prefix,
383:                    ModuleConfig config, String configPath)
384:                    throws ServletException {
385:                if (log.isDebugEnabled()) {
386:                    log.debug("initExpressoSubapplication()");
387:                }
388:
389:                InputStream input = null;
390:                try {
391:                    // Configure the Digester instance we will use
392:                    Digester digester = initConfigDigester();
393:
394:                    if (log.isDebugEnabled()) {
395:                        log.debug("prefix=`" + prefix + "'");
396:                        log.debug("config=`" + config + "'");
397:                        log.debug("configPath=`" + configPath + "'");
398:                    }
399:
400:                    // Process each specified resource path
401:                    digester.push(config);
402:                    URL url = getServletContext().getResource(configPath);
403:                    if (log.isDebugEnabled()) {
404:                        log.debug("url=`" + url + "'");
405:                    }
406:                    InputSource is = null;
407:                    if (url == null) {
408:                        //Try a file-type parameter instead
409:                    } else {
410:                        is = new InputSource(url.toExternalForm());
411:                        input = getServletContext().getResourceAsStream(
412:                                configPath);
413:                        is.setByteStream(input);
414:                    }
415:
416:                    digester.parse(is);
417:                } catch (Throwable t) {
418:                    log
419:                            .error(internal.getMessage("configParse",
420:                                    configPath, t));
421:                    throw new UnavailableException(internal.getMessage(
422:                            "configParse", configPath));
423:                } finally {
424:                    if (input != null) {
425:                        try {
426:                            input.close();
427:                        } catch (IOException e) {
428:                            ;
429:                        }
430:                    }
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 className The className of the controller to get/instantiate
439:             * @return an instantiated Controller object
440:             * @throws ControllerException upon error
441:             */
442:            public synchronized Controller getController(String className)
443:                    throws ControllerException {
444:                return getController("", className);
445:            }
446:
447:            /**
448:             * Struts compatible version of the controller factory.  Adds the created class
449:             * to the actions list if it doesn't exist already.
450:             *
451:             * @param moduleName The Struts 1.1 module name
452:             * @param className  The className of the controller to get/instantiate
453:             * @return an instantiated Controller object
454:             * @throws ControllerException upon error
455:             */
456:            public synchronized Controller getController(String moduleName,
457:                    String className) throws ControllerException {
458:                // Store the configuration inside our private map collection
459:                // *PP* Sun Feb 16 14:18:02 GMT 2003
460:                ModuleConfig config = null;
461:
462:                synchronized (mapModuleConfig) {
463:                    config = (ModuleConfig) mapModuleConfig.get(moduleName);
464:                }
465:                if (config == null) {
466:                    throw new ControllerException(
467:                            "unable to find specified Struts module 1.1 prefix:`"
468:                                    + moduleName + "'");
469:                }
470:
471:                ExpressoRequestProcessor processor = null;
472:                try {
473:                    processor = (ExpressoRequestProcessor) getRequestProcessor(config);
474:                } catch (ServletException se) {
475:                    throw new ControllerException(
476:                            "Unable to retrieve request processor from module config.",
477:                            se);
478:                } catch (ClassCastException ex) {
479:                    throw new ControllerException(
480:                            "You need to set the request processor in your configuration for module: "
481:                                    + moduleName
482:                                    + " to point to a derivative of "
483:                                    + ExpressoRequestProcessor.class.getName()
484:                                    + " instead we got: " + ex.getMessage());
485:                }
486:
487:                Action action = processor.createAction(className);
488:                if (!(action instanceof  Controller)) {
489:                    throw new ControllerException("className:`" + className
490:                            + "' is not a subclass of `"
491:                            + Controller.class.getName() + "'");
492:                }
493:                Controller controller = (Controller) action;
494:                return controller;
495:            }
496:
497:            /**
498:             * This method is similar to getController(className) except that it may try
499:             * to route the construction call to the appropriate controlling servlet
500:             *
501:             * @param request The ControllerRequest that has all the parameters we
502:             *                need to construct the appropriate controller.
503:             * @return an instantiated Controller object
504:             * @throws ControllerException if there's an error instantiating the
505:             *                             controller
506:             */
507:            public Controller getController(ControllerRequest request)
508:                    throws ControllerException {
509:                // We have to get a HttpServletRequest and from this object
510:                // get the module context.
511:
512:                // We can then load the ModuleConfig object and then instantiate
513:                // a request processor and create the action class
514:
515:                String className = request
516:                        .getParameter(Controller.CONTROLLER_PARAM_KEY);
517:
518:                if (className == null || className.length() == 0) {
519:                    throw new IllegalArgumentException(
520:                            "You must define your controller "
521:                                    + "parameter in your controller request");
522:                }
523:                if (request instanceof  ServletControllerRequest) {
524:                    ServletControllerRequest scr = (ServletControllerRequest) request;
525:                    javax.servlet.Servlet as = scr.getCallingServlet();
526:
527:                    if (as instanceof  ControllerFactory) {
528:                        if (as != this ) {
529:                            return ((ControllerFactory) as)
530:                                    .getController(className);
531:                        } else {
532:                            return this .getController(className);
533:                        }
534:                    } else {
535:
536:                        //They can't handle it anyway.
537:                        return this .getController(className);
538:                    }
539:                }
540:
541:                return this .getController(className);
542:            }
543:
544:            /**
545:             * Initialization Code
546:             *
547:             * @throws ServletException upon error
548:             */
549:            public void init() throws javax.servlet.ServletException {
550:                ConfigManager.setControllerFactory(this );
551:                super .init();
552:            }
553:
554:            /**
555:             * Remove myself as a controller factory
556:             */
557:            public void destroy() {
558:                ConfigManager.setControllerFactory(null);
559:                super .destroy();
560:            }
561:
562:            /**
563:             * subclass in order to allow ExpressoActionServlet to be a dispatcher
564:             * for any finite-state-machine request which includes parameters for controller &
565:             * state.  if ExpressoActionServlet does not play this role, URLs must have
566:             * a known controller embedded, which is not good for a JSP, for example,
567:             * that isn't supposed to know about controllers.  instead,
568:             * ExpressoServletAction can be the "universal dispatcher"
569:             *
570:             * Identify and return the path component (from the request URI) that
571:             * we will use to select an ActionMapping to dispatch with.  If no such
572:             * path can be identified, return <code>null</code>.
573:             *
574:             * @param request The servlet request we are processing
575:             * @return String
576:             */
577:            /**
578:             protected String processPath(HttpServletRequest request) {
579:             String path = super.processPath(request);
580:
581:             String controller = request.getParameter(Controller.CONTROLLER_PARAM_KEY);
582:             if ( controller != null ) {
583:             // do reverse-lookup from controller class to mapping
584:             ActionMapping mapping = ConfigManager.getMapping(
585:             controller,
586:             request.getParameter(STATE_PARAM_KEY));
587:             if ( mapping != null ) {
588:             path = mapping.getPath();
589:             }
590:             }
591:
592:             return path;
593:             }
594:             */
595:
596:            /**
597:             * Perform backwards-compatible configuration of the default module's
598:             * controller configuration from servlet initialization parameters (as
599:             * were used in Struts 1.0).
600:             *
601:             * @param config The ModuleConfig object for the default module
602:             * @since Struts 1.1
603:             * @deprecated Will be removed in a release after Struts 1.1.
604:             */
605:            private void defaultControllerConfig(ModuleConfig config) {
606:
607:                String value = null;
608:                ControllerConfig cc = config.getControllerConfig();
609:
610:                value = getServletConfig().getInitParameter("bufferSize");
611:                if (value != null) {
612:                    cc.setBufferSize(Integer.parseInt(value));
613:                }
614:
615:                value = getServletConfig().getInitParameter("content");
616:                if (value != null) {
617:                    cc.setContentType(value);
618:                }
619:
620:                value = getServletConfig().getInitParameter("locale");
621:                // must check for null here
622:                if (value != null) {
623:                    if ("true".equalsIgnoreCase(value)
624:                            || "yes".equalsIgnoreCase(value)) {
625:                        cc.setLocale(true);
626:                    } else {
627:                        cc.setLocale(false);
628:                    }
629:                }
630:
631:                value = getServletConfig().getInitParameter("maxFileSize");
632:                if (value != null) {
633:                    cc.setMaxFileSize(value);
634:                }
635:
636:                value = getServletConfig().getInitParameter("nocache");
637:                if (value != null) {
638:                    if ("true".equalsIgnoreCase(value)
639:                            || "yes".equalsIgnoreCase(value)) {
640:                        cc.setNocache(true);
641:                    } else {
642:                        cc.setNocache(false);
643:                    }
644:                }
645:
646:                value = getServletConfig().getInitParameter("multipartClass");
647:                if (value != null) {
648:                    cc.setMultipartClass(value);
649:                }
650:
651:                value = getServletConfig().getInitParameter("tempDir");
652:                if (value != null) {
653:                    cc.setTempDir(value);
654:                }
655:
656:            }
657:
658:            /**
659:             * Perform backwards-compatible configuration of an ActionFormBeans
660:             * collection, and expose it as a servlet context attribute (as was
661:             * used in Struts 1.0).  Note that the current controller code does
662:             * not (and should not) reference this attribute for any reason.
663:             *
664:             * @param config The ModuleConfig object for the default app
665:             * @since Struts 1.1
666:             * @deprecated Will be removed in a release after Struts 1.1.
667:             */
668:            private void defaultFormBeansConfig(ModuleConfig config) {
669:
670:                FormBeanConfig fbcs[] = config.findFormBeanConfigs();
671:                ActionFormBeans afb = new ActionFormBeans();
672:                afb.setFast(false);
673:                for (int i = 0; i < fbcs.length; i++) {
674:                    afb.addFormBean((ActionFormBean) fbcs[i]);
675:                }
676:                afb.setFast(true);
677:                getServletContext().setAttribute(Globals.FORM_BEANS_KEY, afb);
678:
679:            }
680:
681:            /**
682:             * Perform backwards-compatible configuration of an ActionForwards
683:             * collection, and expose it as a servlet context attribute (as was
684:             * used in Struts 1.0).  Note that the current controller code does
685:             * not (and should not) reference this attribute for any reason.
686:             *
687:             * @param config The ModuleConfig object for the default app
688:             * @since Struts 1.1
689:             * @deprecated Will be removed in a release after Struts 1.1.
690:             */
691:            private void defaultForwardsConfig(ModuleConfig config) {
692:
693:                ForwardConfig fcs[] = config.findForwardConfigs();
694:                ActionForwards af = new ActionForwards();
695:                af.setFast(false);
696:                for (int i = 0; i < fcs.length; i++) {
697:                    af.addForward((ActionForward) fcs[i]);
698:                }
699:                af.setFast(true);
700:                getServletContext().setAttribute(Globals.FORWARDS_KEY, af);
701:
702:            }
703:
704:            /**
705:             * Perform backwards-compatible configuration of an ActionMappings
706:             * collection, and expose it as a servlet context attribute (as was
707:             * used in Struts 1.0).  Note that the current controller code does
708:             * not (and should not) reference this attribute for any reason.
709:             *
710:             * @param config The ModuleConfig object for the default app
711:             * @since Struts 1.1
712:             * @deprecated Will be removed in a release after Struts 1.1.
713:             */
714:            private void defaultMappingsConfig(ModuleConfig config) {
715:
716:                ActionConfig acs[] = config.findActionConfigs();
717:                ActionMappings am = new ActionMappings();
718:                am.setServlet(this );
719:                am.setFast(false);
720:                for (int i = 0; i < acs.length; i++) {
721:                    am.addMapping((ActionMapping) acs[i]);
722:                }
723:                am.setFast(true);
724:                getServletContext().setAttribute(Globals.MAPPINGS_KEY, am);
725:
726:            }
727:
728:            /**
729:             * Perform backwards-compatible configuration of the default module's
730:             * message resources configuration from servlet initialization parameters
731:             * (as were used in Struts 1.0).
732:             *
733:             * @param config The ModuleConfig object for the default module
734:             * @since Struts 1.1
735:             * @deprecated Will be removed in a release after Struts 1.1.
736:             */
737:            private void defaultMessageResourcesConfig(ModuleConfig config) {
738:
739:                String value = null;
740:
741:                MessageResourcesConfig mrc = config
742:                        .findMessageResourcesConfig(Globals.MESSAGES_KEY);
743:                if (mrc == null) {
744:                    mrc = new MessageResourcesConfig();
745:                    mrc.setKey(Globals.MESSAGES_KEY);
746:                    config.addMessageResourcesConfig(mrc);
747:                }
748:                value = getServletConfig().getInitParameter("application");
749:                if (value != null) {
750:                    mrc.setParameter(value);
751:                }
752:                value = getServletConfig().getInitParameter("factory");
753:                if (value != null) {
754:                    mrc.setFactory(value);
755:                }
756:                value = getServletConfig().getInitParameter("null");
757:                if (value != null) {
758:                    if (value.equalsIgnoreCase("true")
759:                            || value.equalsIgnoreCase("yes")) {
760:                        mrc.setNull(true);
761:                    } else {
762:                        mrc.setNull(false);
763:                    }
764:                }
765:
766:            }
767:
768:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.