KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > params > SerializableParamBean


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12

13 //
14
// ParamBean
15
// EV 03.11.2000
16
// EV 23.12.2000 SettingsBean now in ParamBean
17
// SH 24.01.2001 added getSession accessor
18
// SH 24.01.2001 added some debugging code and some comments about comportement under Orion
19
// DJ 30.01.2001 added an internal wrapper for FileUpload/HttpServletRequest getParameter.
20
// SH 04.02.2001 added some comments on InputStream, Parameters, WebApps problems + javadoc
21
// MJ 21.03.2001 replaced basic URL parameters with PathInfo elements
22
// NK 17.04.2001 added Multisite features
23
// NK 14.05.2001 Jump to requested site's home page when the actual requested page is not of this site
24
// instead of page not found Exception.
25
// NK 11.07.2001 Added last requested page parameter
26
// JB 25.10.2001 Added setOperationMode methode
27
// SH 01.02.2002 Added defaultParameterValues hashtable to reduce URL length
28
// when using default values for engine names, operation
29
// modes, etc...
30
// FH 15.08.2003 - javadoc fixes
31
// - removed redundant class casting
32
// - removed unused private attribute
33
//
34
// Development notes : for the moment this class does not handle the problematic
35
// of reading an input stream multiple times. This can cause problems if for
36
// example Jahia needs to read the InputStream object from the request before
37
// forwarding it to a web application. Also, under some server implementations,
38
// such as the Orion server, retrieving an InputStream object before reading the
39
// parameters will cause an error when trying to call a getParameter method.
40
// The main issue of all this is that we are very dependant on the implementation
41
// of these methods right now. A solution that was studied involved writing
42
// parsers for the content of the request and managing the body internally inside
43
// Jahia. This is probably the most solid way to do it, but it involves a lot of
44
// development, especially since there should be a significant performance hit
45
// if not done fully.
46
// Basically the solution would be something like this :
47
// 1. Jahia retrieves the InputStream (or Reader) object
48
// 2. Jahia retrieves the full content and stores it either in memory or on disk
49
// depending on some criteria to be defined (size, type of request ?)
50
// 3. Jahia parses the parameters included in the request body, making sure it
51
// then uses only the result of that parsing internally
52
// 4. Jahia's dispatching service can then emulate a full web container behaviour
53
// without much problems, since it can intercept everything, include the request
54
// body (which is the part of the emulation currently missing). So the application
55
// could indeed retrieve an InputStream or a Reader that is passed the body only
56
// of that application and that comes from memory or disk storage instead of the
57
// socket.
58
//
59
// Advantages :
60
// - Allows for a FULL implementation of a request object
61
// - Allows Jahia and web applications to process the request multiple times
62
// - Improved security because we could only pass the body that concerns the
63
// web application.
64
//
65
// Disadvantages :
66
// - Serious performance hit because the worst case is : Jahia processes the
67
// request body, parses it, forwards it to the app, that reprocesses it again !
68
// The current case is : Jahia forwards it directly to the webapp, not reading
69
// it most of the time.
70
// - Loss of security because in some cases an application can receive a GET
71
// request that actually has the body of a POST request (this is because the
72
// emulation replaces the URL but not the body currently, mostly for performance
73
// reasons).
74
// - More usage of resources, since request bodies should have to be stored
75
// in memory and/or on disk, probably multiple times.
76
// The current decision was not to go forward with this implementation since it
77
// will involve a lot of work and that the benefits are dependant on the applications
78
// that must run under it. If the applications do not undergo problems in the
79
// meantime the current solution should be sufficient.
80
//
81

82 /**
83  * @todo Implement a system to store parameters either in the session or in
84  * the URL, transparently, in order to generate short URLs
85  *
86      * @todo Implement static (or search engine) friendly URLs, such as .html ending
87  * URLs
88  */

89
90 package org.jahia.params;
91
92 import java.io.IOException JavaDoc;
93 import java.io.ObjectInputStream JavaDoc;
94 import java.io.ObjectOutputStream JavaDoc;
95 import java.io.Serializable JavaDoc;
96 import java.util.ArrayList JavaDoc;
97 import java.util.Locale JavaDoc;
98
99 import javax.servlet.http.HttpServletRequest JavaDoc;
100
101 import org.jahia.bin.Jahia;
102 import org.jahia.exceptions.JahiaException;
103 import org.jahia.exceptions.JahiaPageNotFoundException;
104 import org.jahia.exceptions.JahiaSessionExpirationException;
105 import org.jahia.exceptions.JahiaSiteNotFoundException;
106 import org.jahia.services.applications.ServletIncludeRequestWrapper;
107 import org.jahia.services.sites.JahiaSite;
108 import org.jahia.services.usermanager.JahiaUser;
109 import org.jahia.services.version.EntryLoadRequest;
110
111 /**
112  * A ParamBean with null request and null response
113  *
114  */

115 public class SerializableParamBean extends ParamBean implements Serializable JavaDoc {
116
117     private DummyServletRequestWrapper dummyRequest;
118
119     private String JavaDoc operationMode = ParamBean.EDIT;
120
121     private Locale JavaDoc locale;
122     
123     
124     /**
125      * Initializes an instance of this class. This constructor is required for
126      * the serialization.
127      */

128     public SerializableParamBean()
129     {
130       // do nothing
131
}
132     
133     /**
134      * jParams should not be null !
135      *
136      * @param jParams
137      * @throws JahiaPageNotFoundException
138      * @throws JahiaSessionExpirationException
139      * @throws JahiaSiteNotFoundException
140      * @throws JahiaException
141      */

142     public SerializableParamBean(ParamBean jParams)
143     throws JahiaPageNotFoundException, JahiaSessionExpirationException,
144             JahiaSiteNotFoundException, JahiaException
145     {
146         super(null, null, Jahia.getStaticServletConfig().getServletContext(),
147               Jahia.getSettings(), System.currentTimeMillis(),
148               ParamBean.POST_METHOD, jParams.getSite(), jParams.getUser(), jParams.getContentPage());
149         this.dummyRequest = new DummyServletRequestWrapper(jParams.getUser());
150         this.operationMode = jParams.getOperationMode();
151         entryLoadRequest = new EntryLoadRequest(jParams.getEntryLoadRequest());
152         this.locale = (Locale JavaDoc)jParams.getLocale().clone();
153     }
154
155     public HttpServletRequest JavaDoc getRequest(){
156       return this.dummyRequest;
157     }
158
159     public ServletIncludeRequestWrapper getRequestWrapper() {
160         return null;
161     }
162     public HttpServletRequest JavaDoc getRealRequest(){
163         return this.dummyRequest;
164     }
165
166
167     /**
168      * jParams should not be null !
169      *
170      * @param jParams
171      *
172      * @throws JahiaPageNotFoundException
173      * @throws JahiaSessionExpirationException
174      * @throws JahiaSiteNotFoundException
175      * @throws JahiaException
176      */

177     public static SerializableParamBean getInstance(ParamBean jParams)
178     throws JahiaPageNotFoundException, JahiaSessionExpirationException,
179             JahiaSiteNotFoundException, JahiaException {
180         return new SerializableParamBean(jParams);
181     }
182
183     public void changeLanguage (Locale JavaDoc theLocale)
184         throws JahiaSessionExpirationException, JahiaException {
185     }
186
187     public ArrayList JavaDoc getLocales ()
188         throws JahiaException {
189         return new ArrayList JavaDoc();
190     }
191
192     public ArrayList JavaDoc getLocales (boolean allowMixLanguages)
193         throws JahiaException {
194         return new ArrayList JavaDoc();
195     }
196
197     public String JavaDoc getSiteURL (int pageID, boolean withSessionID, boolean withOperationMode) {
198         return null;
199     }
200
201     public String JavaDoc getOperationMode() {
202         return operationMode;
203     }
204
205     public void setOperationMode(String JavaDoc theOperationMode) {
206         this.operationMode = theOperationMode;
207     }
208
209     public Locale JavaDoc getLocale() {
210         return locale;
211     }
212
213     public void setLocale(Locale JavaDoc theLocale) {
214         this.locale = theLocale;
215     }
216     
217     public String JavaDoc toString() {
218         return "SerializableParamBean{siteId: "
219           + getSiteID()
220           + "; locale: "
221           + locale
222           + "; user: "
223           + getUser()
224           + "}";
225     }
226     
227     private void writeObject(ObjectOutputStream JavaDoc out) throws IOException JavaDoc
228     {
229       out.defaultWriteObject();
230       out.writeObject(getSite());
231       out.writeObject(getUser());
232       out.writeObject(entryLoadRequest);
233     }
234   
235     private void readObject(ObjectInputStream JavaDoc in)
236       throws IOException JavaDoc, ClassNotFoundException JavaDoc
237     {
238       in.defaultReadObject();
239       JahiaSite site = (JahiaSite)in.readObject();
240       JahiaUser user = (JahiaUser)in.readObject();
241       entryLoadRequest = (EntryLoadRequest)in.readObject();
242       setData(site, user);
243     }
244
245 }
246
Popular Tags