1 package com.eyeq.pivot4j.pentaho.servlet;
2
3 import javax.servlet.ServletRequestAttributeEvent;
4 import javax.servlet.ServletRequestEvent;
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletRequestWrapper;
7 import javax.servlet.http.HttpSession;
8
9 import org.apache.commons.lang.ObjectUtils;
10 import org.apache.myfaces.webapp.StartupServletContextListener;
11
12 public class PluginServletRequest extends HttpServletRequestWrapper {
13
14 public static final String PLUGIN_PREFIX = "/plugin";
15
16 public static final String SERVLET_PATH = "/pivot4j/faces";
17
18 private PluginServletContext servletContext;
19
20
21
22
23
24 public PluginServletRequest(PluginServletContext servletContext,
25 HttpServletRequest request) {
26 super(request);
27
28 this.servletContext = servletContext;
29 }
30
31
32
33
34 protected PluginServletContext getServletContext() {
35 return servletContext;
36 }
37
38 public void initialize() {
39 StartupServletContextListener listener = servletContext.getListener();
40 listener.requestInitialized(new ServletRequestEvent(servletContext,
41 this));
42 }
43
44 public void destroy() {
45 StartupServletContextListener listener = servletContext.getListener();
46 listener.requestDestroyed(new ServletRequestEvent(servletContext, this));
47 }
48
49
50
51
52 @Override
53 public String getServletPath() {
54 return PLUGIN_PREFIX + SERVLET_PATH;
55 }
56
57
58
59
60 @Override
61 public String getPathInfo() {
62 String pathInfo = super.getPathInfo();
63
64 if (pathInfo.startsWith(SERVLET_PATH)) {
65 pathInfo = pathInfo.substring(SERVLET_PATH.length());
66 }
67
68 return pathInfo;
69 }
70
71
72
73
74
75 @Override
76 public void setAttribute(String name, Object value) {
77 Object oldValue = getAttribute(name);
78
79 super.setAttribute(name, value);
80
81 StartupServletContextListener listener = servletContext.getListener();
82
83 if (oldValue == null) {
84 listener.attributeAdded(new ServletRequestAttributeEvent(
85 servletContext, this, name, value));
86 } else if (!ObjectUtils.equals(oldValue, value)) {
87 listener.attributeReplaced(new ServletRequestAttributeEvent(
88 servletContext, this, name, value));
89 }
90 }
91
92
93
94
95 @Override
96 public void removeAttribute(String name) {
97 Object value = getAttribute(name);
98
99 super.removeAttribute(name);
100
101 StartupServletContextListener listener = servletContext.getListener();
102 listener.attributeRemoved(new ServletRequestAttributeEvent(
103 servletContext, this, name, value));
104 }
105
106
107
108
109 @Override
110 public HttpSession getSession() {
111 HttpSession session = super.getSession();
112
113 if (!(session instanceof PluginServletSession)) {
114 session = new PluginServletSession(servletContext, session);
115 }
116
117 return session;
118 }
119
120
121
122
123 @Override
124 public HttpSession getSession(boolean create) {
125 HttpSession session = super.getSession(create);
126
127 if (!(session instanceof PluginServletSession)) {
128 session = new PluginServletSession(servletContext, session);
129 }
130
131 return session;
132 }
133 }