01: package org.kohsuke.rngom.xml.sax;
02:
03: import javax.xml.parsers.ParserConfigurationException;
04: import javax.xml.parsers.SAXParserFactory;
05:
06: import org.xml.sax.SAXException;
07: import org.xml.sax.XMLReader;
08:
09: /**
10: * {@link XMLReaderCreator} that uses JAXP to create
11: * {@link XMLReader}s.
12: *
13: * @author
14: * Kohsuke Kawaguchi (kk@kohsuke.org)
15: */
16: public class JAXPXMLReaderCreator implements XMLReaderCreator {
17:
18: private final SAXParserFactory spf;
19:
20: public JAXPXMLReaderCreator(SAXParserFactory spf) {
21: this .spf = spf;
22: }
23:
24: /**
25: * Creates a {@link JAXPXMLReaderCreator} by using
26: * {@link SAXParserFactory#newInstance()}.
27: */
28: public JAXPXMLReaderCreator() {
29: spf = SAXParserFactory.newInstance();
30: spf.setNamespaceAware(true);
31: }
32:
33: /**
34: * @see org.kohsuke.rngom.xml.sax.XMLReaderCreator#createXMLReader()
35: */
36: public XMLReader createXMLReader() throws SAXException {
37: try {
38: return spf.newSAXParser().getXMLReader();
39: } catch (ParserConfigurationException e) {
40: throw new SAXException(e);
41: }
42: }
43:
44: }
|