Hello Chris,

I have noticed Dimitry reported some issues with opening files, issues that
appeared after the replacement of toURL() call with toURI().toURL() call.

Attached please find a method from FreeMind.java that works fine for me on
Windows Vista, in conjunction with URLs passed to it that are created using
toURI().toURL() call.

The key change is located at:

                if (url.getProtocol().equals("file")) {
                    command = "rundll32 url.dll,FileProtocolHandler
"+url.toString();
                    //The above used to be (?) Tools.urlGetFile(url); The

I have only tested the change on a Windows Vista machine; other Windows
versions like Windows XP need to be tested too.

Best regards,
Dan


-------------

    /** Opens url in a web browser. Hides some differences between operating
systems. */
    public void openURL(URL url) throws Exception {
        // Originally, this method determined external application, with
which the document
        // should be opened. Which application should open which document
type was
        // configured in FreeMind properties file. As a result, FreeMind
tried to solve the
        // problem (of determining application for a file type), which
should better be
        // solved somewhere else. Indeed, on Windows, this problem is
perfectly solved by
        // Explorer. On KDE, this problem is solved by Konqueror default
browser. In
        // general, most WWW browsers have to solve this problem.

        // As a result, the only thing we do here, is to open URL in WWW
browser.

        String osName = System.getProperty("os.name");
        if (osName.startsWith("Win")) {
            String propertyString = new
String("default_browser_command_windows");
                        if (osName.indexOf("9") != -1 ||
osName.indexOf("Me") != -1) {
                                propertyString += "_9x";
                        } else {
                                propertyString += "_nt";
                        }

            String browser_command=new String();
            String command=new String();
            // Here we introduce " around the parameter of explorer
            // command. This is not because of possible spaces in this
            // parameter - it is because of "=" character, which causes
            // problems. My understanding of MSDOS is not so good, but at
            // least I can say, that "=" is used in general for the purpose
            // of variable assignment.
            //String[] call = { browser_command, "\""+url.toString()+"\"" };
            try  {
                // This is working fine on Windows 2000 and NT as well
                // Below is a piece of code showing how to run executables
directly
                // without asking. However, we don't want to do that.
Explorer will run
                // executable, but ask before it actually runs it.
                //
                // Imagine you download a package of maps containing also
nasty
                // executable. Let's say there is a map "index.mm". This map
contains a
                // link to that nasty executable, but the name of the link
appearing to the
                // user does not indicate at all that clicking the link
leads to execution
                // of a programm.  This executable is located on your local
computer, so
                // asking before executing remote executable does not solve
the
                // problem. You click the link and there you are running
evil executable.

                // build string for default browser:
                // ask for property about browser: fc, 26.11.2003.
                Object[] messageArguments = { url.toString() };
                MessageFormat formatter = new
MessageFormat(getProperty(propertyString));
                browser_command = formatter.format(messageArguments);

                if (url.getProtocol().equals("file")) {
                    command = "rundll32 url.dll,FileProtocolHandler
"+url.toString();
                    //The above used to be (?) Tools.urlGetFile(url); The
                    //current solution works when the URL passed to
                    //this method has been created properly, using
                    //toURI().toURL() instead of toURL(). I have
                    //however only tested the new solution with
                    //Windows Vista. Still, originally we have been
                    //using deprecated toURL(), so that things are
                    //working fine using pure Java methods now is
                    //unsurprising. --Dan
                } else if (url.toString().startsWith("mailto:";)) {
                    command = "rundll32 url.dll,FileProtocolHandler
"+url.toString();
                } else {
                    command = browser_command;
                }
                //System.out.println("Starting browser with "+command);
                Runtime.getRuntime().exec(command);
            }
            catch(IOException x) {
                Maid.errorMessage("Could not invoke browser.\n\nFreemind
excecuted the following statement on a command
line:\n\""+command+"\".\n\nYou may look at the user or default property
called '"+propertyString+"'.");
                System.err.println("Caught: " + x);
            }
        } else if (osName.startsWith("Mac OS")) {
//             String urlString = url.toString();
//             if (url.getProtocol().equals("file")) {
//                 urlString = urlString.replace('\\','/').replaceAll("
","%20"); }
//             // ^ This is more of a heuristic than a "logical" code

            // System.out.println("Opening URL "+urlString);
            String browser_command=new String();
            try {
                // build string for default browser:
                String correctedUrl = new String(url.toExternalForm());
                // ask for property about browser: fc, 26.11.2003.
                Object[] messageArguments = { correctedUrl, url.toString()
};
                MessageFormat formatter = new
MessageFormat(getProperty("default_browser_command_mac"));
                browser_command = formatter.format(messageArguments);
                Runtime.getRuntime().exec(browser_command); }
            catch(IOException ex2) {
                Maid.errorMessage("Could not invoke browser.\n\nFreemind
excecuted the following statement on a command line:\n\""+
                               browser_command+"\".\n\nYou may look at the
user or default property called 'default_browser_command_mac'.");
                System.err.println("Caught: " + ex2);
            }
        } else {
            // There is no '"' character around url.toString (compare to
Windows code
            // above). Putting '"' around does not work on Linux - instead,
the '"'
            // becomes part of URL, which is malformed, as a result.


           //             String urlString = url.toString();
           //             if (url.getProtocol().equals("file")) {
           //                 urlString =
urlString.replace('\\','/').replaceAll(" ","%20"); }
           //             // ^ This is more of a heuristic than a "logical"
code

            // System.out.println("Opening URL "+urlString);
            String browser_command=new String();
            try {
                // build string for default browser:
                String correctedUrl = new String(url.toExternalForm());
                // ask for property about browser: fc, 26.11.2003.
                Object[] messageArguments = { correctedUrl, url.toString()
};
                MessageFormat formatter = new
MessageFormat(getProperty("default_browser_command_other_os"));
                browser_command = formatter.format(messageArguments);
                Runtime.getRuntime().exec(browser_command); }
            catch(IOException ex2) {
                Maid.errorMessage("Could not invoke browser.\n\nFreemind
excecuted the following statement on a command line:\n\""+
                               browser_command+"\".\n\nYou may look at the
user or default property called "+
                               "'default_browser_command_other_os'.");
                System.err.println("Caught: " + ex2);
            }
        }
    }
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Freemind-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemind-developer

Reply via email to