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