5

I desperately need your expertise in resolving a Windows-7 issue.

Scenario: I have a frame-based Help package that is set up for context-sensitive help calls. A Java application is able to control what page the Help packages opens to by passing a tag representing the desired HTML named anchor to an HTML file called pophelp. This file has javascripting that reads the passed tag from the end of the URL and maps it to the appropriate HTML file in the help package and opens it.

Issue: The above scenario works in Windows XP, but no longer in Windows 7.

Calling mechanism from Java application: rundll32 url.dll,FileProtocolHandler file://filepath/pophelp.html?tag

Summary of findings so far: It appears that url.dll no longer allows parameters to be passed with URLs in Windows 7. Parameters are being stripped. I also tried the same type of call using Desktop.getDesktop().browse() from Java, but it too seems to strip off all parameters after .html.

Sample code:

Original call that works in Windows XP --

Running command: rundll32 url.dll,FileProtocolHandler file://C:\Program Files\App System\App-Editor-8.0.1\help\pophelp.html?TAG=callsubflow

Result: ?TAG=callsubflow is not passed.

New code using Desktop.getDesktop().browse() --

public static void main(String[] args) {

    String url = "file:///C:/Program Files/App System/App-Editor-8.0.1/help/pophelp.html?TAG=callsubflow";

    try {
        if (Desktop.isDesktopSupported()) {
            Desktop desktop = Desktop.getDesktop();
                  if (desktop.isSupported(Desktop.Action.BROWSE)) {
                      desktop.browse(new URI(url.replace(" ", "%20")));
            }
        }

    } catch (IOException e) {
        System.out.println("Unable to open "+url+": "+e.getMessage());

    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

}

Result: ?TAG=callsubflow is not passed.

Any assistance would be appreciated!

Kawili-wili
  • 439
  • 5
  • 16
  • 2
    BasicService seems to work for [Google on Java](http://www.google.com/search?q=java) so it seems this is peculiar to local files. In that case, my WAG is that it was a 'security upgrade' of some sort (though don't ask me to explain it) where this was changed for local files. – Andrew Thompson Mar 23 '11 at 15:33
  • I was thinking the same, but it seemed crazy that there's no workaround or setting to make this work when you need it. I don't like my computer dictating what I can and cannot do in absolute terms. – Kawili-wili Mar 23 '11 at 23:40

2 Answers2

3

I really can't tell why Windows removes parameters on local files. As mentioned in the comments this seams to be some kind of weird restrictions for security. But I once had a similar problem and I found a workaround that fits in this situation as well.
Simply create a local temporary HTML file (without parameters) that redirects you to the desired one (with parameters).
Have a look at these two methods:

// creates w3c conform redirect HTML page
public String createRedirectPage(String url){
    return  "<!DOCTYPE HTML>" +
            "<meta charset=\"UTF-8\">" +
            "<meta http-equiv=\"refresh\" content=\"1; url=" + url + "\">" +
            "<script>" +
            "window.location.href = \"" + url + "\"" +
            "</script>" +
            "<title>Page Redirection</title>" +
            "<!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->" +
            "If you are not redirected automatically, follow the <a href='" + url + "'>link</a>";
}

// creates temporary file with content of redirect HTML page
public URI createRedirectTempFile(String url) {        
    BufferedWriter writer = null;
    File tmpFile = null;
    try {
        // creates temporary file
        tmpFile = File.createTempFile("pophelp", ".html", null);
        // deletes file when the virtual machine terminate
        tmpFile.deleteOnExit(); 
        // writes redirect page content to file 
        writer = new BufferedWriter(new FileWriter(tmpFile));
        writer.write(createRedirectPage(url));
        writer.close();
    }
    catch (IOException e) {
        return null;
    }
    return tmpFile.toURI();
}

Now you can use these like this:

String url = "file:///C:/Program Files/App System/App-Editor-8.0.1/help/pophelp.html?TAG=callsubflow";

if (Desktop.isDesktopSupported()) {
    Desktop desktop = Desktop.getDesktop();
    if (desktop.isSupported(Desktop.Action.BROWSE)) {
        desktop.browse(createRedirectTempFile(url.replace(" ", "%20")));
    }
}
ArcticLord
  • 3,999
  • 3
  • 27
  • 47
1

I have a solution, not a quick (or pretty) solution, but a solution nonetheless :)

rundll32 url.dll,FileProtocolHandler does pass params when using URLs with http/s protocol (try rundll32 url.dll,FileProtocolHandler http://www.google.com?q=google), so you can setup small http server (like Jetty i guess) to serve your help files and show them using

rundll32 url.dll,FileProtocolHandler http://localhost:[helpServerIp]/help/pophelp.html?TAG=callsubflow
Yoav Aharoni
  • 2,672
  • 13
  • 18