1 | /* |
2 | * Copyright 2003,2004 The Apache Software Foundation. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | package org.apache.pluto.driver; |
17 | |
18 | import org.apache.pluto.driver.services.portal.admin.DriverAdministrationException; |
19 | import org.apache.pluto.driver.services.portal.admin.PortletRegistryAdminService; |
20 | import org.apache.pluto.driver.config.AdminConfiguration; |
21 | |
22 | import javax.servlet.http.HttpServlet; |
23 | import javax.servlet.http.HttpServletRequest; |
24 | import javax.servlet.http.HttpServletResponse; |
25 | import javax.servlet.ServletException; |
26 | import java.io.IOException; |
27 | |
28 | |
29 | /** |
30 | * Publishing administrative servlet. |
31 | * Allows external clients to connect and notify the portal |
32 | * of available portlet applications. |
33 | * |
34 | * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>: |
35 | * @version 1.0 |
36 | * @since Nov 23, 2005 |
37 | */ |
38 | public class PublishServlet extends HttpServlet { |
39 | |
40 | protected void doGet(HttpServletRequest req, |
41 | HttpServletResponse res) |
42 | throws ServletException, IOException { |
43 | |
44 | String context = req.getParameter("context"); |
45 | try { |
46 | doPublish(context); |
47 | } |
48 | catch(Throwable t) { |
49 | StringBuffer sb = new StringBuffer(); |
50 | sb.append("Unable to publish portlet application bound to context '"+context+"'."); |
51 | sb.append("Reason: ").append(t.getMessage()); |
52 | res.getWriter().println(sb.toString()); |
53 | } |
54 | } |
55 | |
56 | private void doPublish(String context) throws DriverAdministrationException { |
57 | AdminConfiguration adminConfig = (AdminConfiguration)getServletContext() |
58 | .getAttribute(AttributeKeys.DRIVER_ADMIN_CONFIG); |
59 | |
60 | PortletRegistryAdminService admin = adminConfig.getPortletRegistryAdminService(); |
61 | |
62 | admin.addPortletApplication(context); |
63 | } |
64 | } |