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.jsp;
|
9
|
|
|
10
|
|
import com.tirsen.angkor.Application;
|
11
|
|
import com.tirsen.angkor.Debug;
|
12
|
|
import com.tirsen.angkor.RenderContext;
|
13
|
|
import com.tirsen.angkor.process.ExecuteContext;
|
14
|
|
import com.tirsen.angkor.process.Pipeline;
|
15
|
|
import org.apache.log4j.Category;
|
16
|
|
|
17
|
|
import javax.servlet.Filter;
|
18
|
|
import javax.servlet.FilterChain;
|
19
|
|
import javax.servlet.FilterConfig;
|
20
|
|
import javax.servlet.ServletException;
|
21
|
|
import javax.servlet.ServletRequest;
|
22
|
|
import javax.servlet.ServletResponse;
|
23
|
|
import javax.servlet.http.HttpServletRequest;
|
24
|
|
import javax.servlet.http.HttpServletResponse;
|
25
|
|
import java.io.IOException;
|
26
|
|
|
27
|
|
/**
|
28
|
|
* A servlet filter acting as the main entry point to the Angkor engine, passes the request
|
29
|
|
* to RenderContext where the actual engine is implemented.
|
30
|
|
*
|
31
|
|
* <!-- $Id: PrerenderFilter.java,v 1.3 2002/10/09 21:37:37 tirsen Exp $ -->
|
32
|
|
*
|
33
|
|
* @author $Author: tirsen $
|
34
|
|
* @version $Revision: 1.3 $
|
35
|
|
*/
|
36
|
|
public class PrerenderFilter implements Filter
|
37
|
|
{
|
38
|
|
private static final Category logger = Category.getInstance(Debug.LOGGER_NAME);
|
39
|
|
|
40
|
|
public static final String REGISTRY_NAME = "_angkor_prerendered_registry";
|
41
|
|
|
42
|
|
private FilterConfig filterConfig;
|
43
|
|
|
44
|
0
|
public FilterConfig getFilterConfig()
|
45
|
|
{
|
46
|
0
|
return filterConfig;
|
47
|
|
}
|
48
|
|
|
49
|
0
|
public void setFilterConfig(FilterConfig filterConfig)
|
50
|
|
{
|
51
|
0
|
this.filterConfig = filterConfig;
|
52
|
|
}
|
53
|
|
|
54
|
0
|
public void init(FilterConfig config) throws ServletException
|
55
|
|
{
|
56
|
|
}
|
57
|
|
|
58
|
0
|
public void doFilter(ServletRequest sRequest, ServletResponse sResponse, FilterChain chain)
|
59
|
|
throws IOException, ServletException
|
60
|
|
{
|
61
|
0
|
HttpServletRequest request = (HttpServletRequest) sRequest;
|
62
|
0
|
HttpServletResponse response = (HttpServletResponse) sResponse;
|
63
|
|
|
64
|
0
|
RenderContext context = new RenderContext(request, response);
|
65
|
|
|
66
|
0
|
Application application = context.getApplication();
|
67
|
0
|
Pipeline pipeline = application.createPrerenderPipeline();
|
68
|
0
|
ExecuteContext exec;
|
69
|
0
|
try
|
70
|
|
{
|
71
|
0
|
exec = pipeline.createExecuteContext(context);
|
72
|
0
|
pipeline.execute(exec);
|
73
|
|
}
|
74
|
|
catch (Exception e)
|
75
|
|
{
|
76
|
0
|
throw new ServletException(e);
|
77
|
|
}
|
78
|
0
|
PrerenderedComponentsRegistry registry = (PrerenderedComponentsRegistry)
|
79
|
|
exec.getAttribute(PrerenderValve.PrerenderedComponentsRegistryAttribute);
|
80
|
0
|
sRequest.setAttribute(REGISTRY_NAME, registry);
|
81
|
|
|
82
|
|
// the processing could end up redirecting the request or sending an error or anything else
|
83
|
|
// make sure not to write on a commited response
|
84
|
0
|
if (!response.isCommitted()) chain.doFilter(sRequest, sResponse);
|
85
|
|
}
|
86
|
|
|
87
|
0
|
public void destroy()
|
88
|
|
{
|
89
|
|
}
|
90
|
|
}
|
91
|
|
|