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 _XFA_PARSER_IMP 8 #define _XFA_PARSER_IMP 9 #define _XFA_VERIFY_Checksum_ 10 class CXFA_XMLParser; 11 class CXFA_SimpleParser : public IXFA_Parser { 12 public: 13 CXFA_SimpleParser(IXFA_ObjFactory* pFactory, FX_BOOL bDocumentParser = FALSE); 14 ~CXFA_SimpleParser(); Release()15 virtual void Release() { delete this; } 16 17 virtual int32_t StartParse(IFX_FileRead* pStream, 18 XFA_XDPPACKET ePacketID = XFA_XDPPACKET_XDP); 19 virtual int32_t DoParse(IFX_Pause* pPause = NULL); 20 virtual int32_t ParseXMLData(const CFX_WideString& wsXML, 21 IFDE_XMLNode*& pXMLNode, 22 IFX_Pause* pPause = NULL); 23 virtual void ConstructXFANode(CXFA_Node* pXFANode, IFDE_XMLNode* pXMLNode); GetFactory()24 virtual IXFA_ObjFactory* GetFactory() const { return m_pFactory; } GetRootNode()25 virtual CXFA_Node* GetRootNode() const { return m_pRootNode; } GetXMLDoc()26 virtual IFDE_XMLDoc* GetXMLDoc() const { return m_pXMLDoc; } 27 virtual void CloseParser(); 28 29 protected: 30 CXFA_Node* ParseAsXDPPacket(IFDE_XMLNode* pXMLDocumentNode, 31 XFA_XDPPACKET ePacketID); 32 CXFA_Node* ParseAsXDPPacket_XDP(IFDE_XMLNode* pXMLDocumentNode, 33 XFA_XDPPACKET ePacketID); 34 CXFA_Node* ParseAsXDPPacket_Config(IFDE_XMLNode* pXMLDocumentNode, 35 XFA_XDPPACKET ePacketID); 36 CXFA_Node* ParseAsXDPPacket_TemplateForm(IFDE_XMLNode* pXMLDocumentNode, 37 XFA_XDPPACKET ePacketID); 38 CXFA_Node* ParseAsXDPPacket_Data(IFDE_XMLNode* pXMLDocumentNode, 39 XFA_XDPPACKET ePacketID); 40 CXFA_Node* ParseAsXDPPacket_LocaleConnectionSourceSet( 41 IFDE_XMLNode* pXMLDocumentNode, 42 XFA_XDPPACKET ePacketID); 43 CXFA_Node* ParseAsXDPPacket_Xdc(IFDE_XMLNode* pXMLDocumentNode, 44 XFA_XDPPACKET ePacketID); 45 CXFA_Node* ParseAsXDPPacket_User(IFDE_XMLNode* pXMLDocumentNode, 46 XFA_XDPPACKET ePacketID); 47 CXFA_Node* NormalLoader(CXFA_Node* pXFANode, 48 IFDE_XMLNode* pXMLDoc, 49 XFA_XDPPACKET ePacketID, 50 FX_BOOL bUseAttribute = TRUE); 51 CXFA_Node* DataLoader(CXFA_Node* pXFANode, 52 IFDE_XMLNode* pXMLDoc, 53 FX_BOOL bDoTransform); 54 CXFA_Node* UserPacketLoader(CXFA_Node* pXFANode, IFDE_XMLNode* pXMLDoc); 55 void ParseContentNode(CXFA_Node* pXFANode, 56 IFDE_XMLNode* pXMLNode, 57 XFA_XDPPACKET ePacketID); 58 void ParseDataValue(CXFA_Node* pXFANode, 59 IFDE_XMLNode* pXMLNode, 60 XFA_XDPPACKET ePacketID); 61 void ParseDataGroup(CXFA_Node* pXFANode, 62 IFDE_XMLNode* pXMLNode, 63 XFA_XDPPACKET ePacketID); 64 void ParseInstruction(CXFA_Node* pXFANode, 65 IFDE_XMLInstruction* pXMLInstruction, 66 XFA_XDPPACKET ePacketID); 67 void SetFactory(IXFA_ObjFactory* pFactory); 68 69 CXFA_XMLParser* m_pXMLParser; 70 IFDE_XMLDoc* m_pXMLDoc; 71 IFX_Stream* m_pStream; 72 IFX_FileRead* m_pFileRead; 73 IXFA_ObjFactory* m_pFactory; 74 CXFA_Node* m_pRootNode; 75 XFA_XDPPACKET m_ePacketID; 76 FX_BOOL m_bDocumentParser; 77 friend class CXFA_DocumentParser; 78 }; 79 class CXFA_DocumentParser : public IXFA_DocParser { 80 public: 81 CXFA_DocumentParser(IXFA_Notify* pNotify); 82 ~CXFA_DocumentParser(); Release()83 virtual void Release() { delete this; } 84 virtual int32_t StartParse(IFX_FileRead* pStream, 85 XFA_XDPPACKET ePacketID = XFA_XDPPACKET_XDP); 86 virtual int32_t DoParse(IFX_Pause* pPause = NULL); 87 virtual int32_t ParseXMLData(const CFX_WideString& wsXML, 88 IFDE_XMLNode*& pXMLNode, 89 IFX_Pause* pPause = NULL); 90 virtual void ConstructXFANode(CXFA_Node* pXFANode, IFDE_XMLNode* pXMLNode); GetFactory()91 virtual IXFA_ObjFactory* GetFactory() const { 92 return m_nodeParser.GetFactory(); 93 } GetRootNode()94 virtual CXFA_Node* GetRootNode() const { return m_nodeParser.GetRootNode(); } GetXMLDoc()95 virtual IFDE_XMLDoc* GetXMLDoc() const { return m_nodeParser.GetXMLDoc(); } GetNotify()96 virtual IXFA_Notify* GetNotify() const { return m_pNotify; } GetDocument()97 virtual CXFA_Document* GetDocument() const { return m_pDocument; } 98 virtual void CloseParser(); 99 100 protected: 101 CXFA_SimpleParser m_nodeParser; 102 IXFA_Notify* m_pNotify; 103 CXFA_Document* m_pDocument; 104 }; 105 typedef CFX_StackTemplate<IFDE_XMLNode*> CXFA_XMLNodeStack; 106 class CXFA_XMLParser : public IFDE_XMLParser { 107 public: 108 CXFA_XMLParser(IFDE_XMLNode* pRoot, IFX_Stream* pStream); 109 ~CXFA_XMLParser(); 110 Release()111 virtual void Release() { delete this; } 112 virtual int32_t DoParser(IFX_Pause* pPause); 113 114 #ifdef _XFA_VERIFY_Checksum_ 115 FX_FILESIZE m_nStart[2]; 116 size_t m_nSize[2]; 117 FX_FILESIZE m_nElementStart; 118 FX_WORD m_dwCheckStatus; 119 FX_WORD m_dwCurrentCheckStatus; 120 #endif 121 122 protected: 123 IFDE_XMLNode* m_pRoot; 124 IFX_Stream* m_pStream; 125 IFDE_XMLSyntaxParser* m_pParser; 126 127 IFDE_XMLNode* m_pParent; 128 IFDE_XMLNode* m_pChild; 129 CXFA_XMLNodeStack m_NodeStack; 130 CFX_WideString m_ws1; 131 CFX_WideString m_ws2; 132 FX_DWORD m_dwStatus; 133 }; 134 #endif 135