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.kernel.plugin;
022:
023: import com.liferay.portal.kernel.util.StringPool;
024:
025: import java.util.ArrayList;
026: import java.util.HashMap;
027: import java.util.Iterator;
028: import java.util.List;
029: import java.util.Map;
030: import java.util.Properties;
031: import java.util.Set;
032: import java.util.TreeSet;
033:
034: /**
035: * <a href="RemotePluginPackageRepository.java.html"><b><i>View Source</i></b>
036: * </a>
037: *
038: * @author Jorge Ferrer
039: *
040: */
041: public class RemotePluginPackageRepository {
042:
043: public static final String LOCAL_URL = "LOCAL_URL";
044:
045: public static final String SETTING_USE_DOWNLOAD_URL = "use-download-url";
046:
047: public RemotePluginPackageRepository(String repositoryURL) {
048: _repositoryURL = repositoryURL;
049: }
050:
051: public String getRepositoryURL() {
052: return _repositoryURL;
053: }
054:
055: public List getPluginPackages() {
056: return _pluginPackages;
057: }
058:
059: public Properties getSettings() {
060: return _settings;
061: }
062:
063: public void setSettings(Properties settings) {
064: _settings = settings;
065: }
066:
067: public Set getTags() {
068: return _tags;
069: }
070:
071: public void addPluginPackage(PluginPackage pluginPackage) {
072:
073: // Avoid duplicates
074:
075: PluginPackage existingPackage = (PluginPackage) _moduleIdIndex
076: .get(pluginPackage.getModuleId());
077:
078: if (existingPackage != null) {
079: return;
080: }
081:
082: _artifactURLIndex.put(pluginPackage.getArtifactURL(),
083: pluginPackage);
084: _moduleIdIndex.put(pluginPackage.getModuleId(), pluginPackage);
085: _addToGroupAndArtifactIndex(pluginPackage.getGroupId(),
086: pluginPackage.getArtifactId(), pluginPackage);
087: _pluginPackages.add(pluginPackage);
088: _tags.addAll(pluginPackage.getTags());
089: }
090:
091: public PluginPackage findPluginByArtifactURL(String artifactURL) {
092: return (PluginPackage) _artifactURLIndex.get(artifactURL);
093: }
094:
095: public PluginPackage findPluginPackageByModuleId(String moduleId) {
096: return (PluginPackage) _moduleIdIndex.get(moduleId);
097: }
098:
099: public List findPluginsByGroupIdAndArtifactId(String groupId,
100: String artifactId) {
101:
102: return (List) _groupAndArtifactIndex.get(groupId
103: + StringPool.SLASH + artifactId);
104: }
105:
106: public void removePlugin(PluginPackage pluginPackage) {
107: _artifactURLIndex.remove(pluginPackage.getArtifactURL());
108: _moduleIdIndex.remove(pluginPackage.getModuleId());
109: _removeFromGroupAndArtifactIndex(pluginPackage.getGroupId(),
110: pluginPackage.getArtifactId(), pluginPackage
111: .getModuleId());
112: _pluginPackages.remove(pluginPackage);
113: }
114:
115: private void _addToGroupAndArtifactIndex(String groupId,
116: String artifactId, PluginPackage pluginPackage) {
117:
118: List plugins = findPluginsByGroupIdAndArtifactId(groupId,
119: artifactId);
120:
121: if (plugins == null) {
122: plugins = new ArrayList();
123:
124: _groupAndArtifactIndex.put(groupId + StringPool.SLASH
125: + artifactId, plugins);
126: }
127:
128: plugins.add(pluginPackage);
129: }
130:
131: private void _removeFromGroupAndArtifactIndex(String groupId,
132: String artifactId, String moduleId) {
133:
134: List plugins = findPluginsByGroupIdAndArtifactId(groupId,
135: artifactId);
136:
137: if (plugins != null) {
138: Iterator itr = plugins.iterator();
139:
140: while (itr.hasNext()) {
141: PluginPackage pluginPackage = (PluginPackage) itr
142: .next();
143:
144: if (pluginPackage.getModuleId().equals(moduleId)) {
145: itr.remove();
146:
147: break;
148: }
149: }
150: }
151: }
152:
153: private String _repositoryURL;
154: private Map _artifactURLIndex = new HashMap();
155: private Map _moduleIdIndex = new HashMap();
156: private Map _groupAndArtifactIndex = new HashMap();
157: private List _pluginPackages = new ArrayList();
158: private Properties _settings = null;
159: private Set _tags = new TreeSet();
160:
161: }
|