Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
hiral
Posts: 54
Registered: ‎11-12-2009
My Device: Not Specified

Browser Field : Replace href link with html uri

[ Edited ]

Hi,

 

I am working on the Blackberry net.rim.device.api.browser.field2.BrowserField and its related classes. I load a local html resource using the "local" keyword into the browser field. This local html resource has an anchor tag <a href> which points to another local html resource.

 

My usecase requires me to replace the link in href with the actual html data since the resource wont be available directly. For this I am trying to use the URI scheme with type data &colon; text/html.

 

For example, I have : <a href="local_resource_one.html">

I want to replace it with the html content in the file "local_resource_one.html".

 

I have a CustomController that extends the ProtocolController, and am trying to do this replacement in the handleNavigationRequest, but when I click on this href link, no action occurs and I stay on the same page itself. No exception is thrown.

 

What is possibly going wrong here, how do I replace the html link with its data?

 

public void handleNavigationRequest(BrowserFieldRequest request)
			throws Exception {
String url = request.getURL();
if (url.startsWith("local:///")) {

				String htmlFileName = url.substring(url.lastIndexOf('/') + 1);
				try {
					byte[] htmlBytes = MyResourceManager()
							.getResourceAsBinary(htmlFileName);
					if (htmlBytes != null) {
						String html = new String(htmlBytes);
						request.setURL("data&colon;text/html;charset=utf-8,"+html);

}
}
}
Please use plain text.
Developer
raquibulbari
Posts: 137
Registered: ‎09-30-2009
My Device: Torch 9800

Re: Browser Field : Replace href link with html uri

Instead of using the seturl you can show the html content of html variable by using browserfield.displayContent function
http://docs.blackberry.com/en/developers/deliverables/11958/Display_HTML_from_a_resource_within_your...
----------------------
Press like if you find a message helpful
---------
Please use plain text.
Developer
hiral
Posts: 54
Registered: ‎11-12-2009
My Device: Not Specified

Re: Browser Field : Replace href link with html uri

Agreed, that can be done and I am already doing the same for some other use case.

 

However, for this particular scenario, I need to over-ride the handleNavigationRequest() of the ProtocolController so that for every subsequent request for a local html resource, my replacement code is in place.

Please use plain text.