1 57 package com.sun.org.apache.xerces.internal.parsers; 58 59 import com.sun.org.apache.xerces.internal.impl.Constants; 60 import com.sun.org.apache.xerces.internal.util.SymbolTable; 61 import com.sun.org.apache.xerces.internal.xinclude.XIncludeHandler; 62 import com.sun.org.apache.xerces.internal.xinclude.XIncludeNamespaceSupport; 63 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; 64 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 65 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 66 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 67 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource; 68 69 80 public class XIncludeParserConfiguration extends XML11Configuration { 81 82 private XIncludeHandler fXIncludeHandler; 83 84 85 protected static final String ALLOW_UE_AND_NOTATION_EVENTS = 86 Constants.SAX_FEATURE_PREFIX + Constants.ALLOW_DTD_EVENTS_AFTER_ENDDTD_FEATURE; 87 88 89 protected static final String XINCLUDE_AWARE = 90 Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_AWARE ; 91 92 93 94 protected static final String XINCLUDE_HANDLER = 95 Constants.XERCES_PROPERTY_PREFIX + Constants.XINCLUDE_HANDLER_PROPERTY; 96 97 98 protected static final String NAMESPACE_CONTEXT = 99 Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY; 100 101 102 private boolean enableXInclude = false; 103 104 105 public XIncludeParserConfiguration() { 106 this(null, null, null); 107 } 109 114 public XIncludeParserConfiguration(SymbolTable symbolTable) { 115 this(symbolTable, null, null); 116 } 118 126 public XIncludeParserConfiguration( 127 SymbolTable symbolTable, 128 XMLGrammarPool grammarPool) { 129 this(symbolTable, grammarPool, null); 130 } 132 141 public XIncludeParserConfiguration( 142 SymbolTable symbolTable, 143 XMLGrammarPool grammarPool, 144 XMLComponentManager parentSettings) { 145 super(symbolTable, grammarPool, parentSettings); 146 147 148 final String [] recognizedFeatures = { 150 ALLOW_UE_AND_NOTATION_EVENTS, 151 XINCLUDE_AWARE 152 }; 153 addRecognizedFeatures(recognizedFeatures); 154 fXIncludeHandler = new XIncludeHandler(); 156 addComponent(fXIncludeHandler); 157 final String [] recognizedProperties = { 158 XINCLUDE_HANDLER, 159 NAMESPACE_CONTEXT 160 }; 161 162 addRecognizedProperties(recognizedProperties); 163 setProperty(XINCLUDE_HANDLER, fXIncludeHandler); 164 setProperty(NAMESPACE_CONTEXT, new XIncludeNamespaceSupport()); 165 setFeature(ALLOW_UE_AND_NOTATION_EVENTS, true); 166 setFeature(XINCLUDE_AWARE, false); 167 } 169 170 171 protected void configurePipeline() { 172 super.configurePipeline(); 173 if(enableXInclude){ 174 fDTDScanner.setDTDHandler(fDTDProcessor); 176 fDTDProcessor.setDTDSource(fDTDScanner); 177 fDTDProcessor.setDTDHandler(fXIncludeHandler); 178 fXIncludeHandler.setDTDSource(fDTDProcessor); 179 fXIncludeHandler.setDTDHandler(fDTDHandler); 180 if (fDTDHandler != null) { 181 fDTDHandler.setDTDSource(fXIncludeHandler); 182 } 183 184 XMLDocumentSource prev = null; 187 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 188 prev = fSchemaValidator.getDocumentSource(); 191 } 192 else { 194 prev = fLastComponent; 195 fLastComponent = fXIncludeHandler; 196 } 197 198 if (prev != null) { 199 XMLDocumentHandler next = prev.getDocumentHandler(); 200 if (next != null) { 201 fXIncludeHandler.setDocumentHandler(next); 202 next.setDocumentSource(fXIncludeHandler); 203 } 204 prev.setDocumentHandler(fXIncludeHandler); 205 fXIncludeHandler.setDocumentSource(prev); 206 } 207 else { 208 setDocumentHandler(fXIncludeHandler); 209 } 210 } 211 } 213 protected void configureXML11Pipeline() { 214 super.configureXML11Pipeline(); 215 if(enableXInclude){ 216 addXML11Component(fXIncludeHandler); 217 fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor); 219 fXML11DTDProcessor.setDTDSource(fXML11DTDScanner); 220 fXML11DTDProcessor.setDTDHandler(fXIncludeHandler); 221 fXIncludeHandler.setDTDSource(fXML11DTDProcessor); 222 fXIncludeHandler.setDTDHandler(fDTDHandler); 223 if (fDTDHandler != null) { 224 fDTDHandler.setDTDSource(fXIncludeHandler); 225 } 226 227 XMLDocumentSource prev = null; 230 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 231 prev = fSchemaValidator.getDocumentSource(); 234 } 235 else { 237 prev = fLastComponent; 238 fLastComponent = fXIncludeHandler; 239 } 240 241 XMLDocumentHandler next = prev.getDocumentHandler(); 242 prev.setDocumentHandler(fXIncludeHandler); 243 fXIncludeHandler.setDocumentSource(prev); 244 if (next != null) { 245 fXIncludeHandler.setDocumentHandler(next); 246 next.setDocumentSource(fXIncludeHandler); 247 } 248 } 249 } 251 public void setProperty(String propertyId, Object value) 252 throws XMLConfigurationException { 253 254 if (propertyId.equals(XINCLUDE_HANDLER)) { 255 } 256 257 super.setProperty(propertyId, value); 258 } 260 public void setFeature(String featureId, boolean state) 261 throws XMLConfigurationException { 262 if(featureId.equals(Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_AWARE)){ 263 enableXInclude = state; 264 } 265 super.setFeature(featureId,state); 266 } 267 } 268 | Popular Tags |