01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/velocity/tags/sakai_2-4-1/tool/src/java/org/sakaiproject/vm/ComponentServlet.java $
03: * $Id: ComponentServlet.java 7247 2006-03-29 21:09:51Z ggolden@umich.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.vm;
21:
22: import java.io.IOException;
23: import java.io.PrintWriter;
24:
25: import javax.servlet.ServletException;
26: import javax.servlet.http.HttpServlet;
27: import javax.servlet.http.HttpServletRequest;
28: import javax.servlet.http.HttpServletResponse;
29:
30: import org.sakaiproject.util.ParameterParser;
31:
32: /**
33: * <p>
34: * ComponentServlet does some setup and provides some support for (mostly legacy) Sakai servlets and tools.
35: * <p>
36: */
37: public abstract class ComponentServlet extends HttpServlet {
38: /** This request's parsed parameters */
39: protected final static String ATTR_PARAMS = "sakai.wrapper.params";
40:
41: /**
42: * Override service, adding the setup for legacy.
43: */
44: protected void service(HttpServletRequest req,
45: HttpServletResponse resp) throws ServletException,
46: java.io.IOException {
47: // parse the parameters of the request, considering Unicode issues, into a ParameterParser
48: ParameterParser parser = new ParameterParser(req);
49:
50: // make this available from the req as an attribute
51: req.setAttribute(ATTR_PARAMS, parser);
52:
53: // Setup.setup(req, resp);
54: super .service(req, resp);
55: }
56:
57: /**
58: * Send a redirect so our parent ends up at the url, via javascript.
59: *
60: * @param url
61: * The redirect url
62: */
63: protected void sendParentRedirect(HttpServletResponse resp,
64: String url) {
65: try {
66: resp.setContentType("text/html; charset=UTF-8");
67: PrintWriter out = resp.getWriter();
68: out
69: .println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
70: out.println("<html><head></head><body>");
71: out
72: .println("<script type=\"text/javascript\" language=\"JavaScript\">");
73: out.println("if (parent)\n"
74: + "{\n\tparent.location.replace('" + url
75: + "');\n}\n");
76: out.println("</script>");
77: out.println("</body></html>");
78: resp.flushBuffer();
79: } catch (IOException e) {
80: }
81: }
82:
83: // set standard no-cache headers
84: protected void setNoCacheHeaders(HttpServletResponse resp) {
85: resp.setContentType("text/html; charset=UTF-8");
86: // some old date
87: resp.addHeader("Expires", "Mon, 01 Jan 2001 00:00:00 GMT");
88: // TODO: do we need this? adding a date header is expensive contention for the date formatter, ours or Tomcats.
89: // resp.addDateHeader("Last-Modified", System.currentTimeMillis());
90: resp
91: .addHeader("Cache-Control",
92: "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
93: resp.addHeader("Pragma", "no-cache");
94: }
95: }
|