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.XMLDocumentScannerImpl; 25 import com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl; 26 import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator; 27 import com.sun.org.apache.xerces.internal.impl.dtd.XMLNSDTDValidator; 28 import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator; 29 import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter; 30 import com.sun.org.apache.xerces.internal.util.SymbolTable; 31 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 32 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; 33 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 34 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner; 35 36 /** 37 * This is configuration uses a scanner that integrates both scanning of the document 38 * and binding namespaces. 39 * 40 * If namespace feature is turned on, the pipeline is constructured with the 41 * following components: 42 * XMLNSDocumentScannerImpl -> XMLNSDTDValidator -> (optional) XMLSchemaValidator 43 * 44 * If the namespace feature is turned off the default document scanner implementation 45 * is used (XMLDocumentScannerImpl). 46 * <p> 47 * In addition to the features and properties recognized by the base 48 * parser configuration, this class recognizes these additional 49 * features and properties: 50 * <ul> 51 * <li>Features 52 * <ul> 53 * <li>http://apache.org/xml/features/validation/schema</li> 54 * <li>http://apache.org/xml/features/validation/schema-full-checking</li> 55 * <li>http://apache.org/xml/features/validation/schema/normalized-value</li> 56 * <li>http://apache.org/xml/features/validation/schema/element-default</li> 57 * </ul> 58 * <li>Properties 59 * <ul> 60 * <li>http://apache.org/xml/properties/internal/error-reporter</li> 61 * <li>http://apache.org/xml/properties/internal/entity-manager</li> 62 * <li>http://apache.org/xml/properties/internal/document-scanner</li> 63 * <li>http://apache.org/xml/properties/internal/dtd-scanner</li> 64 * <li>http://apache.org/xml/properties/internal/grammar-pool</li> 65 * <li>http://apache.org/xml/properties/internal/validator/dtd</li> 66 * <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li> 67 * </ul> 68 * </ul> 69 * 70 * @author Elena Litani, IBM 71 * 72 */ 73 public class IntegratedParserConfiguration 74 extends StandardParserConfiguration { 75 76 77 // 78 // REVISIT: should this configuration depend on the others 79 // like DTD/Standard one? 80 // 81 82 /** Document scanner that does namespace binding. */ 83 protected XMLNSDocumentScannerImpl fNamespaceScanner; 84 85 /** Default Xerces implementation of scanner */ 86 protected XMLDocumentScannerImpl fNonNSScanner; 87 88 /** DTD Validator that does not bind namespaces */ 89 protected XMLDTDValidator fNonNSDTDValidator; 90 91 // 92 // Constructors 93 // 94 95 /** Default constructor. */ IntegratedParserConfiguration()96 public IntegratedParserConfiguration() { 97 this(null, null, null); 98 } // <init>() 99 100 /** 101 * Constructs a parser configuration using the specified symbol table. 102 * 103 * @param symbolTable The symbol table to use. 104 */ IntegratedParserConfiguration(SymbolTable symbolTable)105 public IntegratedParserConfiguration(SymbolTable symbolTable) { 106 this(symbolTable, null, null); 107 } // <init>(SymbolTable) 108 109 /** 110 * Constructs a parser configuration using the specified symbol table and 111 * grammar pool. 112 * <p> 113 * <strong>REVISIT:</strong> 114 * Grammar pool will be updated when the new validation engine is 115 * implemented. 116 * 117 * @param symbolTable The symbol table to use. 118 * @param grammarPool The grammar pool to use. 119 */ IntegratedParserConfiguration(SymbolTable symbolTable, XMLGrammarPool grammarPool)120 public IntegratedParserConfiguration(SymbolTable symbolTable, 121 XMLGrammarPool grammarPool) { 122 this(symbolTable, grammarPool, null); 123 } // <init>(SymbolTable,XMLGrammarPool) 124 125 /** 126 * Constructs a parser configuration using the specified symbol table, 127 * grammar pool, and parent settings. 128 * <p> 129 * <strong>REVISIT:</strong> 130 * Grammar pool will be updated when the new validation engine is 131 * implemented. 132 * 133 * @param symbolTable The symbol table to use. 134 * @param grammarPool The grammar pool to use. 135 * @param parentSettings The parent settings. 136 */ IntegratedParserConfiguration(SymbolTable symbolTable, XMLGrammarPool grammarPool, XMLComponentManager parentSettings)137 public IntegratedParserConfiguration(SymbolTable symbolTable, 138 XMLGrammarPool grammarPool, 139 XMLComponentManager parentSettings) { 140 super(symbolTable, grammarPool, parentSettings); 141 142 // create components 143 fNonNSScanner = new XMLDocumentScannerImpl(); 144 fNonNSDTDValidator = new XMLDTDValidator(); 145 146 // add components 147 addComponent((XMLComponent)fNonNSScanner); 148 addComponent((XMLComponent)fNonNSDTDValidator); 149 150 } // <init>(SymbolTable,XMLGrammarPool) 151 152 153 /** Configures the pipeline. */ configurePipeline()154 protected void configurePipeline() { 155 156 // use XML 1.0 datatype library 157 setProperty(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory); 158 159 // setup DTD pipeline 160 configureDTDPipeline(); 161 162 // setup document pipeline 163 if (fFeatures.get(NAMESPACES) == Boolean.TRUE) { 164 fProperties.put(NAMESPACE_BINDER, fNamespaceBinder); 165 fScanner = fNamespaceScanner; 166 fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner); 167 if (fDTDValidator != null) { 168 fProperties.put(DTD_VALIDATOR, fDTDValidator); 169 fNamespaceScanner.setDTDValidator(fDTDValidator); 170 fNamespaceScanner.setDocumentHandler(fDTDValidator); 171 fDTDValidator.setDocumentSource(fNamespaceScanner); 172 fDTDValidator.setDocumentHandler(fDocumentHandler); 173 if (fDocumentHandler != null) { 174 fDocumentHandler.setDocumentSource(fDTDValidator); 175 } 176 fLastComponent = fDTDValidator; 177 } 178 else { 179 fNamespaceScanner.setDocumentHandler(fDocumentHandler); 180 fNamespaceScanner.setDTDValidator(null); 181 if (fDocumentHandler != null) { 182 fDocumentHandler.setDocumentSource(fNamespaceScanner); 183 } 184 fLastComponent = fNamespaceScanner; 185 } 186 } 187 else { 188 fScanner = fNonNSScanner; 189 fProperties.put(DOCUMENT_SCANNER, fNonNSScanner); 190 if (fNonNSDTDValidator != null) { 191 fProperties.put(DTD_VALIDATOR, fNonNSDTDValidator); 192 fNonNSScanner.setDocumentHandler(fNonNSDTDValidator); 193 fNonNSDTDValidator.setDocumentSource(fNonNSScanner); 194 fNonNSDTDValidator.setDocumentHandler(fDocumentHandler); 195 if (fDocumentHandler != null) { 196 fDocumentHandler.setDocumentSource(fNonNSDTDValidator); 197 } 198 fLastComponent = fNonNSDTDValidator; 199 } 200 else { 201 fScanner.setDocumentHandler(fDocumentHandler); 202 if (fDocumentHandler != null) { 203 fDocumentHandler.setDocumentSource(fScanner); 204 } 205 fLastComponent = fScanner; 206 } 207 } 208 209 // setup document pipeline 210 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 211 // If schema validator was not in the pipeline insert it. 212 if (fSchemaValidator == null) { 213 fSchemaValidator = new XMLSchemaValidator(); 214 215 // add schema component 216 fProperties.put(SCHEMA_VALIDATOR, fSchemaValidator); 217 addComponent(fSchemaValidator); 218 // add schema message formatter 219 if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) { 220 XSMessageFormatter xmft = new XSMessageFormatter(); 221 fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft); 222 } 223 224 } 225 226 fLastComponent.setDocumentHandler(fSchemaValidator); 227 fSchemaValidator.setDocumentSource(fLastComponent); 228 fSchemaValidator.setDocumentHandler(fDocumentHandler); 229 if (fDocumentHandler != null) { 230 fDocumentHandler.setDocumentSource(fSchemaValidator); 231 } 232 fLastComponent = fSchemaValidator; 233 } 234 } // configurePipeline() 235 236 237 238 /** Create a document scanner: this scanner performs namespace binding 239 */ createDocumentScanner()240 protected XMLDocumentScanner createDocumentScanner() { 241 fNamespaceScanner = new XMLNSDocumentScannerImpl(); 242 return fNamespaceScanner; 243 } // createDocumentScanner():XMLDocumentScanner 244 245 246 /** Create a DTD validator: this validator performs namespace binding. 247 */ createDTDValidator()248 protected XMLDTDValidator createDTDValidator() { 249 return new XMLNSDTDValidator(); 250 } // createDTDValidator():XMLDTDValidator 251 252 } // class IntegratedParserConfiguration 253