Posts Tagged ‘blackberry’

Managing delicious(del.icio.us) bookmarks from BlackBerry Java application

Posted by guptaradhesh on October 14, 2010

Managing delicious(del.icio.us) bookmarks from BlackBerry Java application

With an aim to fetch (manage) the bookmarks in a del.icio.us account to the blackberry device, I searched for java api’s I can get from delicious.

Being able to easily get the java api’s delicious jars (http://sourceforge.net/projects/delicious-java/), i tried using the methods available for managing bookmarks. Got stuck somewhere-

the del.icio.us api’s use java.util.List internally in most of the methods. BlackBerry Api’s doesn’t provide with this java.util.List classes etc. Trying to add java.unit.List jar was a big overhead – moreover the jar I found was of around 20MB+.

As an alternate to it – I tried with using web api’s provided by delicious (http://delicious.com/help/api) . Sending concerned request url would fetch/manage according bookmarks.

Another hitch which I encountered for the same was to send login credentials. I tried sending the request in the form e.g. https://username:password@api.del.icio.us/v1/posts/all – (this url works with firefox but throws error with IE – don’t know way??), but it gives MALFormedUrl Exception.

I found that there is some standard way(not sure whether standard or not) to send login credentials for http-requests. One needs to make Byte64 encoded byte string of “username:password” and attach it as authorization property to the http request.

Being unable to find apache’s commom-codec-3.jar, the Base64 didn’t work. Thankfully, BB Api’s provide with Base64.

The code snippet for fetching most recent bookmarks from a delicious account is as:

String url = "https://api.del.icio.us/v1/posts/recent?";
String loginString = "pensivemode:Aditi01*";
try {
authString = Base64OutputStream.encodeAsString(loginString.getBytes(), 0, loginString.length(), false, false);
catch (IOException e) {
Status.show("problem with base64");
connection = (HttpConnection) Connector.open(url);
connection.setRequestProperty("Authorization", "Basic " + authString);
 InputStream inpStream = connection.openInputStream();

The delicious api returns an XML, which can be parsed using DOM or SAX, as per the data required.


Posted in java | Tagged: , , , | Leave a Comment »

Parsing http XML response in JAVA (BlackBerry)

Posted by guptaradhesh on October 14, 2010

Parsing http XML response in JAVA (BlackBerry)

Being foolish/novice enough, I had got stuck in how to parse an XML one receives in form of http response.

I could find many ways where one can parse an XML file – but reading http XML response became a challenge for me. Writing the response to a file and then reading the XML from there was not the ideal way. Being round the bend for quite a while, I was able to get things work.

Here is the code snippet, if anyone wants to refer:


// send http request for XML response via connection object
// input stream http response
InputStream inpStream = connection.openInputStream();
// Parsing XML using SAX
void parseStringXML(InputStream xmlString){
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
Status.show("preparing parse");
sp.parse(xmlString, new Handler());
catch (Throwable t) {
Status.show("exception in ParseStringXML");
// Parse SAX Handler – for getting a particular attribute of a tag
class Handler extends DefaultHandler {
boolean tag = false;
boolean attribute   = false;
public void startElement(String nsURI, String strippedName,
String tagName, Attributes attributes)
if (tagName.equalsIgnoreCase("tagName")){
title = true;
bookMarksReceivedField = new LabelField(attributes.getValue("attribute"), FOCUSABLE );

Posted in java | Tagged: , , , , | Leave a Comment »


Posted by guptaradhesh on October 14, 2010


I tried to find a json me jar to add it to my blackberry project.
Finding difficult to get the same, I made and uploaded this json-jar after compiling the json-me source code and creating the jar by using the standard command-

> jar -cvf json.jar org\json\*.class

To download the Json-me jar, Click here Download
(this jar is pre-verified and can be used for adding an external dependency in a blackberry project)

PS: The source code of json-me has been taken from http://json.org/

Posted in java | Tagged: , , , | Leave a Comment »

Using external jar files in BlackBerry (eclipse blackberry plugin)

Posted by guptaradhesh on October 14, 2010

Using external jar files in BlackBerry (eclipse blackberry plugin)

Here is my experience of trying using external jars with my eclipse blackberry plugin.
I googled hell lot and found many posts and steps for adding external jars to my working BB-project. One needs to pre-varify the external jar before using it.
The steps to be followed for preverifying are available at many places.
Let me mention them once again –

1. Go to your JDE installation folder, for Windows XP it is usually C:\Program Files\Research In Motion\BlackBerry JDE 4.3.0\bin. If you are using eclipse then you can also find the installation directory of BlackBerry plugin.
2. Copy your jar file to bin folder.
3. Notice the preverify.exe file. This is the tool we’ll use.
4. Now open your command prompt and change your current directory to your JDE installation directory.
5. execute the following command:
preverify -classpath “JDE_PATH_HERE\lib\net_rim_api.jar” “your_jar_filename”
6. Notice that in bin directory, another folder named output has been created. Preverified jar file resides here. Copy the preverified jar file with the same name that the non-preverified jar file has.
I have uploaded one such preverified json jar in my previous post.

My experience while accessing the preverified jars-
When I created a blackberry library project and added this self-created preverified jar and added this as an external library to my working project, I was able to use the external library.
I was successful in case of using kxml.jar, but the same thing falters when I use the self-created json.jar.
I hope I didn’t do any mistake while preverifying it.
If anyone is able to use the json.jar as external library project, do post a comment.

Posted in tech | Tagged: , , | 2 Comments »