1
22
23 package com.liferay.portlet.tags.service.impl;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.util.GetterUtil;
28 import com.liferay.portal.model.Company;
29 import com.liferay.portal.model.Group;
30 import com.liferay.portal.util.PortalUtil;
31 import com.liferay.portlet.tags.model.TagsAsset;
32 import com.liferay.portlet.tags.model.TagsAssetDisplay;
33 import com.liferay.portlet.tags.model.TagsAssetType;
34 import com.liferay.portlet.tags.service.base.TagsAssetServiceBaseImpl;
35 import com.liferay.util.RSSUtil;
36
37 import com.sun.syndication.feed.synd.SyndContent;
38 import com.sun.syndication.feed.synd.SyndContentImpl;
39 import com.sun.syndication.feed.synd.SyndEntry;
40 import com.sun.syndication.feed.synd.SyndEntryImpl;
41 import com.sun.syndication.feed.synd.SyndFeed;
42 import com.sun.syndication.feed.synd.SyndFeedImpl;
43 import com.sun.syndication.io.FeedException;
44
45 import java.io.IOException;
46
47 import java.util.ArrayList;
48 import java.util.Date;
49 import java.util.Iterator;
50 import java.util.List;
51
52
59 public class TagsAssetServiceImpl extends TagsAssetServiceBaseImpl {
60
61 public void deleteAsset(long assetId)
62 throws PortalException, SystemException {
63
64 tagsAssetLocalService.deleteAsset(assetId);
65 }
66
67 public TagsAsset getAsset(long assetId)
68 throws PortalException, SystemException {
69
70 return tagsAssetLocalService.getAsset(assetId);
71 }
72
73 public String getAssetsRSS(
74 long groupId, long[] classNameIds, long[] entryIds,
75 long[] notEntryIds, boolean andOperator, String orderByCol1,
76 String orderByCol2, String orderByType1, String orderByType2,
77 boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
78 int max, String type, double version, String displayStyle,
79 String feedURL, String entryURL)
80 throws PortalException, SystemException {
81
82 Group group = groupPersistence.findByPrimaryKey(groupId);
83
84 String name = group.getName();
85
86 List assets = tagsAssetLocalService.getAssets(
87 groupId, classNameIds, entryIds, notEntryIds, andOperator,
88 orderByCol1, orderByCol2, orderByType1, orderByType2,
89 excludeZeroViewCount, publishDate, expirationDate, 0, max);
90
91 return exportToRSS(
92 name, null, type, version, displayStyle, feedURL, entryURL, assets);
93 }
94
95 public TagsAssetType[] getAssetTypes(String languageId) {
96 return tagsAssetLocalService.getAssetTypes(languageId);
97 }
98
99 public TagsAssetDisplay[] getCompanyAssetDisplays(
100 long companyId, int begin, int end, String languageId)
101 throws PortalException, SystemException {
102
103 return tagsAssetLocalService.getCompanyAssetDisplays(
104 companyId, begin, end, languageId);
105 }
106
107 public List getCompanyAssets(long companyId, int begin, int end)
108 throws SystemException {
109
110 return tagsAssetLocalService.getCompanyAssets(companyId, begin, end);
111 }
112
113 public int getCompanyAssetsCount(long companyId) throws SystemException {
114 return tagsAssetLocalService.getCompanyAssetsCount(companyId);
115 }
116
117 public String getCompanyAssetsRSS(
118 long companyId, int max, String type, double version,
119 String displayStyle, String feedURL, String entryURL)
120 throws PortalException, SystemException {
121
122 Company company = companyPersistence.findByPrimaryKey(companyId);
123
124 String name = company.getName();
125
126 List assets = getCompanyAssets(companyId, 0, max);
127
128 return exportToRSS(
129 name, null, type, version, displayStyle, feedURL, entryURL, assets);
130 }
131
132 public TagsAsset incrementViewCounter(String className, long classPK)
133 throws PortalException, SystemException {
134
135 return tagsAssetLocalService.incrementViewCounter(className, classPK);
136 }
137
138 public TagsAssetDisplay[] searchAssetDisplays(
139 long companyId, String portletId, String keywords,
140 String languageId, int begin, int end)
141 throws PortalException, SystemException {
142
143 return tagsAssetLocalService.searchAssetDisplays(
144 companyId, portletId, keywords, languageId, begin, end);
145 }
146
147 public int searchAssetDisplaysCount(
148 long companyId, String portletId, String keywords,
149 String languageId)
150 throws SystemException {
151
152 return tagsAssetLocalService.searchAssetDisplaysCount(
153 companyId, portletId, keywords, languageId);
154 }
155
156 public TagsAsset updateAsset(
157 long groupId, String className, long classPK, String[] entryNames,
158 Date startDate, Date endDate, Date publishDate, Date expirationDate,
159 String mimeType, String title, String description, String summary,
160 String url, int height, int width, Integer priority)
161 throws PortalException, SystemException {
162
163 return tagsAssetLocalService.updateAsset(
164 getUserId(), groupId, className, classPK, entryNames, startDate,
165 endDate, publishDate, expirationDate, mimeType, title, description,
166 summary, url, height, width, priority);
167 }
168
169 protected String exportToRSS(
170 String name, String description, String type, double version,
171 String displayStyle, String feedURL, String entryURL, List assets)
172 throws SystemException {
173
174 SyndFeed syndFeed = new SyndFeedImpl();
175
176 syndFeed.setFeedType(type + "_" + version);
177 syndFeed.setTitle(name);
178 syndFeed.setLink(feedURL);
179 syndFeed.setDescription(GetterUtil.getString(description, name));
180
181 List entries = new ArrayList();
182
183 syndFeed.setEntries(entries);
184
185 Iterator itr = assets.iterator();
186
187 while (itr.hasNext()) {
188 TagsAsset asset = (TagsAsset)itr.next();
189
190 String author = PortalUtil.getUserName(
191 asset.getUserId(), asset.getUserName());
192
193 String link = entryURL + "assetId=" + asset.getAssetId();
194
195 String value = asset.getSummary();
196
197 SyndEntry syndEntry = new SyndEntryImpl();
198
199 syndEntry.setAuthor(author);
200 syndEntry.setTitle(asset.getTitle());
201 syndEntry.setLink(link);
202 syndEntry.setPublishedDate(asset.getCreateDate());
203
204 SyndContent syndContent = new SyndContentImpl();
205
206 syndContent.setType("html");
207 syndContent.setValue(value);
208
209 syndEntry.setDescription(syndContent);
210
211 entries.add(syndEntry);
212 }
213
214 try {
215 return RSSUtil.export(syndFeed);
216 }
217 catch (FeedException fe) {
218 throw new SystemException(fe);
219 }
220 catch (IOException ioe) {
221 throw new SystemException(ioe);
222 }
223 }
224
225 }