summaryrefslogtreecommitdiff
path: root/javainstaller2/src/JavaSetup/org/openoffice/setup/SetupData/PackageDescription.java
blob: 6124efa1d3439fe6996a1a6aa6bf55d7ddef5cec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: PackageDescription.java,v $
 * $Revision: 1.6 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

package org.openoffice.setup.SetupData;

import org.openoffice.setup.Util.Parser;
import java.io.Reader;
import java.io.StringReader;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Vector;
import javax.swing.tree.TreeNode;

/**
 *
 * @author Ingo Schmidt
 */
public class PackageDescription implements TreeNode {

    public final static int NOTA_UNIT= 0;
    public final static int RPM_UNIT = 1;
    public final static int PKG_UNIT = 2;
    /* public final static int MSI_UNIT = 3;
     * public final static int TAR_UNIT = 4;
     * public final static int TGZ_UNIT = 5;
     */

    public final static int DONT_INSTALL      = 0;
    public final static int INSTALL           = 1;
    public final static int INSTALL_SOME      = 2;
    public final static int REMOVE            = 3;
    public final static int DONT_REMOVE       = 4;
    public final static int REMOVE_SOME       = 5;
    public final static int IGNORE            = 6;
    public final static int DONT_KNOW         = 7;

    /* hierarchy information */
    private Vector children           = null;
    private PackageDescription parent = null;

    /* did the user select this package */
    private int     usrSelectionState = DONT_KNOW;

    /* display information */
    private String  dpyName            = "";
    private String  dpyDescription     = "";
    private String  checkSolaris       = "";
    private int     instSize    = 0;
    private int     dpySortKey  = 0;
    private boolean isDefault   = true;
    private boolean isHidden    = false;
    private boolean showInUserInstall = true;
    private boolean isOptional  = true;
    private boolean dontUninstall = false;
    private boolean allChildrenHidden = false;

    /* package information */
    private String  pkgMD5Sum   = "";
    private String  pkgFileName = "";
    private String  pkgFullName = null;
    private String  pkgVersion = null;
    private String  pkgRelease = null;
    private String  pkgRealName = null;
    private String  pkgSubdir = null;
    private String  pkgLanguage = null;
    private int     pkgSize     = 0;
    private int     pkgOrder    = 0;
    private int     pkgType     = NOTA_UNIT;
    private boolean pkgExists = true;  // must be default, especially for uninstallation
    private boolean isRelocatable = true;
    private boolean isUpdatePackage = false;
    private boolean showMultiLingualOnly = false;
    private boolean isApplicationPackage = false;
    private boolean isJavaPackage = false;
    private boolean isNewInstalled = false;
    private boolean wasAlreadyInstalled = false;

    /* Saving the default selection state. This is necessary, if the user chooses
     * the custom installation type, makes changes, and then changes into
     * the typical installation set. Then all user settings have to be removed again.
     * On the other hand, if the user then changes to the custom installation type
     * again, he probably wants to see the settings he has done before.
     */

    private int     typicalSelectionState = DONT_KNOW;  // Saving settings for typical installation
    private int     customSelectionState = DONT_KNOW;   // Saving settings for custom installation
    private int     startSelectionState = DONT_KNOW;    // Saving settings at start of installation

    /**
     * construct only with package information to wrap
     */
    protected PackageDescription(XMLPackageDescription p) {
        this(p, (PackageDescription)null);
    }

    private PackageDescription(XMLPackageDescription descriptionData, PackageDescription parent) {

        this.parent = parent;
        children = new Vector();
        parse(descriptionData);

        /* sort according to display sort key */
        Collections.sort(children, new PackageComparator());
     }

    /**
     * retrieve information about the package properties
     */

    public String getName() {
        return dpyName;
    }

    public String getDescription() {
        return dpyDescription;
    }

    public String getCheckSolaris() {
        return checkSolaris;
    }

    public int getSize() {
        return pkgSize;
    }

    public void setSize(int size) {
        pkgSize = size;
    }

    public int getOrder() {
        return pkgOrder;
    }

    // public int getAccumulatedSize() {
    //     int size = getSize();
    //
    //     for (Enumeration e = this.children(); e.hasMoreElements(); ) {
    //         // Should only be accumulated for selected modules
    //         PackageDescription data = (PackageDescription) e.nextElement();
    //         size += data.getSize();
    //     }
    //
    //     return size;
    // }

    public boolean isOptional() {
        return isOptional;
    }

    public boolean isHidden() {
        return isHidden;
    }

    public boolean showInUserInstall() {
        return showInUserInstall;
    }

    public boolean dontUninstall() {
        return dontUninstall;
    }

    public boolean isUpdatePackage() {
        return isUpdatePackage;
    }

    public boolean showMultiLingualOnly() {
        return showMultiLingualOnly;
    }

    public boolean isApplicationPackage() {
        return isApplicationPackage;
    }

    public boolean isJavaPackage() {
        return isJavaPackage;
    }

    public void setIsNewInstalled(boolean installed) {
        isNewInstalled = installed;
    }

    public boolean isNewInstalled() {
        return isNewInstalled;
    }

    public void setWasAlreadyInstalled(boolean installed) {
        wasAlreadyInstalled = installed;
    }

    public boolean wasAlreadyInstalled() {
        return wasAlreadyInstalled;
    }

    public boolean isDefault() {
        return isDefault;
    }

    public String getMD5() {
        return pkgMD5Sum;
    }

    public boolean isRelocatable() {
        return isRelocatable;
    }

    public String getPackageName() {
        return pkgFileName;
    }

    public String getFullPackageName() {
        return pkgFullName;
    }

    public void setFullPackageName(String fullPackageName) {
        pkgFullName = fullPackageName;
    }

    public int getSelectionState() {
        return usrSelectionState;
    }

    public void setSelectionState(int state) {
        usrSelectionState = state;
    }

    public int getCustomSelectionState() {
        return customSelectionState;
    }

    public void setCustomSelectionState(int state) {
        customSelectionState = state;
    }

     public int getTypicalSelectionState() {
        return typicalSelectionState;
    }

    public void setTypicalSelectionState(int state) {
        typicalSelectionState = state;
    }

    public int getStartSelectionState() {
        return startSelectionState;
    }

    public void setStartSelectionState(int state) {
        startSelectionState = state;
    }

    public boolean isAllChildrenHidden() {
        return allChildrenHidden;
    }

    public void setAllChildrenHidden(boolean hidden) {
        allChildrenHidden = hidden;
    }

    public void setIsHidden(boolean hidden) {
        isHidden = hidden;
    }

    public boolean pkgExists() {
        return pkgExists;
    }

    public void setPkgExists(boolean exists) {
        pkgExists = exists;
    }

    public String getPkgVersion() {
        return pkgVersion;
    }

    public void setPkgVersion(String version) {
        pkgVersion = version;
    }

    public String getPkgRelease() {
        return pkgRelease;
    }

    public void setPkgRelease(String release) {
        pkgRelease = release;
    }

    public String getPkgRealName() {
        return pkgRealName;
    }

    public void setPkgRealName(String realName) {
        pkgRealName = realName;
    }

    public String getPkgSubdir() {
        return pkgSubdir;
    }

    public void setPkgSubdir(String subdir) {
        pkgSubdir = subdir;
    }

    public String getPkgLanguage() {
        return pkgLanguage;
    }

    public void setPkgLanguage(String language) {
        pkgLanguage = language;
    }

    /**
     * extract the name and the description according to the locale
     */
    private String getLocalizedValue(XMLPackageDescription packageData, String section, Locale l) {
        String localizedValue = "";

        String countryString  = l.getCountry();
        String languageString = l.getLanguage();
        String localeString   = languageString + "_" + countryString;

        XMLPackageDescription subPackage = packageData.getElement(section, "lang", localeString);
        if (subPackage == null) {
            subPackage = packageData.getElement(section, "lang", languageString);
            if (subPackage == null) {
                subPackage = packageData.getElement(section, "lang", "en_US");
            }
        }
        if (subPackage != null) {
            localizedValue = subPackage.getValue();
        }

        return localizedValue;
    }

    /**
     * parse the wrapped package description
     */

    private void parse(XMLPackageDescription data) {

        XMLPackageDescription section;
        XMLPackageDescription subSection;

        /* information about how to display the node */
        section = data.getElement("display");
        if (section != null) {
            /* display types: hidden, visible */
            String displayType = section.getAttribute("type");
            if (displayType != null) {
                isHidden = displayType.equals("hidden");
            }

            /* name and description according to the current locale */
            Locale locale = Locale.getDefault();
            dpyName        = getLocalizedValue(section, "name",        locale);
            dpyDescription = getLocalizedValue(section, "description", locale);

            subSection = section.getElement("sortkey");
            if (subSection != null) {
                String sort = subSection.getValue();
                dpySortKey = Integer.parseInt(sort);
            }

            subSection = section.getElement("default");
            if (subSection != null) {
                String defaultValue = subSection.getValue();
                isDefault = Parser.parseBoolean(defaultValue);
                // isDefault = Boolean.parseBoolean(defaultValue);
            }

            subSection = section.getElement("showinuserinstall");
            if (subSection != null) {
                String showInUserInstallValue = subSection.getValue();
                showInUserInstall = Parser.parseBoolean(showInUserInstallValue);
                // showInUserInstall = Boolean.parseBoolean(showInUserInstallValue);
            }

            subSection = section.getElement("dontuninstall");
            if (subSection != null) {
                String dontUninstallValue = subSection.getValue();
                dontUninstall = Parser.parseBoolean(dontUninstallValue);
                // dontUninstall = Boolean.parseBoolean(dontUninstallValue);
            }

            subSection = section.getElement("checksolaris");
            if (subSection != null) {
                checkSolaris = subSection.getValue();
            }

            subSection = section.getElement("isupdatepackage");
            if (subSection != null) {
                String isUpdatePackageValue = subSection.getValue();
                isUpdatePackage = Parser.parseBoolean(isUpdatePackageValue);
                // isUpdatePackage = Boolean.parseBoolean(isUpdatePackageValue);
            }

            subSection = section.getElement("showmultilingualonly");
            if (subSection != null) {
                String showMultiLingualOnlyValue = subSection.getValue();
                showMultiLingualOnly = Parser.parseBoolean(showMultiLingualOnlyValue);
            }

            subSection = section.getElement("applicationmodule");
            if (subSection != null) {
                String isApplicationPackageValue = subSection.getValue();
                isApplicationPackage = Parser.parseBoolean(isApplicationPackageValue);
            }

            subSection = section.getElement("isjavapackage");
            if (subSection != null) {
                String isJavaPackageValue = subSection.getValue();
                isJavaPackage = Parser.parseBoolean(isJavaPackageValue);
                // isJavaPackage = Boolean.parseBoolean(isJavaPackageValue);
            }

        }

        /* query information about the physical (rpm/pkg/msi...) package itself */
        section = data.getElement("installunit");
        if (section != null) {
            String pkgTypeName = section.getAttribute("type");
            if (pkgTypeName != null) {
                if (pkgTypeName.equals("rpm")) {
                    pkgType = RPM_UNIT;
                } else if (pkgTypeName.equals("pkg")) {
                    pkgType = PKG_UNIT;
                }
            }

            subSection = section.getElement("size");
            if (subSection != null) {
                String sz = subSection.getValue();
                pkgSize = Integer.parseInt(sz);
            }
            subSection = section.getElement("installorder");
            if (subSection != null) {
                String order = subSection.getValue();
                pkgOrder = Integer.parseInt(order);
            } else {
                // Setting the default for packages without order
                pkgOrder = 1000;
            }
            subSection = section.getElement("md5");
            if (subSection != null) {
                pkgMD5Sum = subSection.getValue();
            }
            subSection = section.getElement("name");
            if (subSection != null) {
                pkgFileName = subSection.getValue();
            }
            subSection = section.getElement("fullpkgname");
            if (subSection != null) {
                pkgFullName = subSection.getValue();
            }
            subSection = section.getElement("pkgversion");
            if (subSection != null) {
                pkgVersion = subSection.getValue();
            }
            subSection = section.getElement("subdir");
            if (subSection != null) {
                pkgSubdir = subSection.getValue();
            }
            subSection = section.getElement("relocatable");
            if (subSection != null) {
                String relocatableValue = subSection.getValue();
                isRelocatable = Parser.parseBoolean(relocatableValue);
                // isRelocatable = Boolean.parseBoolean(relocatableValue);
            }
            subSection = section.getElement("solarislanguage");
            if (subSection != null) {
                pkgLanguage = subSection.getValue();
            }

        }

        /* line up the subpackages */
        for (Enumeration enumPackages = data.elements(); enumPackages.hasMoreElements(); ) {
            XMLPackageDescription p = (XMLPackageDescription) enumPackages.nextElement();
            if (p.getKey().equals("package")) {
                children.add(new PackageDescription(p, this));
            }
        }
    }

    /**
     * sort according to the display sortkey
     */

    private class PackageComparator implements Comparator {
        public int compare(Object w1, Object w2) {
            return ((PackageDescription) w1).dpySortKey - ((PackageDescription) w2).dpySortKey;
        }
    }

    /**
     * implement a TreeNode interface for convenient travelling through the data
     */

    private class PackageEnumeration implements Enumeration {

        Enumeration e;

        protected PackageEnumeration() {
            e = children.elements();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
        public Object nextElement() {
            return e.nextElement();
        }
    }

    /**
     * TreeNode interface
     */
    public Enumeration children() {
        return new PackageEnumeration();
    }

    public boolean getAllowsChildren() {
        return true;
    }

//    public PackageDescription getChildAt(int childIndex) {
//        return (PackageDescription) children.elementAt(childIndex);
//    }

    public TreeNode getChildAt(int childIndex) {
        return (TreeNode)children.elementAt(childIndex);
    }

    public int getChildCount() {
        return children.size();
    }

    public int getIndex(TreeNode node) {
        return children.indexOf(node);
    }

//    public PackageDescription getParent() {
//        return parent;
//    }

    public TreeNode getParent() {
        return (TreeNode)parent;
    }

    public boolean isLeaf() {
        return children.size() == 0;
    }

}