001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.webdav.methods;
022:
023: import com.liferay.portal.kernel.util.StringMaker;
024: import com.liferay.portal.webdav.Resource;
025: import com.liferay.portal.webdav.WebDAVException;
026: import com.liferay.portal.webdav.WebDAVRequest;
027: import com.liferay.portal.webdav.WebDAVStorage;
028: import com.liferay.portal.webdav.WebDAVUtil;
029:
030: import javax.servlet.http.HttpServletRequest;
031: import javax.servlet.http.HttpServletResponse;
032:
033: import org.apache.commons.logging.Log;
034: import org.apache.commons.logging.LogFactory;
035:
036: /**
037: * <a href="CopyMethodImpl.java.html"><b><i>View Source</i></b></a>
038: *
039: * @author Brian Wing Shun Chan
040: * @author Alexander Chow
041: *
042: */
043: public class CopyMethodImpl implements Method {
044:
045: public int process(WebDAVRequest webDavReq) throws WebDAVException {
046: WebDAVStorage storage = webDavReq.getWebDAVStorage();
047: HttpServletRequest req = webDavReq.getHttpServletRequest();
048:
049: String destination = WebDAVUtil.getDestination(req, storage
050: .getRootPath());
051:
052: StringMaker sm = new StringMaker();
053:
054: if (_log.isInfoEnabled()) {
055: sm.append("Destination is " + destination);
056: }
057:
058: int status = HttpServletResponse.SC_FORBIDDEN;
059:
060: if ((!destination.equals(webDavReq.getPath()))
061: && (WebDAVUtil.getGroupId(destination) == webDavReq
062: .getGroupId())) {
063:
064: Resource resource = storage.getResource(webDavReq);
065:
066: if (resource == null) {
067: status = HttpServletResponse.SC_NOT_FOUND;
068: } else if (resource.isCollection()) {
069: boolean overwrite = WebDAVUtil.isOverwrite(req);
070: long depth = WebDAVUtil.getDepth(req);
071:
072: if (_log.isInfoEnabled()) {
073: sm.append(", overwrite is " + overwrite);
074: sm.append(", depth is " + depth);
075:
076: _log.info(sm.toString());
077: }
078:
079: status = storage.copyCollectionResource(webDavReq,
080: resource, destination, overwrite, depth);
081: } else {
082: boolean overwrite = WebDAVUtil.isOverwrite(req);
083:
084: if (_log.isInfoEnabled()) {
085: sm.append(", overwrite is " + overwrite);
086:
087: _log.info(sm.toString());
088: }
089:
090: status = storage.copySimpleResource(webDavReq,
091: resource, destination, overwrite);
092: }
093: }
094:
095: return status;
096: }
097:
098: private static Log _log = LogFactory.getLog(CopyMethodImpl.class);
099:
100: }
|