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.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                    if (groupId != 0) {
042                            Status status = storage.makeCollection(webDAVRequest);
043    
044                            if (Validator.isNotNull(status.getObject())) {
045                                    response.setHeader(
046                                            HttpHeaders.LOCATION,
047                                            PortalUtil.getPortalURL(request) +
048                                                    webDAVRequest.getRootPath() + StringPool.SLASH +
049                                                            status.getObject());
050                            }
051    
052                            return status.getCode();
053                    }
054    
055                    return HttpServletResponse.SC_FORBIDDEN;
056            }
057    
058    }