KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > business > library > item > LibraryItemDO


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: LibraryItemDO.java,v $
31  * Revision 1.4 2005/04/26 15:18:45 colinmacleod
32  * Renamed Faq to FAQ.
33  *
34  * Revision 1.3 2005/04/10 20:31:59 colinmacleod
35  * Added new themes.
36  * Changed id type to String.
37  * Changed i tag to em and b tag to strong.
38  * Improved PicoContainerFactory with NanoContainer scripts.
39  *
40  * Revision 1.2 2005/04/09 17:19:45 colinmacleod
41  * Changed copyright text to GPL v2 explicitly.
42  *
43  * Revision 1.1.1.1 2005/03/10 17:51:59 colinmacleod
44  * Restructured ivata op around Hibernate/PicoContainer.
45  * Renamed ivata groupware.
46  *
47  * Revision 1.3 2004/07/13 19:47:28 colinmacleod
48  * Moved project to POJOs from EJBs.
49  * Applied PicoContainer to services layer (replacing session EJBs).
50  * Applied Hibernate to persistence layer (replacing entity EJBs).
51  *
52  * Revision 1.2 2004/03/21 21:16:29 colinmacleod
53  * Shortened name to ivata op.
54  *
55  * Revision 1.1.1.1 2004/01/27 20:58:40 colinmacleod
56  * Moved ivata openportal to SourceForge..
57  *
58  * Revision 1.4 2004/01/19 21:13:14 colin
59  * Removed minutes for ivata groupware v0.9
60  *
61  * Revision 1.3 2003/10/28 13:16:14 jano
62  * commiting library,
63  * still fixing compile and building openGroupware project
64  *
65  * Revision 1.2 2003/10/15 14:16:53 colin
66  * fixing for XDoclet
67  *
68  * Revision 1.1 2003/02/24 19:09:22 colin
69  * moved to business
70  *
71  * Revision 1.3 2003/02/04 17:43:47 colin
72  * copyright notice
73  *
74  * Revision 1.2 2002/07/02 14:56:31 colin
75  * tried to fix jbuilder EJB designer
76  *
77  * Revision 1.1 2002/06/18 11:40:13 colin
78  * first version of library
79  * -----------------------------------------------------------------------------
80  */

81 package com.ivata.groupware.business.library.item;
82
83 import java.beans.XMLDecoder JavaDoc;
84 import java.beans.XMLEncoder JavaDoc;
85 import java.io.File JavaDoc;
86 import java.io.FileOutputStream JavaDoc;
87 import java.io.IOException JavaDoc;
88 import java.util.List JavaDoc;
89
90 import com.ivata.groupware.business.drive.file.FileContentDO;
91 import com.ivata.groupware.business.library.topic.TopicDO;
92 import com.ivata.groupware.container.persistence.TimestampDO;
93
94 /**
95  * <p>Represents a single item within the library. The item can be one of six
96  * types:<br/>
97  * <ul>
98  * <li>document</li>
99  * <li>Faq (Frequently Asked Question)</li>
100  * <li>memo</li>
101  * <li>note</li>
102  * <li>news item</li>
103  * <li>meeting agenda/minutes</li>
104  * </ul></p>
105  *
106  * <p>This is a dependent value class, used to pass data back from the.</p>
107  * {@link LibraryItemBean LibraryItemBean} to a client application.</p>
108  *
109  * <p><strong>Note:</strong> This class provides data from {@link LibraryItemBean LibraryItemBean}.
110  * This is no local copy of the bean class, however, and changes here
111  * will not be automatically reflected in {@link LibraryItemBean LibraryItemBean}.</p>
112  *
113  * @since 2002-06-14
114  * @author Colin MacLeod
115  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
116  * @version $Revision: 1.4 $
117  * @see LibraryItemBean
118  *
119  * @hibernate.class
120  * table="library_item"
121  */

122 public class LibraryItemDO extends TimestampDO {
123
124     /**
125      * <p>This method converts an XML file to a LibraryItemDO.</p>
126      *
127      * @param fileContent contains the XML to be converted
128      * @return valid library item.
129      */

130     public static LibraryItemDO convertFromFile(FileContentDO fileContent) {
131         XMLDecoder JavaDoc decoder = new XMLDecoder JavaDoc(fileContent.getContent().getInputStream());
132         LibraryItemDO itemDO = (LibraryItemDO) decoder.readObject();
133
134         decoder.close();
135         return itemDO;
136     }
137
138     /**
139      * <p>If the item is frequently asked questions, store all the categoreies
140      * of questions here.</p>
141      */

142     private List JavaDoc fAQCategories;
143
144     /**
145      * <p>Store the directory to store images in for this library item.</p>
146      */

147     private String JavaDoc imageDirectory;
148
149     /**
150      * <p>Store all the pages of this item, if it has pages.</p>
151      */

152     private List JavaDoc pages;
153
154     /**
155      * <p>Store the summary text. This summary will appear on the noticeboard page,
156      * giving an overview of the content of the item.</p>
157      */

158     private String JavaDoc summary;
159
160
161     /**
162      * <p>Store the title for this item. Is usually used in the titlebar of the
163      * window which displays the item.</p>
164      */

165     private String JavaDoc title;
166
167     /**
168      * <p>Topics are used to group items together and apply rights.</p>
169      */

170     private TopicDO topic;
171     /**
172      * <p>Store the type of the item, to one of the values found in {@link LibraryItemConstants
173      * LibraryItemConstants}.</p>
174      */

175     private Integer JavaDoc type;
176
177     /**
178      * <p>If the item is frequently asked questions, set all the categoreies
179      * of questions here.</p>
180      *
181      * @return fAQCategories <code>List</code> of <code>FAQCategoryDO</code>
182      * instances.
183      *
184      * @hibernate.bag
185      * cascade="all"
186      * @hibernate.collection-key
187      * column="library_item"
188      * @hibernate.collection-one-to-many
189      * class="com.ivata.groupware.business.library.faq.category.FAQCategoryDO"
190      */

191     public List JavaDoc getFAQCategories() {
192         return fAQCategories;
193     }
194     /**
195      * <p>Get the directory to store images in for this library item.</p>
196      *
197      * @return the directory to store images in for this library item.
198      * @hibernate.property
199      * column="image_directory"
200      */

201     public final String JavaDoc getImageDirectory() {
202         return imageDirectory;
203     }
204
205     /**
206      * <p>Set all the pages of this item, as a <code>List</code> of
207      * <code>PageDO</code> instances.</p>
208      *
209      * <p>
210      * <strong>Note:</strong> not all types have pages. Use this method only if this
211      * library item represents a document, news item or meeting minutes.</p>
212      *
213      * @return page texts as a set of DO instances.
214      *
215      * @hibernate.bag
216      * cascade="all"
217      * @hibernate.collection-key
218      * column="library_item"
219      * @hibernate.collection-one-to-many
220      * class="com.ivata.groupware.business.library.page.PageDO"
221      */

222     public List JavaDoc getPages() {
223         return pages;
224     }
225
226     /**
227      * <p>Set the summary text. This summary will appear on the noticeboard page,
228      * giving an overview of the content of the item.</p>
229      *
230      * @return the summary text.
231      * @hibernate.property
232      */

233     public final String JavaDoc getSummary() {
234         return summary;
235     }
236
237     /**
238      * <p>Set the title for this item. Is usually used in the titlebar of the
239      * window which displays the item.</p>
240      *
241      * @return the title for this item. Is usually used in the titlebar of the
242      * window which displays the item.
243      * @hibernate.property
244      */

245     public final String JavaDoc getTitle() {
246         return title;
247     }
248
249     /**
250      * <p>Topics are used to group items together and apply rights.</p>
251      *
252      * @return current value of topic.
253      * @hibernate.many-to-one
254      * column="library_topic"
255      */

256     public final TopicDO getTopic() {
257         return topic;
258     }
259
260     /**
261      * <p>Get the type of the item, as one of the values found in {@link LibraryItemConstants
262      * LibraryItemConstants}.</p>
263      * @hibernate.property
264      */

265     public final Integer JavaDoc getType() {
266         return type;
267     }
268
269     /**
270      * <p>This method will convert a library item to a to a file.
271      * In this case it will be an XML file.</p>
272      *
273      * @return name of the file this library item was saved to.
274      */

275     public String JavaDoc saveToFile()
276             throws IOException JavaDoc {
277         String JavaDoc returnFileName = "";
278
279         // create temporary file
280
File JavaDoc tmpFile = File.createTempFile("drive", "xml");
281
282         returnFileName = tmpFile.getPath();
283         // write itemDO to file
284
FileOutputStream JavaDoc file = new FileOutputStream JavaDoc(returnFileName);
285         XMLEncoder JavaDoc encoder = new XMLEncoder JavaDoc(file);
286
287         encoder.writeObject(this);
288         encoder.close();
289         file.close();
290
291         return returnFileName;
292     }
293
294     /**
295      * <p>If the item is frequently asked questions, set all the categoreies
296      * of questions here.</p>
297      *
298      * @param fAQCategories <code>List</code> of <code>FAQCategoryDO</code>
299      * instances.
300      */

301     public final void setFAQCategories(final List JavaDoc fAQCategories) {
302         this.fAQCategories = fAQCategories;
303     }
304
305     /**
306      * <p>Set the directory to store images in for this library item.</p>
307      *
308      * @param imageDirectory new value of image directory.
309      */

310     public final void setImageDirectory(final String JavaDoc imageDirectory) {
311         this.imageDirectory = imageDirectory;
312     }
313
314     /**
315      * <p>Set all the pages of this item, as a <code>List</code> of
316      * <code>PageDO</code> instances.</p>
317      *
318      * <p>
319      * <strong>Note:</strong> not all types have pages. Use this method only if this
320      * library item represents a document, news item or meeting minutes.</p>
321      *
322      * @param pages new value of page texts as a set of DO instances.
323      */

324     public final void setPages(final List JavaDoc pages) {
325         this.pages = pages;
326     }
327
328     /**
329      * <p>Set the summary text. This summary will appear on the noticeboard page,
330      * giving an overview of the content of the item.</p>
331      *
332      * @param summary summary of the item's contents.
333      */

334     public final void setSummary(final String JavaDoc summary) {
335         this.summary = summary;
336     }
337
338
339     /**
340      * <p>Set the title for this item. Is usually used in the titlebar of the
341      * window which displays the item.</p>
342      *
343      * @param title new value of title.
344      */

345     public final void setTitle(final String JavaDoc title) {
346         this.title = title;
347     }
348
349     /**
350      * <p>Topics are used to group items together and apply rights.</p>
351      *
352      * @param topic new value of topic.
353      */

354     public final void setTopic(final TopicDO topic) {
355         this.topic = topic;
356     }
357
358     /**
359      * <p>Set the type of the item, to one of the values found in {@link LibraryItemConstants
360      * LibraryItemConstants}.</p>
361      */

362     public final void setType(final Integer JavaDoc type) {
363         this.type = type;
364     }
365
366 }
367
Popular Tags