|
|
||
|
| ||
Part 3 Java XML Programmers Reference Chapter 11: XML Tools for Information Appliances October 8, 2001
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)
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: Coming Up Next: Setting Up the Environment | ||
|
PAGE: 1 | 2 | 3 | 4 | 5 | 6 | FIRST PAGE |
||













