1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.util.filter;
17
18 import java.io.IOException;
19
20 import javax.servlet.Filter;
21 import javax.servlet.FilterChain;
22 import javax.servlet.FilterConfig;
23 import javax.servlet.ServletException;
24 import javax.servlet.ServletRequest;
25 import javax.servlet.ServletResponse;
26 import javax.servlet.http.HttpServletRequest;
27
28 import org.apache.struts.action.ActionServlet;
29 import org.apache.struts.util.ModuleUtils;
30 import org.seasar.framework.container.S2Container;
31 import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
32 import org.seasar.tuigwaa.system.Constants;
33 import org.seasar.tuigwaa.system.SiteConfig;
34 import org.seasar.tuigwaa.system.SiteService;
35 import org.seasar.tuigwaa.util.TgwContext;
36 import org.seasar.tuigwaa.util.TgwUtils;
37
38 public class TgwFilter implements Filter {
39
40 public void init(FilterConfig arg0) throws ServletException {
41 }
42
43 public void doFilter(ServletRequest request, ServletResponse response,
44 FilterChain chain) throws IOException, ServletException {
45 S2Container container = SingletonS2ContainerFactory.getContainer();
46
47
48 ActionServlet servlet = (ActionServlet) TgwUtils
49 .getTuigwaaActionServlet();
50
51 String siteName = null;
52 String prefix = ModuleUtils.getInstance().getModuleName(
53 (HttpServletRequest) request, servlet.getServletContext());
54 if (prefix != null && prefix.length() > 0)
55 siteName = prefix.substring(1);
56
57 SiteService siteService = (SiteService) container
58 .getComponent(SiteService.class);
59 SiteConfig config = siteService.getSiteConfig(siteName);
60 request.setAttribute(Constants.RATTR_SITECONFIG, config);
61
62
63
64 String pageName = TgwContext.getPageName();
65 if (pageName == null || pageName.equals("")) {
66 pageName = request.getParameter(Constants.PARAM_PAGENAME);
67 if (pageName != null && !pageName.equals("")) {
68 TgwContext.bindPageName(pageName);
69 }
70 }
71
72
73 String entityName = request.getParameter(Constants.PARAM_ENTITY_NAME);
74 TgwContext.bindEntityName(entityName);
75
76
77 TgwContext.bindPageSettings();
78
79
80 TgwContext.bindContextPath();
81
82 chain.doFilter(request, response);
83 }
84
85 public void destroy() {
86 }
87 }