001
014
015 package com.liferay.portal.webdav;
016
017 import com.liferay.portal.kernel.util.StringPool;
018 import com.liferay.portal.kernel.webdav.BaseResourceImpl;
019 import com.liferay.portal.kernel.webdav.BaseWebDAVStorageImpl;
020 import com.liferay.portal.kernel.webdav.Resource;
021 import com.liferay.portal.kernel.webdav.WebDAVException;
022 import com.liferay.portal.kernel.webdav.WebDAVRequest;
023 import com.liferay.portal.kernel.webdav.WebDAVUtil;
024 import com.liferay.portal.model.Group;
025 import com.liferay.portal.model.User;
026 import com.liferay.portal.service.UserLocalServiceUtil;
027
028 import java.util.ArrayList;
029 import java.util.List;
030
031
034 public class CompanyWebDAVStorageImpl extends BaseWebDAVStorageImpl {
035
036 public Resource getResource(WebDAVRequest webDavRequest) {
037 String path = getRootPath() + webDavRequest.getPath();
038
039 return new BaseResourceImpl(path, StringPool.BLANK, StringPool.BLANK);
040 }
041
042 public List<Resource> getResources(WebDAVRequest webDavRequest)
043 throws WebDAVException {
044
045 try {
046 long userId = webDavRequest.getUserId();
047
048 return getResources(userId);
049 }
050 catch (Exception e) {
051 throw new WebDAVException(e);
052 }
053 }
054
055 protected List<Resource> getResources(long userId) throws Exception {
056 User user = UserLocalServiceUtil.getUserById(userId);
057
058 List<Group> groups = WebDAVUtil.getGroups(user);
059
060 List<Resource> resources = new ArrayList<Resource>(groups.size());
061
062 for (Group group : groups) {
063 String parentPath = getRootPath();
064
065 String name = group.getFriendlyURL();
066
067 name = name.substring(1);
068
069 resources.add(new BaseResourceImpl(parentPath, name, name));
070 }
071
072 return resources;
073 }
074
075 }