1 16 package org.apache.xerces.parsers; 17 18 import org.apache.xerces.impl.Constants; 19 import org.apache.xerces.util.SymbolTable; 20 import org.apache.xerces.xinclude.XIncludeHandler; 21 import org.apache.xerces.xinclude.XIncludeNamespaceSupport; 22 import org.apache.xerces.xni.XMLDocumentHandler; 23 import org.apache.xerces.xni.grammars.XMLGrammarPool; 24 import org.apache.xerces.xni.parser.XMLComponentManager; 25 import org.apache.xerces.xni.parser.XMLConfigurationException; 26 import org.apache.xerces.xni.parser.XMLDocumentSource; 27 28 38 public class XIncludeParserConfiguration extends XML11Configuration { 39 40 private XIncludeHandler fXIncludeHandler; 41 42 43 protected static final String ALLOW_UE_AND_NOTATION_EVENTS = 44 Constants.SAX_FEATURE_PREFIX + Constants.ALLOW_DTD_EVENTS_AFTER_ENDDTD_FEATURE; 45 46 47 protected static final String XINCLUDE_FIXUP_BASE_URIS = 48 Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_BASE_URIS_FEATURE; 49 50 51 protected static final String XINCLUDE_FIXUP_LANGUAGE = 52 Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_LANGUAGE_FEATURE; 53 54 55 protected static final String XINCLUDE_HANDLER = 56 Constants.XERCES_PROPERTY_PREFIX + Constants.XINCLUDE_HANDLER_PROPERTY; 57 58 59 protected static final String NAMESPACE_CONTEXT = 60 Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY; 61 62 63 public XIncludeParserConfiguration() { 64 this(null, null, null); 65 } 67 72 public XIncludeParserConfiguration(SymbolTable symbolTable) { 73 this(symbolTable, null, null); 74 } 76 84 public XIncludeParserConfiguration( 85 SymbolTable symbolTable, 86 XMLGrammarPool grammarPool) { 87 this(symbolTable, grammarPool, null); 88 } 90 99 public XIncludeParserConfiguration( 100 SymbolTable symbolTable, 101 XMLGrammarPool grammarPool, 102 XMLComponentManager parentSettings) { 103 super(symbolTable, grammarPool, parentSettings); 104 105 fXIncludeHandler = new XIncludeHandler(); 106 addCommonComponent(fXIncludeHandler); 107 108 final String [] recognizedFeatures = { 109 ALLOW_UE_AND_NOTATION_EVENTS, 110 XINCLUDE_FIXUP_BASE_URIS, 111 XINCLUDE_FIXUP_LANGUAGE 112 }; 113 addRecognizedFeatures(recognizedFeatures); 114 115 final String [] recognizedProperties = 117 { XINCLUDE_HANDLER, NAMESPACE_CONTEXT }; 118 addRecognizedProperties(recognizedProperties); 119 120 setFeature(ALLOW_UE_AND_NOTATION_EVENTS, true); 121 setFeature(XINCLUDE_FIXUP_BASE_URIS, true); 122 setFeature(XINCLUDE_FIXUP_LANGUAGE, true); 123 124 setProperty(XINCLUDE_HANDLER, fXIncludeHandler); 125 setProperty(NAMESPACE_CONTEXT, new XIncludeNamespaceSupport()); 126 } 128 129 130 protected void configurePipeline() { 131 super.configurePipeline(); 132 133 fDTDScanner.setDTDHandler(fDTDProcessor); 135 fDTDProcessor.setDTDSource(fDTDScanner); 136 fDTDProcessor.setDTDHandler(fXIncludeHandler); 137 fXIncludeHandler.setDTDSource(fDTDProcessor); 138 fXIncludeHandler.setDTDHandler(fDTDHandler); 139 if (fDTDHandler != null) { 140 fDTDHandler.setDTDSource(fXIncludeHandler); 141 } 142 143 XMLDocumentSource prev = null; 146 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 147 prev = fSchemaValidator.getDocumentSource(); 150 } 151 else { 153 prev = fLastComponent; 154 fLastComponent = fXIncludeHandler; 155 } 156 157 XMLDocumentHandler next = prev.getDocumentHandler(); 158 prev.setDocumentHandler(fXIncludeHandler); 159 fXIncludeHandler.setDocumentSource(prev); 160 if (next != null) { 161 fXIncludeHandler.setDocumentHandler(next); 162 next.setDocumentSource(fXIncludeHandler); 163 } 164 165 } 167 protected void configureXML11Pipeline() { 168 super.configureXML11Pipeline(); 169 170 fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor); 172 fXML11DTDProcessor.setDTDSource(fXML11DTDScanner); 173 fXML11DTDProcessor.setDTDHandler(fXIncludeHandler); 174 fXIncludeHandler.setDTDSource(fXML11DTDProcessor); 175 fXIncludeHandler.setDTDHandler(fDTDHandler); 176 if (fDTDHandler != null) { 177 fDTDHandler.setDTDSource(fXIncludeHandler); 178 } 179 180 XMLDocumentSource prev = null; 183 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 184 prev = fSchemaValidator.getDocumentSource(); 187 } 188 else { 190 prev = fLastComponent; 191 fLastComponent = fXIncludeHandler; 192 } 193 194 XMLDocumentHandler next = prev.getDocumentHandler(); 195 prev.setDocumentHandler(fXIncludeHandler); 196 fXIncludeHandler.setDocumentSource(prev); 197 if (next != null) { 198 fXIncludeHandler.setDocumentHandler(next); 199 next.setDocumentSource(fXIncludeHandler); 200 } 201 202 } 204 public void setProperty(String propertyId, Object value) 205 throws XMLConfigurationException { 206 207 if (propertyId.equals(XINCLUDE_HANDLER)) { 208 } 209 210 super.setProperty(propertyId, value); 211 } } | Popular Tags |