1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.xerces.internal.parsers; 23 24 import com.sun.org.apache.xerces.internal.impl.Constants; 25 import com.sun.org.apache.xerces.internal.util.SymbolTable; 26 import com.sun.org.apache.xerces.internal.xpointer.XPointerHandler; 27 import com.sun.org.apache.xerces.internal.xinclude.XIncludeHandler; 28 import com.sun.org.apache.xerces.internal.xinclude.XIncludeNamespaceSupport; 29 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; 30 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 31 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 32 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 33 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource; 34 35 /** 36 * This parser configuration includes an <code>XPointerHandler</code> in the pipeline 37 * before the schema validator, or as the last component in the pipeline if there is 38 * no schema validator. Using this pipeline will enable processing according to the 39 * XML Inclusions specification with XPointers, to the conformance level described in 40 * <code>XPointerHandler.</code>. 41 * 42 * @see com.sun.org.apache.xerces.internal.xpointer.XPointerHandler 43 */ 44 public class XPointerParserConfiguration extends XML11Configuration { 45 46 private XPointerHandler fXPointerHandler; 47 48 private XIncludeHandler fXIncludeHandler; 49 50 /** Feature identifier: allow notation and unparsed entity events to be sent out of order. */ 51 protected static final String ALLOW_UE_AND_NOTATION_EVENTS = 52 Constants.SAX_FEATURE_PREFIX + Constants.ALLOW_DTD_EVENTS_AFTER_ENDDTD_FEATURE; 53 54 /** Feature identifier: fixup base URIs. */ 55 protected static final String XINCLUDE_FIXUP_BASE_URIS = 56 Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_BASE_URIS_FEATURE; 57 58 /** Feature identifier: fixup language. */ 59 protected static final String XINCLUDE_FIXUP_LANGUAGE = 60 Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_LANGUAGE_FEATURE; 61 62 /** Property identifier: error reporter. */ 63 protected static final String XPOINTER_HANDLER = 64 Constants.XERCES_PROPERTY_PREFIX + Constants.XPOINTER_HANDLER_PROPERTY; 65 66 /** Property identifier: error reporter. */ 67 protected static final String XINCLUDE_HANDLER = 68 Constants.XERCES_PROPERTY_PREFIX + Constants.XINCLUDE_HANDLER_PROPERTY; 69 70 /** Property identifier: error reporter. */ 71 protected static final String NAMESPACE_CONTEXT = 72 Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY; 73 74 /** Default constructor. */ XPointerParserConfiguration()75 public XPointerParserConfiguration() { 76 this(null, null, null); 77 } // <init>() 78 79 /** 80 * Constructs a parser configuration using the specified symbol table. 81 * 82 * @param symbolTable The symbol table to use. 83 */ XPointerParserConfiguration(SymbolTable symbolTable)84 public XPointerParserConfiguration(SymbolTable symbolTable) { 85 this(symbolTable, null, null); 86 } // <init>(SymbolTable) 87 88 /** 89 * Constructs a parser configuration using the specified symbol table and 90 * grammar pool. 91 * <p> 92 * 93 * @param symbolTable The symbol table to use. 94 * @param grammarPool The grammar pool to use. 95 */ XPointerParserConfiguration( SymbolTable symbolTable, XMLGrammarPool grammarPool)96 public XPointerParserConfiguration( 97 SymbolTable symbolTable, 98 XMLGrammarPool grammarPool) { 99 this(symbolTable, grammarPool, null); 100 } // <init>(SymbolTable,XMLGrammarPool) 101 102 /** 103 * Constructs a parser configuration using the specified symbol table, 104 * grammar pool, and parent settings. 105 * <p> 106 * 107 * @param symbolTable The symbol table to use. 108 * @param grammarPool The grammar pool to use. 109 * @param parentSettings The parent settings. 110 */ XPointerParserConfiguration( SymbolTable symbolTable, XMLGrammarPool grammarPool, XMLComponentManager parentSettings)111 public XPointerParserConfiguration( 112 SymbolTable symbolTable, 113 XMLGrammarPool grammarPool, 114 XMLComponentManager parentSettings) { 115 super(symbolTable, grammarPool, parentSettings); 116 117 fXIncludeHandler = new XIncludeHandler(); 118 addCommonComponent(fXIncludeHandler); 119 120 fXPointerHandler = new XPointerHandler(); 121 addCommonComponent(fXPointerHandler); 122 123 final String[] recognizedFeatures = { 124 ALLOW_UE_AND_NOTATION_EVENTS, 125 XINCLUDE_FIXUP_BASE_URIS, 126 XINCLUDE_FIXUP_LANGUAGE 127 }; 128 addRecognizedFeatures(recognizedFeatures); 129 130 // add default recognized properties 131 final String[] recognizedProperties = 132 { XINCLUDE_HANDLER, XPOINTER_HANDLER, NAMESPACE_CONTEXT }; 133 addRecognizedProperties(recognizedProperties); 134 135 setFeature(ALLOW_UE_AND_NOTATION_EVENTS, true); 136 setFeature(XINCLUDE_FIXUP_BASE_URIS, true); 137 setFeature(XINCLUDE_FIXUP_LANGUAGE, true); 138 139 setProperty(XINCLUDE_HANDLER, fXIncludeHandler); 140 setProperty(XPOINTER_HANDLER, fXPointerHandler); 141 setProperty(NAMESPACE_CONTEXT, new XIncludeNamespaceSupport()); 142 143 144 } // <init>(SymbolTable,XMLGrammarPool)} 145 146 147 /** Configures the pipeline. */ configurePipeline()148 protected void configurePipeline() { 149 super.configurePipeline(); 150 151 //configure DTD pipeline 152 fDTDScanner.setDTDHandler(fDTDProcessor); 153 fDTDProcessor.setDTDSource(fDTDScanner); 154 155 fDTDProcessor.setDTDHandler(fXIncludeHandler); 156 fXIncludeHandler.setDTDSource(fDTDProcessor); 157 fXIncludeHandler.setDTDHandler(fXPointerHandler); 158 fXPointerHandler.setDTDSource(fXIncludeHandler); 159 fXPointerHandler.setDTDHandler(fDTDHandler); 160 if (fDTDHandler != null) { 161 fDTDHandler.setDTDSource(fXPointerHandler); 162 } 163 164 // configure XML document pipeline: insert after DTDValidator and 165 // before XML Schema validator 166 XMLDocumentSource prev = null; 167 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 168 // we don't have to worry about fSchemaValidator being null, since 169 // super.configurePipeline() instantiated it if the feature was set 170 prev = fSchemaValidator.getDocumentSource(); 171 } 172 // Otherwise, insert after the last component in the pipeline 173 else { 174 prev = fLastComponent; 175 fLastComponent = fXPointerHandler; 176 } 177 178 XMLDocumentHandler next = prev.getDocumentHandler(); 179 prev.setDocumentHandler(fXIncludeHandler); 180 fXIncludeHandler.setDocumentSource(prev); 181 182 if (next != null) { 183 fXIncludeHandler.setDocumentHandler(next); 184 next.setDocumentSource(fXIncludeHandler); 185 } 186 187 fXIncludeHandler.setDocumentHandler(fXPointerHandler); 188 fXPointerHandler.setDocumentSource(fXIncludeHandler); 189 } // configurePipeline() 190 configureXML11Pipeline()191 protected void configureXML11Pipeline() { 192 super.configureXML11Pipeline(); 193 194 // configure XML 1.1. DTD pipeline 195 fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor); 196 fXML11DTDProcessor.setDTDSource(fXML11DTDScanner); 197 198 fDTDProcessor.setDTDHandler(fXIncludeHandler); 199 fXIncludeHandler.setDTDSource(fXML11DTDProcessor); 200 fXIncludeHandler.setDTDHandler(fXPointerHandler); 201 fXPointerHandler.setDTDSource(fXIncludeHandler); 202 fXPointerHandler.setDTDHandler(fDTDHandler); 203 if (fDTDHandler != null) { 204 fDTDHandler.setDTDSource(fXPointerHandler); 205 } 206 207 208 // configure XML document pipeline: insert after DTDValidator and 209 // before XML Schema validator 210 XMLDocumentSource prev = null; 211 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 212 // we don't have to worry about fSchemaValidator being null, since 213 // super.configurePipeline() instantiated it if the feature was set 214 prev = fSchemaValidator.getDocumentSource(); 215 } 216 // Otherwise, insert after the last component in the pipeline 217 else { 218 prev = fLastComponent; 219 fLastComponent = fXPointerHandler; 220 } 221 222 XMLDocumentHandler next = prev.getDocumentHandler(); 223 prev.setDocumentHandler(fXIncludeHandler); 224 fXIncludeHandler.setDocumentSource(prev); 225 226 if (next != null) { 227 fXIncludeHandler.setDocumentHandler(next); 228 next.setDocumentSource(fXIncludeHandler); 229 } 230 231 fXIncludeHandler.setDocumentHandler(fXPointerHandler); 232 fXPointerHandler.setDocumentSource(fXIncludeHandler); 233 234 235 } // configureXML11Pipeline() 236 setProperty(String propertyId, Object value)237 public void setProperty(String propertyId, Object value) 238 throws XMLConfigurationException { 239 240 //if (propertyId.equals(XINCLUDE_HANDLER)) { 241 //} 242 243 super.setProperty(propertyId, value); 244 } // setProperty(String,Object) 245 } 246