• 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_DOCUMENT_PARSER_H_
8 #define XFA_FXFA_PARSER_CXFA_DOCUMENT_PARSER_H_
9 
10 #include <memory>
11 #include <utility>
12 
13 #include "core/fxcrt/fx_string.h"
14 #include "core/fxcrt/retain_ptr.h"
15 #include "xfa/fxfa/fxfa_basic.h"
16 
17 class CFX_XMLDocument;
18 class CFX_XMLNode;
19 class CXFA_Document;
20 class CXFA_Node;
21 class CFX_XMLInstruction;
22 class IFX_SeekableReadStream;
23 
24 class CXFA_DocumentParser {
25  public:
26   explicit CXFA_DocumentParser(CXFA_Document* pFactory);
27   ~CXFA_DocumentParser();
28 
29   bool Parse(const RetainPtr<IFX_SeekableReadStream>& pStream,
30              XFA_PacketType ePacketID);
31 
32   CFX_XMLNode* ParseXMLData(const ByteString& wsXML);
33   void ConstructXFANode(CXFA_Node* pXFANode, CFX_XMLNode* pXMLNode);
34 
GetXMLDoc()35   std::unique_ptr<CFX_XMLDocument> GetXMLDoc() { return std::move(xml_doc_); }
36   CXFA_Node* GetRootNode() const;
37 
38  private:
39   std::unique_ptr<CFX_XMLDocument> LoadXML(
40       const RetainPtr<IFX_SeekableReadStream>& pStream);
41 
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   void ParseContentNode(CXFA_Node* pXFANode,
63                         CFX_XMLNode* pXMLNode,
64                         XFA_PacketType ePacketID);
65   void ParseDataValue(CXFA_Node* pXFANode,
66                       CFX_XMLNode* pXMLNode,
67                       XFA_PacketType ePacketID);
68   void ParseDataGroup(CXFA_Node* pXFANode,
69                       CFX_XMLNode* pXMLNode,
70                       XFA_PacketType ePacketID);
71   void ParseInstruction(CXFA_Node* pXFANode,
72                         CFX_XMLInstruction* pXMLInstruction,
73                         XFA_PacketType ePacketID);
74 
75   UnownedPtr<CXFA_Document> m_pFactory;
76   std::unique_ptr<CFX_XMLDocument> xml_doc_;
77   // TODO(dsinclair): Figure out who owns this.
78   CXFA_Node* m_pRootNode = nullptr;
79   size_t m_ExecuteRecursionDepth = 0;
80 };
81 
82 #endif  // XFA_FXFA_PARSER_CXFA_DOCUMENT_PARSER_H_
83