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.xpointer.XPointerHandler; 21 import org.apache.xerces.xinclude.XIncludeHandler; 22 import org.apache.xerces.xinclude.XIncludeNamespaceSupport; 23 import org.apache.xerces.xni.XMLDocumentHandler; 24 import org.apache.xerces.xni.grammars.XMLGrammarPool; 25 import org.apache.xerces.xni.parser.XMLComponentManager; 26 import org.apache.xerces.xni.parser.XMLConfigurationException; 27 import org.apache.xerces.xni.parser.XMLDocumentSource; 28 29 38 public class XPointerParserConfiguration extends XML11Configuration { 39 40 private XPointerHandler fXPointerHandler; 41 42 private XIncludeHandler fXIncludeHandler; 43 44 45 protected static final String ALLOW_UE_AND_NOTATION_EVENTS = 46 Constants.SAX_FEATURE_PREFIX + Constants.ALLOW_DTD_EVENTS_AFTER_ENDDTD_FEATURE; 47 48 49 protected static final String XINCLUDE_FIXUP_BASE_URIS = 50 Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_BASE_URIS_FEATURE; 51 52 53 protected static final String XINCLUDE_FIXUP_LANGUAGE = 54 Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_LANGUAGE_FEATURE; 55 56 57 protected static final String XPOINTER_HANDLER = 58 Constants.XERCES_PROPERTY_PREFIX + Constants.XPOINTER_HANDLER_PROPERTY; 59 60 61 protected static final String XINCLUDE_HANDLER = 62 Constants.XERCES_PROPERTY_PREFIX + Constants.XINCLUDE_HANDLER_PROPERTY; 63 64 65 protected static final String NAMESPACE_CONTEXT = 66 Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY; 67 68 69 public XPointerParserConfiguration() { 70 this(null, null, null); 71 } 73 78 public XPointerParserConfiguration(SymbolTable symbolTable) { 79 this(symbolTable, null, null); 80 } 82 90 public XPointerParserConfiguration( 91 SymbolTable symbolTable, 92 XMLGrammarPool grammarPool) { 93 this(symbolTable, grammarPool, null); 94 } 96 105 public XPointerParserConfiguration( 106 SymbolTable symbolTable, 107 XMLGrammarPool grammarPool, 108 XMLComponentManager parentSettings) { 109 super(symbolTable, grammarPool, parentSettings); 110 111 fXIncludeHandler = new XIncludeHandler(); 112 addCommonComponent(fXIncludeHandler); 113 114 fXPointerHandler = new XPointerHandler(); 115 addCommonComponent(fXPointerHandler); 116 117 final String [] recognizedFeatures = { 118 ALLOW_UE_AND_NOTATION_EVENTS, 119 XINCLUDE_FIXUP_BASE_URIS, 120 XINCLUDE_FIXUP_LANGUAGE 121 }; 122 addRecognizedFeatures(recognizedFeatures); 123 124 final String [] recognizedProperties = 126 { XINCLUDE_HANDLER, XPOINTER_HANDLER, NAMESPACE_CONTEXT }; 127 addRecognizedProperties(recognizedProperties); 128 129 setFeature(ALLOW_UE_AND_NOTATION_EVENTS, true); 130 setFeature(XINCLUDE_FIXUP_BASE_URIS, true); 131 setFeature(XINCLUDE_FIXUP_LANGUAGE, true); 132 133 setProperty(XINCLUDE_HANDLER, fXIncludeHandler); 134 setProperty(XPOINTER_HANDLER, fXPointerHandler); 135 setProperty(NAMESPACE_CONTEXT, new XIncludeNamespaceSupport()); 136 137 138 } 140 141 142 protected void configurePipeline() { 143 super.configurePipeline(); 144 145 fDTDScanner.setDTDHandler(fDTDProcessor); 147 fDTDProcessor.setDTDSource(fDTDScanner); 148 149 fDTDProcessor.setDTDHandler(fXIncludeHandler); 150 fXIncludeHandler.setDTDSource(fDTDProcessor); 151 fXIncludeHandler.setDTDHandler(fXPointerHandler); 152 fXPointerHandler.setDTDSource(fXIncludeHandler); 153 fXPointerHandler.setDTDHandler(fDTDHandler); 154 if (fDTDHandler != null) { 155 fDTDHandler.setDTDSource(fXPointerHandler); 156 } 157 158 XMLDocumentSource prev = null; 161 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 162 prev = fSchemaValidator.getDocumentSource(); 165 } 166 else { 168 prev = fLastComponent; 169 fLastComponent = fXPointerHandler; 170 } 171 172 XMLDocumentHandler next = prev.getDocumentHandler(); 173 prev.setDocumentHandler(fXIncludeHandler); 174 fXIncludeHandler.setDocumentSource(prev); 175 176 if (next != null) { 177 fXIncludeHandler.setDocumentHandler(next); 178 next.setDocumentSource(fXIncludeHandler); 179 } 180 181 fXIncludeHandler.setDocumentHandler(fXPointerHandler); 182 fXPointerHandler.setDocumentSource(fXIncludeHandler); 183 } 185 protected void configureXML11Pipeline() { 186 super.configureXML11Pipeline(); 187 188 fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor); 190 fXML11DTDProcessor.setDTDSource(fXML11DTDScanner); 191 192 fDTDProcessor.setDTDHandler(fXIncludeHandler); 193 fXIncludeHandler.setDTDSource(fXML11DTDProcessor); 194 fXIncludeHandler.setDTDHandler(fXPointerHandler); 195 fXPointerHandler.setDTDSource(fXIncludeHandler); 196 fXPointerHandler.setDTDHandler(fDTDHandler); 197 if (fDTDHandler != null) { 198 fDTDHandler.setDTDSource(fXPointerHandler); 199 } 200 201 202 XMLDocumentSource prev = null; 205 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 206 prev = fSchemaValidator.getDocumentSource(); 209 } 210 else { 212 prev = fLastComponent; 213 fLastComponent = fXPointerHandler; 214 } 215 216 XMLDocumentHandler next = prev.getDocumentHandler(); 217 prev.setDocumentHandler(fXIncludeHandler); 218 fXIncludeHandler.setDocumentSource(prev); 219 220 if (next != null) { 221 fXIncludeHandler.setDocumentHandler(next); 222 next.setDocumentSource(fXIncludeHandler); 223 } 224 225 fXIncludeHandler.setDocumentHandler(fXPointerHandler); 226 fXPointerHandler.setDocumentSource(fXIncludeHandler); 227 228 229 } 231 public void setProperty(String propertyId, Object value) 232 throws XMLConfigurationException { 233 234 237 super.setProperty(propertyId, value); 238 } } | Popular Tags |