KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xml2 > jaxp > SAXParserFactoryImpl


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.xml2.jaxp;
30
31 import com.caucho.xml2.XMLReaderImpl;
32
33 import org.xml.sax.Parser JavaDoc;
34 import org.xml.sax.SAXNotRecognizedException JavaDoc;
35 import org.xml.sax.XMLReader JavaDoc;
36
37 import javax.xml.parsers.SAXParser JavaDoc;
38 import javax.xml.parsers.SAXParserFactory JavaDoc;
39
40 /**
41  * JAXP SAX parser factory for strict XML parsing.
42  */

43 public class SAXParserFactoryImpl extends SAXParserFactory JavaDoc {
44   private int _namespaces = -1;
45   private int _namespacePrefixes = -1;
46   private int _validation = -1;
47   
48   /**
49    * Creates a new SAX Parser
50    */

51   public SAXParser JavaDoc newSAXParser()
52   {
53     return new XmlSAXParser();
54   }
55
56   /**
57    * Returns a SAX property.
58    */

59   public Object JavaDoc getProperty(String JavaDoc key)
60   {
61     return null;
62   }
63
64   /**
65    * Sets a SAX property.
66    */

67   public void setProperty(String JavaDoc key, Object JavaDoc value)
68   {
69   }
70
71   /**
72    * Returns a SAX feature.
73    */

74   public boolean getFeature(String JavaDoc key)
75   {
76     if (key.equals("http://xml.org/sax/features/namespaces"))
77       return isNamespaceAware();
78     else if (key.equals("http://xml.org/sax/features/namespace-prefixes"))
79       return isNamespacePrefixes();
80     else if (key.equals("http://xml.org/sax/features/validation"))
81       return _validation != 0;
82     else
83       return false;
84   }
85
86   /**
87    * Sets a SAX feature.
88    */

89   public void setFeature(String JavaDoc key, boolean value)
90     throws SAXNotRecognizedException JavaDoc
91   {
92     if (key.equals("http://xml.org/sax/features/namespaces"))
93       _namespaces = value ? 1 : 0;
94     else if (key.equals("http://xml.org/sax/features/namespace-prefixes"))
95       _namespacePrefixes = value ? 1 : 0;
96     else if (key.equals("http://xml.org/sax/features/validation"))
97       _validation = value ? 1 : 0;
98     else
99       throw new SAXNotRecognizedException JavaDoc(key);
100   }
101
102   /**
103    * Returns true if namespaces prefixes are generated.
104    */

105   public boolean isNamespacePrefixes()
106   {
107     if (_namespacePrefixes >= 0)
108       return _namespacePrefixes == 1;
109     else if (_namespaces >= 0)
110       return _namespaces == 1;
111     else
112       return false;
113   }
114
115   public boolean isNamespaceAware()
116   {
117     if (_namespacePrefixes >= 0)
118       return true;
119     else if (_namespaces >= 0)
120       return _namespaces == 1;
121     else
122       return super.isNamespaceAware();
123   }
124
125   public class XmlSAXParser extends SAXParser JavaDoc {
126     private XMLReaderImpl _reader;
127
128     XmlSAXParser()
129     {
130       _reader = new XMLReaderImpl();
131       /*
132       _parser.setNamespaceAware(_factory.isNamespaceAware());
133       _parser.setNamespacePrefixes(_factory.isNamespacePrefixes());
134       // _parser.setValidating(_factory.isValidating());
135       _parser.setValidating(true);
136       */

137     }
138
139     /**
140      * Gets a SAX property.
141      */

142     public Object JavaDoc getProperty(String JavaDoc name)
143     {
144       return null;
145     }
146
147     /**
148      * Sets a SAX property.
149      *
150      * @param name the property name
151      * @param value the property value
152      */

153     public void setProperty(String JavaDoc name, Object JavaDoc value)
154     {
155     }
156
157     /**
158      * Returns the SAX parser instance.
159      */

160     public Parser JavaDoc getParser()
161     {
162       return null;
163     }
164
165     /**
166      * Returns the SAX XMLReader
167      */

168     public XMLReader JavaDoc getXMLReader()
169     {
170       return _reader;
171     }
172
173     /**
174      * Returns true if the SAXParser is namespace aware.
175      */

176     public boolean isNamespaceAware()
177     {
178       return SAXParserFactoryImpl.this.isNamespaceAware();
179     }
180     
181     /**
182      * Returns true if the SAXParser is validating.
183      */

184     public boolean isValidating()
185     {
186       return SAXParserFactoryImpl.this.isValidating();
187     }
188   }
189 }
190
Popular Tags