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            @Override
036            public int process(WebDAVRequest webDavRequest) throws WebDAVException {
037                    WebDAVStorage storage = webDavRequest.getWebDAVStorage();
038                    HttpServletRequest request = webDavRequest.getHttpServletRequest();
039                    HttpServletResponse response = webDavRequest.getHttpServletResponse();
040                    long groupId = webDavRequest.getGroupId();
041    
042                    if (groupId != 0) {
043                            Status status = storage.makeCollection(webDavRequest);
044    
045                            if (Validator.isNotNull(status.getObject())) {
046                                    response.setHeader(
047                                            HttpHeaders.LOCATION,
048                                            PortalUtil.getPortalURL(request) +
049                                                    webDavRequest.getRootPath() + StringPool.SLASH +
050                                                            status.getObject());
051                            }
052    
053                            return status.getCode();
054                    }
055    
056                    return HttpServletResponse.SC_FORBIDDEN;
057            }
058    
059    }