Introduction- In JAVA/Android, we don”t have any utility we can now use RESTLET framework to generate Entity Classes similarly to .NET or PHP. Depending on your preference, you can either follow the
1.Restlet Framework Method
2.Manual Method.
1.Restlet Framework Method- This method requires you to download these custom library files. After which, you need to follow the steps mentioned below.
First, copy the org directory from the downloaded custom library files to your java src directory
Next, add reference to libraries. They are namely
org.restlet.jar
org.restlet.ext.xml.jar
org.restlet.ext.freemarker.jar
org.restlet.ext.atom.jar
org.freemarker.jar
Run the Generator Class to generate entity and helper classes
Add authentication information
Executing the query to get back the dataset
The sample code for consuming data via Restlet for Java is now available.
2. Manual Method – The same idea as querying the Data Service from your Web Browser.
//Creating a URLConnection.
URL url = new URL(“{Data Service URI Here}” + “[?$filter={filters here}(Optional)]“);
//Adding Authentication Information.
conn.addRequestProperty(“AccountKey”, “{Account Key Value Here}”);
conn.addRequestProperty(“UniqueUserID”, “{GUID Value Here}”);
//Executing the URLConnection and getting the result in Atom Feed format.
BufferedReader bf = new BufferedReader(new InputStreamReader(conn.getInputStream()),8000);
Oh, what about the XML now? How do i format the XML returned?
Parsing Atom Feed using an easy(read lazy) way
The properties of the Entity in the results is encapsulated by the ”<m:properties>” tag.
Assuming that the atom feed is stored in a String variable myAtomFeed,
we can get the entities by splitting by the string “<m:properties>”.
//This will return you an array of String. myAtomFeed.split(“<m:properties>”)
You can easily iterate through this array of String and get the properties values out by doing a getStringBetween() custom function to extract the values between the two string values found in the specified string.getStringBetween() source (for the lazy ones like me
):
public static String getStringBetween(String src, String start, String end)
{
StringBuilder sb = new StringBuilder();
int startIdx = src.indexOf(start) + start.length();
int endIdx = src.indexOf(end);
while(startIdx < endIdx){
sb.append("" + String.valueOf(src.charAt(startIdx)));
startIdx++;
}
return sb.toString();
}
usage: if we have a string variable
myAtomFeed = "<d:CuisineType>Malay</d:CuisineType>" getStringBetween(myAtomFeed,"<d:CuisineType>","</d:CuisineType>");
By executing this, we will get the string “Malay” back.
Querying Data Service (Manual Method)

Pingback: Datasets – Singapore Land Transport Authority (LTA) « Project Nimbus
Pingback: Datasets – Singapore National Environment Agency (NEA) « Project Nimbus
Pingback: Datasets – HungryGoWhere (HGW) « Project Nimbus
Pingback: Datasets – National Library Board (NLB) « Project Nimbus
Pingback: Datasets – Singapore Post (SP) « Project Nimbus
Pingback: Datasets – ShowNearBy (SNB) « Project Nimbus
Pingback: Datasets – Cinema Online (CO) « Project Nimbus
Pingback: Datasets – Singapore Tourism Board (STB) « Project Nimbus
Pingback: Datasets – Chlkboard (CHKB) | Project Nimbus
Pingback: Datasets – User Contributed Content (USR) | Project Nimbus
Pingback: Datasets – Places.sg | Project Nimbus
Pingback: Datasets – Chlkboard | Project Nimbus