xref: /AOO41X/main/javainstaller2/src/JavaSetup/org/openoffice/setup/SetupData/SetupDataProvider.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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.InstallData;
31 import org.openoffice.setup.Installer.Installer;
32 import org.openoffice.setup.Installer.InstallerFactory;
33 import java.util.Enumeration;
34 import java.util.Vector;
35 import javax.swing.tree.DefaultMutableTreeNode;
36 
37 /**
38  *
39  * @author Christof Pintaske
40  */
41 public class SetupDataProvider {
42 
43     static private PackageDescription packageData;
44     static private ProductDescription productData;
45 
46     private SetupDataProvider() {
47     }
48 
49     public static PackageDescription getPackageDescription() {
50         return packageData;
51     }
52 
53     public static ProductDescription getProductDescription() {
54         return productData;
55     }
56 
57     public static String replaceMacros(String s) {
58         return productData.replaceMacros(s);
59     }
60 
61     public static String getString(String key) {
62         return productData.get(key);
63     }
64 
65     public static void setNewMacro(String key, String value) {
66         productData.setNewMacro(key, value);
67     }
68 
69     public static void dumpMacros() {
70         productData.dumpMacros();
71     }
72 
73     private static DefaultMutableTreeNode createTree(PackageDescription data, InstallData installData) {
74         DefaultMutableTreeNode node = new DefaultMutableTreeNode();
75 
76         node.setUserObject(new DisplayPackageDescription(data));
77 
78         for (Enumeration e = data.children(); e.hasMoreElements(); ) {
79             PackageDescription child = (PackageDescription) e.nextElement();
80 
81             // Do not display modules with "showinuserinstall" set to false in xpd file
82             // if this is a user installation.
83             if (( installData.isUserInstallation() ) && ( ! child.showInUserInstall() )) {
84                 child.setIsHidden(true);
85                 child.setSelectionState(PackageDescription.IGNORE);
86             }
87 
88             // Only add modules, if they have not display type="hidden" in xpd file
89             if (!child.isHidden()) {
90                 node.add(createTree(child, installData));
91             }
92         }
93 
94         return node;
95     }
96 
97     public static DefaultMutableTreeNode createTree() {
98         InstallData installData = InstallData.getInstance();
99         return createTree(getPackageDescription(), installData);
100     }
101 
102     static {
103         XMLPackageDescription rawData = new XMLPackageDescription();
104         rawData.read();
105         // rawData.dump();
106         packageData = new PackageDescription(rawData);
107         productData = new ProductDescription(rawData);
108     }
109 }
110