Upcoming Events

Cloud Connect
Santa Clara
Feb 13-16, 2012

Cloud Connect brings together the entire cloud eco-system to better understand the transformation we're experiencing and promises to be the defining event of the cloud computing industry. Learn about the latest cloud technologies and platforms from thought leaders in Cloud Connect’s comprehensive conference.

Register Now!

More Events »

Subscribe to Newsletter

  • Keep up with all of the latest news and analysis on the fast-moving IT industry with Network Computing newsletters.
Sign Up

Netdesign Manual

Part 3

Java XML Programmers Reference

Chapter 11: XML Tools for Information Appliances


October 8, 2001


Brought to you by:





Check It Out!

WML TroubleTicketViewer Application

Our last step is to build an application that uses the translet and source XML to generate WML.

You should be able to compile this code with the ant build.xml file available at the Wrox Press web site along with all source code (see Appendix A). Some of this code we've already seen.


import org.apache.xalan.xsltc.*;
import org.apache.xalan.xsltc.dom.DOMImpl;
import org.apache.xalan.xsltc.runtime.TextOutput;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import java.io.FileReader;

public class TroubleTicketViewer  {

  public TroubleTicketViewer(String inputfile)
throws Exception { //load and create the translet Class cls = Class.forName("TroubleTicket"); Translet xlet = (Translet)cls.newInstance(); DOMImpl dom = new DOMImpl(); //will contain the parsed source XML //create SAX 2.0 parser & get the XMLReader
uses object it SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); //Set the DOM's builder as the XMLReader's SAX 2.0
content handler reader.setContentHandler(dom.getBuilder()); //parse reader.parse(new InputSource(new FileReader(inputfile)));
Now that we've parsed the source XML and have it in DOM, let's tell the translet to do the translation. We'll have the translet put the translated document into another DOMImpl object, wmlDOM, although we could have passed it a SAX 1.0 handler to receive callbacks instead.

DOMImpl wmlDOM = new DOMImpl(); //implements

sax.DocumentHandler

TextOutput txtOutput; //implements

TransletOutputHandler

txtOutput = new TextOutput(wmlDOM.getBuilder());

//pass the translet the source XML and a handler

xlet.transform(dom, txtOutput);



Finally, let's output the WML to stdout:

wmlDOM.print(1, 1); //print the root and its children

}

public static void main(String[] args) throws Exception

{

TroubleTicketViewer ttv = new

TroubleTicketViewer(args[0]);

}

}

Run the application:

> java TroubleTicketViewer TroubleTicket.xml



You should get this WML output. It's not pretty, but it's what we expect:

<wml><card

title="Ticket:T746284"

id="T746284"><p><b>Installation failed</b>

<br></br>

<br></br>

Int'l Steel<br></br>

Ann McKinsey<br></br>

303-781-7777<br></br>

SteelPlant2001</p>

</card>

</wml>

The Future

As XSLTC begins to benefit from the open source development cycle at Apache, expect new initiatives for transformation in the information appliance arena. Translets are ideally placed to foster a viable peer-to-peer environment on small devices, bringing with them the power of universal transformation to the growing support for XML on these appliances. Keep an eye on the xalan-dev@xml.apache.org mailing list!

SOAP On Lightweight Clients

The potential for SOAP on lightweight clients is big. SOAP is notoriously slow and resource-intensive compared to RPC, CORBA, and JNI calls, but with more powerful information appliances becoming available each day, this hopefully won't be an issue soon. Simple and relatively infrequent calls, such as requests for weather or stock data from HTTP SOAP servers, are certainly feasible with today's information appliances.

There are currently two lightweight Java SOAP libraries that are worth mentioning:

  • KVM kSOAP


  • nanoSOAP, implementing only SOAP 1.0 and, unfortunately, no longer supported


Coming Up Next: Setting Up the Environment


PAGE: 1 | 2 | 3 | 4 | 5 | 6 | FIRST PAGE
 

Research and Reports

Hypervisor Derby
August 2011

Network Computing: August 2011

TechWeb Careers