001package jmaster.jumploader.model.api.upload;
002
003import java.awt.Image;
004import java.io.File;
005
006import jmaster.jumploader.model.api.common.IAttributeSet;
007import jmaster.jumploader.model.api.common.IListSelection;
008import jmaster.jumploader.model.api.common.ITransferProgress;
009import jmaster.jumploader.model.api.exception.UploaderException;
010
011/**
012 * IUploader
013 * 
014 * @author timur
015 */
016
017public interface IUploader {
018        //---------------------------------------------------------------
019        //      constants
020        //---------------------------------------------------------------
021        static final int STATUS_READY = 0;
022        static final int STATUS_UPLOADING = 1;
023        /**
024         * attribute name for main file
025         */
026        static final String ATTR_MAIN_FILE = "mainFile";
027        /**
028         * attribute name for image rotate angle
029         */
030        static final String ATTR_ROTATE_ANGLE = "rotateAngle";
031        //---------------------------------------------------------------
032        //      business methods
033        //---------------------------------------------------------------
034        /**
035         * shows if destroyed
036         */
037        boolean isDestroyed();
038        /**
039         * initalizer, called by main
040         */
041        void init();
042        /**
043         * add listener
044         */
045        void addListener( IUploaderListener listener );
046        /**
047         * remove listener
048         */
049        void removeListener( IUploaderListener listener );
050        /**
051         * add IUploaderAddListener
052         */
053        void addAddListener( IUploaderAddListener listener );
054        /**
055         * remove IUploaderAddListener
056         */
057        void removeAddListener( IUploaderAddListener listener );
058        /**
059         * shows whether file addition is enabled
060         */
061        boolean isFileAdditionEnabled();
062        /**
063         * set file addition is enabled
064         */
065        void setFileAdditionEnabled( boolean enabled );
066        /**
067         * shows whether file removal is enabled
068         */
069        boolean isFileRemovalEnabled();
070        /**
071         * set file removal is enabled
072         */
073        void setFileRemovalEnabled( boolean enabled );
074        /**
075         * upload file count retrieval
076         */
077        int getFileCount();
078        /**
079         * upload file retrieval
080         */
081        IUploadFile getFile( int index );
082        /**
083         * all files snapshot retrieval
084         */
085        IUploadFile[] getAllFiles();
086        /**
087         * upload file retrieval by path
088         * @return null if not found
089         */
090        IUploadFile getFileByPath( String path );
091        /**
092         * upload file count retrieval by status
093         * @param status see IUploadFile constants
094         */
095        int getFileCountByStatus( int status );
096        /**
097         * upload files retrieval by status
098         * @return array of IUploadFile or null, if no such files 
099         */
100        IUploadFile[] getFilesByStatus( int status );
101        /**
102         * index of file retrieval
103         */
104        int indexOfFile( IUploadFile uf );
105        /**
106         * all files length retrieval
107         */
108        long getFilesLength();
109        /**
110         * add upload file
111         */
112        IUploadFile addFile( String path )
113        throws UploaderException;
114        /**
115         * add multiple files
116         */
117        void addFiles(String[] paths)
118        throws UploaderException;
119        /**
120         * add upload file with predefined status
121         */
122        IUploadFile addFile( String path, int status )
123        throws UploaderException;
124        IUploadFile addFile( String path, int status, String error )
125        throws UploaderException;
126        /**
127         * remove upload file
128         */
129        void removeFile( IUploadFile uploadFile )
130        throws UploaderException;
131        /**
132         * move files to specified insert index
133         * @throws UploaderException 
134         */
135        void moveFiles( IUploadFile[] uploadFiles, int insertIndex ) 
136        throws UploaderException;
137        /**
138         * status retrieval
139         */
140        int getStatus();
141        /**
142         * ready status check
143         */
144        boolean isReady();
145        /**
146         * uploading status check
147         */
148        boolean isUploading();
149        /**
150         * upload thread count retrieval
151         */
152        int getUploadThreadCount();
153        /**
154         * upload thread retrieval
155         */
156        IUploadThread getUploadThread( int index );
157        /**
158         * start upload
159         */
160        void startUpload()
161        throws UploaderException;
162        /**
163         * stop upload
164         */
165        void stopUpload()
166        throws UploaderException;
167        /**
168         * shows whether startUpload() action is applicable
169         */
170        boolean canStartUpload();
171        /**
172         * shows whether stopUpload() action is applicable
173         */
174        boolean canStopUpload();
175        /**
176         * stop uploading specified file
177         */
178        void stopFileUpload( IUploadFile file )
179        throws UploaderException;
180        /**
181         * retry uplod of specified upload file
182         */
183        void retryFileUpload( IUploadFile file )
184        throws UploaderException;
185        /**
186         * transfer progress retrieval, valid if uploading
187         */
188        ITransferProgress getTransferProgress();
189        /**
190         * destroy
191         */
192        void destroy();
193        /**
194         * attribute set retrieval
195         */
196        IAttributeSet getAttributeSet();
197        /**
198         * selection retrieval
199         */
200        IListSelection getSelection();
201        /**
202         * upload enabled retrieval
203         */
204        boolean isUploadEnabled();
205        /**
206         * upload enabled set
207         */
208        void setUploadEnabled( boolean enabled );
209        /**
210         * check whether addition of specified file is possible
211         */
212        boolean canAddFile( String path );
213        /**
214         * update file, i.e. re-initialize existing entry from another file handle
215         * @param uploadFile an upload file to update
216         * @param file a new file handle
217         * @param preserveName shows whether old name should be preserved for upload file
218         */
219        void updateFile( IUploadFile uploadFile, File file, boolean preserveName );
220        /**
221         * update file name
222         */
223        void updateFileName(IUploadFile uploadFile, String name);
224        /**
225         * set "main file" attribute for specified file, remove from previously set
226         */
227        void setMainFile( IUploadFile uploadFile )
228        throws UploaderException;
229        /**
230         * update file status with notification issue
231         */
232        void updateFileStatus( IUploadFile file, int status );
233        /**
234         * apply transformations to the upload file 
235         */
236        void applyTransformations( IUploadFile file )
237        throws UploaderException;
238        /**
239         * notification about changed metadata
240         */
241        void metadataChanged( IUploadFile file );
242        /**
243         * check if files being added
244         */
245        boolean isAddingFiles();
246        /**
247         * interrupt adding files
248         */
249        void stopAddingFiles();
250        /**
251         * retrieve current file being added
252         */
253        IUploadFile getAddFileCurrent();
254        /**
255         * add image for upload
256         */
257        IUploadFile addImage(Image image) throws UploaderException;
258        /**
259         * add text file for upload
260         */
261        IUploadFile addText(String text) throws UploaderException;
262        /**
263         * retrieve image info for specified file
264         */
265        IImageInfo getImageInfo(IUploadFile file) throws UploaderException;
266        /**
267         * reset image info for specified file
268         */
269        void resetImageInfo(IUploadFile file) throws UploaderException;
270        //---------------------------------------------------------------
271        //      document download/edit related methods
272        //---------------------------------------------------------------
273        /**
274         * process document - first download to the temporary file, open
275         * editor, then upload back.
276         */
277        IUploadFile processDocument( String key, String downloadLocation, 
278                        String uploadLocation, String filename, String options )
279        throws UploaderException;
280        /**
281         * shows whether has downloading files
282         */
283        boolean isDownloading();
284        /**
285         * process that document again
286         */
287        void processDocument( IUploadFile file );
288        /**
289         * add download file
290         * @param remoteFile a download location (url), required.
291         * @param localFile a local file to download to (full path), temporary file will be created if null passed
292         * @param name a name to give to UploadFile (displayed to user), if null, download file name will be used
293         */
294        IUploadFile addDownload(String remoteFile, String localFile, String name);
295        
296        /**
297         * shows whether paste action is available
298         */
299        boolean isPasteEnabled();
300        
301        /**
302         * paste clipboard content
303         * @return true if pasted, false otherwise
304         */
305        boolean pasteFromClipboard();
306        //---------------------------------------------------------------
307        //      misc
308        //---------------------------------------------------------------
309        /**
310         * execute system process
311         */
312        void exec(String... args);
313        
314        /**
315         * execute system process and wait for result
316         * @return the exit value of the process. 
317         * by convention, the value 0 indicates normal termination.
318         */
319        int execAndWait(String... args);
320}