dims        00/11/10 04:32:02

  Modified:    src/org/apache/cocoon/components/language/markup Tag:
                        xml-cocoon2 Logicsheet.java
                        LogicsheetCodeGenerator.java
               src/org/apache/cocoon/transformation Tag: xml-cocoon2
                        XalanTransformer.java
  Log:
  Cleaning up usage of the new javax.xml.transform interfaces from Xalan2J.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.8   +17 -11    
xml-cocoon/src/org/apache/cocoon/components/language/markup/Attic/Logicsheet.java
  
  Index: Logicsheet.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/Attic/Logicsheet.java,v
  retrieving revision 1.1.2.7
  retrieving revision 1.1.2.8
  diff -u -r1.1.2.7 -r1.1.2.8
  --- Logicsheet.java   2000/11/08 20:35:07     1.1.2.7
  +++ Logicsheet.java   2000/11/10 12:32:01     1.1.2.8
  @@ -32,11 +32,11 @@
   import org.xml.sax.helpers.XMLReaderFactory;
   
   import javax.xml.transform.TransformerFactory;
  -import javax.xml.transform.Transformer;
   import javax.xml.transform.Templates;
  -import javax.xml.transform.sax.SAXSource;
   import javax.xml.transform.TransformerConfigurationException;
  -import org.apache.xalan.transformer.TrAXFilter;
  +import javax.xml.transform.sax.SAXSource;
  +import javax.xml.transform.sax.TransformerHandler;
  +import javax.xml.transform.sax.SAXTransformerFactory;
   
   /**
    * A code-generation logicsheet. This class is actually a wrapper for
  @@ -47,10 +47,15 @@
    * This class should probably be based on an interface...
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a>
  - * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/11/08 20:35:07 $
  + * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
  + * @version CVS $Revision: 1.1.2.8 $ $Date: 2000/11/10 12:32:01 $
    */
   public class Logicsheet {
       /**
  +    * The trax TransformerFactory
  +    */
  +    protected SAXTransformerFactory tfactory;
  +    /**
       * The trax templates
       */
       protected Templates templates;
  @@ -66,27 +71,28 @@
           throws SAXException, IOException
       {
           try {
  -            TransformerFactory tfactory = TransformerFactory.newInstance();
  +            tfactory = (SAXTransformerFactory) 
TransformerFactory.newInstance();
               templates = tfactory.newTemplates(new SAXSource(inputSource));
           } catch (TransformerConfigurationException e){
  +            // FIXME (DIMS) - Need to handle exceptions gracefully.
               e.printStackTrace();
           }
       }
   
       /**
  -    * Get the XMLFilter that performs the stylesheet transformation.
  +    * Get the TransformerHandler that performs the stylesheet transformation.
       *
  -    * @return The XMLFilter for the associated stylesheet.
  +    * @return The TransformerHandler for the associated stylesheet.
       */
  -    public XMLFilter getXMLFilter() 
  +    public TransformerHandler getTransformerHandler()
       {
  -        XMLFilter filter = null;
           try {
  -            filter = new TrAXFilter(templates);
  +            return tfactory.newTransformerHandler(templates);
           } catch (TransformerConfigurationException e){
  +            // FIXME (DIMS) - Need to handle exceptions gracefully.
               e.printStackTrace();
           }
  -        return filter;
  +        return null;
       }
   }
   
  
  
  
  1.1.2.7   +33 -27    
xml-cocoon/src/org/apache/cocoon/components/language/markup/Attic/LogicsheetCodeGenerator.java
  
  Index: LogicsheetCodeGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/Attic/LogicsheetCodeGenerator.java,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- LogicsheetCodeGenerator.java      2000/11/08 20:35:08     1.1.2.6
  +++ LogicsheetCodeGenerator.java      2000/11/10 12:32:01     1.1.2.7
  @@ -13,24 +13,25 @@
   
   import org.xml.sax.InputSource;
   import org.xml.sax.XMLReader;
  -import org.xml.sax.XMLFilter;
  -import org.xml.sax.Attributes;
   import org.xml.sax.ContentHandler;
  -import org.xml.sax.helpers.XMLFilterImpl;
   
   import java.io.IOException;
  -import org.xml.sax.SAXException;
   
   import org.apache.serialize.SerializerFactory;
   import org.apache.serialize.Method;
   import org.apache.serialize.Serializer;
   import org.apache.serialize.OutputFormat;
   
  +import javax.xml.transform.sax.TransformerHandler;
  +import javax.xml.transform.sax.SAXResult;
  +import javax.xml.transform.TransformerException;
  +
   /**
    * A logicsheet-based implementation of <code>MarkupCodeGenerator</code>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a>
  - * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/11/08 20:35:08 $
  + * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
  + * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/11/10 12:32:01 $
    */
   public class LogicsheetCodeGenerator implements MarkupCodeGenerator {
   
  @@ -42,7 +43,7 @@
   
       private XMLReader rootReader;
   
  -    private XMLFilter currentParent;
  +    private TransformerHandler currentParent;
   
       /**
       * The default constructor
  @@ -76,28 +77,33 @@
       * @param logicsheet The logicsheet to be added
       */
       public void addLogicsheet(Logicsheet logicsheet) {
  -        if (this.currentParent==null) {
  -            // Setup the first transformer of the chain.
  -            this.currentParent = logicsheet.getXMLFilter();
  -
  -            // the parent is the rootReader
  -            this.currentParent.setParent(this.rootReader);
  -
  -            // Set content handler for the end of the chain : serializer
  -            
this.currentParent.setContentHandler(this.serializerContentHandler);
  -
  -        } else {
  -            // Build the transformer chain on the fly
  -            XMLFilter newParent=logicsheet.getXMLFilter();
  -
  -            // the currentParent is the parent of the new logicsheet filter
  -            newParent.setParent(this.currentParent);
  -
  -            // reset the new parent and the contentHanlder
  -            this.currentParent = newParent;
  -            
this.currentParent.setContentHandler(this.serializerContentHandler);
  +        try {
  +            if (this.currentParent==null) {
  +                // Setup the first transformer of the chain.
  +                this.currentParent = logicsheet.getTransformerHandler();
  +
  +                // the parent is the rootReader
  +                this.rootReader.setContentHandler(this.currentParent);;
  +
  +                // Set content handler for the end of the chain : serializer
  +                this.currentParent.setResult(new 
SAXResult(this.serializerContentHandler));
  +
  +            } else {
  +                // Build the transformer chain on the fly
  +                TransformerHandler 
newParent=logicsheet.getTransformerHandler();
  +
  +                // the currentParent is the parent of the new logicsheet 
filter
  +                this.currentParent.setResult(new SAXResult(newParent));
  +
  +                // reset the new parent and the contentHanlder
  +                this.currentParent = newParent;
  +                this.currentParent.setResult(new 
SAXResult(this.serializerContentHandler));
  +            }
  +        } catch (TransformerException e) {
  +            // FIXME (DIMS) - Need to handle exceptions gracefully.
  +            e.printStackTrace();
           }
  -    }
  +    }   
   
       /**
       * Generate source code from the input document. Filename information is
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.20  +29 -18    
xml-cocoon/src/org/apache/cocoon/transformation/Attic/XalanTransformer.java
  
  Index: XalanTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/transformation/Attic/XalanTransformer.java,v
  retrieving revision 1.1.2.19
  retrieving revision 1.1.2.20
  diff -u -r1.1.2.19 -r1.1.2.20
  --- XalanTransformer.java     2000/11/08 20:35:18     1.1.2.19
  +++ XalanTransformer.java     2000/11/10 12:32:01     1.1.2.20
  @@ -36,14 +36,15 @@
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
   import org.xml.sax.ext.LexicalHandler;
  -import org.xml.sax.helpers.XMLReaderFactory;
  -import org.xml.sax.XMLReader;
   
   import javax.xml.transform.TransformerFactory;
   import javax.xml.transform.Templates;
  -import javax.xml.transform.sax.SAXSource;
   import javax.xml.transform.TransformerConfigurationException;
  -import org.apache.xalan.transformer.TransformerImpl;
  +import javax.xml.transform.sax.SAXSource;
  +import javax.xml.transform.sax.TransformerHandler;
  +import javax.xml.transform.sax.SAXTransformerFactory;
  +import javax.xml.transform.sax.SAXResult;
  +import javax.xml.transform.TransformerException;
   
   /**
    *
  @@ -51,16 +52,19 @@
    *         (Apache Software Foundation, Exoffice Technologies)
    * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.1.2.19 $ $Date: 2000/11/08 20:35:18 $
  + * @version CVS $Revision: 1.1.2.20 $ $Date: 2000/11/10 12:32:01 $
    */
   public class XalanTransformer extends ContentHandlerWrapper
   implements Transformer, Composer, Poolable, Configurable {
   
       /** The store service instance */
       private Store store = null;
  +
  +    /** The trax TransformerFactory */
  +    private SAXTransformerFactory tfactory = null;
   
  -    /** The XALAN Transformer */
  -     javax.xml.transform.Transformer transformer = null;
  +    /** The trax TransformerHandler */
  +     private TransformerHandler transformerHandler = null;
   
       /** Hash table for Templates */
       private static Hashtable templatesCache = new Hashtable();
  @@ -68,9 +72,13 @@
       /** Is the cache turned on? (default is on) */
       private boolean useCache = true;
   
  -    private javax.xml.transform.Transformer getTransformer(EntityResolver 
resolver, String xsluri)
  +    TransformerHandler getTransformerHandler(EntityResolver resolver, String 
xsluri)
         throws SAXException, ProcessingException, IOException, 
TransformerConfigurationException
       {
  +        // Initialize a shared Transformer factory instance.
  +        if(tfactory == null)
  +            tfactory = (SAXTransformerFactory) 
TransformerFactory.newInstance();
  +            
           // Only local files are checked for midification for compatibility 
reasons!
           // Using the entity resolver we get the filename of the current file:
           // The systemID if such a resource starts with file:/.
  @@ -99,7 +107,6 @@
           }
           if(templates == null)
           {
  -            TransformerFactory tfactory = TransformerFactory.newInstance();
               templates = tfactory.newTemplates(new SAXSource(new 
InputSource(systemID)));
               if (this.useCache == true)
               {
  @@ -115,7 +122,7 @@
                   }
               }
           }
  -        return templates.newTransformer();
  +        return tfactory.newTransformerHandler(templates);
       }
   
       /**
  @@ -155,9 +162,9 @@
               throw new ProcessingException("Stylesheet URI can't be null");
           }
   
  -        /** get a transformer */
  +        /** Get a Transformer Handler */
           try {
  -         transformer = getTransformer(resolver,xsluri);
  +         transformerHandler = getTransformerHandler(resolver,xsluri);
           } catch (TransformerConfigurationException e){
               throw new ProcessingException("Problem in getTransformer:" + 
e.toString());  
           }
  @@ -168,15 +175,14 @@
                   String name = (String) parameters.nextElement();
                   if (isValidXSLTParameterName(name)) {
                       String value = request.getParameter(name);
  -                    transformer.setParameter(name,value);
  +                    
transformerHandler.getTransformer().setParameter(name,value);
                   }
               }
           }
   
  -        ContentHandler chandler = 
((TransformerImpl)transformer).getInputContentHandler();
  -        super.setContentHandler(chandler);
  -        if(chandler instanceof org.xml.sax.ext.LexicalHandler)
  -            this.setLexicalHandler((org.xml.sax.ext.LexicalHandler)chandler);
  +        super.setContentHandler(transformerHandler);
  +        if(transformerHandler instanceof org.xml.sax.ext.LexicalHandler)
  +            
this.setLexicalHandler((org.xml.sax.ext.LexicalHandler)transformerHandler);
       }
   
       /**
  @@ -196,7 +202,12 @@
        * accessing the protected <code>super.contentHandler</code> field.
        */
       public void setContentHandler(ContentHandler content) {
  -        ((TransformerImpl)transformer).setContentHandler(content);
  +        try {
  +            transformerHandler.setResult(new SAXResult(content));
  +        } catch (TransformerException e){
  +            // FIXME (DIMS) - Need to handle exceptions gracefully.
  +            e.printStackTrace();
  +        }
       }
   
       /**
  
  
  

Reply via email to