KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > portlets > files > model > File


1 package com.dotmarketing.portlets.files.model;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import org.apache.commons.lang.builder.EqualsBuilder;
7 import org.apache.commons.lang.builder.HashCodeBuilder;
8 import org.apache.commons.lang.builder.ToStringBuilder;
9
10 import com.dotmarketing.beans.Identifier;
11 import com.dotmarketing.beans.WebAsset;
12 import com.dotmarketing.factories.IdentifierFactory;
13 import com.dotmarketing.portlets.folders.model.Folder;
14 import com.dotmarketing.util.Logger;
15 import com.dotmarketing.util.UtilMethods;
16
17 /** @author Hibernate CodeGenerator */
18 public class File extends WebAsset implements Serializable JavaDoc, Comparable JavaDoc {
19
20     private static final long serialVersionUID = 1L;
21
22     /** identifier field */
23     private long parent;
24
25     /** nullable persistent field */
26     private String JavaDoc fileName;
27
28     /** nullable persistent field */
29     private int size;
30
31     /** nullable persistent field */
32     private int height;
33
34     /** nullable persistent field */
35     private int width;
36     
37     /** nullable persistent field */
38     private String JavaDoc mimeType;
39
40     /** nullable persistent field */
41     private String JavaDoc author;
42
43     /** nullable persistent field */
44     private java.util.Date JavaDoc publishDate;
45
46     /** nullable persistent field */
47     private int maxSize;
48     /** nullable persistent field */
49     private int maxHeight;
50     /** nullable persistent field */
51     private int maxWidth;
52     /** nullable persistent field */
53     private int minHeight;
54
55     /** nullable persistent field */
56     private String JavaDoc[] categories;
57
58     /** default constructor */
59     public File() {
60         super.setType("file_asset");
61         super.setModDate(new java.util.Date JavaDoc());
62         publishDate = new java.util.Date JavaDoc();
63     }
64
65     public String JavaDoc getURI(Folder folder) {
66         return folder.getPath() + this.getFileName();
67     }
68     public String JavaDoc getURI() {
69         Identifier id = IdentifierFactory.getIdentifierByInode(this);
70         return id.getURI();
71
72
73     }
74
75     public long getInode() {
76         return this.inode;
77     }
78
79     public void setInode(long inode) {
80         this.inode = inode;
81     }
82     public java.lang.String JavaDoc getFileName() {
83         return this.fileName;
84     }
85
86     public void setFileName(java.lang.String JavaDoc fileName) {
87         this.fileName = fileName;
88     }
89     public int getSize() {
90         return this.size;
91     }
92
93     public void setSize(int size) {
94         this.size = size;
95     }
96     public String JavaDoc toString() {
97         return ToStringBuilder.reflectionToString(this);
98     }
99
100     public boolean equals(Object JavaDoc other) {
101         if ( !(other instanceof File) ) return false;
102         File castOther = (File) other;
103         return new EqualsBuilder()
104             .append(this.inode, castOther.inode)
105             .isEquals();
106     }
107
108     public int hashCode() {
109         return new HashCodeBuilder()
110             .append(inode)
111             .toHashCode();
112     }
113
114     /**
115      * Returns the maxHeight.
116      * @return int
117      */

118     public int getMaxHeight() {
119         return maxHeight;
120     }
121
122     /**
123      * Returns the maxSize.
124      * @return int
125      */

126     public int getMaxSize() {
127         return maxSize;
128     }
129
130     /**
131      * Returns the maxWidth.
132      * @return int
133      */

134     public int getMaxWidth() {
135         return maxWidth;
136     }
137
138     /**
139      * Returns the minHeight.
140      * @return int
141      */

142     public int getMinHeight() {
143         return minHeight;
144     }
145
146     /**
147      * Sets the maxHeight.
148      * @param maxHeight The maxHeight to set
149      */

150     public void setMaxHeight(int maxHeight) {
151         this.maxHeight = maxHeight;
152     }
153
154     /**
155      * Sets the maxSize.
156      * @param maxSize The maxSize to set
157      */

158     public void setMaxSize(int maxSize) {
159         this.maxSize = maxSize;
160     }
161
162     /**
163      * Sets the maxWidth.
164      * @param maxWidth The maxWidth to set
165      */

166     public void setMaxWidth(int maxWidth) {
167         this.maxWidth = maxWidth;
168     }
169
170     /**
171      * Sets the minHeight.
172      * @param minHeight The minHeight to set
173      */

174     public void setMinHeight(int minHeight) {
175         this.minHeight = minHeight;
176     }
177
178     /**
179      * Returns the parent.
180      * @return long
181      */

182     public long getParent() {
183         return parent;
184     }
185
186     /**
187      * Sets the parent.
188      * @param parent The parent to set
189      */

190     public void setParent(long parent) {
191         this.parent = parent;
192     }
193     
194     //Every Web Asset should implement this method!!!
195
public void copy(File newFile) {
196         this.setParent(newFile.getParent());
197         this.setFileName(newFile.getFileName());
198         this.setSize(newFile.getSize());
199         this.setMimeType(newFile.getMimeType());
200         this.setWidth(newFile.getWidth());
201         this.setHeight(newFile.getHeight());
202         super.copy(newFile);
203     }
204     /**
205      * Returns the mimeType.
206      * @return String
207      */

208     public String JavaDoc getMimeType() {
209         return mimeType;
210     }
211
212     /**
213      * Sets the mimeType.
214      * @param mimeType The mimeType to set
215      */

216     public void setMimeType(String JavaDoc mimeType) {
217         this.mimeType = mimeType;
218     }
219
220     /**
221      * Returns the height.
222      * @return int
223      */

224     public int getHeight() {
225         return height;
226     }
227
228     /**
229      * Returns the width.
230      * @return int
231      */

232     public int getWidth() {
233         return width;
234     }
235
236     public String JavaDoc getExtension(){
237         return UtilMethods.getFileExtension(fileName);
238         
239     }
240
241     public java.lang.String JavaDoc getNameOnly() {
242         return UtilMethods.getFileName(fileName);
243     }
244
245     /**
246      * Sets the height.
247      * @param height The height to set
248      */

249     public void setHeight(int height) {
250         this.height = height;
251     }
252
253     /**
254      * Sets the width.
255      * @param width The width to set
256      */

257     public void setWidth(int width) {
258         this.width = width;
259     }
260     
261     public int compareTo(Object JavaDoc compObject){
262
263         if(!(compObject instanceof File))return -1;
264         
265         File file = (File) compObject;
266         return (file.getFileName().compareTo(this.getFileName()));
267
268     }
269
270     /**
271      * Returns the author.
272      * @return String
273      */

274     public String JavaDoc getAuthor() {
275         return author;
276     }
277
278     /**
279      * Returns the publishDate.
280      * @return java.util.Date
281      */

282     public java.util.Date JavaDoc getPublishDate() {
283         return publishDate;
284     }
285
286     /**
287      * Sets the author.
288      * @param author The author to set
289      */

290     public void setAuthor(String JavaDoc author) {
291         this.author = author;
292     }
293
294     /**
295      * Sets the publishDate.
296      * @param publishDate The publishDate to set
297      */

298     public void setPublishDate(java.util.Date JavaDoc publishDate) {
299         this.publishDate = publishDate;
300     }
301
302     /**
303      * Returns the categories.
304      * @return String[]
305      */

306     public String JavaDoc[] getCategories() {
307         return categories;
308     }
309
310     /**
311      * Sets the categories.
312      * @param categories The categories to set
313      */

314     public void setCategories(String JavaDoc[] categories) {
315         Logger.debug(this, "\n\nFile setCategories=" + categories.length);
316         this.categories = categories;
317     }
318
319     /**
320      * This method returns a map with all the file attributes
321      */

322     public Map JavaDoc<String JavaDoc, Object JavaDoc> getMap () {
323         Map JavaDoc<String JavaDoc, Object JavaDoc> map = super.getMap();
324         map.put("parent", parent);
325         map.put("fileName", fileName);
326         map.put("extension", getExtension());
327         map.put("size", size);
328         map.put("height", height);
329         map.put("width", width);
330         map.put("maxHeight", maxHeight);
331         map.put("maxSize", maxSize);
332         map.put("publishDate", publishDate);
333         map.put("author", author);
334         map.put("maxWidth", maxWidth);
335         map.put("minHeight", minHeight);
336         map.put("categories", categories);
337         return map;
338     }
339 }
340
Popular Tags