001    /**
002     * Copyright (c) 2000-2013 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.kernel.webdav.methods.Method;
025    import com.liferay.portal.util.PortalUtil;
026    
027    import javax.servlet.http.HttpServletRequest;
028    import javax.servlet.http.HttpServletResponse;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     * @author Alexander Chow
033     */
034    public class MkcolMethodImpl implements Method {
035    
036            @Override
037            public int process(WebDAVRequest webDAVRequest) throws WebDAVException {
038                    WebDAVStorage storage = webDAVRequest.getWebDAVStorage();
039                    HttpServletRequest request = webDAVRequest.getHttpServletRequest();
040                    HttpServletResponse response = webDAVRequest.getHttpServletResponse();
041                    long groupId = webDAVRequest.getGroupId();
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                            return status.getCode();
055                    }
056    
057                    return HttpServletResponse.SC_FORBIDDEN;
058            }
059    
060    }