001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }