2 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
\r
4 * This library is free software; you can redistribute it and/or modify it under
\r
5 * the terms of the GNU Lesser General Public License as published by the Free
\r
6 * Software Foundation; either version 2.1 of the License, or (at your option)
\r
9 * This library is distributed in the hope that it will be useful, but WITHOUT
\r
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
\r
15 package com.liferay.portal.webdav.methods;
\r
17 import com.liferay.portal.kernel.webdav.Resource;
\r
18 import com.liferay.portal.kernel.webdav.WebDAVException;
\r
19 import com.liferay.portal.kernel.webdav.WebDAVRequest;
\r
20 import com.liferay.portal.kernel.webdav.WebDAVStorage;
\r
22 import javax.servlet.http.HttpServletResponse;
\r
24 import java.text.DateFormat;
\r
25 import java.text.SimpleDateFormat;
\r
26 import java.util.Locale;
\r
28 * @author Brian Wing Shun Chan
\r
29 * @author Alexander Chow
\r
31 public class HeadMethodImpl implements Method {
\r
33 private static DateFormat _modifiedDateFormatter =
\r
34 new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
\r
36 public int process(WebDAVRequest webDavRequest) throws WebDAVException {
\r
38 WebDAVStorage storage = webDavRequest.getWebDAVStorage();
\r
39 HttpServletResponse response =
\r
40 webDavRequest.getHttpServletResponse();
\r
42 Resource resource = storage.getResource(webDavRequest);
\r
44 if (resource == null) {
\r
45 return HttpServletResponse.SC_NOT_FOUND;
\r
48 if (!resource.isCollection()) {
\r
49 response.setContentLength((int)resource.getSize());
\r
50 response.setContentType(resource.getContentType());
\r
51 response.setDateHeader("Last-Modified", _modifiedDateFormatter.parse(resource.getModifiedDate()).getTime());
\r
54 response.addHeader("Translate", "F");
\r
55 return HttpServletResponse.SC_OK;
\r
57 catch (Exception e) {
\r
58 throw new WebDAVException(e);
\r