Home | History | Annotate | Download | only in xml
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #ifndef _FX_SAX_IMP_
      8 #define _FX_SAX_IMP_
      9 
     10 class CFX_SAXFile {
     11  public:
     12   CFX_SAXFile();
     13   FX_BOOL StartFile(IFX_FileRead* pFile, FX_DWORD dwStart, FX_DWORD dwLen);
     14   FX_BOOL ReadNextBlock();
     15   void Reset();
     16   IFX_FileRead* m_pFile;
     17   FX_DWORD m_dwStart;
     18   FX_DWORD m_dwEnd;
     19   FX_DWORD m_dwCur;
     20   uint8_t* m_pBuf;
     21   FX_DWORD m_dwBufSize;
     22   FX_DWORD m_dwBufIndex;
     23 };
     24 enum FX_SAXMODE {
     25   FX_SAXMODE_Text = 0,
     26   FX_SAXMODE_NodeStart,
     27   FX_SAXMODE_DeclOrComment,
     28   FX_SAXMODE_DeclNode,
     29   FX_SAXMODE_Comment,
     30   FX_SAXMODE_CommentContent,
     31   FX_SAXMODE_TagName,
     32   FX_SAXMODE_TagAttributeName,
     33   FX_SAXMODE_TagAttributeEqual,
     34   FX_SAXMODE_TagAttributeValue,
     35   FX_SAXMODE_TagMaybeClose,
     36   FX_SAXMODE_TagClose,
     37   FX_SAXMODE_TagEnd,
     38   FX_SAXMODE_TargetData,
     39   FX_SAXMODE_MAX,
     40 };
     41 class CFX_SAXItem {
     42  public:
     43   CFX_SAXItem()
     44       : m_pNode(NULL),
     45         m_eNode(FX_SAXNODE_Unknown),
     46         m_dwID(0),
     47         m_bSkip(FALSE),
     48         m_pPrev(NULL),
     49         m_pNext(NULL) {}
     50   void* m_pNode;
     51   FX_SAXNODE m_eNode;
     52   FX_DWORD m_dwID;
     53   FX_BOOL m_bSkip;
     54   CFX_SAXItem* m_pPrev;
     55   CFX_SAXItem* m_pNext;
     56 };
     57 class CFX_SAXCommentContext {
     58  public:
     59   CFX_SAXCommentContext() : m_iHeaderCount(0), m_iTailCount(0) {}
     60   int32_t m_iHeaderCount;
     61   int32_t m_iTailCount;
     62 };
     63 class CFX_SAXReader : public IFX_SAXReader {
     64  public:
     65   CFX_SAXReader();
     66   ~CFX_SAXReader();
     67   virtual void Release() { delete this; }
     68   virtual int32_t StartParse(IFX_FileRead* pFile,
     69                              FX_DWORD dwStart = 0,
     70                              FX_DWORD dwLen = -1,
     71                              FX_DWORD dwParseMode = 0);
     72   virtual int32_t ContinueParse(IFX_Pause* pPause = NULL);
     73   virtual void SkipCurrentNode();
     74   virtual void SetHandler(IFX_SAXReaderHandler* pHandler);
     75   void AppendData(uint8_t ch);
     76   void AppendName(uint8_t ch);
     77   void ParseText();
     78   void ParseNodeStart();
     79   void ParseInstruction();
     80   void ParseDeclOrComment();
     81   void ParseDeclNode();
     82   void ParseComment();
     83   void ParseCommentContent();
     84   void ParseTagName();
     85   void ParseTagAttributeName();
     86   void ParseTagAttributeEqual();
     87   void ParseTagAttributeValue();
     88   void ParseMaybeClose();
     89   void ParseTagClose();
     90   void ParseTagEnd();
     91   void ParseTargetData();
     92 
     93  protected:
     94   CFX_SAXFile m_File;
     95   IFX_SAXReaderHandler* m_pHandler;
     96   int32_t m_iState;
     97   CFX_SAXItem* m_pRoot;
     98   CFX_SAXItem* m_pCurItem;
     99   FX_DWORD m_dwItemID;
    100   FX_SAXMODE m_eMode;
    101   FX_SAXMODE m_ePrevMode;
    102   FX_BOOL m_bCharData;
    103   uint8_t m_CurByte;
    104   FX_DWORD m_dwDataOffset;
    105   CFX_ByteArray m_SkipStack;
    106   uint8_t m_SkipChar;
    107   FX_DWORD m_dwNodePos;
    108   uint8_t* m_pszData;
    109   int32_t m_iDataSize;
    110   int32_t m_iDataLength;
    111   int32_t m_iEntityStart;
    112   int32_t m_iDataPos;
    113   uint8_t* m_pszName;
    114   int32_t m_iNameSize;
    115   int32_t m_iNameLength;
    116   FX_DWORD m_dwParseMode;
    117   CFX_SAXCommentContext* m_pCommentContext;
    118   void Reset();
    119   void Push();
    120   void Pop();
    121   FX_BOOL SkipSpace(uint8_t ch);
    122   void SkipNode();
    123   void NotifyData();
    124   void NotifyEnter();
    125   void NotifyAttribute();
    126   void NotifyBreak();
    127   void NotifyClose();
    128   void NotifyEnd();
    129   void NotifyTargetData();
    130   void ReallocDataBuffer();
    131   void ReallocNameBuffer();
    132   void ParseChar(uint8_t ch);
    133 };
    134 #endif
    135