KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > applications > actions > DeployPortletAction


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23 package org.infoglue.deliver.applications.actions;
24
25 import java.io.File JavaDoc;
26 import java.io.InputStream JavaDoc;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.exolab.castor.jdo.Database;
31 import org.exolab.castor.jdo.PersistenceException;
32 import org.exolab.castor.jdo.TransactionAbortedException;
33 import org.exolab.castor.jdo.TransactionNotInProgressException;
34 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
35 import org.infoglue.cms.controllers.kernel.impl.simple.CastorDatabaseService;
36 import org.infoglue.cms.controllers.kernel.impl.simple.PortletAssetController;
37 import org.infoglue.cms.entities.content.DigitalAsset;
38 import org.infoglue.cms.util.CmsPropertyHandler;
39 import org.infoglue.deliver.portal.deploy.Deploy;
40 import org.infoglue.deliver.portal.dispatcher.PortalServletDispatcher;
41 import org.infoglue.deliver.util.CacheController;
42
43 /**
44  * Deploy a portlet in the servlet container. Requires that the 'portletBase'
45  * property points to where the .war-file should be deployed (placed), e.g.
46  * TOMCAT/webapps
47  *
48  * @author jand
49  *
50  */

51 public class DeployPortletAction extends InfoGlueAbstractAction {
52     private static final Log log = LogFactory.getLog(DeployPortletAction.class);
53
54     // TODO fixme;
55
private static final String JavaDoc PORTLET_BASE = CmsPropertyHandler.getPortletBase();
56
57     private Integer JavaDoc digitalAssetId;
58
59     /*
60      * (non-Javadoc)
61      *
62      * @see org.infoglue.cms.applications.common.actions.WebworkAbstractAction#doExecute()
63      */

64     protected String JavaDoc doExecute() throws Exception JavaDoc
65     {
66         log.debug("Deploying portlet, digitalAssetId=" + digitalAssetId);
67
68         Database db = CastorDatabaseService.getDatabase();
69
70         try
71         {
72             db.begin();
73
74             DigitalAsset da = PortletAssetController.getDigitalAssetWithId(digitalAssetId, db);
75             if (da == null)
76             {
77                 return "error";
78             }
79
80             String JavaDoc webappsDir = PORTLET_BASE;
81             if (webappsDir == null || webappsDir.length() == 0)
82             {
83                 String JavaDoc tomcat_home = System.getProperty("CATALINA_HOME");
84                 if (tomcat_home == null)
85                 {
86                     tomcat_home = System.getProperty("TOMCAT_HOME");
87                 }
88                 if (tomcat_home != null)
89                 {
90                     webappsDir = new File JavaDoc(tomcat_home, "webapps").getAbsolutePath();
91                 }
92             }
93
94             String JavaDoc containerName = (String JavaDoc) getRequest().getAttribute(PortalServletDispatcher.PORTLET_CONTAINER_NAME);
95
96             // Deploy portlet
97
String JavaDoc warName = da.getAssetFileName();
98             log.info("Deploying portlet " + warName + " at " + webappsDir);
99             InputStream JavaDoc is = da.getAssetBlob();
100             boolean deployed = Deploy.deployArchive(webappsDir, warName, is, containerName);
101             is.close();
102             if (deployed)
103             {
104                 log.debug("Successful portlet deployment!");
105             }
106             else
107             {
108                 log.debug("Portlet already deployed!");
109             }
110             
111             CacheController.clearPortlets();
112         }
113         catch(Exception JavaDoc e)
114         {
115             log.error("An error occurred when deployin portlet:" + e.getMessage(), e);
116         }
117         finally
118         {
119             try
120             {
121                 db.commit();
122                 db.close();
123             }
124             catch (Exception JavaDoc e)
125             {
126                 e.printStackTrace();
127             }
128         }
129         
130         return "success";
131     }
132
133     /**
134      * @return
135      */

136     public Integer JavaDoc getDigitalAssetId() {
137         return digitalAssetId;
138     }
139
140     /**
141      * @param integer
142      */

143     public void setDigitalAssetId(Integer JavaDoc integer) {
144         digitalAssetId = integer;
145     }
146
147 }
Popular Tags