KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > contrib > dbroggisch > examples > controller > DBRApplicationGateway


1 /*
2  * Copyright (C) 2003 Diez B. Roggisch [deets@web.de]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: DBRApplicationGateway.java,v 1.5 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.contrib.dbroggisch.examples.controller;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import org.enhydra.barracuda.core.event.ApplicationGateway;
26 import org.enhydra.barracuda.core.event.DispatcherFactory;
27 import org.enhydra.barracuda.core.helper.servlet.RequestWrapper;
28 import org.enhydra.barracuda.core.helper.servlet.DefaultServletRequestWrapper;
29 import org.enhydra.barracuda.contrib.dbroggisch.page.PageDispatcherFactory;
30 import org.enhydra.barracuda.contrib.dbroggisch.page.RenderPageEventGateway;
31 import org.apache.log4j.Logger;
32
33 import org.enhydra.barracuda.contrib.dbroggisch.examples.controller.servlets.MyMultipartRequest;
34
35
36 public class DBRApplicationGateway extends ApplicationGateway {
37
38     private static final Logger logger = Logger.getLogger(DBRApplicationGateway.class.getName());
39
40     public static boolean WRAPPER_INSTALLED = false;
41
42     public void initializeLocal() {
43         WRAPPER_INSTALLED = installWrapper();
44         specifyEventGateways(new RenderPageEventGateway());
45
46     }
47
48     private boolean installWrapper() {
49         String JavaDoc destDir = null;
50         File JavaDoc tempDir = (File JavaDoc)getServletConfig().getServletContext().getAttribute("javax.servlet.context.tempdir");
51         // Only if we have write permission to that directory we install the wrapper.
52
if(tempDir.canWrite()) {
53             REQUEST_WRAPPER = new SampleRequestWrapper(tempDir.getAbsolutePath());
54             return true;
55         }
56         return false;
57     }
58
59     public static class SampleRequestWrapper implements RequestWrapper {
60         String JavaDoc _destDir;
61         public SampleRequestWrapper(String JavaDoc destDir) {
62             _destDir = destDir;
63         }
64
65         public HttpServletRequest JavaDoc wrap(HttpServletRequest JavaDoc req) {
66             // If the request isn't multipart/mime, we'll get a IOException. Then we
67
// simply pass the request directly to the
68
// org.enhydra.barracuda.core.helper.servlet.DefaultServletRequestWrapper
69
try {
70                 return new DefaultServletRequestWrapper(new MyMultipartRequest(req, _destDir));
71             } catch(IOException JavaDoc ex) {
72                 return new DefaultServletRequestWrapper(req);
73             }
74         }
75     }
76
77 // public DispatcherFactory getDispatcherFactory() {
78
// if (logger.isDebugEnabled()) logger.debug("instantiating SessionTreeStateDispatcherFactory");
79
// return new SessionTreeStateDispatcher.DispatcherFactory();
80
// }
81

82     public DispatcherFactory getDispatcherFactory() {
83         return new PageDispatcherFactory();
84     }
85
86 }
87
Popular Tags