Revision 40581 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.installer/org.gvsig.installer.swing/org.gvsig.installer.swing.impl/src/main/java/org/gvsig/installer/swing/impl/DefaultSwingInstallerManager.java
DefaultSwingInstallerManager.java | ||
---|---|---|
38 | 38 |
import java.net.MalformedURLException; |
39 | 39 |
import java.net.URL; |
40 | 40 |
import java.util.ArrayList; |
41 |
import java.util.Collection; |
|
42 |
import java.util.Iterator; |
|
41 | 43 |
import java.util.List; |
44 |
import java.util.ListIterator; |
|
42 | 45 |
|
43 | 46 |
import org.gvsig.i18n.Messages; |
44 | 47 |
import org.gvsig.installer.lib.api.Dependencies; |
... | ... | |
71 | 74 |
*/ |
72 | 75 |
public class DefaultSwingInstallerManager implements SwingInstallerManager { |
73 | 76 |
|
77 |
public class DefaultUrlAndLabel implements UrlAndLabel { |
|
78 |
|
|
79 |
private URL url; |
|
80 |
private String label; |
|
81 |
|
|
82 |
public DefaultUrlAndLabel(URL url, String label) { |
|
83 |
this.url = url; |
|
84 |
this.label = label; |
|
85 |
} |
|
86 |
public URL getURL() { |
|
87 |
return this.url; |
|
88 |
} |
|
89 |
|
|
90 |
public String getLabel() { |
|
91 |
return this.label; |
|
92 |
} |
|
93 |
|
|
94 |
public void setLabel(String label) { |
|
95 |
this.label = label; |
|
96 |
} |
|
97 |
@Override |
|
98 |
public String toString() { |
|
99 |
if( label == null ) { |
|
100 |
return this.url.toString(); |
|
101 |
} |
|
102 |
return this.label + " - " + this.url.toString(); |
|
103 |
} |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* |
|
108 |
* This class is for compatibility with deprecated method |
|
109 |
* List<URL> getDefaultDownloadURLs() |
|
110 |
* |
|
111 |
* @author jjdelcerro |
|
112 |
* |
|
113 |
*/ |
|
114 |
public class DefaultDownloadURLsIterator<URL> implements ListIterator<URL> { |
|
115 |
private List<UrlAndLabel> urlAndLabels; |
|
116 |
private ListIterator<UrlAndLabel> it; |
|
117 |
|
|
118 |
DefaultDownloadURLsIterator(List<UrlAndLabel> urlAndLabels, int index) { |
|
119 |
this.urlAndLabels = urlAndLabels; |
|
120 |
this.it = this.urlAndLabels.listIterator(index); |
|
121 |
} |
|
122 |
|
|
123 |
DefaultDownloadURLsIterator(List<UrlAndLabel> urlAndLabels) { |
|
124 |
this.urlAndLabels = urlAndLabels; |
|
125 |
this.it = this.urlAndLabels.listIterator(); |
|
126 |
} |
|
127 |
|
|
128 |
public boolean hasNext() { |
|
129 |
return this.it.hasNext(); |
|
130 |
} |
|
131 |
|
|
132 |
public URL next() { |
|
133 |
UrlAndLabel value = this.it.next(); |
|
134 |
if( value == null ) { |
|
135 |
return null; |
|
136 |
} |
|
137 |
return (URL) value.getURL(); |
|
138 |
} |
|
139 |
|
|
140 |
public boolean hasPrevious() { |
|
141 |
return it.hasPrevious(); |
|
142 |
} |
|
143 |
|
|
144 |
public int nextIndex() { |
|
145 |
return it.nextIndex(); |
|
146 |
} |
|
147 |
|
|
148 |
public URL previous() { |
|
149 |
UrlAndLabel value = this.it.previous(); |
|
150 |
if( value == null ) { |
|
151 |
return null; |
|
152 |
} |
|
153 |
return (URL) value.getURL(); |
|
154 |
} |
|
155 |
|
|
156 |
public int previousIndex() { |
|
157 |
return it.previousIndex(); |
|
158 |
} |
|
159 |
|
|
160 |
public void remove() { |
|
161 |
throw new UnsupportedOperationException("This is read-only"); |
|
162 |
} |
|
163 |
|
|
164 |
public void add(Object arg0) { |
|
165 |
throw new UnsupportedOperationException("This is read-only"); |
|
166 |
} |
|
167 |
|
|
168 |
public void set(Object arg0) { |
|
169 |
throw new UnsupportedOperationException("This is read-only"); |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* |
|
175 |
* This class is for compatibility with deprecated method |
|
176 |
* List<URL> getDefaultDownloadURLs() |
|
177 |
* |
|
178 |
* @author jjdelcerro |
|
179 |
* |
|
180 |
*/ |
|
181 |
public class DefaultDownloadURLs<URL> implements List<URL> { |
|
182 |
|
|
183 |
private List<UrlAndLabel> urlAndLabels; |
|
184 |
|
|
185 |
DefaultDownloadURLs(List<UrlAndLabel> urlAndLabels) { |
|
186 |
this.urlAndLabels = urlAndLabels; |
|
187 |
} |
|
188 |
|
|
189 |
public boolean add(Object url) { |
|
190 |
throw new UnsupportedOperationException("This is a read-only list"); |
|
191 |
} |
|
192 |
|
|
193 |
public void add(int arg0, Object url) { |
|
194 |
throw new UnsupportedOperationException("This is a read-only list"); |
|
195 |
} |
|
196 |
|
|
197 |
public boolean addAll(Collection arg0) { |
|
198 |
throw new UnsupportedOperationException("This is a read-only list"); |
|
199 |
} |
|
200 |
|
|
201 |
public boolean addAll(int arg0, Collection arg1) { |
|
202 |
throw new UnsupportedOperationException("This is a read-only list"); |
|
203 |
} |
|
204 |
|
|
205 |
public void clear() { |
|
206 |
throw new UnsupportedOperationException("This is a read-only list"); |
|
207 |
} |
|
208 |
|
|
209 |
public boolean contains(Object arg0) { |
|
210 |
Iterator<UrlAndLabel> it = this.urlAndLabels.iterator(); |
|
211 |
while( it.hasNext() ) { |
|
212 |
UrlAndLabel x = it.next(); |
|
213 |
if( x.getURL().equals(arg0) ) { |
|
214 |
return true; |
|
215 |
} |
|
216 |
} |
|
217 |
return false; |
|
218 |
} |
|
219 |
|
|
220 |
public boolean containsAll(Collection arg0) { |
|
221 |
throw new UnsupportedOperationException("This method is not supported"); |
|
222 |
} |
|
223 |
|
|
224 |
public URL get(int arg0) { |
|
225 |
return (URL) this.urlAndLabels.get(arg0).getURL(); |
|
226 |
} |
|
227 |
|
|
228 |
public int indexOf(Object arg0) { |
|
229 |
for( int i=0; i<this.urlAndLabels.size(); i++) { |
|
230 |
if( this.urlAndLabels.get(i).getURL().equals(arg0) ) { |
|
231 |
return i; |
|
232 |
} |
|
233 |
} |
|
234 |
return -1; |
|
235 |
} |
|
236 |
|
|
237 |
public boolean isEmpty() { |
|
238 |
return this.urlAndLabels.isEmpty(); |
|
239 |
} |
|
240 |
|
|
241 |
public Iterator iterator() { |
|
242 |
return new DefaultDownloadURLsIterator(this.urlAndLabels); |
|
243 |
} |
|
244 |
|
|
245 |
public int lastIndexOf(Object arg0) { |
|
246 |
for( int i=this.urlAndLabels.size()-1; i>=0; i--) { |
|
247 |
if( this.urlAndLabels.get(i).getURL().equals(arg0) ) { |
|
248 |
return i; |
|
249 |
} |
|
250 |
} |
|
251 |
return -1; |
|
252 |
} |
|
253 |
|
|
254 |
public ListIterator listIterator() { |
|
255 |
return new DefaultDownloadURLsIterator(this.urlAndLabels); |
|
256 |
} |
|
257 |
|
|
258 |
public ListIterator listIterator(int arg0) { |
|
259 |
return new DefaultDownloadURLsIterator(this.urlAndLabels, arg0); |
|
260 |
} |
|
261 |
|
|
262 |
public boolean remove(Object arg0) { |
|
263 |
throw new UnsupportedOperationException("This is a read-only list"); |
|
264 |
} |
|
265 |
|
|
266 |
public URL remove(int arg0) { |
|
267 |
throw new UnsupportedOperationException("This is a read-only list"); |
|
268 |
} |
|
269 |
|
|
270 |
public boolean removeAll(Collection arg0) { |
|
271 |
throw new UnsupportedOperationException("This is a read-only list"); |
|
272 |
} |
|
273 |
|
|
274 |
public boolean retainAll(Collection arg0) { |
|
275 |
throw new UnsupportedOperationException("This is a read-only list"); |
|
276 |
} |
|
277 |
|
|
278 |
public Object set(int arg0, Object arg1) { |
|
279 |
throw new UnsupportedOperationException("This is a read-only list"); |
|
280 |
} |
|
281 |
|
|
282 |
public int size() { |
|
283 |
return this.urlAndLabels.size(); |
|
284 |
} |
|
285 |
|
|
286 |
public List subList(int arg0, int arg1) { |
|
287 |
throw new UnsupportedOperationException("This method is not supported"); |
|
288 |
} |
|
289 |
|
|
290 |
public Object[] toArray() { |
|
291 |
throw new UnsupportedOperationException("This method is not supported"); |
|
292 |
} |
|
293 |
|
|
294 |
public Object[] toArray(Object[] arg0) { |
|
295 |
throw new UnsupportedOperationException("This method is not supported"); |
|
296 |
} |
|
297 |
|
|
298 |
} |
|
299 |
|
|
74 | 300 |
private static Logger logger = LoggerFactory |
75 | 301 |
.getLogger(DefaultSwingInstallerManager.class); |
76 | 302 |
|
... | ... | |
81 | 307 |
.getExtensionPointManager(); |
82 | 308 |
|
83 | 309 |
private String applicationVersion = "1.0.0"; |
84 |
private List<URL> defaultDownloadURLs = new ArrayList<URL>();
|
|
310 |
private List<UrlAndLabel> defaultDownloadURLs = new ArrayList<UrlAndLabel>();
|
|
85 | 311 |
|
86 | 312 |
public String getText(String key) { |
87 | 313 |
return Messages.getText(key); |
... | ... | |
113 | 339 |
if (defaultDownloadURLs.size() < 1) { |
114 | 340 |
return null; |
115 | 341 |
} |
116 |
return defaultDownloadURLs.get(0); |
|
342 |
return defaultDownloadURLs.get(0).getURL();
|
|
117 | 343 |
} |
118 | 344 |
|
345 |
public List<URL> getDefaultDownloadURLs() { |
|
346 |
return new DefaultDownloadURLs(this.defaultDownloadURLs); |
|
347 |
} |
|
348 |
|
|
349 |
public List<UrlAndLabel> getDefaultDownloadUrlAndLabels() { |
|
350 |
return this.defaultDownloadURLs; |
|
351 |
} |
|
352 |
|
|
119 | 353 |
public void setDefaultDownloadURL(String defaultDownloadURLs) { |
120 | 354 |
String[] urls = defaultDownloadURLs.split(";"); |
121 | 355 |
for (int i = 0; i < urls.length; i++) { |
... | ... | |
160 | 394 |
} |
161 | 395 |
|
162 | 396 |
public void addDefaultDownloadURL(URL url) { |
163 |
if( !this.defaultDownloadURLs.contains(url)) { |
|
164 |
this.defaultDownloadURLs.add(url); |
|
397 |
addDefaultDownloadURL(url,null); |
|
398 |
} |
|
399 |
|
|
400 |
public void addDefaultDownloadURL(URL url, String label) { |
|
401 |
Iterator<UrlAndLabel> it = this.defaultDownloadURLs.iterator(); |
|
402 |
while( it.hasNext() ) { |
|
403 |
DefaultUrlAndLabel value = (DefaultUrlAndLabel) it.next(); |
|
404 |
if( value.getURL().equals(url) ) { |
|
405 |
if( value.getLabel() == null ) { |
|
406 |
value.setLabel(label); |
|
407 |
} |
|
408 |
// Already exists the url, don't duplicate. |
|
409 |
return; |
|
410 |
} |
|
165 | 411 |
} |
412 |
this.defaultDownloadURLs.add( new DefaultUrlAndLabel(url, label)); |
|
166 | 413 |
} |
167 | 414 |
|
168 | 415 |
public void addDefaultDownloadURL(String url) throws MalformedURLException { |
416 |
String label = null; |
|
417 |
|
|
418 |
if( url.startsWith("#") ) { |
|
419 |
return; |
|
420 |
} |
|
169 | 421 |
Version version = getInstallerManager().createVersion(); |
170 | 422 |
String versionFormat = version.getMajor() + "." + version.getMinor() |
171 | 423 |
+ "." + version.getRevision(); |
424 |
int n = url.indexOf("##"); |
|
425 |
if( n>0 ) { |
|
426 |
label = url.substring(n+2); |
|
427 |
url = url.substring(0, n-1); |
|
428 |
} |
|
172 | 429 |
url = url.replace("$version", versionFormat); |
173 | 430 |
url = url.replace("<%Version%>", versionFormat); |
174 | 431 |
url = url.replace("$build", Integer.toString(version.getBuild())); |
175 | 432 |
url = url.replace("<%Build%>", Integer.toString(version.getBuild())); |
176 |
addDefaultDownloadURL(new URL(url)); |
|
433 |
addDefaultDownloadURL(new URL(url), label);
|
|
177 | 434 |
} |
178 | 435 |
|
179 |
public List<URL> getDefaultDownloadURLs() { |
|
180 |
return this.defaultDownloadURLs; |
|
181 |
} |
|
182 |
|
|
183 | 436 |
public InstallerManager getInstallerManager() { |
184 | 437 |
return InstallerLocator.getInstallerManager(); |
185 | 438 |
} |
Also available in: Unified diff