1 57 58 59 package com.sun.org.apache.xerces.internal.jaxp; 60 61 import java.util.Hashtable ; 62 63 import javax.xml.parsers.DocumentBuilder ; 64 import javax.xml.parsers.DocumentBuilderFactory ; 65 import javax.xml.parsers.ParserConfigurationException ; 66 import javax.xml.validation.Schema ; 67 import com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter; 68 69 import com.sun.org.apache.xerces.internal.impl.Constants; 70 import com.sun.org.apache.xerces.internal.parsers.DOMParser; 71 import org.xml.sax.SAXException ; 72 73 78 public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory { 79 80 private Hashtable attributes; 81 private Schema grammar; 82 private boolean isXIncludeAware; 83 84 88 public DocumentBuilder newDocumentBuilder() 89 throws ParserConfigurationException { 90 if( attributes!= null && attributes.containsKey("http://java.sun.com/xml/jaxp/properties/schemaLanguage") && grammar!=null ) 95 throw new ParserConfigurationException ( 96 DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, 97 "jaxp-schema-support",null)); 98 99 100 try { 101 return new DocumentBuilderImpl(this, attributes); 102 } catch (SAXException se) { 103 throw new ParserConfigurationException (se.getMessage()); 105 } 106 } 107 108 114 public void setAttribute(String name, Object value) 115 throws IllegalArgumentException { 116 if (value == null) { 118 if (attributes != null) { 119 attributes.remove(name); 120 } 121 return; 123 } 124 125 128 if (attributes == null) { 130 attributes = new Hashtable (); 131 } 132 133 attributes.put(name, value); 134 135 try { 137 new DocumentBuilderImpl(this, attributes); 138 } catch (Exception e) { 139 attributes.remove(name); 140 throw new IllegalArgumentException (e.getMessage()); 141 } 142 } 143 144 148 public Object getAttribute(String name) throws IllegalArgumentException { 149 if (attributes != null) { 151 Object val = attributes.get(name); 152 if (val != null) { 153 return val; 154 } 155 } 156 157 DOMParser domParser = null; 158 try { 159 domParser = 162 new DocumentBuilderImpl(this, attributes).getDOMParser(); 163 return domParser.getProperty(name); 164 } catch (SAXException se1) { 165 try { 167 boolean result = domParser.getFeature(name); 168 return result ? Boolean.TRUE : Boolean.FALSE; 170 } catch (SAXException se2) { 171 throw new IllegalArgumentException (se1.getMessage()); 173 } 174 } 175 } 176 177 public Schema getSchema() { 178 return grammar; 179 } 180 181 public void setSchema(Schema grammar) { 182 this.grammar = grammar; 183 } 184 185 public boolean isXIncludeAware() { 186 return this.isXIncludeAware; 187 } 188 189 public void setXIncludeAware(boolean state) { 190 this.isXIncludeAware = state; 191 } 192 193 public void setFeature(String name, boolean value) 194 throws ParserConfigurationException { 195 196 if(attributes == null) 204 attributes = new Hashtable (); 205 if(name.equals(Constants.FEATURE_SECURE_PROCESSING)){ 206 attributes.put(Constants.FEATURE_SECURE_PROCESSING,Boolean.valueOf(value)); 207 } else throw new ParserConfigurationException ( 208 DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, 209 "jaxp_feature_not_supported", 210 new Object [] {name})); 211 212 } 213 214 public boolean getFeature(String name) 215 throws ParserConfigurationException { 216 217 if (name.equals(Constants.FEATURE_SECURE_PROCESSING)){ 218 Object ob = attributes.get(Constants.FEATURE_SECURE_PROCESSING); 219 if(ob == null) return false; 220 return ((Boolean )ob).booleanValue(); 221 } 222 else 223 throw new ParserConfigurationException (DOMMessageFormatter.formatMessage( 224 DOMMessageFormatter.DOM_DOMAIN,"jaxp_feature_not_supported", 225 new Object [] {name})); 226 } 227 } 228 | Popular Tags |