1. /*
  2. *
  3. * The Apache Software License, Version 1.1
  4. *
  5. *
  6. * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
  7. * reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. *
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in
  18. * the documentation and/or other materials provided with the
  19. * distribution.
  20. *
  21. * 3. The end-user documentation included with the redistribution,
  22. * if any, must include the following acknowledgment:
  23. * "This product includes software developed by the
  24. * Apache Software Foundation (http://www.apache.org/)."
  25. * Alternately, this acknowledgment may appear in the software itself,
  26. * if and wherever such third-party acknowledgments normally appear.
  27. *
  28. * 4. The names "Xerces" and "Apache Software Foundation" must
  29. * not be used to endorse or promote products derived from this
  30. * software without prior written permission. For written
  31. * permission, please contact apache@apache.org.
  32. *
  33. * 5. Products derived from this software may not be called "Apache",
  34. * nor may "Apache" appear in their name, without prior written
  35. * permission of the Apache Software Foundation.
  36. *
  37. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  38. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  39. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  40. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  41. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  42. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  43. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  44. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  45. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  46. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  47. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  48. * SUCH DAMAGE.
  49. * ====================================================================
  50. *
  51. * This software consists of voluntary contributions made by many
  52. * individuals on behalf of the Apache Software Foundation and was
  53. * originally based on software copyright (c) 1999, Sun Microsystems, Inc.,
  54. * http://www.sun.com. For more information on the Apache Software
  55. * Foundation, please see <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.xerces.internal.jaxp;
  58. import java.util.Hashtable;
  59. import javax.xml.XMLConstants;
  60. import javax.xml.parsers.ParserConfigurationException;
  61. import javax.xml.parsers.SAXParser;
  62. import javax.xml.parsers.SAXParserFactory;
  63. import javax.xml.validation.Schema;
  64. import org.xml.sax.SAXException;
  65. import org.xml.sax.SAXNotRecognizedException;
  66. import org.xml.sax.SAXNotSupportedException;
  67. /**
  68. * @author Rajiv Mordani
  69. * @author Edwin Goei
  70. * @version $Id: SAXParserFactoryImpl.java,v 1.6 2003/11/18 00:22:59 kk122374 Exp $
  71. */
  72. /**
  73. * This is the implementation specific class for the
  74. * <code>javax.xml.parsers.SAXParserFactory</code>. This is the platform
  75. * default implementation for the platform.
  76. */
  77. public class SAXParserFactoryImpl extends SAXParserFactory {
  78. private Hashtable features;
  79. private Schema grammar;
  80. private boolean isXIncludeAware;
  81. /**
  82. * Creates a new instance of <code>SAXParser</code> using the currently
  83. * configured factory parameters.
  84. * @return javax.xml.parsers.SAXParser
  85. */
  86. public SAXParser newSAXParser()
  87. throws ParserConfigurationException
  88. {
  89. SAXParser saxParserImpl;
  90. try {
  91. saxParserImpl = new SAXParserImpl(this, features);
  92. } catch (SAXException se) {
  93. // Translate to ParserConfigurationException
  94. throw new ParserConfigurationException(se.getMessage());
  95. }
  96. return saxParserImpl;
  97. }
  98. /**
  99. * Common code for translating exceptions
  100. */
  101. private SAXParserImpl newSAXParserImpl()
  102. throws ParserConfigurationException, SAXNotRecognizedException,
  103. SAXNotSupportedException
  104. {
  105. SAXParserImpl saxParserImpl;
  106. try {
  107. saxParserImpl = new SAXParserImpl(this, features);
  108. } catch (SAXNotSupportedException e) {
  109. throw e;
  110. } catch (SAXNotRecognizedException e) {
  111. throw e;
  112. } catch (SAXException se) {
  113. throw new ParserConfigurationException(se.getMessage());
  114. }
  115. return saxParserImpl;
  116. }
  117. /**
  118. * Sets the particular feature in the underlying implementation of
  119. * org.xml.sax.XMLReader.
  120. */
  121. public void setFeature(String name, boolean value)
  122. throws ParserConfigurationException, SAXNotRecognizedException,
  123. SAXNotSupportedException
  124. {
  125. // XXX This is ugly. We have to collect the features and then
  126. // later create an XMLReader to verify the features.
  127. if (features == null) {
  128. features = new Hashtable();
  129. }
  130. features.put(name, value ? Boolean.TRUE : Boolean.FALSE);
  131. // Test the feature by possibly throwing SAX exceptions
  132. try {
  133. newSAXParserImpl();
  134. } catch (SAXNotSupportedException e) {
  135. features.remove(name);
  136. throw e;
  137. } catch (SAXNotRecognizedException e) {
  138. features.remove(name);
  139. throw e;
  140. }
  141. }
  142. /**
  143. * returns the particular property requested for in the underlying
  144. * implementation of org.xml.sax.XMLReader.
  145. */
  146. public boolean getFeature(String name)
  147. throws ParserConfigurationException, SAXNotRecognizedException,
  148. SAXNotSupportedException
  149. {
  150. // Check for valid name by creating a dummy XMLReader to get
  151. // feature value
  152. if(name.equals(XMLConstants.FEATURE_SECURE_PROCESSING) && features != null){
  153. Boolean ob =(Boolean) features.get(name);
  154. if(ob == null )
  155. return false;
  156. return ob.booleanValue();
  157. }
  158. return newSAXParserImpl().getXMLReader().getFeature(name);
  159. }
  160. public Schema getSchema() {
  161. return grammar;
  162. }
  163. public void setSchema(Schema grammar) {
  164. this.grammar = grammar;
  165. }
  166. public boolean isXIncludeAware() {
  167. return this.isXIncludeAware;
  168. }
  169. public void setXIncludeAware(boolean state) {
  170. this.isXIncludeAware = state;
  171. }
  172. }