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 00018 /* 00019 * $Id: ValidationContextImpl.cpp 903149 2010-01-26 09:58:40Z borisk $ 00020 */ 00021 00022 00023 // --------------------------------------------------------------------------- 00024 // Includes 00025 // --------------------------------------------------------------------------- 00026 #include <xercesc/internal/ValidationContextImpl.hpp> 00027 #include <xercesc/framework/XMLRefInfo.hpp> 00028 #include <xercesc/validators/DTD/DTDEntityDecl.hpp> 00029 #include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp> 00030 #include <xercesc/validators/schema/NamespaceScope.hpp> 00031 #include <xercesc/internal/ElemStack.hpp> 00032 #include <xercesc/internal/XMLScanner.hpp> 00033 00034 XERCES_CPP_NAMESPACE_BEGIN 00035 00036 // --------------------------------------------------------------------------- 00037 // Constructor and Destructor 00038 // --------------------------------------------------------------------------- 00039 00040 ValidationContextImpl::~ValidationContextImpl() 00041 { 00042 if (fIdRefList) 00043 delete fIdRefList; 00044 } 00045 00046 ValidationContextImpl::ValidationContextImpl(MemoryManager* const manager) 00047 :ValidationContext(manager) 00048 ,fIdRefList(0) 00049 ,fEntityDeclPool(0) 00050 ,fToCheckIdRefList(true) 00051 ,fValidatingMemberType(0) 00052 ,fElemStack(0) 00053 ,fScanner(0) 00054 ,fNamespaceScope(0) 00055 { 00056 fIdRefList = new (fMemoryManager) RefHashTableOf<XMLRefInfo>(109, fMemoryManager); 00057 } 00058 00063 RefHashTableOf<XMLRefInfo>* ValidationContextImpl::getIdRefList() const 00064 { 00065 return fIdRefList; 00066 } 00067 00068 void ValidationContextImpl::setIdRefList(RefHashTableOf<XMLRefInfo>* const newIdRefList) 00069 { 00070 if (fIdRefList) 00071 delete fIdRefList; 00072 00073 fIdRefList = newIdRefList; 00074 } 00075 00076 void ValidationContextImpl::clearIdRefList() 00077 { 00078 if (fIdRefList) 00079 fIdRefList->removeAll(); 00080 00081 } 00082 00083 void ValidationContextImpl::addId(const XMLCh * const content) 00084 { 00085 if (!fIdRefList || !fToCheckIdRefList) 00086 return; 00087 00088 XMLRefInfo* idEntry = fIdRefList->get(content); 00089 00090 if (idEntry) 00091 { 00092 if (idEntry->getDeclared()) 00093 { 00094 ThrowXMLwithMemMgr1(InvalidDatatypeValueException 00095 , XMLExcepts::VALUE_ID_Not_Unique 00096 , content 00097 , fMemoryManager); 00098 } 00099 } 00100 else 00101 { 00102 idEntry = new (fMemoryManager) XMLRefInfo(content, false, false, fMemoryManager); 00103 fIdRefList->put((void*)idEntry->getRefName(), idEntry); 00104 } 00105 00106 // 00107 // Mark it declared 00108 // 00109 idEntry->setDeclared(true); 00110 00111 } 00112 00113 void ValidationContextImpl::addIdRef(const XMLCh * const content) 00114 { 00115 if (!fIdRefList || !fToCheckIdRefList) 00116 return; 00117 00118 XMLRefInfo* idEntry = fIdRefList->get(content); 00119 00120 if (!idEntry) 00121 { 00122 idEntry = new (fMemoryManager) XMLRefInfo(content, false, false, fMemoryManager); 00123 fIdRefList->put((void*)idEntry->getRefName(), idEntry); 00124 } 00125 00126 // 00127 // Mark it used 00128 // 00129 idEntry->setUsed(true); 00130 00131 } 00132 00133 void ValidationContextImpl::toCheckIdRefList(bool toCheck) 00134 { 00135 fToCheckIdRefList = toCheck; 00136 } 00137 00142 const NameIdPool<DTDEntityDecl>* ValidationContextImpl::getEntityDeclPool() const 00143 { 00144 return fEntityDeclPool; 00145 } 00146 00147 const NameIdPool<DTDEntityDecl>* ValidationContextImpl::setEntityDeclPool(const NameIdPool<DTDEntityDecl>* const newEntityDeclPool) 00148 { 00149 // we don't own it so we return the existing one for the owner to delete 00150 const NameIdPool<DTDEntityDecl>* tempPool = fEntityDeclPool; 00151 fEntityDeclPool = newEntityDeclPool; 00152 return tempPool; 00153 00154 } 00155 00156 void ValidationContextImpl::checkEntity(const XMLCh * const content) const 00157 { 00158 00159 if (fEntityDeclPool) 00160 { 00161 const DTDEntityDecl* decl = fEntityDeclPool->getByKey(content); 00162 00163 if (!decl || !decl->isUnparsed()) 00164 { 00165 ThrowXMLwithMemMgr1(InvalidDatatypeValueException 00166 , XMLExcepts::VALUE_ENTITY_Invalid 00167 , content 00168 , fMemoryManager); 00169 } 00170 00171 } 00172 else 00173 { 00174 ThrowXMLwithMemMgr1 00175 ( 00176 InvalidDatatypeValueException 00177 , XMLExcepts::VALUE_ENTITY_Invalid 00178 , content 00179 , fMemoryManager 00180 ); 00181 } 00182 00183 } 00184 00185 /* QName 00186 */ 00187 bool ValidationContextImpl::isPrefixUnknown(XMLCh* prefix) { 00188 bool unknown = false; 00189 if (XMLString::equals(prefix, XMLUni::fgXMLNSString)) { 00190 return true; 00191 } 00192 else if (!XMLString::equals(prefix, XMLUni::fgXMLString)) { 00193 if(fElemStack && !fElemStack->isEmpty()) 00194 fElemStack->mapPrefixToURI(prefix, unknown); 00195 else if(fNamespaceScope) 00196 unknown = (fNamespaceScope->getNamespaceForPrefix(prefix)==fNamespaceScope->getEmptyNamespaceId()); 00197 } 00198 return unknown; 00199 } 00200 00201 const XMLCh* ValidationContextImpl::getURIForPrefix(XMLCh* prefix) { 00202 bool unknown = false; 00203 unsigned int uriId = 0; 00204 if(fElemStack) 00205 uriId = fElemStack->mapPrefixToURI(prefix, unknown); 00206 else if(fNamespaceScope) 00207 { 00208 uriId = fNamespaceScope->getNamespaceForPrefix(prefix); 00209 unknown = uriId == fNamespaceScope->getEmptyNamespaceId(); 00210 } 00211 if (!unknown) 00212 return fScanner->getURIText(uriId); 00213 00214 return XMLUni::fgZeroLenString; 00215 } 00216 00217 XERCES_CPP_NAMESPACE_END