KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > servlet > DownloadServlet


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.tools.admingui.servlet;
24
25 import java.io.IOException JavaDoc;
26 import java.io.BufferedInputStream JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.StringTokenizer JavaDoc;
31
32 import javax.servlet.Servlet JavaDoc;
33 import javax.servlet.ServletConfig JavaDoc;
34 import javax.servlet.ServletException JavaDoc;
35 import javax.servlet.ServletRequest JavaDoc;
36 import javax.servlet.ServletResponse JavaDoc;
37 import javax.servlet.http.HttpServlet JavaDoc;
38 import javax.servlet.http.HttpServletRequest JavaDoc;
39 import javax.servlet.http.HttpServletResponse JavaDoc;
40
41
42 /**
43  * <p> This Servlet provides the ability to download information from the
44  * Server to the client. It provides the ability to set the content type
45  * of the downloaded file, if not specified, it will attempt to guess
46  * based on the extension (if possible). It requires the
47  * {@link DownloadServlet#ContentSource} of the data to download to be
48  * specified by passing in a <code>ServletRequest</code> parameter named
49  * {@link DownloadServlet#CONTENT_SOURCE_ID}. The
50  * {@link DownloadServlet.ContentSource} provides a plugable means
51  * of obtaining data from an arbitrary source (i.e. the filesystem,
52  * generated on the fly, from some network location, etc.). The available
53  * {@link DownloadServlet.ContentSource} implemenatations must be
54  * specified via a <code>Servlet</code> init parameter named
55  * {@link DownloadServlet#CONTENT_SOURCES}.</p>
56  */

57 public class DownloadServlet extends HttpServlet JavaDoc {
58
59     /**
60      * <p> Default Constructor.</p>
61      */

62     public DownloadServlet() {
63     super();
64     }
65
66     /**
67      * <p> Servlet initialization method.</p>
68      */

69     public void init(ServletConfig JavaDoc config) throws ServletException JavaDoc {
70     super.init(config);
71
72     // Register ContentSources
73
String JavaDoc sources = config.getInitParameter(CONTENT_SOURCES);
74     if ((sources == null) || (sources.trim().length() == 0)) {
75         throw new ServletException JavaDoc("No ContentSources specified! Ensure "
76             + "at least 1 DownloadServlet.ContentSource is provided as"
77             + " a Servlet init parameter (key: " + CONTENT_SOURCES
78             + ").");
79     }
80     StringTokenizer JavaDoc tokens = new StringTokenizer JavaDoc(sources, " \t\n\r\f,;:");
81     while (tokens.hasMoreTokens()) {
82         registerContentSource(tokens.nextToken());
83     }
84     }
85
86     /**
87      * <p> This method registers the given class name as a
88      * {@link DownloadServlet#ContentSource}. This method will attempt
89      * to resolve and instantiate the class using the current
90      * classloader.</p>
91      */

92     public void registerContentSource(String JavaDoc className) {
93     // Sanity Check
94
if ((className == null) || className.trim().equals("")) {
95         return;
96     }
97
98     Class JavaDoc cls = null;
99     try {
100         cls = Class.forName(className);
101     } catch (Exception JavaDoc ex) {
102         throw new RuntimeException JavaDoc(ex);
103     }
104     registerContentSource(cls);
105     }
106
107     /**
108      * <p> This method registers the given class name as a
109      * {@link DownloadServlet#ContentSource}. This method will attempt
110      * to instantiate the class via the default constructor.</p>
111      */

112     public void registerContentSource(Class JavaDoc cls) {
113     // Create a new instance
114
DownloadServlet.ContentSource source = null;
115     try {
116         source = (DownloadServlet.ContentSource) cls.newInstance();
117     } catch (Exception JavaDoc ex) {
118         throw new RuntimeException JavaDoc(ex);
119     }
120     // Add the new instance to the registered ContentSources
121
_contentSources.put(source.getId(), source);
122     }
123
124     /**
125      * <p> This method looks up a DownloadServlet.ContentSource given its id.
126      * The {@link DownloadServlet#ContentSource} must be previously
127      * registered.</p>
128      */

129     public DownloadServlet.ContentSource getContentSource(String JavaDoc id) {
130     return _contentSources.get(id);
131     }
132
133     /**
134      * <p> This method delegates to the {@link #doPost()} method.</p>
135      */

136     public void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc {
137     doPost(request, response);
138     }
139
140     /**
141      * <p> This method is the main method for this class when used in an
142      * <code>HttpServlet</code> environment. It drives the process, which
143      * includes creating a {@link DownloadServet#Context}, choosing the
144      * appropriate {@link DownloadServlet#ContentSource}, and copying the
145      * output of the {@link DownloadServlet#ContentSource} to the
146      * <code>ServletResponse</code>'s <code>OutputStream</code>.</p>
147      */

148     public void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc {
149     // Get the Download Context
150
DownloadServlet.Context context = getDownloadContext(request, response);
151
152     // Get the ContentSource
153
ContentSource source = getContentSource(request);
154
155     // Write Content
156
writeContent(source, context);
157
158     // Clean Up
159
source.cleanUp(context);
160     }
161
162     /**
163      * <p> This method instantiates a {@link DownloadServlet.Context} and
164      * initializes it with the Servlet, ServletConfig, ServletRequest,
165      * and ServletResponse.</p>
166      */

167     protected DownloadServlet.Context getDownloadContext(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
168     DownloadServlet.Context ctx =
169         (DownloadServlet.Context) request.getAttribute(DOWNLOAD_CONTEXT);
170     if (ctx == null) {
171         ctx = new DownloadServlet.Context();
172
173         ctx.setServlet(this);
174         ctx.setServletConfig(getServletConfig());
175         ctx.setServletRequest(request);
176         request.setAttribute(DOWNLOAD_CONTEXT, ctx);
177     }
178
179     // This is done differently b/c the response may initially be null,
180
// subsequent calls may provide this information
181
ctx.setServletResponse(response);
182
183     return ctx;
184     }
185
186     /**
187      * <p> This method locates the appropriate
188      * {@link DownloadServlet#ContentSource} for this request. It uses
189      * the given <code>ServletRequest</code> to look for a
190      * <b>ServletRequest Parameter</b> named {@link #CONTENT_SOURCE_ID}.
191      * This value is used as the key when looking up registered
192      * {@link DownloadServlet#ContentSource} implementations.
193      */

194     protected DownloadServlet.ContentSource getContentSource(ServletRequest JavaDoc request) {
195     // Get the ContentSource id
196
String JavaDoc id = request.getParameter(CONTENT_SOURCE_ID);
197     if (id == null) {
198         id = getServletConfig().getInitParameter(CONTENT_SOURCE_ID);
199         if(id == null) {
200         throw new RuntimeException JavaDoc("You must provide the '"
201             + CONTENT_SOURCE_ID + "' request parameter!");
202         }
203     }
204
205     // Get the ContentSource
206
DownloadServlet.ContentSource src = getContentSource(id);
207     if (src == null) {
208         throw new RuntimeException JavaDoc("The ContentSource with id '" + id
209             + "' is not registered!");
210     }
211
212     // Return the ContentSource
213
return src;
214     }
215
216     /**
217      * <p> This method is responsible for setting the response header
218      * information.</p>
219      */

220     protected void writeHeader(DownloadServlet.ContentSource source, DownloadServlet.Context context) {
221     ServletResponse JavaDoc resp = context.getServletResponse();
222     if (!(resp instanceof HttpServletResponse JavaDoc)) {
223         // This implementation is only valid for HttpServletResponse
224
return;
225     }
226
227     // Set the "Last-Modified" Header
228
// First check context
229
long longTime = source.getLastModified(context);
230     if (longTime != -1) {
231         ((HttpServletResponse JavaDoc) resp).
232         setDateHeader("Last-Modified", longTime);
233     }
234
235     // First check CONTENT_TYPE
236
String JavaDoc contentType = (String JavaDoc) context.getAttribute(CONTENT_TYPE);
237     if (contentType == null) {
238         // Not found yet, check EXTENSION
239
String JavaDoc ext = (String JavaDoc) context.getAttribute(EXTENSION);
240         if (ext != null) {
241         contentType = mimeTypes.get(ext);
242         }
243         if (contentType == null) {
244         // Default Content-type is: application/octet-stream
245
contentType = DEFAULT_CONTENT_TYPE;
246         }
247     }
248     ((HttpServletResponse JavaDoc) resp).setHeader("Content-type", contentType);
249     }
250
251     /**
252      * <p> This method is responsible for copying the data from the given
253      * <code>InputStream</code> to the <code>ServletResponse</code>'s
254      * <code>OutputStream</code>. The <code>InputStream</code> should be
255      * the from the {@link DownloadServlet#ContentSource}.</p>
256      */

257     protected void writeContent(DownloadServlet.ContentSource source, DownloadServlet.Context context) {
258     // Get the InputStream
259
InputStream JavaDoc in = source.getInputStream(context);
260
261     // Get the OutputStream
262
ServletResponse JavaDoc resp = context.getServletResponse();
263     if(in == null) {
264         //nothing to write
265
String JavaDoc jspPage = (String JavaDoc)context.getAttribute("JSP_PAGE_SERVED");
266         if(jspPage != null && (jspPage.equals("false"))) {
267         try {
268             //Mainly to take care of javahelp2, bcz javahelp2 code needs an Exception to be thrown for FileNotFound.
269
//We may have to localize this message.
270
((HttpServletResponse JavaDoc)resp).sendError(404, "File Not Found");
271         } catch (IOException JavaDoc ex) {
272             //squelch it, just return.
273
}
274         }
275         return;
276     }
277     try {
278         javax.servlet.ServletOutputStream JavaDoc out = resp.getOutputStream();
279
280         // Get the InputStream
281
InputStream JavaDoc stream = new BufferedInputStream JavaDoc(in);
282
283         // Write the header
284
writeHeader(source, context);
285
286         // Copy the data to the ServletOutputStream
287
byte [] buf = new byte[512]; // Set our buffer at 512 bytes
288
int read = stream.read(buf, 0, 512);
289         while (read != -1) {
290         // Write data from the OutputStream to the InputStream
291
out.write(buf, 0, read);
292
293         // Read more...
294
read = stream.read(buf, 0, 512);
295         }
296
297         // Close the Stream
298
stream.close();
299     } catch (IOException JavaDoc ex) {
300         throw new RuntimeException JavaDoc(ex);
301     }
302     }
303
304
305     //////////////////////////////////////////////////////////////////////////
306
// Inner Classes
307
//////////////////////////////////////////////////////////////////////////
308

309     /**
310      * <p> Implement this interface to provide an Object that is capable of
311      * providing data to <code>DownloadServlet</code>.
312      * <code>ContentSource</code> implementations must be thread safe.
313      * The <code>DownloadServlet</code> will reuse the same instance when
314      * 2 requests are made to the same ContentSource type. Instance
315      * variables, therefore, should not be used; you may use the context
316      * to store local information.</p>
317      */

318     public static interface ContentSource {
319
320     /**
321      * <p> This method should return a unique string used to identify this
322      * <code>ContentSource</code>. This string must be specified in
323      * order to select the appropriate <code>ContentSource</code> when
324      * using the <code>DownloadServlet</code>.</p>
325      */

326     public String JavaDoc getId();
327
328     /**
329      * <p> This method is responsible for generating the content and
330      * returning an InputStream to that content. It is also
331      * responsible for setting any attribute values in the
332      * {@link DownloadServlet#Context}, such as {@link EXTENSION} or
333      * {@link CONTENT_TYPE}.</p>
334      */

335     public InputStream JavaDoc getInputStream(DownloadServlet.Context ctx);
336
337     /**
338      * <p> This method may be used to clean up any temporary resources.
339      * It will be invoked after the <code>InputStream</code> has
340      * been completely read.</p>
341      */

342     public void cleanUp(DownloadServlet.Context ctx);
343
344     /**
345      * <p> This method is responsible for returning the last modified date
346      * of the content, or -1 if not applicable. This information will
347      * be used for caching.</p>
348      */

349     public long getLastModified(DownloadServlet.Context context);
350     }
351
352
353     /**
354      * <p> This class provides information about the request that may be
355      * necessary for the <code>DownloadServlet.ContentSource</code> to
356      * provide content. The <code>DownloadServlet</code> is responsible
357      * for supplying this object to the
358      * <code>DownloadServlet.ContentSource</code>.</p>
359      */

360     public static class Context {
361
362     /**
363      * <p> The default constructor.</p>
364      */

365     public Context() {
366     }
367
368     /**
369      * <p> This method may be used to manage arbitrary information between
370      * the <code>DownloadServlet</code> and the
371      * <code>DownloadServlet.ContentSource</code>. This method
372      * retrieves an attribute.</p>
373      */

374     public Object JavaDoc getAttribute(String JavaDoc name) {
375         if (name == null) {
376         return null;
377         }
378
379         // First check the local attribute Map
380
Object JavaDoc value = _att.get(name);
381         if (value == null) {
382         // Not found, check the Request attributes...
383
value = getServletRequest().getParameter(name);
384         }
385
386         // Return the value (if any)
387
return value;
388     }
389
390     /**
391      * <p> This method may be used to manage arbitrary information between
392      * the <code>DownloadServlet</code> and the
393      * <code>DownloadServlet.ContentSource</code>. This method sets
394      * an attribute.</p>
395      */

396     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
397         if (name != null) {
398         _att.put(name, value);
399         }
400     }
401
402     /**
403      * <p> This method may be used to manage arbitrary information between
404      * the <code>DownloadServlet</code> and the
405      * <code>DownloadServlet.ContentSource</code>. This method
406      * removes an attribute.</p>
407      */

408     public void removeAttribute(String JavaDoc name) {
409         _att.remove(name);
410     }
411
412     /**
413      * <p> This returns the <code>Servlet</code> associated with the
414      * request. This may be cast to the specific <code>Servlet</code>
415      * instance, such as <code>HttpServlet</code>.</p>
416      */

417     public Servlet JavaDoc getServlet() {
418         return _servlet;
419     }
420
421     /**
422      * <p> This sets the <code>Servlet</code> associated with the
423      * request.</p>
424      */

425     protected void setServlet(Servlet JavaDoc servlet) {
426         _servlet = servlet;
427     }
428
429     /**
430      * <p> This returns the <code>ServletConfig</code>.</p>
431      */

432     public ServletConfig JavaDoc getServletConfig() {
433         return _servletConfig;
434     }
435
436     /**
437      * <p> This sets the <code>ServletConfig</code>.</p>
438      */

439     protected void setServletConfig(ServletConfig JavaDoc config) {
440         _servletConfig = config;
441     }
442
443     /**
444      * <p> This returns the <code>ServletRequest</code> associated with
445      * the request. This may be cast to the specific type, such as
446      * <code>HttpServletRequest</code>.</p>
447      */

448     public ServletRequest JavaDoc getServletRequest() {
449         return _request;
450     }
451
452     /**
453      * <p> This sets the <code>ServletRequest</code> associated with the
454      * request.</p>
455      */

456     protected void setServletRequest(ServletRequest JavaDoc request) {
457         _request = request;
458     }
459
460     /**
461      * <p> This returns the <code>ServletResponse</code> associated with
462      * the request. This may be cast to the specific type, such as
463      * <code>HttpServletResponse</code>.</p>
464      */

465     public ServletResponse JavaDoc getServletResponse() {
466         return _response;
467     }
468
469     /**
470      * <p> This sets the <code>ServletResponse</code> associated with the
471      * request.</p>
472      */

473     protected void setServletResponse(ServletResponse JavaDoc response) {
474         _response = response;
475     }
476
477
478     private Servlet JavaDoc _servlet = null;
479     private ServletConfig JavaDoc _servletConfig = null;
480     private ServletRequest JavaDoc _request = null;
481     private ServletResponse JavaDoc _response = null;
482     private Map JavaDoc<String JavaDoc, Object JavaDoc> _att = new HashMap JavaDoc<String JavaDoc, Object JavaDoc>();
483     }
484
485     /**
486      * <p> This method gets called before the doGet/doPost method. The
487      * requires us to create the {@link DownloadServlet#Context} here.
488      * However, we do not have the <code>HttpServletResponse</code> yet,
489      * so it will be null.</p>
490      */

491     protected long getLastModified(HttpServletRequest JavaDoc request) {
492     // Get the DownloadServlet Context
493
DownloadServlet.Context context = getDownloadContext(request, null);
494
495     // Get the ContentSource
496
ContentSource source = getContentSource(request);
497     
498     // Calculate the last modified date
499
return source.getLastModified(context);
500     }
501
502
503     /**
504      * HashMap to hold mimetypes by extension.
505      */

506     private static Map JavaDoc<String JavaDoc, String JavaDoc> mimeTypes =
507         new HashMap JavaDoc<String JavaDoc, String JavaDoc>(120);
508     static {
509     mimeTypes.put("aif", "audio/x-aiff");
510     mimeTypes.put("aifc", "audio/x-aiff");
511     mimeTypes.put("aiff", "audio/x-aiff");
512     mimeTypes.put("asc", "text/plain");
513     mimeTypes.put("asf", "application/x-ms-asf");
514     mimeTypes.put("asx", "application/x-ms-asf");
515     mimeTypes.put("au", "audio/basic");
516     mimeTypes.put("avi", "video/x-msvideo");
517     mimeTypes.put("bin", "application/octet-stream");
518     mimeTypes.put("bmp", "image/bmp");
519     mimeTypes.put("bwf", "audio/wav");
520     mimeTypes.put("bz2", "application/x-bzip2");
521     mimeTypes.put("c", "text/plain");
522     mimeTypes.put("cc", "text/plain");
523     mimeTypes.put("cdda", "audio/x-aiff");
524     mimeTypes.put("class", "application/octet-stream");
525     mimeTypes.put("com", "application/octet-stream");
526     mimeTypes.put("cpp", "text/plain");
527     mimeTypes.put("cpr", "image/cpr");
528     mimeTypes.put("css", "text/css");
529     mimeTypes.put("doc", "application/msword");
530     mimeTypes.put("dot", "application/msword");
531     mimeTypes.put("dtd", "text/xml");
532     mimeTypes.put("ear", "application/zip");
533     mimeTypes.put("exe", "application/octet-stream");
534     mimeTypes.put("flc", "video/flc");
535     mimeTypes.put("fm", "application/x-maker");
536     mimeTypes.put("frame", "application/x-maker");
537     mimeTypes.put("frm", "application/x-maker");
538     mimeTypes.put("h", "text/plain");
539     mimeTypes.put("hh", "text/plain");
540     mimeTypes.put("hpp", "text/plain");
541     mimeTypes.put("hqx", "application/mac-binhex40");
542     mimeTypes.put("htm", "text/html");
543     mimeTypes.put("html", "text/html");
544     mimeTypes.put("gif", "image/gif");
545     mimeTypes.put("gz", "application/x-gunzip");
546     mimeTypes.put("ico", "image/x-icon");
547     mimeTypes.put("iso", "application/octet-stream");
548     mimeTypes.put("jar", "application/zip");
549     mimeTypes.put("java", "text/plain");
550     mimeTypes.put("jnlp", "application/x-java-jnlp-file");
551     mimeTypes.put("jpeg", "image/jpeg");
552     mimeTypes.put("jpe", "image/jpeg");
553     mimeTypes.put("jpg", "image/jpeg");
554     mimeTypes.put("js", "text/x-javascript");
555     mimeTypes.put("m3u", "audio/x-mpegurl");
556     mimeTypes.put("maker", "application/x-maker");
557     mimeTypes.put("mid", "audio/midi");
558     mimeTypes.put("midi", "audio/midi");
559     mimeTypes.put("mim", "application/mime");
560     mimeTypes.put("mime", "application/mime");
561     mimeTypes.put("mov", "video/quicktime");
562     mimeTypes.put("mp2", "audio/mpeg");
563     mimeTypes.put("mp3", "audio/mpeg");
564     mimeTypes.put("mp4", "video/mpeg4");
565     mimeTypes.put("mpa", "video/mpeg");
566     mimeTypes.put("mpe", "video/mpeg");
567     mimeTypes.put("mpeg", "video/mpeg");
568     mimeTypes.put("mpg", "video/mpeg");
569     mimeTypes.put("mpga", "audio/mpeg");
570     mimeTypes.put("mpm", "video/mpeg");
571     mimeTypes.put("mpv", "video/mpeg");
572     mimeTypes.put("pdf", "application/pdf");
573     mimeTypes.put("pic", "image/x-pict");
574     mimeTypes.put("pict", "image/x-pict");
575     mimeTypes.put("pct", "image/x-pict");
576     mimeTypes.put("pl", "application/x-perl");
577     mimeTypes.put("png", "image/png");
578     mimeTypes.put("pnm", "image/x-portable-anymap");
579     mimeTypes.put("pbm", "image/x-portable-bitmap");
580     mimeTypes.put("ppm", "image/x-portable-pixmap");
581     mimeTypes.put("ps", "application/postscript");
582     mimeTypes.put("ppt", "application/vnd.ms-powerpoint");
583     mimeTypes.put("qt", "video/quicktime");
584     mimeTypes.put("ra", "application/vnd.rn-realaudio");
585     mimeTypes.put("rar", "application/zip");
586     mimeTypes.put("rf", "application/vnd.rn-realflash");
587     mimeTypes.put("ra", "audio/vnd.rn-realaudio");
588     mimeTypes.put("ram", "audio/x-pn-realaudio");
589     mimeTypes.put("rm", "application/vnd.rn-realmedia");
590     mimeTypes.put("rmm", "audio/x-pn-realaudio");
591     mimeTypes.put("rsml", "application/vnd.rn-rsml");
592     mimeTypes.put("rtf", "text/rtf");
593     mimeTypes.put("rv", "video/vnd.rn-realvideo");
594     mimeTypes.put("spl", "application/futuresplash");
595     mimeTypes.put("snd", "audio/basic");
596     mimeTypes.put("ssm", "application/smil");
597     mimeTypes.put("swf", "application/x-shockwave-flash");
598     mimeTypes.put("tar", "application/x-tar");
599     mimeTypes.put("tgz", "application/x-gtar");
600     mimeTypes.put("tif", "image/tiff");
601     mimeTypes.put("tiff", "image/tiff");
602     mimeTypes.put("txt", "text/plain");
603     mimeTypes.put("ulw", "audio/basic");
604     mimeTypes.put("war", "application/zip");
605     mimeTypes.put("wav", "audio/x-wav");
606     mimeTypes.put("wax", "application/x-ms-wax");
607     mimeTypes.put("wm", "application/x-ms-wm");
608     mimeTypes.put("wma", "application/x-ms-wma");
609     mimeTypes.put("wml", "text/wml");
610     mimeTypes.put("wmw", "application/x-ms-wmw");
611     mimeTypes.put("wrd", "application/msword");
612     mimeTypes.put("wvx", "application/x-ms-wvx");
613     mimeTypes.put("xbm", "image/x-xbitmap");
614     mimeTypes.put("xpm", "image/image/x-xpixmap");
615     mimeTypes.put("xml", "text/xml");
616     mimeTypes.put("xsl", "text/xml");
617     mimeTypes.put("xls", "application/vnd.ms-excel");
618     mimeTypes.put("zip", "application/zip");
619     mimeTypes.put("z", "application/x-compress");
620     mimeTypes.put("Z", "application/x-compress");
621     }
622
623
624     private static Map JavaDoc<String JavaDoc, DownloadServlet.ContentSource> _contentSources =
625         new HashMap JavaDoc<String JavaDoc, DownloadServlet.ContentSource>();
626
627     /**
628      * <p> This String ("downloadContext") is the name if the
629      * <b>ServletRequest Attribute</b> used to store the
630      * {@link DownloadServlet#Context} object for this request.</p>
631      */

632     public static final String JavaDoc DOWNLOAD_CONTEXT = "downloadContext";
633
634     /**
635      * <p> This String ("ContentSources") is the name if the <b>Servlet Init
636      * Parameter</b> that should be used to register all available
637      * {@link DownloadServlet#ContentSource} implementations.</p>
638      */

639     public static final String JavaDoc CONTENT_SOURCES = "ContentSources";
640
641     /**
642      * <p> This is the <b>ServletRequest Parameter</b> that should be provided
643      * to identify the <code>DownloadServlet.ContentSource</code>
644      * implementation that should be used. This value must match the
645      * value returned by the <code>DownloadServlet.ContentSource</code>
646      * implementation's <code>getId()</code> method.</p>
647      */

648     public static final String JavaDoc CONTENT_SOURCE_ID = "contentSourceId";
649
650     /**
651      * <p> The Content-type ("ContentType"). This is the
652      * {@link DownloadServlet#Context} attribute used to specify an
653      * explicit "Content-type". It may be set by the
654      * {@link DownloadServlet#ContentSource}, or may be passed in via a
655      * request parameter. If not specified, the {@link #EXTENSION} will
656      * be used. If that fails, the {@link #DEFAULT_CONTENT_TYPE} will
657      * apply.</p>
658      */

659     public static final String JavaDoc CONTENT_TYPE = "ContentType";
660
661     /**
662      * <p> The Default Content-type ("application/octet-stream").</p>
663      */

664     public static final String JavaDoc DEFAULT_CONTENT_TYPE =
665         "application/octet-stream";
666
667     /**
668      * <p> This is the {@link DownloadServlet#Context} attribute name used to
669      * specify the filename extension of the content. It is the
670      * responsibility of the {@link DownloadServlet#ContentSource} to set
671      * this value. The value should represent the filename extension of
672      * the content if it were saved to a filesystem.</p>
673      */

674     public static final String JavaDoc EXTENSION = "extension";
675 }
676
Popular Tags