- Timestamp:
- 2004-01-28T14:37:50+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.