vhardy      2003/07/08 01:57:16

  Modified:    sources/org/apache/batik/transcoder
                        XMLAbstractTranscoder.java
               sources/org/apache/batik/dom/util DocumentFactory.java
                        SAXDocumentFactory.java
  Added:       test-resources/org/apache/batik/transcoder unitTesting.xml
               test-sources/org/apache/batik/transcoder
                        TranscoderInputTest.java
  Log:
  Fix and regression test for Bug 14788
  
  Revision  Changes    Path
  1.1                  
xml-batik/test-resources/org/apache/batik/transcoder/unitTesting.xml
  
  Index: unitTesting.xml
  ===================================================================
  <!-- ====================================================================== -->
  <!-- Copyright (C) The Apache Software Foundation. All rights reserved.     -->
  <!--                                                                        -->
  <!-- This software is published under the terms of the Apache Software      -->
  <!-- License version 1.1, a copy of which has been included with this       -->
  <!-- distribution in the LICENSE file.                                      -->
  <!-- ====================================================================== -->
  
  <!-- ====================================================================== -->
  <!-- @author [EMAIL PROTECTED]                                          -->
  <!-- @version $Id: unitTesting.xml,v 1.1 2003/07/08 08:57:16 vhardy Exp $ -->
  <!-- ====================================================================== -->
  <testSuite id="transcoder.unitTesting" 
           name="org.apache.batik.transcoder package Unit Testing">
  
  <!-- ================================================================== -->
  <!--                         TranscoderInput Test                       -->
  <!-- ================================================================== -->
  
  <test id="TranscoderInput" class="org.apache.batik.transcoder.TranscoderInputTest" />
  
  </testSuite>
  
  
  
  1.1                  
xml-batik/test-sources/org/apache/batik/transcoder/TranscoderInputTest.java
  
  Index: TranscoderInputTest.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.transcoder;
  
  
  import java.io.File;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.Reader;
  import java.io.StringWriter;
  import java.io.Writer;
  
  import java.net.URL;
  
  import org.xml.sax.XMLReader;
  import org.xml.sax.helpers.XMLReaderFactory;
  
  import org.apache.batik.test.AbstractTest;
  import org.apache.batik.test.TestReport;
  
  
  import org.w3c.dom.Document;
  
  import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
  import org.apache.batik.util.XMLResourceDescriptor;
  import org.apache.batik.dom.svg.ExtensibleSVGDOMImplementation;
  import org.apache.batik.util.SVGConstants;
  
  /**
   * This test validates that the various configurations of TranscoderInput 
   * are supported by the XMLAbstractTranscoder class.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
   * @version $Id: TranscoderInputTest.java,v 1.1 2003/07/08 08:57:16 vhardy Exp $
   */
  public class TranscoderInputTest extends AbstractTest {
      public TestReport runImpl() throws Exception {
          String TEST_URI = (new File("samples/anne.svg")).toURL().toString();
  
          TestTranscoder t = new TestTranscoder();
  
          TranscoderOutput out = new TranscoderOutput(new StringWriter());
  
          // XMLReader
          XMLReader xmlReader = XMLReaderFactory.createXMLReader();
          TranscoderInput ti = new TranscoderInput(xmlReader);
          ti.setURI(TEST_URI);
          t.transcode(ti, out);
          assertTrue(t.passed);
          
          // Input Stream
          URL uri = new URL(TEST_URI);
          InputStream is = uri.openStream();
          ti = new TranscoderInput(is);
          ti.setURI(TEST_URI);
          t = new TestTranscoder();
          t.transcode(ti, out);
          assertTrue(t.passed);
  
          // Reader
          uri = new URL(TEST_URI);
          is = uri.openStream();
          Reader r = new InputStreamReader(is);
          ti = new TranscoderInput(r);
          ti.setURI(TEST_URI);
          t = new TestTranscoder();
          t.transcode(ti, out);
          assertTrue(t.passed);
  
          // Document
          String parser = XMLResourceDescriptor.getXMLParserClassName();
          SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
          Document doc = f.createDocument(TEST_URI);        
          ti = new TranscoderInput(doc);
          ti.setURI(TEST_URI);
          t = new TestTranscoder();
          t.transcode(ti, out);
          assertTrue(t.passed);
  
          // URI only
          ti = new TranscoderInput(TEST_URI);
          t = new TestTranscoder();
          t.transcode(ti, out);
          assertTrue(t.passed);
          
          return reportSuccess();
      }
  
      static class TestTranscoder extends XMLAbstractTranscoder {
          boolean passed = false;
  
          public TestTranscoder() {
              addTranscodingHint(KEY_DOCUMENT_ELEMENT_NAMESPACE_URI,
                                 SVGConstants.SVG_NAMESPACE_URI);
              addTranscodingHint(KEY_DOM_IMPLEMENTATION,
                                 
ExtensibleSVGDOMImplementation.getDOMImplementation());
              addTranscodingHint(KEY_DOCUMENT_ELEMENT,
                                 SVGConstants.SVG_SVG_TAG);
              addTranscodingHint(KEY_DOM_IMPLEMENTATION,
                                 
ExtensibleSVGDOMImplementation.getDOMImplementation());
          }
  
          protected void transcode(Document document,
                                   String uri,
                                   TranscoderOutput output) {
              passed = (document != null);
          }
      }
  }
  
  
  
  1.12      +7 -2      
xml-batik/sources/org/apache/batik/transcoder/XMLAbstractTranscoder.java
  
  Index: XMLAbstractTranscoder.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/transcoder/XMLAbstractTranscoder.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- XMLAbstractTranscoder.java        11 Apr 2003 13:59:23 -0000      1.11
  +++ XMLAbstractTranscoder.java        8 Jul 2003 08:57:16 -0000       1.12
  @@ -109,11 +109,16 @@
                                                   documentElement,
                                                   input.getURI(),
                                                   input.getReader());
  +                } else if (input.getXMLReader() != null) {
  +                    document = f.createDocument(namespaceURI,
  +                                                documentElement,
  +                                                input.getURI(),
  +                                                input.getXMLReader());
                   } else if (uri != null) {
                       document = f.createDocument(namespaceURI,
                                                   documentElement,
                                                   uri);
  -                }
  +                } 
               } catch (DOMException ex) {
                   handler.fatalError(new TranscoderException(ex));
               } catch (IOException ex) {
  
  
  
  1.9       +14 -1     xml-batik/sources/org/apache/batik/dom/util/DocumentFactory.java
  
  Index: DocumentFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/dom/util/DocumentFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DocumentFactory.java      11 Apr 2003 13:57:10 -0000      1.8
  +++ DocumentFactory.java      8 Jul 2003 08:57:16 -0000       1.9
  @@ -14,6 +14,8 @@
   
   import org.w3c.dom.Document;
   
  +import org.xml.sax.XMLReader;
  +
   /**
    * This interface represents an object which can build a Document.
    *
  @@ -53,6 +55,17 @@
        * @exception IOException if an error occured while reading the document.
        */
       Document createDocument(String ns, String root, String uri, InputStream is)
  +        throws IOException;
  +
  +    /**
  +     * Creates a Document instance.
  +     * @param ns The namespace URI of the root element of the document.
  +     * @param root The name of the root element of the document.
  +     * @param uri The document URI.
  +     * @param r An XMLReader instance
  +     * @exception IOException if an error occured while reading the document.
  +     */
  +    Document createDocument(String ns, String root, String uri, XMLReader r)
           throws IOException;
   
       /**
  
  
  
  1.17      +29 -1     
xml-batik/sources/org/apache/batik/dom/util/SAXDocumentFactory.java
  
  Index: SAXDocumentFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/dom/util/SAXDocumentFactory.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- SAXDocumentFactory.java   11 Apr 2003 13:57:11 -0000      1.16
  +++ SAXDocumentFactory.java   8 Jul 2003 08:57:16 -0000       1.17
  @@ -247,6 +247,34 @@
   
       /**
        * Creates a Document instance.
  +     * @param ns The namespace URI of the root element of the document.
  +     * @param root The name of the root element of the document.
  +     * @param uri The document URI.
  +     * @param r an XMLReaderInstance
  +     * @exception IOException if an error occured while reading the document.
  +     */
  +    public Document createDocument(String ns, String root, String uri,
  +                                   XMLReader r) throws IOException {
  +        r.setContentHandler(this);
  +        r.setDTDHandler(this);
  +        r.setEntityResolver(this);
  +        try {
  +            r.parse(uri);
  +        } catch (SAXException e) {
  +            Exception ex = e.getException();
  +            if (ex != null && ex instanceof InterruptedIOException) {
  +                throw (InterruptedIOException) ex;
  +            }
  +            throw new IOException(e.getMessage());
  +        }
  +        currentNode = null;
  +        Document ret = document;
  +        document = null;
  +        return ret;
  +    }
  +
  +    /**
  +     * Creates a Document instance.
        * @param uri The document URI.
        * @param r The document reader.
        * @exception IOException if an error occured while reading the document.
  
  
  

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

Reply via email to