Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:27:30

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_DTDGRAMMAR_HPP)
0023 #define XERCESC_INCLUDE_GUARD_DTDGRAMMAR_HPP
0024 
0025 #include <xercesc/util/RefHashTableOf.hpp>
0026 #include <xercesc/util/NameIdPool.hpp>
0027 #include <xercesc/util/StringPool.hpp>
0028 #include <xercesc/validators/common/Grammar.hpp>
0029 #include <xercesc/validators/DTD/DTDElementDecl.hpp>
0030 #include <xercesc/validators/DTD/DTDEntityDecl.hpp>
0031 #include <xercesc/framework/XMLDTDDescription.hpp>
0032 
0033 
0034 XERCES_CPP_NAMESPACE_BEGIN
0035 
0036 //
0037 // This class stores the DTD information
0038 //  NOTE: DTDs are not namespace aware, so we just use regular NameIdPool
0039 //  data structures to store element and attribute decls. They are all set
0040 //  to be in the global namespace and the full QName is used as the base name
0041 //  of the decl. This means that all the URI parameters below are expected
0042 //  to be null pointers (and anything else will cause an exception.)
0043 //
0044 
0045 class VALIDATORS_EXPORT DTDGrammar : public Grammar
0046 {
0047 public:
0048     // -----------------------------------------------------------------------
0049     //  Constructors and Destructor
0050     // -----------------------------------------------------------------------
0051     DTDGrammar(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0052     virtual ~DTDGrammar();
0053 
0054     // -----------------------------------------------------------------------
0055     //  Implementation of Virtual Interface
0056     // -----------------------------------------------------------------------
0057     virtual Grammar::GrammarType getGrammarType() const;
0058     virtual const XMLCh* getTargetNamespace() const;
0059 
0060     // this method should only be used while the grammar is being
0061     // constructed, not while it is being used
0062     // in a validation episode!
0063     virtual XMLElementDecl* findOrAddElemDecl
0064     (
0065         const   unsigned int    uriId
0066         , const XMLCh* const    baseName
0067         , const XMLCh* const    prefixName
0068         , const XMLCh* const    qName
0069         , unsigned int          scope
0070         ,       bool&           wasAdded
0071     ) ;
0072 
0073     virtual XMLSize_t getElemId
0074     (
0075         const   unsigned int    uriId
0076         , const XMLCh* const    baseName
0077         , const XMLCh* const    qName
0078         , unsigned int          scope
0079     )   const ;
0080 
0081     virtual const XMLElementDecl* getElemDecl
0082     (
0083         const   unsigned int    uriId
0084         , const XMLCh* const    baseName
0085         , const XMLCh* const    qName
0086         , unsigned int          scope
0087     )   const ;
0088 
0089     virtual XMLElementDecl* getElemDecl
0090     (
0091         const   unsigned int    uriId
0092         , const XMLCh* const    baseName
0093         , const XMLCh* const    qName
0094         , unsigned int          scope
0095     );
0096 
0097     virtual const XMLElementDecl* getElemDecl
0098     (
0099         const   unsigned int    elemId
0100     )   const;
0101 
0102     virtual XMLElementDecl* getElemDecl
0103     (
0104         const   unsigned int    elemId
0105     );
0106 
0107     virtual const XMLNotationDecl* getNotationDecl
0108     (
0109         const   XMLCh* const    notName
0110     )   const;
0111 
0112     virtual XMLNotationDecl* getNotationDecl
0113     (
0114         const   XMLCh* const    notName
0115     );
0116 
0117     virtual bool getValidated() const;
0118 
0119     virtual XMLElementDecl* putElemDecl
0120     (
0121         const   unsigned int    uriId
0122         , const XMLCh* const    baseName
0123         , const XMLCh* const    prefixName
0124         , const XMLCh* const    qName
0125         , unsigned int          scope
0126         , const bool            notDeclared = false
0127     );
0128 
0129     virtual XMLSize_t putElemDecl
0130     (
0131         XMLElementDecl* const elemDecl
0132         , const bool          notDeclared = false
0133     )   ;
0134 
0135     virtual XMLSize_t putNotationDecl
0136     (
0137         XMLNotationDecl* const notationDecl
0138     )   const;
0139 
0140     virtual void setValidated(const bool newState);
0141 
0142     virtual void reset();
0143 
0144     // -----------------------------------------------------------------------
0145     //  Getter methods
0146     // -----------------------------------------------------------------------
0147 
0148     const DTDEntityDecl* getEntityDecl(const XMLCh* const entName) const;
0149     DTDEntityDecl* getEntityDecl(const XMLCh* const entName);
0150     NameIdPool<DTDEntityDecl>* getEntityDeclPool();
0151     const NameIdPool<DTDEntityDecl>* getEntityDeclPool() const;
0152     NameIdPoolEnumerator<DTDElementDecl> getElemEnumerator() const;
0153     NameIdPoolEnumerator<DTDEntityDecl> getEntityEnumerator() const;
0154     NameIdPoolEnumerator<XMLNotationDecl> getNotationEnumerator() const;
0155 
0156     // -----------------------------------------------------------------------
0157     //  Setter methods
0158     // -----------------------------------------------------------------------
0159 
0160     virtual void                    setGrammarDescription( XMLGrammarDescription*);
0161     virtual XMLGrammarDescription*  getGrammarDescription() const;
0162 
0163     // -----------------------------------------------------------------------
0164     //  Content management methods
0165     // -----------------------------------------------------------------------
0166     XMLSize_t putEntityDecl(DTDEntityDecl* const entityDecl) const;
0167 
0168     /***
0169      * Support for Serialization/De-serialization
0170      ***/
0171     DECL_XSERIALIZABLE(DTDGrammar)
0172 
0173 private:
0174     // -----------------------------------------------------------------------
0175     // Unimplemented constructors and operators
0176     // -----------------------------------------------------------------------
0177     DTDGrammar(const DTDGrammar &);
0178     DTDGrammar& operator = (const  DTDGrammar&);
0179 
0180     // -----------------------------------------------------------------------
0181     //  Private data members
0182     //
0183     //  fElemDeclPool
0184     //      This is the element decl pool. It contains all of the elements
0185     //      declared in the DTD (and their associated attributes.)
0186     //
0187     //  fElemNonDeclPool
0188     //      This is the element decl pool that is is populated as new elements
0189     //      are seen in the XML document (not declared in the DTD), and they
0190     //      are given default characteristics.
0191     //
0192     //  fEntityDeclPool
0193     //      This is a pool of EntityDecl objects, which contains all of the
0194     //      general entities that are declared in the DTD subsets, plus the
0195     //      default entities (such as &gt; &lt; ...) defined by the XML Standard.
0196     //
0197     //  fNotationDeclPool
0198     //      This is a pool of NotationDecl objects, which contains all of the
0199     //      notations declared in the DTD subsets.
0200     //
0201     //  fValidated
0202     //      Indicates if the content of the Grammar has been pre-validated
0203     //      or not. When using a cached grammar, no need for pre content
0204     //      validation.
0205     //
0206     //  fGramDesc: adopted
0207     //
0208     // -----------------------------------------------------------------------
0209     static NameIdPool<DTDEntityDecl>* fDefaultEntities;
0210     MemoryManager*                    fMemoryManager;
0211     NameIdPool<DTDElementDecl>*       fElemDeclPool;
0212     NameIdPool<DTDElementDecl>*       fElemNonDeclPool;
0213     NameIdPool<DTDEntityDecl>*        fEntityDeclPool;
0214     NameIdPool<XMLNotationDecl>*      fNotationDeclPool;
0215     XMLDTDDescription*                fGramDesc;
0216 
0217     bool                              fValidated;
0218 
0219     friend class XMLInitializer;
0220 };
0221 
0222 // ---------------------------------------------------------------------------
0223 //  DTDGrammar: Getter methods
0224 // ---------------------------------------------------------------------------
0225 inline NameIdPoolEnumerator<DTDElementDecl>
0226 DTDGrammar::getElemEnumerator() const
0227 {
0228     return NameIdPoolEnumerator<DTDElementDecl>(fElemDeclPool, fMemoryManager);
0229 }
0230 
0231 inline NameIdPoolEnumerator<DTDEntityDecl>
0232 DTDGrammar::getEntityEnumerator() const
0233 {
0234     return NameIdPoolEnumerator<DTDEntityDecl>(fEntityDeclPool, fMemoryManager);
0235 }
0236 
0237 inline NameIdPoolEnumerator<XMLNotationDecl>
0238 DTDGrammar::getNotationEnumerator() const
0239 {
0240     return NameIdPoolEnumerator<XMLNotationDecl>(fNotationDeclPool, fMemoryManager);
0241 }
0242 
0243 inline const DTDEntityDecl*
0244 DTDGrammar::getEntityDecl(const XMLCh* const entName) const
0245 {
0246     DTDEntityDecl* decl = fDefaultEntities->getByKey(entName);
0247 
0248     if (!decl)
0249         return fEntityDeclPool->getByKey(entName);
0250 
0251     return decl;
0252 }
0253 
0254 inline DTDEntityDecl* DTDGrammar::getEntityDecl(const XMLCh* const entName)
0255 {
0256     DTDEntityDecl* decl = fDefaultEntities->getByKey(entName);
0257 
0258     if (!decl)
0259         return fEntityDeclPool->getByKey(entName);
0260 
0261     return decl;
0262 }
0263 
0264 
0265 inline NameIdPool<DTDEntityDecl>* DTDGrammar::getEntityDeclPool()
0266 {
0267     return fEntityDeclPool;
0268 }
0269 
0270 inline const NameIdPool<DTDEntityDecl>* DTDGrammar::getEntityDeclPool() const
0271 {
0272     return fEntityDeclPool;
0273 }
0274 
0275 // -----------------------------------------------------------------------
0276 //  Setter methods
0277 // -----------------------------------------------------------------------
0278 inline XMLSize_t DTDGrammar::putEntityDecl(DTDEntityDecl* const entityDecl)   const
0279 {
0280     return fEntityDeclPool->put(entityDecl);
0281 }
0282 
0283 
0284 // ---------------------------------------------------------------------------
0285 //  DTDGrammar: Virtual methods
0286 // ---------------------------------------------------------------------------
0287 inline Grammar::GrammarType DTDGrammar::getGrammarType() const {
0288     return Grammar::DTDGrammarType;
0289 }
0290 
0291 inline const XMLCh* DTDGrammar::getTargetNamespace() const {
0292     return XMLUni::fgZeroLenString;
0293 }
0294 
0295 // Element Decl
0296 inline XMLSize_t DTDGrammar::getElemId (const   unsigned int
0297                                               , const XMLCh* const
0298                                               , const XMLCh* const    qName
0299                                               , unsigned int) const
0300 {
0301     //
0302     //  In this case, we don't return zero to mean 'not found', so we have to
0303     //  map it to the official not found value if we don't find it.
0304     //
0305     const DTDElementDecl* decl = fElemDeclPool->getByKey(qName);
0306     if (!decl)
0307         return XMLElementDecl::fgInvalidElemId;
0308     return decl->getId();
0309 }
0310 
0311 inline const XMLElementDecl* DTDGrammar::getElemDecl( const   unsigned int
0312                                               , const XMLCh* const
0313                                               , const XMLCh* const    qName
0314                                               , unsigned int)   const
0315 {
0316     const XMLElementDecl* elemDecl = fElemDeclPool->getByKey(qName);
0317 
0318     if (!elemDecl && fElemNonDeclPool)
0319         elemDecl = fElemNonDeclPool->getByKey(qName);
0320 
0321     return elemDecl;
0322 }
0323 
0324 inline XMLElementDecl* DTDGrammar::getElemDecl (const   unsigned int
0325                                               , const XMLCh* const
0326                                               , const XMLCh* const    qName
0327                                               , unsigned int)
0328 {
0329     XMLElementDecl* elemDecl = fElemDeclPool->getByKey(qName);
0330 
0331     if (!elemDecl && fElemNonDeclPool)
0332         elemDecl = fElemNonDeclPool->getByKey(qName);
0333 
0334     return elemDecl;
0335 }
0336 
0337 inline const XMLElementDecl* DTDGrammar::getElemDecl(const unsigned int elemId) const
0338 {
0339     // Look up this element decl by id
0340     return fElemDeclPool->getById(elemId);
0341 }
0342 
0343 inline XMLElementDecl* DTDGrammar::getElemDecl(const unsigned int elemId)
0344 {
0345     // Look up this element decl by id
0346     return fElemDeclPool->getById(elemId);
0347 }
0348 
0349 inline XMLSize_t
0350 DTDGrammar::putElemDecl(XMLElementDecl* const elemDecl,
0351                         const bool notDeclared)
0352 {
0353     if (notDeclared)
0354     {
0355         if(!fElemNonDeclPool)
0356             fElemNonDeclPool = new (fMemoryManager) NameIdPool<DTDElementDecl>(29, 128, fMemoryManager);
0357         return fElemNonDeclPool->put((DTDElementDecl*) elemDecl);
0358     }
0359 
0360     return fElemDeclPool->put((DTDElementDecl*) elemDecl);
0361 }
0362 
0363 // Notation Decl
0364 inline const XMLNotationDecl* DTDGrammar::getNotationDecl(const XMLCh* const notName) const
0365 {
0366     return fNotationDeclPool->getByKey(notName);
0367 }
0368 
0369 inline XMLNotationDecl* DTDGrammar::getNotationDecl(const XMLCh* const notName)
0370 {
0371     return fNotationDeclPool->getByKey(notName);
0372 }
0373 
0374 inline XMLSize_t DTDGrammar::putNotationDecl(XMLNotationDecl* const notationDecl)   const
0375 {
0376     return fNotationDeclPool->put(notationDecl);
0377 }
0378 
0379 inline bool DTDGrammar::getValidated() const
0380 {
0381     return fValidated;
0382 }
0383 
0384 inline void DTDGrammar::setValidated(const bool newState)
0385 {
0386     fValidated = newState;
0387 }
0388 
0389 XERCES_CPP_NAMESPACE_END
0390 
0391 #endif