1 23 24 package org.infoglue.cms.applications.managementtool.actions; 25 26 import java.io.ByteArrayInputStream ; 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 30 import org.apache.log4j.Logger; 31 import org.apache.pluto.portalImpl.services.portletentityregistry.PortletEntityRegistry; 32 import org.exolab.castor.jdo.Database; 33 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction; 34 import org.infoglue.cms.controllers.kernel.impl.simple.CastorDatabaseService; 35 import org.infoglue.cms.controllers.kernel.impl.simple.PortletAssetController; 36 import org.infoglue.cms.entities.content.DigitalAsset; 37 import org.infoglue.cms.entities.content.DigitalAssetVO; 38 import org.infoglue.cms.util.CmsPropertyHandler; 39 import org.infoglue.cms.util.NotificationMessage; 40 import org.infoglue.cms.util.RemoteCacheUpdater; 41 import org.infoglue.deliver.portal.services.PortletEntityRegistryServiceDBImpl; 42 43 46 47 public class UpdatePortletRegistryAction extends InfoGlueAbstractAction 48 { 49 private final static Logger logger = Logger.getLogger(UpdatePortletRegistryAction.class.getName()); 50 51 private String portletRegistry; 52 53 public String doExecute() throws Exception 54 { 55 store(); 56 57 return "success"; 58 } 59 60 private void store() throws IOException 61 { 62 logger.info("Storing PortletEntityRegistry...\n" + portletRegistry); 63 64 try 65 { 66 Database db = CastorDatabaseService.getDatabase(); 67 db.begin(); 68 69 byte[] serial = portletRegistry.getBytes(); 70 InputStream is = new ByteArrayInputStream (serial); 71 72 DigitalAsset da = PortletAssetController.getPortletAssetController().getPortletRegistryAsset(db); 73 if (da == null) 74 { 75 logger.info("Creating new " + PortletEntityRegistryServiceDBImpl.PORTLET_REGISTRY_CONTENT_NAME); 76 77 String filePath = CmsPropertyHandler.getDigitalAssetPath(); 78 DigitalAssetVO newAsset = new DigitalAssetVO(); 79 newAsset.setAssetContentType("text/xml"); 80 newAsset.setAssetKey(PortletEntityRegistryServiceDBImpl.PORTLET_REGISTRY_CONTENT_NAME); 81 newAsset.setAssetFileName(PortletEntityRegistryServiceDBImpl.PORTLET_REGISTRY_CONTENT_NAME); 82 newAsset.setAssetFilePath(filePath); 83 newAsset.setAssetFileSize(new Integer (serial.length)); 84 85 da = PortletAssetController.getPortletAssetController().create(db, newAsset, is); 86 logger.warn(PortletEntityRegistryServiceDBImpl.PORTLET_REGISTRY_CONTENT_NAME + " stored as id=" + da.getId()); 87 } 88 else 89 { 90 logger.info("Updating " + PortletEntityRegistryServiceDBImpl.PORTLET_REGISTRY_CONTENT_NAME); 91 92 DigitalAssetVO daVO = da.getValueObject(); 93 daVO.setAssetFileSize(new Integer (serial.length)); 94 95 PortletAssetController.update(daVO, is); 96 } 97 98 is.close(); 99 100 PortletEntityRegistry.load(); 101 102 NotificationMessage notificationMessage = new NotificationMessage("UpdatePortletRegistryAction.store():", "PortletRegistry", this.getInfoGluePrincipal().getName(), NotificationMessage.SYSTEM, "0", "PortletRegistry"); 103 RemoteCacheUpdater.getSystemNotificationMessages().add(notificationMessage); 104 105 db.commit(); 106 db.close(); 107 logger.debug("Stored PortletEntityRegistry successfully"); 108 } 109 catch (Throwable e) 110 { 111 logger.error("Failed to store PortletEntityRegistry", e); 112 } 113 } 114 115 116 public String getPortletRegistry() 117 { 118 return portletRegistry; 119 } 120 121 public void setPortletRegistry(String portletRegistry) 122 { 123 this.portletRegistry = portletRegistry; 124 } 125 126 127 } 128 | Popular Tags |