01: /*
02: * RedirectTemplate.java
03: *
04: * Brazil project web application Framework,
05: * export version: 1.1
06: * Copyright (c) 1998-2000 Sun Microsystems, Inc.
07: *
08: * Sun Public License Notice
09: *
10: * The contents of this file are subject to the Sun Public License Version
11: * 1.0 (the "License"). You may not use this file except in compliance with
12: * the License. A copy of the License is included as the file "license.terms",
13: * and also available at http://www.sun.com/
14: *
15: * The Original Code is from:
16: * Brazil project web application Framework release 1.1.
17: * The Initial Developer of the Original Code is: suhler.
18: * Portions created by suhler are Copyright (C) Sun Microsystems, Inc.
19: * All Rights Reserved.
20: *
21: * Contributor(s): cstevens, suhler.
22: *
23: * Version: 1.8
24: * Created by suhler on 98/09/14
25: * Last modified by suhler on 00/05/31 13:48:34
26: */
27:
28: package sunlabs.brazil.template;
29:
30: /**
31: * Template class for redirecting an html page
32: * This class is used by the TemplateHandler
33: * @author Stephen Uhler
34: * @version 1.0, 09/04/98
35: */
36:
37: public class RedirectTemplate extends Template {
38: String redirect;
39:
40: /**
41: * Look for a redirect tag, change it to an HREF, and remember where
42: * to redirect to (e.g. <code><redirect http://some.where.com>)
43: * </code>
44: */
45:
46: public void redirect(RewriteContext hr) {
47: redirect = hr.getArgs();
48:
49: hr.append("<A HREF=" + redirect + ">" + redirect + "</A>");
50: }
51:
52: /**
53: * adjust the response headers to reflect redirection, if supplied.
54: * Otherwise, ignore this request.
55: */
56:
57: public boolean done(RewriteContext hr) {
58: if (redirect != null) {
59: hr.request.addHeader("location", redirect);
60: hr.request.setStatus(302);
61: return true;
62: } else {
63: return false;
64: }
65: }
66: }
|