zongaro 2003/02/03 14:35:43
Modified: java/samples/CompiledBrazil Tag: XSLTC_DTM README.brazil
Log:
Updated README to remove references to the XSLTC Native API. Also added more
details on how to use the sample in a Brazil server.
Revision Changes Path
No revision
No revision
1.2.12.1 +19 -125 xml-xalan/java/samples/CompiledBrazil/README.brazil
Index: README.brazil
===================================================================
RCS file: /home/cvs/xml-xalan/java/samples/CompiledBrazil/README.brazil,v
retrieving revision 1.2
retrieving revision 1.2.12.1
diff -u -r1.2 -r1.2.12.1
--- README.brazil 19 Jul 2001 12:48:34 -0000 1.2
+++ README.brazil 3 Feb 2003 22:35:43 -0000 1.2.12.1
@@ -3,7 +3,6 @@
o) HOW TO PROVIDE XSL TRANSFORMATIONS AS A WEB SERVICE
o) HOW TO INVOKE TRANSLETS FROM A BRAZIL HANDLER
- o) BUILDING YOUR OWN DOM CACHE
------------------------------------------------------------
HOW TO PROVIDE XSL TRANSFORMATIONS AS A WEB SERVICE
@@ -18,144 +17,39 @@
"handler", which very much resembles a servlet.
The CompiledEJB and CompiledServlet sample code
-demonstrate other aproaches to providing XSL transformations
+demonstrate other approaches to providing XSL transformations
as a web service.
------------------------------------------------------------
HOW TO INVOKE TRANSLETS FROM A BRAZIL HANDLER
-The .CompiledBrazil directory contains the example source code:
+The CompiledBrazil directory contains the example source code:
TransformHandler.java
This file contains a minimal implementation of an XSL
-transformation handler. The handler performs the same basic
-steps as the class implementing the XSLTC command-line tool:
+transformation handler. You can find a precompiled version
+in xsltcbrazil.jar.
- // Obtain a reference to the translet class
- Class cls = Class.forName(transletName);
- // Instanciate a translet object (inherits AbstractTranslet)
- AbstractTranslet translet = (AbstractTranslet)cls.newInstance();
-
- // Prepare the internal DOM tree
- final DOMImpl dom = new DOMImpl();
- dom.setDocumentURI(inputURI);
-
- // Create a parser for the input document
- // org.apache.xalan.xsltc.runtime.Constants sets NAMESPACE_FEATURE
- final SAXParserFactory facory = SAXFactory.newInstance();
- try {
- factory.setFeature(NAMESPACE_FEATURE,true);
- }
- catch (Exception e) {
- factory.setNamespaceAware(true);
- }
- parser = factory.newSAXParser();
- reader = parser.getXMLReader();
- reader.setContentHandler(dom.getBuilder());
-
- // Create a DTDMonitor for handling ID references in the DTD
- DTDMonitor dtdMonitor = new DTDMonitor();
- dtdMonitor.handleDTD(reader);
-
- // Create output handler (you can plug in your own)
- DefaultSAXOutputHandler saxHandler;
- saxHandler = new DefaultSAXOutputHandler(out);
-
- // Parse the document and build the internal DOM
- reader.parse(inputURI);
-
- // Pass information on id/key indicies to the translet
- translet.setIndexSize(dom.getSize());
- dtdMonitor.buildIdIndex(dom, 0, translet);
- translet.setUnparsedEntityURIs(dtdMonitor.getUnparsedEntityURIs());
-
- // Start the transformation
- translet.transform(dom, new TextOutput(saxHandler));
-
-Alternatively the handler can use a cache for storing
-frequently accessed XML documents. This is not only a matter
-of reading the initial input document from the cache, as
-the translet may load other XML input documents as runtime.
-(If the xsl:document() function was used in the stylesheet.)
-
- // Get a reference to the translet class
- Class cls = Class.forName(transletName);
-
- // Instanciate a translet object (inherits AbstractTranslet)
- AbstractTranslet translet = (AbstractTranslet)cls.newInstance();
-
- // The translet needs a reference to the cache in case
- // in needs to load additional XML documents.
- translet.setDOMCache(cache);
-
- // Get the DOM from the DOM cache
- DOMImpl dom = cache.retrieveDocument(documentURI, 0, translet);
-
- // Create output handler (you can plug in your own)
- DefaultSAXOutputHandler saxHandler;
- saxHandler = new DefaultSAXOutputHandler(out);
+Compile any stylesheets you're interested in into translets.
+Set your CLASSPATH to include xalan.jar, xercesImpl.jar,
+xml-apis.jar, your translet classes and the Brazil server
+jar file.
- // Start the transformation
- translet.transform(dom, new TextOutput(saxHandler));
+You can now set up the Brazil server to service requests by
+using the following command:
-------------------------------------------------------------
-BUILDING YOUR OWN DOM CACHE
-
-The interface for the DOM cache consists of a single method,
-and its definition can be found in:
-
- org/apache/xalan/xsltc/DOMCache.java
-
-The method contained in the interface is:
-
- public DOMImpl retrieveDocument(String uri,
- int mask,
- Translet translet);
-
-The responsibilities of this method are:
-
- A) Build new a DOMImpl and DTDMonitor for XML documents
- that are not already in the cache:
-
- // Instanciate a DOMImpl object
- Parser parser = new Parser();
- DOMImpl dom = new DOMImpl();
- dom.setDocumentURI(uri);
- parser.setDocumentHandler(dom.getBuilder());
-
- // Use a DTDMonitor to track ID references in DTD
- DTDMonitor dtdMonitor = new DTDMonitor();
- parser.setDTDHandler(dtdMonitor);
-
- // Parse the input document and build DOM
- parser.parse(uri);
-
- At this point the DOMImpl and DTDMonitor objects are
- populated with the necessary data. The two objects
- are ready to be put in the cache (using the URI as
- the lookup key).
-
- B) For each time a new document is requested by a translet:
-
- // Expand translet's index array to fit this DOM
- translet.setIndexSize(dom.getSize());
-
- // Build indices for this DOM's DTD's ID references
- dtd.buildIdIndex(dom, mask, translet);
-
- // Pass unparsed entity URIs to the translet
- translet.setUnparsedEntityURIs(dtd.getUnparsedEntityURIs());
-
-Step A) must be done every time a document is read into the
-cache, and step B) every time a document is given to a
-translet.
+$ java
-Djavax.xml.transform.TransformerFactory=org.apache.xalan.xsltc.TransformerFactoryImpl
\
+ sunlabs.brazil.server.Main -port 8080 \
+ -handler TransformHandler
-The XSLTC package contains an example implementation of a
-DOM cache, based on a very simple round-robin caching
-algorithm:
+In a browser, you can enter a URI similar to the following:
- org/apache/xalan/xsltc/dom/DocumentCache.java
+ http://localhost:8080/?translet=myTrans&document=myDoc
+where "myTrans" is the URI of a stylesheet that you've
+compiled into a translet and "myDoc" is URI of an XML document
+you'd like to process using that stylesheet. The result of
+the transformation will be displayed in your browser.
------------------------------------------------------------
END OF README
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]