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