Changeset 9869
- Timestamp:
- 2005-05-13T15:57:47+12:00 (19 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/Configuration.java
r9437 r9869 71 71 static public String GS3_CONFIG_XML = "config3.xml"; 72 72 73 static final private String CURRENT_CONFIGURATION_VERSION = "2.60";74 73 /** The name of the root element of the subtree containing gatherer configuration options. This is required as the document itself may contain several other subtrees of settings (such as in the case of a '.col' file). */ 75 74 static final private String GATHERER_CONFIG = "GathererConfig"; … … 97 96 static public Configuration self = null; 98 97 99 static public boolean just_ created_new_config_file = false;98 static public boolean just_updated_config_xml_file = false; 100 99 /** The path to the Greenstone Suite installation directory. */ 101 100 static public String gsdl_path = ""; … … 150 149 config_xml_file_name = GS3_CONFIG_XML; 151 150 } 151 152 // If the existing user config.xml file isn't recent enough, backup the old version and update it 152 153 File config_xml_file = new File(Utility.getGLIUserFolder(), config_xml_file_name); 153 154 if (config_xml_file != null && config_xml_file.exists()) { 154 general_config = Utility.parse(config_xml_file.getAbsolutePath(), false); 155 } 156 157 // If the version of the config we've loaded isn't recent enough, backup the old version and create a new one 158 just_created_new_config_file = false; 159 if (general_config != null) { 160 Element configuration_element = general_config.getDocumentElement(); 161 String configuration_version = configuration_element.getAttribute(StaticStrings.VERSION_ATTRIBUTE); 162 if (!configuration_version.equals(CURRENT_CONFIGURATION_VERSION)) { 163 // !!! JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Configuration.Obsolete_Config"), Dictionary.get("Configuration.Obsolete_Config_Title"), JOptionPane.ERROR_MESSAGE); 164 File backup = new File(config_xml_file.getAbsolutePath() + ".bak"); 165 config_xml_file.renameTo(backup); 166 general_config = null; 167 } 155 just_updated_config_xml_file = updateUserConfigXMLFileIfNecessary(config_xml_file); 156 general_config = XMLTools.parseXMLFile(config_xml_file); 168 157 } 169 158 … … 171 160 if (general_config == null) { 172 161 general_config = Utility.parse(TEMPLATE_CONFIG_XML, true); 173 just_ created_new_config_file = true;162 just_updated_config_xml_file = true; 174 163 } 175 164 … … 210 199 } 211 200 } 201 } 202 203 204 static private boolean updateUserConfigXMLFileIfNecessary(File config_xml_file) 205 { 206 // Check if the configuration file actually needs updating by looking at the version numbers 207 Document new_document = Utility.parse(TEMPLATE_CONFIG_XML, true); 208 Document old_document = XMLTools.parseXMLFile(config_xml_file); 209 210 String new_version = new_document.getDocumentElement().getAttribute(StaticStrings.VERSION_ATTRIBUTE); 211 String old_version = old_document.getDocumentElement().getAttribute(StaticStrings.VERSION_ATTRIBUTE); 212 if (new_version.compareTo(old_version) <= 0) { 213 // Don't need to update file 214 return false; 215 } 216 217 System.err.println("Updating user config.xml from version " + old_version + " to version " + new_version + "..."); 218 219 // Build up the new user config.xml file from the template config.xml with the user's preferences added 220 // Make a backup of the old config.xml file first 221 config_xml_file.renameTo(new File(config_xml_file.getAbsolutePath() + ".old")); 222 223 // Check all of the Argument elements in the new config.xml file 224 NodeList new_argument_elements_nodelist = new_document.getElementsByTagName("Argument"); 225 NodeList old_argument_elements_nodelist = old_document.getElementsByTagName("Argument"); 226 for (int i = 0; i < new_argument_elements_nodelist.getLength(); i++) { 227 Element new_argument_element = (Element) new_argument_elements_nodelist.item(i); 228 String new_argument_element_name = new_argument_element.getAttribute("name"); 229 String new_argument_element_value = XMLTools.getElementTextValue(new_argument_element); 230 231 // Did this Argument have a non-default value set? 232 for (int j = old_argument_elements_nodelist.getLength() - 1; j >= 0; j--) { 233 Element old_argument_element = (Element) old_argument_elements_nodelist.item(j); 234 String old_argument_element_name = old_argument_element.getAttribute("name"); 235 236 // Argument found 237 if (old_argument_element_name.equals(new_argument_element_name)) { 238 String old_argument_element_value = XMLTools.getElementTextValue(old_argument_element); 239 if (!old_argument_element_value.equals(new_argument_element_value)) { 240 XMLTools.setElementTextValue(new_argument_element, old_argument_element_value); 241 } 242 243 // We don't care about this option any more 244 old_argument_element.getParentNode().removeChild(old_argument_element); 245 break; 246 } 247 } 248 } 249 250 // Are there any old Argument elements left over? Keep these around for old time's sake 251 old_argument_elements_nodelist = old_document.getElementsByTagName("Argument"); 252 if (old_argument_elements_nodelist.getLength() > 0) { 253 NodeList new_gathererconfig_elements_nodelist = new_document.getElementsByTagName("GathererConfig"); 254 if (new_gathererconfig_elements_nodelist.getLength() > 0) { 255 Element new_gathererconfig_element = (Element) new_gathererconfig_elements_nodelist.item(0); 256 new_gathererconfig_element.appendChild(new_document.createComment(" Legacy options ")); 257 258 // Add the legacy Arguments to the GathererConfig element 259 for (int i = 0; i < old_argument_elements_nodelist.getLength(); i++) { 260 Element old_argument_element = (Element) old_argument_elements_nodelist.item(i); 261 new_gathererconfig_element.appendChild(new_document.importNode(old_argument_element, true)); 262 } 263 } 264 } 265 266 // Keep all the Mapping elements 267 NodeList new_directorymappings_elements_nodelist = new_document.getElementsByTagName("DirectoryMappings"); 268 if (new_directorymappings_elements_nodelist.getLength() > 0) { 269 Element new_directorymappings_element = (Element) new_directorymappings_elements_nodelist.item(0); 270 271 NodeList old_mapping_elements_nodelist = old_document.getElementsByTagName("Mapping"); 272 for (int i = 0; i < old_mapping_elements_nodelist.getLength(); i++) { 273 Element old_mapping_element = (Element) old_mapping_elements_nodelist.item(i); 274 new_directorymappings_element.appendChild(new_document.importNode(old_mapping_element, true)); 275 } 276 } 277 278 // Check all of the Associations elements in the new config.xml file 279 NodeList new_entry_elements_nodelist = new_document.getElementsByTagName("Entry"); 280 NodeList old_entry_elements_nodelist = old_document.getElementsByTagName("Entry"); 281 for (int i = 0; i < new_entry_elements_nodelist.getLength(); i++) { 282 Element new_entry_element = (Element) new_entry_elements_nodelist.item(i); 283 String new_entry_element_name = new_entry_element.getAttribute("extension"); 284 String new_entry_element_value = XMLTools.getElementTextValue(new_entry_element); 285 286 // Did this Entry have a non-default value set? 287 for (int j = old_entry_elements_nodelist.getLength() - 1; j >= 0; j--) { 288 Element old_entry_element = (Element) old_entry_elements_nodelist.item(j); 289 String old_entry_element_name = old_entry_element.getAttribute("extension"); 290 291 // Entry found 292 if (old_entry_element_name.equals(new_entry_element_name)) { 293 String old_entry_element_value = XMLTools.getElementTextValue(old_entry_element); 294 if (!old_entry_element_value.equals(new_entry_element_value)) { 295 XMLTools.setElementTextValue(new_entry_element, old_entry_element_value); 296 } 297 298 // We don't care about this option any more 299 old_entry_element.getParentNode().removeChild(old_entry_element); 300 break; 301 } 302 } 303 } 304 305 // Are there any old Entry elements left over? We want to keep these 306 old_entry_elements_nodelist = old_document.getElementsByTagName("Entry"); 307 if (old_entry_elements_nodelist.getLength() > 0) { 308 NodeList new_associations_elements_nodelist = new_document.getElementsByTagName("Associations"); 309 if (new_associations_elements_nodelist.getLength() > 0) { 310 Element new_associations_element = (Element) new_associations_elements_nodelist.item(0); 311 312 // Add the legacy Entries to the Associations element 313 for (int i = 0; i < old_entry_elements_nodelist.getLength(); i++) { 314 Element old_entry_element = (Element) old_entry_elements_nodelist.item(i); 315 new_associations_element.appendChild(new_document.importNode(old_entry_element, true)); 316 } 317 } 318 } 319 320 // Write out the updated config.xml file 321 XMLTools.writeXMLFile(config_xml_file, new_document); 322 return true; 212 323 } 213 324 -
trunk/gli/src/org/greenstone/gatherer/Gatherer.java
r9865 r9869 146 146 // Load GLI config file 147 147 new Configuration(gsdl_path, gsdl3_path, site_name); 148 if (Configuration.just_ created_new_config_file) {148 if (Configuration.just_updated_config_xml_file) { 149 149 // Delete the plugins.dat and classifiers.dat files 150 150 PluginManager.clearPluginCache();
Note:
See TracChangeset
for help on using the changeset viewer.