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.xinclude.XIncludeHandler; 27 import com.sun.org.apache.xerces.internal.xinclude.XIncludeNamespaceSupport; 28 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; 29 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 30 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 31 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 32 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource; 33 34 /** 35 * This parser configuration includes an <code>XIncludeHandler</code> in the pipeline 36 * before the schema validator, or as the last component in the pipeline if there is 37 * no schema validator. Using this pipeline will enable processing according to the 38 * XML Inclusions specification, to the conformance level described in 39 * <code>XIncludeHandler</code>. 40 * 41 * @author Peter McCracken, IBM 42 * @see com.sun.org.apache.xerces.internal.xinclude.XIncludeHandler 43 */ 44 public class XIncludeParserConfiguration extends XML11Configuration { 45 46 private XIncludeHandler fXIncludeHandler; 47 48 /** Feature identifier: allow notation and unparsed entity events to be sent out of order. */ 49 protected static final String ALLOW_UE_AND_NOTATION_EVENTS = 50 Constants.SAX_FEATURE_PREFIX + Constants.ALLOW_DTD_EVENTS_AFTER_ENDDTD_FEATURE; 51 52 /** Feature identifier: fixup base URIs. */ 53 protected static final String XINCLUDE_FIXUP_BASE_URIS = 54 Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_BASE_URIS_FEATURE; 55 56 /** Feature identifier: fixup language. */ 57 protected static final String XINCLUDE_FIXUP_LANGUAGE = 58 Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_LANGUAGE_FEATURE; 59 60 /** Property identifier: error reporter. */ 61 protected static final String XINCLUDE_HANDLER = 62 Constants.XERCES_PROPERTY_PREFIX + Constants.XINCLUDE_HANDLER_PROPERTY; 63 64 /** Property identifier: error reporter. */ 65 protected static final String NAMESPACE_CONTEXT = 66 Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY; 67 68 /** Default constructor. */ XIncludeParserConfiguration()69 public XIncludeParserConfiguration() { 70 this(null, null, null); 71 } // <init>() 72 73 /** 74 * Constructs a parser configuration using the specified symbol table. 75 * 76 * @param symbolTable The symbol table to use. 77 */ XIncludeParserConfiguration(SymbolTable symbolTable)78 public XIncludeParserConfiguration(SymbolTable symbolTable) { 79 this(symbolTable, null, null); 80 } // <init>(SymbolTable) 81 82 /** 83 * Constructs a parser configuration using the specified symbol table and 84 * grammar pool. 85 * <p> 86 * 87 * @param symbolTable The symbol table to use. 88 * @param grammarPool The grammar pool to use. 89 */ XIncludeParserConfiguration( SymbolTable symbolTable, XMLGrammarPool grammarPool)90 public XIncludeParserConfiguration( 91 SymbolTable symbolTable, 92 XMLGrammarPool grammarPool) { 93 this(symbolTable, grammarPool, null); 94 } // <init>(SymbolTable,XMLGrammarPool) 95 96 /** 97 * Constructs a parser configuration using the specified symbol table, 98 * grammar pool, and parent settings. 99 * <p> 100 * 101 * @param symbolTable The symbol table to use. 102 * @param grammarPool The grammar pool to use. 103 * @param parentSettings The parent settings. 104 */ XIncludeParserConfiguration( SymbolTable symbolTable, XMLGrammarPool grammarPool, XMLComponentManager parentSettings)105 public XIncludeParserConfiguration( 106 SymbolTable symbolTable, 107 XMLGrammarPool grammarPool, 108 XMLComponentManager parentSettings) { 109 super(symbolTable, grammarPool, parentSettings); 110 111 fXIncludeHandler = new XIncludeHandler(); 112 addCommonComponent(fXIncludeHandler); 113 114 final String[] recognizedFeatures = { 115 ALLOW_UE_AND_NOTATION_EVENTS, 116 XINCLUDE_FIXUP_BASE_URIS, 117 XINCLUDE_FIXUP_LANGUAGE 118 }; 119 addRecognizedFeatures(recognizedFeatures); 120 121 // add default recognized properties 122 final String[] recognizedProperties = 123 { XINCLUDE_HANDLER, NAMESPACE_CONTEXT }; 124 addRecognizedProperties(recognizedProperties); 125 126 setFeature(ALLOW_UE_AND_NOTATION_EVENTS, true); 127 setFeature(XINCLUDE_FIXUP_BASE_URIS, true); 128 setFeature(XINCLUDE_FIXUP_LANGUAGE, true); 129 130 setProperty(XINCLUDE_HANDLER, fXIncludeHandler); 131 setProperty(NAMESPACE_CONTEXT, new XIncludeNamespaceSupport()); 132 } // <init>(SymbolTable,XMLGrammarPool)} 133 134 135 /** Configures the pipeline. */ configurePipeline()136 protected void configurePipeline() { 137 super.configurePipeline(); 138 139 //configure DTD pipeline 140 fDTDScanner.setDTDHandler(fDTDProcessor); 141 fDTDProcessor.setDTDSource(fDTDScanner); 142 fDTDProcessor.setDTDHandler(fXIncludeHandler); 143 fXIncludeHandler.setDTDSource(fDTDProcessor); 144 fXIncludeHandler.setDTDHandler(fDTDHandler); 145 if (fDTDHandler != null) { 146 fDTDHandler.setDTDSource(fXIncludeHandler); 147 } 148 149 // configure XML document pipeline: insert after DTDValidator and 150 // before XML Schema validator 151 XMLDocumentSource prev = null; 152 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 153 // we don't have to worry about fSchemaValidator being null, since 154 // super.configurePipeline() instantiated it if the feature was set 155 prev = fSchemaValidator.getDocumentSource(); 156 } 157 // Otherwise, insert after the last component in the pipeline 158 else { 159 prev = fLastComponent; 160 fLastComponent = fXIncludeHandler; 161 } 162 163 if (prev != null) { 164 XMLDocumentHandler next = prev.getDocumentHandler(); 165 prev.setDocumentHandler(fXIncludeHandler); 166 fXIncludeHandler.setDocumentSource(prev); 167 if (next != null) { 168 fXIncludeHandler.setDocumentHandler(next); 169 next.setDocumentSource(fXIncludeHandler); 170 } 171 } 172 else { 173 setDocumentHandler(fXIncludeHandler); 174 } 175 176 } // configurePipeline() 177 configureXML11Pipeline()178 protected void configureXML11Pipeline() { 179 super.configureXML11Pipeline(); 180 181 // configure XML 1.1. DTD pipeline 182 fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor); 183 fXML11DTDProcessor.setDTDSource(fXML11DTDScanner); 184 fXML11DTDProcessor.setDTDHandler(fXIncludeHandler); 185 fXIncludeHandler.setDTDSource(fXML11DTDProcessor); 186 fXIncludeHandler.setDTDHandler(fDTDHandler); 187 if (fDTDHandler != null) { 188 fDTDHandler.setDTDSource(fXIncludeHandler); 189 } 190 191 // configure XML document pipeline: insert after DTDValidator and 192 // before XML Schema validator 193 XMLDocumentSource prev = null; 194 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 195 // we don't have to worry about fSchemaValidator being null, since 196 // super.configurePipeline() instantiated it if the feature was set 197 prev = fSchemaValidator.getDocumentSource(); 198 } 199 // Otherwise, insert after the last component in the pipeline 200 else { 201 prev = fLastComponent; 202 fLastComponent = fXIncludeHandler; 203 } 204 205 XMLDocumentHandler next = prev.getDocumentHandler(); 206 prev.setDocumentHandler(fXIncludeHandler); 207 fXIncludeHandler.setDocumentSource(prev); 208 if (next != null) { 209 fXIncludeHandler.setDocumentHandler(next); 210 next.setDocumentSource(fXIncludeHandler); 211 } 212 213 } // configureXML11Pipeline() 214 setProperty(String propertyId, Object value)215 public void setProperty(String propertyId, Object value) 216 throws XMLConfigurationException { 217 218 if (propertyId.equals(XINCLUDE_HANDLER)) { 219 } 220 221 super.setProperty(propertyId, value); 222 } // setProperty(String,Object) 223 } 224