Changeset 5894


Ignore:
Timestamp:
2003-11-19T14:12:47+13:00 (20 years ago)
Author:
kjdon
Message:

added in getBrowserCommand - uses the file association stuff for linux. but should be removed from here I think.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/file/FileAssociationManager.java

    r4675 r5894  
    9393    }
    9494
     95    public String getBrowserCommand(String url) {
     96    String command = null;
     97    if(Utility.isWindows()) {
     98        // we use cmd and start
     99        if (Utility.isWindows9x()) {
     100        command = "command.com /c start \"\" \""+url+"\"";
     101        } else {
     102        command = "cmd.exe /c start \"\" \""+url+"\"";
     103        }
     104        return command;
     105    }
     106    // for now uder linux get the fileassoc thing. but eventually want a separate thing.
     107    // pretend we are tyring to open an html file
     108    String extension = "html";
     109    Element entry = getCommand(extension);
     110    if (entry != null) {
     111        command = MSMUtils.getValue(entry);
     112    }
     113   
     114    if(command == null || command.length() == 0) {
     115        FileAssociationDialog dialog = new FileAssociationDialog(this);
     116        command = dialog.display(extension);
     117        dialog = null;
     118    }
     119    if(command != null) {
     120        // If no previous entry existed create one.
     121        if(entry == null) {
     122        entry = document.createElement(ENTRY_ELEMENT);
     123        entry.setAttribute(EXTENSION_ATTRIBUTE, extension);
     124        document.getDocumentElement().appendChild(entry);
     125        }
     126        // Replace the text in this node. Remember to replace the dummy filename with %1
     127        MSMUtils.setValue(entry, command.replaceAll("temp.html", FILENAME_ARG));
     128    }
     129   
     130    // if we haven't got a command by now, we'll never get one
     131    if (command == null) return null;
     132    // Replace %1 with the url in quotes
     133    command = command.replaceAll(FILENAME_ARG, url);
     134    return command;
     135    }
     136   
    95137    public String getCommand(File file) {
    96138    String command = null;
     
    103145        if(entry != null) {
    104146        command = MSMUtils.getValue(entry);
     147        }
     148        if(command == null || command.length() == 0) {
     149        // If command is null, and we are on windows try searching the registry.
     150        if(Utility.isWindows()) {
     151            command = WinRegistry.openCommand(filename);
     152        }
     153        // Otherwise display the dialog and ask the user to enter launching command.
    105154        if(command == null || command.length() == 0) {
    106             // If command is null, and we are on windows try searching the registry.
    107             if(Utility.isWindows()) {
    108             command = WinRegistry.openCommand(filename);
     155            // Show the dialog which forces a user to select the launch command for a certain file.
     156            FileAssociationDialog dialog = new FileAssociationDialog(this);
     157            command = dialog.display(extension);
     158            dialog = null;
     159        }
     160        // Hopefully by now we have a command, or else we're never going to get one. Add the association.
     161        if(command != null) {
     162            // If no previous entry existed create one.
     163            if(entry == null) {
     164            entry = document.createElement(ENTRY_ELEMENT);
     165            entry.setAttribute(EXTENSION_ATTRIBUTE, extension);
     166            document.getDocumentElement().appendChild(entry);
    109167            }
    110             // Otherwise display the dialog and ask the user to enter launching command.
    111             if(command == null || command.length() == 0) {
    112             // Show the dialog which forces a user to select the launch command for a certain file.
    113             FileAssociationDialog dialog = new FileAssociationDialog(this);
    114             command = dialog.display(extension);
    115             dialog = null;
    116             }
    117             // Hopefully by now we have a command, or else we're never going to get one. Add the association.
    118             if(command != null) {
    119             // If no previous entry existed create one.
    120             if(entry == null) {
    121                 entry = document.createElement(ENTRY_ELEMENT);
    122                 entry.setAttribute(EXTENSION_ATTRIBUTE, extension);
    123                 document.getDocumentElement().appendChild(entry);
    124             }
    125             // Replace the text in this node. Remember to replace the dummy filename with %1
    126             MSMUtils.setValue(entry, command.replaceAll(filename, FILENAME_ARG));
    127             }
    128         }
    129         if(command != null) {
    130             // We have to fix filename under windows to escape the backslashes.
    131             filename = filename.replaceAll(ESCAPE, ESCAPED_ESCAPE);
    132             // Replace %1 with the appropriate filename
    133             command = command.replaceAll(FILENAME_ARG, filename);
    134         }
    135         }
     168            // Replace the text in this node. Remember to replace the dummy filename with %1
     169            MSMUtils.setValue(entry, command.replaceAll(filename, FILENAME_ARG));
     170        }
     171        }
     172        if(command != null) {
     173        // We have to fix filename under windows to escape the backslashes.
     174        filename = filename.replaceAll(ESCAPE, ESCAPED_ESCAPE);
     175        // Replace %1 with the appropriate filename
     176        command = command.replaceAll(FILENAME_ARG, filename);
     177        }
     178       
    136179        entry = null;
    137180        extension = null;
Note: See TracChangeset for help on using the changeset viewer.