| HeadMethodImpl.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 */
14
15 package com.liferay.portal.webdav.methods;
16
17 import com.liferay.portal.webdav.Resource;
18 import com.liferay.portal.webdav.WebDAVException;
19 import com.liferay.portal.webdav.WebDAVRequest;
20 import com.liferay.portal.webdav.WebDAVStorage;
21
22 import javax.servlet.http.HttpServletResponse;
23
24 /**
25 * <a href="HeadMethodImpl.java.html"><b><i>View Source</i></b></a>
26 *
27 * @author Brian Wing Shun Chan
28 * @author Alexander Chow
29 */
30 public class HeadMethodImpl implements Method {
31
32 public int process(WebDAVRequest webDavRequest) throws WebDAVException {
33 try {
34 WebDAVStorage storage = webDavRequest.getWebDAVStorage();
35 HttpServletResponse response =
36 webDavRequest.getHttpServletResponse();
37
38 Resource resource = storage.getResource(webDavRequest);
39
40 int status = HttpServletResponse.SC_NOT_FOUND;
41
42 if (resource == null) {
43 response.sendError(
44 HttpServletResponse.SC_NOT_FOUND, webDavRequest.getPath());
45 }
46 else {
47 if (!resource.isCollection()) {
48 response.setContentLength(resource.getSize());
49 }
50
51 status = HttpServletResponse.SC_OK;
52 }
53
54 return status;
55 }
56 catch (Exception e) {
57 throw new WebDAVException(e);
58 }
59 }
60
61 }