KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portlet > admin > controller > DeployWarPortlet


1 /*
2  * Copyright 2003,2004,2005 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.portlet.admin.controller;
17
18 import java.io.IOException JavaDoc;
19
20 import javax.portlet.ActionRequest;
21 import javax.portlet.ActionResponse;
22 import javax.portlet.PortletException;
23 import javax.portlet.PortletMode;
24 import javax.portlet.PortletSession;
25 import javax.portlet.RenderRequest;
26 import javax.portlet.RenderResponse;
27
28 import org.apache.pluto.portlet.admin.PlutoAdminConstants;
29 import org.apache.pluto.portlet.admin.bean.PageTO;
30 import org.apache.pluto.portlet.admin.bean.PortletMessage;
31 import org.apache.pluto.portlet.admin.bean.PortletMessageType;
32 import org.apache.pluto.portlet.admin.services.DeployWarService;
33
34
35 /**
36  * Deploys a Portlet Application in a war file including adding a
37  * record to portletentityregistry.xml and pageregistry.xml.
38  *
39  * @author Ken Atherton
40  *
41  */

42 public class DeployWarPortlet extends ControllerPortlet {
43     private DeployWarService service = null;
44
45
46     protected void doEdit(RenderRequest request, RenderResponse response)
47     throws PortletException, IOException JavaDoc {
48         super.doEdit(request, response);
49     }
50
51     /* (non-Javadoc)
52      * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
53      */

54     protected void doView(RenderRequest request, RenderResponse response)
55             throws PortletException, IOException JavaDoc {
56         super.doView(request, response);
57     }
58
59     /* (non-Javadoc)
60      * @see javax.portlet.GenericPortlet#init()
61      */

62     public void init() throws PortletException {
63         super.init();
64         service = new DeployWarService();
65     }
66
67     /* (non-Javadoc)
68      * @see javax.portlet.GenericPortlet#doHelp(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
69      */

70     protected void doHelp(RenderRequest request, RenderResponse response)
71             throws PortletException, IOException JavaDoc {
72         super.doHelp(request, response);
73     }
74
75     public void processAction(ActionRequest request, ActionResponse response)
76             throws PortletException, IOException JavaDoc
77     {
78         try {
79                 String JavaDoc action = request.getParameter("action");
80                 log("Action param == " + action);
81
82                 if (action == null) {
83                     //process file upload
84
String JavaDoc fileName = service.processFileUpload(request,response);
85
86               //Remove .war from the name
87
int index = fileName.indexOf(".war");
88                     String JavaDoc name = null;
89                     if ( index != -1) {
90                         name = fileName.substring(0, index);
91                     } else {
92                         name = fileName;
93                     }
94                     //Add to portletcontexts.txt (for Release Candidate 2+)
95
service.addToPortletContexts(name);
96
97                     //Create a new Page
98
PageTO oPage = new PageTO();
99                     oPage.setName(name);
100                     request.getPortletSession().setAttribute(PlutoAdminConstants.PAGE_ATTR, oPage);
101
102                     //forward to next page to pick rows/cols
103
_incView = "/portlets/admin/PageRegistryAdd.jsp";
104                     response.setPortletMode(PortletMode.VIEW);
105
106                 } else if (action.equals("showhome")) {
107
108                     _incView = "/portlets/admin/DeployWarView.jsp";
109                     response.setPortletMode(PortletMode.VIEW);
110
111                 } else if (action.equals("showpagelayout")) {
112
113                     PortletSession session = request.getPortletSession();
114                     PageTO page = (PageTO)session.getAttribute(PlutoAdminConstants.PAGE_ATTR);
115                     String JavaDoc name = "";
116                     if (page != null) {
117                         name = page.getName();
118                     }
119                     if (page != null && !service.pageExists(name)) {
120                         service.setPage(request);
121                         //forward to page layout page
122
_incView = "/portlets/admin/PageRegistryAdd2.jsp";
123                     } else {
124                         session.setAttribute(PlutoAdminConstants.MESSAGE_ATTR, new PortletMessage("Page '" + name + "' already exists in pageregistry.xml", PortletMessageType.INFO));
125                         _incView = "/portlets/admin/DeployWarView.jsp";
126                     }
127                     response.setPortletMode(PortletMode.VIEW);
128
129                 } else if (action.equals("savepagelayout")) {
130
131                     service.savePageLayout(request);
132                     //forward to first page
133
request.getPortletSession().setAttribute(PlutoAdminConstants.MESSAGE_ATTR, new PortletMessage("Deployment successful. Please restart the Pluto portal.", PortletMessageType.SUCCESS));
134                     _incView = "/portlets/admin/DeployWarView.jsp";
135                     response.setPortletMode(PortletMode.VIEW);
136                 }
137
138         } catch (Throwable JavaDoc e) {
139                 log("Error! ", e);
140                 request.getPortletSession().setAttribute(PlutoAdminConstants.MESSAGE_ATTR, new PortletMessage("A problem has occurred: " + e.getMessage() + ". Please check the servlet container's error log.", PortletMessageType.ERROR));
141             }
142     }
143
144 }
145
Popular Tags