TinyBrowser/0.1

This example explores the possibility of using XML as a protocol language between client and server. TinyBrowser introduces itself as "TinyBrowser/0.1" by using User-Agent HTTP header. TinyServer produces an HTML output for the directory that does not contain an "index.html" file. TinyServer handles this process differently when it realizes that the client is TinyBrowser. In this case, TinyServer produces an XML formatted directory representation conforming to the following DTD.

<!ELEMENT xml-stylesheet EMPTY>
<!ATTLIST xml-stylesheet href CDATA #REQUIRED>
<!ATTLIST xml-stylesheet text CDATA >

<!ELEMENT base  (#PCDATA)>
<!ELEMENT title (#PCDATA)>

<!ELEMENT ances  (ances*)>
<!ATTLIST ances   name CDATA #REQUIRED>

<!ELEMENT name   (#PCDATA)>
<!ELEMENT date   (#PCDATA)>
<!ELEMENT length (#PCDATA)>
<!ELEMENT type   (#PCDATA)>

<!ELEMENT resource (name,date,length,type)>

<!ELEMENT directory (xml-stylesheet?,base?,title?,ances,resource*)>
Figure 1:

TinyServer handles HTTP Requests. It produces HTML representation of directory if the client is not TinyBrowser and XML representation if it is.

Directory of /xmlstu/
Up to /

File Name Size Type Last Nodified
aa.html 540 bytes  text/html  10 Mar 1999 15:09:18 GMT
bb.html 221 bytes  text/html  10 Mar 1999 15:09:19 GMT
.. .. .. ..

Processed by TinyServer 1.0

Figure 2:

A snopshot of /xmlstu/ directory when browsed with Navigator. TinyServer returns an HTML representation of the directory to the client since it is not TinyBrowser.

This example contains the following files:

DIRDOM.java

This object extracts the directory structure from the given org.w3c.dom.Document object and it can produce the HTML representation. This object keeps the table of ResourceRecord objects.

ResourceRecord.java

This object encapsulates the resource (file or folder) described in the directory. It contains the name, size, content type, and last modified date information.

GetURL.java

Gets the URL of the page from the user.

TinyBrowser.java

Swing based GUI. This object gets the URL of the page and displays it. It uses JEditorPane object to handle the rendering.

TinyBrowser has very limited functionality; opening a page and terminating the program.

Figure 3:

OpenURL option asks the user to enter the URL of the page. Exit terminates the program execution.

When OpenURL option is selected, it asks the URL of the web page in a pop up window (see GetURL). Once the URL is entered, it fetches the page and displays it. If the received content type of data is "text/xml" and it conforms with the DTD given before, then it tries to read this XML formatted data and obtain org.w3c.dom.Document object.

Figure 4:

TinyServer sends the XML formatted directory representation, on the client side this information is parsed with XML parser and a DOM object is build as a representation of this document (protocol).

Figure 5:

User enters the directory name served by TinyServer.

When the received content type produces DOM object, then DIRDOM object is used to build the directory representation. The following code snippet is taken from TinyBrowser

// Get the DOM 
Document doc = web.openDocument(urlConnection.getInputStream(),url.toString());

// Get the Directory object from org.w3c.dom.Document 
DIRDOM dirDOM = new DIRDOM(doc);

// Convert it to HTML for rendering.
htmlPane.setText(dirDOM.toString(url.toString()));

web is an implementation of iwt.web.xmldomxsl.XMLDOMXSL interface. iwt.web.xmldomxsl interfaces are defined in TinyServer to experiment with various parser, DOM implementation, and XSL engines. When the user runs the TinyBrowser, it reads a configuration file (browser.properties is default) to decide the implementations. For example, a possible browser.properties file looks as the following:

org.xml.sax.driver=com.microstar.xml.SAXDriver
org.w3c.domFactory=edu.npac.iwt.IWTDOMFactory
#org.w3c.domFactory=test.xml4j.XMLJDOMFactory
#org.w3c.xslProcessor=test.lotus.LotusXSLProcessor
#org.w3c.xslProcessor=test.xslp.XSLPXSLProcessor
org.w3c.xslProcessor=edu.npac.iwt.IWTXSLProcessor
org.w3c.xmldomxsl=edu.npac.iwt.XMLDOMXSLImpl

-rule [new_config_file_name] option directs the TinyBrowser to read these settings from the given file instead of the default configuration file. Once configuration settings are read, then browser knows which implementation to use. When it requires the implementation of iwt.web.xmldomxsl.XMLDOMXSL interface, it creates the instance of this object with the following code:

...
iwt.web.xmldomxsl.XMLDOMXSL web = null;

String xmldomxsl = props.getProperty("org.w3c.xmldomxsl");

if( xmldomxsl!=null )
{
  try
  {
     Class xmldomxslClass   = Class.forName(xmldomxsl);;
     Object xmldomxslIns  = xmldomxslClass.newInstance();
     if ( xmldomxslIns instanceof iwt.web.xmldomxsl.XMLDOMXSL )
     { 
        web = (iwt.web.xmldomxsl.XMLDOMXSL)xmldomxslIns;
        web.setAll(props);

     } else System.out.println(xmldomxsl+" does not implements iwt.web.xmldomxsl.XMLDOMXSL!");

   } catch(Exception e) 
     { System.out.println(xmldomxsl+" is not reachable!"); }

}// end of if

After DIRDOM object produces the HTML presentation of the directory, it looks as the following.

Figure 6:

When the user browses the directory served by TinyServer, it receives an XML representation of directory structure from the server. Browser parses this message, builds DOM object, and produces HTML representation to able to render it. This snapshot is the result of this process.

TinyServer applies XSL processing on the XML documents if there is a specified XSL file within query string or there is an accessible default.xsl file in the document's directory. In either case, server uses its XSL processor and returns the result of this process to the client.

Figure 7:

A snapshot of GUI after client browses an XML document on the TinyBrowser when the server can find an XSL file to apply before serving. This gives an example of processing XML documents on the server side and producing the presentation output to the client. This is usefull especially some selective presentation process needs to be applied on the raw XML document based on the user's capabilities, clearance, ect..

The user gives the XSL file name within the query string to instruct the server to use particular rules in the XSL Processor. This is the similar student list we have used in the previous examples.

Figure 8:

A snapshot of the GUI after the URL is given. Snapshots are overlapped to show GUI before and after user entered the URL.