Sunday, June 19, 2011

Reading REST from DOM

In our server REST web services return XML (eXtensible Markup Language). XML Maybe it is a little hard to understand, but XML does not DO anything. XML was created to structure, store, and transport information. So Here we also getting XML from our web services.

Here is example that I am getting when I request my inbox from  our REST ful web services

image

The XMLHttpRequest object is used to exchange data with a server (REST web services) behind the scenes.

The XMLHttpRequest object can:

  • Update a web page without reloading the page (getting new data to user site no reloading)
  • Request data from a server after the page has loaded (asking new emails from REST web services)
  • Receive data from a server after the page has loaded (User is in box new email receiving, no reloading )
  • Send data to a server in the background (boosting all our web features)

So it leads me to used XMLHttpRequest to my module also.

The XML DOM defines a standard way for accessing and manipulating XML documents.The XML DOM views an XML document as a tree-structure.All elements can be accessed through the DOM tree. XML DOM content (text and attributes) can be modified or deleted, and new elements can be created. The elements, their text, and their attributes are all known as nodes.Here are some common XMLHttpRequest Object Methods

Method    Description

abort()   

Stops the current request

getAllResponseHeaders() Returns complete set of headers (labels and values) as a string
getResponseHeader("headerLabel") Returns the string value of a single header label
open("method", "URL"[, asyncFlag[, "userName"[, "password"]]]) Assigns destination URL, method, and other optional attributes of a pending request
send(content) Transmits the request, optionally with postable string or DOM object data
setRequestHeader("label", "value") Assigns a label/value pair to the header to be sent with a request

All modern browsers have a built-in XML parser.An XML parser converts an XML document into an XML DOM object - which can then be manipulated with a JavaScript.The following code fragment parses an REST web services resturn my recently recive email in my Inbox (XML document) into an XML DOM object:

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST","http:localhost:8081/DBmail/Madhuka/INBOX1.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

XMLHttpRequest Object Properties

Once a request has been sent, scripts can look to several properties that all implementations have in common, shown in below Table and all properties are read-only.

image

because I did call the my above method in Java script so in browser console we will call the JS method and try  some XML http Request object properties

readyState :   Object status integer:
0 = uninitialized
1 = loading
2 = loaded
3 = interactive
4 = complete

image

status is 4 it means complete

 

onreadystatechange    Event handler for an event that fires at every state change

responseText    String version of data returned from server process

image


responseXML    DOM-compatible document object of data returned from server process

image


status    Numeric code returned by server, such as 404 for "Not Found" or 200 for "OK"


statusText    String message accompanying the status code

image

Now I think we have good idea on XMLHttpRequest object to get Inbox email list xml to local storage in HTML5.

Tuesday, April 19, 2011

Client-side Storages with HTML 5

In this project contain 5 parties but each are integrated and final it will bring new looking new functioning and answering to drawbacks in current email systems.

Today I will point out Client side storage feature that I am doing for this project mainly. There are several reasons to use client-side storage.

  • We can make our app work when the user is offline, possibly sync'ing
  • It make app to performance booster (instead of waiting for it to download again)
  • It is easier programming model, with no server infrastructure required

The technologies for local storages are:

  • Web Storage: it provides a key-value mapping (present implementations only support string-to-string mappings)
  • Web SQL Database: it gives us all the power of SQL relational database.
  • Indexed Database: This is somewhere in between Web Storage and Web SQL Database. Like Web Storage, it's a straightforward key-value mapping, but it supports indexes like those of relational databases
  • File Access: It is an API for reading file content in JavaScript (There are also proposals underway for file writing capabilities)

Lets check the Browser support

here is code for test that I am going to use

function browserSupport(){
console.log("Indexed Database: " + window.mozIndexedDB);
console.log("Web SQL Database: " + window.openDatabase);
console.log("Web Storage: " + typeof(localStorage));
console.log("File Access: " + window.FileReader);
}

1. Lets check this in chrome

image

No indexed Database support (but it was supporting some months ago)

2. Now I will try in Firefox

image

It is support indexed Database but not SQL data bases yet.

3. Now try with Safari

image

No Indexed Databases and file Access

4. Now I will test in IE

image

only it is web storage

5. Final try it out with Opera

image

it is not supporting for indexed and file API

Here is full results

  Chrome   Firefox   Safari   Opera  IE
Web Storage yes yes yes yes yes
Indexed DB   yes      
Web SQL DB yes     yes  
File Access
yes yes      


So all of browser support Web Storage with (key/Value)

Sunday, March 6, 2011

Hello

Thanks for setting up the blog.
Looking forward to your posts.

Our Developer Team

This project arms to build next generation of email system. In here we have five members with supervised by Prof. Gihan Dias. Each of one have separate tasks and objectives for achieving and each of them are interconnected.

Our Developer Team is:

  • Ishara Gunathilake
  • Mithila Karunarathna
  • Shalika Pathirathna
  • Tharindu Rathnayake
  • Madhuka Udantha

We work for to achieve this Next Generation email system that will have more effective database structure, RESTfull interface for email interaction, advance IMAP, offline capabilities for Web based email with used of HTML5. 

After this post you will able to find our each one post on development and their research on their tasks.

We will be grateful Prof. Gihan Dias for giving this idea and guiding us towards to this goal with his grate experiences.