KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > apollo > SecureFileChooser


1 /*
2 ** Apollo - Test Skeleton Toolkit for Web Start/JNLP
3 ** Copyright (c) 2001, 2002, 2003 by Gerald Bauer
4 **
5 ** This program is free software.
6 **
7 ** You may redistribute it and/or modify it under the terms of the GNU
8 ** General Public License as published by the Free Software Foundation.
9 ** Version 2 of the license should be included with this distribution in
10 ** the file LICENSE, as well as License.html. If the license is not
11 ** included with this distribution, you may find a copy at the FSF web
12 ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
13 ** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
14 **
15 ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
16 ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
17 ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
18 ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
19 ** REDISTRIBUTION OF THIS SOFTWARE.
20 **
21 */

22
23 package apollo;
24
25 import java.io.*;
26
27 public class SecureFileChooser
28 {
29    public final static int CANCEL = 2;
30    // todo: rename to SecFileChooser??
31
// SecClipboard, SecFileSrv, SecPrintSrv??
32
// SecSrvMan??
33

34    public final static int OK = 1;
35
36    private FileContents _file;
37
38    private FileOpenService _fileOpenService;
39    private FileSaveService _fileSaveService;
40    private FileContents _files[];
41
42    public SecureFileChooser()
43    {
44       _fileOpenService = ServiceManager.lookupFileOpenService();
45       _fileSaveService = ServiceManager.lookupFileSaveService();
46    }
47
48    public FileContents getFileContents()
49    {
50       // todo: rename to getFile and getFiles??
51
return _file;
52    }
53
54    public FileContents[] getMultiFileContents()
55    {
56       // todo: set a flag for multi-selection and throw an exception if not set
57
// to guard against misuse
58
return _files;
59    }
60
61    public int showOpenDialog() throws IOException
62    {
63       clear();
64       _file = _fileOpenService.openFileDialog( null, null );
65
66       if( _file == null )
67          return CANCEL;
68       else
69          return OK;
70    }
71
72    public int showSaveAsDialog( FileContents contents ) throws IOException
73    {
74       clear();
75       _file = _fileSaveService.saveAsFileDialog( null, null, contents );
76
77       if( _file == null )
78          return CANCEL;
79       else
80          return OK;
81    }
82
83    public int showSaveDialog( InputStream stream ) throws IOException
84    {
85       clear();
86       _file = _fileSaveService.saveFileDialog( null, null, stream, null );
87
88       if( _file == null )
89          return CANCEL;
90       else
91          return OK;
92    }
93
94    private void clear()
95    {
96       _file = null;
97       _files = null;
98    }
99 }
100
Popular Tags