1 23 27 package org.infoglue.cms.controllers.kernel.impl.simple; 28 29 import java.io.InputStream ; 30 import java.util.ArrayList ; 31 import java.util.List ; 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 49 public class PortletAssetController extends DigitalAssetController 50 { 51 private final static Logger logger = Logger.getLogger(PortletAssetController.class.getName()); 52 53 56 57 public static PortletAssetController getPortletAssetController() 58 { 59 return new PortletAssetController(); 60 } 61 62 public static DigitalAsset create(DigitalAssetVO digitalAssetVO, InputStream 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 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 getDigitalAssetByName(String name) throws SystemException 91 { 92 Database db = CastorDatabaseService.getDatabase(); 93 94 List contents = new ArrayList (); 95 96 beginTransaction(db); 97 try 98 { 99 contents = getDigitalAssetByName(name, db); 100 101 commitTransaction(db); 102 } 103 catch (Exception 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 getDigitalAssetByName(String name, Database db) throws SystemException, Exception 114 { 115 List contents = new ArrayList (); 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 134 { 135 List 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 151 { 152 List 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 |