BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-11-2009, 09:52 AM   #1 (permalink)
New Member
 
Join Date: Sep 2009
Model: 7100T
PIN: N/A
Carrier: AT&T
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Using getDisplayableContent to display raw HTML

Please Login to Remove!

Hi. I've overloaded the HttpConnection class so that it returns a string instead of making a connection. But when I call getDisplayableContent(), the resulting field contains no data. I looked at the connection class and the data is in the class. Does anyone know what we need to do for getDisplayableContent() to display the content? I'm not sure what method it is calling from the connection class because I've tried breakpoitns in all the methods, but they don't get called. Thanks for any help.


Code:
renderingSession = RenderingSession.getNewInstance();
renderingSession.getRenderingOptions().setProperty(RenderingOptions.CORE_OPTIONS_GUID, RenderingOptions.SHOW_IMAGES_IN_HTML, false);
HttpConnection connection = new CustomHttpConn("This is a test.");
BrowserContent browserContent = _renderingSession.getBrowserContent(connection, null, null);
Field field = browserContent.getDisplayableContent();
Offline  
Old 09-18-2009, 01:42 AM   #2 (permalink)
New Member
 
Join Date: Apr 2009
Model: 8800
PIN: N/A
Carrier: Software developer
Posts: 14
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can implement javax.microedition.io.HttpConnection interface so that it takes your text like this.

Code:
public class HttpConnectionImpl implements HttpConnection {
private DataInputStream dataInput;
private InputStream in;
private String encoding = "text/html";

public HttpConnectionImpl(String text) {
try {
in = new ByteArrayInputStream(text.getBytes("UTF-8"));
dataInput = new DataInputStream(in);
} catch (Exception e) {
System.out.println("HttpConnectionImpl : Exception : " + e);
}

}

// implement rest of the methods of HttpConnection interface with dummy methods


}

Then you can pass an object of this implementation to get the field as follows;

Code:
String text= "This is a test.";

HttpConnection connection = new HttpConnectionImpl(text);

renderingSession = RenderingSession.getNewInstance();

renderingSession.getRenderingOptions().setProperty(RenderingOptions.CORE_OPTIONS_GUID, RenderingOptions.SHOW_IMAGES_IN_HTML, false);

BrowserContent browserContent = renderingSession.getBrowserContent(connection, null, null);

Field field = browserContent.getDisplayableContent();


Regards,

-Kelum-
Offline  
Old 09-20-2009, 07:49 PM   #3 (permalink)
New Member
 
Join Date: Sep 2009
Model: 7100T
PIN: N/A
Carrier: AT&T
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

Thank you for your help. But it seems nothing is being displayed after implementing your code. I must be doing something incorrect. Here's my connection class.

Code:
public class LocalHttpConn implements HttpConnection {
	private InputStream is = null;

	public LocalHttpConn(String html){
		try 
		{
			is = new ByteArrayInputStream(html.getBytes("UTF-8"));
		}
		catch(Exception e) {}
	}
	
	public LocalHttpConn(byte[] bits){
		is = new ByteArrayInputStream(bits);
	}
	
	public long getDate() throws IOException {
		return 0;
	}

	public long getExpiration() throws IOException {
		return 0;
	}

	public String getFile() {
		return null;
	}

	public String getHeaderField(String name) throws IOException {
		return null;
	}

	public String getHeaderField(int n) throws IOException {
		return null;
	}

	public long getHeaderFieldDate(String name, long def)
			throws IOException {
		return 0;
	}

	public int getHeaderFieldInt(String name, int def) throws IOException {
		return 0;
	}

	public String getHeaderFieldKey(int n) throws IOException {
		return null;
	}

	public String getHost() {
		return null;
	}

	public long getLastModified() throws IOException {
		return 0;
	}

	public int getPort() {
		return 0;
	}

	public String getProtocol() {
		return null;
	}

	public String getQuery() {
		return null;
	}

	public String getRef() {
		return null;
	}

	public String getRequestMethod() {
		return null;
	}

	public String getRequestProperty(String key) {
		return null;
	}

	public int getResponseCode() throws IOException {
		return 200;
	}

	public String getResponseMessage() throws IOException {
		return "OK";
	}

	public String getURL() {
		return "";
	}

	public void setRequestMethod(String method) throws IOException {
		return;
	}

	public void setRequestProperty(String key, String value)
			throws IOException {
		return;
	}

	public String getEncoding() {
		return "UTF-8";
	}

	public long getLength() {
		try {
			if (is != null )
				return is.available();
			else return 0;
		} catch (IOException e) {
		}
		return 0L;
	}

	public String getType() {
		return "text/html";
	}

	public DataInputStream openDataInputStream() throws IOException {
		return new DataInputStream(new ByteArrayInputStream(html.getBytes("UTF-8")));
	}

	public InputStream openInputStream() throws IOException {
		return is;
	}

	public void close() throws IOException {
		is.close();
		return;
	}

	public DataOutputStream openDataOutputStream() throws IOException {
		return null;
	}

	public OutputStream openOutputStream() throws IOException {
		return null;
	}

This is the main code

Code:
		try
		{
			_renderingSession = RenderingSession.getNewInstance();		
			HttpConnection connection1 = new LocalHttpConn("<html>test is a test</html>");
			BrowserContent browserContent = _renderingSession.getBrowserContent(connection1, null, null);
			
			Field field = browserContent.getDisplayableContent();		
			tab1Manager.add(field);
		}
There are no errors when I run it, but the browser displays nothing and I don't get any errors. Thanks for any help.
Offline  
Old 09-21-2009, 12:22 AM   #4 (permalink)
New Member
 
Join Date: Apr 2009
Model: 8800
PIN: N/A
Carrier: Software developer
Posts: 14
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think the reason is implementation of the rest of the methods of javax.microedition.io.HttpConnection interface. Don't implement those methods to return null values. You can see below how I implemented it.

Code:
public class HttpConnectionImpl implements HttpConnection {
    private long streamLength = 7000;
    private DataInputStream dataInput;
    private InputStream in;
    private String encoding = "text/html";

    public HttpConnectionImpl(String data) {
        try {
            in = new ByteArrayInputStream(data.getBytes("UTF-8"));
            dataInput = new DataInputStream(in);
        } catch (Exception e) {
            System.out.println("HttpConnectionImpl : Exception : " + e);
        }

    }

    public String getURL() {
        return "";
    }

    public String getProtocol() {
        return "";
    }

    public String getHost() {
        return "";
    }

    public String getFile() {
        return "";
    }

    public String getRef() {
        return "";
    }

    public String getQuery() {
        return "";
    }

    public int getPort() {
        return 0;
    }

    public String getRequestMethod() {
        return "";
    }

    public void setRequestMethod(String s) throws IOException {

    }

    public String getRequestProperty(String s) {
        return "";
    }

    public void setRequestProperty(String s, String s1) throws IOException {

    }

    public int getResponseCode() throws IOException {
        return 200;
    }

    public String getResponseMessage() throws IOException {
        return "";
    }

    public long getExpiration() throws IOException {
        return 0;
    }

    public long getDate() throws IOException {
        return 0;
    }

    public long getLastModified() throws IOException {
        return 0;
    }

    public String getHeaderField(String s) throws IOException {
        return "";
    }

    public int getHeaderFieldInt(String s, int i) throws IOException {
        return 0;
    }

    public long getHeaderFieldDate(String s, long l) throws IOException {
        return 0;
    }

    public String getHeaderField(int i) throws IOException {
        return "";
    }

    public String getHeaderFieldKey(int i) throws IOException {
        return "";
    }

    public String getType() {
        return "text/html";
    }

    public String getEncoding() {
        return encoding;
    }

    public long getLength() {
        return streamLength;
    }

    public InputStream openInputStream() throws IOException {
        return in;
    }

    public DataInputStream openDataInputStream() throws IOException {
        return dataInput;
    }

    public void close() throws IOException {

    }

    public OutputStream openOutputStream() throws IOException {
        return new ByteArrayOutputStream();
    }

    public DataOutputStream openDataOutputStream() throws IOException {
        return new DataOutputStream(new ByteArrayOutputStream());
    }
}

Try this way and hope it'll work for you.

Cheers,

-Kelum-
Offline  
Old 09-28-2009, 10:33 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2007
Model: 8100
Carrier: T-Mobile
Posts: 54
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm having the same problem as JJ
I've posted in the BlackBerry (RIM) forums as well.
I feel stupid at this point that this isn't working.
Did you get this working JJ?
If so, could you please post your Screen code, and the HttpConnectionImpl classes?
This is driving me insane that I can't get this working!!!
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.