20
21 package com.sun.org.apache.xerces.internal.jaxp;
22
23 import java.util.Hashtable;
24
25 import javax.xml.XMLConstants;
26 import javax.xml.parsers.DocumentBuilder;
27 import javax.xml.parsers.DocumentBuilderFactory;
28 import javax.xml.parsers.ParserConfigurationException;
29 import javax.xml.validation.Schema;
30
31 import com.sun.org.apache.xerces.internal.parsers.DOMParser;
32 import com.sun.org.apache.xerces.internal.util.SAXMessageFormatter;
33 import org.xml.sax.SAXException;
34 import org.xml.sax.SAXNotRecognizedException;
35 import org.xml.sax.SAXNotSupportedException;
36
37 /**
38 * @author Rajiv Mordani
39 * @author Edwin Goei
40 * @version $Id: DocumentBuilderFactoryImpl.java,v 1.6 2009/07/28 23:48:32 joehw Exp $
41 */
42 public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory {
43 /** These are DocumentBuilderFactory attributes not DOM attributes */
44 private Hashtable attributes;
45 private Hashtable features;
46 private Schema grammar;
47 private boolean isXIncludeAware;
48
49 /**
50 * State of the secure processing feature, initially <code>false</code>
51 */
52 private boolean fSecureProcess = true;
53
54 /**
55 * Creates a new instance of a {@link javax.xml.parsers.DocumentBuilder}
56 * using the currently configured parameters.
57 */
58 public DocumentBuilder newDocumentBuilder()
59 throws ParserConfigurationException
60 {
174 return fSecureProcess;
175 }
176 // See if it's in the features Hashtable
177 if (features != null) {
178 Object val = features.get(name);
179 if (val != null) {
180 return ((Boolean) val).booleanValue();
181 }
182 }
183 try {
184 DOMParser domParser = new DocumentBuilderImpl(this, attributes, features).getDOMParser();
185 return domParser.getFeature(name);
186 }
187 catch (SAXException e) {
188 throw new ParserConfigurationException(e.getMessage());
189 }
190 }
191
192 public void setFeature(String name, boolean value)
193 throws ParserConfigurationException {
194 // If this is the secure processing feature, save it then return.
195 if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
196 if (System.getSecurityManager() != null && (!value)) {
197 throw new ParserConfigurationException(
198 SAXMessageFormatter.formatMessage(null,
199 "jaxp-secureprocessing-feature", null));
200 }
201 fSecureProcess = value;
202 return;
203 }
204 if (features == null) {
205 features = new Hashtable();
206 }
207 features.put(name, value ? Boolean.TRUE : Boolean.FALSE);
208 // Test the feature by possibly throwing SAX exceptions
209 try {
210 new DocumentBuilderImpl(this, attributes, features);
211 }
212 catch (SAXNotSupportedException e) {
213 features.remove(name);
214 throw new ParserConfigurationException(e.getMessage());
215 }
216 catch (SAXNotRecognizedException e) {
217 features.remove(name);
218 throw new ParserConfigurationException(e.getMessage());
219 }
220 }
221 }
|
20
21 package com.sun.org.apache.xerces.internal.jaxp;
22
23 import java.util.Hashtable;
24
25 import javax.xml.XMLConstants;
26 import javax.xml.parsers.DocumentBuilder;
27 import javax.xml.parsers.DocumentBuilderFactory;
28 import javax.xml.parsers.ParserConfigurationException;
29 import javax.xml.validation.Schema;
30
31 import com.sun.org.apache.xerces.internal.parsers.DOMParser;
32 import com.sun.org.apache.xerces.internal.util.SAXMessageFormatter;
33 import org.xml.sax.SAXException;
34 import org.xml.sax.SAXNotRecognizedException;
35 import org.xml.sax.SAXNotSupportedException;
36
37 /**
38 * @author Rajiv Mordani
39 * @author Edwin Goei
40 * @version $Id: DocumentBuilderFactoryImpl.java,v 1.8 2010-11-01 04:40:06 joehw Exp $
41 */
42 public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory {
43 /** These are DocumentBuilderFactory attributes not DOM attributes */
44 private Hashtable attributes;
45 private Hashtable features;
46 private Schema grammar;
47 private boolean isXIncludeAware;
48
49 /**
50 * State of the secure processing feature, initially <code>false</code>
51 */
52 private boolean fSecureProcess = true;
53
54 /**
55 * Creates a new instance of a {@link javax.xml.parsers.DocumentBuilder}
56 * using the currently configured parameters.
57 */
58 public DocumentBuilder newDocumentBuilder()
59 throws ParserConfigurationException
60 {
174 return fSecureProcess;
175 }
176 // See if it's in the features Hashtable
177 if (features != null) {
178 Object val = features.get(name);
179 if (val != null) {
180 return ((Boolean) val).booleanValue();
181 }
182 }
183 try {
184 DOMParser domParser = new DocumentBuilderImpl(this, attributes, features).getDOMParser();
185 return domParser.getFeature(name);
186 }
187 catch (SAXException e) {
188 throw new ParserConfigurationException(e.getMessage());
189 }
190 }
191
192 public void setFeature(String name, boolean value)
193 throws ParserConfigurationException {
194 if (features == null) {
195 features = new Hashtable();
196 }
197 // If this is the secure processing feature, save it then return.
198 if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
199 if (System.getSecurityManager() != null && (!value)) {
200 throw new ParserConfigurationException(
201 SAXMessageFormatter.formatMessage(null,
202 "jaxp-secureprocessing-feature", null));
203 }
204 fSecureProcess = value;
205 features.put(name, value ? Boolean.TRUE : Boolean.FALSE);
206 return;
207 }
208
209 features.put(name, value ? Boolean.TRUE : Boolean.FALSE);
210 // Test the feature by possibly throwing SAX exceptions
211 try {
212 new DocumentBuilderImpl(this, attributes, features);
213 }
214 catch (SAXNotSupportedException e) {
215 features.remove(name);
216 throw new ParserConfigurationException(e.getMessage());
217 }
218 catch (SAXNotRecognizedException e) {
219 features.remove(name);
220 throw new ParserConfigurationException(e.getMessage());
221 }
222 }
223 }
|