Changeset 6630
- Timestamp:
- 2004-01-28T14:37:50+13:00 (20 years ago)
- Location:
- trunk/gli
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/classes/xml/config.xml
r6622 r6630 1 1 <?xml version="1.0" encoding="UTF-8" ?> 2 2 <!DOCTYPE Configuration [ 3 <!ELEMENT Configuration (GathererConfig, Other, DirectoryMappings )>3 <!ELEMENT Configuration (GathererConfig, Other, DirectoryMappings, Associations)> 4 4 <!ELEMENT GathererConfig (Argument*)> 5 5 <!ELEMENT Argument (#PCDATA)> … … 22 22 name CDATA #REQUIRED 23 23 file CDATA #REQUIRED> 24 <!ELEMENT Associations (Entry*)> 25 <!ELEMENT Entry (#PCDATA)> 26 <!ATTLIST Entry 27 extension CDATA #REQUIRED> 24 28 ]> 25 29 26 <Configuration >30 <Configuration version="2.4"> 27 31 <GathererConfig> 28 32 <!-- ***** General Options: apply globally to the Gatherers execution. ***** --> … … 131 135 <Other/> 132 136 <DirectoryMappings/> 137 <Associations> 138 <Entry extension="doc"/> 139 <Entry extension="gif"/> 140 <Entry extension="htm"/> 141 <Entry extension="html"/> 142 <Entry extension="jpg"/> 143 <Entry extension="jpeg"/> 144 <Entry extension="pdf"/> 145 <Entry extension="png"/> 146 <Entry extension="ps"/> 147 <Entry extension="rtf"/> 148 <Entry extension="txt"/> 149 <Entry extension="text"/> 150 </Associations> 133 151 </Configuration> -
trunk/gli/src/org/greenstone/gatherer/Configuration.java
r6622 r6630 68 68 /** The name of the general Gatherer configuration file. */ 69 69 static final private String CONFIG_XML = "config.xml"; 70 71 static final private String CURRENT_CONFIGURATION_VERSION = "2.4"; 70 72 /** 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). */ 71 73 static final private String GATHERER_CONFIG = "GathererConfig"; … … 189 191 190 192 // Try to reload the configuration. The first place we look is the user specific location 191 File user_config_xml = new File(Utility.getGLIUserFolder(), CONFIG_XML);192 if( user_config_xml != null && user_config_xml.exists()) {193 general_config = Utility.parse( user_config_xml.getAbsolutePath(), false);193 File config_xml = new File(Utility.getGLIUserFolder(), CONFIG_XML); 194 if(config_xml != null && config_xml.exists()) { 195 general_config = Utility.parse(config_xml.getAbsolutePath(), false); 194 196 } 195 197 196 198 // We then try within the gli directory itself 197 199 if(general_config == null) { 198 Fileconfig_xml = new File(CONFIG_XML);200 config_xml = new File(CONFIG_XML); 199 201 if(config_xml.exists()) { 200 202 general_config = Utility.parse(CONFIG_XML, false); 201 203 } 204 } 205 206 // Check the version of the config we have loaded, and if it isn't recent enough, backup the old version, and then create a new config. 207 if(general_config != null) { 208 Element configuration_element = general_config.getDocumentElement(); 209 String configuration_version = configuration_element.getAttribute(StaticStrings.VERSION_ATTRIBUTE); 210 if(!configuration_version.equals(CURRENT_CONFIGURATION_VERSION)) { 211 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Configuration.Obsolete_Config"), Dictionary.get("Configuration.Obsolete_Config_Title"), JOptionPane.ERROR_MESSAGE); 212 general_config = null; 213 configuration_element = null; 214 File backup = new File(config_xml.getAbsolutePath() + ".bak"); 215 config_xml.renameTo(backup); 216 backup = null; 217 } 218 else { 219 configuration_element = null; 220 } 221 configuration_version = null; 202 222 } 203 223 … … 422 442 String email = getString(GENERAL_EMAIL_SETTING, true); 423 443 return (email.length() > 0 ? email : null); 444 } 445 446 public Element getFileAssociations() { 447 NodeList file_association_elements = general_config.getDocumentElement().getElementsByTagName(StaticStrings.ASSOCIATIONS_ELEMENT); 448 return (Element) file_association_elements.item(0); 424 449 } 425 450 -
trunk/gli/src/org/greenstone/gatherer/file/FileAssociationManager.java
r6622 r6630 41 41 extends AbstractTableModel { 42 42 static final public String FILENAME_ARG = "%1"; 43 static final private String DATA_FILENAME = "associations.xml";44 static final private String ENTRY_ELEMENT = "Entry";45 43 static final private String ESCAPE = "\\\\"; // '\' 46 44 static final private String ESCAPED_ESCAPE = "\\\\\\\\"; // '\\' 47 static final private String EXTENSION_ATTRIBUTE = "extension"; 48 private Document document; 45 private Element associations_element; 49 46 private File data_file; 50 47 51 48 public FileAssociationManager() { 52 // If a associations.xml is available in the GLI install directory load it. 53 data_file = new File(Utility.BASE_DIR + DATA_FILENAME); 54 if(data_file.exists()) { 55 document = Utility.parse(data_file, true); 56 } 57 // Load the default associations xml data file. This can be done using the classloader. 58 else { 59 document = Utility.parse(Utility.XML_DIRECTORY + DATA_FILENAME, true); 60 } 49 // Retrieve the associations_element from the config 50 associations_element = Gatherer.config.getFileAssociations(); 61 51 // Initialize the associations. This involves looking through all current associations searching for those with a command of "". 62 if( document != null) {63 NodeList entries = (document.getDocumentElement()).getElementsByTagName(ENTRY_ELEMENT);52 if(associations_element != null) { 53 NodeList entries = associations_element.getElementsByTagName(StaticStrings.ENTRY_ELEMENT); 64 54 for(int i = 0; i < entries.getLength(); i++) { 65 55 Element entry = (Element) entries.item(i); 66 String extension = entry.getAttribute( EXTENSION_ATTRIBUTE);56 String extension = entry.getAttribute(StaticStrings.EXTENSION_ATTRIBUTE); 67 57 String command = MSMUtils.getValue(entry); 68 58 // If we encounter a command of ""... … … 139 129 // pretend we are trying to open an html file 140 130 // Mmmoooo. - jmt12 141 /* 142 String extension = "html"; 143 Element entry = getCommand(extension); 144 if (entry != null) { 145 command = MSMUtils.getValue(entry); 146 } 147 148 if(command == null || command.length() == 0) { 149 FileAssociationDialog dialog = new FileAssociationDialog(this); 150 command = dialog.display(extension); 151 dialog = null; 152 } 153 if(command != null) { 154 // If no previous entry existed create one. 155 if(entry == null) { 156 entry = document.createElement(ENTRY_ELEMENT); 157 entry.setAttribute(EXTENSION_ATTRIBUTE, extension); 158 document.getDocumentElement().appendChild(entry); 159 } 160 // Replace the text in this node. Remember to replace the dummy filename with %1 161 MSMUtils.setValue(entry, command.replaceAll("temp.html", FILENAME_ARG)); 162 } 163 */ 131 164 132 // if we haven't got a command by now, we'll never get one 165 133 if (command == null) { … … 234 202 // If no previous entry existed create one. 235 203 if(entry == null) { 236 entry = document.createElement(ENTRY_ELEMENT);237 entry.setAttribute( EXTENSION_ATTRIBUTE, extension);238 document.getDocumentElement().appendChild(entry);204 entry = associations_element.getOwnerDocument().createElement(StaticStrings.ENTRY_ELEMENT); 205 entry.setAttribute(StaticStrings.EXTENSION_ATTRIBUTE, extension); 206 associations_element.appendChild(entry); 239 207 } 240 208 // Replace the text in this node. Remember to replace the dummy filename with %1 - I dont think the filename will ever be in the comand now … … 258 226 259 227 public Element getCommand(String target_extension) { 260 NodeList entries = document.getDocumentElement().getElementsByTagName(ENTRY_ELEMENT);228 NodeList entries = associations_element.getElementsByTagName(StaticStrings.ENTRY_ELEMENT); 261 229 for(int i = 0; i < entries.getLength(); i++) { 262 230 Element entry = (Element) entries.item(i); 263 String extension = entry.getAttribute( EXTENSION_ATTRIBUTE);231 String extension = entry.getAttribute(StaticStrings.EXTENSION_ATTRIBUTE); 264 232 if(extension.equalsIgnoreCase(target_extension)) { 265 233 entries = null; … … 283 251 284 252 public String getExtension(int index) { 285 NodeList entries = document.getDocumentElement().getElementsByTagName(ENTRY_ELEMENT);253 NodeList entries = associations_element.getElementsByTagName(StaticStrings.ENTRY_ELEMENT); 286 254 if(0 <= index && index < entries.getLength()) { 287 255 Element entry = (Element) entries.item(index); 288 return entry.getAttribute( EXTENSION_ATTRIBUTE);256 return entry.getAttribute(StaticStrings.EXTENSION_ATTRIBUTE); 289 257 } 290 258 return ""; … … 292 260 293 261 public int getRowCount() { 294 NodeList entries = document.getDocumentElement().getElementsByTagName(ENTRY_ELEMENT); 295 return entries.getLength(); 262 return size(); 296 263 } 297 264 … … 307 274 308 275 public void save() { 309 Utility.export(document, data_file);310 276 } 311 277 … … 316 282 // If no previous entry existed create one. 317 283 if(entry == null && command != null) { 318 entry = document.createElement(ENTRY_ELEMENT);319 entry.setAttribute( EXTENSION_ATTRIBUTE, extension);320 document.getDocumentElement().appendChild(entry);284 entry = associations_element.getOwnerDocument().createElement(StaticStrings.ENTRY_ELEMENT); 285 entry.setAttribute(StaticStrings.EXTENSION_ATTRIBUTE, extension); 286 associations_element.appendChild(entry); 321 287 } 322 288 … … 327 293 else { 328 294 // Remove the entry 329 document.getDocumentElement().removeChild(entry);295 associations_element.removeChild(entry); 330 296 } 331 297 entry = null; … … 334 300 335 301 public int size() { 336 NodeList entries = document.getDocumentElement().getElementsByTagName(ENTRY_ELEMENT);302 NodeList entries = associations_element.getElementsByTagName(StaticStrings.ENTRY_ELEMENT); 337 303 return entries.getLength(); 338 304 }
Note:
See TracChangeset
for help on using the changeset viewer.