KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > flex > CmsFlexRequestKey


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/flex/CmsFlexRequestKey.java,v $
3  * Date : $Date: 2006/03/27 14:52:35 $
4  * Version: $Revision: 1.12 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.flex;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.file.CmsRequestContext;
36 import org.opencms.loader.I_CmsResourceLoader;
37 import org.opencms.main.CmsLog;
38
39 import java.util.Map JavaDoc;
40
41 import javax.servlet.http.HttpServletRequest JavaDoc;
42 import javax.servlet.http.HttpSession JavaDoc;
43
44 import org.apache.commons.logging.Log;
45
46 /**
47  * Describes the caching behaviour (or caching options) for a Flex request.<p>
48  *
49  * @author Alexander Kandzior
50  *
51  * @version $Revision: 1.12 $
52  *
53  * @since 6.0.0
54  */

55 public class CmsFlexRequestKey {
56
57     /** The log object for this class. */
58     private static final Log LOG = CmsLog.getLog(CmsFlexRequestKey.class);
59
60     /** The request context this request was made in. */
61     private CmsRequestContext m_context;
62
63     /** The (Flex) Http request this key was constructed for. */
64     private HttpServletRequest JavaDoc m_request;
65
66     /** The OpenCms resource that this key is used for. */
67     private String JavaDoc m_resource;
68
69     /**
70      * This constructor is used when building a cache key from a request.<p>
71      *
72      * The request contains several data items that are neccessary to construct
73      * the output. These items are e.g. the Query-String, the requested resource,
74      * the current time etc. etc.
75      * All required items are saved in the constructed cache - key.<p>
76      *
77      * @param req the request to construct the key for
78      * @param target the requested resource in the OpenCms VFS
79      * @param online must be true for an online resource, false for offline resources
80      */

81     public CmsFlexRequestKey(HttpServletRequest JavaDoc req, String JavaDoc target, boolean online) {
82
83         // store the request
84
m_request = req;
85
86         // fetch the cms from the request
87
CmsObject cms = CmsFlexController.getCmsObject(req);
88
89         // store the request context
90
m_context = cms.getRequestContext();
91
92         // calculate the resource name
93
m_resource = CmsFlexCacheKey.getKeyName(m_context.addSiteRoot(target), online);
94
95         if (LOG.isDebugEnabled()) {
96             LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXREQUESTKEY_CREATED_NEW_KEY_1, m_resource));
97         }
98     }
99
100     /**
101      * Returns the element.<p>
102      *
103      * @return the element
104      */

105     public String JavaDoc getElement() {
106
107         return m_request.getParameter(I_CmsResourceLoader.PARAMETER_ELEMENT);
108     }
109
110     /**
111      * Returns the encoding.<p>
112      *
113      * @return the encoding
114      */

115     public String JavaDoc getEncoding() {
116
117         return m_context.getEncoding();
118     }
119
120     /**
121      * Returns the ip.<p>
122      *
123      * @return the ip
124      */

125     public String JavaDoc getIp() {
126
127         return m_context.getRemoteAddress();
128     }
129
130     /**
131      * Returns the locale.<p>
132      *
133      * @return the locale
134      */

135     public String JavaDoc getLocale() {
136
137         return m_context.getLocale().toString();
138     }
139
140     /**
141      * Returns the params.<p>
142      *
143      * @return the params
144      */

145     public Map JavaDoc getParams() {
146
147         // get the params
148
Map JavaDoc params = m_request.getParameterMap();
149         if (params.size() == 0) {
150             return null;
151         }
152         return params;
153     }
154
155     /**
156      * Returns the port.<p>
157      *
158      * @return the port
159      */

160     public Integer JavaDoc getPort() {
161
162         return new Integer JavaDoc(m_request.getServerPort());
163     }
164
165     /**
166      * Returns the resource.<p>
167      *
168      * @return the resource
169      */

170     public String JavaDoc getResource() {
171
172         return m_resource;
173     }
174
175     /**
176      * Returns the schemes.<p>
177      *
178      * @return the schemes
179      */

180     public String JavaDoc getScheme() {
181
182         return m_request.getScheme().toLowerCase();
183     }
184
185     /**
186      * Returns the the current users session, or <code>null</code> if the current user
187      * has no session.<p>
188      *
189      * @return the current users session, or <code>null</code> if the current user has no session
190      */

191     public HttpSession JavaDoc getSession() {
192
193         return m_request.getSession(false);
194     }
195
196     /**
197      * Returns the site root.<p>
198      *
199      * @return the site root
200      */

201     public String JavaDoc getSite() {
202
203         return m_context.getSiteRoot();
204     }
205
206     /**
207      * Returns the uri.<p>
208      *
209      * @return the uri
210      */

211     public String JavaDoc getUri() {
212
213         return m_context.addSiteRoot(m_context.getUri());
214     }
215
216     /**
217      * Returns the user.<p>
218      *
219      * @return the user
220      */

221     public String JavaDoc getUser() {
222
223         return m_context.currentUser().getName();
224     }
225 }
Popular Tags