KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > managementtool > actions > UpdatePortletRegistryAction


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
24 package org.infoglue.cms.applications.managementtool.actions;
25
26 import java.io.ByteArrayInputStream JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.io.InputStream JavaDoc;
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 /**
44  * @author Mattias Bogeblad
45  */

46
47 public class UpdatePortletRegistryAction extends InfoGlueAbstractAction
48 {
49     private final static Logger logger = Logger.getLogger(UpdatePortletRegistryAction.class.getName());
50
51     private String JavaDoc portletRegistry;
52     
53     public String JavaDoc doExecute() throws Exception JavaDoc
54     {
55         store();
56         
57         return "success";
58     }
59
60     private void store() throws IOException JavaDoc
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 JavaDoc is = new ByteArrayInputStream JavaDoc(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 JavaDoc 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 JavaDoc(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 JavaDoc(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 JavaDoc e)
110         {
111             logger.error("Failed to store PortletEntityRegistry", e);
112         }
113     }
114
115     
116     public String JavaDoc getPortletRegistry()
117     {
118         return portletRegistry;
119     }
120
121     public void setPortletRegistry(String JavaDoc portletRegistry)
122     {
123         this.portletRegistry = portletRegistry;
124     }
125     
126
127 }
128
Popular Tags