xref: /trunk/main/javainstaller2/src/JavaSetup/org/openoffice/setup/SetupData/SetupDataProvider.java (revision 34ecb7974825649843db8a4c8b63b5a16053c597)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.setup.SetupData;
25 
26 import org.openoffice.setup.InstallData;
27 import org.openoffice.setup.Installer.Installer;
28 import org.openoffice.setup.Installer.InstallerFactory;
29 import java.util.Enumeration;
30 import javax.swing.tree.DefaultMutableTreeNode;
31 
32 /**
33  *
34  * @author Christof Pintaske
35  */
36 public class SetupDataProvider {
37 
38     static private PackageDescription packageData;
39     static private ProductDescription productData;
40 
41     private SetupDataProvider() {
42     }
43 
44     public static PackageDescription getPackageDescription() {
45         return packageData;
46     }
47 
48     public static ProductDescription getProductDescription() {
49         return productData;
50     }
51 
52     public static String replaceMacros(String s) {
53         return productData.replaceMacros(s);
54     }
55 
56     public static String getString(String key) {
57         return productData.get(key);
58     }
59 
60     public static void setNewMacro(String key, String value) {
61         productData.setNewMacro(key, value);
62     }
63 
64     public static void dumpMacros() {
65         productData.dumpMacros();
66     }
67 
68     private static DefaultMutableTreeNode createTree(PackageDescription data, InstallData installData) {
69         DefaultMutableTreeNode node = new DefaultMutableTreeNode();
70 
71         node.setUserObject(new DisplayPackageDescription(data));
72 
73         for (Enumeration e = data.children(); e.hasMoreElements(); ) {
74             PackageDescription child = (PackageDescription) e.nextElement();
75 
76             // Do not display modules with "showinuserinstall" set to false in xpd file
77             // if this is a user installation.
78             if (( installData.isUserInstallation() ) && ( ! child.showInUserInstall() )) {
79                 child.setIsHidden(true);
80                 child.setSelectionState(PackageDescription.IGNORE);
81             }
82 
83             // Only add modules, if they have not display type="hidden" in xpd file
84             if (!child.isHidden()) {
85                 node.add(createTree(child, installData));
86             }
87         }
88 
89         return node;
90     }
91 
92     public static DefaultMutableTreeNode createTree() {
93         InstallData installData = InstallData.getInstance();
94         return createTree(getPackageDescription(), installData);
95     }
96 
97     static {
98         XMLPackageDescription rawData = new XMLPackageDescription();
99         rawData.read();
100         // rawData.dump();
101         packageData = new PackageDescription(rawData);
102         productData = new ProductDescription(rawData);
103     }
104 }
105