svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.installer / org.gvsig.installer.lib / org.gvsig.installer.lib.impl / src / main / java / org / gvsig / installer / lib / impl / DefaultPackageInfo.java @ 40926
History | View | Annotate | Download (22.6 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2010 {Prodevelop} {Task}
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.installer.lib.impl; |
30 |
|
31 |
import java.io.File; |
32 |
import java.io.IOException; |
33 |
import java.net.MalformedURLException; |
34 |
import java.net.URL; |
35 |
import java.security.InvalidParameterException; |
36 |
import java.util.ArrayList; |
37 |
import java.util.Iterator; |
38 |
import java.util.List; |
39 |
|
40 |
import org.gvsig.installer.lib.api.Dependencies; |
41 |
import org.gvsig.installer.lib.api.InstallerLocator; |
42 |
import org.gvsig.installer.lib.api.InstallerManager; |
43 |
import org.gvsig.installer.lib.api.InstallerManager.ARCH; |
44 |
import org.gvsig.installer.lib.api.InstallerManager.JVM; |
45 |
import org.gvsig.installer.lib.api.InstallerManager.OS; |
46 |
import org.gvsig.installer.lib.api.InstallerManager.STATE; |
47 |
import org.gvsig.installer.lib.api.PackageInfo; |
48 |
import org.gvsig.installer.lib.api.Version; |
49 |
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException; |
50 |
import org.gvsig.installer.lib.impl.info.InstallerInfoTags; |
51 |
import org.gvsig.installer.lib.impl.utils.DeleteFile; |
52 |
import org.gvsig.installer.lib.impl.utils.Download; |
53 |
import org.gvsig.installer.lib.impl.utils.SignUtil; |
54 |
import org.gvsig.tools.packageutils.StringWithAlias; |
55 |
import org.gvsig.tools.packageutils.impl.DefaultStringWithAlias; |
56 |
import org.gvsig.tools.task.SimpleTaskStatus; |
57 |
import org.slf4j.Logger; |
58 |
import org.slf4j.LoggerFactory; |
59 |
|
60 |
/**
|
61 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
62 |
*/
|
63 |
public class DefaultPackageInfo implements PackageInfo { |
64 |
|
65 |
private static final Logger LOG = LoggerFactory |
66 |
.getLogger(DefaultPackageInfo.class); |
67 |
|
68 |
private StringWithAlias code = null; |
69 |
private String name = null; |
70 |
private String description = null; |
71 |
private Version version = null; |
72 |
private boolean official; |
73 |
private List<File> auxFiles = null; |
74 |
private String antScript = null; |
75 |
private String type = "unknow"; |
76 |
private Boolean signed = false; |
77 |
private Boolean broken = false; |
78 |
|
79 |
private String state = STATE.DEVEL; |
80 |
private String operatingSystem = OS.ALL; |
81 |
private String architecture = ARCH.ALL; |
82 |
private String javaVM = JVM.J1_5; |
83 |
|
84 |
private String owner = ""; |
85 |
private URL ownerURL = null; |
86 |
private URL sources = null; |
87 |
private String gvSIGVersion = ""; |
88 |
|
89 |
private String defaultDownloadURL = null; |
90 |
|
91 |
private String modelVersion = "1.0.1"; |
92 |
private Dependencies dependencies = null; |
93 |
private List<String> categories = null; |
94 |
|
95 |
private URL webURL = null; |
96 |
|
97 |
public DefaultPackageInfo() {
|
98 |
super();
|
99 |
auxFiles = new ArrayList<File>(); |
100 |
this.version = new DefaultVersion().parse("0.0.1"); |
101 |
this.dependencies = new DefaultDependencies(); |
102 |
this.categories = new ArrayList<String>(); |
103 |
} |
104 |
|
105 |
public String getCode() { |
106 |
if( code == null ) { |
107 |
return null; |
108 |
} |
109 |
return code.toString();
|
110 |
} |
111 |
|
112 |
public StringWithAlias getAllCodes() {
|
113 |
return this.code; |
114 |
} |
115 |
|
116 |
private String getAliasAsString() { |
117 |
if( this.code == null ) { |
118 |
return ""; |
119 |
} |
120 |
StringBuffer s = new StringBuffer(); |
121 |
Iterator alias = this.code.getAlias().iterator(); |
122 |
while( alias.hasNext() ) {
|
123 |
String ss = (String) alias.next(); |
124 |
s.append(ss); |
125 |
if( alias.hasNext() ) {
|
126 |
s.append(", ");
|
127 |
} |
128 |
} |
129 |
return s.toString();
|
130 |
} |
131 |
|
132 |
public boolean hasThisCode(String code) { |
133 |
if( this.code == null ) { |
134 |
if( code == null ) { |
135 |
return true; |
136 |
} |
137 |
return false; |
138 |
} |
139 |
return this.code.equalsIgnoreCase(code); |
140 |
} |
141 |
|
142 |
public boolean hasThisCode(StringWithAlias code) { |
143 |
if( this.code == null ) { |
144 |
if( code == null ) { |
145 |
return true; |
146 |
} |
147 |
return false; |
148 |
} |
149 |
return this.code.equalsIgnoreCase(code); |
150 |
} |
151 |
|
152 |
|
153 |
public String getID() { |
154 |
String id =
|
155 |
this.getCode() + "#" + this.getVersion() |
156 |
+ "#" + this.getOperatingSystem() + "#" |
157 |
+ this.getArchitecture();
|
158 |
return id;
|
159 |
} |
160 |
|
161 |
public String getName() { |
162 |
return name;
|
163 |
} |
164 |
|
165 |
public String getDescription() { |
166 |
return description;
|
167 |
} |
168 |
|
169 |
public Version getVersion() {
|
170 |
return version;
|
171 |
} |
172 |
|
173 |
public int getBuild() { |
174 |
return this.version.getBuild(); |
175 |
} |
176 |
|
177 |
public String getState() { |
178 |
return state;
|
179 |
} |
180 |
|
181 |
public boolean isOfficial() { |
182 |
return official;
|
183 |
} |
184 |
|
185 |
public void setCode(String code) { |
186 |
if( code == null ) { |
187 |
this.code = null; |
188 |
} else {
|
189 |
this.code = new DefaultStringWithAlias(code); |
190 |
} |
191 |
} |
192 |
|
193 |
public void setName(String name) { |
194 |
this.name = name;
|
195 |
} |
196 |
|
197 |
public void setDescription(String description) { |
198 |
this.description = description;
|
199 |
} |
200 |
|
201 |
public void setVersion(String version) { |
202 |
if (version == null) { |
203 |
return;
|
204 |
} |
205 |
int prev = this.version.getBuild(); |
206 |
this.version.parse(version);
|
207 |
int curr = this.version.getBuild(); |
208 |
if (prev != 0 && curr == 0) { |
209 |
this.version.setBuild(prev);
|
210 |
} |
211 |
} |
212 |
|
213 |
public void setVersion(Version version) { |
214 |
try {
|
215 |
int prev = this.version.getBuild(); |
216 |
this.version = (Version) version.clone();
|
217 |
int curr = this.version.getBuild(); |
218 |
if (prev != 0 && curr == 0) { |
219 |
this.version.setBuild(prev);
|
220 |
} |
221 |
} catch (CloneNotSupportedException e) { |
222 |
throw new RuntimeException(e); |
223 |
} |
224 |
} |
225 |
|
226 |
public void setBuild(int build) { |
227 |
this.version.setBuild(build);
|
228 |
} |
229 |
|
230 |
public void setState(String state) { |
231 |
this.state = state;
|
232 |
} |
233 |
|
234 |
public void setOfficial(boolean official) { |
235 |
this.official = official;
|
236 |
} |
237 |
|
238 |
public String getOperatingSystem() { |
239 |
return operatingSystem;
|
240 |
} |
241 |
|
242 |
public void setOperatingSystem(String operatingSystem) { |
243 |
this.operatingSystem = operatingSystem;
|
244 |
} |
245 |
|
246 |
public String getArchitecture() { |
247 |
return architecture;
|
248 |
} |
249 |
|
250 |
public void setArchitecture(String architecture) { |
251 |
this.architecture = architecture;
|
252 |
} |
253 |
|
254 |
public String getJavaVM() { |
255 |
return javaVM;
|
256 |
} |
257 |
|
258 |
public void setJavaVM(String javaVM) { |
259 |
this.javaVM = javaVM;
|
260 |
} |
261 |
|
262 |
public String getAntScript() { |
263 |
return antScript;
|
264 |
} |
265 |
|
266 |
public void setAntScript(String antScript) { |
267 |
this.antScript = antScript;
|
268 |
} |
269 |
|
270 |
public String getType() { |
271 |
return type;
|
272 |
} |
273 |
|
274 |
public void setType(String type) { |
275 |
this.type = type;
|
276 |
} |
277 |
|
278 |
public String getGvSIGVersion() { |
279 |
return gvSIGVersion;
|
280 |
} |
281 |
|
282 |
public void setGvSIGVersion(String gvSIGVersion) { |
283 |
this.gvSIGVersion = gvSIGVersion;
|
284 |
} |
285 |
|
286 |
private URL internalGetDownloadURL() { |
287 |
if (defaultDownloadURL != null) { |
288 |
try {
|
289 |
return new URL(defaultDownloadURL); |
290 |
} catch (MalformedURLException e) { |
291 |
throw new RuntimeException( |
292 |
"Error converting to URL the package download url: "
|
293 |
+ defaultDownloadURL, e); |
294 |
} |
295 |
} |
296 |
return null; |
297 |
} |
298 |
|
299 |
public URL getDownloadURL() { |
300 |
InstallerManager manager = InstallerLocator.getInstallerManager(); |
301 |
if (manager == null) { |
302 |
return null; |
303 |
} |
304 |
return getDownloadURL(manager.getDownloadBaseURL());
|
305 |
} |
306 |
|
307 |
public URL getDownloadURL(URL baseURL) { |
308 |
try {
|
309 |
return internalGetDownloadURL();
|
310 |
} catch (RuntimeException e) { |
311 |
// The download URL in the package info is not a valid URL,
|
312 |
// so it might be a relative one.
|
313 |
// Try to create and absolute one.
|
314 |
} |
315 |
|
316 |
// Create a full URL with the base one and the download one.
|
317 |
try {
|
318 |
return new URL(baseURL, this.defaultDownloadURL); |
319 |
} catch (MalformedURLException e) { |
320 |
throw new RuntimeException( |
321 |
"Error converting to URL the package download url, "
|
322 |
+ "with the base URL: " + baseURL
|
323 |
+ ", the package download URL: " + this.defaultDownloadURL, |
324 |
e); |
325 |
} |
326 |
} |
327 |
|
328 |
public String getDownloadURLAsString() { |
329 |
return this.defaultDownloadURL; |
330 |
} |
331 |
|
332 |
public void setDownloadURL(URL defaultDownloadURL) { |
333 |
this.defaultDownloadURL = defaultDownloadURL.toString();
|
334 |
} |
335 |
|
336 |
public void setDownloadURL(String defaultDownloadURL) { |
337 |
this.defaultDownloadURL = defaultDownloadURL;
|
338 |
} |
339 |
|
340 |
public String getModelVersion() { |
341 |
return modelVersion;
|
342 |
} |
343 |
|
344 |
public void setModelVersion(String modelVersion) { |
345 |
this.modelVersion = modelVersion;
|
346 |
} |
347 |
|
348 |
public String getOwner() { |
349 |
return owner;
|
350 |
} |
351 |
|
352 |
public void setOwner(String owner) { |
353 |
this.owner = owner;
|
354 |
} |
355 |
|
356 |
public URL getOwnerURL() { |
357 |
return ownerURL;
|
358 |
} |
359 |
|
360 |
public void setOwnerURL(URL sources) { |
361 |
this.ownerURL = sources;
|
362 |
} |
363 |
|
364 |
public URL getSourcesURL() { |
365 |
return sources;
|
366 |
} |
367 |
|
368 |
public void setSourcesURL(URL sources) { |
369 |
this.sources = sources;
|
370 |
} |
371 |
|
372 |
@Override
|
373 |
public String toString() { |
374 |
StringBuffer buffer = new StringBuffer(super.toString()).append(" ("); |
375 |
|
376 |
append(buffer, InstallerInfoTags.CODE, getCode()); |
377 |
append(buffer, InstallerInfoTags.NAME, getName()); |
378 |
append(buffer, InstallerInfoTags.DESCRIPTION, getDescription()); |
379 |
append(buffer, InstallerInfoTags.GVSIG_VERSION, getGvSIGVersion()); |
380 |
append(buffer, InstallerInfoTags.VERSION, getVersion()); |
381 |
append(buffer, InstallerInfoTags.BUILD, getBuild()); |
382 |
append(buffer, InstallerInfoTags.OS, getOperatingSystem()); |
383 |
append(buffer, InstallerInfoTags.ARCHITECTURE, getArchitecture()); |
384 |
append(buffer, InstallerInfoTags.JVM, getJavaVM()); |
385 |
append(buffer, InstallerInfoTags.DOWNLOAD_URL, getDownloadURL()); |
386 |
append(buffer, InstallerInfoTags.STATE, getState()); |
387 |
append(buffer, InstallerInfoTags.OFFICIAL, isOfficial()); |
388 |
append(buffer, InstallerInfoTags.TYPE, getType()); |
389 |
append(buffer, InstallerInfoTags.MODEL_VERSION, getModelVersion()); |
390 |
append(buffer, InstallerInfoTags.OWNER, getOwner()); |
391 |
append(buffer, InstallerInfoTags.OWNER_URL, getOwnerURL()); |
392 |
append(buffer, InstallerInfoTags.SOURCES_URL, getSourcesURL()); |
393 |
append(buffer, InstallerInfoTags.DEPENDENCIES, getDependencies()); |
394 |
append(buffer, InstallerInfoTags.WEB_URL, getWebURL()); |
395 |
append(buffer, InstallerInfoTags.CATEGORIES, getCategories()); |
396 |
append(buffer, InstallerInfoTags.CODEALIAS, getAliasAsString()); |
397 |
|
398 |
return buffer.append(')').toString(); |
399 |
} |
400 |
|
401 |
public String toStringCompact() { |
402 |
// type code version state os arch jvm dep
|
403 |
return String |
404 |
.format( |
405 |
"%1$-8.8s %2$-40s %3$-20.20s %4$-5.5s %5$-5.5s %6$-6.6s %7$-5.5s %8$s %8$s",
|
406 |
this.type, this.code, this.version, this.state, |
407 |
this.operatingSystem, this.architecture, this.javaVM, |
408 |
this.dependencies, this.getAliasAsString()); |
409 |
} |
410 |
|
411 |
private DefaultPackageInfo append(StringBuffer buffer, String key, |
412 |
Object value) {
|
413 |
buffer.append("\n\t").append(key).append(": ") |
414 |
.append(value == null ? "" : value); |
415 |
return this; |
416 |
} |
417 |
|
418 |
@Override
|
419 |
public Object clone() throws CloneNotSupportedException { |
420 |
DefaultPackageInfo clone = (DefaultPackageInfo) super.clone();
|
421 |
clone.auxFiles = new ArrayList<File>(auxFiles); |
422 |
return clone;
|
423 |
} |
424 |
|
425 |
public File downloadFile() throws InstallPackageServiceException { |
426 |
return this.downloadFile(null); |
427 |
} |
428 |
|
429 |
public class FileDownloadException extends InstallPackageServiceException { |
430 |
|
431 |
private static final long serialVersionUID = 8640183295766490512L; |
432 |
|
433 |
private static final String message = "File '%(url)s' download error"; |
434 |
|
435 |
private static final String KEY = "_File_XurlX_download_error"; |
436 |
|
437 |
public FileDownloadException(URL url, IOException e) { |
438 |
super(message, e, KEY, serialVersionUID);
|
439 |
setValue("url", url.toString());
|
440 |
} |
441 |
|
442 |
} |
443 |
|
444 |
public File downloadFile(SimpleTaskStatus taskStatus) |
445 |
throws InstallPackageServiceException {
|
446 |
|
447 |
Download download = new Download(taskStatus);
|
448 |
|
449 |
// First try to download from the index base URL this package info has
|
450 |
// been downloaded from, looking first as if the index is located in the
|
451 |
// main version folder, and if not in the build folder.
|
452 |
// If also not there, download from the URL available in the
|
453 |
// downloadURL property.
|
454 |
// Example baseURL: http://downloads.gvsig.org/download/gvsig-desktop/dists/2.0.0/
|
455 |
String versionRelativePath = "../../pool/" + getCode() + "/" |
456 |
+ getPackageFileName(); |
457 |
File file = downloadFromRelativeURL(download, versionRelativePath);
|
458 |
|
459 |
if (file == null) { |
460 |
// Example baseURL: http://downloads.gvsig.org/download/gvsig-desktop/dists/2.0.0/builds/2048/
|
461 |
String buildRelativePath = "../../../../pool/" + getCode() + "/" |
462 |
+ getPackageFileName(); |
463 |
file = downloadFromRelativeURL(download, buildRelativePath); |
464 |
} |
465 |
|
466 |
if (file == null) { |
467 |
file = downloadFromPackageInfoURL(download); |
468 |
} |
469 |
|
470 |
return file;
|
471 |
} |
472 |
|
473 |
private File downloadFromRelativeURL(Download download, |
474 |
String buildRelativePath) {
|
475 |
InstallerManager manager = InstallerLocator.getInstallerManager(); |
476 |
URL baseURL = manager.getDownloadBaseURL();
|
477 |
try {
|
478 |
URL downloadURL = new URL(baseURL, buildRelativePath); |
479 |
return download.downloadFile(downloadURL, null); |
480 |
} catch (IOException e) { |
481 |
LOG.debug("Package " + getName()
|
482 |
+ " not found relative to the build index URL: " + baseURL
|
483 |
+ ", in the URL: " + buildRelativePath, e);
|
484 |
} |
485 |
return null; |
486 |
} |
487 |
|
488 |
private File downloadFromPackageInfoURL(Download download) throws FileDownloadException { |
489 |
try {
|
490 |
return download.downloadFile(this.getDownloadURL(), null); |
491 |
} catch (IOException ex3) { |
492 |
throw new FileDownloadException(this.getDownloadURL(), ex3); |
493 |
} |
494 |
} |
495 |
|
496 |
private String getPackageFileName() { |
497 |
Object[] values = |
498 |
new Object[] { "gvSIG-desktop", getGvSIGVersion(), getCode(), |
499 |
getVersion(), getState(), getOperatingSystem(), |
500 |
getArchitecture(), getJavaVM() }; |
501 |
StringBuffer buffer = new StringBuffer(); |
502 |
for (int i = 0; i < values.length - 1; i++) { |
503 |
buffer.append(values[i]).append('-');
|
504 |
} |
505 |
buffer.append(values[values.length - 1]).append(".gvspkg"); |
506 |
return buffer.toString();
|
507 |
} |
508 |
|
509 |
public void addFileToCopy(File file) { |
510 |
auxFiles.add(file); |
511 |
} |
512 |
|
513 |
public File getFileToCopy(int i) { |
514 |
return auxFiles.get(i);
|
515 |
} |
516 |
|
517 |
public void removeFileToCopy(File file) { |
518 |
auxFiles.remove(file); |
519 |
} |
520 |
|
521 |
public void clearFilesToCopy() { |
522 |
auxFiles.clear(); |
523 |
} |
524 |
|
525 |
public List<File> getFilesToCopy() { |
526 |
return auxFiles;
|
527 |
} |
528 |
|
529 |
public boolean removeInstallFolder(File folder) { |
530 |
DeleteFile delete = new DeleteFile();
|
531 |
boolean success = delete.delete(folder);
|
532 |
setAntScript(null);
|
533 |
clearFilesToCopy(); |
534 |
return success;
|
535 |
} |
536 |
|
537 |
public boolean removeFilesFolder(File folder) { |
538 |
DeleteFile delete = new DeleteFile();
|
539 |
return delete.delete(folder);
|
540 |
} |
541 |
|
542 |
public boolean matchID(String string) { |
543 |
String id = this.getID(); |
544 |
String[] stringParts = string.split("#"); |
545 |
|
546 |
switch (stringParts.length) {
|
547 |
case 1: |
548 |
if (stringParts[0].equals(this.getCode())) { |
549 |
return true; |
550 |
} else {
|
551 |
return false; |
552 |
} |
553 |
case 2: |
554 |
if (!stringParts[0].equals(this.getCode())) { |
555 |
return false; |
556 |
} |
557 |
Version version = new DefaultVersion();
|
558 |
try {
|
559 |
version.parse(stringParts[1]);
|
560 |
} catch (InvalidParameterException ex) { |
561 |
return false; |
562 |
} |
563 |
|
564 |
if (version.equals(this.getVersion())) { |
565 |
return true; |
566 |
} |
567 |
return false; |
568 |
default:
|
569 |
return string.equals(id);
|
570 |
|
571 |
} |
572 |
|
573 |
} |
574 |
|
575 |
public Dependencies getDependencies() {
|
576 |
return this.dependencies; |
577 |
} |
578 |
|
579 |
public void setDependencies(Dependencies dependencies) { |
580 |
this.dependencies = dependencies;
|
581 |
} |
582 |
|
583 |
public void setDependencies(String dependencies) { |
584 |
if (dependencies == null) { |
585 |
this.dependencies = null; |
586 |
} else {
|
587 |
this.dependencies = new DefaultDependencies().parse(dependencies); |
588 |
} |
589 |
} |
590 |
|
591 |
@Override
|
592 |
public boolean equals(Object obj) { |
593 |
PackageInfo other; |
594 |
try {
|
595 |
other = (PackageInfo) obj; |
596 |
} catch (Exception e) { |
597 |
return false; |
598 |
} |
599 |
if (!code.equalsIgnoreCase(other.getCode())) {
|
600 |
return false; |
601 |
} |
602 |
if (!version.check("=", other.getVersion())) { |
603 |
return false; |
604 |
} |
605 |
if (!operatingSystem.equalsIgnoreCase(other.getOperatingSystem())) {
|
606 |
return false; |
607 |
} |
608 |
if (!gvSIGVersion.equalsIgnoreCase(other.getGvSIGVersion())) {
|
609 |
return false; |
610 |
} |
611 |
if (!state.equalsIgnoreCase(other.getState())) {
|
612 |
return false; |
613 |
} |
614 |
if (!architecture.equalsIgnoreCase(other.getArchitecture())) {
|
615 |
return false; |
616 |
} |
617 |
if (!javaVM.equalsIgnoreCase(other.getJavaVM())) {
|
618 |
return false; |
619 |
} |
620 |
if (!type.equalsIgnoreCase(other.getType())) {
|
621 |
return false; |
622 |
} |
623 |
if (official != other.isOfficial()) {
|
624 |
return false; |
625 |
} |
626 |
return true; |
627 |
} |
628 |
|
629 |
public URL getWebURL() { |
630 |
return webURL;
|
631 |
} |
632 |
|
633 |
public void setWebURL(URL webURL) { |
634 |
this.webURL = webURL;
|
635 |
} |
636 |
|
637 |
public List<String> getCategories() { |
638 |
return this.categories; |
639 |
} |
640 |
|
641 |
public void setCategories(List categoriesList) { |
642 |
for (int i = 0; i < categoriesList.size(); i++) { |
643 |
if (!this.categories.contains(categoriesList.get(i))) { |
644 |
this.categories.add((String) categoriesList.get(i)); |
645 |
} |
646 |
} |
647 |
} |
648 |
|
649 |
public String getCategoriesAsString() { |
650 |
String categoriesString = ""; |
651 |
for (int i = 0; i < this.categories.size(); i++) { |
652 |
if (i + 1 < this.categories.size()) { |
653 |
categoriesString += this.categories.get(i) + ", "; |
654 |
} else {
|
655 |
categoriesString += this.categories.get(i);
|
656 |
} |
657 |
} |
658 |
return categoriesString;
|
659 |
} |
660 |
|
661 |
public void addCategoriesAsString(String categoriesString) { |
662 |
if (categoriesString == null) { |
663 |
return;
|
664 |
} |
665 |
categoriesString.trim(); |
666 |
String[] cadena = categoriesString.split(","); |
667 |
|
668 |
for (int i = 0; i < cadena.length; i++) { |
669 |
String trimCadena = cadena[i].trim();
|
670 |
if ((!this.categories.contains(trimCadena)) && (trimCadena != "")) { |
671 |
this.categories.add(trimCadena);
|
672 |
} |
673 |
} |
674 |
|
675 |
} |
676 |
|
677 |
public void checkSignature(byte[] pkgdata) { |
678 |
this.signed = false; |
679 |
SignUtil signutil = null;
|
680 |
List<byte[]> keys = |
681 |
InstallerLocator.getInstallerManager().getPublicKeys(); |
682 |
if (keys.size() < 1) { |
683 |
// No hay claves publicas, asi que no comprobamos ninguna firma
|
684 |
// y decirmos a todos que no estan firmados.
|
685 |
this.signed = false; |
686 |
return;
|
687 |
} |
688 |
for (byte[] rawkey : keys) { |
689 |
signutil = new SignUtil(rawkey);
|
690 |
if (signutil.canVerify()) {
|
691 |
int status = signutil.verify(pkgdata);
|
692 |
switch (status) {
|
693 |
case SignUtil.SIGN_OK:
|
694 |
// El paquete tiene una firma correcta,lo marcamos
|
695 |
// como firmado y salimos.
|
696 |
this.signed = true; |
697 |
return;
|
698 |
case SignUtil.NOT_SIGNED:
|
699 |
// El paquete no va firmado, lo marcamos como no
|
700 |
// firmado y salimos.
|
701 |
this.signed = false; |
702 |
return;
|
703 |
case SignUtil.SIGN_FAIL:
|
704 |
default:
|
705 |
// La firma del paquete no es correcta para esta clave,
|
706 |
// lo intentamos con el resto de claves.
|
707 |
break;
|
708 |
} |
709 |
} |
710 |
} |
711 |
// Si habiendo claves publicas la comprobacion de la firma con todas
|
712 |
// ellas
|
713 |
// falla marcamos el paquete como roto.
|
714 |
this.broken = true; |
715 |
} |
716 |
|
717 |
public boolean isBroken() { |
718 |
if (this.broken) { |
719 |
return true; |
720 |
} |
721 |
// if( this.isOfficial() && !this.isSigned() ) {
|
722 |
// return true;
|
723 |
// }
|
724 |
return false; |
725 |
} |
726 |
|
727 |
public boolean isSigned() { |
728 |
return signed;
|
729 |
} |
730 |
|
731 |
/* (non-Javadoc)
|
732 |
* @see org.gvsig.installer.lib.api.PackageInfo#getApplicationVersion()
|
733 |
*/
|
734 |
public Version getApplicationVersion() {
|
735 |
// TODO Auto-generated method stub
|
736 |
return null; |
737 |
} |
738 |
|
739 |
/* (non-Javadoc)
|
740 |
* @see org.gvsig.installer.lib.api.PackageInfo#setApplicationVersion(org.gvsig.installer.lib.api.Version)
|
741 |
*/
|
742 |
public void setApplicationVersion(Version version) { |
743 |
// TODO Auto-generated method stub
|
744 |
|
745 |
} |
746 |
|
747 |
/* (non-Javadoc)
|
748 |
* @see org.gvsig.installer.lib.api.PackageInfo#setValue(java.lang.String, java.lang.Object)
|
749 |
*/
|
750 |
public void setValue(String name, Object value) { |
751 |
// TODO Auto-generated method stub
|
752 |
|
753 |
} |
754 |
|
755 |
/* (non-Javadoc)
|
756 |
* @see org.gvsig.installer.lib.api.PackageInfo#getValue(java.lang.String)
|
757 |
*/
|
758 |
public Object getValue(String name) { |
759 |
// TODO Auto-generated method stub
|
760 |
return null; |
761 |
} |
762 |
|
763 |
/* (non-Javadoc)
|
764 |
* @see org.gvsig.installer.lib.api.PackageInfo#getPreferedPackageFileName()
|
765 |
*/
|
766 |
public String getPreferedPackageFileName() { |
767 |
// TODO Auto-generated method stub
|
768 |
return null; |
769 |
} |
770 |
|
771 |
} |