KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > xml > sax > Sax2XMLReaderCreator


1 package com.thaiopensource.xml.sax;
2
3 import org.xml.sax.SAXException JavaDoc;
4 import org.xml.sax.XMLReader JavaDoc;
5 import org.xml.sax.SAXNotRecognizedException JavaDoc;
6 import org.xml.sax.SAXNotSupportedException JavaDoc;
7 import org.xml.sax.helpers.XMLReaderFactory JavaDoc;
8
9 import com.thaiopensource.xml.sax.XMLReaderCreator;
10
11 /**
12  * An <code>XMLReaderCreator</code> that creates <code>XMLReader</code>s using the SAX2 <code>XMLReaderFactory</code>.
13  * An instance of this class is safe for concurrent access by multiple threads.
14  *
15  * @see org.xml.sax.helpers.XMLReaderFactory
16  * @author <a HREF="mailto:jjc@jclark.com">James Clark</a>
17  */

18 public class Sax2XMLReaderCreator implements XMLReaderCreator {
19   private final String JavaDoc className;
20
21   /**
22    * Constructs a <code>Sax2XMLReaderCreator</code> that uses system defaults to construct <code>XMLReader</code>s.
23    */

24   public Sax2XMLReaderCreator() {
25     this.className = null;
26   }
27
28  /**
29   * Constructs a <code>Sax2XMLReaderCreator</code> that constructs <code>XMLReader</code>s with the specified
30   * class name.
31   *
32   * @param className the fully-qualified name of the class implementing <code>XMLReader</code>;
33   * if <code>null</code> equivalent to the no-argument constructor
34   *
35   */

36   public Sax2XMLReaderCreator(String JavaDoc className) {
37     this.className = className;
38   }
39
40   public XMLReader JavaDoc createXMLReader() throws SAXException JavaDoc {
41     XMLReader JavaDoc xr;
42     if (className == null)
43       xr = XMLReaderFactory.createXMLReader();
44     else
45       xr = XMLReaderFactory.createXMLReader(className);
46     xr.setFeature("http://xml.org/sax/features/namespaces", true);
47     xr.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
48     try {
49       xr.setFeature("http://xml.org/sax/features/validation", false);
50     }
51     catch (SAXNotRecognizedException JavaDoc e) {
52     }
53     catch (SAXNotSupportedException JavaDoc e) {
54     }
55     return xr;
56   }
57 }
58
Popular Tags