• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_FXFA_PARSER_CXFA_SIMPLE_PARSER_H_
8 #define XFA_FXFA_PARSER_CXFA_SIMPLE_PARSER_H_
9 
10 #include <memory>
11 
12 #include "xfa/fxfa/fxfa_basic.h"
13 
14 class CXFA_Document;
15 class CXFA_Node;
16 class CFX_XMLDoc;
17 class CFX_XMLInstruction;
18 class CFX_XMLNode;
19 class CFX_XMLParser;
20 class IFX_SeekableStream;
21 class CFX_SeekableStreamProxy;
22 
23 class CXFA_SimpleParser {
24  public:
25   CXFA_SimpleParser();
26   explicit CXFA_SimpleParser(CXFA_Document* pFactory);
27   ~CXFA_SimpleParser();
28 
29   int32_t StartParse(const RetainPtr<IFX_SeekableStream>& pStream,
30                      XFA_PacketType ePacketID);
31   int32_t DoParse();
32   CFX_XMLNode* ParseXMLData(const ByteString& wsXML);
33   void ConstructXFANode(CXFA_Node* pXFANode, CFX_XMLNode* pXMLNode);
34   CXFA_Node* GetRootNode() const;
35   CFX_XMLDoc* GetXMLDoc() const;
36   void CloseParser();
37 
38   // Called later for the ctor with no parameters.
39   void SetFactory(CXFA_Document* pFactory);
40 
41  private:
42   CXFA_Node* ParseAsXDPPacket(CFX_XMLNode* pXMLDocumentNode,
43                               XFA_PacketType ePacketID);
44   CXFA_Node* ParseAsXDPPacket_XDP(CFX_XMLNode* pXMLDocumentNode);
45   CXFA_Node* ParseAsXDPPacket_Config(CFX_XMLNode* pXMLDocumentNode);
46   CXFA_Node* ParseAsXDPPacket_Template(CFX_XMLNode* pXMLDocumentNode);
47   CXFA_Node* ParseAsXDPPacket_Form(CFX_XMLNode* pXMLDocumentNode);
48   CXFA_Node* ParseAsXDPPacket_Data(CFX_XMLNode* pXMLDocumentNode);
49   CXFA_Node* ParseAsXDPPacket_LocaleConnectionSourceSet(
50       CFX_XMLNode* pXMLDocumentNode,
51       XFA_PacketType packet_type,
52       XFA_Element element);
53   CXFA_Node* ParseAsXDPPacket_Xdc(CFX_XMLNode* pXMLDocumentNode);
54   CXFA_Node* ParseAsXDPPacket_User(CFX_XMLNode* pXMLDocumentNode);
55   CXFA_Node* NormalLoader(CXFA_Node* pXFANode,
56                           CFX_XMLNode* pXMLDoc,
57                           XFA_PacketType ePacketID,
58                           bool bUseAttribute);
59   CXFA_Node* DataLoader(CXFA_Node* pXFANode,
60                         CFX_XMLNode* pXMLDoc,
61                         bool bDoTransform);
62   CXFA_Node* UserPacketLoader(CXFA_Node* pXFANode, CFX_XMLNode* pXMLDoc);
63   void ParseContentNode(CXFA_Node* pXFANode,
64                         CFX_XMLNode* pXMLNode,
65                         XFA_PacketType ePacketID);
66   void ParseDataValue(CXFA_Node* pXFANode,
67                       CFX_XMLNode* pXMLNode,
68                       XFA_PacketType ePacketID);
69   void ParseDataGroup(CXFA_Node* pXFANode,
70                       CFX_XMLNode* pXMLNode,
71                       XFA_PacketType ePacketID);
72   void ParseInstruction(CXFA_Node* pXFANode,
73                         CFX_XMLInstruction* pXMLInstruction,
74                         XFA_PacketType ePacketID);
75 
76   std::unique_ptr<CFX_XMLDoc> m_pXMLDoc;
77   UnownedPtr<CFX_XMLParser> m_pXMLParser;  // Owned by |m_pXMLDoc|
78   RetainPtr<CFX_SeekableStreamProxy> m_pStream;
79   RetainPtr<IFX_SeekableStream> m_pFileRead;
80   UnownedPtr<CXFA_Document> m_pFactory;
81   // TODO(dsinclair): Figure out who owns this.
82   CXFA_Node* m_pRootNode = nullptr;
83   XFA_PacketType m_ePacketID = XFA_PacketType::User;
84   bool m_bParseStarted = false;
85   const bool m_bDocumentParser;
86 };
87 
88 #endif  // XFA_FXFA_PARSER_CXFA_SIMPLE_PARSER_H_
89