1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.mirae.j2me.xml;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21
22 import javax.xml.parsers.ParserConfigurationException;
23 import javax.xml.parsers.SAXParser;
24 import javax.xml.parsers.SAXParserFactory;
25
26 import org.xml.sax.InputSource;
27 import org.xml.sax.SAXException;
28 import org.xml.sax.SAXNotRecognizedException;
29 import org.xml.sax.SAXNotSupportedException;
30 import org.xml.sax.helpers.DefaultHandler;
31
32 /***
33 * This is an implementation of javax.xml.parsers.SAXParser
34 * @author Ias (iasandcb@tmax.co.kr)
35 *
36 */
37 public class SAXParserImpl extends SAXParser {
38
39 private SAXParserFactory factory;
40
41 public SAXParserImpl(SAXParserFactory factory) {
42 this.factory = factory;
43 }
44
45 /***
46 * @see javax.xml.parsers.SAXParser#parse(InputStream, DefaultHandler)
47 */
48 public void parse(InputStream is, DefaultHandler dh) throws SAXException, IOException {
49
50 if (is == null) {
51 throw new IllegalArgumentException("InputStream cannot be null");
52 }
53
54 InputSource input = new InputSource(is);
55 this.parse(input, dh);
56 }
57
58 /***
59 * @see javax.xml.parsers.SAXParser#parse(InputSource, DefaultHandler)
60 */
61 public void parse(InputSource is, DefaultHandler handler) throws SAXException, IOException {
62
63
64 if (is == null) {
65 throw new IllegalArgumentException("InputSource cannot be null");
66 }
67 NonValidatingParser parser = new NonValidatingParser(is, handler,this);
68 parser.parse();
69 }
70
71 /***
72 * @see javax.xml.parsers.SAXParser#isNamespaceAware()
73 */
74 public boolean isNamespaceAware() {
75 boolean namespaceAware = true;
76 try {
77 namespaceAware = factory.getFeature(SAXParserFactoryImpl.SAX_FEATURE_PREFIX + SAXParserFactoryImpl.NAMESPACE_PREFIXES_FEATURE);
78 } catch (SAXNotRecognizedException e) {
79 e.printStackTrace();
80 } catch (SAXNotSupportedException e) {
81 e.printStackTrace();
82 } catch (ParserConfigurationException e) {
83 e.printStackTrace();
84 }
85 return namespaceAware;
86 }
87
88 /***
89 * This additional feature should be supported by SAX2
90 * @return a boolean value indicating whether the feature is on or off
91 */
92 public boolean isNamespacePrefixAware() {
93 boolean namespacePrefixAware = false;
94 try {
95 namespacePrefixAware = factory.getFeature(SAXParserFactoryImpl.SAX_FEATURE_PREFIX + SAXParserFactoryImpl.NAMESPACE_PREFIXES_FEATURE);
96 } catch (SAXNotRecognizedException e) {
97 e.printStackTrace();
98 } catch (SAXNotSupportedException e) {
99 e.printStackTrace();
100 } catch (ParserConfigurationException e) {
101 e.printStackTrace();
102 }
103 return namespacePrefixAware;
104 }
105
106 /***
107 * @see javax.xml.parsers.SAXParser#isValidating()
108 */
109 public boolean isValidating() {
110
111 return false;
112 }
113
114 }