BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 09-11-2009, 08:52 AM   #1
jj12
New Member
 
Join Date: Sep 2009
Model: 7100T
PIN: N/A
Carrier: AT&T
Posts: 3
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, 12:42 AM   #2
kelumkps
New Member
 
Join Date: Apr 2009
Model: 8800
PIN: N/A
Carrier: Software developer
Posts: 14
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, 06:49 PM   #3
jj12
New Member
 
Join Date: Sep 2009
Model: 7100T
PIN: N/A
Carrier: AT&T
Posts: 3
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-20-2009, 11:22 PM   #4
kelumkps
New Member
 
Join Date: Apr 2009
Model: 8800
PIN: N/A
Carrier: Software developer
Posts: 14
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, 09:33 AM   #5
mdwheaton
Thumbs Must Hurt
 
Join Date: Feb 2007
Model: 8100
Carrier: T-Mobile
Posts: 54
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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


OEM Battery for MacBook Pro 17

OEM Battery for MacBook Pro 17" A1309 A1297 Early 2009 Mid 2009 2010 MC226

$42.80



NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch picture

NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch

$35.90



NEW OEM A1618 Battery for Apple MacBook Pro 15” Retina 99.5Wh A1398 Mid 2015 picture

NEW OEM A1618 Battery for Apple MacBook Pro 15” Retina 99.5Wh A1398 Mid 2015

$49.90



Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013 picture

Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013

$37.90



Genuine OEM A1417 Battery For Apple Macbook Pro 15

Genuine OEM A1417 Battery For Apple Macbook Pro 15" Retina A1398 2012 2013 NEW

$38.90



A1618 NEW OEM Battery for MacBook Pro 15

A1618 NEW OEM Battery for MacBook Pro 15" Retina A1398 Mid 2015 020-00079

$49.90







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