KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > filemanager > JahiaFilemanagerService


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
// JahiaFilemanagerService
15
//
16
// NK 02.02.2001
17
//
18
//
19

20 package org.jahia.services.filemanager;
21
22
23 import org.jahia.data.JahiaDOMObject;
24 import org.jahia.data.files.JahiaFile;
25 import org.jahia.data.files.JahiaFileField;
26 import org.jahia.exceptions.JahiaException;
27 import org.jahia.exceptions.JahiaInitializationException;
28 import org.jahia.params.ParamBean;
29 import org.jahia.services.JahiaService;
30 import org.jahia.services.sites.JahiaSite;
31 import org.jahia.services.usermanager.JahiaUser;
32 import org.jahia.settings.SettingsBean;
33 import org.jahia.tools.files.FileUpload;
34
35 import javax.servlet.ServletContext JavaDoc;
36 import javax.servlet.ServletException JavaDoc;
37 import javax.servlet.http.HttpServletRequest JavaDoc;
38 import javax.servlet.http.HttpServletResponse JavaDoc;
39 import java.io.File JavaDoc;
40 import java.io.IOException JavaDoc;
41 import java.util.Vector JavaDoc;
42
43
44 /**
45  * Abstract class JahiaFilemanagerService
46  * Handle files stored on disk.
47  *
48  * @author Khue ng
49  * @version 1.0
50  */

51 public abstract class JahiaFilemanagerService extends JahiaService {
52
53
54     /**
55      * init
56      * NK 31.10.2000
57      * NK 18.11.2000 setting passed through parameters
58      *
59      * @param JahiaPrivateSettings jSettings
60      */

61     public abstract void init (SettingsBean jSettings)
62             throws JahiaInitializationException;
63
64
65     //--------------------------------------------------------------------------
66
//
67
// Jahia Context Section
68
//
69
//--------------------------------------------------------------------------
70

71
72     /**
73      * @param siteID
74      * @param pageID
75      * @param bothPublic
76      *
77      * @return Vector of available files
78      */

79     public abstract Vector JavaDoc getFilesByPage (int siteID, int pageID, boolean publicFile);
80
81     /**
82      * Change the field value with new file ID
83      *
84      * @param int fieldID
85      * @param int fileID
86      */

87     public abstract void changeFile (int fieldID, int fileID)
88             throws JahiaException;
89
90     //--------------------------------------------------------------------------
91
//
92
// Disk Storage Section
93
//
94
//--------------------------------------------------------------------------
95

96
97     /**
98      * Get the File Repository Root Path
99      */

100     public abstract String JavaDoc getFileRepositoryRootPath ();
101
102
103     /**
104      * Set the FileRepositoryRootPath
105      *
106      * @param path the FileRepositoryRootPath
107      */

108     protected abstract void setFileRepositoryRootPath (String JavaDoc path);
109
110
111     /**
112      * Get the Dir Prefix Name
113      */

114     public abstract String JavaDoc getDirPrefixName ();
115
116
117     /**
118      * Set the Dir Prefix Name
119      *
120      * @param path the prefixName
121      */

122     public abstract void setDirPrefixName (String JavaDoc prefixName);
123
124     /**
125      * @throws ServletException
126      * @throws IOException
127      */

128     public abstract File getRealFile (JahiaFile jahiaFile);
129
130     /**
131      * Handle file download
132      *
133      * @throws ServletException
134      * @throws IOException
135      */

136     public abstract boolean handleFileDownload (
137             HttpServletRequest JavaDoc req,
138             HttpServletResponse JavaDoc res,
139             int fileID, String JavaDoc versionID
140             );
141
142
143     /**
144      * Delete a file from disk
145      *
146      * @param JahiaFile the abstract file
147      */

148     public abstract boolean deleteFile (JahiaFile fileItem);
149
150
151     /**
152      * Get the File Upload Max Size
153      */

154     public abstract int getFileUploadMaxSize ();
155
156
157     /**
158      * Set the FileUploadMaxSize
159      *
160      * @param maxSize the file Upload Max Size
161      */

162     public abstract void setFileUploadMaxSize (int maxSize);
163
164
165     /**
166      * Create a new directory in the File Repository Root Directory<br>
167      * The Directory name is randomly generated
168      *
169      * @return the abstract File for the created directory else null on error
170      *
171      * @author Khue ng
172      */

173     public abstract File createDirectory ();
174
175
176     /**
177      * Create a new directory in the File Repository Root Directory for a gived site<br>
178      * The Directory name is randomly generated
179      *
180      * @return the abstract File for the created directory else null on error
181      *
182      * @author Khue ng
183      */

184     public abstract File createDirectory (JahiaSite site);
185
186
187     /**
188      * Create a new directory in the File Repository Root Directory<br>
189      *
190      * @param dirName The name of the directory to create
191      * @param overwrite if true overwrite existing directory with same name
192      *
193      * @return the abstract File for the created directory else null on error
194      */

195     public abstract File createDirectory (String JavaDoc dirName, boolean overwrite);
196
197     /**
198      * return a FileUpload Handler object
199      * Files uploaded are stored in a temporary directory with a random generated name
200      *
201      * @param context ServletContext
202      * @param req HttpServletRequest
203      *
204      * @return a FileUpload object or null
205      *
206      * @throws ServletException
207      * @throws IOException
208      */

209     public abstract FileUpload getFileUploadHandler (
210             ServletContext JavaDoc context,
211             HttpServletRequest JavaDoc req
212             ) throws ServletException JavaDoc, IOException JavaDoc;
213
214
215     /**
216      * Handle file upload of new files, save them in the filemanager assotiated with
217      * the current JahiaID
218      *
219      * @throws ServletException
220      * @throws IOException
221      */

222     public abstract int handleFileUpload (
223             ParamBean jParams,
224             FileUpload fupload,
225             int folderID,
226             String JavaDoc fileTitle,
227             String JavaDoc uploadUser,
228             int isPublic
229
230             ) throws ServletException JavaDoc, IOException JavaDoc, JahiaException;
231
232
233     /**
234      * Create a copy a a JahiaFile
235      *
236      * @return the id of the new file or -1 on error
237      *
238      * @throws ServletException
239      * @throws IOException
240      */

241     public abstract int copyJahiaFile (JahiaFile jahiaFile,
242                                        ParamBean jParams,
243                                        String JavaDoc fileTitle,
244                                        int isPublic,
245                                        String JavaDoc filePrefixName)
246             throws ServletException JavaDoc, IOException JavaDoc, JahiaException;
247
248     //--------------------------------------------------------------------------
249
//
250
//
251
// Jahia Filemanager DB Handling Section
252
//
253
//
254
//--------------------------------------------------------------------------
255

256
257     /**
258      * create a filemanager for a gived owner
259      */

260     public abstract boolean createFilemanager (int ownerID);
261
262     /**
263      * Delete a filemanager and all its contents
264      */

265     public abstract boolean deleteFilemanager (JahiaUser user, int ownerID)
266             throws JahiaException;
267
268
269     /**
270      * Method getFilemanager<br>
271      * Return a filemanager
272      *
273      * @param filemanagerID the filemanager id
274      *
275      * @return filemanager or null
276      */

277     public abstract Filemanager getFilemanager (int filemanagerID);
278
279     /**
280      * Method getFilemanagerByOwner<br>
281      * Return a filemanager
282      *
283      * @param filemanagerID the filemanager id
284      *
285      * @return filemanager or null
286      */

287     public abstract Filemanager getFilemanagerByOwner (int ownerID);
288
289
290
291     //--------------------------------------------------------------------------
292
//
293
//
294
// File DB Handling Section
295
//
296
//
297
//--------------------------------------------------------------------------
298

299
300     /**
301      * @param the file object to create
302      *
303      * @return the fileID or -1 on errors
304      */

305     public abstract int insertFileDB (JahiaFileField aFile) throws JahiaException;
306
307     /**
308      * Insert new row in jahia_filemgr_files table
309      *
310      * @param the file object to create
311      *
312      * @return the fileID of the new file or -1 on error
313      */

314     public abstract int insertFileDB (JahiaFile aFile) throws JahiaException;
315
316     /**
317      * Update a row in jahia_filemgr_files table
318      *
319      * @param a file object
320      * @param oldVersion
321      *
322      * @return true if no exception occurs
323      */

324     public abstract boolean updateFileDB (JahiaFile aFile, String JavaDoc oldVersion);
325
326     /**
327      * Delete a row in jahia_filemgr_files table
328      *
329      * @param fileID
330      *
331      * @return false on any error else true
332      */

333     public abstract boolean deleteFileDB (int fileID);
334
335     /**
336      * Delete all row in jahia_filemgr_files table for a given file ID and a version
337      *
338      * @param fileID
339      * @param version
340      *
341      * @return false on any error else true
342      */

343     public abstract boolean deleteFileDB (int fileID, String JavaDoc version);
344
345     /**
346      * Method getFile
347      * Return a file object looking at it's id and state = 1 ( active )
348      *
349      * @param file id
350      *
351      * @return a file object else null
352      */

353     public abstract JahiaFile getFileDB (int fileID, String JavaDoc versionID);
354
355     /**
356      * Method getFile
357      * Return a file object looking at it's id
358      *
359      * @param file id
360      *
361      * @return a file object else null
362      */

363     public abstract JahiaFile getFileDB (int fileID);
364
365
366     /**
367      * Method getFiles
368      * Return a Vectors of Files objects depending of a sql where condition
369      *
370      * @param sqlWhere
371      *
372      * @return a Vector of Files object else null
373      */

374     public abstract Vector JavaDoc getFilesDB (String JavaDoc sqlWhere);
375
376     /**
377      * Method getFilesByFolder
378      * Return a Vector of files for a gived folderID
379      *
380      * @param folder id
381      * @param orderSql an optional sql order command
382      *
383      * @return a Vector of link objects else null
384      */

385     public abstract Vector JavaDoc getFilesByFolderDB (int folderID, String JavaDoc orderSql);
386
387
388     /**
389      * delete all files in a gived folder
390      *
391      * @param folderID
392      *
393      * @return the false on error
394      */

395     public abstract boolean deleteFilesDB (int folderID) throws JahiaException;
396
397
398     //--------------------------------------------------------------------------
399
//
400
//
401
// Folder DB Section
402
//
403
//
404
//--------------------------------------------------------------------------
405

406
407     /**
408      * Method getFilemanager<br>
409      * Return a filemanager
410      *
411      * @param filemanagerID the filemanager id
412      *
413      * @return filemanager or null
414      */

415     public abstract Folder getFolderByFile (int fileID);
416
417
418     /**
419      * Method getFolder<br>
420      * Return a folder
421      *
422      * @param folderID the folder id
423      *
424      * @return folder or null
425      */

426     public abstract Folder getFolder (int folderID);
427
428
429     //--------------------------------------------------------------------------
430
//
431
//
432
// DOM Representation Section
433
//
434
//
435
//--------------------------------------------------------------------------
436

437
438     //--------------------------------------------------------------------------
439
/**
440      * returns a DOM representation of the filemanager of a site
441      *
442      * @param int siteID
443      *
444      * @auhtor NK
445      */

446     public abstract JahiaDOMObject getFileMgrAsDOM (int siteID)
447             throws JahiaException;
448
449
450
451     //--------------------------------------------------------------------------
452
/**
453      * returns a DOM representation of the filemanager folders of a site
454      *
455      * @param int siteID
456      *
457      * @auhtor NK
458      */

459     public abstract JahiaDOMObject getFileMgrFoldersAsDOM (int siteID)
460             throws JahiaException;
461
462
463     //--------------------------------------------------------------------------
464
/**
465      * returns a DOM representation of the filemanager files of a site
466      *
467      * @param int siteID
468      *
469      * @auhtor NK
470      */

471     public abstract JahiaDOMObject getFileMgrFilesAsDOM (int siteID)
472             throws JahiaException;
473
474
475     //--------------------------------------------------------------------------
476
/**
477      * return a DOM document of the Filemanager file fields of a site
478      *
479      * @param int the site id
480      *
481      * @return JahiaDOMObject a DOM representation of this object
482      *
483      * @author NK
484      */

485     public abstract JahiaDOMObject getFileMgrFileFieldsAsDOM (int siteID)
486             throws JahiaException;
487
488
489 } // end Class JahiaFileRepositoryService
Popular Tags