KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > controllers > kernel > impl > simple > PortletAssetController


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  * Created on 2005-apr-05
25  *
26  */

27 package org.infoglue.cms.controllers.kernel.impl.simple;
28
29 import java.io.InputStream JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.List JavaDoc;
32
33 import org.apache.log4j.Logger;
34 import org.exolab.castor.jdo.Database;
35 import org.exolab.castor.jdo.OQLQuery;
36 import org.exolab.castor.jdo.QueryResults;
37 import org.infoglue.cms.entities.content.DigitalAsset;
38 import org.infoglue.cms.entities.content.DigitalAssetVO;
39 import org.infoglue.cms.entities.content.impl.simple.DigitalAssetImpl;
40 import org.infoglue.cms.exception.SystemException;
41 import org.infoglue.deliver.portal.services.PortletEntityRegistryServiceDBImpl;
42
43
44 /**
45  * Controller that handles portlets. Simply an extension of DigitalAssetController.
46  *
47  * @author jand
48  */

49 public class PortletAssetController extends DigitalAssetController
50 {
51     private final static Logger logger = Logger.getLogger(PortletAssetController.class.getName());
52
53     /**
54      * Factory method
55      */

56
57     public static PortletAssetController getPortletAssetController()
58     {
59         return new PortletAssetController();
60     }
61
62     public static DigitalAsset create(DigitalAssetVO digitalAssetVO, InputStream JavaDoc is) throws SystemException
63     {
64         Database db = CastorDatabaseService.getDatabase();
65
66         DigitalAsset digitalAsset = null;
67
68         beginTransaction(db);
69         
70         try
71         {
72             digitalAsset = new DigitalAssetImpl();
73             digitalAsset.setValueObject(digitalAssetVO);
74             digitalAsset.setAssetBlob(is);
75
76             db.create(digitalAsset);
77
78             commitTransaction(db);
79         }
80         catch (Exception JavaDoc e)
81         {
82             logger.error("An error occurred so we should not complete the transaction:" + e, e);
83             rollbackTransaction(db);
84             throw new SystemException(e.getMessage());
85         }
86
87         return digitalAsset;
88     }
89
90     public static List JavaDoc getDigitalAssetByName(String JavaDoc name) throws SystemException
91     {
92         Database db = CastorDatabaseService.getDatabase();
93         
94         List JavaDoc contents = new ArrayList JavaDoc();
95
96         beginTransaction(db);
97         try
98         {
99             contents = getDigitalAssetByName(name, db);
100             
101             commitTransaction(db);
102         }
103         catch (Exception JavaDoc e)
104         {
105             logger.error("An error occurred so we should not complete the transaction:" + e, e);
106             rollbackTransaction(db);
107             throw new SystemException(e.getMessage());
108         }
109
110         return contents;
111     }
112
113     public static List JavaDoc getDigitalAssetByName(String JavaDoc name, Database db) throws SystemException, Exception JavaDoc
114     {
115         List JavaDoc contents = new ArrayList JavaDoc();
116
117         OQLQuery oql = db.getOQLQuery("SELECT c FROM org.infoglue.cms.entities.content.impl.simple.DigitalAssetImpl c WHERE c.assetFileName = $1");
118         oql.bind(name);
119
120         QueryResults results = oql.execute(Database.ReadOnly);
121
122         while (results.hasMore())
123         {
124             contents.add(results.next());
125         }
126
127         results.close();
128         oql.close();
129
130         return contents;
131     }
132
133     public DigitalAsset getPortletRegistryAsset() throws Exception JavaDoc
134     {
135         List JavaDoc das = PortletAssetController.getDigitalAssetByName(PortletEntityRegistryServiceDBImpl.PORTLET_REGISTRY_CONTENT_NAME);
136         if (das != null && das.size() > 0)
137         {
138             DigitalAsset da = (DigitalAsset) das.get(0);
139             logger.debug("Registry located as id=" + da.getId());
140             return da;
141         }
142         else
143         {
144             logger.info("Portlet Registry not found");
145         }
146         
147         return null;
148     }
149
150     public DigitalAsset getPortletRegistryAsset(Database db) throws Exception JavaDoc
151     {
152         List JavaDoc das = PortletAssetController.getDigitalAssetByName(PortletEntityRegistryServiceDBImpl.PORTLET_REGISTRY_CONTENT_NAME, db);
153         if (das != null && das.size() > 0)
154         {
155             DigitalAsset da = (DigitalAsset) das.get(0);
156             logger.debug("Registry located as id=" + da.getId());
157             return da;
158         }
159         else
160         {
161             logger.info("Portlet Registry not found");
162         }
163         
164         return null;
165     }
166
167 }
Popular Tags