1 /*
2 * Angkor Web Framework
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */
7
8 package com.tirsen.angkor.process;
9
10 import com.tirsen.angkor.Debug;
11 import com.tirsen.angkor.RenderContext;
12 import org.apache.log4j.Category;
13
14 /***
15 * <!-- $Id: RedirectValve.java,v 1.3 2002/10/09 21:37:37 tirsen Exp $ -->
16 * <!-- $Author: tirsen $ -->
17 *
18 * @author Jon Tirs´n (tirsen@users.sourceforge.net)
19 * @version $Revision: 1.3 $
20 */
21 public class RedirectValve implements Valve
22 {
23 private static final Category logger = Debug.getCategory();
24
25 public static final ExecuteContext.Attribute RedirectToAttribute = new ExecuteContext.Attribute("RedirectTo");
26
27 public static void redirectTo(String url)
28 {
29 logger.info("redirecting to " + url);
30 Pipeline.getCurrentExecuteContext().setAttribute(RedirectToAttribute, url);
31 }
32
33 public void execute(ExecuteContext exec) throws Exception
34 {
35 String redirectTo = (String) exec.getAttribute(RedirectToAttribute);
36 System.out.println("exec = " + exec);
37 System.out.println("redirectTo = " + redirectTo);
38 if (redirectTo == null)
39 {
40 exec.executeNext();
41 }
42 else
43 {
44 RenderContext context = (RenderContext) exec.getAttribute(ExecuteContext.RenderContextAttribute);
45 logger.info("sending redirect " + redirectTo);
46 context.getResponse().sendRedirect(redirectTo);
47 }
48 }
49 }
This page was automatically generated by Maven