001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.plugin;
016    
017    import com.liferay.portal.kernel.plugin.License;
018    import com.liferay.portal.kernel.plugin.PluginPackage;
019    import com.liferay.portal.kernel.plugin.RemotePluginPackageRepository;
020    import com.liferay.portal.kernel.plugin.Screenshot;
021    import com.liferay.portal.kernel.util.GetterUtil;
022    import com.liferay.portal.kernel.util.StringBundler;
023    import com.liferay.portal.kernel.util.StringPool;
024    import com.liferay.portal.kernel.util.Validator;
025    
026    import java.io.Serializable;
027    
028    import java.util.ArrayList;
029    import java.util.Date;
030    import java.util.List;
031    import java.util.Properties;
032    
033    import org.apache.commons.lang.builder.EqualsBuilder;
034    import org.apache.commons.lang.builder.HashCodeBuilder;
035    
036    /**
037     * @author Jorge Ferrer
038     */
039    public class PluginPackageImpl
040            implements Comparable<PluginPackage>, PluginPackage, Serializable {
041    
042            public static final String STATUS_ALL = "all";
043    
044            public static final String STATUS_INSTALLATION_IN_PROCESS =
045                    "installationInProcess";
046    
047            public static final String STATUS_NEWER_VERSION_INSTALLED =
048                    "newerVersionInstalled";
049    
050            public static final String STATUS_NOT_INSTALLED = "notInstalled";
051    
052            public static final String STATUS_NOT_INSTALLED_OR_OLDER_VERSION_INSTALLED =
053                    "notInstalledOrOlderVersionInstalled";
054    
055            public static final String STATUS_OLDER_VERSION_INSTALLED =
056                    "olderVersionInstalled";
057    
058            public static final String STATUS_SAME_VERSION_INSTALLED =
059                    "sameVersionInstalled";
060    
061            public PluginPackageImpl(String moduleId) {
062                    _moduleId = ModuleId.getInstance(moduleId);
063            }
064    
065            public int compareTo(PluginPackage pluginPackage) {
066                    return getName().compareTo(pluginPackage.getName());
067            }
068    
069            public boolean equals(Object obj) {
070                    if (!(obj instanceof PluginPackage)) {
071                            return false;
072                    }
073    
074                    PluginPackage pluginPackage = (PluginPackage)obj;
075    
076                    EqualsBuilder equalsBuilder = new EqualsBuilder();
077    
078                    equalsBuilder.append(getModuleId(), pluginPackage.getModuleId());
079                    equalsBuilder.append(
080                            getRepositoryURL(), pluginPackage.getRepositoryURL());
081    
082                    return equalsBuilder.isEquals();
083            }
084    
085            public String getArtifactId() {
086                    return _moduleId.getArtifactId();
087            }
088    
089            public String getArtifactURL() {
090                    return getRepositoryURL() + _moduleId.getArtifactPath();
091            }
092    
093            public String getAuthor() {
094                    return _author;
095            }
096    
097            public String getChangeLog() {
098                    return _changeLog;
099            }
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    }