1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.plugin;
16  
17  import com.liferay.portal.kernel.plugin.License;
18  import com.liferay.portal.kernel.plugin.PluginPackage;
19  import com.liferay.portal.kernel.plugin.RemotePluginPackageRepository;
20  import com.liferay.portal.kernel.plugin.Screenshot;
21  import com.liferay.portal.kernel.util.GetterUtil;
22  import com.liferay.portal.kernel.util.StringBundler;
23  import com.liferay.portal.kernel.util.StringPool;
24  import com.liferay.portal.kernel.util.Validator;
25  
26  import java.util.ArrayList;
27  import java.util.Date;
28  import java.util.List;
29  import java.util.Properties;
30  
31  import org.apache.commons.lang.builder.EqualsBuilder;
32  import org.apache.commons.lang.builder.HashCodeBuilder;
33  
34  /**
35   * <a href="PluginPackageImpl.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Jorge Ferrer
38   */
39  public class PluginPackageImpl
40      implements Comparable<PluginPackage>, PluginPackage {
41  
42      public static final String STATUS_ALL = "all";
43  
44      public static final String STATUS_INSTALLATION_IN_PROCESS =
45          "installationInProcess";
46  
47      public static final String STATUS_NEWER_VERSION_INSTALLED =
48          "newerVersionInstalled";
49  
50      public static final String STATUS_NOT_INSTALLED = "notInstalled";
51  
52      public static final String STATUS_NOT_INSTALLED_OR_OLDER_VERSION_INSTALLED =
53          "notInstalledOrOlderVersionInstalled";
54  
55      public static final String STATUS_OLDER_VERSION_INSTALLED =
56          "olderVersionInstalled";
57  
58      public static final String STATUS_SAME_VERSION_INSTALLED =
59          "sameVersionInstalled";
60  
61      public PluginPackageImpl(String moduleId) {
62          _moduleId = ModuleId.getInstance(moduleId);
63      }
64  
65      public int compareTo(PluginPackage pluginPackage) {
66          return getName().compareTo(pluginPackage.getName());
67      }
68  
69      public boolean equals(Object obj) {
70          if (!(obj instanceof PluginPackage)) {
71              return false;
72          }
73  
74          PluginPackage pluginPackage = (PluginPackage)obj;
75  
76          EqualsBuilder equalsBuilder = new EqualsBuilder();
77  
78          equalsBuilder.append(getModuleId(), pluginPackage.getModuleId());
79          equalsBuilder.append(
80              getRepositoryURL(), pluginPackage.getRepositoryURL());
81  
82          return equalsBuilder.isEquals();
83      }
84  
85      public String getArtifactId() {
86          return _moduleId.getArtifactId();
87      }
88  
89      public String getArtifactURL() {
90          return getRepositoryURL() + _moduleId.getArtifactPath();
91      }
92  
93      public String getAuthor() {
94          return _author;
95      }
96  
97      public String getChangeLog() {
98          return _changeLog;
99      }
100 
101     public String getContext() {
102         return _context;
103     }
104 
105     public Properties getDeploymentSettings() {
106         return _deploymentSettings;
107     }
108 
109     public String getDownloadURL() {
110         String useDownloadURL = getRepository().getSettings().getProperty(
111             RemotePluginPackageRepository.SETTING_USE_DOWNLOAD_URL);
112 
113         if (!GetterUtil.getBoolean(useDownloadURL, true)) {
114             return getArtifactURL();
115         }
116 
117         if (Validator.isNotNull(_downloadURL)) {
118             return _downloadURL;
119         }
120 
121         return getArtifactURL();
122     }
123 
124     public String getGroupId() {
125         return _moduleId.getGroupId();
126     }
127 
128     public List<License> getLicenses() {
129         return _licenses;
130     }
131 
132     public List<String> getLiferayVersions() {
133         return _liferayVersions;
134     }
135 
136     public String getLongDescription() {
137         return _longDescription;
138     }
139 
140     public Date getModifiedDate() {
141         return _modifiedDate;
142     }
143 
144     public String getModuleId() {
145         return _moduleId.toString();
146     }
147 
148     public String getName() {
149         return _name;
150     }
151 
152     public String getPackageId() {
153         return _moduleId.getPackageId();
154     }
155 
156     public String getPageURL() {
157         return _pageURL;
158     }
159 
160     public String getRecommendedDeploymentContext() {
161         String context = _recommendedDeploymentContext;
162 
163         if (Validator.isNull(context)) {
164             context = _moduleId.getArtifactId();
165         }
166 
167         return context;
168     }
169 
170     public RemotePluginPackageRepository getRepository() {
171         return _repository;
172     }
173 
174     public String getRepositoryURL() {
175         if (_repository != null) {
176             return _repository.getRepositoryURL();
177         }
178         else {
179             return RemotePluginPackageRepository.LOCAL_URL;
180         }
181     }
182 
183     public List<Screenshot> getScreenshots() {
184         return _screenshots;
185     }
186 
187     public String getShortDescription() {
188         return _shortDescription;
189     }
190 
191     public List<String> getTags() {
192         return _tags;
193     }
194 
195     public List<String> getTypes() {
196         return _types;
197     }
198 
199     public String getVersion() {
200         return _moduleId.getVersion();
201     }
202 
203     public int hashCode() {
204         HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
205 
206         hashCodeBuilder.append(getModuleId());
207         hashCodeBuilder.append(getRepositoryURL());
208 
209         return hashCodeBuilder.hashCode();
210     }
211 
212     public boolean isLaterVersionThan(PluginPackage pluginPackage) {
213         return _moduleId.isLaterVersionThan(pluginPackage.getVersion());
214     }
215 
216     public boolean isPreviousVersionThan(PluginPackage pluginPackage) {
217         return _moduleId.isPreviousVersionThan(pluginPackage.getVersion());
218     }
219 
220     public boolean isSameVersionAs(PluginPackage pluginPackage) {
221         return _moduleId.isSameVersionAs(pluginPackage.getVersion());
222     }
223 
224     public void setAuthor(String author) {
225         _author = author;
226     }
227 
228     public void setChangeLog(String changeLog) {
229         _changeLog = changeLog;
230     }
231 
232     public void setContext(String context) {
233         _context = context;
234     }
235 
236     public void setDeploymentSettings(Properties deploymentSettings) {
237         _deploymentSettings = deploymentSettings;
238     }
239 
240     public void setDownloadURL(String downloadURL) {
241         _downloadURL = downloadURL;
242     }
243 
244     public void setLicenses(List<License> licenses) {
245         _licenses = licenses;
246     }
247 
248     public void setLiferayVersions(List<String> liferayVersions) {
249         _liferayVersions = liferayVersions;
250     }
251 
252     public void setLongDescription(String longDescription) {
253         _longDescription = longDescription;
254     }
255 
256     public void setModifiedDate(Date modifiedDate) {
257         _modifiedDate = modifiedDate;
258     }
259 
260     public void setName(String name) {
261         _name = name;
262     }
263 
264     public void setPageURL(String pageURL) {
265         _pageURL = pageURL;
266     }
267 
268     public void setRecommendedDeploymentContext(
269         String recommendedDeploymentContext) {
270 
271         _recommendedDeploymentContext = recommendedDeploymentContext;
272     }
273 
274     public void setRepository(RemotePluginPackageRepository repository) {
275         _repository = repository;
276     }
277 
278     public void setScreenshots(List<Screenshot> screenshots) {
279         _screenshots = screenshots;
280     }
281 
282     public void setShortDescription(String shortDescription) {
283         _shortDescription = shortDescription;
284     }
285 
286     public void setTags(List<String> tags) {
287         _tags = tags;
288     }
289 
290     public void setTypes(List<String> types) {
291         _types = types;
292     }
293 
294     public String toString() {
295         StringBundler sb = new StringBundler(4);
296 
297         sb.append(StringPool.SLASH);
298         sb.append(_context);
299         sb.append(StringPool.COLON);
300         sb.append(_moduleId);
301 
302         return sb.toString();
303     }
304 
305     private String _author;
306     private String _changeLog = StringPool.BLANK;
307     private String _context;
308     private Properties _deploymentSettings;
309     private String _downloadURL;
310     private List<License> _licenses = new ArrayList<License>();
311     private List<String> _liferayVersions = new ArrayList<String>();
312     private String _longDescription = StringPool.BLANK;
313     private Date _modifiedDate;
314     private ModuleId _moduleId;
315     private String _name;
316     private String _pageURL;
317     private String _recommendedDeploymentContext;
318     private RemotePluginPackageRepository _repository;
319     private List<Screenshot> _screenshots = new ArrayList<Screenshot>();
320     private String _shortDescription = StringPool.BLANK;
321     private List<String> _tags = new ArrayList<String>();
322     private List<String> _types = new ArrayList<String>();
323 
324 }