KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mc > formgenerator > servlets > ServletView


1 /*
2  * Created on 16 mai 2005 by the Message Center Team
3  *
4  */

5 package mc.formgenerator.servlets;
6
7 //import java.io.File;
8
import hero.util.HeroException;
9
10 import java.io.File JavaDoc;
11 import java.io.FileNotFoundException JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.io.PrintWriter JavaDoc;
14 import java.net.MalformedURLException JavaDoc;
15 //import java.io.PrintWriter;
16
import java.rmi.RemoteException JavaDoc;
17 import java.util.Enumeration JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20 import hero.interfaces.*;
21
22 import javax.ejb.CreateException JavaDoc;
23 import javax.naming.NamingException JavaDoc;
24 import javax.security.auth.login.LoginException JavaDoc;
25 import javax.servlet.ServletConfig JavaDoc;
26 import javax.servlet.ServletException JavaDoc;
27 import javax.servlet.http.HttpServlet JavaDoc;
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
30 import javax.servlet.http.HttpSession JavaDoc;
31 import javax.xml.transform.TransformerConfigurationException JavaDoc;
32 import javax.xml.transform.TransformerException JavaDoc;
33
34 import mc.formgenerator.bonita.BonitaActivityAdapter;
35 import mc.formgenerator.bonita.BonitaActivityExecutor;
36 import mc.formgenerator.bonita.BonitaProjectAdapter;
37 import mc.formgenerator.bonita.BonitaProjectExecutor;
38 import mc.formgenerator.bonita.DocumentParser;
39 import mc.formgenerator.ggf.GGF;
40 import mc.formgenerator.servlets.util.MessageServlet;
41
42 import org.chiba.adapter.web.ServletAdapter;
43 import org.chiba.adapter.ChibaAdapter;
44 import org.chiba.xml.xforms.config.Config;
45 import org.chiba.xml.xforms.exception.XFormsException;
46 import org.w3c.dom.Document JavaDoc;
47 import org.xml.sax.SAXException JavaDoc;
48
49 import org.apache.log4j.Category;
50
51 /**
52  * Servlet that will show Xforms
53  * @author cesterbj
54  */

55 public class ServletView extends HttpServlet JavaDoc {
56
57     //ServletAdapter instance
58
private ServletAdapter servletAdapter = null;
59     
60     //GGF instance
61
private GGF ggf = null;
62     
63     //Allow us to know if we are working with an activity or a project
64
private Boolean JavaDoc isActivity;
65     
66     //Name of the project we are working with
67
private String JavaDoc projectName = null;
68
69     //Name of the activity we are working with
70
private String JavaDoc activityName = null;
71         
72     //Application mode consumer or exploitant
73
private String JavaDoc mode = null;
74     
75     //init-params
76
private static Category cat = Category.getInstance(ServletView.class);
77
78     private static final String JavaDoc FORM_PARAM_NAME = "form";
79     private static final String JavaDoc XSL_PARAM_NAME = "xslt";
80     private static final String JavaDoc CSS_PARAM_NAME = "css";
81     private static final String JavaDoc ACTIONURL_PARAM_NAME = "action_url";
82     /*
83      * It is not thread safe to modify these variables once the
84      * init(ServletConfig) method has been called
85      */

86     // the absolute path to the Chiba config-file
87
private String JavaDoc configPath = null;
88
89     // the rootdir of this app; forms + documents fill be searched under this root
90
private String JavaDoc contextRoot = null;
91
92     // where uploaded files are stored
93
private String JavaDoc uploadDir = null;
94
95     private String JavaDoc stylesPath = null;
96     
97         
98     /**
99      * Returns a short description of the servlet.
100      *
101      * @return - Returns a short description of the servlet.
102      */

103     public String JavaDoc getServletInfo() {
104         return "Servlet Controller for Chiba XForms Processor";
105     }
106
107     /**
108      * Destroys the servlet.
109      */

110     public void destroy() {
111     }
112
113     /**
114      * Start the server side interpretation of the xforms document
115      * @param document the xforms document we have to interprete
116      * @param writer the servlet's writer
117      */

118     private void xformProcessing(Document JavaDoc instance, PrintWriter JavaDoc writer, HttpServletRequest JavaDoc request, String JavaDoc actionURL, HttpSession JavaDoc session)
119         throws TransformerConfigurationException JavaDoc, XFormsException,
120         FileNotFoundException JavaDoc, TransformerException JavaDoc, IOException JavaDoc{
121                     
122         //Build HTML page according to an activity or a project we are working with
123
try{
124             // determine Form to load
125
String JavaDoc formPath = request.getParameter(FORM_PARAM_NAME);
126             //String formPath = File.separator + "web" + File.separator + "xforms" + File.separator + request.getParameter(FORM_PARAM_NAME);
127
System.out.println("===> formpath: "+formPath);
128                         
129             if (formPath == null) {
130                 throw new IOException JavaDoc("File: " + formPath + " not found");
131             }
132             
133             String JavaDoc xslFile = request.getParameter(XSL_PARAM_NAME);
134             String JavaDoc css = request.getParameter(CSS_PARAM_NAME);
135             this.servletAdapter = setupServletAdapter(actionURL, session, formPath, xslFile, css);
136             updateContext(request, session, instance);
137             
138             //add all request params that are not used by this servlet to the context map in ChibaBean
139
storeContextParams(request);
140             this.servletAdapter.init();
141             this.servletAdapter.executeHandler();
142             this.servletAdapter.buildUI(writer);
143         } catch (Exception JavaDoc e) {
144             //Error
145
e.printStackTrace();
146         }
147     }
148     
149     /**
150      * Action on doGet
151      * @param writer Response's writer
152      * @param request Request access
153      * @param response servlet response
154      * @throws TransformerConfigurationException
155      * @throws FileNotFoundException
156      * @throws XFormsException
157      * @throws TransformerException
158      * @throws IOException
159      */

160     private void writingUI(PrintWriter JavaDoc writer, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, String JavaDoc actionURL, HttpSession JavaDoc session)
161         throws LoginException JavaDoc, TransformerConfigurationException JavaDoc,
162                 FileNotFoundException JavaDoc, TransformerException JavaDoc,
163                 IOException JavaDoc, Exception JavaDoc{
164             
165         ProjectSessionHome projecth = null;
166
167         ProjectSession project = null;
168         
169         //Document for server side interpretation
170
Document JavaDoc instance = null;
171
172         //We must get bonita project name
173
this.projectName = request.getParameter("projectName");
174         
175         //We must get bonita activity name eventually
176
this.activityName = request.getParameter("activityName");
177     
178         //Mode consumer or exploitant
179
this.mode = request.getParameter("mode");
180         
181         //Start or stop the activity
182
String JavaDoc action = request.getParameter("action");
183         
184         //Project name parameter is present
185
if(this.projectName != null){
186             
187             //We are working with an activity
188
if(this.activityName != null){
189             
190                 if (action != null){
191                     
192                     if(action.equals("stop")){
193                         
194                         //Creation of executor
195
BonitaActivityExecutor bonitaActivityExecutor = new BonitaActivityExecutor();
196                         
197                         //Terminate activity
198
bonitaActivityExecutor.endActivity(this.activityName, this.projectName);
199                         
200                         //Redirection to work list
201
response.sendRedirect("/formgenerator/ServletWorkList");
202                         
203                         return;
204                     }
205                     else{
206                         this.isActivity = new Boolean JavaDoc(true);
207                         
208                         //Creation of adapter
209
BonitaActivityAdapter bonitaActivityAdapter = new BonitaActivityAdapter();
210                         
211                         //Getting process informations via the adapter
212
instance = bonitaActivityAdapter.getActivityData(this.projectName, activityName);
213                     }
214                 }
215                 else{
216                     this.isActivity = new Boolean JavaDoc(true);
217                     
218                     //Creation of adapter
219
BonitaActivityAdapter bonitaActivityAdapter = new BonitaActivityAdapter();
220                     
221                     //Getting process informations via the adapter
222
instance = bonitaActivityAdapter.getActivityData(this.projectName, activityName);
223                         System.out.println("xformsDocument Act : "+GGF.toString(instance));
224                 }
225             }
226             else{
227                     
228                 //We are working with a project
229
this.isActivity = new Boolean JavaDoc(false);
230                         
231                 //Getting local home by using JNDI
232
projecth = ProjectSessionUtil.getHome();
233
234                 //Creation of the project
235
project = projecth.create();
236
237                 //Project instanciation
238
this.projectName=project.instantiateProject(this.projectName);
239                 
240                 //Creation of adapter
241
BonitaProjectAdapter bonitaProjectAdapter = new BonitaProjectAdapter();
242                     
243                 //Getting process informations via the adapter
244
instance = bonitaProjectAdapter.getProjectData(this.projectName);
245                 System.out.println("xformsDocument Proj : "+GGF.toString(instance));
246             }
247             
248             DocumentParser parser = new DocumentParser();
249             
250             //If the document has properties
251
if(parser.hasProperties(instance)){
252                 //Finally starting of interpretation
253
this.xformProcessing(instance, writer, request, actionURL, session);
254             }
255             else{
256                 //Call executor
257
this.callExecutor(instance);
258                 if (request.getParameter("forward")!=null)
259                 {
260                     response.sendRedirect(request.getParameter("forward"));
261                     }
262                 else
263                 {
264                     //Page redirection
265
if(this.isActivity.booleanValue() == true){
266                         
267                         if(this.mode.equals("consumer"))
268                             //Redirection to todo list
269
response.sendRedirect("/formgenerator/ServletActivityToDoList?projectName=" + projectName);
270                         else
271                             //Redirection to work list
272
response.sendRedirect("/formgenerator/ServletWorkList");
273                     }
274                     else{
275                         if(this.mode.equals("consumer"))
276                             //Redirection to instances projets
277
response.sendRedirect("/formgenerator/ServletInstancesProjects");
278                         else
279                             //Redirection to work list
280
response.sendRedirect("/formgenerator/ServletWorkList");
281                     }
282                     }
283             }
284         }
285         else
286             //Message to user
287
(new MessageServlet()).writeMessage(writer, "PARAMETER FOR projectName IS MISSING CANNOT PERFORM OPERATION");
288     }
289     
290     
291     
292     
293     /**
294      * Call the correct executor
295      * @param filledDocument document that will be use by the executor
296      * @param mode the application mode: consumer or exploitant
297      */

298     private void callExecutor(Document JavaDoc filledDocument)
299         throws MalformedURLException JavaDoc, SAXException JavaDoc, IOException JavaDoc,
300                 RemoteException JavaDoc, NamingException JavaDoc, CreateException JavaDoc, HeroException{
301             
302         System.out.println("===> callExecutor test");
303         if(this.isActivity.booleanValue() == true){
304             
305             //Creation of executor
306
BonitaActivityExecutor bonitaActivityExecutor = new BonitaActivityExecutor();
307                 
308             //Terminate the activity
309
bonitaActivityExecutor.actOnActivity(filledDocument, this.mode);
310         }
311         else{
312
313             //Creation of executor
314
BonitaProjectExecutor bonitaProjectExecutor = new BonitaProjectExecutor();
315                 
316             //Instanciate project
317
bonitaProjectExecutor.startBonitaProject(filledDocument);
318         }
319     }
320     
321     /**
322      * Initializes the servlet.
323      *
324      * @param config - the ServletConfig object
325      * @throws javax.servlet.ServletException
326      */

327     public void init(ServletConfig JavaDoc config) throws ServletException JavaDoc {
328         super.init(config);
329
330         //read some params from web-inf
331
contextRoot = getServletConfig().getServletContext().getRealPath("");
332         if (contextRoot == null)
333             contextRoot = getServletConfig().getServletContext().getRealPath(".");
334         System.out.println("===> contextRoot: "+ contextRoot);
335         
336         //get the relative path to the chiba config-file
337
String JavaDoc path = getServletConfig().getInitParameter("chiba.config");
338
339         //get the real path for the config-file
340
if (path != null) {
341             configPath = getServletConfig().getServletContext().getRealPath(path);
342         }
343         System.out.println("===> configpath : "+ configPath);
344         
345         //get the path for the stylesheets
346
//path = getServletConfig().getServletContext().getInitParameter("chiba.xforms.stylesPath");
347
path = getServletConfig().getInitParameter("chiba.xforms.stylesPath");
348
349         //get the real path for the stylesheets and configure a new StylesheetLoader with it
350
if (path != null) {
351             stylesPath = getServletConfig().getServletContext().getRealPath(path);
352             cat.info("stylesPath: " + stylesPath);
353         }
354         System.out.println("===> stylespath : "+ stylesPath);
355
356         //uploadDir = contextRoot + "/" + getServletConfig().getServletContext().getInitParameter("chiba.upload");
357
//uploadDir = getServletConfig().getServletContext().getInitParameter("chiba.upload");
358
uploadDir = getServletConfig().getInitParameter("chiba.upload");
359         System.out.println("===> uploadDir : "+ uploadDir);
360
361         //Security constraint
362
if (uploadDir != null) {
363             if (uploadDir.toUpperCase().indexOf("WEB-INF") >= 0) {
364                 throw new ServletException JavaDoc("Chiba security constraint: uploadDir '" + uploadDir + "' not allowed");
365             }
366         }
367     }
368
369     
370     /**
371      * Servlet reaction on get method:
372      * Display the form generated for filling a valid XML file
373      */

374     protected void doGet(HttpServletRequest JavaDoc request,HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc
375     {
376         System.out.println("===> GET");
377         
378         this.servletAdapter = null;
379         HttpSession JavaDoc session = request.getSession(true);
380         
381         // get the user language
382
String JavaDoc userLanguage = request.getHeader("Accept-Language");
383         System.out.println("===> userLanguage : "+userLanguage);
384         
385         //write the 'forward' parameter in the session
386
if (request.getParameter("forward")!=null)
387             session.setAttribute("forward",request.getParameter("forward"));
388         else
389             session.removeAttribute("forward");
390                 
391         try {
392             response.setContentType("text/html");
393             java.io.PrintWriter JavaDoc out = response.getWriter();
394
395             // build actionURL where forms are submitted to
396
String JavaDoc actionURL = getActionURL(request, response);
397             
398             //instanciate the generator with a transformation file
399
if (request.getParameter("transform")!=null){
400                 this.ggf = new GGF(this.contextRoot, actionURL,request.getParameter("transform"), userLanguage);
401             }
402             //instanciate with the default xsl file
403
else this.ggf = new GGF(this.contextRoot, actionURL, userLanguage);
404                         
405             
406             //Build HTML page according to an activity or a project we are working with
407
writingUI(out, request, response, actionURL, session);
408
409             //Stores the GGF in the session
410
session.setAttribute("formgenerator.GGF", this.ggf);
411             
412             //Stores the state of isActivity attribute in the session
413
session.setAttribute("formgenerator.isActivity", this.isActivity);
414             
415             //Stores the projectname in the session
416
session.setAttribute("formgenerator.projectName", this.projectName);
417             
418             //Stores the activity name in the session
419
session.setAttribute("formgenerator.activityName", this.activityName);
420             
421             //Stores the application mode in the session
422
session.setAttribute("formgenerator.mode", this.mode);
423         
424             //Stores the servletAdapter
425
session.setAttribute("formgenerator.sAdapter", this.servletAdapter);
426             
427             out.close();
428             
429         } catch (Exception JavaDoc e) {
430             //Error
431
e.printStackTrace();
432         }
433     }
434     
435     /**
436      * this method is responsible for passing all context information needed by the Adapter and Processor from
437      * ServletRequest to ChibaContext.
438      *
439      * @param servletAdapter the ChibaAdapter to use
440      * @param request the ServletRequest
441      * @param session the ServletSession
442      */

443     protected void updateContext(HttpServletRequest JavaDoc request, HttpSession JavaDoc session,Document JavaDoc formDocument) {
444         this.servletAdapter.setContextProperty(ServletAdapter.USERAGENT, request.getHeader("User-Agent"));
445         this.servletAdapter.setContextProperty(ServletAdapter.HTTP_SERVLET_REQUEST, request);
446         this.servletAdapter.setContextProperty(ServletAdapter.HTTP_SESSION_OBJECT, session);
447         this.servletAdapter.setContextProperty("instance",formDocument);
448     }
449
450
451     /**
452      * handles all interaction with the user during a form-session.
453      *
454      * @param request servlet request
455      * @param response servlet response
456      * @throws javax.servlet.ServletException
457      * @throws java.io.IOException
458      */

459     protected void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc
460     {
461         //Getting the current session
462
HttpSession JavaDoc session = request.getSession(true);
463         this.servletAdapter = null;
464
465         try {
466             //Getting servletAdapter from the session
467
System.out.println("===> ServletAdapter");
468             this.servletAdapter = (ServletAdapter)session.getAttribute("formgenerator.sAdapter");
469
470             //Getting GGF from the session
471
System.out.println("===> GGF");
472             this.ggf = (GGF)session.getAttribute("formgenerator.GGF");
473             //Reset the GGF in the session
474
session.setAttribute("formgenerator.GGF", this.ggf);
475             
476             //Getting isActivity from the session
477
this.isActivity = (Boolean JavaDoc)session.getAttribute("formgenerator.isActivity");
478             //Set isActivity in the session
479
session.setAttribute("formgenerator.isActivity", this.isActivity);
480             
481             //Getting projectName from the session
482
this.projectName = (String JavaDoc)session.getAttribute("formgenerator.projectName");
483             System.out.println("===> projectName : "+projectName);
484             //Set the projectname in the session
485
session.setAttribute("formgenerator.projectName", this.projectName);
486             
487             //Getting activityName from the session
488
this.activityName = (String JavaDoc)session.getAttribute("formgenerator.activityName");
489             //Set the activityname in the session
490
session.setAttribute("formgenerator.activityName", this.activityName);
491                 
492             //Getting mode from the session
493
this.mode = (String JavaDoc)session.getAttribute("formgenerator.mode");
494             
495             
496             if ((this.servletAdapter == null)||(this.ggf == null)||(this.isActivity == null)||(this.projectName == null)){
497                 //Exception
498
throw new IOException JavaDoc("Invalid session - Cannot retrieve servletAdapter or ggf or isActivity or projectName in the session");
499             }
500                     
501             updateContextPost(request, session);
502             
503             this.servletAdapter.executeHandler();
504             System.out.println("===> executeHandler");
505             
506             //get instance filled
507
Document JavaDoc filledDocument = (Document JavaDoc)this.servletAdapter.getChibaBean().getContainer().getModel("model").getInstance("instance").getInstanceDocument();
508             
509             if (filledDocument == null) {
510                 throw new ServletException JavaDoc(Config.getInstance().getErrorMessage("session-invalid"));
511             }
512             System.out.println("===> filledDocument : " + GGF.toString(filledDocument));
513             
514
515             /*
516             // handle setRedirect <xforms:load show='replace'/>
517             // and redirect from submission as well
518             // NOTE - this needs to be checked *before* the this.getForwardMap()
519             // as a submission handler may force a redirect
520             if (this.servletAdapter.getRedirectUri() != null) {
521                 String redirectTo = this.servletAdapter.getRedirectUri();
522                 // todo: remove from session ?
523                 // shutdown processor
524                 this.servletAdapter.getChibaBean().shutdown();
525
526                 // send redirect (after encoding session id if required)
527                 response.sendRedirect(response.encodeRedirectURL(redirectTo));
528
529                 // remove redirect uri and terminate
530                 this.servletAdapter.setRedirect(null);
531                 return;
532             }
533
534             // handle forward <xforms:submission replace='all'/>
535             Map forwardMap = this.servletAdapter.getForwardMap();
536             InputStream forwardStream = (InputStream) forwardMap.get(ChibaAdapter.SUBMISSION_RESPONSE_STREAM);
537             if (forwardStream != null) {
538                 // todo: remove from session ?
539                 // shutdown processor
540                 this.servletAdapter.getChibaBean().shutdown();
541
542                 // forward submission response
543                 forwardResponse(forwardMap, response);
544
545                 // remove forward response and terminate
546                 this.servletAdapter.forward(null);
547                 return;
548             }
549             */

550
551             // set content type
552
response.setContentType("text/html");
553             
554             //Calling the executor
555
this.callExecutor(filledDocument);
556             
557             //Page redirection
558

559             //use the forward parameter form the session in order to redirect the output
560
String JavaDoc forward = (String JavaDoc)session.getAttribute("forward");
561             if ((forward!=null)&&!forward.equals(""))
562                 response.sendRedirect(forward);
563             
564             //use default redirection
565
else
566                 if(this.isActivity.booleanValue() == true){
567                     
568                     if(this.mode.equals("consumer"))
569                         //Redirection to todo list
570
response.sendRedirect("/formgenerator/ServletActivityToDoList?projectName=" + projectName);
571                     else
572                         //Redirection to work list
573
response.sendRedirect("/formgenerator/ServletWorkList");
574                 }
575                 else{
576                     if(this.mode.equals("consumer"))
577                         //Redirection to instances projets
578
response.sendRedirect("/formgenerator/ServletInstancesProjects");
579                     else
580                         //Redirection to work list
581
response.sendRedirect("/formgenerator/ServletWorkList");
582                 }
583
584             // render result to output
585
this.servletAdapter.buildUI(response.getWriter());
586             response.getWriter().close();
587         } catch (Exception JavaDoc e) {
588             //Error
589
e.printStackTrace();
590         }
591     }
592     
593     /**
594      * this method is responsible for passing all context information needed by the Adapter and Processor from
595      * ServletRequest to ChibaContext.
596      *
597      * @param servletAdapter the ChibaAdapter to use
598      * @param request the ServletRequest
599      * @param session the ServletSession
600      */

601     protected void updateContextPost(HttpServletRequest JavaDoc request, HttpSession JavaDoc session) {
602         this.servletAdapter.setContextProperty(ServletAdapter.USERAGENT, request.getHeader("User-Agent"));
603         this.servletAdapter.setContextProperty(ServletAdapter.HTTP_SERVLET_REQUEST, request);
604         this.servletAdapter.setContextProperty(ServletAdapter.HTTP_SESSION_OBJECT, session);
605     }
606
607     /**
608      * creates and configures the ServletAdapter which does the actual request processing.
609      *
610      * @param actionURL - the URL to submit to
611      * @param session - the Servlet session
612      * @param formPath - the relative location where forms are stored
613      * @param xslFile - the xsl file to use for transform
614      * @param cssFile - the CSS file to use for styling the output
615      * @return ServletAdapter
616      */

617     private ServletAdapter setupServletAdapter(String JavaDoc actionURL,
618                                                HttpSession JavaDoc session,
619                                                String JavaDoc formPath,
620                                                String JavaDoc xslFile,
621                                                String JavaDoc cssFile) {
622         //setup and configure the adapter
623
ServletAdapter aAdapter = new ServletAdapter();
624         aAdapter.setContextRoot(contextRoot);
625         if ((configPath != null) && !(configPath.equals(""))) {
626             aAdapter.setConfigPath(configPath);
627         }
628         aAdapter.setFormPath(formPath);
629         aAdapter.setStylesheetPath(stylesPath);
630         aAdapter.setActionUrl(actionURL);
631         aAdapter.setUploadDir(uploadDir);
632
633         if (xslFile != null) {
634             aAdapter.setStylesheet(xslFile);
635             if (cat.isDebugEnabled()) {
636                 cat.debug("using xsl stylesheet: " + xslFile);
637             }
638         }
639         if (cssFile != null) {
640             aAdapter.setCSS(cssFile);
641             if (cat.isDebugEnabled()) {
642                 cat.debug("using css stylesheet: " + cssFile);
643             }
644         }
645
646         Map JavaDoc servletMap = new HashMap JavaDoc();
647         servletMap.put(ChibaAdapter.SESSION_ID, session.getId());
648         aAdapter.setContextProperty(ChibaAdapter.SUBMISSION_RESPONSE, servletMap);
649
650         return aAdapter;
651     }
652
653     private void storeContextParams(HttpServletRequest JavaDoc request) {
654         Enumeration JavaDoc params = request.getParameterNames();
655         String JavaDoc s;
656         while (params.hasMoreElements()) {
657             s = (String JavaDoc) params.nextElement();
658             //store all request-params we don't use in the context map of ChibaBean
659
if (!(s.equals(FORM_PARAM_NAME) || s.equals(XSL_PARAM_NAME) || s.equals(CSS_PARAM_NAME) || s.equals(ACTIONURL_PARAM_NAME))) {
660                 String JavaDoc value = request.getParameter(s);
661                 this.servletAdapter.setContextProperty(s, value);
662                 if (cat.isDebugEnabled()) {
663                     cat.debug("added request param '" + s + "' added to context");
664                 }
665             }
666         }
667     }
668
669     private String JavaDoc getActionURL(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
670         String JavaDoc defaultActionURL =
671                 request.getScheme()
672                 + "://"
673                 + request.getServerName()
674                 + ":"
675                 + request.getServerPort()
676                 + request.getContextPath()
677                 + request.getServletPath();
678         String JavaDoc encodedDefaultActionURL = response.encodeURL(defaultActionURL);
679         int sessIdx = encodedDefaultActionURL.indexOf(";jsession");
680         String JavaDoc sessionId = null;
681         if (sessIdx > -1) {
682             sessionId = encodedDefaultActionURL.substring(sessIdx);
683         }
684         String JavaDoc actionURL = request.getParameter(ACTIONURL_PARAM_NAME);
685         if (null == actionURL) {
686             actionURL = encodedDefaultActionURL;
687         } else if (null != sessionId) {
688             actionURL += sessionId;
689         }
690
691         cat.info("actionURL: " + actionURL);
692         // encode the URL to allow for session id rewriting
693
actionURL = response.encodeURL(actionURL);
694         return actionURL;
695     }
696 /*
697     private void forwardResponse(Map forwardMap, HttpServletResponse response) throws IOException {
698         // fetch response stream
699         InputStream responseStream = (InputStream) forwardMap.remove(ChibaAdapter.SUBMISSION_RESPONSE_STREAM);
700
701         // copy header information
702         Iterator iterator = forwardMap.keySet().iterator();
703         while (iterator.hasNext()) {
704             String name = iterator.next().toString();
705             String value = forwardMap.get(name).toString();
706             response.setHeader(name, value);
707         }
708
709         // copy stream content
710         OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
711         for (int b = responseStream.read();
712              b > -1;
713              b = responseStream.read()) {
714             outputStream.write(b);
715         }
716
717         // close streams
718         responseStream.close();
719         outputStream.close();
720     }
721
722     private void shutdown(HttpSession session, Exception e, HttpServletResponse response, HttpServletRequest request) throws IOException {
723         // attempt to shutdown processor
724         if (this.servletAdapter != null && this.servletAdapter.getChibaBean() != null) {
725             try {
726                 this.servletAdapter.getChibaBean().shutdown();
727             } catch (XFormsException xfe) {
728                 xfe.printStackTrace();
729             }
730         }
731
732         // store exception
733         session.setAttribute("chiba.exception", e);
734
735         // redirect to error page (after encoding session id if required)
736         response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/" +
737                 request.getSession().getServletContext().getInitParameter("error.page")));
738     }
739     */

740 }
Popular Tags