GME
13
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00029 // --------------------------------------------------------------------------- 00030 // Includes 00031 // --------------------------------------------------------------------------- 00032 #include <xercesc/parsers/DOMLSParserImpl.hpp> 00033 #include <xercesc/dom/DOMLSResourceResolver.hpp> 00034 #include <xercesc/dom/DOMErrorHandler.hpp> 00035 #include <xercesc/dom/DOMLSParserFilter.hpp> 00036 #include <xercesc/dom/DOMNodeFilter.hpp> 00037 #include <xercesc/dom/impl/DOMErrorImpl.hpp> 00038 #include <xercesc/dom/impl/DOMLocatorImpl.hpp> 00039 #include <xercesc/dom/impl/DOMConfigurationImpl.hpp> 00040 #include <xercesc/dom/impl/DOMStringListImpl.hpp> 00041 #include <xercesc/dom/impl/DOMDocumentImpl.hpp> 00042 #include <xercesc/dom/DOMException.hpp> 00043 #include <xercesc/dom/DOMLSException.hpp> 00044 #include <xercesc/dom/DOMDocumentFragment.hpp> 00045 #include <xercesc/dom/DOMNamedNodeMap.hpp> 00046 #include <xercesc/internal/XMLScanner.hpp> 00047 #include <xercesc/framework/Wrapper4DOMLSInput.hpp> 00048 #include <xercesc/framework/XMLGrammarPool.hpp> 00049 #include <xercesc/framework/XMLSchemaDescription.hpp> 00050 #include <xercesc/util/Janitor.hpp> 00051 #include <xercesc/validators/common/GrammarResolver.hpp> 00052 #include <xercesc/util/OutOfMemoryException.hpp> 00053 #include <xercesc/util/XMLEntityResolver.hpp> 00054 #include <xercesc/util/RuntimeException.hpp> 00055 #include <xercesc/util/XMLDOMMsg.hpp> 00056 00057 XERCES_CPP_NAMESPACE_BEGIN 00058 00059 00060 // --------------------------------------------------------------------------- 00061 // A filter used to abort processing 00062 // --------------------------------------------------------------------------- 00063 class __AbortFilter : public DOMLSParserFilter 00064 { 00065 public: 00066 __AbortFilter() {} 00067 virtual FilterAction acceptNode(DOMNode*) { return FILTER_INTERRUPT; } 00068 virtual FilterAction startElement(DOMElement* ) { return FILTER_INTERRUPT; } 00069 virtual DOMNodeFilter::ShowType getWhatToShow() const { return DOMNodeFilter::SHOW_ALL; } 00070 }; 00071 00072 static __AbortFilter g_AbortFilter; 00073 00074 // --------------------------------------------------------------------------- 00075 // DOMLSParserImpl: Constructors and Destructor 00076 // --------------------------------------------------------------------------- 00077 DOMLSParserImpl::DOMLSParserImpl( XMLValidator* const valToAdopt 00078 , MemoryManager* const manager 00079 , XMLGrammarPool* const gramPool) : 00080 00081 AbstractDOMParser(valToAdopt, manager, gramPool) 00082 , fEntityResolver(0) 00083 , fXMLEntityResolver(0) 00084 , fErrorHandler(0) 00085 , fFilter(0) 00086 , fCharsetOverridesXMLEncoding(true) 00087 , fUserAdoptsDocument(false) 00088 , fSupportedParameters(0) 00089 , fFilterAction(0) 00090 , fFilterDelayedTextNodes(0) 00091 , fWrapNodesInDocumentFragment(0) 00092 , fWrapNodesContext(0) 00093 { 00094 // dom spec has different default from scanner's default, so set explicitly 00095 getScanner()->setNormalizeData(false); 00096 00097 fSupportedParameters=new (fMemoryManager) DOMStringListImpl(48, manager); 00098 fSupportedParameters->add(XMLUni::fgDOMResourceResolver); 00099 fSupportedParameters->add(XMLUni::fgDOMErrorHandler); 00100 fSupportedParameters->add(XMLUni::fgXercesEntityResolver); 00101 fSupportedParameters->add(XMLUni::fgXercesSchemaExternalSchemaLocation); 00102 fSupportedParameters->add(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation); 00103 fSupportedParameters->add(XMLUni::fgXercesSecurityManager); 00104 fSupportedParameters->add(XMLUni::fgXercesScannerName); 00105 fSupportedParameters->add(XMLUni::fgXercesParserUseDocumentFromImplementation); 00106 fSupportedParameters->add(XMLUni::fgDOMCharsetOverridesXMLEncoding); 00107 fSupportedParameters->add(XMLUni::fgDOMDisallowDoctype); 00108 fSupportedParameters->add(XMLUni::fgDOMIgnoreUnknownCharacterDenormalization); 00109 fSupportedParameters->add(XMLUni::fgDOMNamespaces); 00110 fSupportedParameters->add(XMLUni::fgDOMSupportedMediatypesOnly); 00111 fSupportedParameters->add(XMLUni::fgDOMValidate); 00112 fSupportedParameters->add(XMLUni::fgDOMValidateIfSchema); 00113 fSupportedParameters->add(XMLUni::fgDOMWellFormed); 00114 fSupportedParameters->add(XMLUni::fgDOMCanonicalForm); 00115 fSupportedParameters->add(XMLUni::fgDOMCDATASections); 00116 fSupportedParameters->add(XMLUni::fgDOMCheckCharacterNormalization); 00117 fSupportedParameters->add(XMLUni::fgDOMComments); 00118 fSupportedParameters->add(XMLUni::fgDOMDatatypeNormalization); 00119 fSupportedParameters->add(XMLUni::fgDOMElementContentWhitespace); 00120 fSupportedParameters->add(XMLUni::fgDOMEntities); 00121 fSupportedParameters->add(XMLUni::fgDOMNamespaceDeclarations); 00122 fSupportedParameters->add(XMLUni::fgDOMNormalizeCharacters); 00123 fSupportedParameters->add(XMLUni::fgDOMSchemaLocation); 00124 fSupportedParameters->add(XMLUni::fgDOMSchemaType); 00125 fSupportedParameters->add(XMLUni::fgDOMSplitCDATASections); 00126 fSupportedParameters->add(XMLUni::fgDOMInfoset); 00127 fSupportedParameters->add(XMLUni::fgXercesSchema); 00128 fSupportedParameters->add(XMLUni::fgXercesSchemaFullChecking); 00129 fSupportedParameters->add(XMLUni::fgXercesUserAdoptsDOMDocument); 00130 fSupportedParameters->add(XMLUni::fgXercesLoadExternalDTD); 00131 fSupportedParameters->add(XMLUni::fgXercesLoadSchema); 00132 fSupportedParameters->add(XMLUni::fgXercesContinueAfterFatalError); 00133 fSupportedParameters->add(XMLUni::fgXercesValidationErrorAsFatal); 00134 fSupportedParameters->add(XMLUni::fgXercesCacheGrammarFromParse); 00135 fSupportedParameters->add(XMLUni::fgXercesUseCachedGrammarInParse); 00136 fSupportedParameters->add(XMLUni::fgXercesCalculateSrcOfs); 00137 fSupportedParameters->add(XMLUni::fgXercesStandardUriConformant); 00138 fSupportedParameters->add(XMLUni::fgXercesDOMHasPSVIInfo); 00139 fSupportedParameters->add(XMLUni::fgXercesGenerateSyntheticAnnotations); 00140 fSupportedParameters->add(XMLUni::fgXercesValidateAnnotations); 00141 fSupportedParameters->add(XMLUni::fgXercesIdentityConstraintChecking); 00142 fSupportedParameters->add(XMLUni::fgXercesIgnoreCachedDTD); 00143 fSupportedParameters->add(XMLUni::fgXercesIgnoreAnnotations); 00144 fSupportedParameters->add(XMLUni::fgXercesDisableDefaultEntityResolution); 00145 fSupportedParameters->add(XMLUni::fgXercesSkipDTDValidation); 00146 fSupportedParameters->add(XMLUni::fgXercesDoXInclude); 00147 fSupportedParameters->add(XMLUni::fgXercesHandleMultipleImports); 00148 00149 // LSParser by default does namespace processing 00150 setDoNamespaces(true); 00151 } 00152 00153 00154 DOMLSParserImpl::~DOMLSParserImpl() 00155 { 00156 delete fSupportedParameters; 00157 delete fFilterAction; 00158 delete fFilterDelayedTextNodes; 00159 } 00160 00161 00162 // --------------------------------------------------------------------------- 00163 // DOMLSParserImpl: Setter methods 00164 // --------------------------------------------------------------------------- 00165 bool DOMLSParserImpl::getBusy() const 00166 { 00167 return getParseInProgress(); 00168 } 00169 00170 // --------------------------------------------------------------------------- 00171 // DOMLSParserImpl: Setter methods 00172 // --------------------------------------------------------------------------- 00173 void DOMLSParserImpl::setFilter(DOMLSParserFilter* const filter) 00174 { 00175 fFilter = filter; 00176 } 00177 00178 // --------------------------------------------------------------------------- 00179 // DOMLSParserImpl: DOMConfiguration methods 00180 // --------------------------------------------------------------------------- 00181 void DOMLSParserImpl::setParameter(const XMLCh* name, const void* value) 00182 { 00183 if (XMLString::compareIStringASCII(name, XMLUni::fgDOMResourceResolver) == 0) 00184 { 00185 fEntityResolver = (DOMLSResourceResolver*)value; 00186 if (fEntityResolver) { 00187 getScanner()->setEntityHandler(this); 00188 fXMLEntityResolver = 0; 00189 } 00190 else { 00191 getScanner()->setEntityHandler(0); 00192 } 00193 } 00194 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMErrorHandler) == 0) 00195 { 00196 fErrorHandler = (DOMErrorHandler*)value; 00197 if (fErrorHandler) { 00198 getScanner()->setErrorReporter(this); 00199 } 00200 else { 00201 getScanner()->setErrorReporter(0); 00202 } 00203 } 00204 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaLocation) == 0) 00205 { 00206 // TODO 00207 } 00208 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaType) == 0) 00209 { 00210 // TODO 00211 } 00212 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesEntityResolver) == 0) 00213 { 00214 fXMLEntityResolver = (XMLEntityResolver*)value; 00215 if (fXMLEntityResolver) { 00216 getScanner()->setEntityHandler(this); 00217 fEntityResolver = 0; 00218 } 00219 else { 00220 getScanner()->setEntityHandler(0); 00221 } 00222 } 00223 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaExternalSchemaLocation) == 0) 00224 { 00225 setExternalSchemaLocation((XMLCh*)value); 00226 } 00227 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation) == 0) 00228 { 00229 setExternalNoNamespaceSchemaLocation((XMLCh*)value); 00230 } 00231 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSecurityManager) == 0) 00232 { 00233 setSecurityManager((SecurityManager*)value); 00234 } 00235 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesScannerName) == 0) 00236 { 00237 AbstractDOMParser::useScanner((const XMLCh*) value); 00238 } 00239 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesParserUseDocumentFromImplementation) == 0) 00240 { 00241 useImplementation((const XMLCh*) value); 00242 } 00243 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLowWaterMark) == 0) 00244 { 00245 setLowWaterMark(*(const XMLSize_t*)value); 00246 } 00247 else 00248 throw DOMException(DOMException::NOT_FOUND_ERR, 0, getMemoryManager()); 00249 } 00250 00251 void DOMLSParserImpl::setParameter(const XMLCh* name, bool state) 00252 { 00253 if (XMLString::compareIStringASCII(name, XMLUni::fgDOMCharsetOverridesXMLEncoding) == 0) 00254 { 00255 // in fact, setting this has no effect to the parser 00256 fCharsetOverridesXMLEncoding = state; 00257 } 00258 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMDisallowDoctype) == 0) 00259 { 00260 // TODO 00261 } 00262 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMIgnoreUnknownCharacterDenormalization) == 0) 00263 { 00264 // TODO 00265 } 00266 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNamespaces) == 0) 00267 { 00268 setDoNamespaces(state); 00269 } 00270 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSupportedMediatypesOnly) == 0) 00271 { 00272 if (state) 00273 throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, getMemoryManager()); 00274 } 00275 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMValidate) == 0) 00276 { 00277 if (state) { 00278 if (getValidationScheme() == AbstractDOMParser::Val_Never) 00279 setValidationScheme(AbstractDOMParser::Val_Always); 00280 } 00281 else { 00282 setValidationScheme(AbstractDOMParser::Val_Never); 00283 } 00284 } 00285 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMValidateIfSchema) == 0) 00286 { 00287 if (state) { 00288 setValidationScheme(AbstractDOMParser::Val_Auto); 00289 } 00290 else { 00291 setValidationScheme(AbstractDOMParser::Val_Never); 00292 } 00293 } 00294 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMWellFormed) == 0) 00295 { 00296 if(state==false) 00297 throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, getMemoryManager()); 00298 } 00299 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMCanonicalForm) == 0 ) 00300 { 00301 // TODO 00302 } 00303 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMCDATASections) == 0 ) 00304 { 00305 // TODO 00306 } 00307 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMCheckCharacterNormalization) == 0 ) 00308 { 00309 // TODO 00310 } 00311 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMComments) == 0) 00312 { 00313 setCreateCommentNodes(state); 00314 } 00315 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMDatatypeNormalization) == 0) 00316 { 00317 getScanner()->setNormalizeData(state); 00318 } 00319 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMElementContentWhitespace) == 0) 00320 { 00321 setIncludeIgnorableWhitespace(state); 00322 } 00323 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMEntities) == 0) 00324 { 00325 setCreateEntityReferenceNodes(state); 00326 } 00327 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNamespaceDeclarations) == 0) 00328 { 00329 if (state==false) 00330 throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, getMemoryManager()); 00331 } 00332 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNormalizeCharacters) == 0) 00333 { 00334 // TODO 00335 } 00336 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSplitCDATASections) == 0) 00337 { 00338 // TODO 00339 } 00340 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMInfoset) == 0) 00341 { 00342 if (!state) 00343 throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, getMemoryManager()); 00344 } 00345 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchema) == 0) 00346 { 00347 setDoSchema(state); 00348 } 00349 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaFullChecking) == 0) 00350 { 00351 setValidationSchemaFullChecking(state); 00352 } 00353 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesUserAdoptsDOMDocument) == 0) 00354 { 00355 if(state) 00356 fUserAdoptsDocument = true; 00357 else 00358 fUserAdoptsDocument = false; 00359 } 00360 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadExternalDTD) == 0) 00361 { 00362 setLoadExternalDTD(state); 00363 } 00364 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadSchema) == 0) 00365 { 00366 setLoadSchema(state); 00367 } 00368 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesContinueAfterFatalError) == 0) 00369 { 00370 setExitOnFirstFatalError(!state); 00371 } 00372 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesValidationErrorAsFatal) == 0) 00373 { 00374 setValidationConstraintFatal(state); 00375 } 00376 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesCacheGrammarFromParse) == 0) 00377 { 00378 getScanner()->cacheGrammarFromParse(state); 00379 00380 if (state) 00381 getScanner()->useCachedGrammarInParse(state); 00382 } 00383 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesUseCachedGrammarInParse) == 0) 00384 { 00385 if (state || !getScanner()->isCachingGrammarFromParse()) 00386 getScanner()->useCachedGrammarInParse(state); 00387 } 00388 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesCalculateSrcOfs) == 0) 00389 { 00390 getScanner()->setCalculateSrcOfs(state); 00391 } 00392 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesStandardUriConformant) == 0) 00393 { 00394 getScanner()->setStandardUriConformant(state); 00395 } 00396 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesDOMHasPSVIInfo) == 0) 00397 { 00398 setCreateSchemaInfo(state); 00399 } 00400 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesGenerateSyntheticAnnotations) == 0) 00401 { 00402 getScanner()->setGenerateSyntheticAnnotations(state); 00403 } 00404 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesValidateAnnotations) == 0) 00405 { 00406 getScanner()->setValidateAnnotations(state); 00407 } 00408 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesIdentityConstraintChecking) == 0) 00409 { 00410 getScanner()->setIdentityConstraintChecking(state); 00411 } 00412 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesIgnoreCachedDTD) == 0) 00413 { 00414 getScanner()->setIgnoredCachedDTD(state); 00415 } 00416 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesIgnoreAnnotations) == 0) 00417 { 00418 getScanner()->setIgnoreAnnotations(state); 00419 } 00420 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesDisableDefaultEntityResolution) == 0) 00421 { 00422 getScanner()->setDisableDefaultEntityResolution(state); 00423 } 00424 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSkipDTDValidation) == 0) 00425 { 00426 getScanner()->setSkipDTDValidation(state); 00427 } 00428 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesDoXInclude) == 0) 00429 { 00430 setDoXInclude(state); 00431 } 00432 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesHandleMultipleImports) == 0) 00433 { 00434 getScanner()->setHandleMultipleImports(state); 00435 } 00436 else 00437 throw DOMException(DOMException::NOT_FOUND_ERR, 0, getMemoryManager()); 00438 } 00439 00440 const void* DOMLSParserImpl::getParameter(const XMLCh* name) const 00441 { 00442 if (XMLString::compareIStringASCII(name, XMLUni::fgDOMCharsetOverridesXMLEncoding) == 0) 00443 { 00444 return (void*)fCharsetOverridesXMLEncoding; 00445 } 00446 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMDisallowDoctype) == 0) 00447 { 00448 // TODO 00449 return 0; 00450 } 00451 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMIgnoreUnknownCharacterDenormalization) == 0) 00452 { 00453 // TODO 00454 return 0; 00455 } 00456 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNamespaces) == 0) 00457 { 00458 return (void*)getDoNamespaces(); 00459 } 00460 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMResourceResolver) == 0) 00461 { 00462 return fEntityResolver; 00463 } 00464 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSupportedMediatypesOnly) == 0) 00465 { 00466 return (void*)false; 00467 } 00468 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMValidate) == 0) 00469 { 00470 return (void*)(getValidationScheme() != AbstractDOMParser::Val_Never); 00471 } 00472 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMValidateIfSchema) == 0) 00473 { 00474 return (void*)(getValidationScheme() == AbstractDOMParser::Val_Auto); 00475 } 00476 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMWellFormed) == 0) 00477 { 00478 return (void*)true; 00479 } 00480 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMCanonicalForm) == 0 ) 00481 { 00482 // TODO 00483 return 0; 00484 } 00485 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMCDATASections) == 0 ) 00486 { 00487 // TODO 00488 return 0; 00489 } 00490 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMCheckCharacterNormalization) == 0 ) 00491 { 00492 // TODO 00493 return 0; 00494 } 00495 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMComments) == 0) 00496 { 00497 return (void*)getCreateCommentNodes(); 00498 } 00499 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMDatatypeNormalization) == 0) 00500 { 00501 return (void*)getScanner()->getNormalizeData(); 00502 } 00503 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMElementContentWhitespace) == 0) 00504 { 00505 return (void*)getIncludeIgnorableWhitespace(); 00506 } 00507 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMEntities) == 0) 00508 { 00509 return (void*)getCreateEntityReferenceNodes(); 00510 } 00511 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMErrorHandler) == 0) 00512 { 00513 return fErrorHandler; 00514 } 00515 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNamespaceDeclarations) == 0) 00516 { 00517 return (void*)true; 00518 } 00519 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNormalizeCharacters) == 0) 00520 { 00521 return 0; 00522 } 00523 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaLocation) == 0) 00524 { 00525 return 0; 00526 } 00527 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaType) == 0) 00528 { 00529 return 0; 00530 } 00531 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSplitCDATASections) == 0) 00532 { 00533 return 0; 00534 } 00535 else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMInfoset) == 0) 00536 { 00537 return (void*)true; 00538 } 00539 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchema) == 0) 00540 { 00541 return (void*)getDoSchema(); 00542 } 00543 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaFullChecking) == 0) 00544 { 00545 return (void*)getValidationSchemaFullChecking(); 00546 } 00547 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesIdentityConstraintChecking) == 0) 00548 { 00549 return (void*)getIdentityConstraintChecking(); 00550 } 00551 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadExternalDTD) == 0) 00552 { 00553 return (void*)getLoadExternalDTD(); 00554 } 00555 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadSchema) == 0) 00556 { 00557 return (void*)getLoadSchema(); 00558 } 00559 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesContinueAfterFatalError) == 0) 00560 { 00561 return (void*)!getExitOnFirstFatalError(); 00562 } 00563 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesValidationErrorAsFatal) == 0) 00564 { 00565 return (void*)getValidationConstraintFatal(); 00566 } 00567 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesCacheGrammarFromParse) == 0) 00568 { 00569 return (void*)getScanner()->isCachingGrammarFromParse(); 00570 } 00571 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesUseCachedGrammarInParse) == 0) 00572 { 00573 return (void*)getScanner()->isUsingCachedGrammarInParse(); 00574 } 00575 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesCalculateSrcOfs) == 0) 00576 { 00577 return (void*)getScanner()->getCalculateSrcOfs(); 00578 } 00579 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesStandardUriConformant) == 0) 00580 { 00581 return (void*)getScanner()->getStandardUriConformant(); 00582 } 00583 else if(XMLString::compareIStringASCII(name, XMLUni::fgXercesUserAdoptsDOMDocument) == 0) 00584 { 00585 return (void*)fUserAdoptsDocument; 00586 } 00587 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesDOMHasPSVIInfo) == 0) 00588 { 00589 return (void*)getCreateSchemaInfo(); 00590 } 00591 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesGenerateSyntheticAnnotations) == 0) 00592 { 00593 return (void*)getScanner()->getGenerateSyntheticAnnotations(); 00594 } 00595 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesValidateAnnotations) == 0) 00596 { 00597 return (void*)getScanner()->getValidateAnnotations(); 00598 } 00599 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesIgnoreCachedDTD) == 0) 00600 { 00601 return (void*)getScanner()->getIgnoreCachedDTD(); 00602 } 00603 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesIgnoreAnnotations) == 0) 00604 { 00605 return (void*)getScanner()->getIgnoreAnnotations(); 00606 } 00607 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesDisableDefaultEntityResolution) == 0) 00608 { 00609 return (void*)getScanner()->getDisableDefaultEntityResolution(); 00610 } 00611 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSkipDTDValidation) == 0) 00612 { 00613 return (void*)getScanner()->getSkipDTDValidation(); 00614 } 00615 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesHandleMultipleImports) == 0) 00616 { 00617 return (void*)getScanner()->getHandleMultipleImports(); 00618 } 00619 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesEntityResolver) == 0) 00620 { 00621 return fXMLEntityResolver; 00622 } 00623 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaExternalSchemaLocation) == 0) 00624 { 00625 return getExternalSchemaLocation(); 00626 } 00627 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation) == 0) 00628 { 00629 return getExternalNoNamespaceSchemaLocation(); 00630 } 00631 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesSecurityManager) == 0) 00632 { 00633 return getSecurityManager(); 00634 } 00635 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesDoXInclude) == 0) 00636 { 00637 return (void *)getDoXInclude(); 00638 } 00639 else if (XMLString::compareIStringASCII(name, XMLUni::fgXercesLowWaterMark) == 0) 00640 { 00641 return (void*)&getLowWaterMark(); 00642 } 00643 else 00644 throw DOMException(DOMException::NOT_FOUND_ERR, 0, getMemoryManager()); 00645 } 00646 00647 bool DOMLSParserImpl::canSetParameter(const XMLCh* name, const void* /*value*/) const 00648 { 00649 if (XMLString::compareIStringASCII(name, XMLUni::fgDOMResourceResolver) == 0 || 00650 XMLString::compareIStringASCII(name, XMLUni::fgDOMErrorHandler) == 0 || 00651 XMLString::compareIStringASCII(name, XMLUni::fgXercesEntityResolver) == 0 || 00652 XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaExternalSchemaLocation) == 0 || 00653 XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation) == 0 || 00654 XMLString::compareIStringASCII(name, XMLUni::fgXercesSecurityManager) == 0 || 00655 XMLString::compareIStringASCII(name, XMLUni::fgXercesScannerName) == 0 || 00656 XMLString::compareIStringASCII(name, XMLUni::fgXercesParserUseDocumentFromImplementation) == 0 || 00657 XMLString::compareIStringASCII(name, XMLUni::fgXercesLowWaterMark) == 0) 00658 return true; 00659 else if(XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaLocation) == 0 || 00660 XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaType) == 0) 00661 return false; 00662 00663 return false; 00664 } 00665 00666 bool DOMLSParserImpl::canSetParameter(const XMLCh* name, bool value) const 00667 { 00668 if (XMLString::compareIStringASCII(name, XMLUni::fgDOMCharsetOverridesXMLEncoding) == 0 || 00669 XMLString::compareIStringASCII(name, XMLUni::fgDOMNamespaces) == 0 || 00670 XMLString::compareIStringASCII(name, XMLUni::fgDOMValidate) == 0 || 00671 XMLString::compareIStringASCII(name, XMLUni::fgDOMValidateIfSchema) == 0 || 00672 XMLString::compareIStringASCII(name, XMLUni::fgDOMComments) == 0 || 00673 XMLString::compareIStringASCII(name, XMLUni::fgDOMDatatypeNormalization) == 0 || 00674 XMLString::compareIStringASCII(name, XMLUni::fgDOMElementContentWhitespace) == 0 || 00675 XMLString::compareIStringASCII(name, XMLUni::fgDOMEntities) == 0 || 00676 XMLString::compareIStringASCII(name, XMLUni::fgXercesSchema) == 0 || 00677 XMLString::compareIStringASCII(name, XMLUni::fgXercesSchemaFullChecking) == 0 || 00678 XMLString::compareIStringASCII(name, XMLUni::fgXercesIdentityConstraintChecking) == 0 || 00679 XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadExternalDTD) == 0 || 00680 XMLString::compareIStringASCII(name, XMLUni::fgXercesLoadSchema) == 0 || 00681 XMLString::compareIStringASCII(name, XMLUni::fgXercesContinueAfterFatalError) == 0 || 00682 XMLString::compareIStringASCII(name, XMLUni::fgXercesValidationErrorAsFatal) == 0 || 00683 XMLString::compareIStringASCII(name, XMLUni::fgXercesCacheGrammarFromParse) == 0 || 00684 XMLString::compareIStringASCII(name, XMLUni::fgXercesUseCachedGrammarInParse) == 0 || 00685 XMLString::compareIStringASCII(name, XMLUni::fgXercesCalculateSrcOfs) == 0 || 00686 XMLString::compareIStringASCII(name, XMLUni::fgXercesStandardUriConformant) == 0 || 00687 XMLString::compareIStringASCII(name, XMLUni::fgXercesUserAdoptsDOMDocument) == 0 || 00688 XMLString::compareIStringASCII(name, XMLUni::fgXercesDOMHasPSVIInfo) == 0 || 00689 XMLString::compareIStringASCII(name, XMLUni::fgXercesGenerateSyntheticAnnotations) == 0 || 00690 XMLString::compareIStringASCII(name, XMLUni::fgXercesValidateAnnotations) == 0 || 00691 XMLString::compareIStringASCII(name, XMLUni::fgXercesIgnoreCachedDTD) == 0 || 00692 XMLString::compareIStringASCII(name, XMLUni::fgXercesIgnoreAnnotations) == 0 || 00693 XMLString::compareIStringASCII(name, XMLUni::fgXercesDisableDefaultEntityResolution) == 0 || 00694 XMLString::compareIStringASCII(name, XMLUni::fgXercesSkipDTDValidation) == 0 || 00695 XMLString::compareIStringASCII(name, XMLUni::fgXercesDoXInclude) == 0 || 00696 XMLString::compareIStringASCII(name, XMLUni::fgXercesHandleMultipleImports) == 0) 00697 return true; 00698 else if(XMLString::compareIStringASCII(name, XMLUni::fgDOMDisallowDoctype) == 0 || 00699 XMLString::compareIStringASCII(name, XMLUni::fgDOMIgnoreUnknownCharacterDenormalization) == 0 || 00700 XMLString::compareIStringASCII(name, XMLUni::fgDOMCanonicalForm) == 0 || 00701 XMLString::compareIStringASCII(name, XMLUni::fgDOMCDATASections) == 0 || 00702 XMLString::compareIStringASCII(name, XMLUni::fgDOMCheckCharacterNormalization) == 0 || 00703 XMLString::compareIStringASCII(name, XMLUni::fgDOMNormalizeCharacters) == 0 || 00704 XMLString::compareIStringASCII(name, XMLUni::fgDOMSplitCDATASections) == 0) 00705 return false; 00706 else if(XMLString::compareIStringASCII(name, XMLUni::fgDOMSupportedMediatypesOnly) == 0) 00707 return value?false:true; 00708 else if(XMLString::compareIStringASCII(name, XMLUni::fgDOMWellFormed) == 0 || 00709 XMLString::compareIStringASCII(name, XMLUni::fgDOMNamespaceDeclarations) == 0 || 00710 XMLString::compareIStringASCII(name, XMLUni::fgDOMInfoset) == 0) 00711 return value?true:false; 00712 00713 return false; 00714 } 00715 00716 const DOMStringList* DOMLSParserImpl::getParameterNames() const 00717 { 00718 return fSupportedParameters; 00719 } 00720 00721 // --------------------------------------------------------------------------- 00722 // DOMLSParserImpl: Feature methods 00723 // --------------------------------------------------------------------------- 00724 void DOMLSParserImpl::release() 00725 { 00726 DOMLSParserImpl* builder = (DOMLSParserImpl*) this; 00727 delete builder; 00728 } 00729 00730 void DOMLSParserImpl::resetDocumentPool() 00731 { 00732 resetPool(); 00733 } 00734 00735 00736 // --------------------------------------------------------------------------- 00737 // DOMLSParserImpl: Parsing methods 00738 // --------------------------------------------------------------------------- 00739 DOMDocument* DOMLSParserImpl::parse(const DOMLSInput* source) 00740 { 00741 if (getParseInProgress()) 00742 throw DOMException(DOMException::INVALID_STATE_ERR, XMLDOMMsg::LSParser_ParseInProgress, fMemoryManager); 00743 00744 // remove the abort filter, if present 00745 if(fFilter==&g_AbortFilter) 00746 fFilter=0; 00747 if(fFilterAction) 00748 fFilterAction->removeAll(); 00749 if(fFilterDelayedTextNodes) 00750 fFilterDelayedTextNodes->removeAll(); 00751 00752 Wrapper4DOMLSInput isWrapper((DOMLSInput*)source, fEntityResolver, false, getMemoryManager()); 00753 00754 AbstractDOMParser::parse(isWrapper); 00755 00756 // Disabled until 4.0.0. See XERCESC-1894 for details. 00757 //if(getErrorCount()!=0) 00758 // throw DOMLSException(DOMLSException::PARSE_ERR, XMLDOMMsg::LSParser_ParsingFailed, fMemoryManager); 00759 00760 if (fUserAdoptsDocument) 00761 return adoptDocument(); 00762 else 00763 return getDocument(); 00764 } 00765 00766 DOMDocument* DOMLSParserImpl::parseURI(const XMLCh* const systemId) 00767 { 00768 if (getParseInProgress()) 00769 throw DOMException(DOMException::INVALID_STATE_ERR, XMLDOMMsg::LSParser_ParseInProgress, fMemoryManager); 00770 00771 // remove the abort filter, if present 00772 if(fFilter==&g_AbortFilter) 00773 fFilter=0; 00774 if(fFilterAction) 00775 fFilterAction->removeAll(); 00776 if(fFilterDelayedTextNodes) 00777 fFilterDelayedTextNodes->removeAll(); 00778 00779 AbstractDOMParser::parse(systemId); 00780 00781 // Disabled until 4.0.0. See XERCESC-1894 for details. 00782 //if(getErrorCount()!=0) 00783 // throw DOMLSException(DOMLSException::PARSE_ERR, XMLDOMMsg::LSParser_ParsingFailed, fMemoryManager); 00784 00785 if (fUserAdoptsDocument) 00786 return adoptDocument(); 00787 else 00788 return getDocument(); 00789 } 00790 00791 DOMDocument* DOMLSParserImpl::parseURI(const char* const systemId) 00792 { 00793 if (getParseInProgress()) 00794 throw DOMException(DOMException::INVALID_STATE_ERR, XMLDOMMsg::LSParser_ParseInProgress, fMemoryManager); 00795 00796 // remove the abort filter, if present 00797 if(fFilter==&g_AbortFilter) 00798 fFilter=0; 00799 if(fFilterAction) 00800 fFilterAction->removeAll(); 00801 if(fFilterDelayedTextNodes) 00802 fFilterDelayedTextNodes->removeAll(); 00803 00804 AbstractDOMParser::parse(systemId); 00805 00806 // Disabled until 4.0.0. See XERCESC-1894 for details. 00807 //if(getErrorCount()!=0) 00808 // throw DOMLSException(DOMLSException::PARSE_ERR, XMLDOMMsg::LSParser_ParsingFailed, fMemoryManager); 00809 00810 if (fUserAdoptsDocument) 00811 return adoptDocument(); 00812 else 00813 return getDocument(); 00814 } 00815 00816 void DOMLSParserImpl::startDocument() 00817 { 00818 if(fWrapNodesInDocumentFragment) 00819 { 00820 fDocument = (DOMDocumentImpl*)fWrapNodesInDocumentFragment->getOwnerDocument(); 00821 fCurrentParent = fCurrentNode = fWrapNodesInDocumentFragment; 00822 // set DOM error checking off 00823 fDocument->setErrorChecking(false); 00824 00825 // if we have namespaces in scope, push them down to the reader 00826 ValueHashTableOf<unsigned int> inScopeNS(7, fMemoryManager); 00827 DOMNode* cursor = fWrapNodesContext; 00828 while(cursor) 00829 { 00830 if(cursor->getNodeType()==DOMNode::ELEMENT_NODE) 00831 { 00832 DOMNamedNodeMap* attrs = cursor->getAttributes(); 00833 for(XMLSize_t i=0; i<attrs->getLength(); i++) 00834 { 00835 DOMNode* attr = attrs->item(i); 00836 if(XMLString::equals(attr->getNamespaceURI(), XMLUni::fgXMLNSURIName) && !inScopeNS.containsKey(attr->getLocalName())) 00837 inScopeNS.put((void*)attr->getLocalName(), fScanner->getURIStringPool()->addOrFind(attr->getNodeValue())); 00838 else if(XMLString::equals(attr->getNodeName(), XMLUni::fgXMLNSString) && !inScopeNS.containsKey(XMLUni::fgZeroLenString)) 00839 inScopeNS.put((void*)XMLUni::fgZeroLenString, fScanner->getURIStringPool()->addOrFind(attr->getNodeValue())); 00840 } 00841 } 00842 cursor = cursor->getParentNode(); 00843 } 00844 ValueHashTableOfEnumerator<unsigned int> iter(&inScopeNS, false, fMemoryManager); 00845 while(iter.hasMoreElements()) 00846 { 00847 XMLCh* prefix = (XMLCh*)iter.nextElementKey(); 00848 fScanner->addGlobalPrefix(prefix, inScopeNS.get(prefix)); 00849 } 00850 00851 // in this case the document URI and the input encoding must be propagated to the context document 00852 if(fWrapNodesAction==ACTION_REPLACE_CHILDREN && fWrapNodesContext->getNodeType()==DOMNode::DOCUMENT_NODE) 00853 { 00854 fDocument->setDocumentURI(fScanner->getLocator()->getSystemId()); 00855 fDocument->setInputEncoding(fScanner->getReaderMgr()->getCurrentEncodingStr()); 00856 } 00857 } 00858 else 00859 AbstractDOMParser::startDocument(); 00860 } 00861 00862 void DOMLSParserImpl::XMLDecl( const XMLCh* const versionStr 00863 , const XMLCh* const encodingStr 00864 , const XMLCh* const standaloneStr 00865 , const XMLCh* const actualEncStr 00866 ) 00867 { 00868 if(fWrapNodesInDocumentFragment && !(fWrapNodesAction==ACTION_REPLACE_CHILDREN && fWrapNodesContext->getNodeType()==DOMNode::DOCUMENT_NODE)) 00869 { 00870 // don't change the properties for the context document, unless the context node is a 00871 // DOMDocument node and the action is ACTION_REPLACE_CHILDREN 00872 } 00873 else 00874 AbstractDOMParser::XMLDecl(versionStr, encodingStr, standaloneStr, actualEncStr); 00875 } 00876 00877 DOMNode* DOMLSParserImpl::parseWithContext(const DOMLSInput* source, 00878 DOMNode* contextNode, 00879 const ActionType action) 00880 { 00881 if (getParseInProgress()) 00882 throw DOMException(DOMException::INVALID_STATE_ERR, XMLDOMMsg::LSParser_ParseInProgress, fMemoryManager); 00883 00884 // remove the abort filter, if present 00885 if(fFilter==&g_AbortFilter) 00886 fFilter=0; 00887 if(fFilterAction) 00888 fFilterAction->removeAll(); 00889 if(fFilterDelayedTextNodes) 00890 fFilterDelayedTextNodes->removeAll(); 00891 00892 DOMDocumentFragment* holder = contextNode->getOwnerDocument()->createDocumentFragment(); 00893 // When parsing the input stream, the context node (or its parent, depending on where 00894 // the result will be inserted) is used for resolving unbound namespace prefixes 00895 if(action==ACTION_INSERT_BEFORE || action==ACTION_INSERT_AFTER || action==ACTION_REPLACE) 00896 fWrapNodesContext = contextNode->getParentNode(); 00897 else 00898 fWrapNodesContext = contextNode; 00899 fWrapNodesInDocumentFragment = holder; 00900 fWrapNodesAction = action; 00901 // When calling parseWithContext, the values of the following configuration parameters 00902 // will be ignored and their default values will always be used instead: "validate", 00903 // "validate-if-schema", and "element-content-whitespace". 00904 ValSchemes oldValidate = getValidationScheme(); 00905 setValidationScheme(Val_Never); 00906 bool oldElementContentWhitespace = getIncludeIgnorableWhitespace(); 00907 setIncludeIgnorableWhitespace(true); 00908 00909 Wrapper4DOMLSInput isWrapper((DOMLSInput*)source, fEntityResolver, false, getMemoryManager()); 00910 AbstractDOMParser::parse(isWrapper); 00911 00912 setValidationScheme(oldValidate); 00913 setIncludeIgnorableWhitespace(oldElementContentWhitespace); 00914 fWrapNodesContext = NULL; 00915 fWrapNodesInDocumentFragment = NULL; 00916 fDocument = NULL; 00917 00918 if(getErrorCount()!=0) 00919 { 00920 holder->release(); 00921 throw DOMLSException(DOMLSException::PARSE_ERR, XMLDOMMsg::LSParser_ParsingFailed, fMemoryManager); 00922 } 00923 00924 DOMNode* result = holder->getFirstChild(); 00925 DOMNode* node, *parent = contextNode->getParentNode(); 00926 switch(action) 00927 { 00928 case ACTION_REPLACE_CHILDREN: 00929 // remove existing children 00930 while((node = contextNode->getFirstChild())!=NULL) 00931 contextNode->removeChild(node)->release(); 00932 // then fall back to behave like an append 00933 case ACTION_APPEND_AS_CHILDREN: 00934 while((node = holder->getFirstChild())!=NULL) 00935 contextNode->appendChild(holder->removeChild(node)); 00936 break; 00937 case ACTION_INSERT_BEFORE: 00938 while((node = holder->getFirstChild())!=NULL) 00939 parent->insertBefore(holder->removeChild(node), contextNode); 00940 break; 00941 case ACTION_INSERT_AFTER: 00942 while((node = holder->getLastChild())!=NULL) 00943 parent->insertBefore(holder->removeChild(node), contextNode->getNextSibling()); 00944 break; 00945 case ACTION_REPLACE: 00946 while((node = holder->getFirstChild())!=NULL) 00947 parent->insertBefore(holder->removeChild(node), contextNode); 00948 parent->removeChild(contextNode)->release(); 00949 break; 00950 } 00951 holder->release(); 00952 00953 // TODO whenever we add support for DOM Mutation Events: 00954 // As the new data is inserted into the document, at least one mutation event is fired 00955 // per new immediate child or sibling of the context node. 00956 return result; 00957 } 00958 00959 void DOMLSParserImpl::abort() 00960 { 00961 fFilter=&g_AbortFilter; 00962 } 00963 00964 // --------------------------------------------------------------------------- 00965 // DOMLSParserImpl: Implementation of the XMLErrorReporter interface 00966 // --------------------------------------------------------------------------- 00967 void DOMLSParserImpl::error( const unsigned int code 00968 , const XMLCh* const 00969 , const XMLErrorReporter::ErrTypes errType 00970 , const XMLCh* const errorText 00971 , const XMLCh* const systemId 00972 , const XMLCh* const 00973 , const XMLFileLoc lineNum 00974 , const XMLFileLoc colNum) 00975 { 00976 if (fErrorHandler) { 00977 00978 DOMError::ErrorSeverity severity = DOMError::DOM_SEVERITY_ERROR; 00979 00980 if (errType == XMLErrorReporter::ErrType_Warning) 00981 severity = DOMError::DOM_SEVERITY_WARNING; 00982 else if (errType == XMLErrorReporter::ErrType_Fatal) 00983 severity = DOMError::DOM_SEVERITY_FATAL_ERROR; 00984 00985 DOMLocatorImpl location(lineNum, colNum, getCurrentNode(), systemId); 00986 if(getScanner()->getCalculateSrcOfs()) 00987 location.setByteOffset(getScanner()->getSrcOffset()); 00988 DOMErrorImpl domError(severity, errorText, &location); 00989 00990 // if user return false, we should stop the process, so throw an error 00991 bool toContinueProcess = true; 00992 try 00993 { 00994 toContinueProcess = fErrorHandler->handleError(domError); 00995 } 00996 catch(...) 00997 { 00998 } 00999 if (!toContinueProcess && !getScanner()->getInException()) 01000 throw (XMLErrs::Codes) code; 01001 } 01002 } 01003 01004 void DOMLSParserImpl::resetErrors() 01005 { 01006 } 01007 01008 01009 // --------------------------------------------------------------------------- 01010 // DOMLSParserImpl: Implementation of XMLEntityHandler interface 01011 // --------------------------------------------------------------------------- 01012 InputSource* 01013 DOMLSParserImpl::resolveEntity( XMLResourceIdentifier* resourceIdentifier ) 01014 { 01015 // 01016 // Just map it to the SAX entity resolver. If there is not one installed, 01017 // return a null pointer to cause the default resolution. 01018 // 01019 if (fEntityResolver) { 01020 DOMLSInput* is = fEntityResolver->resolveResource(resourceIdentifier->getResourceIdentifierType()==XMLResourceIdentifier::ExternalEntity?XMLUni::fgDOMDTDType:XMLUni::fgDOMXMLSchemaType, 01021 resourceIdentifier->getNameSpace(), 01022 resourceIdentifier->getPublicId(), 01023 resourceIdentifier->getSystemId(), 01024 resourceIdentifier->getBaseURI()); 01025 if (is) 01026 return new (getMemoryManager()) Wrapper4DOMLSInput(is, fEntityResolver, true, getMemoryManager()); 01027 } 01028 if (fXMLEntityResolver) { 01029 return(fXMLEntityResolver->resolveEntity(resourceIdentifier)); 01030 } 01031 01032 return 0; 01033 } 01034 01035 typedef JanitorMemFunCall<DOMLSParserImpl> ResetParseType; 01036 01037 // --------------------------------------------------------------------------- 01038 // DOMLSParserImpl: Grammar preparsing methods 01039 // --------------------------------------------------------------------------- 01040 Grammar* DOMLSParserImpl::loadGrammar(const char* const systemId, 01041 const Grammar::GrammarType grammarType, 01042 const bool toCache) 01043 { 01044 // Avoid multiple entrance 01045 if (getParseInProgress()) 01046 throw DOMException(DOMException::INVALID_STATE_ERR, XMLDOMMsg::LSParser_ParseInProgress, fMemoryManager); 01047 01048 ResetParseType resetParse(this, &DOMLSParserImpl::resetParse); 01049 01050 Grammar* grammar = 0; 01051 01052 try 01053 { 01054 setParseInProgress(true); 01055 if (grammarType == Grammar::DTDGrammarType) 01056 getScanner()->setDocTypeHandler(0); 01057 grammar = getScanner()->loadGrammar(systemId, grammarType, toCache); 01058 } 01059 catch(const OutOfMemoryException&) 01060 { 01061 resetParse.release(); 01062 01063 throw; 01064 } 01065 01066 return grammar; 01067 } 01068 01069 Grammar* DOMLSParserImpl::loadGrammar(const XMLCh* const systemId, 01070 const Grammar::GrammarType grammarType, 01071 const bool toCache) 01072 { 01073 // Avoid multiple entrance 01074 if (getParseInProgress()) 01075 throw DOMException(DOMException::INVALID_STATE_ERR, XMLDOMMsg::LSParser_ParseInProgress, fMemoryManager); 01076 01077 ResetParseType resetParse(this, &DOMLSParserImpl::resetParse); 01078 01079 Grammar* grammar = 0; 01080 01081 try 01082 { 01083 setParseInProgress(true); 01084 if (grammarType == Grammar::DTDGrammarType) 01085 getScanner()->setDocTypeHandler(0); 01086 grammar = getScanner()->loadGrammar(systemId, grammarType, toCache); 01087 } 01088 catch(const OutOfMemoryException&) 01089 { 01090 resetParse.release(); 01091 01092 throw; 01093 } 01094 01095 return grammar; 01096 } 01097 01098 Grammar* DOMLSParserImpl::loadGrammar(const DOMLSInput* source, 01099 const Grammar::GrammarType grammarType, 01100 const bool toCache) 01101 { 01102 // Avoid multiple entrance 01103 if (getParseInProgress()) 01104 throw DOMException(DOMException::INVALID_STATE_ERR, XMLDOMMsg::LSParser_ParseInProgress, fMemoryManager); 01105 01106 ResetParseType resetParse(this, &DOMLSParserImpl::resetParse); 01107 01108 Grammar* grammar = 0; 01109 01110 try 01111 { 01112 setParseInProgress(true); 01113 if (grammarType == Grammar::DTDGrammarType) 01114 getScanner()->setDocTypeHandler(0); 01115 Wrapper4DOMLSInput isWrapper((DOMLSInput*)source, fEntityResolver, false, getMemoryManager()); 01116 grammar = getScanner()->loadGrammar(isWrapper, grammarType, toCache); 01117 } 01118 catch(const OutOfMemoryException&) 01119 { 01120 resetParse.release(); 01121 01122 throw; 01123 } 01124 01125 return grammar; 01126 } 01127 01128 void DOMLSParserImpl::resetCachedGrammarPool() 01129 { 01130 getGrammarResolver()->resetCachedGrammar(); 01131 getScanner()->resetCachedGrammar(); 01132 } 01133 01134 void DOMLSParserImpl::resetParse() 01135 { 01136 if (getScanner()->getDocTypeHandler() == 0) 01137 { 01138 getScanner()->setDocTypeHandler(this); 01139 } 01140 01141 setParseInProgress(false); 01142 } 01143 01144 Grammar* DOMLSParserImpl::getGrammar(const XMLCh* const nameSpaceKey) const 01145 { 01146 return getGrammarResolver()->getGrammar(nameSpaceKey); 01147 } 01148 01149 Grammar* DOMLSParserImpl::getRootGrammar() const 01150 { 01151 return getScanner()->getRootGrammar(); 01152 } 01153 01154 const XMLCh* DOMLSParserImpl::getURIText(unsigned int uriId) const 01155 { 01156 return getScanner()->getURIText(uriId); 01157 } 01158 01159 XMLFilePos DOMLSParserImpl::getSrcOffset() const 01160 { 01161 return getScanner()->getSrcOffset(); 01162 } 01163 01164 void DOMLSParserImpl::applyFilter(DOMNode* node) 01165 { 01166 DOMLSParserFilter::FilterAction action; 01167 // if the parent was already rejected, reject this too 01168 if(fFilterAction && fFilterAction->containsKey(fCurrentParent) && fFilterAction->get(fCurrentParent)==DOMLSParserFilter::FILTER_REJECT) 01169 action = DOMLSParserFilter::FILTER_REJECT; 01170 else 01171 action = fFilter->acceptNode(node); 01172 01173 switch(action) 01174 { 01175 case DOMLSParserFilter::FILTER_ACCEPT: break; 01176 case DOMLSParserFilter::FILTER_REJECT: 01177 case DOMLSParserFilter::FILTER_SKIP: if(node==fCurrentNode) 01178 fCurrentNode = (node->getPreviousSibling()?node->getPreviousSibling():fCurrentParent); 01179 fCurrentParent->removeChild(node); 01180 node->release(); 01181 break; 01182 case DOMLSParserFilter::FILTER_INTERRUPT: throw DOMLSException(DOMLSException::PARSE_ERR, XMLDOMMsg::LSParser_ParsingAborted, fMemoryManager); 01183 } 01184 } 01185 01186 void DOMLSParserImpl::docCharacters(const XMLCh* const chars 01187 , const XMLSize_t length 01188 , const bool cdataSection) 01189 { 01190 AbstractDOMParser::docCharacters(chars, length, cdataSection); 01191 if(fFilter) 01192 { 01193 // send the notification for the previous text node 01194 if(fFilterDelayedTextNodes && fCurrentNode->getPreviousSibling() && fFilterDelayedTextNodes->containsKey(fCurrentNode->getPreviousSibling())) 01195 { 01196 DOMNode* textNode = fCurrentNode->getPreviousSibling(); 01197 fFilterDelayedTextNodes->removeKey(textNode); 01198 applyFilter(textNode); 01199 } 01200 DOMNodeFilter::ShowType whatToShow=fFilter->getWhatToShow(); 01201 if(cdataSection && (whatToShow & DOMNodeFilter::SHOW_CDATA_SECTION)) 01202 { 01203 applyFilter(fCurrentNode); 01204 } 01205 else if(!cdataSection && (whatToShow & DOMNodeFilter::SHOW_TEXT)) 01206 { 01207 if(fFilterDelayedTextNodes==0) 01208 fFilterDelayedTextNodes=new (fMemoryManager) ValueHashTableOf<bool, PtrHasher>(7, fMemoryManager); 01209 fFilterDelayedTextNodes->put(fCurrentNode, true); 01210 } 01211 } 01212 } 01213 01214 void DOMLSParserImpl::docComment(const XMLCh* const comment) 01215 { 01216 if(fFilter) 01217 { 01218 // send the notification for the previous text node 01219 if(fFilterDelayedTextNodes && fFilterDelayedTextNodes->containsKey(fCurrentNode)) 01220 { 01221 fFilterDelayedTextNodes->removeKey(fCurrentNode); 01222 applyFilter(fCurrentNode); 01223 } 01224 } 01225 01226 AbstractDOMParser::docComment(comment); 01227 if(fFilter) 01228 { 01229 DOMNodeFilter::ShowType whatToShow=fFilter->getWhatToShow(); 01230 if(whatToShow & DOMNodeFilter::SHOW_COMMENT) 01231 applyFilter(fCurrentNode); 01232 } 01233 } 01234 01235 void DOMLSParserImpl::docPI(const XMLCh* const target 01236 , const XMLCh* const data) 01237 { 01238 if(fFilter) 01239 { 01240 // send the notification for the previous text node 01241 if(fFilterDelayedTextNodes && fFilterDelayedTextNodes->containsKey(fCurrentNode)) 01242 { 01243 fFilterDelayedTextNodes->removeKey(fCurrentNode); 01244 applyFilter(fCurrentNode); 01245 } 01246 } 01247 01248 AbstractDOMParser::docPI(target, data); 01249 if(fFilter) 01250 { 01251 DOMNodeFilter::ShowType whatToShow=fFilter->getWhatToShow(); 01252 if(whatToShow & DOMNodeFilter::SHOW_PROCESSING_INSTRUCTION) 01253 applyFilter(fCurrentNode); 01254 } 01255 } 01256 01257 void DOMLSParserImpl::startEntityReference(const XMLEntityDecl& entDecl) 01258 { 01259 if(fCreateEntityReferenceNodes && fFilter) 01260 { 01261 // send the notification for the previous text node 01262 if(fFilterDelayedTextNodes && fFilterDelayedTextNodes->containsKey(fCurrentNode)) 01263 { 01264 fFilterDelayedTextNodes->removeKey(fCurrentNode); 01265 applyFilter(fCurrentNode); 01266 } 01267 } 01268 01269 DOMNode* origParent = fCurrentParent; 01270 AbstractDOMParser::startEntityReference(entDecl); 01271 if (fCreateEntityReferenceNodes && fFilter) 01272 { 01273 if(fFilterAction && fFilterAction->containsKey(origParent) && fFilterAction->get(origParent)==DOMLSParserFilter::FILTER_REJECT) 01274 fFilterAction->put(fCurrentNode, DOMLSParserFilter::FILTER_REJECT); 01275 } 01276 } 01277 01278 void DOMLSParserImpl::endElement(const XMLElementDecl& elemDecl 01279 , const unsigned int urlId 01280 , const bool isRoot 01281 , const XMLCh* const elemPrefix) 01282 { 01283 if(fFilter) 01284 { 01285 // send the notification for the previous text node 01286 if(fFilterDelayedTextNodes && fFilterDelayedTextNodes->containsKey(fCurrentNode)) 01287 { 01288 fFilterDelayedTextNodes->removeKey(fCurrentNode); 01289 applyFilter(fCurrentNode); 01290 } 01291 } 01292 01293 AbstractDOMParser::endElement(elemDecl, urlId, isRoot, elemPrefix); 01294 if(fFilter) 01295 { 01296 DOMNodeFilter::ShowType whatToShow=fFilter->getWhatToShow(); 01297 if(whatToShow & DOMNodeFilter::SHOW_ELEMENT) 01298 { 01299 DOMNode* thisNode = fCurrentNode; 01300 DOMLSParserFilter::FilterAction action; 01301 if(fFilterAction && fFilterAction->containsKey(thisNode)) 01302 { 01303 action = fFilterAction->get(thisNode); 01304 fFilterAction->removeKey(thisNode); 01305 } 01306 else 01307 action = fFilter->acceptNode(thisNode); 01308 switch(action) 01309 { 01310 case DOMLSParserFilter::FILTER_ACCEPT: break; 01311 case DOMLSParserFilter::FILTER_REJECT: fCurrentNode = (thisNode->getPreviousSibling()?thisNode->getPreviousSibling():fCurrentParent); 01312 fCurrentParent->removeChild(thisNode); 01313 thisNode->release(); 01314 break; 01315 case DOMLSParserFilter::FILTER_SKIP: { 01316 DOMNode* child=thisNode->getFirstChild(); 01317 while(child) 01318 { 01319 DOMNode* next=child->getNextSibling(); 01320 fCurrentParent->appendChild(child); 01321 child=next; 01322 } 01323 fCurrentNode = (thisNode->getPreviousSibling()?thisNode->getPreviousSibling():fCurrentParent); 01324 fCurrentParent->removeChild(thisNode); 01325 thisNode->release(); 01326 } 01327 break; 01328 case DOMLSParserFilter::FILTER_INTERRUPT: throw DOMLSException(DOMLSException::PARSE_ERR, XMLDOMMsg::LSParser_ParsingAborted, fMemoryManager); 01329 } 01330 } 01331 } 01332 } 01333 01334 void DOMLSParserImpl::startElement(const XMLElementDecl& elemDecl 01335 , const unsigned int urlId 01336 , const XMLCh* const elemPrefix 01337 , const RefVectorOf<XMLAttr>& attrList 01338 , const XMLSize_t attrCount 01339 , const bool isEmpty 01340 , const bool isRoot) 01341 { 01342 if(fFilter) 01343 { 01344 // send the notification for the previous text node 01345 if(fFilterDelayedTextNodes && fFilterDelayedTextNodes->containsKey(fCurrentNode)) 01346 { 01347 fFilterDelayedTextNodes->removeKey(fCurrentNode); 01348 applyFilter(fCurrentNode); 01349 } 01350 } 01351 01352 DOMNode* origParent = fCurrentParent; 01353 AbstractDOMParser::startElement(elemDecl, urlId, elemPrefix, attrList, attrCount, false, isRoot); 01354 if(fFilter) 01355 { 01356 // if the parent was already rejected, reject this too 01357 if(fFilterAction && fFilterAction->containsKey(origParent) && fFilterAction->get(origParent)==DOMLSParserFilter::FILTER_REJECT) 01358 fFilterAction->put(fCurrentNode, DOMLSParserFilter::FILTER_REJECT); 01359 else 01360 { 01361 DOMLSParserFilter::FilterAction action = fFilter->startElement((DOMElement*)fCurrentNode); 01362 01363 switch(action) 01364 { 01365 case DOMLSParserFilter::FILTER_ACCEPT: break; 01366 case DOMLSParserFilter::FILTER_REJECT: 01367 case DOMLSParserFilter::FILTER_SKIP: if(fFilterAction==0) 01368 fFilterAction=new (fMemoryManager) ValueHashTableOf<DOMLSParserFilter::FilterAction, PtrHasher>(7, fMemoryManager); 01369 fFilterAction->put(fCurrentNode, action); 01370 break; 01371 case DOMLSParserFilter::FILTER_INTERRUPT: throw DOMLSException(DOMLSException::PARSE_ERR, XMLDOMMsg::LSParser_ParsingAborted, fMemoryManager); 01372 } 01373 } 01374 } 01375 if(isEmpty) 01376 endElement(elemDecl, urlId, isRoot, elemPrefix); 01377 } 01378 01379 XERCES_CPP_NAMESPACE_END