01: /*
02: JSPWiki - a JSP-based WikiWiki clone.
03:
04: Copyright (C) 2001-2007 Janne Jalkanen (Janne.Jalkanen@iki.fi)
05:
06: This program is free software; you can redistribute it and/or modify
07: it under the terms of the GNU Lesser General Public License as published by
08: the Free Software Foundation; either version 2.1 of the License, or
09: (at your option) any later version.
10:
11: This program is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU Lesser General Public License for more details.
15:
16: You should have received a copy of the GNU Lesser General Public License
17: along with this program; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package com.ecyrd.jspwiki.dav.items;
21:
22: import java.util.Collection;
23:
24: import javax.servlet.ServletContext;
25:
26: import org.jdom.Element;
27:
28: import com.ecyrd.jspwiki.attachment.Attachment;
29: import com.ecyrd.jspwiki.dav.AttachmentDavProvider;
30: import com.ecyrd.jspwiki.dav.DavPath;
31:
32: /**
33: * Represents a DAV attachment.
34: * @author jalkanen
35: *
36: * @since
37: */
38: public class AttachmentItem extends PageDavItem {
39:
40: /**
41: * Constructs a new DAV attachment.
42: * @param provider the dav provider
43: * @param path the current dav path
44: * @param att the attachment
45: */
46: public AttachmentItem(AttachmentDavProvider provider, DavPath path,
47: Attachment att) {
48: super (provider, path, att);
49: }
50:
51: /**
52: * Returns a collection of properties for this attachment.
53: * @return the attachment properties
54: * @see com.ecyrd.jspwiki.dav.items.DavItem#getPropertySet()
55: */
56: public Collection getPropertySet() {
57: Collection set = getCommonProperties();
58:
59: set.add(new Element("getcontentlength", m_davns).setText(Long
60: .toString(getLength())));
61: set.add(new Element("getcontenttype", m_davns)
62: .setText(getContentType()));
63:
64: return set;
65: }
66:
67: public String getHref() {
68: return m_provider.getURL(m_path);
69: }
70:
71: /**
72: * Returns the content type as defined by the servlet container;
73: * or if the container cannot be found, returns "application/octet-stream".
74: * @return the content type
75: */
76: public String getContentType() {
77: ServletContext ctx = ((AttachmentDavProvider) m_provider)
78: .getEngine().getServletContext();
79:
80: if (ctx != null) {
81: String mimetype = ctx.getMimeType(m_page.getName());
82:
83: if (mimetype != null)
84: return mimetype;
85: }
86:
87: return "application/octet-stream"; // FIXME: This is not correct
88: }
89:
90: /**
91: * Returns the length of the attachment.
92: * @return the length
93: * @see com.ecyrd.jspwiki.dav.items.DavItem#getLength()
94: */
95: public long getLength() {
96: return m_page.getSize();
97: }
98: }
|