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_DTDSCANNER_HPP)
0023 #define XERCESC_INCLUDE_GUARD_DTDSCANNER_HPP
0024 
0025 #include <xercesc/validators/DTD/DTDGrammar.hpp>
0026 #include <xercesc/validators/DTD/DTDEntityDecl.hpp>
0027 
0028 XERCES_CPP_NAMESPACE_BEGIN
0029 
0030 class XMLScanner;
0031 
0032 /*
0033  * Default implementation of an XML DTD scanner.
0034  */
0035 class DocTypeHandler;
0036 
0037 class VALIDATORS_EXPORT DTDScanner : public XMemory
0038 {
0039 public:
0040     // -----------------------------------------------------------------------
0041     //  Class specific types
0042     //
0043     //  EntityExpRes
0044     //      Returned from scanEntityRef() to indicate how the expanded text
0045     //      was treated.
0046     //
0047     //  IDTypes
0048     //      Type of the ID
0049     // -----------------------------------------------------------------------
0050     enum EntityExpRes
0051     {
0052         EntityExp_Failed
0053         , EntityExp_Pushed
0054         , EntityExp_Returned
0055     };
0056 
0057     enum IDTypes
0058     {
0059         IDType_Public
0060         , IDType_External
0061         , IDType_Either
0062     };
0063 
0064 
0065 
0066     // -----------------------------------------------------------------------
0067     //  Constructors and Destructor
0068     // -----------------------------------------------------------------------
0069     DTDScanner
0070     (
0071           DTDGrammar*           dtdGrammar
0072         , DocTypeHandler* const docTypeHandler
0073         , MemoryManager* const  grammarPoolMemoryManager
0074         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
0075     );
0076     virtual ~DTDScanner();
0077 
0078     // -----------------------------------------------------------------------
0079     //  Getter methods
0080     // -----------------------------------------------------------------------
0081     DocTypeHandler* getDocTypeHandler();
0082     const DocTypeHandler* getDocTypeHandler() const;
0083 
0084     // -----------------------------------------------------------------------
0085     //  Setter methods
0086     //
0087     //  setScannerInfo() is called by the scanner to tell the DTDScanner
0088     //  about the stuff it needs to have access to.
0089     // -----------------------------------------------------------------------
0090     void setScannerInfo
0091     (
0092         XMLScanner* const           owningScanner
0093         , ReaderMgr* const          readerMgr
0094         , XMLBufferMgr* const       bufMgr
0095     );
0096 
0097     void setDocTypeHandler
0098     (
0099             DocTypeHandler* const handlerToSet
0100     );
0101 
0102     void scanExtSubsetDecl(const bool inIncludeSect, const bool isDTD);
0103     bool scanInternalSubset();
0104     bool scanId
0105     (
0106                 XMLBuffer&  pubIdToFill
0107         ,       XMLBuffer&  sysIdToFill
0108         , const IDTypes     whatKind
0109     );
0110 
0111 private:
0112     // -----------------------------------------------------------------------
0113     // Unimplemented constructors and operators
0114     // -----------------------------------------------------------------------
0115     DTDScanner(const DTDScanner &);
0116     DTDScanner& operator = (const  DTDScanner&);
0117 
0118     // -----------------------------------------------------------------------
0119     //  Private DTD scanning methods. These are all in XMLValidator2.cpp
0120     // -----------------------------------------------------------------------
0121     bool checkForPERef
0122     (
0123           const bool    inLiteral
0124         , const bool    inMarkup
0125     );
0126     bool expandPERef
0127     (
0128         const   bool    scanExternal
0129         , const bool    inLiteral
0130         , const bool    inMarkup
0131         , const bool    throwEndOfExt = false
0132     );
0133     bool getQuotedString(XMLBuffer& toFill);
0134     XMLAttDef* scanAttDef(DTDElementDecl& elemDecl, XMLBuffer& bufToUse);
0135     bool scanAttValue
0136     (
0137         const   XMLCh* const        attrName
0138         ,       XMLBuffer&          toFill
0139         , const XMLAttDef::AttTypes type
0140     );
0141     void scanAttListDecl();
0142     ContentSpecNode* scanChildren
0143     (
0144         const   DTDElementDecl&     elemDecl
0145         ,       XMLBuffer&          bufToUse
0146         ,       unsigned int&       depth
0147     );
0148     bool scanCharRef(XMLCh& toFill, XMLCh& second);
0149     void scanComment();
0150     bool scanContentSpec(DTDElementDecl& toFill);
0151     void scanDefaultDecl(DTDAttDef& toFill);
0152     void scanElementDecl();
0153     void scanEntityDecl();
0154     bool scanEntityDef();
0155     bool scanEntityLiteral(XMLBuffer& toFill);
0156     bool scanEntityDef(DTDEntityDecl& decl, const bool isPEDecl);
0157     EntityExpRes scanEntityRef(XMLCh& firstCh, XMLCh& secondCh, bool& escaped);
0158     bool scanEnumeration
0159     (
0160         const   DTDAttDef&  attDef
0161         ,       XMLBuffer&  toFill
0162         , const bool        notation
0163     );
0164     bool scanEq();
0165     void scanIgnoredSection();
0166     void scanMarkupDecl(const bool parseTextDecl);
0167     bool scanMixed(DTDElementDecl& toFill);
0168     void scanNotationDecl();
0169     void scanPI();
0170     bool scanPublicLiteral(XMLBuffer& toFill);
0171     bool scanSystemLiteral(XMLBuffer& toFill);
0172     void scanTextDecl();
0173     bool isReadingExternalEntity();
0174 
0175 
0176     // -----------------------------------------------------------------------
0177     //  Private data members
0178     //
0179     //  fDocTypeHandler
0180     //      This holds the optional doc type handler that can be installed
0181     //      and used to call back for all markup events. It is DTD specific.
0182     //
0183     //  fDumAttDef
0184     //  fDumElemDecl
0185     //  fDumEntityDecl
0186     //      These are dummy objects into which mark decls are parsed when
0187     //      they are just overrides of previously declared markup decls. In
0188     //      such situations, the first one wins but we need to have somewhere
0189     //      to parse them into. So these are lazily created and used as needed
0190     //      when such markup decls are seen.
0191     //
0192     //  fInternalSubset
0193     //      This is used to track whether we are in the internal subset or not,
0194     //      in which case we are in the external subset.
0195     //
0196     //  fNextAttrId
0197     //      Since att defs are per-element, we don't have a validator wide
0198     //      attribute def pool. So we use a simpler data structure in each
0199     //      element decl to store its att defs, and we use this simple counter
0200     //      to apply a unique id to each new attribute.
0201     //
0202     //  fDTDGrammar
0203     //      The DTD information we scanned like element decl, attribute decl
0204     //      are stored in this Grammar.
0205     //
0206     //  fBufMgr
0207     //      This is the buffer manager of the scanner. This is provided as a
0208     //      convenience so that the DTDScanner doesn't have to create its own
0209     //      buffer manager during the parse process.
0210     //
0211     //  fReaderMgr
0212     //      This is a pointer to the reader manager that is being used by the scanner.
0213     //
0214     //  fScanner
0215     //      The pointer to the scanner to which this DTDScanner belongs
0216     //
0217     //  fPEntityDeclPool
0218     //      This is a pool of EntityDecl objects, which contains all of the
0219     //      parameter entities that are declared in the DTD subsets.
0220     //
0221     //  fEmptyNamespaceId
0222     //      The uri for all DTD decls
0223     //
0224     //  fDocTypeReaderId
0225     //      The original reader in the fReaderMgr - to be compared against the
0226     //      current reader to decide whether we are processing an external/internal
0227     //      declaration
0228     // -----------------------------------------------------------------------
0229     MemoryManager*                  fMemoryManager;
0230     MemoryManager*                  fGrammarPoolMemoryManager;
0231     DocTypeHandler*                 fDocTypeHandler;
0232     DTDAttDef*                      fDumAttDef;
0233     DTDElementDecl*                 fDumElemDecl;
0234     DTDEntityDecl*                  fDumEntityDecl;
0235     bool                            fInternalSubset;
0236     unsigned int                    fNextAttrId;
0237     DTDGrammar*                     fDTDGrammar;
0238     XMLBufferMgr*                   fBufMgr;
0239     ReaderMgr*                      fReaderMgr;
0240     XMLScanner*                     fScanner;
0241     NameIdPool<DTDEntityDecl>*      fPEntityDeclPool;
0242     unsigned int                    fEmptyNamespaceId;
0243     XMLSize_t                       fDocTypeReaderId;
0244 };
0245 
0246 
0247 // ---------------------------------------------------------------------------
0248 //  DTDScanner: Getter methods
0249 // ---------------------------------------------------------------------------
0250 inline DocTypeHandler* DTDScanner::getDocTypeHandler()
0251 {
0252     return fDocTypeHandler;
0253 }
0254 
0255 inline const DocTypeHandler* DTDScanner::getDocTypeHandler() const
0256 {
0257     return fDocTypeHandler;
0258 }
0259 
0260 
0261 // ---------------------------------------------------------------------------
0262 //  DTDScanner: Setter methods
0263 // ---------------------------------------------------------------------------
0264 inline void DTDScanner::setDocTypeHandler(DocTypeHandler* const handlerToSet)
0265 {
0266     fDocTypeHandler = handlerToSet;
0267 }
0268 
0269 // -----------------------------------------------------------------------
0270 //  Helper methods
0271 // -----------------------------------------------------------------------
0272 inline bool DTDScanner::isReadingExternalEntity() {
0273     return (fDocTypeReaderId != fReaderMgr->getCurrentReaderNum());
0274 }
0275 
0276 XERCES_CPP_NAMESPACE_END
0277 
0278 #endif