1
22
23 package com.liferay.portal.webdav;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.util.StringPool;
27 import com.liferay.portal.model.Group;
28 import com.liferay.portal.model.User;
29 import com.liferay.portal.service.GroupLocalServiceUtil;
30 import com.liferay.portal.service.LayoutLocalServiceUtil;
31 import com.liferay.portal.service.UserLocalServiceUtil;
32 import com.liferay.util.dao.hibernate.QueryUtil;
33
34 import java.util.ArrayList;
35 import java.util.Iterator;
36 import java.util.LinkedHashMap;
37 import java.util.List;
38
39
45 public abstract class BaseWebDAVStorageImpl implements WebDAVStorage {
46
47 public String getRootPath() {
48 return _rootPath;
49 }
50
51 public void setRootPath(String rootPath) {
52 _rootPath = rootPath;
53 }
54
55 public List getCommunities(WebDAVRequest webDavReq)
56 throws WebDAVException {
57
58 try {
59 LinkedHashMap groupParams = new LinkedHashMap();
60
61 groupParams.put("usersGroups", new Long(webDavReq.getUserId()));
62
63 List communities = new ArrayList();
64
65 Iterator itr = GroupLocalServiceUtil.search(
66 webDavReq.getCompanyId(), null, null, groupParams,
67 QueryUtil.ALL_POS, QueryUtil.ALL_POS).iterator();
68
69 while (itr.hasNext()) {
70 Group group = (Group)itr.next();
71
72 Resource resource = getResource(group);
73
74 communities.add(resource);
75 }
76
77 Group group = GroupLocalServiceUtil.getUserGroup(
78 webDavReq.getCompanyId(), webDavReq.getUserId());
79
80 Resource resource = getResource(group);
81
82 communities.add(resource);
83
84 return communities;
85 }
86 catch (Exception e) {
87 throw new WebDAVException(e);
88 }
89 }
90
91 public boolean isAvailable(WebDAVRequest webDavReq)
92 throws WebDAVException {
93
94 if (getResource(webDavReq) == null) {
95 return false;
96 }
97 else {
98 return true;
99 }
100 }
101
102 protected Resource getResource(Group group) throws WebDAVException {
103 try {
104 String href =
105 getRootPath() + StringPool.SLASH + group.getCompanyId() +
106 StringPool.SLASH + group.getGroupId();
107
108 String name = group.getName();
109
110 if (group.isUser()) {
111 long userId = group.getClassPK();
112
113 User user = UserLocalServiceUtil.getUserById(userId);
114
115 name = user.getFullName();
116 }
117
118 return new BaseResourceImpl(href, name, true);
119 }
120 catch (Exception e) {
121 throw new WebDAVException(e);
122 }
123 }
124
125 protected long getPlid(long groupId) throws SystemException {
126 return LayoutLocalServiceUtil.getDefaultPlid(groupId, true);
127 }
128
129 private String _rootPath;
130
131 }