pietsch     2003/02/23 12:24:30

  Modified:    src/org/apache/fop/apps Tag: fop-0_20_2-maintain
                        TraxInputHandler.java
  Log:
  Made new constructors for XSLTInputHandler and TraxInputHandler
  actually construct something usable.
  PR:17118
  Submitted by: [EMAIL PROTECTED]
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.5.2.2   +54 -44    xml-fop/src/org/apache/fop/apps/TraxInputHandler.java
  
  Index: TraxInputHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/TraxInputHandler.java,v
  retrieving revision 1.5.2.1
  retrieving revision 1.5.2.2
  diff -u -r1.5.2.1 -r1.5.2.2
  --- TraxInputHandler.java     17 Sep 2002 22:01:06 -0000      1.5.2.1
  +++ TraxInputHandler.java     23 Feb 2003 20:24:30 -0000      1.5.2.2
  @@ -1,6 +1,6 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
    */
  @@ -32,48 +32,40 @@
   import java.io.File;
   
   /**
  - * XSLTInputHandler basically takes an xmlfile and transforms it with an xsltfile
  - * and the resulting xsl:fo document is input for Fop.
  + * XSLTInputHandler basically takes an xml source and transforms it with
  + * an xslt source and the resulting xsl:fo document is input for Fop.
    */
   public class TraxInputHandler extends InputHandler {
  -
  -    File xmlfile, xsltfile;
       private Transformer transformer;
  -    private Source xmlSource;
  +    private StreamSource xmlSource;
  +    private Source xsltSource;
   
       public TraxInputHandler(File xmlfile, File xsltfile)
  -      throws FOPException {
  -        this.xmlfile = xmlfile;
  -        this.xsltfile = xsltfile;
  -        try {
  -            transformer = TransformerFactory.newInstance().newTransformer(
  -              new StreamSource(xsltfile));
  -        }
  -        catch( Exception ex) {
  -            throw new FOPException(ex);
  -        }
  +        throws FOPException {
  +        xmlSource  = new StreamSource(xmlfile);
  +        xsltSource = new StreamSource(xsltfile);
  +        initTransformer();
       }
   
       public TraxInputHandler(String xmlURL, String xsltURL)
  -      throws FOPException {
  -        this.xmlSource = new StreamSource(xmlURL);
  -        try {
  -            transformer = TransformerFactory.newInstance().newTransformer(
  -              new StreamSource(xsltURL));
  -        }
  -        catch( Exception ex) {
  -            throw new FOPException(ex);
  -        }
  +        throws FOPException {
  +        this.xmlSource  = new StreamSource(xmlURL);
  +        this.xsltSource = new StreamSource(xsltURL);
  +        initTransformer();
       }
   
       public TraxInputHandler(InputSource xmlSource, InputSource xsltSource) 
  -      throws FOPException {
  -        this.xmlSource = new StreamSource(xmlSource.getByteStream(),
  -                                          xmlSource.getSystemId());
  +        throws FOPException {
  +        this.xmlSource  = new StreamSource(xmlSource.getByteStream(),
  +                                           xmlSource.getSystemId());
  +        this.xsltSource = new StreamSource(xsltSource.getByteStream(),
  +                                           xsltSource.getSystemId());
  +        initTransformer();
  +    }
  +    
  +    private void initTransformer() throws FOPException {
           try {
  -            transformer = TransformerFactory.newInstance().newTransformer(
  -              new StreamSource(xsltSource.getByteStream(),
  -                               xsltSource.getSystemId()));
  +            transformer = TransformerFactory.newInstance().newTransformer 
(xsltSource);
           }
           catch( Exception ex) {
               throw new FOPException(ex);
  @@ -85,17 +77,21 @@
        * @deprecated
        */
       public InputSource getInputSource() {
  -        return fileInputSource(xmlfile);
  +        InputSource is = new InputSource();
  +        is.setByteStream(xmlSource.getInputStream());
  +        is.setSystemId(xmlSource.getSystemId());
  +        return is;
       }
   
       /**
  -     * overwrites this method of the super class and returns an XMLFilter instead 
of a
  +     * overwrites this method of the super class and returns an XMLFilter 
  +     instead of a
        * simple XMLReader which allows chaining of transformations
        * @deprecated
        *
        */
       public XMLReader getParser() throws FOPException {
  -        return this.getXMLFilter(xmlfile, xsltfile);
  +        return this.getXMLFilter(xsltSource);
       }
   
       /**
  @@ -106,22 +102,22 @@
        * @param xmlfile The xmlfile containing the text data
        * @param xsltfile An xslt stylesheet
        * @return XMLFilter an XMLFilter which can be chained together with other 
XMLReaders or XMLFilters
  -     */
  -    public static XMLFilter getXMLFilter(File xmlfile,
  -                                         File xsltfile) throws FOPException {
  +    */
  +    private static XMLFilter getXMLFilter(Source xsltSource)
  +        throws FOPException {
           try {
               // Instantiate  a TransformerFactory.
               TransformerFactory tFactory = TransformerFactory.newInstance();
  -            // Determine whether the TransformerFactory supports The use uf 
SAXSource
  -            // and SAXResult
  +            // Determine whether the TransformerFactory supports the
  +            // use of SAXSource and SAXResult
               if (tFactory.getFeature(SAXSource.FEATURE)
  -                    && tFactory.getFeature(SAXResult.FEATURE)) {
  +                && tFactory.getFeature(SAXResult.FEATURE)) {
                   // Cast the TransformerFactory to SAXTransformerFactory.
                   SAXTransformerFactory saxTFactory =
                       ((SAXTransformerFactory)tFactory);
                   // Create an XMLFilter for each stylesheet.
                   XMLFilter xmlfilter =
  -                    saxTFactory.newXMLFilter(new StreamSource(xsltfile));
  +                    saxTFactory.newXMLFilter(xsltSource);
   
                   // Create an XMLReader.
                   XMLReader parser = createParser();
  @@ -129,7 +125,7 @@
                       throw new FOPException("Unable to create SAX parser");
                   }
   
  -                // xmlFilter1 uses the XMLReader as its reader.
  +                // xmlFilter uses the XMLReader as its reader.
                   xmlfilter.setParent(parser);
                   return xmlfilter;
               } else {
  @@ -143,6 +139,21 @@
           }
       }
   
  +
  +    /**
  +     * Creates from the transformer an instance of an XMLFilter which
  +     * then can be used in a chain with the XMLReader passed to Driver. This way
  +     * during the conversion of the xml file + xslt stylesheet the resulting
  +     * data is fed into Fop. This should help to avoid memory problems
  +     * @param xmlfile The xmlfile containing the text data
  +     * @param xsltfile An xslt stylesheet
  +     * @return XMLFilter an XMLFilter which can be chained together with other 
XMLReaders or XMLFilters
  +    */
  +    public static XMLFilter getXMLFilter(File xmlfile,
  +                                         File xsltfile) throws FOPException {
  +        return getXMLFilter(new StreamSource(xsltfile));
  +    }
  +
       public void run(Driver driver) throws FOPException {
           try {
               transformer.transform(xmlSource,
  @@ -157,4 +168,3 @@
       }
   
   }
  -
  
  
  

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

Reply via email to