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