KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > doc > javadoc > JspUtil


1 /*
2  * Copyright (c) 1998-2003 Caucho Technology -- all rights reserved
3  *
4  * Caucho Technology permits redistribution, modification and use
5  * of this file in source and binary form ("the Software") under the
6  * Caucho Developer Source License ("the License"). The following
7  * conditions must be met:
8  *
9  * 1. Each copy or derived work of the Software must preserve the copyright
10  * notice and this notice unmodified.
11  *
12  * 2. Redistributions of the Software in source or binary form must include
13  * an unmodified copy of the License, normally in a plain ASCII text
14  *
15  * 3. The names "Resin" or "Caucho" are trademarks of Caucho Technology and
16  * may not be used to endorse products derived from this software.
17  * "Resin" or "Caucho" may not appear in the names of products derived
18  * from this software.
19  *
20  * This Software is provided "AS IS," without a warranty of any kind.
21  * ALL EXPRESS OR IMPLIED REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
22  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
23  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
24  *
25  * CAUCHO TECHNOLOGY AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
26  * SUFFERED BY LICENSEE OR ANY THIRD PARTY AS A RESULT OF USING OR
27  * DISTRIBUTING SOFTWARE. IN NO EVENT WILL CAUCHO OR ITS LICENSORS BE LIABLE
28  * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
29  * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
30  * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
31  * INABILITY TO USE SOFTWARE, EVEN IF HE HAS BEEN ADVISED OF THE POSSIBILITY
32  * OF SUCH DAMAGES.
33  *
34  * @author Sam
35  */

36
37 package com.caucho.doc.javadoc;
38
39 import com.caucho.log.Log;
40 import com.caucho.util.L10N;
41
42 import java.util.logging.Logger JavaDoc;
43
44 import javax.servlet.http.HttpServletResponse JavaDoc;
45 import javax.servlet.jsp.JspException JavaDoc;
46 import javax.servlet.http.HttpServletRequest JavaDoc;
47
48 /**
49  * Utilities common to all jsp pages.
50  */

51 public class JspUtil {
52   static protected final Logger JavaDoc log = Log.open(JspUtil.class);
53   static final L10N L = new L10N(JspUtil.class);
54
55   private HttpServletRequest JavaDoc _request;
56   private HttpServletResponse JavaDoc _response;
57
58   private Store _store;
59
60   public JspUtil()
61   {
62   }
63
64   public void setRequest(HttpServletRequest JavaDoc request)
65   {
66     _request = request;
67   }
68
69   public void setResponse(HttpServletResponse JavaDoc response)
70   {
71     _response = response;
72   }
73
74   /**
75    * Get the Store object.
76    */

77   public Store getStore()
78     throws JspException JavaDoc
79   {
80     if (_store == null) {
81       try {
82         _store = Store.getInstance();
83       } catch (Exception JavaDoc ex) {
84         throw new JspException JavaDoc(ex);
85       }
86     }
87
88     return _store;
89   }
90
91   /**
92    * Send appropriate HTTP cache headers based on the value of
93    * http-cache-period for the Store.
94    */

95   public void sendHttpCacheHeaders()
96     throws JspException JavaDoc
97   {
98     Store store = getStore();
99
100     long period = getStore().getHttpCachePeriod();
101
102     if (period < 0) {
103       // disable caching
104
_response.setHeader("Cache-Control","no-cache,post-check=0,pre-check=0,no-store");
105       _response.setHeader("Pragma","no-cache");
106       _response.setHeader("Expires","Thu,01Dec199416:00:00GMT");
107     } else {
108       long now = System.currentTimeMillis();
109       _response.setDateHeader("Expires", now + period);
110     }
111   }
112
113 }
114
115
Popular Tags