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;
|
9
|
|
|
10
|
|
import com.tirsen.angkor.process.Pipeline;
|
11
|
|
|
12
|
|
import javax.servlet.ServletConfig;
|
13
|
|
import javax.servlet.ServletException;
|
14
|
|
import javax.servlet.http.HttpServlet;
|
15
|
|
import javax.servlet.http.HttpServletRequest;
|
16
|
|
import javax.servlet.http.HttpServletResponse;
|
17
|
|
import java.io.IOException;
|
18
|
|
|
19
|
|
/**
|
20
|
|
* Fetches a named component based either on configuration in a init parameter or on the last
|
21
|
|
* part of the request uri, the named component is fetched from the application instantiated by the
|
22
|
|
* ApplicationFilter which must be mapped to all requests to this servlet.
|
23
|
|
*
|
24
|
|
* <!-- $Id: ComponentServlet.java,v 1.6 2002/10/13 13:37:26 tirsen Exp $ -->
|
25
|
|
*
|
26
|
|
* @author $Author: tirsen $
|
27
|
|
* @version $Revision: 1.6 $
|
28
|
|
*/
|
29
|
|
public class ComponentServlet extends HttpServlet
|
30
|
|
{
|
31
|
|
private String componentName;
|
32
|
|
|
33
|
0
|
public void init(ServletConfig config) throws ServletException
|
34
|
|
{
|
35
|
0
|
super.init(config);
|
36
|
0
|
componentName = config.getInitParameter("componentName");
|
37
|
|
}
|
38
|
|
|
39
|
1
|
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
40
|
|
{
|
41
|
1
|
if (componentName == null)
|
42
|
|
{
|
43
|
1
|
String requestURI = request.getRequestURI();
|
44
|
1
|
componentName = requestURI.substring(requestURI.lastIndexOf("/") + 1);
|
45
|
|
}
|
46
|
|
|
47
|
1
|
RenderContext ctx = new RenderContext(request, response);
|
48
|
|
|
49
|
1
|
Application application = ctx.getApplication();
|
50
|
|
|
51
|
1
|
ViewFactory factory = application.getComponent(componentName);
|
52
|
1
|
Pipeline pipeline = application.createRenderPipeline(factory);
|
53
|
1
|
try
|
54
|
|
{
|
55
|
1
|
pipeline.execute(ctx);
|
56
|
|
}
|
57
|
|
catch (Exception e)
|
58
|
|
{
|
59
|
0
|
throw new ServletException(e);
|
60
|
|
}
|
61
|
0
|
if (application.getError() != null) throw new ServletException(application.getError());
|
62
|
|
}
|
63
|
|
}
|
64
|
|
|