Custom protocol support







ProtocolListener is the listener interface for receiving requests for your own custom protocol implementations.

Through the ProtocolListener event, document loading can be controlled. The ProtocolListener is comprised of the onOpen method that notifies the application upon a request for the protocol. The ProtocolEvent handles the streaming of the content into the document through the startRequest(String contentType), onDataAvailable(byte[ ] data), onStopRequest(int requestStatus).

The custom protocol is registered with the IMozillaBrowserCanvas using the registerProtocol method. The onOpen method is invoked when the browser needs to load a resource from a protocol that this is registered for. This method is always invoked in a new Java thread so multiple invocations of onOpen can happen simultaneously.

Example of use the "hello:" protocol

IMozillaBrowserCanvas browser = BrowserFactory.spawnMozilla();
browser.registerProtocol("hello",new ProtocolListener() {
        public void onOpen(ProtocolEvent e) {
                String url = e.getURL();
                //Start Requst with content type text/html
                //Send the data through, this can be called as many times as needed while data becomes available
                e.onDataAvailable(("<B>Hello</B> World: <EM>" +url.substring(url.indexOf(":")+1,url.length()) +"< /EM>"). getBytes());
                //Tell the browser we are finished and everything went ok.

Loading the url "hello:John" will show :

Hello World: John



 Copyright © JadeLiquid Software - www.jadeliquid.com