KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > applications > StrutsRequestDispatcherProcessor


1 package org.jahia.services.applications;
2
3 import org.apache.struts.Globals;
4
5 import javax.servlet.ServletException JavaDoc;
6 import java.util.Vector JavaDoc;
7
8 /**
9  * For request forward and include pre/post processing
10  * <p>Title: </p>
11  * <p>Description: </p>
12  * <p>Copyright: Copyright (c) 2002</p>
13  * <p>Company: </p>
14  *
15  * @author Khue Nguyen
16  * @version 1.0
17  */

18 public class StrutsRequestDispatcherProcessor implements
19         RequestDispatcherProcessor {
20
21     private boolean preProcessed = false;
22     private boolean postProcessed = false;
23
24     private static String JavaDoc[] attributeNames;
25     private static String JavaDoc[] attributeScopes;
26
27     private Vector JavaDoc attributes;
28
29
30     static {
31
32         String JavaDoc[] names =
33           {
34             Globals.ACTION_SERVLET_KEY,
35             Globals.CANCEL_KEY,
36             Globals.DATA_SOURCE_KEY,
37             Globals.ERROR_KEY,
38             Globals.EXCEPTION_KEY,
39             Globals.LOCALE_KEY,
40             Globals.MAPPING_KEY,
41             Globals.MESSAGE_KEY,
42             Globals.MESSAGES_KEY,
43             Globals.MODULE_KEY,
44             Globals.MODULE_PREFIXES_KEY,
45             Globals.MULTIPART_KEY,
46             Globals.PLUG_INS_KEY,
47             Globals.REQUEST_PROCESSOR_KEY,
48             Globals.SERVLET_KEY,
49                           Globals.TRANSACTION_TOKEN_KEY};
50         attributeNames = names;
51
52         String JavaDoc[] scopes =
53           {
54                            StrutsGlobalAttribute.REQUEST_SCOPE,
55                            StrutsGlobalAttribute.REQUEST_SCOPE,
56                            StrutsGlobalAttribute.REQUEST_SCOPE,
57                            StrutsGlobalAttribute.REQUEST_SCOPE,
58                            StrutsGlobalAttribute.REQUEST_SCOPE,
59                            StrutsGlobalAttribute.SESSION_SCOPE,
60                            StrutsGlobalAttribute.REQUEST_SCOPE,
61                            StrutsGlobalAttribute.REQUEST_SCOPE,
62                            StrutsGlobalAttribute.REQUEST_SCOPE,
63                            StrutsGlobalAttribute.REQUEST_SCOPE,
64                            StrutsGlobalAttribute.REQUEST_SCOPE,
65                            StrutsGlobalAttribute.REQUEST_SCOPE,
66                            StrutsGlobalAttribute.REQUEST_SCOPE,
67                            StrutsGlobalAttribute.REQUEST_SCOPE,
68                            StrutsGlobalAttribute.REQUEST_SCOPE,
69                            StrutsGlobalAttribute.SESSION_SCOPE};
70
71         attributeScopes = scopes;
72
73     }
74
75     public StrutsRequestDispatcherProcessor () {
76         initAttributes ();
77     }
78
79     public void preForward (ServletIncludeRequestWrapper request,
80                             ServletIncludeResponseWrapper response)
81             throws ServletException JavaDoc, java.io.IOException JavaDoc {
82         backupGlobalAttributes (request, response);
83     }
84
85     public void postForward (ServletIncludeRequestWrapper request,
86                              ServletIncludeResponseWrapper response)
87             throws ServletException JavaDoc, java.io.IOException JavaDoc {
88         restoreGlobalAttributes (request, response);
89     }
90
91     public void preInclude (ServletIncludeRequestWrapper request,
92                             ServletIncludeResponseWrapper response)
93             throws ServletException JavaDoc, java.io.IOException JavaDoc {
94         backupGlobalAttributes (request, response);
95     }
96
97     public void postInclude (ServletIncludeRequestWrapper request,
98                              ServletIncludeResponseWrapper response)
99             throws ServletException JavaDoc, java.io.IOException JavaDoc {
100         restoreGlobalAttributes (request, response);
101     }
102
103     private void backupGlobalAttributes (ServletIncludeRequestWrapper request,
104                                          ServletIncludeResponseWrapper response)
105             throws ServletException JavaDoc, java.io.IOException JavaDoc {
106         if (!preProcessed) {
107             int size = this.attributes.size ();
108             StrutsGlobalAttribute at = null;
109             for (int i = 0; i < size; i++) {
110                 at = (StrutsGlobalAttribute) this.attributes.get (i);
111                 at.backupAttribute (request, response);
112             }
113         }
114     }
115
116     private void restoreGlobalAttributes (ServletIncludeRequestWrapper request,
117                                           ServletIncludeResponseWrapper response)
118             throws ServletException JavaDoc, java.io.IOException JavaDoc {
119         if (!postProcessed) {
120             int size = this.attributes.size ();
121             StrutsGlobalAttribute at = null;
122             for (int i = 0; i < size; i++) {
123                 at = (StrutsGlobalAttribute) this.attributes.get (i);
124                 at.restoreAttribute (request, response);
125             }
126         }
127     }
128
129     /**
130      *
131      */

132     private void initAttributes () {
133         this.attributes = new Vector JavaDoc ();
134
135         int length = attributeNames.length;
136         for (int i = 0; i < length; i++) {
137             StrutsGlobalAttribute at =
138                     new StrutsGlobalAttribute (attributeNames[i], attributeScopes[i]);
139             this.attributes.add (at);
140         }
141     }
142 }
143
Popular Tags