1 23 package org.infoglue.deliver.applications.actions; 24 25 import java.io.File ; 26 import java.io.InputStream ; 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 51 public class DeployPortletAction extends InfoGlueAbstractAction { 52 private static final Log log = LogFactory.getLog(DeployPortletAction.class); 53 54 private static final String PORTLET_BASE = CmsPropertyHandler.getPortletBase(); 56 57 private Integer digitalAssetId; 58 59 64 protected String doExecute() throws Exception 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 webappsDir = PORTLET_BASE; 81 if (webappsDir == null || webappsDir.length() == 0) 82 { 83 String 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 (tomcat_home, "webapps").getAbsolutePath(); 91 } 92 } 93 94 String containerName = (String ) getRequest().getAttribute(PortalServletDispatcher.PORTLET_CONTAINER_NAME); 95 96 String warName = da.getAssetFileName(); 98 log.info("Deploying portlet " + warName + " at " + webappsDir); 99 InputStream 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 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 e) 125 { 126 e.printStackTrace(); 127 } 128 } 129 130 return "success"; 131 } 132 133 136 public Integer getDigitalAssetId() { 137 return digitalAssetId; 138 } 139 140 143 public void setDigitalAssetId(Integer integer) { 144 digitalAssetId = integer; 145 } 146 147 } | Popular Tags |