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.portlet.tags.service.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.util.GetterUtil;
026: import com.liferay.portal.model.Company;
027: import com.liferay.portal.model.Group;
028: import com.liferay.portal.util.PortalUtil;
029: import com.liferay.portlet.tags.model.TagsAsset;
030: import com.liferay.portlet.tags.model.TagsAssetDisplay;
031: import com.liferay.portlet.tags.model.TagsAssetType;
032: import com.liferay.portlet.tags.service.base.TagsAssetServiceBaseImpl;
033: import com.liferay.util.RSSUtil;
034:
035: import com.sun.syndication.feed.synd.SyndContent;
036: import com.sun.syndication.feed.synd.SyndContentImpl;
037: import com.sun.syndication.feed.synd.SyndEntry;
038: import com.sun.syndication.feed.synd.SyndEntryImpl;
039: import com.sun.syndication.feed.synd.SyndFeed;
040: import com.sun.syndication.feed.synd.SyndFeedImpl;
041: import com.sun.syndication.io.FeedException;
042:
043: import java.io.IOException;
044:
045: import java.util.ArrayList;
046: import java.util.Date;
047: import java.util.Iterator;
048: import java.util.List;
049:
050: /**
051: * <a href="TagsAssetServiceImpl.java.html"><b><i>View Source</i></b></a>
052: *
053: * @author Brian Wing Shun Chan
054: * @author Jorge Ferrer
055: *
056: */
057: public class TagsAssetServiceImpl extends TagsAssetServiceBaseImpl {
058:
059: public void deleteAsset(long assetId) throws PortalException,
060: SystemException {
061:
062: tagsAssetLocalService.deleteAsset(assetId);
063: }
064:
065: public TagsAsset getAsset(long assetId) throws PortalException,
066: SystemException {
067:
068: return tagsAssetLocalService.getAsset(assetId);
069: }
070:
071: public String getAssetsRSS(long groupId, long[] classNameIds,
072: long[] entryIds, long[] notEntryIds, boolean andOperator,
073: String orderByCol1, String orderByCol2,
074: String orderByType1, String orderByType2,
075: boolean excludeZeroViewCount, Date publishDate,
076: Date expirationDate, int max, String type, double version,
077: String displayStyle, String feedURL, String entryURL)
078: throws PortalException, SystemException {
079:
080: Group group = groupPersistence.findByPrimaryKey(groupId);
081:
082: String name = group.getName();
083:
084: List assets = tagsAssetLocalService.getAssets(groupId,
085: classNameIds, entryIds, notEntryIds, andOperator,
086: orderByCol1, orderByCol2, orderByType1, orderByType2,
087: excludeZeroViewCount, publishDate, expirationDate, 0,
088: max);
089:
090: return exportToRSS(name, null, type, version, displayStyle,
091: feedURL, entryURL, assets);
092: }
093:
094: public TagsAssetType[] getAssetTypes(String languageId) {
095: return tagsAssetLocalService.getAssetTypes(languageId);
096: }
097:
098: public TagsAssetDisplay[] getCompanyAssetDisplays(long companyId,
099: int begin, int end, String languageId)
100: throws PortalException, SystemException {
101:
102: return tagsAssetLocalService.getCompanyAssetDisplays(companyId,
103: begin, end, languageId);
104: }
105:
106: public List getCompanyAssets(long companyId, int begin, int end)
107: throws SystemException {
108:
109: return tagsAssetLocalService.getCompanyAssets(companyId, begin,
110: end);
111: }
112:
113: public int getCompanyAssetsCount(long companyId)
114: throws SystemException {
115: return tagsAssetLocalService.getCompanyAssetsCount(companyId);
116: }
117:
118: public String getCompanyAssetsRSS(long companyId, int max,
119: String type, double version, String displayStyle,
120: String feedURL, String entryURL) throws PortalException,
121: SystemException {
122:
123: Company company = companyPersistence
124: .findByPrimaryKey(companyId);
125:
126: String name = company.getName();
127:
128: List assets = getCompanyAssets(companyId, 0, max);
129:
130: return exportToRSS(name, null, type, version, displayStyle,
131: feedURL, entryURL, assets);
132: }
133:
134: public TagsAsset incrementViewCounter(String className, long classPK)
135: throws PortalException, SystemException {
136:
137: return tagsAssetLocalService.incrementViewCounter(className,
138: classPK);
139: }
140:
141: public TagsAssetDisplay[] searchAssetDisplays(long companyId,
142: String portletId, String keywords, String languageId,
143: int begin, int end) throws PortalException, SystemException {
144:
145: return tagsAssetLocalService.searchAssetDisplays(companyId,
146: portletId, keywords, languageId, begin, end);
147: }
148:
149: public int searchAssetDisplaysCount(long companyId,
150: String portletId, String keywords, String languageId)
151: throws SystemException {
152:
153: return tagsAssetLocalService.searchAssetDisplaysCount(
154: companyId, portletId, keywords, languageId);
155: }
156:
157: public TagsAsset updateAsset(long groupId, String className,
158: long classPK, String[] entryNames, Date startDate,
159: Date endDate, Date publishDate, Date expirationDate,
160: String mimeType, String title, String description,
161: String summary, String url, int height, int width,
162: Integer priority) throws PortalException, SystemException {
163:
164: return tagsAssetLocalService.updateAsset(getUserId(), groupId,
165: className, classPK, entryNames, startDate, endDate,
166: publishDate, expirationDate, mimeType, title,
167: description, summary, url, height, width, priority);
168: }
169:
170: protected String exportToRSS(String name, String description,
171: String type, double version, String displayStyle,
172: String feedURL, String entryURL, List assets)
173: throws SystemException {
174:
175: SyndFeed syndFeed = new SyndFeedImpl();
176:
177: syndFeed.setFeedType(type + "_" + version);
178: syndFeed.setTitle(name);
179: syndFeed.setLink(feedURL);
180: syndFeed
181: .setDescription(GetterUtil.getString(description, name));
182:
183: List entries = new ArrayList();
184:
185: syndFeed.setEntries(entries);
186:
187: Iterator itr = assets.iterator();
188:
189: while (itr.hasNext()) {
190: TagsAsset asset = (TagsAsset) itr.next();
191:
192: String author = PortalUtil.getUserName(asset.getUserId(),
193: asset.getUserName());
194:
195: String link = entryURL + "assetId=" + asset.getAssetId();
196:
197: String value = asset.getSummary();
198:
199: SyndEntry syndEntry = new SyndEntryImpl();
200:
201: syndEntry.setAuthor(author);
202: syndEntry.setTitle(asset.getTitle());
203: syndEntry.setLink(link);
204: syndEntry.setPublishedDate(asset.getCreateDate());
205:
206: SyndContent syndContent = new SyndContentImpl();
207:
208: syndContent.setType("html");
209: syndContent.setValue(value);
210:
211: syndEntry.setDescription(syndContent);
212:
213: entries.add(syndEntry);
214: }
215:
216: try {
217: return RSSUtil.export(syndFeed);
218: } catch (FeedException fe) {
219: throw new SystemException(fe);
220: } catch (IOException ioe) {
221: throw new SystemException(ioe);
222: }
223: }
224:
225: }
|