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