Thursday, June 5, 2014

Howto use Xulrunner instead of Internet explorer as browser component in a Notes RCP

One of the coolest features in Notes RCP applications is, that you can embed a browser widget in your application. You can use the browser widget as a document viewer, to view an interactive map for example with openlayer, or to visualize your data as a chart with dojo chart running inside the browser widget.




The browser widget in a Notes RCP application uses the built in browser of your operating system. For example on Windows this is always the internet explorer no matter what browser you have chosen as default in windows or Notes. IE has some serious disadvantages compared to other rendering engines:
  • IE is very slow when you are using Openlayer maps with many features.
  • Maybe your application will break if IE is updated by an automatic software update from MS.
  • IE can not render .BMP files.
  • IE does not support web standards.
Fortunately there is a XULRunner (rendering engine from Mozilla Firefox) built into Notes and with some tricks you can create a XULRunnner browser widget instead of the IE one. Here is the code with a fallback to IE if something went wrong.

 
    //Get built in XULRunner of Notes for Windows
  Bundle bundle = Platform.getBundle("com.ibm.rcp.xulrunner.runtime.win32.x86"); 
  boolean xulRunnerAvailable = false;
  if (bundle != null) {
   URL resourceUrl = bundle.getResource("xulrunner"); 
   if (resourceUrl != null) {
    try {
     URL fileUrl = FileLocator.toFileURL(resourceUrl);
     File file = new File(fileUrl.getFile().substring(1));
     //Set the XULRunnerPath to the built in runtime.
     System.setProperty("org.eclipse.swt.browser.XULRunnerPath", file.getAbsolutePath()); 
     xulRunnerAvailable = true;
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  }
  //If XulRunner is available get an Instance of Mozilla or if not fallback to IE.
  if (xulRunnerAvailable)
   browser = new Browser(parentComposite, SWT.MOZILLA);
  else
   browser = new Browser(parentComposite, SWT.NONE);


The only drawback of the Xulrunner of Notes is, that it is a little bit dated. So i really hope that IBM will update the instance of XULRunner in future service packs of the Notes client. This is especially important because this Xulrunner runs xPages in the Notes client too.

No comments:

Post a Comment

ad