KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > files > JahiaFile


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//
13
//
14
// JahiaFile
15
//
16
// NK 02.02.2001
17
//
18
//
19

20 package org.jahia.data.files;
21
22 import java.text.DateFormat JavaDoc;
23 import java.util.Date JavaDoc;
24
25 import org.jahia.registries.ServicesRegistry;
26 import org.jahia.services.usermanager.JahiaUser;
27 import java.io.Serializable JavaDoc;
28
29
30 /**
31  * Class JahiaFile.<br>
32  * A file item in the filemanager Application.<br>
33  *
34  * @author Khue ng
35  * @version 1.0
36  */

37 public class JahiaFile implements Serializable JavaDoc, Cloneable JavaDoc {
38
39     public static final int STATE_ACTIVE = 1;
40     public static final int STATE_BACKUP = 0;
41
42     /** the file identifier **/
43     private int m_FileID = -1;
44     /** the filemanager identifier **/
45     private int m_FilemanagerID = -1;
46     /** the folder identifier **/
47     private int m_FolderID = -1;
48     /** the upload user identifer **/
49     private String JavaDoc m_UploadUser = "";
50     /** the page id **/
51     private int m_PageID = -1;
52     /** is public or not **/
53     private int m_IsPublic = 1;
54     /** the real name of the file **/
55     private String JavaDoc m_RealName = "";
56     /** the storage name on disk **/
57     private String JavaDoc m_StorageName = "";
58     /** the last modification date **/
59     private long m_LastModifDate;
60     /** the size in bytes **/
61     private long m_Size = 0;
62     /** the content-type **/
63     private String JavaDoc m_Type ="";
64     /** the general title (short desc) **/
65     private String JavaDoc m_Title = "";
66     /** the general desc of the file **/
67     private String JavaDoc m_Descr ="";
68     /** the download Url **/
69     private String JavaDoc m_DownloadUrl ="#";
70     /** the version id **/
71     private String JavaDoc m_Version = "0";
72     /** the state **/
73     private int m_State = STATE_ACTIVE;
74
75
76     /**
77      * Constructor
78      *
79      */

80     protected JahiaFile(){
81     }
82
83     /**
84       * Constructor
85       *
86       * @param filemanagerID
87       * @param folderID
88       * @param uploadUser
89       * @param realName
90       * @param storageName
91       * @param lastModifDate
92       * @param size
93       * @param type
94       * @param title
95       * @param descr
96       * @param versionID
97       * @param state
98       */

99     public JahiaFile( int filemanagerID,
100                         int folderID,
101                         String JavaDoc uploadUser,
102                         String JavaDoc realName,
103                         String JavaDoc storageName,
104                         long lastModifDate,
105                         long size,
106                         String JavaDoc type,
107                         String JavaDoc title,
108                         String JavaDoc descr,
109                         String JavaDoc version,
110                         int state )
111     {
112         m_FilemanagerID = filemanagerID;
113         m_FolderID = folderID;
114         m_UploadUser = uploadUser;
115         m_RealName = realName;
116         m_StorageName = storageName;
117         m_LastModifDate = lastModifDate;
118         m_Size = size;
119         m_Type = type;
120         m_Title = title;
121         m_Descr = descr;
122         m_Version = version;
123         m_State = state;
124     }
125
126     public int getFileID(){
127         return m_FileID;
128     }
129
130     public void setFileID(int id){
131         m_FileID = id;
132     }
133
134     public int getFilemanagerID(){
135         return m_FilemanagerID;
136     }
137
138     public void setFilemanagerID(int id){
139         m_FilemanagerID = id;
140     }
141
142     public int getFolderID(){
143         return m_FolderID;
144     }
145
146     public void setFolderID(int id){
147         m_FolderID = id;
148     }
149
150     public String JavaDoc getUploadUser(){
151         return m_UploadUser;
152     }
153
154     public void setUploadUser(String JavaDoc name){
155         m_UploadUser = name;
156     }
157
158     public int getPageID(){
159         return m_PageID;
160     }
161
162     public void setPageID(int id){
163         m_PageID = id;
164     }
165
166     public int getPublic(){
167         return m_IsPublic;
168     }
169
170     public void setPublic(int val){
171         m_IsPublic = val;
172     }
173
174     public String JavaDoc getRealName(){
175         return m_RealName;
176     }
177
178     public void setRealName(String JavaDoc realName){
179         m_RealName = realName;
180     }
181
182     public String JavaDoc getStorageName(){
183         return m_StorageName;
184     }
185
186     public void setStorageName(String JavaDoc storageName){
187         m_StorageName = storageName;
188     }
189
190     public long getLastModifDate(){
191         return m_LastModifDate;
192     }
193
194     public void setLastModifDate(long lastModifDate){
195         m_LastModifDate = lastModifDate;
196     }
197
198     public long getSize(){
199         return m_Size;
200     }
201
202     public void setSize(long size){
203         m_Size = size;
204     }
205
206     public String JavaDoc getType(){
207         return m_Type;
208     }
209
210     public void setType(String JavaDoc type){
211         m_Type = type;
212     }
213
214     public String JavaDoc getTitle(){
215         return m_Title;
216     }
217
218     public void setTitle(String JavaDoc title){
219         m_Title = title;
220     }
221
222     public String JavaDoc getDescr(){
223         return m_Descr;
224     }
225
226     public void setDescr(String JavaDoc descr){
227         m_Descr = descr;
228     }
229
230     public String JavaDoc getVersion(){
231         return this.m_Version;
232     }
233
234     public void setVersion(String JavaDoc version){
235         this.m_Version = version;
236     }
237
238     public int getState(){
239         return this.m_State;
240     }
241
242     public void setState(int state){
243         this.m_State = state;
244     }
245
246     public String JavaDoc getDownloadUrl(){
247         return m_DownloadUrl;
248     }
249
250     public void setDownloadUrl(String JavaDoc dUrl){
251         m_DownloadUrl = dUrl;
252     }
253
254
255     // Output Representation purpose
256

257     public String JavaDoc getFormatedLastModifDate(){
258
259         String JavaDoc fmtDate = "";
260         Date JavaDoc tmpDate = new Date JavaDoc();
261         tmpDate.setTime(m_LastModifDate);
262
263         DateFormat JavaDoc dateFmt = DateFormat.getDateInstance();
264
265         fmtDate = DateFormat.getDateInstance().format(tmpDate);
266
267         return fmtDate;
268     }
269
270     public String JavaDoc getFormatedSize(){
271
272         return String.valueOf(m_Size >> 10) + " Kb";
273     }
274
275
276     public boolean isImage(){
277
278         return m_Type.startsWith("image");
279
280     }
281
282
283     public boolean isDownloadable(){
284         if ( m_StorageName == null ){
285             return false;
286         } else {
287             return (m_StorageName.trim().length()>0);
288         }
289     }
290
291
292     public String JavaDoc getUploadUsername(){
293         if ( m_UploadUser != null && m_UploadUser.length()>0 ){
294             JahiaUser user = ServicesRegistry.getInstance()
295                                             .getJahiaUserManagerService()
296                                             .lookupUser(m_UploadUser);
297             if ( user != null ){
298                 return user.getUsername();
299             }
300         }
301         return "";
302     }
303
304     public Object JavaDoc clone(){
305         JahiaFile file =
306                new JahiaFile(this.getFilemanagerID(),
307                this.getFolderID(),this.getUploadUser(),this.getRealName(),
308                this.getStorageName(),this.getLastModifDate(),this.getSize(),
309                this.getType(),this.getTitle(),this.getDescr(),this.getVersion(),this.getState());
310         file.setFileID(this.getFileID());
311         return file;
312     }
313
314 }
315
Popular Tags