001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.webdav;
022:
023: import com.liferay.portal.kernel.util.StringPool;
024: import com.liferay.portal.model.Group;
025: import com.liferay.portal.model.User;
026: import com.liferay.portal.service.GroupLocalServiceUtil;
027: import com.liferay.portal.service.UserLocalServiceUtil;
028: import com.liferay.util.dao.hibernate.QueryUtil;
029:
030: import java.util.ArrayList;
031: import java.util.Iterator;
032: import java.util.LinkedHashMap;
033: import java.util.List;
034:
035: /**
036: * <a href="BaseWebDAVStorageImpl.java.html"><b><i>View Source</i></b></a>
037: *
038: * @author Brian Wing Shun Chan
039: *
040: */
041: public abstract class BaseWebDAVStorageImpl implements WebDAVStorage {
042:
043: public String getRootPath() {
044: return _rootPath;
045: }
046:
047: public void setRootPath(String rootPath) {
048: _rootPath = rootPath;
049: }
050:
051: public List getCommunities(WebDAVRequest webDavReq)
052: throws WebDAVException {
053:
054: try {
055: LinkedHashMap groupParams = new LinkedHashMap();
056:
057: groupParams.put("usersGroups", new Long(webDavReq
058: .getUserId()));
059:
060: List communities = new ArrayList();
061:
062: Iterator itr = GroupLocalServiceUtil.search(
063: webDavReq.getCompanyId(), null, null, groupParams,
064: QueryUtil.ALL_POS, QueryUtil.ALL_POS).iterator();
065:
066: while (itr.hasNext()) {
067: Group group = (Group) itr.next();
068:
069: Resource resource = getResource(group);
070:
071: communities.add(resource);
072: }
073:
074: Group group = GroupLocalServiceUtil.getUserGroup(webDavReq
075: .getCompanyId(), webDavReq.getUserId());
076:
077: Resource resource = getResource(group);
078:
079: communities.add(resource);
080:
081: return communities;
082: } catch (Exception e) {
083: throw new WebDAVException(e);
084: }
085: }
086:
087: public boolean isAvailable(WebDAVRequest webDavReq)
088: throws WebDAVException {
089:
090: if (getResource(webDavReq) == null) {
091: return false;
092: } else {
093: return true;
094: }
095: }
096:
097: protected Resource getResource(Group group) throws WebDAVException {
098: try {
099: String parentPath = getRootPath() + StringPool.SLASH
100: + group.getCompanyId();
101:
102: String name = group.getName();
103:
104: if (group.isUser()) {
105: long userId = group.getClassPK();
106:
107: User user = UserLocalServiceUtil.getUserById(userId);
108:
109: name = user.getFullName();
110: }
111:
112: return new BaseResourceImpl(parentPath, group.getGroupId(),
113: name);
114: } catch (Exception e) {
115: throw new WebDAVException(e);
116: }
117: }
118:
119: private String _rootPath;
120:
121: }
|