View Javadoc

1   /**
2    * 2009, Digitalis Informatica. All rights reserved. Distribuicao e Gestao de Informatica, Lda. Estrada de Paco de Arcos
3    * num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999 http://www.digitalis.pt
4    */
5   
6   package pt.digitalis.dif.utils.extensions.document;
7   
8   import java.util.Arrays;
9   import java.util.Date;
10  
11  /**
12   * @author Galaio da Silva <a href="mailto:jgalaio@digitalis.pt">jgalaio@digitalis.pt</a><br/>
13   * @created Jun 15, 2009
14   */
15  public class DocumentRepositoryEntry {
16  
17      /**
18       * Document Fields
19       * 
20       * @author Galaio da Silva <a href="mailto:jgalaio@digitalis.pt">jgalaio@digitalis.pt</a><br/>
21       * @created Jun 15, 2009
22       */
23      public static enum Fields {
24          /** The file in bytes */
25          BYTE_CONTENT {
26  
27              @Override
28              public String toString()
29              {
30                  return "ByteContent";
31              }
32          },
33          /** Creation Date */
34          CREATION_DATE {
35  
36              @Override
37              public String toString()
38              {
39                  return "Date";
40              }
41          },
42          /** The creator id */
43          CREATOR {
44  
45              @Override
46              public String toString()
47              {
48                  return "Creator";
49              }
50          },
51          /** Document Description */
52          DESCRIPTION {
53  
54              @Override
55              public String toString()
56              {
57                  return "Description";
58              }
59          },
60          /** Original file name */
61          FILENAME {
62  
63              @Override
64              public String toString()
65              {
66                  return "FileName";
67              }
68          },
69          /** Document Id */
70          ID {
71  
72              @Override
73              public String toString()
74              {
75                  return "Id";
76              }
77          },
78  
79          /** The file myme type */
80          MIMETYPE {
81  
82              @Override
83              public String toString()
84              {
85                  return "MimeType";
86              }
87          },
88          /** Document Name */
89          NAME {
90  
91              @Override
92              public String toString()
93              {
94                  return "Name";
95              }
96          }
97      }
98  
99      /** the binary mimeType */
100     private static final String BINARY_MIME_TYPE = "binary";
101 
102     /** The document data */
103     private byte[] bytes;
104 
105     /** The date when the document was created */
106     private Date creationDate;
107 
108     /** the creator user ID */
109     private String creatorID;
110 
111     /**
112      * For updates interfaces, indicating that the form through an FileUploadField/ImageUploadField has issued a delete
113      * action on this document/"associated parameter"
114      */
115     private boolean deleteRequested;
116 
117     /** The document description */
118     private String description;
119 
120     /** The original file name */
121     private String fileName;
122 
123     /** the document unique identifier in the document repository */
124     private Long id;
125 
126     /** The document mime Type */
127     private String mimeType;
128 
129     /** The document name */
130     private String name;
131 
132     /**
133      * Default constructor for <code>DocumentRepositoryEntry</code>.
134      */
135     public DocumentRepositoryEntry()
136     {
137         super();
138 
139         creationDate = new Date();
140     }
141 
142     /**
143      * Constructor for <code>DocumentRepositoryEntry</code>.
144      * 
145      * @param id
146      *            the document id.
147      * @param creatorID
148      *            the creator id.
149      * @param name
150      *            the document name.
151      * @param description
152      *            the document description.
153      * @param fileName
154      *            the document original fileName.
155      * @param creationDate
156      *            the Document creation date.
157      * @param mimeType
158      *            the document mimeType.
159      * @param bytes
160      *            the document content in bytes.
161      */
162     public DocumentRepositoryEntry(Long id, String creatorID, String name, String description, String fileName,
163             Date creationDate, String mimeType, byte[] bytes)
164     {
165         this.id = id;
166         this.creatorID = creatorID;
167         this.name = name;
168         this.description = description;
169         this.fileName = fileName;
170         this.creationDate = creationDate;
171         this.mimeType = mimeType;
172         this.bytes = bytes;
173     }
174 
175     /**
176      * Constructor for <code>DocumentRepositoryEntry</code>.
177      * 
178      * @param creatorID
179      *            the creator id.
180      * @param name
181      *            the document name.
182      * @param description
183      *            the document description.
184      * @param fileName
185      *            the document original fileName.
186      * @param creationDate
187      *            the Document creation date.
188      * @param mimeType
189      *            the document mimeType.
190      * @param bytes
191      *            the document content in bytes.
192      */
193     public DocumentRepositoryEntry(String creatorID, String name, String description, String fileName,
194             Date creationDate, String mimeType, byte[] bytes)
195     {
196         this.creatorID = creatorID;
197         this.name = name;
198         this.description = description;
199         this.fileName = fileName;
200         this.creationDate = creationDate;
201         this.mimeType = mimeType;
202         this.bytes = bytes;
203     }
204 
205     /**
206      * Automaticaly calculate the Mime Type
207      */
208     public void calculateMimeType()
209     {
210         if (this.fileName != null)
211         {
212             String[] splitFile = this.fileName.split("\\.");
213             if (splitFile.length >= 2)
214             {
215                 this.mimeType = splitFile[splitFile.length - 1];
216 
217             }
218             else
219             {
220                 this.mimeType = BINARY_MIME_TYPE;
221             }
222         }
223     }
224 
225     /**
226      * @see java.lang.Object#equals(java.lang.Object)
227      */
228     @Override
229     public boolean equals(Object obj)
230     {
231         if (this == obj)
232             return true;
233         if (obj == null)
234             return false;
235         if (!(obj instanceof DocumentRepositoryEntry))
236             return false;
237         final DocumentRepositoryEntry other = (DocumentRepositoryEntry) obj;
238         if (!Arrays.equals(bytes, other.bytes))
239             return false;
240         if (creationDate == null)
241         {
242             if (other.creationDate != null)
243                 return false;
244         }
245         else if (!creationDate.equals(other.creationDate))
246             return false;
247         if (creatorID == null)
248         {
249             if (other.creatorID != null)
250                 return false;
251         }
252         else if (!creatorID.equals(other.creatorID))
253             return false;
254         if (description == null)
255         {
256             if (other.description != null)
257                 return false;
258         }
259         else if (!description.equals(other.description))
260             return false;
261         if (fileName == null)
262         {
263             if (other.fileName != null)
264                 return false;
265         }
266         else if (!fileName.equals(other.fileName))
267             return false;
268         if (id == null)
269         {
270             if (other.id != null)
271                 return false;
272         }
273         else if (!id.equals(other.id))
274             return false;
275         if (mimeType == null)
276         {
277             if (other.mimeType != null)
278                 return false;
279         }
280         else if (!mimeType.equals(other.mimeType))
281             return false;
282         if (name == null)
283         {
284             if (other.name != null)
285                 return false;
286         }
287         else if (!name.equals(other.name))
288             return false;
289         return true;
290     }
291 
292     /**
293      * Inspector for the 'bytes' attribute.
294      * 
295      * @return the bytes value
296      */
297     public byte[] getBytes()
298     {
299         return bytes;
300     }
301 
302     /**
303      * Inspector for the 'creationDate' attribute.
304      * 
305      * @return the creationDate value
306      */
307     public Date getCreationDate()
308     {
309         return creationDate;
310     }
311 
312     /**
313      * Inspector for the 'creatorID' attribute.
314      * 
315      * @return the creatorID value
316      */
317     public String getCreatorID()
318     {
319         return creatorID;
320     }
321 
322     /**
323      * Inspector for the 'description' attribute.
324      * 
325      * @return the description value
326      */
327     public String getDescription()
328     {
329         return description;
330     }
331 
332     /**
333      * Inspector for the 'fileName' attribute.
334      * 
335      * @return the fileName value
336      */
337     public String getFileName()
338     {
339         return fileName;
340     }
341 
342     /**
343      * Inspector for the 'id' attribute.
344      * 
345      * @return the id value
346      */
347     public Long getId()
348     {
349         return id;
350     }
351 
352     /**
353      * Inspector for the 'mimeType' attribute.
354      * 
355      * @return the mimeType value
356      */
357     public String getMimeType()
358     {
359         return mimeType;
360     }
361 
362     /**
363      * Inspector for the 'name' attribute.
364      * 
365      * @return the name value
366      */
367     public String getName()
368     {
369         return name;
370     }
371 
372     /**
373      * @see java.lang.Object#hashCode()
374      */
375     @Override
376     public int hashCode()
377     {
378         final int prime = 31;
379         int result = 1;
380         result = prime * result + Arrays.hashCode(bytes);
381         result = prime * result + ((creationDate == null) ? 0 : creationDate.hashCode());
382         result = prime * result + ((creatorID == null) ? 0 : creatorID.hashCode());
383         result = prime * result + ((description == null) ? 0 : description.hashCode());
384         result = prime * result + ((fileName == null) ? 0 : fileName.hashCode());
385         result = prime * result + ((id == null) ? 0 : id.hashCode());
386         result = prime * result + ((mimeType == null) ? 0 : mimeType.hashCode());
387         result = prime * result + ((name == null) ? 0 : name.hashCode());
388         return result;
389     }
390 
391     /**
392      * Inspector for the 'deleteRequested' attribute.
393      * 
394      * @return the deleteRequested value
395      */
396     public boolean isDeleteRequested()
397     {
398         return deleteRequested;
399     }
400 
401     /**
402      * Modifier for the 'bytes' attribute.
403      * 
404      * @param bytes
405      *            the new bytes value to set
406      */
407     public void setBytes(byte[] bytes)
408     {
409         this.bytes = bytes;
410     }
411 
412     /**
413      * Modifier for the 'creationDate' attribute.
414      * 
415      * @param creationDate
416      *            the new creationDate value to set
417      */
418     public void setCreationDate(Date creationDate)
419     {
420         this.creationDate = creationDate;
421     }
422 
423     /**
424      * Modifier for the 'creatorID' attribute.
425      * 
426      * @param creatorID
427      *            the new creatorID value to set
428      */
429     public void setCreatorID(String creatorID)
430     {
431         this.creatorID = creatorID;
432     }
433 
434     /**
435      * Modifier for the 'deleteRequested' attribute.
436      * 
437      * @param deleteRequested
438      *            the new deleteRequested value to set
439      */
440     public void setDeleteRequested(boolean deleteRequested)
441     {
442         this.deleteRequested = deleteRequested;
443     }
444 
445     /**
446      * Modifier for the 'description' attribute.
447      * 
448      * @param description
449      *            the new description value to set
450      */
451     public void setDescription(String description)
452     {
453         this.description = description;
454     }
455 
456     /**
457      * Modifier for the 'fileName' attribute.
458      * 
459      * @param fileName
460      *            the new fileName value to set
461      */
462     public void setFileName(String fileName)
463     {
464         this.fileName = fileName;
465     }
466 
467     /**
468      * Modifier for the 'id' attribute.
469      * 
470      * @param id
471      *            the new id value to set
472      */
473     public void setId(Long id)
474     {
475         this.id = id;
476     }
477 
478     /**
479      * Modifier for the 'mimeType' attribute.
480      * 
481      * @param mimeType
482      *            the new mimeType value to set
483      */
484     public void setMimeType(String mimeType)
485     {
486         this.mimeType = mimeType;
487     }
488 
489     /**
490      * Modifier for the 'name' attribute.
491      * 
492      * @param name
493      *            the new name value to set
494      */
495     public void setName(String name)
496     {
497         this.name = name;
498     }
499 
500 }