1 57 58 package com.sun.org.apache.xerces.internal.parsers; 59 60 import java.io.IOException ; 61 62 import com.sun.org.apache.xerces.internal.impl.Constants; 63 import com.sun.org.apache.xerces.internal.impl.dtd.DTDGrammar; 64 import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDLoader; 65 import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar; 66 import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader; 67 import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter; 68 import com.sun.org.apache.xerces.internal.util.SymbolTable; 69 import com.sun.org.apache.xerces.internal.util.SynchronizedSymbolTable; 70 import com.sun.org.apache.xerces.internal.util.XMLGrammarPoolImpl; 71 import com.sun.org.apache.xerces.internal.xni.XNIException; 72 import com.sun.org.apache.xerces.internal.xni.grammars.Grammar; 73 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription; 74 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 75 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 76 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 77 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; 78 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 79 80 104 public class XMLGrammarCachingConfiguration 105 extends XML11Configuration { 106 107 111 public static final int BIG_PRIME = 2039; 116 117 protected static final SynchronizedSymbolTable fStaticSymbolTable = 119 new SynchronizedSymbolTable(BIG_PRIME); 120 121 protected static final XMLGrammarPoolImpl fStaticGrammarPool = 123 new XMLGrammarPoolImpl(); 124 125 protected static final String SCHEMA_FULL_CHECKING = 127 Constants.XERCES_FEATURE_PREFIX+Constants.SCHEMA_FULL_CHECKING; 128 129 131 protected XMLSchemaLoader fSchemaLoader; 133 134 protected XMLDTDLoader fDTDLoader; 136 137 141 142 public XMLGrammarCachingConfiguration() { 143 this(fStaticSymbolTable, fStaticGrammarPool, null); 144 } 146 151 public XMLGrammarCachingConfiguration(SymbolTable symbolTable) { 152 this(symbolTable, fStaticGrammarPool, null); 153 } 155 166 public XMLGrammarCachingConfiguration(SymbolTable symbolTable, 167 XMLGrammarPool grammarPool) { 168 this(symbolTable, grammarPool, null); 169 } 171 183 public XMLGrammarCachingConfiguration(SymbolTable symbolTable, 184 XMLGrammarPool grammarPool, 185 XMLComponentManager parentSettings) { 186 super(symbolTable, grammarPool, parentSettings); 187 188 191 fSchemaLoader = new XMLSchemaLoader(fSymbolTable); 196 fSchemaLoader.setProperty(XMLGRAMMAR_POOL, fGrammarPool); 197 198 fDTDLoader = new XMLDTDLoader(fSymbolTable, fGrammarPool); 200 } 202 206 210 public void lockGrammarPool() { 211 fGrammarPool.lockPool(); 212 } 214 218 public void clearGrammarPool() { 219 fGrammarPool.clear(); 220 } 222 226 public void unlockGrammarPool() { 227 fGrammarPool.unlockPool(); 228 } 230 244 public Grammar parseGrammar(String type, String uri) 245 throws XNIException, IOException { 246 XMLInputSource source = new XMLInputSource(null, uri, null); 247 return parseGrammar(type, source); 248 249 } 250 251 267 public Grammar parseGrammar(String type, XMLInputSource 268 is) throws XNIException, IOException { 269 if(type.equals(XMLGrammarDescription.XML_SCHEMA)) { 270 return parseXMLSchema(is); 272 } else if(type.equals(XMLGrammarDescription.XML_DTD)) { 273 return parseDTD(is); 274 } 275 return null; 277 } 279 283 285 297 protected void checkFeature(String featureId) 298 throws XMLConfigurationException { 299 300 super.checkFeature(featureId); 301 302 } 304 317 protected void checkProperty(String propertyId) 318 throws XMLConfigurationException { 319 super.checkProperty(propertyId); 320 321 } 323 325 330 SchemaGrammar parseXMLSchema(XMLInputSource is) 331 throws IOException { 332 XMLEntityResolver resolver = getEntityResolver(); 333 if(resolver != null) { 334 fSchemaLoader.setEntityResolver(resolver); 335 } 336 if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) { 337 fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, new XSMessageFormatter()); 338 } 339 fSchemaLoader.setProperty(ERROR_REPORTER, fErrorReporter); 340 341 String propPrefix = Constants.XERCES_PROPERTY_PREFIX; 342 String propName = propPrefix + Constants.SCHEMA_LOCATION; 343 fSchemaLoader.setProperty(propName, getProperty(propName)); 344 propName = propPrefix + Constants.SCHEMA_NONS_LOCATION; 345 fSchemaLoader.setProperty(propName, getProperty(propName)); 346 propName = Constants.JAXP_PROPERTY_PREFIX+Constants.SCHEMA_SOURCE; 347 fSchemaLoader.setProperty(propName, getProperty(propName)); 348 fSchemaLoader.setFeature(SCHEMA_FULL_CHECKING, getFeature(SCHEMA_FULL_CHECKING)); 349 350 SchemaGrammar grammar = (SchemaGrammar)fSchemaLoader.loadGrammar(is); 354 if (grammar != null) { 356 fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_SCHEMA, 357 new Grammar[]{grammar}); 358 } 359 360 return grammar; 361 362 } 364 366 DTDGrammar parseDTD(XMLInputSource is) 367 throws IOException { 368 XMLEntityResolver resolver = getEntityResolver(); 369 if(resolver != null) { 370 fDTDLoader.setEntityResolver(resolver); 371 } 372 fDTDLoader.setProperty(ERROR_REPORTER, fErrorReporter); 373 374 DTDGrammar grammar = (DTDGrammar)fDTDLoader.loadGrammar(is); 378 if (grammar != null) { 380 fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_DTD, 381 new Grammar[]{grammar}); 382 } 383 384 return grammar; 385 386 } 388 389 } | Popular Tags |