KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > servlet > AttachmentServlet


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.servlet;
11
12 import java.util.Map JavaDoc;
13 import org.mmbase.bridge.*;
14
15 /**
16  * Serves attachments. An attachments can be any object, as long as it has a byte[] field named
17  * 'handle'. Also the fields 'filename', 'mimetype' and 'title' can be taken into consideration by
18  * this servlet and preferably the node has also those fields.
19   *
20  * @version $Id: AttachmentServlet.java,v 1.10 2006/06/13 07:29:54 andre Exp $
21  * @author Michiel Meeuwissen
22  * @since MMBase-1.6
23  * @see HandleServlet
24  * @see ImageServlet
25  */

26 public class AttachmentServlet extends HandleServlet {
27
28
29     public String JavaDoc getServletInfo() {
30         return "Serves MMBase nodes as attachments";
31     }
32
33     protected Map JavaDoc getAssociations() {
34         Map JavaDoc a = super.getAssociations();
35         a.put("attachments", new Integer JavaDoc(50)); // Is very good in attachments (determines mime-type
36
// starting with 'attachments' builder fields),
37

38         a.put("images", new Integer JavaDoc(10)); // And also can do images (but is not aware of // icaches)
39
a.put("downloads", new Integer JavaDoc(0));
40         return a;
41     }
42
43     // just to get AttachmentServlet in the stacktrace.
44
protected final Cloud getClassCloud() {
45         return super.getClassCloud();
46     }
47
48     /**
49      * Determines the mimetype. Can be overridden.
50      */

51     protected String JavaDoc getMimeType(Node node) {
52         String JavaDoc mimeType = null;
53         if (node.getNodeManager().hasField("mimetype")) mimeType = node.getStringValue("mimetype");
54         if (mimeType == null || mimeType.equals("")) {
55             // mime-type missing, try to suppose that this is an image node, which has the mimetype
56
// as a function.
57
mimeType = node.getFunctionValue("mimetype", null).toString();
58             if (mimeType == null || mimeType.equals("")) {
59                 return super.getMimeType(node);
60             }
61         }
62         return mimeType;
63     }
64
65 }
66
Popular Tags