View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.mirae.j2me.xml;
18  
19  import java.util.Hashtable;
20  
21  import javax.xml.parsers.ParserConfigurationException;
22  import javax.xml.parsers.SAXParser;
23  import javax.xml.parsers.SAXParserFactory;
24  
25  import org.xml.sax.SAXException;
26  import org.xml.sax.SAXNotRecognizedException;
27  import org.xml.sax.SAXNotSupportedException;
28  
29  /***
30   * This is an implementation of javax.xml.parsers.SAXParserFactory
31   * @author Ias (iasandcb@tmax.co.kr)
32   * 
33   */
34  public class SAXParserFactoryImpl extends SAXParserFactory {
35  
36  	/*** SAX feature prefix ("http://xml.org/sax/features/" target="alexandria_uri">http://xml.org/sax/features/"). */
37  	public static final String SAX_FEATURE_PREFIX = "http://xml.org/sax/features/";
38  
39  	/*** Namespaces feature ("namespaces"). */
40  	public static final String NAMESPACES_FEATURE = "namespaces";
41  
42  	/*** Namespace prefixes feature ("namespace-prefixes"). */
43  	public static final String NAMESPACE_PREFIXES_FEATURE = "namespace-prefixes";
44  
45  
46  	private Hashtable features;
47  
48      /***
49       * a default constructor
50       */
51  	public SAXParserFactoryImpl() {
52  		features = new Hashtable();
53  		features.put(SAX_FEATURE_PREFIX + NAMESPACES_FEATURE, new Boolean(true));
54  		features.put(SAX_FEATURE_PREFIX + NAMESPACE_PREFIXES_FEATURE, new Boolean(false));
55  	}
56  	/***
57  	 * @see javax.xml.parsers.SAXParserFactory#setFeature(java.lang.String, boolean)
58  	 */
59  	public void setFeature(String name, boolean value)
60  		throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException {
61  		features.put(name, value ? new Boolean(true) : new Boolean(false));
62  	}
63  
64  	/***
65  	 * @see javax.xml.parsers.SAXParserFactory#getFeature(java.lang.String)
66  	 */
67  	public boolean getFeature(String name)
68  		throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException {
69  		Boolean value = (Boolean) features.get(name);
70  		return value.booleanValue();
71  	}
72  
73  	/***
74  	 * @see javax.xml.parsers.SAXParserFactory#newSAXParser()
75  	 */
76  	public SAXParser newSAXParser() throws ParserConfigurationException, SAXException {
77  		return new SAXParserImpl(this);
78  	}
79  }