001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031 package org.openoffice.setup;
032
033 import org.openoffice.setup.SetupData.SetupDataProvider;
034 import java.io.File;
035 import java.net.MalformedURLException;
036 import java.net.URL;
037 import java.util.Enumeration;
038 import java.util.HashMap;
039 import java.util.Locale;
040 import java.util.MissingResourceException;
041 import java.util.PropertyResourceBundle;
042 import java.util.ResourceBundle;
043 import javax.swing.ImageIcon;
044
045 public class ResourceManager {
046
047 static PropertyResourceBundle stringResourceBundle;
048 static PropertyResourceBundle fileNameResourceBundle;
049 static HashMap setupFiles = new HashMap();
050
051 private ResourceManager() {
052 }
053
054 static public void checkFileExistence(File htmlDirectory) {
055
056 for (Enumeration e = fileNameResourceBundle.getKeys(); e.hasMoreElements(); ) {
057 String key = (String) e.nextElement();
058 String fileName = (String)(fileNameResourceBundle.getObject(key));
059
060 if ( ! fileName.endsWith("html") ) {
061
062 setupFiles.put(key, fileName);
063
064 }
065
066 if ( fileName.endsWith("html") ) {
067 boolean fileExists = true;
068
069 File file = new File(htmlDirectory, fileName);
070 File newFile = null;
071
072 if ( file.exists() ) {
073 setupFiles.put(key, fileName);
074
075 } else {
076 fileExists = false;
077
078 int pos1 = fileName.lastIndexOf("_");
079
080 if ( pos1 > 0 ) {
081 int pos2 = fileName.lastIndexOf(".");
082 String newFileName = fileName.substring(0, pos1) + fileName.substring(pos2, fileName.length());
083 newFile = new File(htmlDirectory, newFileName);
084 if ( newFile.exists() ) {
085 fileExists = true;
086 setupFiles.put(key, newFileName);
087
088 } else {
089
090 String simplePage = "Excuse.html";
091 File simpleFile = new File(htmlDirectory, simplePage);
092 if ( simpleFile.exists() ) {
093 fileExists = true;
094 setupFiles.put(key, simplePage);
095
096 }
097 }
098 }
099 }
100
101 if ( ! fileExists ) {
102 if ( newFile != null ) {
103 System.err.println("ERROR: Neither file \"" + file.getPath() +
104 "\" nor file \"" + newFile.getPath() + "\" do exist!");
105 } else {
106 System.err.println("ERROR: File \"" + file.getPath() + "\" does not exist!");
107 }
108 System.exit(1);
109 }
110 }
111 }
112 }
113
114 static public String getString(String key) {
115 String value = (String)(stringResourceBundle.getObject(key));
116 if (value != null && (value.indexOf('$') >= 0)) {
117 value = SetupDataProvider.replaceMacros(value);
118 }
119 return value;
120 }
121
122 static public String getFileName(String key) {
123 String value = (String)setupFiles.get(key);
124
125 return value;
126 }
127
128 static public ImageIcon getIcon(String key) {
129
130 String name = getFileName(key);
131
132 try {
133 Class c = Class.forName("org.openoffice.setup.ResourceManager");
134 URL url = c.getResource(name);
135 if (url != null) {
136 return new ImageIcon(url);
137 } else {
138 System.err.println("Error: file not found: " + name);
139 }
140 } catch (ClassNotFoundException e) {
141 System.err.println(e);
142 }
143
144 return new ImageIcon();
145 }
146
147 static public ImageIcon getIconFromPath(File file) {
148
149 try {
150 URL url = file.toURL();
151 if (url != null) {
152 return new ImageIcon(url);
153 } else {
154 System.err.println("Error: file not found: " + file.getPath());
155 }
156 } catch (MalformedURLException e) {
157 System.err.println(e);
158 }
159
160 return new ImageIcon();
161 }
162
163 static {
164 Locale locale = Locale.getDefault();
165 System.err.println("System locale: " + locale );
166 try {
167 stringResourceBundle = (PropertyResourceBundle) ResourceBundle.getBundle("org.openoffice.setup.setupstrings", locale);
168 fileNameResourceBundle = (PropertyResourceBundle) ResourceBundle.getBundle("org.openoffice.setup.setupfiles", locale);
169 } catch (MissingResourceException ex) {
170 ex.printStackTrace();
171 System.exit(1);
172 }
173 }
174 }