001: /**
002: *
003: */package clime.messadmin.providers.displayformat;
004:
005: import java.io.IOException;
006: import java.util.Collection;
007: import java.util.Set;
008:
009: import javax.servlet.ServletConfig;
010: import javax.servlet.ServletContext;
011: import javax.servlet.ServletException;
012: import javax.servlet.http.HttpServletRequest;
013: import javax.servlet.http.HttpServletResponse;
014:
015: import clime.messadmin.model.IApplicationInfo;
016: import clime.messadmin.model.IServerInfo;
017: import clime.messadmin.model.ISessionInfo;
018: import clime.messadmin.providers.spi.DisplayFormatProvider;
019:
020: /**
021: * IMPLEMENTATION NOTE: always use include() instead of forward(), to get the real name of this servlet in jsp's
022: * @author Cédrik LIME
023: * @since 4.1
024: */
025: public class HTMLFormatProvider implements DisplayFormatProvider {
026: private transient ServletConfig config;
027:
028: protected String webFilesRoot = "/MessAdmin/";//$NON-NLS-1$
029: protected String serverInfosJspPath = webFilesRoot
030: + "serverInfos.jsp";//$NON-NLS-1$
031: protected String webAppsListJspPath = webFilesRoot
032: + "webAppsList.jsp";//$NON-NLS-1$
033: protected String webAppStatsJspPath = webFilesRoot
034: + "webAppStats.jsp";//$NON-NLS-1$
035: protected String sessionsListJspPath = webFilesRoot
036: + "sessionsList.jsp";//$NON-NLS-1$
037: protected String sessionDetailJspPath = webFilesRoot
038: + "sessionDetail.jsp";//$NON-NLS-1$
039:
040: /**
041: *
042: */
043: public HTMLFormatProvider() {
044: super ();
045: }
046:
047: /* (non-Javadoc)
048: * @see clime.messadmin.providers.spi.BaseProvider#getPriority()
049: */
050: public int getPriority() {
051: return 0;
052: }
053:
054: /* (non-Javadoc)
055: * @see clime.messadmin.providers.spi.DisplayFormatProvider#getFormatID()
056: */
057: public String getFormatID() {
058: return "html";//$NON-NLS-1$
059: }
060:
061: /* (non-Javadoc)
062: * @see clime.messadmin.providers.spi.DisplayFormatProvider#getContentType()
063: */
064: public String getContentType() {
065: return "text/html;charset=UTF-8";//should be "application/xhtml+xml", but IE screws us once again... //$NON-NLS-1$
066: }
067:
068: /* (non-Javadoc)
069: * @see clime.messadmin.providers.spi.DisplayFormatProvider#init(javax.servlet.ServletConfig)
070: */
071: public void init(ServletConfig config) throws ServletException {
072: this .config = config;
073: String initWebFilesRoot = getServletConfig().getInitParameter(
074: "WebFilesRoot");//$NON-NLS-1$
075: if (null != initWebFilesRoot) {
076: webFilesRoot = initWebFilesRoot;
077: }
078: if (!webFilesRoot.startsWith("/")) {//$NON-NLS-1$
079: webFilesRoot = '/' + webFilesRoot;
080: }
081: if (!webFilesRoot.endsWith("/")) {//$NON-NLS-1$
082: webFilesRoot += '/';
083: }
084: String initServerInfosJspPath = getServletConfig()
085: .getInitParameter("ServerInfosJsp");//$NON-NLS-1$
086: if (null != initServerInfosJspPath) {
087: serverInfosJspPath = webFilesRoot + initServerInfosJspPath;
088: }
089: String initWebAppsListJspPath = getServletConfig()
090: .getInitParameter("WebAppsListJsp");//$NON-NLS-1$
091: if (null != initWebAppsListJspPath) {
092: webAppsListJspPath = webFilesRoot + initWebAppsListJspPath;
093: }
094: String initWebAppStatsJspPathJspPath = getServletConfig()
095: .getInitParameter("WebAppStatsJsp");//$NON-NLS-1$
096: if (null != initWebAppStatsJspPathJspPath) {
097: webAppStatsJspPath = webFilesRoot
098: + initWebAppStatsJspPathJspPath;
099: }
100: String initSessionsListJspPath = getServletConfig()
101: .getInitParameter("SessionsListJsp");//$NON-NLS-1$
102: if (null != initSessionsListJspPath) {
103: sessionsListJspPath = webFilesRoot
104: + initSessionsListJspPath;
105: }
106: String initSessionDetailJspPath = getServletConfig()
107: .getInitParameter("SessionDetailJsp");//$NON-NLS-1$
108: if (null != initSessionDetailJspPath) {
109: sessionDetailJspPath = webFilesRoot
110: + initSessionDetailJspPath;
111: }
112: }
113:
114: /**
115: * Returns this servlet's {@link ServletConfig} object.
116: *
117: * @return ServletConfig the <code>ServletConfig</code> object
118: * that initialized this servlet
119: */
120: public ServletConfig getServletConfig() {
121: return config;
122: }
123:
124: /**
125: * Returns a reference to the {@link ServletContext} in which this servlet
126: * is running. See {@link ServletConfig#getServletContext}.
127: *
128: * <p>This method is supplied for convenience. It gets the
129: * context from the servlet's <code>ServletConfig</code> object.
130: *
131: * @return ServletContext the <code>ServletContext</code> object
132: * passed to this servlet by the <code>init</code>
133: * method
134: */
135: public ServletContext getServletContext() {
136: ServletConfig sc = getServletConfig();
137: if (sc == null) {
138: throw new IllegalStateException(
139: "err.servlet_config_not_initialized");
140: }
141: return sc.getServletContext();
142: }
143:
144: /* (non-Javadoc)
145: * @see clime.messadmin.providers.spi.DisplayFormatProvider#preProcess(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
146: */
147: public void preProcess(HttpServletRequest req,
148: HttpServletResponse resp) throws ServletException,
149: IOException {
150: // Some attributes needed by some or all JSPs
151: req
152: .setAttribute(
153: "autorefresh", req.getParameter("autorefresh"));//$NON-NLS-1$ //$NON-NLS-2$
154: req.setAttribute(
155: "WebFilesRoot", req.getContextPath() + webFilesRoot);//$NON-NLS-1$
156: }
157:
158: /* (non-Javadoc)
159: * @see clime.messadmin.providers.spi.DisplayFormatProvider#displayWebAppsList(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
160: */
161: public void displayWebAppsList(HttpServletRequest req,
162: HttpServletResponse resp,
163: Set/*<IApplicationInfo>*/applicationInfos)
164: throws ServletException, IOException {
165: req.setAttribute("applications", applicationInfos);//$NON-NLS-1$
166: getServletContext().getRequestDispatcher(webAppsListJspPath)
167: .include(req, resp);
168: }
169:
170: /* (non-Javadoc)
171: * @see clime.messadmin.providers.spi.DisplayFormatProvider#displaySessionsListPage(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String)
172: */
173: public void displaySessionsListPage(HttpServletRequest req,
174: HttpServletResponse resp, String sortBy, String orderBy,
175: IApplicationInfo webAppStats,
176: Collection/*<ISessionInfo>*/activeSessions,
177: Collection/*<String>*/passiveSessionsIds)
178: throws ServletException, IOException {
179: // keep sort order
180: req.setAttribute("sort", sortBy);//$NON-NLS-1$
181: req.setAttribute("order", orderBy);//$NON-NLS-1$
182: req.setAttribute("activeSessions", activeSessions);//$NON-NLS-1$
183: req.setAttribute("passiveSessionsIds", passiveSessionsIds);//$NON-NLS-1$
184: req.setAttribute("webAppStats", webAppStats);//$NON-NLS-1$
185: getServletContext().getRequestDispatcher(sessionsListJspPath)
186: .include(req, resp);
187: }
188:
189: /* (non-Javadoc)
190: * @see clime.messadmin.providers.spi.DisplayFormatProvider#displaySessionDetailPage(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String)
191: */
192: public void displaySessionDetailPage(HttpServletRequest req,
193: HttpServletResponse resp, IApplicationInfo webAppStats,
194: ISessionInfo currentSession) throws ServletException,
195: IOException {
196: req.setAttribute("webAppStats", webAppStats);//$NON-NLS-1$
197: req.setAttribute("currentSession", currentSession);//$NON-NLS-1$
198: getServletContext().getRequestDispatcher(sessionDetailJspPath)
199: .include(req, resp);
200: }
201:
202: /* (non-Javadoc)
203: * @see clime.messadmin.providers.spi.DisplayFormatProvider#displayWebAppStatsPage(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String)
204: */
205: public void displayWebAppStatsPage(HttpServletRequest req,
206: HttpServletResponse resp, IApplicationInfo webAppStats)
207: throws ServletException, IOException {
208: req.setAttribute("webAppStats", webAppStats);//$NON-NLS-1$
209: getServletContext().getRequestDispatcher(webAppStatsJspPath)
210: .include(req, resp);
211: }
212:
213: /* (non-Javadoc)
214: * @see clime.messadmin.providers.spi.DisplayFormatProvider#displayServerInfosPage(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
215: */
216: public void displayServerInfosPage(HttpServletRequest req,
217: HttpServletResponse resp, IServerInfo serverInfo)
218: throws ServletException, IOException {
219: req.setAttribute("serverInfos", serverInfo);//$NON-NLS-1$
220: getServletContext().getRequestDispatcher(serverInfosJspPath)
221: .include(req, resp);
222: }
223:
224: }
|