1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.portlets.rpad.portlet;
18
19 import java.io.IOException;
20
21 import javax.portlet.ActionRequest;
22 import javax.portlet.ActionResponse;
23 import javax.portlet.PortletConfig;
24 import javax.portlet.PortletContext;
25 import javax.portlet.PortletException;
26 import javax.portlet.RenderRequest;
27 import javax.portlet.RenderResponse;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.jetspeed.portlets.rpad.RPADException;
32 import org.apache.jetspeed.portlets.rpad.RepositoryManager;
33 import org.apache.portals.bridges.portletfilter.PortletFilter;
34 import org.apache.portals.bridges.portletfilter.PortletFilterChain;
35 import org.apache.portals.bridges.portletfilter.PortletFilterConfig;
36
37 public class RPADPortletFilter implements PortletFilter
38 {
39 /***
40 * Logger for this class
41 */
42 private static final Log log = LogFactory.getLog(RPADPortletFilter.class);
43
44 protected final static String CONFIG_FILE = "config-file";
45
46 protected final static String DEFAULT_CONFIG_FILE = "/WEB-INF/rpad-config.xml";
47
48 protected final static String WEBAPP_ROOT_PREFIX = "${webapp}";
49
50 public void destroy()
51 {
52 try
53 {
54 RepositoryManager.getInstance().store();
55 }
56 catch (RPADException e)
57 {
58 log.error("Could not store the configuration.", e);
59 }
60 }
61
62 public void init(PortletFilterConfig filterConfig) throws PortletException
63 {
64 PortletConfig portletConfig = filterConfig.getPortletConfig();
65 PortletContext portletContext = portletConfig.getPortletContext();
66 String configFile = portletConfig.getInitParameter(CONFIG_FILE);
67 if (configFile == null)
68 {
69 configFile = portletContext.getRealPath(DEFAULT_CONFIG_FILE);
70 }
71 else if (configFile.startsWith(WEBAPP_ROOT_PREFIX))
72 {
73 configFile = portletContext.getRealPath(configFile
74 .substring(WEBAPP_ROOT_PREFIX.length()));
75 }
76
77 if (log.isDebugEnabled())
78 {
79 log.debug("init(PortletConfig) - configFile=" + configFile);
80 }
81
82
83 try
84 {
85 RepositoryManager.init(configFile);
86 }
87 catch (Exception e)
88 {
89 throw new PortletException(
90 "Could not create RepositoryManager. The config file is "
91 + configFile, e);
92 }
93 }
94
95 public void processActionFilter(ActionRequest request,
96 ActionResponse response, PortletFilterChain chain)
97 throws PortletException, IOException
98 {
99 chain.processActionFilter(request, response);
100 }
101
102 public void renderFilter(RenderRequest request, RenderResponse response,
103 PortletFilterChain chain) throws PortletException, IOException
104 {
105 chain.renderFilter(request, response);
106 }
107
108 }