01: /*
02: JSPWiki - a JSP-based WikiWiki clone.
03:
04: Copyright (C) 2001-2002 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.methods;
21:
22: import java.io.IOException;
23: import java.io.InputStream;
24:
25: import javax.servlet.http.HttpServletRequest;
26: import javax.servlet.http.HttpServletResponse;
27:
28: import com.ecyrd.jspwiki.FileUtil;
29: import com.ecyrd.jspwiki.dav.DavPath;
30: import com.ecyrd.jspwiki.dav.DavProvider;
31: import com.ecyrd.jspwiki.dav.items.DavItem;
32:
33: /**
34: * @author jalkanen
35: *
36: * @since
37: */
38: public class GetMethod extends DavMethod {
39:
40: /**
41: *
42: */
43: public GetMethod(DavProvider provider) {
44: super (provider);
45: }
46:
47: public void execute(HttpServletRequest req,
48: HttpServletResponse res, DavPath dp) throws IOException {
49: DavItem di = m_provider.getItem(dp);
50:
51: if (di != null) {
52: String mime = di.getContentType();
53: res.setContentType(mime);
54:
55: long length = di.getLength();
56:
57: if (length >= 0) {
58: res.setContentLength((int) di.getLength());
59: }
60:
61: InputStream in = di.getInputStream();
62:
63: if (in != null) {
64: FileUtil.copyContents(in, res.getOutputStream());
65:
66: in.close();
67: } else {
68: res.sendError(HttpServletResponse.SC_NO_CONTENT); // FIXME: probably not correct
69: }
70:
71: } else {
72: res.sendError(HttpServletResponse.SC_NOT_FOUND);
73: }
74: }
75: }
|