001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.plugin;
022:
023: import com.liferay.portal.kernel.plugin.PluginPackage;
024: import com.liferay.portal.kernel.plugin.RemotePluginPackageRepository;
025: import com.liferay.portal.kernel.util.GetterUtil;
026: import com.liferay.portal.kernel.util.StringMaker;
027: import com.liferay.portal.kernel.util.StringPool;
028: import com.liferay.portal.kernel.util.Validator;
029:
030: import java.util.ArrayList;
031: import java.util.Date;
032: import java.util.List;
033: import java.util.Properties;
034:
035: import org.apache.commons.lang.builder.EqualsBuilder;
036: import org.apache.commons.lang.builder.HashCodeBuilder;
037:
038: /**
039: * <a href="PluginPackageImpl.java.html"><b><i>View Source</i></b></a>
040: *
041: * @author Jorge Ferrer
042: *
043: */
044: public class PluginPackageImpl implements Comparable, PluginPackage {
045:
046: public static final String STATUS_ALL = "all";
047:
048: public static final String STATUS_INSTALLATION_IN_PROCESS = "installationInProcess";
049:
050: public static final String STATUS_NEWER_VERSION_INSTALLED = "newerVersionInstalled";
051:
052: public static final String STATUS_NOT_INSTALLED = "notInstalled";
053:
054: public static final String STATUS_NOT_INSTALLED_OR_OLDER_VERSION_INSTALLED = "notInstalledOrOlderVersionInstalled";
055:
056: public static final String STATUS_OLDER_VERSION_INSTALLED = "olderVersionInstalled";
057:
058: public static final String STATUS_SAME_VERSION_INSTALLED = "sameVersionInstalled";
059:
060: public PluginPackageImpl(String moduleId) {
061: _moduleId = ModuleId.getInstance(moduleId);
062: }
063:
064: public String getModuleId() {
065: return _moduleId.toString();
066: }
067:
068: public String getName() {
069: return _name;
070: }
071:
072: public void setName(String name) {
073: _name = name;
074: }
075:
076: public String getVersion() {
077: return _moduleId.getVersion();
078: }
079:
080: public boolean isLaterVersionThan(PluginPackage pluginPackage) {
081: return _moduleId.isLaterVersionThan(pluginPackage.getVersion());
082: }
083:
084: public boolean isPreviousVersionThan(PluginPackage pluginPackage) {
085: return _moduleId.isPreviousVersionThan(pluginPackage
086: .getVersion());
087: }
088:
089: public boolean isSameVersionAs(PluginPackage pluginPackage) {
090: return _moduleId.isSameVersionAs(pluginPackage.getVersion());
091: }
092:
093: public String getRecommendedDeploymentContext() {
094: String context = _recommendedDeploymentContext;
095:
096: if (Validator.isNull(context)) {
097: context = _moduleId.getArtifactId();
098: }
099:
100: return context;
101: }
102:
103: public void setRecommendedDeploymentContext(
104: String recommendedDeploymentContext) {
105:
106: _recommendedDeploymentContext = recommendedDeploymentContext;
107: }
108:
109: public Date getModifiedDate() {
110: return _modifiedDate;
111: }
112:
113: public void setModifiedDate(Date modifiedDate) {
114: _modifiedDate = modifiedDate;
115: }
116:
117: public String getAuthor() {
118: return _author;
119: }
120:
121: public void setAuthor(String author) {
122: _author = author;
123: }
124:
125: public List getTypes() {
126: return _types;
127: }
128:
129: public void setTypes(List types) {
130: _types = types;
131: }
132:
133: public List getTags() {
134: return _tags;
135: }
136:
137: public void setTags(List tags) {
138: _tags = tags;
139: }
140:
141: public List getLicenses() {
142: return _licenses;
143: }
144:
145: public void setLicenses(List licenses) {
146: _licenses = licenses;
147: }
148:
149: public List getLiferayVersions() {
150: return _liferayVersions;
151: }
152:
153: public void setLiferayVersions(List liferayVersions) {
154: _liferayVersions = liferayVersions;
155: }
156:
157: public String getShortDescription() {
158: return _shortDescription;
159: }
160:
161: public void setShortDescription(String shortDescription) {
162: _shortDescription = shortDescription;
163: }
164:
165: public String getLongDescription() {
166: return _longDescription;
167: }
168:
169: public void setLongDescription(String longDescription) {
170: _longDescription = longDescription;
171: }
172:
173: public String getChangeLog() {
174: return _changeLog;
175: }
176:
177: public void setChangeLog(String changeLog) {
178: _changeLog = changeLog;
179: }
180:
181: public List getScreenshots() {
182: return _screenshots;
183: }
184:
185: public void setScreenshots(List screenshots) {
186: _screenshots = screenshots;
187: }
188:
189: public String getPageURL() {
190: return _pageURL;
191: }
192:
193: public void setPageURL(String pageURL) {
194: _pageURL = pageURL;
195: }
196:
197: public String getDownloadURL() {
198: String useDownloadURL = getRepository()
199: .getSettings()
200: .getProperty(
201: RemotePluginPackageRepository.SETTING_USE_DOWNLOAD_URL);
202:
203: if (!GetterUtil.getBoolean(useDownloadURL, true)) {
204: return getArtifactURL();
205: }
206:
207: if (Validator.isNotNull(_downloadURL)) {
208: return _downloadURL;
209: }
210:
211: return getArtifactURL();
212: }
213:
214: public void setDownloadURL(String downloadURL) {
215: _downloadURL = downloadURL;
216: }
217:
218: public RemotePluginPackageRepository getRepository() {
219: return _repository;
220: }
221:
222: public void setRepository(RemotePluginPackageRepository repository) {
223: _repository = repository;
224: }
225:
226: public String getRepositoryURL() {
227: if (_repository != null) {
228: return _repository.getRepositoryURL();
229: } else {
230: return RemotePluginPackageRepository.LOCAL_URL;
231: }
232: }
233:
234: public String getContext() {
235: return _context;
236: }
237:
238: public void setContext(String context) {
239: _context = context;
240: }
241:
242: public String getArtifactURL() {
243: return getRepositoryURL() + _moduleId.getArtifactPath();
244: }
245:
246: public String getArtifactId() {
247: return _moduleId.getArtifactId();
248: }
249:
250: public String getGroupId() {
251: return _moduleId.getGroupId();
252: }
253:
254: public String getPackageId() {
255: return _moduleId.getPackageId();
256: }
257:
258: public Properties getDeploymentSettings() {
259: return _deploymentSettings;
260: }
261:
262: public void setDeploymentSettings(Properties deploymentSettings) {
263: _deploymentSettings = deploymentSettings;
264: }
265:
266: public int compareTo(Object obj) {
267: if (!(obj instanceof PluginPackage)) {
268: return -1;
269: }
270:
271: PluginPackage pluginPackage = (PluginPackage) obj;
272:
273: return getName().compareTo(pluginPackage.getName());
274: }
275:
276: public boolean equals(Object obj) {
277: if (!(obj instanceof PluginPackage)) {
278: return false;
279: }
280:
281: PluginPackage pluginPackage = (PluginPackage) obj;
282:
283: EqualsBuilder equalsBuilder = new EqualsBuilder();
284:
285: equalsBuilder
286: .append(getModuleId(), pluginPackage.getModuleId());
287: equalsBuilder.append(getRepositoryURL(), pluginPackage
288: .getRepositoryURL());
289:
290: return equalsBuilder.isEquals();
291: }
292:
293: public int hashCode() {
294: HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
295:
296: hashCodeBuilder.append(getModuleId());
297: hashCodeBuilder.append(getRepositoryURL());
298:
299: return hashCodeBuilder.hashCode();
300: }
301:
302: public String toString() {
303: StringMaker sm = new StringMaker();
304:
305: sm.append(StringPool.SLASH);
306: sm.append(_context);
307: sm.append(StringPool.COLON);
308: sm.append(_moduleId);
309:
310: return sm.toString();
311: }
312:
313: private ModuleId _moduleId;
314: private String _recommendedDeploymentContext;
315: private String _name;
316: private Date _modifiedDate;
317: private String _author;
318: private List _types = new ArrayList();
319: private List _tags = new ArrayList();
320: private List _licenses = new ArrayList();
321: private List _liferayVersions = new ArrayList();
322: private String _shortDescription = StringPool.BLANK;
323: private String _longDescription = StringPool.BLANK;
324: private String _changeLog = StringPool.BLANK;
325: private List _screenshots = new ArrayList();
326: private String _pageURL;
327: private String _downloadURL;
328: private RemotePluginPackageRepository _repository;
329: private String _context;
330: private Properties _deploymentSettings;
331:
332: }
|