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.
|
Directory of /xmlstu/
Processed by TinyServer 1.0 | ||||||||||||||||
|
This example contains the following files:
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.
This object encapsulates the resource (file or folder) described in the directory. It contains the name, size, content type, and last modified date information.
Gets the URL of the page from the user.
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.
|
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.
|
|
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.
|
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.
|
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.
|