source: 3thparty/jupload/src/main/java/wjhk/jupload2/context/JUploadContext.java @ 3951

Revision 3951, 11.5 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1709 - Adicao de codigo fonte java do componente jupload

Line 
1//
2// $Id: UploadPolicyFactory.java 629 2009-02-23 16:25:14Z etienne_sf $
3//
4// jupload - A file upload applet.
5// Copyright 2007 The JUpload Team
6//
7// Created: 2009-05-11
8// Creator: etienne_sf
9// Last modified: $Date: 2009-02-23 17:25:14 +0100 (lun., 23 févr. 2009) $
10//
11// This program is free software; you can redistribute it and/or modify it under
12// the terms of the GNU General Public License as published by the Free Software
13// Foundation; either version 2 of the License, or (at your option) any later
14// version. This program is distributed in the hope that it will be useful, but
15// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17// details. You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software Foundation, Inc.,
19// 675 Mass Ave, Cambridge, MA 02139, USA.
20
21package wjhk.jupload2.context;
22
23import java.awt.Cursor;
24import java.awt.Frame;
25import java.util.Vector;
26
27import javax.swing.JApplet;
28
29import wjhk.jupload2.exception.JUploadException;
30import wjhk.jupload2.gui.JUploadPanel;
31import wjhk.jupload2.gui.JUploadTextArea;
32import wjhk.jupload2.policies.DefaultUploadPolicy;
33import wjhk.jupload2.policies.UploadPolicy;
34import wjhk.jupload2.upload.helper.ByteArrayEncoderHTTP;
35
36/**
37 * This interface it used in upload policies to get information on the current
38 * Context. This context is responsible for: <DIR> <LI>Reading parameters from
39 * the environment or the applet parameters. <LI>Storing the current
40 * UploadPolicy (or null if not set yet) <LI> <LI></DIR>
41 *
42 * @author etienne_sf
43 */
44public interface JUploadContext {
45
46        /*
47         * **************************************************************************
48         * **************** VERSION MANAGEMENT
49         * *************************************************************************
50         */
51
52        /**
53         * @return The 'official' version (applet version and SVN revision)
54         */
55        public String getDetailedVersionMessage();
56
57        /**
58         * @return The applet version
59         */
60        public String getVersion();
61
62        /**
63         * @return The applet SVN revision, from which it was compiled
64         */
65        public String getSvnRevision();
66
67        /**
68         * @return Last modification date (date of last commit)
69         */
70        public String getLastModified();
71
72        /**
73         * @return Last modification date (date of last commit)
74         */
75        public String getBuildDate();
76
77        /**
78         * @return Last modification date (date of last commit)
79         */
80        public int getBuildNumber();
81
82        /*
83         * **************************************************************************
84         * **************** GUI MANAGEMENT
85         * *************************************************************************
86         */
87
88        /**
89         * Displays a given URL, in the given target. The target is meant in html
90         * &lt;A&gt; tag, and may be ignored if not relevant.
91         *
92         * @param url
93         *            The URL to display, in text format. It will be normalized
94         *            'before use'.
95         * @param success
96         *            Indicates whether the upload was a success or not.
97         */
98        public void displayURL(String url, boolean success);
99
100        /**
101         * Retrieves the current applet. This call is still used by
102         * {@link ByteArrayEncoderHTTP}, to append form variable. It will be
103         * removed, in the future.
104         *
105         * @return The current applet, or null if not running in an applet
106         */
107        public JApplet getApplet();
108
109        /**
110         * Returns the current frame. Can be used to attach Dialog, for instance.
111         *
112         * @return The current frame
113         */
114        public Frame getFrame();
115
116        /**
117         * Retrieves the current log window of this applet. This log window may
118         * visible or not depending on various applet parameter.
119         *
120         * @return the current log window of this instance.
121         * @see JUploadPanel#showOrHideLogWindow()
122         */
123        public JUploadTextArea getLogWindow();
124
125        /**
126         * Returns the mime type associated with the given file extension. As the
127         * applet may run on windows, the fileExtension is always changed to minor
128         * case, before looking for the corresponding mime type.
129         *
130         * @param fileExtension
131         *            The file extension, in any case.
132         * @return Returns the current mime type, for this extension.
133         */
134
135        public String getMimeType(String fileExtension);
136
137        /**
138         * Retrieves the current upload panel.
139         *
140         * @return the current upload panel of this instance.
141         */
142        public JUploadPanel getUploadPanel();
143
144        /**
145         * This method the current UploadPolicy, associated with the current
146         * execution context. This UploadPolicy is set once, when the application
147         * start. It can not change afterwards.
148         *
149         * @return The current UploadPolicy, or null of the uploadPolicy has not
150         *         been set yet.
151         * @throws JUploadException
152         */
153        public UploadPolicy getUploadPolicy() throws JUploadException;
154
155        /**
156         * @return The current cursor.
157         * @see UploadPolicy#setCursor(Cursor)
158         */
159        public Cursor getCursor();
160
161        /**
162         * @param cursor
163         *            The cursor to set
164         * @return The Cursor that was active, before setting the new one. It's up
165         *         to the caller to remind it, to be able to restore it if
166         *         necessary.
167         * @see UploadPolicy#setCursor(Cursor)
168         */
169        public Cursor setCursor(Cursor cursor);
170
171        /**
172         * Sets the wait cursor on the current application (applet, executable...).
173         *
174         * @return The cursor that was active before the call to this method
175         * @see UploadPolicy#setCursor(Cursor)
176         */
177        public Cursor setWaitCursor();
178
179        /**
180         * Displays a message in the status window.
181         *
182         * @param status
183         */
184        public void showStatus(String status);
185
186        /*
187         * **************************************************************************
188         * **************** PARAMETERS MANAGEMENT
189         * *************************************************************************
190         */
191
192        /**
193         * Get a String parameter value from applet properties or System properties.
194         *
195         * @param key
196         *            The name of the parameter to fetch.
197         * @param def
198         *            A default value which is used, when the specified parameter is
199         *            not set.
200         * @return The value of the applet parameter (resp. system property). If the
201         *         parameter was not specified or no such system property exists,
202         *         returns the given default value.
203         */
204        public String getParameter(String key, String def);
205
206        /**
207         * Get a String parameter value from applet properties or System properties.
208         *
209         * @param key
210         *            The parameter name
211         * @param def
212         *            The default value
213         * @return the parameter value, or the default, if the system is not set.
214         */
215        public int getParameter(String key, int def);
216
217        /**
218         * Get a String parameter value from applet properties or System properties.
219         *
220         * @param key
221         *            The parameter name
222         * @param def
223         *            The default value
224         * @return the parameter value, or the default, if the system is not set.
225         */
226        public float getParameter(String key, float def);
227
228        /**
229         * Get a String parameter value from applet properties or System properties.
230         *
231         * @param key
232         *            The parameter name
233         * @param def
234         *            The default value
235         * @return the parameter value, or the default, if the system is not set.
236         */
237        public long getParameter(String key, long def);
238
239        /**
240         * Get a boolean parameter value from applet properties or System
241         * properties.
242         *
243         * @param key
244         *            The parameter name
245         * @param def
246         *            The default value
247         * @return the parameter value, or the default, if the system is not set.
248         */
249        public boolean getParameter(String key, boolean def);
250
251        /**
252         * This function try to parse value as an integer. If value is not a correct
253         * integer, def is returned.
254         *
255         * @param value
256         *            The string value, that must be parsed
257         * @param def
258         *            The default value
259         * @return The integer value of value, or def if value is not valid.
260         */
261        public int parseInt(String value, int def);
262
263        /**
264         * This function try to parse value as a float number. If value is not a
265         * correct float, def is returned.
266         *
267         * @param value
268         *            The string value, that must be parsed
269         * @param def
270         *            The default value
271         * @return The float value of value, or def if value is not valid.
272         */
273        public float parseFloat(String value, float def);
274
275        /**
276         * This function try to parse value as a Long. If value is not a correct
277         * long, def is returned.
278         *
279         * @param value
280         *            The string value, that must be parsed
281         * @param def
282         *            The default value
283         * @return The integer value of value, or def if value is not valid.
284         */
285        public long parseLong(String value, long def);
286
287        /**
288         * This function try to parse value as a boolean. If value is not a correct
289         * boolean, def is returned.
290         *
291         * @param value
292         *            The new value for this property. If invalid, the default value
293         *            is used.
294         * @param def
295         *            The default value: used if value is invalid.
296         * @return The boolean value of value, or def if value is not a valid
297         *         boolean.
298         */
299        public boolean parseBoolean(String value, boolean def);
300
301        /*
302         * **************************************************************************
303         * **************** TECHNICAL MANAGEMENT
304         * *************************************************************************
305         */
306
307        /**
308         * This method allows to read the navigator cookies. These items will be
309         * added as headers, in the given Vector.
310         *
311         * @param headers
312         *            The headers, coming from {@link DefaultUploadPolicy}
313         */
314        public void readCookieFromNavigator(Vector<String> headers);
315
316        /**
317         * This method allows to read the navigator userAgent. It will be added as
318         * headers, in the given Vector.
319         *
320         * @param headers
321         *            The headers, coming from {@link DefaultUploadPolicy}
322         */
323        public void readUserAgentFromNavigator(Vector<String> headers);
324
325        /**
326         * Generates a valid URL, from a String. The generation may add the
327         * documentBase of the applet.
328         *
329         * @param url
330         *            A url. Can be a path relative to the current one.
331         * @return The normalized URL
332         * @throws JUploadException
333         */
334        public String normalizeURL(String url) throws JUploadException;
335
336        /**
337         * Register a callback to be executed during applet termination.
338         *
339         * @param object
340         *            The Object instance to be registered
341         * @param method
342         *            The Method of that object to be registered. The method must be
343         *            of type void and must not take any parameters and must be
344         *            public.
345         */
346        public void registerUnload(Object object, String method);
347
348        /**
349         * Runs all callback that must be called when releasing the applet.
350         */
351        public void runUnload();
352
353        /**
354         * This allow runtime modifications of properties, from javascript.
355         * Currently, this can only be used after full initialization. This method
356         * only calls the UploadPolicy.setProperty method. <BR>
357         * Ex: document.jupload.setProperty(prop, value);
358         *
359         * @param prop
360         *            The property name that must be set.
361         * @param value
362         *            The value of this property.
363         */
364        public void setProperty(String prop, String value);
365
366        /**
367         * Public method that can be called by Javascript to start upload
368         *
369         * @return Returns the upload result. See the constants defined in the
370         *         {@link JavascriptHandler} javadoc.
371         */
372        public String startUpload();
373}
Note: See TracBrowser for help on using the repository browser.