amiro       01/07/19 05:49:46

  Modified:    java/samples/CompiledServlet README.servlet
  Log:
  Updated readme to reflect recent changes in the current XSLTC native API,
  to mention the NAMESPACE_FEATURE constant, and to remove any anachronistic
  mentions of the "Preview" distriubtion (that was pre Apache).
  
  Revision  Changes    Path
  1.2       +80 -53    xml-xalan/java/samples/CompiledServlet/README.servlet
  
  Index: README.servlet
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/samples/CompiledServlet/README.servlet,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- README.servlet    2001/05/17 15:36:40     1.1
  +++ README.servlet    2001/07/19 12:49:46     1.2
  @@ -1,65 +1,35 @@
  -============================================================
  +=======================================================================
   CONTENTS OF THIS DOCUMENT:
   
     o) HOW TO PROVIDE XSL TRANSFORMATIONS AS A WEB SERVICE
     o) HOW TO INVOKE TRANSLETS FROM A SERVLET
     o) BUILDING YOUR OWN DOM CACHE
   
  -------------------------------------------------------------
  +-----------------------------------------------------------------------
   HOW TO PROVIDE XSL TRANSFORMATIONS AS A WEB SERVICE
   
  -With XSLTC, XSL transformations can be run from within a
  -servlet. The XSLTC preview package contains an example demonstrating
  -how this can be done.
  +With XSLTC, XSL transformations can be run from within a servlet. 
  +This sample code demonstrates how that can be implemented.
   
  -------------------------------------------------------------
  +The CompiledEJB and CompiledBrazil sample code demonstrate other 
  +aproaches to providing XSL transformations as a web service.
  +
  +-----------------------------------------------------------------------
   HOW TO INVOKE TRANSLETS FROM A SERVLET
   
  -The XSLTC preview package contains the example source code:
  +The CompiledServlet directory contains the example source code:
   
       TransformServlet.java
  -
  -This file contains a minimal implementation of an XSL
  -transformation servlet. The servlet performs the same basic
  -steps as the class implementing the XSLT command-line tool:
  -
  -    // 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
  -    final Parser parser = new Parser();
  -    parser.setDocumentHandler(dom.getBuilder());
  -
  -    // Create a DTDMonitor for handling ID references in the DTD
  -    DTDMonitor dtdMonitor = new DTDMonitor();
  -    parser.setDTDHandler(dtdMonitor);
   
  -    // Create output handler (you can plug in your own)
  -    DefaultSAXOutputHandler saxHandler;
  -    saxHandler = new DefaultSAXOutputHandler(out);
  -
  -    // Parse the document and build the internal DOM
  -    parser.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));
  +This file contains a minimal implementation of an XSL transformation 
  +servlet. It utilizes a cache to store the DOM trees for frequently 
  +accessed XML documents. These are not W3C DOM objects; They are 
  +specialized DOMs, native to XSLTC and optimzed for use with compiled 
  +translets. In addition to the initial input XML documents, the cache 
  +may contain DOMs for other XML input documents the translet requires 
  +at runtime, when the xsl:document() function is used in the stylesheet.
   
  -Alternatively the servlet 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.)
  +Here's the essential code in the servlet for doing the transformation:
   
       // Get a reference to the translet class
       Class cls = Class.forName(transletName);
  @@ -71,7 +41,8 @@
       // in needs to load additional XML documents.
       translet.setDOMCache(cache);
   
  -    // Get the DOM from the DOM cache
  +    // Get the DOM from the DOM cache if current, otherwise
  +    // build and cache the DOM first
       DOMImpl dom = cache.retrieveDocument(documentURI, 0, translet);
   
       // Create output handler (you can plug in your own)
  @@ -81,7 +52,7 @@
       // Start the transformation
       translet.transform(dom, new TextOutput(saxHandler));
   
  -------------------------------------------------------------
  +-----------------------------------------------------------------------
   BUILDING YOUR OWN DOM CACHE
   
   The interface for the DOM cache consists of a single method,
  @@ -103,15 +74,18 @@
           // Instanciate a DOMImpl object
           Parser  parser = new Parser();
           DOMImpl dom = new DOMImpl();
  +        // Set URI for imports, includes, and document() functions
           dom.setDocumentURI(uri);
  -        parser.setDocumentHandler(dom.getBuilder());
  +        parser = factory.newSAXParser();
  +        reader = parser.getXMLReader();
  +        reader.setContentHandler(dom.getBuilder());
   
           // Use a DTDMonitor to track ID references in DTD
           DTDMonitor dtdMonitor = new DTDMonitor();
  -        parser.setDTDHandler(dtdMonitor);
  +        dtdMonitor.handleDTD(reader);
   
           // Parse the input document and build DOM
  -        parser.parse(uri);
  +        reader.parse(uri);
   
       At this point the DOMImpl and DTDMonitor objects are
       populated with the necessary data. The two objects
  @@ -124,7 +98,7 @@
           translet.setIndexSize(dom.getSize());
   
           // Build indices for this DOM's DTD's ID references
  -        dtd.buildIdIndex(dom, mask, translet);
  +        dtdMonitor.buildIdIndex(dom, mask, translet);
   
           // Pass unparsed entity URIs to the translet
           translet.setUnparsedEntityURIs(dtd.getUnparsedEntityURIs());
  @@ -138,6 +112,59 @@
   algorithm:
   
       org/apache/xalan/xsltc/dom/DocumentCache.java
  +
  +-----------------------------------------------------------------------
  +DOING TRANSFORMATIONS WITHOUT A DOM CACHE
  +
  +Alternatively, you can program a servlet to perform the same basic
  +steps as the XSLTC command-line tool
  +
  +    org.apache.xalan.xsltc.cmdline.Transform
  +
  +as follows:
  +
  +
  +    // 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));
  +
   
   ------------------------------------------------------------
   END OF README
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to