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