001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.webdav.methods;
016    
017    import com.liferay.portal.kernel.servlet.HttpHeaders;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.kernel.webdav.Status;
021    import com.liferay.portal.kernel.webdav.WebDAVException;
022    import com.liferay.portal.kernel.webdav.WebDAVRequest;
023    import com.liferay.portal.kernel.webdav.WebDAVStorage;
024    import com.liferay.portal.util.PortalUtil;
025    
026    import javax.servlet.http.HttpServletRequest;
027    import javax.servlet.http.HttpServletResponse;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     * @author Alexander Chow
032     */
033    public class MkcolMethodImpl implements Method {
034    
035            public int process(WebDAVRequest webDavRequest) throws WebDAVException {
036                    WebDAVStorage storage = webDavRequest.getWebDAVStorage();
037                    HttpServletRequest request = webDavRequest.getHttpServletRequest();
038                    HttpServletResponse response = webDavRequest.getHttpServletResponse();
039                    long groupId = webDavRequest.getGroupId();
040    
041                    int statusCode = HttpServletResponse.SC_FORBIDDEN;
042    
043                    if (groupId != 0) {
044                            Status status = storage.makeCollection(webDavRequest);
045    
046                            if (Validator.isNotNull(status.getObject())) {
047                                    response.setHeader(
048                                            HttpHeaders.LOCATION,
049                                            PortalUtil.getPortalURL(request) +
050                                                    webDavRequest.getRootPath() + StringPool.SLASH +
051                                                            status.getObject());
052                            }
053    
054                            statusCode = status.getCode();
055                    }
056    
057                    return statusCode;
058            }
059    
060    }