1
19
20 package com.liferay.portal.servlet;
21
22 import com.liferay.portal.NoSuchLayoutException;
23 import com.liferay.portal.kernel.log.Log;
24 import com.liferay.portal.kernel.log.LogFactoryUtil;
25 import com.liferay.portal.kernel.util.GetterUtil;
26 import com.liferay.portal.kernel.util.ParamUtil;
27 import com.liferay.portal.kernel.util.Validator;
28 import com.liferay.portal.util.Portal;
29 import com.liferay.portal.util.PortalUtil;
30 import com.liferay.portal.util.WebKeys;
31
32 import java.io.IOException;
33
34 import javax.servlet.RequestDispatcher;
35 import javax.servlet.ServletContext;
36 import javax.servlet.ServletException;
37 import javax.servlet.http.HttpServlet;
38 import javax.servlet.http.HttpServletRequest;
39 import javax.servlet.http.HttpServletResponse;
40
41
47 public class WidgetServlet extends HttpServlet {
48
49 public void service(
50 HttpServletRequest request, HttpServletResponse response)
51 throws IOException, ServletException {
52
53 try {
54 String redirect = getRedirect(request);
55
56 if (redirect == null) {
57 PortalUtil.sendError(
58 HttpServletResponse.SC_NOT_FOUND,
59 new NoSuchLayoutException(), request, response);
60 }
61 else {
62 request.setAttribute(WebKeys.WIDGET, Boolean.TRUE);
63
64 ServletContext servletContext = getServletContext();
65
66 RequestDispatcher requestDispatcher =
67 servletContext.getRequestDispatcher(redirect);
68
69 requestDispatcher.forward(request, response);
70 }
71 }
72 catch (Exception e) {
73 _log.error(e, e);
74
75 PortalUtil.sendError(
76 HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e, request,
77 response);
78 }
79 }
80
81 protected String getRedirect(HttpServletRequest request) {
82 String path = GetterUtil.getString(request.getPathInfo());
83
84 if (Validator.isNull(path)) {
85 return null;
86 }
87
88 String ppid = ParamUtil.getString(request, "p_p_id");
89
90 int pos = path.indexOf(Portal.FRIENDLY_URL_SEPARATOR);
91
92 if (Validator.isNull(ppid) && (pos == -1)) {
93 return null;
94 }
95
96 return path;
97 }
98
99 private static Log _log = LogFactoryUtil.getLog(WidgetServlet.class);
100
101 }