1   /*
2    *  StreamingCharFactory.java
3    *
4    *  Copyright (c) 1998-2001, The University of Sheffield.
5    *
6    *  This file is part of GATE (see http://gate.ac.uk/), and is free
7    *  software, licenced under the GNU Library General Public License,
8    *  Version 2, June 1991 (in the distribution as file licence.html,
9    *  and also available at http://gate.ac.uk/gate/licence.html).
10   *
11   *  Angel Kirilov,  10 January 2002
12   *
13   *  $Id: StreamingCharFactory.java,v 1.1 2002/01/11 15:22:12 nasso Exp $
14   */
15  
16  package gate.xml;
17  
18  import org.apache.xerces.framework.XMLErrorReporter;
19  import org.apache.xerces.utils.ChunkyByteArray;
20  import org.apache.xerces.utils.StringPool;
21  import org.xml.sax.InputSource;
22  import org.apache.xerces.readers.*;
23  
24  import java.io.*;
25  import java.net.URL;
26  import java.util.Stack;
27  
28  /**
29   * With this class the correct possition in the parsed XML document will be
30   * reported in the characters() callback function during the SAX parsing.
31   * You should set an instance of this class to the parser with the method
32   * setReaderFactory().
33   * <BR>
34   * If you use default reader factory you will recieve zerro instead of correct
35   * position in the file.
36   */
37  public class StreamingCharFactory extends DefaultReaderFactory {
38  
39  
40      public XMLEntityHandler.EntityReader createCharReader(XMLEntityHandler  entityHandler,
41                                                            XMLErrorReporter errorReporter,
42                                                            boolean sendCharDataAsCharArray,
43                                                            Reader reader,
44                                                            StringPool stringPool)
45      throws Exception
46      {
47          return new org.apache.xerces.readers.StreamingCharReader(entityHandler,
48                                                                   errorReporter,
49  //                                                                 sendCharDataAsCharArray,
50                                                                   true,
51                                                                   reader,
52                                                                   stringPool);
53      }
54  
55      public XMLEntityHandler.EntityReader createUTF8Reader(XMLEntityHandler entityHandler,
56                                                            XMLErrorReporter errorReporter,
57                                                            boolean sendCharDataAsCharArray,
58                                                            InputStream data,StringPool stringPool)
59      throws Exception
60      {
61          XMLEntityHandler.EntityReader reader;
62          reader = new org.apache.xerces.readers.StreamingCharReader(entityHandler,
63                                                                     errorReporter,
64  //                                                                 sendCharDataAsCharArray,
65                                                                     true,
66                                                                     new InputStreamReader(data, "UTF8"),
67                                                                     stringPool);
68          return reader;
69      }
70  }