| HeadMethodImpl.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * The contents of this file are subject to the terms of the Liferay Enterprise
5 * Subscription License ("License"). You may not use this file except in
6 * compliance with the License. You can obtain a copy of the License by
7 * contacting Liferay, Inc. See the License for the specific language governing
8 * permissions and limitations under the License, including but not limited to
9 * distribution rights of the Software.
10 *
11 *
12 *
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 }