1 16 17 package com.sun.org.apache.xerces.internal.parsers; 18 19 import com.sun.org.apache.xerces.internal.impl.Constants; 20 import com.sun.org.apache.xerces.internal.util.NamespaceSupport; 21 import com.sun.org.apache.xerces.internal.util.SymbolTable; 22 import com.sun.org.apache.xerces.internal.xinclude.XIncludeHandler; 23 import com.sun.org.apache.xerces.internal.xinclude.XIncludeNamespaceSupport; 24 import com.sun.org.apache.xerces.internal.xni.NamespaceContext; 25 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; 26 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 27 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 28 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 29 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource; 30 31 39 public class XIncludeAwareParserConfiguration extends XML11Configuration { 40 41 42 protected static final String ALLOW_UE_AND_NOTATION_EVENTS = 43 Constants.SAX_FEATURE_PREFIX + Constants.ALLOW_DTD_EVENTS_AFTER_ENDDTD_FEATURE; 44 45 46 protected static final String XINCLUDE_FIXUP_BASE_URIS = 47 Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_BASE_URIS_FEATURE; 48 49 50 protected static final String XINCLUDE_FIXUP_LANGUAGE = 51 Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_LANGUAGE_FEATURE; 52 53 54 protected static final String XINCLUDE_FEATURE = 55 Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FEATURE; 56 57 58 protected static final String XINCLUDE_HANDLER = 59 Constants.XERCES_PROPERTY_PREFIX + Constants.XINCLUDE_HANDLER_PROPERTY; 60 61 62 protected static final String NAMESPACE_CONTEXT = 63 Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY; 64 65 69 70 protected XIncludeHandler fXIncludeHandler; 71 72 73 protected NamespaceSupport fNonXIncludeNSContext; 74 75 76 protected XIncludeNamespaceSupport fXIncludeNSContext; 77 78 79 protected NamespaceContext fCurrentNSContext; 80 81 82 protected boolean fXIncludeEnabled = false; 83 84 85 public XIncludeAwareParserConfiguration() { 86 this(null, null, null); 87 } 89 94 public XIncludeAwareParserConfiguration(SymbolTable symbolTable) { 95 this(symbolTable, null, null); 96 } 98 106 public XIncludeAwareParserConfiguration( 107 SymbolTable symbolTable, 108 XMLGrammarPool grammarPool) { 109 this(symbolTable, grammarPool, null); 110 } 112 121 public XIncludeAwareParserConfiguration( 122 SymbolTable symbolTable, 123 XMLGrammarPool grammarPool, 124 XMLComponentManager parentSettings) { 125 super(symbolTable, grammarPool, parentSettings); 126 127 final String [] recognizedFeatures = { 128 ALLOW_UE_AND_NOTATION_EVENTS, 129 XINCLUDE_FIXUP_BASE_URIS, 130 XINCLUDE_FIXUP_LANGUAGE 131 }; 132 addRecognizedFeatures(recognizedFeatures); 133 134 final String [] recognizedProperties = 136 { XINCLUDE_HANDLER, NAMESPACE_CONTEXT }; 137 addRecognizedProperties(recognizedProperties); 138 139 setFeature(ALLOW_UE_AND_NOTATION_EVENTS, true); 140 setFeature(XINCLUDE_FIXUP_BASE_URIS, true); 141 setFeature(XINCLUDE_FIXUP_LANGUAGE, true); 142 143 fNonXIncludeNSContext = new NamespaceSupport(); 144 fCurrentNSContext = fNonXIncludeNSContext; 145 setProperty(NAMESPACE_CONTEXT, fNonXIncludeNSContext); 146 } 147 148 149 150 protected void configurePipeline() { 151 super.configurePipeline(); 152 if (fXIncludeEnabled) { 153 if (fXIncludeHandler == null) { 155 fXIncludeHandler = new XIncludeHandler(); 156 setProperty(XINCLUDE_HANDLER, fXIncludeHandler); 158 addCommonComponent(fXIncludeHandler); 159 fXIncludeHandler.reset(this); 160 } 161 if (fCurrentNSContext != fXIncludeNSContext) { 163 if (fXIncludeNSContext == null) { 164 fXIncludeNSContext = new XIncludeNamespaceSupport(); 165 } 166 fCurrentNSContext = fXIncludeNSContext; 167 setProperty(NAMESPACE_CONTEXT, fXIncludeNSContext); 168 } 169 fDTDScanner.setDTDHandler(fDTDProcessor); 171 fDTDProcessor.setDTDSource(fDTDScanner); 172 fDTDProcessor.setDTDHandler(fXIncludeHandler); 173 fXIncludeHandler.setDTDSource(fDTDProcessor); 174 fXIncludeHandler.setDTDHandler(fDTDHandler); 175 if (fDTDHandler != null) { 176 fDTDHandler.setDTDSource(fXIncludeHandler); 177 } 178 179 XMLDocumentSource prev = null; 182 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 183 prev = fSchemaValidator.getDocumentSource(); 186 } 187 else { 189 prev = fLastComponent; 190 fLastComponent = fXIncludeHandler; 191 } 192 193 XMLDocumentHandler next = prev.getDocumentHandler(); 194 prev.setDocumentHandler(fXIncludeHandler); 195 fXIncludeHandler.setDocumentSource(prev); 196 if (next != null) { 197 fXIncludeHandler.setDocumentHandler(next); 198 next.setDocumentSource(fXIncludeHandler); 199 } 200 } 201 else { 202 if (fCurrentNSContext != fNonXIncludeNSContext) { 204 fCurrentNSContext = fNonXIncludeNSContext; 205 setProperty(NAMESPACE_CONTEXT, fNonXIncludeNSContext); 206 } 207 } 208 } 210 protected void configureXML11Pipeline() { 211 super.configureXML11Pipeline(); 212 if (fXIncludeEnabled) { 213 if (fXIncludeHandler == null) { 215 fXIncludeHandler = new XIncludeHandler(); 216 setProperty(XINCLUDE_HANDLER, fXIncludeHandler); 218 addCommonComponent(fXIncludeHandler); 219 fXIncludeHandler.reset(this); 220 } 221 if (fCurrentNSContext != fXIncludeNSContext) { 223 if (fXIncludeNSContext == null) { 224 fXIncludeNSContext = new XIncludeNamespaceSupport(); 225 } 226 fCurrentNSContext = fXIncludeNSContext; 227 setProperty(NAMESPACE_CONTEXT, fXIncludeNSContext); 228 } 229 fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor); 231 fXML11DTDProcessor.setDTDSource(fXML11DTDScanner); 232 fXML11DTDProcessor.setDTDHandler(fXIncludeHandler); 233 fXIncludeHandler.setDTDSource(fXML11DTDProcessor); 234 fXIncludeHandler.setDTDHandler(fDTDHandler); 235 if (fDTDHandler != null) { 236 fDTDHandler.setDTDSource(fXIncludeHandler); 237 } 238 239 XMLDocumentSource prev = null; 242 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 243 prev = fSchemaValidator.getDocumentSource(); 246 } 247 else { 249 prev = fLastComponent; 250 fLastComponent = fXIncludeHandler; 251 } 252 253 XMLDocumentHandler next = prev.getDocumentHandler(); 254 prev.setDocumentHandler(fXIncludeHandler); 255 fXIncludeHandler.setDocumentSource(prev); 256 if (next != null) { 257 fXIncludeHandler.setDocumentHandler(next); 258 next.setDocumentSource(fXIncludeHandler); 259 } 260 } 261 else { 262 if (fCurrentNSContext != fNonXIncludeNSContext) { 264 fCurrentNSContext = fNonXIncludeNSContext; 265 setProperty(NAMESPACE_CONTEXT, fNonXIncludeNSContext); 266 } 267 } 268 } 270 public boolean getFeature(String featureId) 271 throws XMLConfigurationException { 272 if (featureId.equals(PARSER_SETTINGS)) { 273 return fConfigUpdated; 274 } 275 else if (featureId.equals(XINCLUDE_FEATURE)) { 276 return fXIncludeEnabled; 277 } 278 return super.getFeature0(featureId); 279 280 } 282 public void setFeature(String featureId, boolean state) 283 throws XMLConfigurationException { 284 if (featureId.equals(XINCLUDE_FEATURE)) { 285 fXIncludeEnabled = state; 286 fConfigUpdated = true; 287 return; 288 } 289 super.setFeature(featureId,state); 290 } 291 292 } 293 | Popular Tags |