1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package org.openoffice.setup.SetupData; 29 30 import org.openoffice.setup.Util.Parser; 31 import java.io.Reader; 32 import java.io.StringReader; 33 import java.util.Collections; 34 import java.util.Comparator; 35 import java.util.Enumeration; 36 import java.util.Locale; 37 import java.util.Vector; 38 import javax.swing.tree.TreeNode; 39 40 /** 41 * 42 * @author Ingo Schmidt 43 */ 44 public class PackageDescription implements TreeNode { 45 46 public final static int NOTA_UNIT= 0; 47 public final static int RPM_UNIT = 1; 48 public final static int PKG_UNIT = 2; 49 /* public final static int MSI_UNIT = 3; 50 * public final static int TAR_UNIT = 4; 51 * public final static int TGZ_UNIT = 5; 52 */ 53 54 public final static int DONT_INSTALL = 0; 55 public final static int INSTALL = 1; 56 public final static int INSTALL_SOME = 2; 57 public final static int REMOVE = 3; 58 public final static int DONT_REMOVE = 4; 59 public final static int REMOVE_SOME = 5; 60 public final static int IGNORE = 6; 61 public final static int DONT_KNOW = 7; 62 63 /* hierarchy information */ 64 private Vector children = null; 65 private PackageDescription parent = null; 66 67 /* did the user select this package */ 68 private int usrSelectionState = DONT_KNOW; 69 70 /* display information */ 71 private String dpyName = ""; 72 private String dpyDescription = ""; 73 private String checkSolaris = ""; 74 private int instSize = 0; 75 private int dpySortKey = 0; 76 private boolean isDefault = true; 77 private boolean isHidden = false; 78 private boolean showInUserInstall = true; 79 private boolean showInUserInstallOnly = false; 80 private boolean isOptional = true; 81 private boolean dontUninstall = false; 82 private boolean allChildrenHidden = false; 83 84 /* package information */ 85 private String pkgMD5Sum = ""; 86 private String pkgFileName = ""; 87 private String pkgFullName = null; 88 private String pkgVersion = null; 89 private String pkgRelease = null; 90 private String pkgRealName = null; 91 private String pkgSubdir = null; 92 private String pkgLanguage = null; 93 private int pkgSize = 0; 94 private int pkgOrder = 0; 95 private int pkgType = NOTA_UNIT; 96 private boolean pkgExists = true; // must be default, especially for uninstallation 97 private boolean isRelocatable = true; 98 private boolean isUpdatePackage = false; 99 private boolean showMultiLingualOnly = false; 100 private boolean isApplicationPackage = false; 101 private boolean isJavaPackage = false; 102 private boolean installCanFail = false; 103 private boolean uninstallCanFail = false; 104 private boolean forceIntoUpdate = false; 105 private boolean useForce = false; 106 private boolean isNewInstalled = false; 107 private boolean wasAlreadyInstalled = false; 108 private boolean ignoreDependsForUninstall = false; 109 110 /* Saving the default selection state. This is necessary, if the user chooses 111 * the custom installation type, makes changes, and then changes into 112 * the typical installation set. Then all user settings have to be removed again. 113 * On the other hand, if the user then changes to the custom installation type 114 * again, he probably wants to see the settings he has done before. 115 */ 116 117 private int typicalSelectionState = DONT_KNOW; // Saving settings for typical installation 118 private int customSelectionState = DONT_KNOW; // Saving settings for custom installation 119 private int startSelectionState = DONT_KNOW; // Saving settings at start of installation 120 121 public PackageDescription() {} 122 123 /** 124 * construct only with package information to wrap 125 */ 126 protected PackageDescription(XMLPackageDescription p) { 127 this(p, (PackageDescription)null); 128 } 129 130 private PackageDescription(XMLPackageDescription descriptionData, PackageDescription parent) { 131 132 this.parent = parent; 133 children = new Vector(); 134 parse(descriptionData); 135 136 /* sort according to display sort key */ 137 Collections.sort(children, new PackageComparator()); 138 } 139 140 /** 141 * retrieve information about the package properties 142 */ 143 144 public String getName() { 145 return dpyName; 146 } 147 148 public void setName(String name) { 149 dpyName = name; 150 } 151 152 public String getDescription() { 153 return dpyDescription; 154 } 155 156 public String getCheckSolaris() { 157 return checkSolaris; 158 } 159 160 public int getSize() { 161 return pkgSize; 162 } 163 164 public void setSize(int size) { 165 pkgSize = size; 166 } 167 168 public int getOrder() { 169 return pkgOrder; 170 } 171 172 public void setOrder(int order) { 173 pkgOrder = order; 174 } 175 176 // public int getAccumulatedSize() { 177 // int size = getSize(); 178 // 179 // for (Enumeration e = this.children(); e.hasMoreElements(); ) { 180 // // Should only be accumulated for selected modules 181 // PackageDescription data = (PackageDescription) e.nextElement(); 182 // size += data.getSize(); 183 // } 184 // 185 // return size; 186 // } 187 188 public boolean isOptional() { 189 return isOptional; 190 } 191 192 public boolean isHidden() { 193 return isHidden; 194 } 195 196 public boolean showInUserInstall() { 197 return showInUserInstall; 198 } 199 200 public boolean showInUserInstallOnly() { 201 return showInUserInstallOnly; 202 } 203 204 public boolean dontUninstall() { 205 return dontUninstall; 206 } 207 208 public boolean isUpdatePackage() { 209 return isUpdatePackage; 210 } 211 212 public boolean showMultiLingualOnly() { 213 return showMultiLingualOnly; 214 } 215 216 public boolean isApplicationPackage() { 217 return isApplicationPackage; 218 } 219 220 public boolean isJavaPackage() { 221 return isJavaPackage; 222 } 223 224 public boolean installCanFail() { 225 return installCanFail; 226 } 227 228 public boolean uninstallCanFail() { 229 return uninstallCanFail; 230 } 231 232 public void setUninstallCanFail(boolean canFail) { 233 uninstallCanFail = canFail; 234 } 235 236 public boolean forceIntoUpdate() { 237 return forceIntoUpdate; 238 } 239 240 public boolean useForce() { 241 return useForce; 242 } 243 244 public void setIsNewInstalled(boolean installed) { 245 isNewInstalled = installed; 246 } 247 248 public boolean isNewInstalled() { 249 return isNewInstalled; 250 } 251 252 public void setWasAlreadyInstalled(boolean installed) { 253 wasAlreadyInstalled = installed; 254 } 255 256 public boolean wasAlreadyInstalled() { 257 return wasAlreadyInstalled; 258 } 259 260 public void setIgnoreDependsForUninstall(boolean ignore) { 261 ignoreDependsForUninstall = ignore; 262 } 263 264 public boolean ignoreDependsForUninstall() { 265 return ignoreDependsForUninstall; 266 } 267 268 public boolean isDefault() { 269 return isDefault; 270 } 271 272 public String getMD5() { 273 return pkgMD5Sum; 274 } 275 276 public boolean isRelocatable() { 277 return isRelocatable; 278 } 279 280 public void setIsRelocatable(boolean relocatable) { 281 isRelocatable = relocatable; 282 } 283 284 public String getPackageName() { 285 return pkgFileName; 286 } 287 288 public void setPackageName(String name) { 289 pkgFileName = name; 290 } 291 292 293 public String getFullPackageName() { 294 return pkgFullName; 295 } 296 297 public void setFullPackageName(String fullPackageName) { 298 pkgFullName = fullPackageName; 299 } 300 301 public int getSelectionState() { 302 return usrSelectionState; 303 } 304 305 public void setSelectionState(int state) { 306 usrSelectionState = state; 307 } 308 309 public int getCustomSelectionState() { 310 return customSelectionState; 311 } 312 313 public void setCustomSelectionState(int state) { 314 customSelectionState = state; 315 } 316 317 public int getTypicalSelectionState() { 318 return typicalSelectionState; 319 } 320 321 public void setTypicalSelectionState(int state) { 322 typicalSelectionState = state; 323 } 324 325 public int getStartSelectionState() { 326 return startSelectionState; 327 } 328 329 public void setStartSelectionState(int state) { 330 startSelectionState = state; 331 } 332 333 public boolean isAllChildrenHidden() { 334 return allChildrenHidden; 335 } 336 337 public void setAllChildrenHidden(boolean hidden) { 338 allChildrenHidden = hidden; 339 } 340 341 public void setIsHidden(boolean hidden) { 342 isHidden = hidden; 343 } 344 345 public boolean pkgExists() { 346 return pkgExists; 347 } 348 349 public void setPkgExists(boolean exists) { 350 pkgExists = exists; 351 } 352 353 public String getPkgVersion() { 354 return pkgVersion; 355 } 356 357 public void setPkgVersion(String version) { 358 pkgVersion = version; 359 } 360 361 public String getPkgRelease() { 362 return pkgRelease; 363 } 364 365 public void setPkgRelease(String release) { 366 pkgRelease = release; 367 } 368 369 public String getPkgRealName() { 370 return pkgRealName; 371 } 372 373 public void setPkgRealName(String realName) { 374 pkgRealName = realName; 375 } 376 377 public String getPkgSubdir() { 378 return pkgSubdir; 379 } 380 381 public void setPkgSubdir(String subdir) { 382 pkgSubdir = subdir; 383 } 384 385 public String getPkgLanguage() { 386 return pkgLanguage; 387 } 388 389 public void setPkgLanguage(String language) { 390 pkgLanguage = language; 391 } 392 393 /** 394 * extract the name and the description according to the locale 395 */ 396 private String getLocalizedValue(XMLPackageDescription packageData, String section, Locale l) { 397 String localizedValue = ""; 398 399 String countryString = l.getCountry(); 400 String languageString = l.getLanguage(); 401 String localeString = languageString + "_" + countryString; 402 403 XMLPackageDescription subPackage = packageData.getElement(section, "lang", localeString); 404 if (subPackage == null) { 405 subPackage = packageData.getElement(section, "lang", languageString); 406 if (subPackage == null) { 407 subPackage = packageData.getElement(section, "lang", "en_US"); 408 } 409 } 410 if (subPackage != null) { 411 localizedValue = subPackage.getValue(); 412 } 413 414 return localizedValue; 415 } 416 417 /** 418 * parse the wrapped package description 419 */ 420 421 private void parse(XMLPackageDescription data) { 422 423 XMLPackageDescription section; 424 XMLPackageDescription subSection; 425 426 /* information about how to display the node */ 427 section = data.getElement("display"); 428 if (section != null) { 429 /* display types: hidden, visible */ 430 String displayType = section.getAttribute("type"); 431 if (displayType != null) { 432 isHidden = displayType.equals("hidden"); 433 } 434 435 /* name and description according to the current locale */ 436 Locale locale = Locale.getDefault(); 437 dpyName = getLocalizedValue(section, "name", locale); 438 dpyDescription = getLocalizedValue(section, "description", locale); 439 440 subSection = section.getElement("sortkey"); 441 if (subSection != null) { 442 String sort = subSection.getValue(); 443 dpySortKey = Integer.parseInt(sort); 444 } 445 446 subSection = section.getElement("default"); 447 if (subSection != null) { 448 String defaultValue = subSection.getValue(); 449 isDefault = Parser.parseBoolean(defaultValue); 450 // isDefault = Boolean.parseBoolean(defaultValue); 451 } 452 453 subSection = section.getElement("showinuserinstall"); 454 if (subSection != null) { 455 String showInUserInstallValue = subSection.getValue(); 456 showInUserInstall = Parser.parseBoolean(showInUserInstallValue); 457 // showInUserInstall = Boolean.parseBoolean(showInUserInstallValue); 458 } 459 460 subSection = section.getElement("showinuserinstallonly"); 461 if (subSection != null) { 462 String showInUserInstallValueOnly = subSection.getValue(); 463 showInUserInstallOnly = Parser.parseBoolean(showInUserInstallValueOnly); 464 } 465 466 subSection = section.getElement("dontuninstall"); 467 if (subSection != null) { 468 String dontUninstallValue = subSection.getValue(); 469 dontUninstall = Parser.parseBoolean(dontUninstallValue); 470 // dontUninstall = Boolean.parseBoolean(dontUninstallValue); 471 } 472 473 subSection = section.getElement("checksolaris"); 474 if (subSection != null) { 475 checkSolaris = subSection.getValue(); 476 } 477 478 subSection = section.getElement("isupdatepackage"); 479 if (subSection != null) { 480 String isUpdatePackageValue = subSection.getValue(); 481 isUpdatePackage = Parser.parseBoolean(isUpdatePackageValue); 482 // isUpdatePackage = Boolean.parseBoolean(isUpdatePackageValue); 483 } 484 485 subSection = section.getElement("showmultilingualonly"); 486 if (subSection != null) { 487 String showMultiLingualOnlyValue = subSection.getValue(); 488 showMultiLingualOnly = Parser.parseBoolean(showMultiLingualOnlyValue); 489 } 490 491 subSection = section.getElement("applicationmodule"); 492 if (subSection != null) { 493 String isApplicationPackageValue = subSection.getValue(); 494 isApplicationPackage = Parser.parseBoolean(isApplicationPackageValue); 495 } 496 497 subSection = section.getElement("isjavapackage"); 498 if (subSection != null) { 499 String isJavaPackageValue = subSection.getValue(); 500 isJavaPackage = Parser.parseBoolean(isJavaPackageValue); 501 // isJavaPackage = Boolean.parseBoolean(isJavaPackageValue); 502 } 503 504 subSection = section.getElement("installcanfail"); 505 if (subSection != null) { 506 String installCanFailValue = subSection.getValue(); 507 installCanFail = Parser.parseBoolean(installCanFailValue); 508 } 509 510 subSection = section.getElement("forceintoupdate"); 511 if (subSection != null) { 512 String forceIntoUpdateValue = subSection.getValue(); 513 forceIntoUpdate = Parser.parseBoolean(forceIntoUpdateValue); 514 } 515 516 subSection = section.getElement("useforce"); 517 if (subSection != null) { 518 String useForceValue = subSection.getValue(); 519 useForce = Parser.parseBoolean(useForceValue); 520 } 521 522 } 523 524 /* query information about the physical (rpm/pkg/msi...) package itself */ 525 section = data.getElement("installunit"); 526 if (section != null) { 527 String pkgTypeName = section.getAttribute("type"); 528 if (pkgTypeName != null) { 529 if (pkgTypeName.equals("rpm")) { 530 pkgType = RPM_UNIT; 531 } else if (pkgTypeName.equals("pkg")) { 532 pkgType = PKG_UNIT; 533 } 534 } 535 536 subSection = section.getElement("size"); 537 if (subSection != null) { 538 String sz = subSection.getValue(); 539 pkgSize = Integer.parseInt(sz); 540 } 541 subSection = section.getElement("installorder"); 542 if (subSection != null) { 543 String order = subSection.getValue(); 544 pkgOrder = Integer.parseInt(order); 545 } else { 546 // Setting the default for packages without order 547 pkgOrder = 1000; 548 } 549 subSection = section.getElement("md5"); 550 if (subSection != null) { 551 pkgMD5Sum = subSection.getValue(); 552 } 553 subSection = section.getElement("name"); 554 if (subSection != null) { 555 pkgFileName = subSection.getValue(); 556 } 557 subSection = section.getElement("fullpkgname"); 558 if (subSection != null) { 559 pkgFullName = subSection.getValue(); 560 } 561 subSection = section.getElement("pkgversion"); 562 if (subSection != null) { 563 pkgVersion = subSection.getValue(); 564 } 565 subSection = section.getElement("subdir"); 566 if (subSection != null) { 567 pkgSubdir = subSection.getValue(); 568 } 569 subSection = section.getElement("relocatable"); 570 if (subSection != null) { 571 String relocatableValue = subSection.getValue(); 572 isRelocatable = Parser.parseBoolean(relocatableValue); 573 // isRelocatable = Boolean.parseBoolean(relocatableValue); 574 } 575 subSection = section.getElement("solarislanguage"); 576 if (subSection != null) { 577 pkgLanguage = subSection.getValue(); 578 } 579 580 } 581 582 /* line up the subpackages */ 583 for (Enumeration enumPackages = data.elements(); enumPackages.hasMoreElements(); ) { 584 XMLPackageDescription p = (XMLPackageDescription) enumPackages.nextElement(); 585 if (p.getKey().equals("package")) { 586 children.add(new PackageDescription(p, this)); 587 } 588 } 589 } 590 591 /** 592 * sort according to the display sortkey 593 */ 594 595 private class PackageComparator implements Comparator { 596 public int compare(Object w1, Object w2) { 597 return ((PackageDescription) w1).dpySortKey - ((PackageDescription) w2).dpySortKey; 598 } 599 } 600 601 /** 602 * implement a TreeNode interface for convenient travelling through the data 603 */ 604 605 private class PackageEnumeration implements Enumeration { 606 607 Enumeration e; 608 609 protected PackageEnumeration() { 610 e = children.elements(); 611 } 612 public boolean hasMoreElements() { 613 return e.hasMoreElements(); 614 } 615 public Object nextElement() { 616 return e.nextElement(); 617 } 618 } 619 620 /** 621 * TreeNode interface 622 */ 623 public Enumeration children() { 624 return new PackageEnumeration(); 625 } 626 627 public boolean getAllowsChildren() { 628 return true; 629 } 630 631 // public PackageDescription getChildAt(int childIndex) { 632 // return (PackageDescription) children.elementAt(childIndex); 633 // } 634 635 public TreeNode getChildAt(int childIndex) { 636 return (TreeNode)children.elementAt(childIndex); 637 } 638 639 public int getChildCount() { 640 return children.size(); 641 } 642 643 public int getIndex(TreeNode node) { 644 return children.indexOf(node); 645 } 646 647 // public PackageDescription getParent() { 648 // return parent; 649 // } 650 651 public TreeNode getParent() { 652 return (TreeNode)parent; 653 } 654 655 public boolean isLeaf() { 656 return children.size() == 0; 657 } 658 659 } 660