| PortalDelegateServlet.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 */
14
15 package com.liferay.portal.kernel.servlet;
16
17 import com.liferay.portal.kernel.log.Log;
18 import com.liferay.portal.kernel.log.LogFactoryUtil;
19
20 import javax.servlet.ServletConfig;
21 import javax.servlet.http.HttpServlet;
22
23 /**
24 * <a href="PortalDelegateServlet.java.html"><b><i>View Source</i></b></a>
25 *
26 * <p>
27 * See http://issues.liferay.com/browse/LEP-2297.
28 * </p>
29 *
30 * @author Olaf Fricke
31 * @author Brian Wing Shun Chan
32 */
33 public class PortalDelegateServlet extends HttpServlet {
34
35 public void init(ServletConfig servletConfig) {
36 String servletClass = servletConfig.getInitParameter("servlet-class");
37
38 _subContext = servletConfig.getInitParameter("sub-context");
39
40 if (_subContext == null) {
41 _subContext = getServletName();
42 }
43
44 try {
45 Thread currentThread = Thread.currentThread();
46
47 ClassLoader contextClassLoader =
48 currentThread.getContextClassLoader();
49
50 HttpServlet servlet = (HttpServlet)contextClassLoader.loadClass(
51 servletClass).newInstance();
52
53 servlet.init(servletConfig);
54
55 PortalDelegatorServlet.addDelegate(_subContext, servlet);
56 }
57 catch (Exception e) {
58 _log.error(e, e);
59 }
60 }
61
62 public void destroy() {
63 PortalDelegatorServlet.removeDelegate(_subContext);
64 }
65
66 private static Log _log = LogFactoryUtil.getLog(
67 PortalDelegateServlet.class);
68
69 private String _subContext;
70
71 }