001: /*
002: * Copyright (c) 1998-2003 Caucho Technology -- all rights reserved
003: *
004: * Caucho Technology permits redistribution, modification and use
005: * of this file in source and binary form ("the Software") under the
006: * Caucho Developer Source License ("the License"). The following
007: * conditions must be met:
008: *
009: * 1. Each copy or derived work of the Software must preserve the copyright
010: * notice and this notice unmodified.
011: *
012: * 2. Redistributions of the Software in source or binary form must include
013: * an unmodified copy of the License, normally in a plain ASCII text
014: *
015: * 3. The names "Resin" or "Caucho" are trademarks of Caucho Technology and
016: * may not be used to endorse products derived from this software.
017: * "Resin" or "Caucho" may not appear in the names of products derived
018: * from this software.
019: *
020: * This Software is provided "AS IS," without a warranty of any kind.
021: * ALL EXPRESS OR IMPLIED REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
022: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
023: * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
024: *
025: * CAUCHO TECHNOLOGY AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
026: * SUFFERED BY LICENSEE OR ANY THIRD PARTY AS A RESULT OF USING OR
027: * DISTRIBUTING SOFTWARE. IN NO EVENT WILL CAUCHO OR ITS LICENSORS BE LIABLE
028: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
029: * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
030: * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
031: * INABILITY TO USE SOFTWARE, EVEN IF HE HAS BEEN ADVISED OF THE POSSIBILITY
032: * OF SUCH DAMAGES.
033: *
034: * @author Sam
035: */
036:
037: package com.caucho.doc.javadoc;
038:
039: import com.caucho.log.Log;
040: import com.caucho.util.L10N;
041:
042: import java.util.logging.Logger;
043:
044: import javax.servlet.http.HttpServletResponse;
045: import javax.servlet.jsp.JspException;
046: import javax.servlet.http.HttpServletRequest;
047:
048: /**
049: * Utilities common to all jsp pages.
050: */
051: public class JspUtil {
052: static protected final Logger log = Log.open(JspUtil.class);
053: static final L10N L = new L10N(JspUtil.class);
054:
055: private HttpServletRequest _request;
056: private HttpServletResponse _response;
057:
058: private Store _store;
059:
060: public JspUtil() {
061: }
062:
063: public void setRequest(HttpServletRequest request) {
064: _request = request;
065: }
066:
067: public void setResponse(HttpServletResponse response) {
068: _response = response;
069: }
070:
071: /**
072: * Get the Store object.
073: */
074: public Store getStore() throws JspException {
075: if (_store == null) {
076: try {
077: _store = Store.getInstance();
078: } catch (Exception ex) {
079: throw new JspException(ex);
080: }
081: }
082:
083: return _store;
084: }
085:
086: /**
087: * Send appropriate HTTP cache headers based on the value of
088: * http-cache-period for the Store.
089: */
090: public void sendHttpCacheHeaders() throws JspException {
091: Store store = getStore();
092:
093: long period = getStore().getHttpCachePeriod();
094:
095: if (period < 0) {
096: // disable caching
097: _response.setHeader("Cache-Control",
098: "no-cache,post-check=0,pre-check=0,no-store");
099: _response.setHeader("Pragma", "no-cache");
100: _response.setHeader("Expires", "Thu,01Dec199416:00:00GMT");
101: } else {
102: long now = System.currentTimeMillis();
103: _response.setDateHeader("Expires", now + period);
104: }
105: }
106:
107: }
|