KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > entities > content > impl > simple > DigitalAssetImpl


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.entities.content.impl.simple;
25
26 import java.io.BufferedInputStream JavaDoc;
27 import java.io.ByteArrayInputStream JavaDoc;
28 import java.io.ByteArrayOutputStream JavaDoc;
29 import java.io.InputStream JavaDoc;
30
31 import org.infoglue.cms.entities.content.DigitalAsset;
32 import org.infoglue.cms.entities.content.DigitalAssetVO;
33 import org.infoglue.cms.entities.kernel.BaseEntityVO;
34
35 public class DigitalAssetImpl implements DigitalAsset
36 {
37     private DigitalAssetVO valueObject = new DigitalAssetVO();
38     private byte[] assetBytes = null;
39     private java.util.Collection JavaDoc contentVersions;
40     private java.util.Collection JavaDoc userProperties;
41     private java.util.Collection JavaDoc roleProperties;
42     private java.util.Collection JavaDoc groupProperties;
43     private java.io.InputStream JavaDoc assetBlob;
44     private boolean assetBlobRead = false;
45         
46     /**
47      * @see org.infoglue.cms.entities.kernel.BaseEntity#getVO()
48      */

49     public BaseEntityVO getVO()
50     {
51         return (BaseEntityVO) getValueObject();
52     }
53
54     /**
55      * @see org.infoglue.cms.entities.kernel.BaseEntity#setVO(BaseEntityVO)
56      */

57     public void setVO(BaseEntityVO valueObject)
58     {
59         setValueObject((DigitalAssetVO) valueObject);
60     }
61  
62     /**
63      * @see org.infoglue.cms.entities.kernel.BaseEntity#getId()
64      */

65     public Integer JavaDoc getId()
66     {
67         return getDigitalAssetId();
68     }
69     
70     public Object JavaDoc getIdAsObject()
71     {
72         return getId();
73     }
74         
75     public DigitalAssetVO getValueObject()
76     {
77         return this.valueObject;
78     }
79         
80     public void setValueObject(DigitalAssetVO valueObject)
81     {
82         this.valueObject = valueObject;
83     }
84     
85     public java.lang.Integer JavaDoc getDigitalAssetId()
86     {
87         return this.valueObject.getDigitalAssetId();
88     }
89             
90     public void setDigitalAssetId(java.lang.Integer JavaDoc digitalAssetId)
91     {
92         this.valueObject.setDigitalAssetId(digitalAssetId);
93     }
94       
95     public java.lang.String JavaDoc getAssetFileName()
96     {
97         return this.valueObject.getAssetFileName();
98     }
99             
100     public void setAssetFileName(java.lang.String JavaDoc assetFileName)
101     {
102         this.valueObject.setAssetFileName(assetFileName);
103     }
104
105     public java.lang.String JavaDoc getAssetKey()
106     {
107         return this.valueObject.getAssetKey();
108     }
109             
110     public void setAssetKey(java.lang.String JavaDoc assetKey)
111     {
112         this.valueObject.setAssetKey(assetKey);
113     }
114       
115     public java.lang.String JavaDoc getAssetFilePath()
116     {
117         return this.valueObject.getAssetFilePath();
118     }
119             
120     public void setAssetFilePath(java.lang.String JavaDoc assetFilePath)
121     {
122         this.valueObject.setAssetFilePath(assetFilePath);
123     }
124       
125     public java.lang.String JavaDoc getAssetContentType()
126     {
127         return this.valueObject.getAssetContentType();
128     }
129             
130     public void setAssetContentType(java.lang.String JavaDoc assetContentType)
131     {
132         this.valueObject.setAssetContentType(assetContentType);
133     }
134       
135     public java.lang.Integer JavaDoc getAssetFileSize()
136     {
137         return this.valueObject.getAssetFileSize();
138     }
139             
140     public void setAssetFileSize(java.lang.Integer JavaDoc assetFileSize)
141     {
142         this.valueObject.setAssetFileSize(assetFileSize);
143     }
144       
145     public java.util.Collection JavaDoc getContentVersions()
146     {
147         return this.contentVersions;
148     }
149             
150     public void setContentVersions (java.util.Collection JavaDoc contentVersions)
151     {
152         this.contentVersions = contentVersions;
153     }
154     
155     public java.util.Collection JavaDoc getUserProperties()
156     {
157         return this.userProperties;
158     }
159     
160     public void setUserProperties(java.util.Collection JavaDoc userProperties)
161     {
162         this.userProperties = userProperties;
163     }
164
165     public java.util.Collection JavaDoc getRoleProperties()
166     {
167         return this.roleProperties;
168     }
169     
170     public void setRoleProperties(java.util.Collection JavaDoc roleProperties)
171     {
172         this.roleProperties = roleProperties;
173     }
174
175     public java.util.Collection JavaDoc getGroupProperties()
176     {
177         return this.groupProperties;
178     }
179     
180     public void setGroupProperties(java.util.Collection JavaDoc groupProperties)
181     {
182         this.groupProperties = groupProperties;
183     }
184     
185     public void setAssetBlob(java.io.InputStream JavaDoc assetBlob)
186     {
187         this.assetBlob = assetBlob;
188     }
189
190     public synchronized InputStream JavaDoc getAssetBlob()
191     {
192         InputStream JavaDoc inputStream = null;
193         if(this.assetBytes != null)
194         {
195             inputStream = new ByteArrayInputStream JavaDoc(assetBytes);
196         }
197         else
198         {
199             inputStream = assetBlob;
200         }
201         
202         assetBlobRead = true;
203         
204         return inputStream;
205     }
206     
207     public void setAssetBytes(byte[] bytes)
208     {
209         setAssetBlob(new ByteArrayInputStream JavaDoc(bytes));
210     }
211
212     
213     public byte[] getAssetBytes()
214     {
215         if(this.assetBytes == null)
216         {
217             try
218             {
219                 ByteArrayOutputStream JavaDoc byteArrayOutputStream = new ByteArrayOutputStream JavaDoc();
220                 
221                 BufferedInputStream JavaDoc bis = new BufferedInputStream JavaDoc(getAssetBlob());
222                 
223                 int character;
224                 while ((character = bis.read()) != -1)
225                 {
226                     byteArrayOutputStream.write(character);
227                 }
228                 byteArrayOutputStream.flush();
229         
230                 bis.close();
231                 byteArrayOutputStream.close();
232                 
233                 this.assetBytes = byteArrayOutputStream.toByteArray();
234             }
235             catch(Exception JavaDoc e)
236             {
237                 e.printStackTrace();
238             }
239         }
240                 
241         return this.assetBytes;
242     }
243
244     public boolean getIsAssetBlobRead()
245     {
246         return assetBlobRead;
247     }
248 }
249
Popular Tags