From 34f86b0c7816289d2a0b402d1909572f4e95613b Mon Sep 17 00:00:00 2001 From: dsinclair Date: Mon, 11 Jul 2016 08:42:33 -0700 Subject: Break xfa_parser_imp apart This CL splits the three parsers into individual files to make working with the code easier. Review-Url: https://codereview.chromium.org/2129963002 --- BUILD.gn | 10 +- pdfium.gyp | 2 +- testing/libfuzzer/pdf_xml_fuzzer.cc | 3 +- xfa.gyp | 8 +- xfa/fxfa/app/xfa_ffdoc.cpp | 7 +- xfa/fxfa/app/xfa_ffwidgethandler.cpp | 1 - xfa/fxfa/fm2js/xfa_fm2jscontext.cpp | 1 - xfa/fxfa/include/xfa_ffdoc.h | 1 + xfa/fxfa/parser/cxfa_document_parser.cpp | 54 + xfa/fxfa/parser/cxfa_document_parser.h | 40 + xfa/fxfa/parser/cxfa_simple_parser.cpp | 1318 +++++++++++++++++ xfa/fxfa/parser/cxfa_simple_parser.h | 86 ++ .../parser/cxfa_simple_parser_embeddertest.cpp | 15 + xfa/fxfa/parser/cxfa_xml_parser.cpp | 176 +++ xfa/fxfa/parser/cxfa_xml_parser.h | 43 + xfa/fxfa/parser/xfa_document.h | 2 +- xfa/fxfa/parser/xfa_document_datamerger_imp.cpp | 1 - xfa/fxfa/parser/xfa_document_imp.cpp | 2 +- xfa/fxfa/parser/xfa_document_serialize.cpp | 2 +- xfa/fxfa/parser/xfa_layout_appadapter.cpp | 1 - xfa/fxfa/parser/xfa_layout_itemlayout.cpp | 1 - xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp | 1 - xfa/fxfa/parser/xfa_object_imp.cpp | 2 +- xfa/fxfa/parser/xfa_parser_imp.cpp | 1542 -------------------- xfa/fxfa/parser/xfa_parser_imp.h | 132 -- xfa/fxfa/parser/xfa_parser_imp_embeddertest.cpp | 15 - xfa/fxfa/parser/xfa_script_eventpseudomodel.cpp | 1 - xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp | 1 - xfa/fxfa/parser/xfa_script_layoutpseudomodel.cpp | 1 - .../parser/xfa_script_signaturepseudomodel.cpp | 1 - 30 files changed, 1756 insertions(+), 1714 deletions(-) create mode 100644 xfa/fxfa/parser/cxfa_document_parser.cpp create mode 100644 xfa/fxfa/parser/cxfa_document_parser.h create mode 100644 xfa/fxfa/parser/cxfa_simple_parser.cpp create mode 100644 xfa/fxfa/parser/cxfa_simple_parser.h create mode 100644 xfa/fxfa/parser/cxfa_simple_parser_embeddertest.cpp create mode 100644 xfa/fxfa/parser/cxfa_xml_parser.cpp create mode 100644 xfa/fxfa/parser/cxfa_xml_parser.h delete mode 100644 xfa/fxfa/parser/xfa_parser_imp.cpp delete mode 100644 xfa/fxfa/parser/xfa_parser_imp.h delete mode 100644 xfa/fxfa/parser/xfa_parser_imp_embeddertest.cpp diff --git a/BUILD.gn b/BUILD.gn index f053ad796a..303829ec87 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1324,6 +1324,8 @@ if (pdf_enable_xfa) { "xfa/fxfa/parser/cxfa_corner.h", "xfa/fxfa/parser/cxfa_data.cpp", "xfa/fxfa/parser/cxfa_data.h", + "xfa/fxfa/parser/cxfa_document_parser.cpp", + "xfa/fxfa/parser/cxfa_document_parser.h", "xfa/fxfa/parser/cxfa_edge.h", "xfa/fxfa/parser/cxfa_event.cpp", "xfa/fxfa/parser/cxfa_event.h", @@ -1346,6 +1348,8 @@ if (pdf_enable_xfa) { "xfa/fxfa/parser/cxfa_rectangle.h", "xfa/fxfa/parser/cxfa_script.cpp", "xfa/fxfa/parser/cxfa_script.h", + "xfa/fxfa/parser/cxfa_simple_parser.cpp", + "xfa/fxfa/parser/cxfa_simple_parser.h", "xfa/fxfa/parser/cxfa_stroke.cpp", "xfa/fxfa/parser/cxfa_stroke.h", "xfa/fxfa/parser/cxfa_submit.cpp", @@ -1362,6 +1366,8 @@ if (pdf_enable_xfa) { "xfa/fxfa/parser/cxfa_valuearray.h", "xfa/fxfa/parser/cxfa_widgetdata.cpp", "xfa/fxfa/parser/cxfa_widgetdata.h", + "xfa/fxfa/parser/cxfa_xml_parser.cpp", + "xfa/fxfa/parser/cxfa_xml_parser.h", "xfa/fxfa/parser/xfa_basic_data.cpp", "xfa/fxfa/parser/xfa_basic_data.h", "xfa/fxfa/parser/xfa_basic_data_attributes.cpp", @@ -1395,8 +1401,6 @@ if (pdf_enable_xfa) { "xfa/fxfa/parser/xfa_localevalue.h", "xfa/fxfa/parser/xfa_object.h", "xfa/fxfa/parser/xfa_object_imp.cpp", - "xfa/fxfa/parser/xfa_parser_imp.cpp", - "xfa/fxfa/parser/xfa_parser_imp.h", "xfa/fxfa/parser/xfa_script.h", "xfa/fxfa/parser/xfa_script_datawindow.cpp", "xfa/fxfa/parser/xfa_script_datawindow.h", @@ -1535,7 +1539,7 @@ test("pdfium_embeddertests") { "testing/embedder_test.h", "testing/embedder_test_mock_delegate.h", "testing/embedder_test_timer_handling_delegate.h", - "xfa/fxfa/parser/xfa_parser_imp_embeddertest.cpp", + "xfa/fxfa/parser/cxfa_simple_parser_embeddertest.cpp", ] deps = [ ":pdfium", diff --git a/pdfium.gyp b/pdfium.gyp index e54223cc2f..3824c756a9 100644 --- a/pdfium.gyp +++ b/pdfium.gyp @@ -961,7 +961,7 @@ 'conditions': [ ['pdf_enable_xfa==1', { 'sources': [ - 'xfa/fxfa/parser/xfa_parser_imp_embeddertest.cpp', + 'xfa/fxfa/parser/cxfa_simple_parser_embeddertest.cpp', ], }], ['pdf_enable_v8==1', { diff --git a/testing/libfuzzer/pdf_xml_fuzzer.cc b/testing/libfuzzer/pdf_xml_fuzzer.cc index c93a5c293a..0b80b1a04c 100644 --- a/testing/libfuzzer/pdf_xml_fuzzer.cc +++ b/testing/libfuzzer/pdf_xml_fuzzer.cc @@ -9,7 +9,8 @@ #include "core/fxcrt/include/fx_basic.h" #include "core/fxcrt/include/fx_system.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" +#include "xfa/fde/xml/fde_xml_imp.h" +#include "xfa/fxfa/parser/cxfa_xml_parser.h" #include "xfa/fxfa/parser/xfa_utils.h" namespace { diff --git a/xfa.gyp b/xfa.gyp index f294f39d08..c223ba61d7 100644 --- a/xfa.gyp +++ b/xfa.gyp @@ -474,6 +474,8 @@ "xfa/fxfa/parser/cxfa_corner.h", "xfa/fxfa/parser/cxfa_data.cpp", "xfa/fxfa/parser/cxfa_data.h", + "xfa/fxfa/parser/cxfa_document_parser.cpp", + "xfa/fxfa/parser/cxfa_document_parser.h", "xfa/fxfa/parser/cxfa_edge.h", "xfa/fxfa/parser/cxfa_event.cpp", "xfa/fxfa/parser/cxfa_event.h", @@ -496,6 +498,8 @@ "xfa/fxfa/parser/cxfa_rectangle.h", "xfa/fxfa/parser/cxfa_script.cpp", "xfa/fxfa/parser/cxfa_script.h", + "xfa/fxfa/parser/cxfa_simple_parser.cpp", + "xfa/fxfa/parser/cxfa_simple_parser.h", "xfa/fxfa/parser/cxfa_stroke.cpp", "xfa/fxfa/parser/cxfa_stroke.h", "xfa/fxfa/parser/cxfa_submit.cpp", @@ -512,6 +516,8 @@ "xfa/fxfa/parser/cxfa_valuearray.h", "xfa/fxfa/parser/cxfa_widgetdata.cpp", "xfa/fxfa/parser/cxfa_widgetdata.h", + "xfa/fxfa/parser/cxfa_xml_parser.cpp", + "xfa/fxfa/parser/cxfa_xml_parser.h", "xfa/fxfa/parser/xfa_basic_data.cpp", "xfa/fxfa/parser/xfa_basic_data_attributes.cpp", "xfa/fxfa/parser/xfa_basic_data_element_attributes.cpp", @@ -545,8 +551,6 @@ "xfa/fxfa/parser/xfa_localevalue.h", "xfa/fxfa/parser/xfa_object.h", "xfa/fxfa/parser/xfa_object_imp.cpp", - "xfa/fxfa/parser/xfa_parser_imp.cpp", - "xfa/fxfa/parser/xfa_parser_imp.h", "xfa/fxfa/parser/xfa_script.h", "xfa/fxfa/parser/xfa_script_datawindow.cpp", "xfa/fxfa/parser/xfa_script_datawindow.h", diff --git a/xfa/fxfa/app/xfa_ffdoc.cpp b/xfa/fxfa/app/xfa_ffdoc.cpp index 6320cb9b2a..294839152e 100644 --- a/xfa/fxfa/app/xfa_ffdoc.cpp +++ b/xfa/fxfa/app/xfa_ffdoc.cpp @@ -23,8 +23,6 @@ #include "xfa/fxfa/include/xfa_fontmgr.h" #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_document_serialize.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" namespace { @@ -168,7 +166,7 @@ uint32_t CXFA_FFDoc::GetDocType() { int32_t CXFA_FFDoc::StartLoad() { m_pNotify.reset(new CXFA_FFNotify(this)); m_pDocumentParser.reset(new CXFA_DocumentParser(m_pNotify.get())); - int32_t iStatus = m_pDocumentParser->StartParse(m_pStream); + int32_t iStatus = m_pDocumentParser->StartParse(m_pStream, XFA_XDPPACKET_XDP); return iStatus; } @@ -275,7 +273,8 @@ int32_t CXFA_FFDoc::DoLoad(IFX_Pause* pPause) { return XFA_PARSESTATUS_SyntaxErr; CXFA_Node* pRootNode = nullptr; - if (pParser->StartParse(m_pStream) == XFA_PARSESTATUS_Ready && + if (pParser->StartParse(m_pStream, XFA_XDPPACKET_XDP) == + XFA_PARSESTATUS_Ready && pParser->DoParse(nullptr) == XFA_PARSESTATUS_Done) { pRootNode = pParser->GetRootNode(); } diff --git a/xfa/fxfa/app/xfa_ffwidgethandler.cpp b/xfa/fxfa/app/xfa_ffwidgethandler.cpp index b60b7fc0a2..8e2b9dfb83 100644 --- a/xfa/fxfa/app/xfa_ffwidgethandler.cpp +++ b/xfa/fxfa/app/xfa_ffwidgethandler.cpp @@ -15,7 +15,6 @@ #include "xfa/fxfa/include/xfa_ffdocview.h" #include "xfa/fxfa/include/xfa_ffwidget.h" #include "xfa/fxfa/parser/xfa_document_layout_imp.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" CXFA_FFWidgetHandler::CXFA_FFWidgetHandler(CXFA_FFDocView* pDocView) : m_pDocView(pDocView) {} diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp index 5813c5204a..6826094b1d 100644 --- a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp +++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp @@ -17,7 +17,6 @@ #include "xfa/fxfa/fm2js/xfa_program.h" #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_localevalue.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" #include "xfa/fxfa/parser/xfa_script_imp.h" namespace { diff --git a/xfa/fxfa/include/xfa_ffdoc.h b/xfa/fxfa/include/xfa_ffdoc.h index b8795bc211..0f32c4300c 100644 --- a/xfa/fxfa/include/xfa_ffdoc.h +++ b/xfa/fxfa/include/xfa_ffdoc.h @@ -11,6 +11,7 @@ #include #include "xfa/fxfa/include/fxfa.h" +#include "xfa/fxfa/parser/cxfa_document_parser.h" #include "xfa/fxfa/parser/xfa_document.h" class CXFA_ChecksumContext; diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp new file mode 100644 index 0000000000..565916ba93 --- /dev/null +++ b/xfa/fxfa/parser/cxfa_document_parser.cpp @@ -0,0 +1,54 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/parser/cxfa_document_parser.h" + +#include "xfa/fxfa/include/fxfa.h" +#include "xfa/fxfa/parser/xfa_document.h" + +CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify) + : m_nodeParser(nullptr, TRUE), m_pNotify(pNotify) {} + +CXFA_DocumentParser::~CXFA_DocumentParser() { + CloseParser(); +} + +int32_t CXFA_DocumentParser::StartParse(IFX_FileRead* pStream, + XFA_XDPPACKET ePacketID) { + CloseParser(); + int32_t nRetStatus = m_nodeParser.StartParse(pStream, ePacketID); + if (nRetStatus == XFA_PARSESTATUS_Ready) { + m_pDocument.reset(new CXFA_Document(this)); + m_nodeParser.SetFactory(m_pDocument.get()); + } + return nRetStatus; +} + +int32_t CXFA_DocumentParser::DoParse(IFX_Pause* pPause) { + int32_t nRetStatus = m_nodeParser.DoParse(pPause); + if (nRetStatus >= XFA_PARSESTATUS_Done) { + ASSERT(m_pDocument); + m_pDocument->SetRoot(m_nodeParser.GetRootNode()); + } + return nRetStatus; +} + +CFDE_XMLDoc* CXFA_DocumentParser::GetXMLDoc() const { + return m_nodeParser.GetXMLDoc(); +} + +CXFA_FFNotify* CXFA_DocumentParser::GetNotify() const { + return m_pNotify; +} + +CXFA_Document* CXFA_DocumentParser::GetDocument() const { + return m_pDocument.get(); +} + +void CXFA_DocumentParser::CloseParser() { + m_pDocument.reset(); + m_nodeParser.CloseParser(); +} diff --git a/xfa/fxfa/parser/cxfa_document_parser.h b/xfa/fxfa/parser/cxfa_document_parser.h new file mode 100644 index 0000000000..42275df1f1 --- /dev/null +++ b/xfa/fxfa/parser/cxfa_document_parser.h @@ -0,0 +1,40 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_DOCUMENT_PARSER_H_ +#define XFA_FXFA_PARSER_CXFA_DOCUMENT_PARSER_H_ + +#include + +#include "xfa/fxfa/parser/cxfa_simple_parser.h" + +class CFDE_XMLDoc; +class CXFA_Document; +class CXFA_FFNotify; +class CXFA_Notify; +class IFX_FileRead; +class IFX_Pause; + +class CXFA_DocumentParser { + public: + explicit CXFA_DocumentParser(CXFA_FFNotify* pNotify); + ~CXFA_DocumentParser(); + + int32_t StartParse(IFX_FileRead* pStream, XFA_XDPPACKET ePacketID); + int32_t DoParse(IFX_Pause* pPause); + + CFDE_XMLDoc* GetXMLDoc() const; + CXFA_FFNotify* GetNotify() const; + CXFA_Document* GetDocument() const; + void CloseParser(); + + protected: + CXFA_SimpleParser m_nodeParser; + CXFA_FFNotify* m_pNotify; + std::unique_ptr m_pDocument; +}; + +#endif // XFA_FXFA_PARSER_CXFA_DOCUMENT_PARSER_H_ diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp new file mode 100644 index 0000000000..c9edf2daff --- /dev/null +++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp @@ -0,0 +1,1318 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/parser/cxfa_simple_parser.h" + +#include "xfa/fgas/crt/fgas_codepage.h" +#include "xfa/fxfa/include/fxfa.h" +#include "xfa/fxfa/include/xfa_checksum.h" +#include "xfa/fxfa/parser/cxfa_xml_parser.h" +#include "xfa/fxfa/parser/xfa_document.h" + +CXFA_SimpleParser::CXFA_SimpleParser(CXFA_Document* pFactory, + bool bDocumentParser) + : m_pXMLParser(nullptr), + m_pXMLDoc(nullptr), + m_pStream(nullptr), + m_pFileRead(nullptr), + m_pFactory(pFactory), + m_pRootNode(nullptr), + m_ePacketID(XFA_XDPPACKET_UNKNOWN), + m_bDocumentParser(bDocumentParser) {} + +CXFA_SimpleParser::~CXFA_SimpleParser() { + CloseParser(); +} + +void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { + m_pFactory = pFactory; +} + +static CFDE_XMLNode* XFA_FDEExtension_GetDocumentNode( + CFDE_XMLDoc* pXMLDoc, + FX_BOOL bVerifyWellFormness = FALSE) { + if (!pXMLDoc) { + return nullptr; + } + CFDE_XMLNode* pXMLFakeRoot = pXMLDoc->GetRoot(); + for (CFDE_XMLNode* pXMLNode = + pXMLFakeRoot->GetNodeItem(CFDE_XMLNode::FirstChild); + pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { + if (pXMLNode->GetType() == FDE_XMLNODE_Element) { + if (bVerifyWellFormness) { + for (CFDE_XMLNode* pNextNode = + pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling); + pNextNode; + pNextNode = pNextNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { + if (pNextNode->GetType() == FDE_XMLNODE_Element) { + return FALSE; + } + } + } + return pXMLNode; + } + } + return nullptr; +} +int32_t CXFA_SimpleParser::StartParse(IFX_FileRead* pStream, + XFA_XDPPACKET ePacketID) { + CloseParser(); + m_pFileRead = pStream; + m_pStream = IFX_Stream::CreateStream( + pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text); + if (!m_pStream) { + return XFA_PARSESTATUS_StreamErr; + } + uint16_t wCodePage = m_pStream->GetCodePage(); + if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && + wCodePage != FX_CODEPAGE_UTF8) { + m_pStream->SetCodePage(FX_CODEPAGE_UTF8); + } + m_pXMLDoc = new CFDE_XMLDoc; + m_pXMLParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream); + if (!m_pXMLDoc->LoadXML(m_pXMLParser)) { + return XFA_PARSESTATUS_StatusErr; + } + m_ePacketID = ePacketID; + return XFA_PARSESTATUS_Ready; +} +int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) { + if (!m_pXMLDoc || m_ePacketID == XFA_XDPPACKET_UNKNOWN) { + return XFA_PARSESTATUS_StatusErr; + } + int32_t iRet = m_pXMLDoc->DoLoad(pPause); + if (iRet < 0) { + return XFA_PARSESTATUS_SyntaxErr; + } + if (iRet < 100) { + return iRet / 2; + } + m_pRootNode = ParseAsXDPPacket(XFA_FDEExtension_GetDocumentNode(m_pXMLDoc), + m_ePacketID); + m_pXMLDoc->CloseXML(); + if (m_pStream) { + m_pStream->Release(); + m_pStream = nullptr; + } + if (!m_pRootNode) { + return XFA_PARSESTATUS_StatusErr; + } + return XFA_PARSESTATUS_Done; +} +int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML, + CFDE_XMLNode*& pXMLNode, + IFX_Pause* pPause) { + CloseParser(); + pXMLNode = nullptr; + IFX_Stream* pStream = XFA_CreateWideTextRead(wsXML); + if (!pStream) { + return XFA_PARSESTATUS_StreamErr; + } + m_pStream = pStream; + m_pXMLDoc = new CFDE_XMLDoc; + CXFA_XMLParser* pParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream); + pParser->m_dwCheckStatus = 0x03; + if (!m_pXMLDoc->LoadXML(pParser)) { + return XFA_PARSESTATUS_StatusErr; + } + int32_t iRet = m_pXMLDoc->DoLoad(pPause); + if (iRet < 0 || iRet >= 100) { + m_pXMLDoc->CloseXML(); + } + if (iRet < 0) { + return XFA_PARSESTATUS_SyntaxErr; + } + if (iRet < 100) { + return iRet / 2; + } + if (m_pStream) { + m_pStream->Release(); + m_pStream = nullptr; + } + pXMLNode = XFA_FDEExtension_GetDocumentNode(m_pXMLDoc); + return XFA_PARSESTATUS_Done; +} + +void CXFA_SimpleParser::ConstructXFANode(CXFA_Node* pXFANode, + CFDE_XMLNode* pXMLNode) { + XFA_XDPPACKET ePacketID = (XFA_XDPPACKET)pXFANode->GetPacketID(); + if (ePacketID == XFA_XDPPACKET_Datasets) { + if (pXFANode->GetElementType() == XFA_Element::DataValue) { + for (CFDE_XMLNode* pXMLChild = + pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); + pXMLChild; + pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { + FDE_XMLNODETYPE eNodeType = pXMLChild->GetType(); + if (eNodeType == FDE_XMLNODE_Instruction) + continue; + + if (eNodeType == FDE_XMLNODE_Element) { + CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, + XFA_Element::DataValue); + if (!pXFAChild) + return; + + CFX_WideString wsNodeStr; + CFDE_XMLElement* child = static_cast(pXMLChild); + child->GetLocalTagName(wsNodeStr); + pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr); + CFX_WideString wsChildValue; + XFA_GetPlainTextFromRichText(child, wsChildValue); + if (!wsChildValue.IsEmpty()) + pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsChildValue); + + pXFANode->InsertChild(pXFAChild); + pXFAChild->SetXMLMappingNode(pXMLChild); + pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); + break; + } + } + m_pRootNode = pXFANode; + } else { + m_pRootNode = DataLoader(pXFANode, pXMLNode, TRUE); + } + } else if (pXFANode->IsContentNode()) { + ParseContentNode(pXFANode, pXMLNode, ePacketID); + m_pRootNode = pXFANode; + } else { + m_pRootNode = NormalLoader(pXFANode, pXMLNode, ePacketID); + } +} + +CXFA_Node* CXFA_SimpleParser::GetRootNode() const { + return m_pRootNode; +} + +CFDE_XMLDoc* CXFA_SimpleParser::GetXMLDoc() const { + return m_pXMLDoc; +} + +FX_BOOL XFA_FDEExtension_ResolveNamespaceQualifier( + CFDE_XMLElement* pNode, + const CFX_WideStringC& wsQualifier, + CFX_WideString& wsNamespaceURI) { + if (!pNode) { + return FALSE; + } + CFDE_XMLNode* pFakeRoot = pNode->GetNodeItem(CFDE_XMLNode::Root); + CFX_WideString wsNSAttribute; + FX_BOOL bRet = FALSE; + if (wsQualifier.IsEmpty()) { + wsNSAttribute = FX_WSTRC(L"xmlns"); + bRet = TRUE; + } else { + wsNSAttribute = FX_WSTRC(L"xmlns:") + wsQualifier; + } + for (; pNode != pFakeRoot; pNode = static_cast( + pNode->GetNodeItem(CFDE_XMLNode::Parent))) { + if (pNode->GetType() != FDE_XMLNODE_Element) { + continue; + } + if (pNode->HasAttribute(wsNSAttribute.c_str())) { + pNode->GetString(wsNSAttribute.c_str(), wsNamespaceURI); + return TRUE; + } + } + wsNamespaceURI.clear(); + return bRet; +} +static inline void XFA_FDEExtension_GetElementTagNamespaceURI( + CFDE_XMLElement* pElement, + CFX_WideString& wsNamespaceURI) { + CFX_WideString wsNodeStr; + pElement->GetNamespacePrefix(wsNodeStr); + if (!XFA_FDEExtension_ResolveNamespaceQualifier( + pElement, wsNodeStr.AsStringC(), wsNamespaceURI)) { + wsNamespaceURI.clear(); + } +} +static FX_BOOL XFA_FDEExtension_MatchNodeName( + CFDE_XMLNode* pNode, + const CFX_WideStringC& wsLocalTagName, + const CFX_WideStringC& wsNamespaceURIPrefix, + uint32_t eMatchFlags = XFA_XDPPACKET_FLAGS_NOMATCH) { + if (!pNode || pNode->GetType() != FDE_XMLNODE_Element) { + return FALSE; + } + CFDE_XMLElement* pElement = reinterpret_cast(pNode); + CFX_WideString wsNodeStr; + pElement->GetLocalTagName(wsNodeStr); + if (wsNodeStr != wsLocalTagName) { + return FALSE; + } + XFA_FDEExtension_GetElementTagNamespaceURI(pElement, wsNodeStr); + if (eMatchFlags & XFA_XDPPACKET_FLAGS_NOMATCH) { + return TRUE; + } + if (eMatchFlags & XFA_XDPPACKET_FLAGS_PREFIXMATCH) { + return wsNodeStr.Left(wsNamespaceURIPrefix.GetLength()) == + wsNamespaceURIPrefix; + } + return wsNodeStr == wsNamespaceURIPrefix; +} +static FX_BOOL XFA_FDEExtension_GetAttributeLocalName( + const CFX_WideStringC& wsAttributeName, + CFX_WideString& wsLocalAttrName) { + CFX_WideString wsAttrName(wsAttributeName); + FX_STRSIZE iFind = wsAttrName.Find(L':', 0); + if (iFind < 0) { + wsLocalAttrName = wsAttrName; + return FALSE; + } else { + wsLocalAttrName = wsAttrName.Right(wsAttrName.GetLength() - iFind - 1); + return TRUE; + } +} +static FX_BOOL XFA_FDEExtension_ResolveAttribute( + CFDE_XMLElement* pElement, + const CFX_WideStringC& wsAttributeName, + CFX_WideString& wsLocalAttrName, + CFX_WideString& wsNamespaceURI) { + CFX_WideString wsAttrName(wsAttributeName); + CFX_WideString wsNSPrefix; + if (XFA_FDEExtension_GetAttributeLocalName(wsAttributeName, + wsLocalAttrName)) { + wsNSPrefix = wsAttrName.Left(wsAttributeName.GetLength() - + wsLocalAttrName.GetLength() - 1); + } + if (wsLocalAttrName == FX_WSTRC(L"xmlns") || + wsNSPrefix == FX_WSTRC(L"xmlns") || wsNSPrefix == FX_WSTRC(L"xml")) { + return FALSE; + } + if (!XFA_FDEExtension_ResolveNamespaceQualifier( + pElement, wsNSPrefix.AsStringC(), wsNamespaceURI)) { + wsNamespaceURI.clear(); + return FALSE; + } + return TRUE; +} +static FX_BOOL XFA_FDEExtension_FindAttributeWithNS( + CFDE_XMLElement* pElement, + const CFX_WideStringC& wsLocalAttributeName, + const CFX_WideStringC& wsNamespaceURIPrefix, + CFX_WideString& wsValue, + FX_BOOL bMatchNSAsPrefix = FALSE) { + if (!pElement) { + return FALSE; + } + CFX_WideString wsAttrName; + CFX_WideString wsAttrValue; + CFX_WideString wsAttrNS; + for (int32_t iAttrCount = pElement->CountAttributes(), i = 0; i < iAttrCount; + i++) { + pElement->GetAttribute(i, wsAttrName, wsAttrValue); + FX_STRSIZE iFind = wsAttrName.Find(L':', 0); + CFX_WideString wsNSPrefix; + if (iFind < 0) { + if (wsLocalAttributeName != wsAttrName) { + continue; + } + } else { + if (wsLocalAttributeName != + wsAttrName.Right(wsAttrName.GetLength() - iFind - 1)) { + continue; + } + wsNSPrefix = wsAttrName.Left(iFind); + } + if (!XFA_FDEExtension_ResolveNamespaceQualifier( + pElement, wsNSPrefix.AsStringC(), wsAttrNS)) { + continue; + } + if (bMatchNSAsPrefix) { + if (wsAttrNS.Left(wsNamespaceURIPrefix.GetLength()) != + wsNamespaceURIPrefix) { + continue; + } + } else { + if (wsAttrNS != wsNamespaceURIPrefix) { + continue; + } + } + wsValue = wsAttrValue; + return TRUE; + } + return FALSE; +} +CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket(CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID) { + switch (ePacketID) { + case XFA_XDPPACKET_UNKNOWN: + return nullptr; + case XFA_XDPPACKET_XDP: + return ParseAsXDPPacket_XDP(pXMLDocumentNode, ePacketID); + case XFA_XDPPACKET_Config: + return ParseAsXDPPacket_Config(pXMLDocumentNode, ePacketID); + case XFA_XDPPACKET_Template: + case XFA_XDPPACKET_Form: + return ParseAsXDPPacket_TemplateForm(pXMLDocumentNode, ePacketID); + case XFA_XDPPACKET_Datasets: + return ParseAsXDPPacket_Data(pXMLDocumentNode, ePacketID); + case XFA_XDPPACKET_Xdc: + return ParseAsXDPPacket_Xdc(pXMLDocumentNode, ePacketID); + case XFA_XDPPACKET_LocaleSet: + case XFA_XDPPACKET_ConnectionSet: + case XFA_XDPPACKET_SourceSet: + return ParseAsXDPPacket_LocaleConnectionSourceSet(pXMLDocumentNode, + ePacketID); + default: + return ParseAsXDPPacket_User(pXMLDocumentNode, ePacketID); + } +} +CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP( + CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID) { + if (!XFA_FDEExtension_MatchNodeName( + pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_XDP)->pName, + XFA_GetPacketByIndex(XFA_PACKET_XDP)->pURI, + XFA_GetPacketByIndex(XFA_PACKET_XDP)->eFlags)) { + return nullptr; + } + CXFA_Node* pXFARootNode = + m_pFactory->CreateNode(XFA_XDPPACKET_XDP, XFA_Element::Xfa); + if (!pXFARootNode) { + return nullptr; + } + m_pRootNode = pXFARootNode; + pXFARootNode->SetCData(XFA_ATTRIBUTE_Name, L"xfa"); + { + CFDE_XMLElement* pElement = static_cast(pXMLDocumentNode); + int32_t iAttributeCount = pElement->CountAttributes(); + for (int32_t i = 0; i < iAttributeCount; i++) { + CFX_WideString wsAttriName, wsAttriValue; + pElement->GetAttribute(i, wsAttriName, wsAttriValue); + if (wsAttriName == FX_WSTRC(L"uuid")) { + pXFARootNode->SetCData(XFA_ATTRIBUTE_Uuid, wsAttriValue); + } else if (wsAttriName == FX_WSTRC(L"timeStamp")) { + pXFARootNode->SetCData(XFA_ATTRIBUTE_TimeStamp, wsAttriValue); + } + } + } + CFDE_XMLNode* pXMLConfigDOMRoot = nullptr; + CXFA_Node* pXFAConfigDOMRoot = nullptr; + { + for (CFDE_XMLNode* pChildItem = + pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); + pChildItem; + pChildItem = pChildItem->GetNodeItem(CFDE_XMLNode::NextSibling)) { + const XFA_PACKETINFO* pPacketInfo = + XFA_GetPacketByIndex(XFA_PACKET_Config); + if (!XFA_FDEExtension_MatchNodeName(pChildItem, pPacketInfo->pName, + pPacketInfo->pURI, + pPacketInfo->eFlags)) { + continue; + } + if (pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) { + return nullptr; + } + pXMLConfigDOMRoot = pChildItem; + pXFAConfigDOMRoot = + ParseAsXDPPacket_Config(pXMLConfigDOMRoot, XFA_XDPPACKET_Config); + pXFARootNode->InsertChild(pXFAConfigDOMRoot, nullptr); + } + } + CFDE_XMLNode* pXMLDatasetsDOMRoot = nullptr; + CFDE_XMLNode* pXMLFormDOMRoot = nullptr; + CFDE_XMLNode* pXMLTemplateDOMRoot = nullptr; + { + for (CFDE_XMLNode* pChildItem = + pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); + pChildItem; + pChildItem = pChildItem->GetNodeItem(CFDE_XMLNode::NextSibling)) { + if (!pChildItem || pChildItem->GetType() != FDE_XMLNODE_Element) { + continue; + } + if (pChildItem == pXMLConfigDOMRoot) { + continue; + } + CFDE_XMLElement* pElement = + reinterpret_cast(pChildItem); + CFX_WideString wsPacketName; + pElement->GetLocalTagName(wsPacketName); + const XFA_PACKETINFO* pPacketInfo = + XFA_GetPacketByName(wsPacketName.AsStringC()); + if (pPacketInfo && pPacketInfo->pURI) { + if (!XFA_FDEExtension_MatchNodeName(pElement, pPacketInfo->pName, + pPacketInfo->pURI, + pPacketInfo->eFlags)) { + pPacketInfo = nullptr; + } + } + XFA_XDPPACKET ePacket = + pPacketInfo ? pPacketInfo->eName : XFA_XDPPACKET_USER; + if (ePacket == XFA_XDPPACKET_XDP) { + continue; + } + if (ePacket == XFA_XDPPACKET_Datasets) { + if (pXMLDatasetsDOMRoot) { + return nullptr; + } + pXMLDatasetsDOMRoot = pElement; + } else if (ePacket == XFA_XDPPACKET_Form) { + if (pXMLFormDOMRoot) { + return nullptr; + } + pXMLFormDOMRoot = pElement; + } else if (ePacket == XFA_XDPPACKET_Template) { + if (pXMLTemplateDOMRoot) { + // Found a duplicate template packet. + return nullptr; + } + CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket); + if (pPacketNode) { + pXMLTemplateDOMRoot = pElement; + pXFARootNode->InsertChild(pPacketNode); + } + } else { + CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket); + if (pPacketNode) { + if (pPacketInfo && + (pPacketInfo->eFlags & XFA_XDPPACKET_FLAGS_SUPPORTONE) && + pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) { + return nullptr; + } + pXFARootNode->InsertChild(pPacketNode); + } + } + } + } + if (!pXMLTemplateDOMRoot) { + // No template is found. + return nullptr; + } + if (pXMLDatasetsDOMRoot) { + CXFA_Node* pPacketNode = + ParseAsXDPPacket(pXMLDatasetsDOMRoot, XFA_XDPPACKET_Datasets); + if (pPacketNode) { + pXFARootNode->InsertChild(pPacketNode); + } + } + if (pXMLFormDOMRoot) { + CXFA_Node* pPacketNode = + ParseAsXDPPacket(pXMLFormDOMRoot, XFA_XDPPACKET_Form); + if (pPacketNode) { + pXFARootNode->InsertChild(pPacketNode); + } + } + pXFARootNode->SetXMLMappingNode(pXMLDocumentNode); + return pXFARootNode; +} +CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Config( + CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID) { + if (!XFA_FDEExtension_MatchNodeName( + pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Config)->pName, + XFA_GetPacketByIndex(XFA_PACKET_Config)->pURI, + XFA_GetPacketByIndex(XFA_PACKET_Config)->eFlags)) { + return nullptr; + } + CXFA_Node* pNode = + m_pFactory->CreateNode(XFA_XDPPACKET_Config, XFA_Element::Config); + if (!pNode) { + return nullptr; + } + pNode->SetCData(XFA_ATTRIBUTE_Name, + XFA_GetPacketByIndex(XFA_PACKET_Config)->pName); + if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { + return nullptr; + } + pNode->SetXMLMappingNode(pXMLDocumentNode); + return pNode; +} +CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm( + CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID) { + CXFA_Node* pNode = nullptr; + if (ePacketID == XFA_XDPPACKET_Template) { + if (XFA_FDEExtension_MatchNodeName( + pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Template)->pName, + XFA_GetPacketByIndex(XFA_PACKET_Template)->pURI, + XFA_GetPacketByIndex(XFA_PACKET_Template)->eFlags)) { + pNode = + m_pFactory->CreateNode(XFA_XDPPACKET_Template, XFA_Element::Template); + if (!pNode) { + return nullptr; + } + pNode->SetCData(XFA_ATTRIBUTE_Name, + XFA_GetPacketByIndex(XFA_PACKET_Template)->pName); + if (m_bDocumentParser) { + CFX_WideString wsNamespaceURI; + CFDE_XMLElement* pXMLDocumentElement = + static_cast(pXMLDocumentNode); + pXMLDocumentElement->GetNamespaceURI(wsNamespaceURI); + if (wsNamespaceURI.IsEmpty()) { + pXMLDocumentElement->GetString(L"xmlns:xfa", wsNamespaceURI); + } + pNode->GetDocument()->RecognizeXFAVersionNumber(wsNamespaceURI); + } + if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { + return nullptr; + } + } + } else if (ePacketID == XFA_XDPPACKET_Form) { + if (XFA_FDEExtension_MatchNodeName( + pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Form)->pName, + XFA_GetPacketByIndex(XFA_PACKET_Form)->pURI, + XFA_GetPacketByIndex(XFA_PACKET_Form)->eFlags)) { + CFDE_XMLElement* pXMLDocumentElement = + static_cast(pXMLDocumentNode); + CFX_WideString wsChecksum; + pXMLDocumentElement->GetString(L"checksum", wsChecksum); + if (wsChecksum.GetLength() != 28 || + m_pXMLParser->m_dwCheckStatus != 0x03) { + return nullptr; + } + std::unique_ptr pChecksum(new CXFA_ChecksumContext); + pChecksum->StartChecksum(); + pChecksum->UpdateChecksum(m_pFileRead, m_pXMLParser->m_nStart[0], + m_pXMLParser->m_nSize[0]); + pChecksum->UpdateChecksum(m_pFileRead, m_pXMLParser->m_nStart[1], + m_pXMLParser->m_nSize[1]); + pChecksum->FinishChecksum(); + CFX_ByteString bsCheck = pChecksum->GetChecksum(); + if (bsCheck != wsChecksum.UTF8Encode()) + return nullptr; + + pNode = m_pFactory->CreateNode(XFA_XDPPACKET_Form, XFA_Element::Form); + if (!pNode) + return nullptr; + + pNode->SetCData(XFA_ATTRIBUTE_Name, + XFA_GetPacketByIndex(XFA_PACKET_Form)->pName); + pNode->SetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum.AsStringC()); + CXFA_Node* pTemplateRoot = + m_pRootNode->GetFirstChildByClass(XFA_Element::Template); + CXFA_Node* pTemplateChosen = + pTemplateRoot + ? pTemplateRoot->GetFirstChildByClass(XFA_Element::Subform) + : nullptr; + FX_BOOL bUseAttribute = TRUE; + if (pTemplateChosen && + pTemplateChosen->GetEnum(XFA_ATTRIBUTE_RestoreState) != + XFA_ATTRIBUTEENUM_Auto) { + bUseAttribute = FALSE; + } + if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID, bUseAttribute)) { + return nullptr; + } + } + } + if (pNode) { + pNode->SetXMLMappingNode(pXMLDocumentNode); + } + return pNode; +} +static CFDE_XMLNode* XFA_GetDataSetsFromXDP(CFDE_XMLNode* pXMLDocumentNode) { + if (XFA_FDEExtension_MatchNodeName( + pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName, + XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI, + XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) { + return pXMLDocumentNode; + } + if (!XFA_FDEExtension_MatchNodeName( + pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_XDP)->pName, + XFA_GetPacketByIndex(XFA_PACKET_XDP)->pURI, + XFA_GetPacketByIndex(XFA_PACKET_XDP)->eFlags)) { + return nullptr; + } + for (CFDE_XMLNode* pDatasetsNode = + pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); + pDatasetsNode; + pDatasetsNode = pDatasetsNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { + if (!XFA_FDEExtension_MatchNodeName( + pDatasetsNode, XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName, + XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI, + XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) { + continue; + } + return pDatasetsNode; + } + return nullptr; +} +CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Data( + CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID) { + CFDE_XMLNode* pDatasetsXMLNode = XFA_GetDataSetsFromXDP(pXMLDocumentNode); + if (pDatasetsXMLNode) { + CXFA_Node* pNode = + m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, XFA_Element::DataModel); + if (!pNode) { + return nullptr; + } + pNode->SetCData(XFA_ATTRIBUTE_Name, + XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName); + if (!DataLoader(pNode, pDatasetsXMLNode, FALSE)) { + return nullptr; + } + pNode->SetXMLMappingNode(pDatasetsXMLNode); + return pNode; + } + CFDE_XMLNode* pDataXMLNode = nullptr; + if (XFA_FDEExtension_MatchNodeName( + pXMLDocumentNode, FX_WSTRC(L"data"), + XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI, + XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) { + static_cast(pXMLDocumentNode) + ->RemoveAttribute(L"xmlns:xfa"); + pDataXMLNode = pXMLDocumentNode; + } else { + CFDE_XMLElement* pDataElement = new CFDE_XMLElement(L"xfa:data"); + CFDE_XMLNode* pParentXMLNode = + pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::Parent); + if (pParentXMLNode) { + pParentXMLNode->RemoveChildNode(pXMLDocumentNode); + } + ASSERT(pXMLDocumentNode->GetType() == FDE_XMLNODE_Element); + if (pXMLDocumentNode->GetType() == FDE_XMLNODE_Element) { + static_cast(pXMLDocumentNode) + ->RemoveAttribute(L"xmlns:xfa"); + } + pDataElement->InsertChildNode(pXMLDocumentNode); + pDataXMLNode = pDataElement; + } + if (pDataXMLNode) { + CXFA_Node* pNode = + m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, XFA_Element::DataGroup); + if (!pNode) { + if (pDataXMLNode != pXMLDocumentNode) { + pDataXMLNode->Release(); + } + return nullptr; + } + CFX_WideString wsLocalName; + static_cast(pDataXMLNode)->GetLocalTagName(wsLocalName); + pNode->SetCData(XFA_ATTRIBUTE_Name, wsLocalName); + if (!DataLoader(pNode, pDataXMLNode, TRUE)) { + return nullptr; + } + pNode->SetXMLMappingNode(pDataXMLNode); + if (pDataXMLNode != pXMLDocumentNode) { + pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false); + } + return pNode; + } + return nullptr; +} +CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_LocaleConnectionSourceSet( + CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID) { + CXFA_Node* pNode = nullptr; + if (ePacketID == XFA_XDPPACKET_LocaleSet) { + if (XFA_FDEExtension_MatchNodeName( + pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pName, + XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pURI, + XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->eFlags)) { + pNode = m_pFactory->CreateNode(XFA_XDPPACKET_LocaleSet, + XFA_Element::LocaleSet); + if (!pNode) { + return nullptr; + } + pNode->SetCData(XFA_ATTRIBUTE_Name, + XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pName); + if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { + return nullptr; + } + } + } else if (ePacketID == XFA_XDPPACKET_ConnectionSet) { + if (XFA_FDEExtension_MatchNodeName( + pXMLDocumentNode, + XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pName, + XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pURI, + XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->eFlags)) { + pNode = m_pFactory->CreateNode(XFA_XDPPACKET_ConnectionSet, + XFA_Element::ConnectionSet); + if (!pNode) { + return nullptr; + } + pNode->SetCData(XFA_ATTRIBUTE_Name, + XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pName); + if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { + return nullptr; + } + } + } else if (ePacketID == XFA_XDPPACKET_SourceSet) { + if (XFA_FDEExtension_MatchNodeName( + pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pName, + XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pURI, + XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->eFlags)) { + pNode = m_pFactory->CreateNode(XFA_XDPPACKET_SourceSet, + XFA_Element::SourceSet); + if (!pNode) { + return nullptr; + } + pNode->SetCData(XFA_ATTRIBUTE_Name, + XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pName); + if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { + return nullptr; + } + } + } + if (pNode) { + pNode->SetXMLMappingNode(pXMLDocumentNode); + } + return pNode; +} +CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Xdc( + CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID) { + if (XFA_FDEExtension_MatchNodeName( + pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pName, + XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pURI, + XFA_GetPacketByIndex(XFA_PACKET_Xdc)->eFlags)) { + CXFA_Node* pNode = + m_pFactory->CreateNode(XFA_XDPPACKET_Xdc, XFA_Element::Xdc); + if (!pNode) { + return nullptr; + } + pNode->SetCData(XFA_ATTRIBUTE_Name, + XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pName); + pNode->SetXMLMappingNode(pXMLDocumentNode); + return pNode; + } + return nullptr; +} +CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_User( + CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID) { + CXFA_Node* pNode = + m_pFactory->CreateNode(XFA_XDPPACKET_XDP, XFA_Element::Packet); + if (!pNode) { + return nullptr; + } + CFX_WideString wsName; + static_cast(pXMLDocumentNode)->GetLocalTagName(wsName); + pNode->SetCData(XFA_ATTRIBUTE_Name, wsName); + if (!UserPacketLoader(pNode, pXMLDocumentNode)) { + return nullptr; + } + pNode->SetXMLMappingNode(pXMLDocumentNode); + return pNode; +} +CXFA_Node* CXFA_SimpleParser::UserPacketLoader(CXFA_Node* pXFANode, + CFDE_XMLNode* pXMLDoc) { + return pXFANode; +} +static FX_BOOL XFA_FDEExtension_IsStringAllWhitespace(CFX_WideString wsText) { + wsText.TrimRight(L"\x20\x9\xD\xA"); + return wsText.IsEmpty(); +} +CXFA_Node* CXFA_SimpleParser::DataLoader(CXFA_Node* pXFANode, + CFDE_XMLNode* pXMLDoc, + FX_BOOL bDoTransform) { + ParseDataGroup(pXFANode, pXMLDoc, XFA_XDPPACKET_Datasets); + return pXFANode; +} +CXFA_Node* CXFA_SimpleParser::NormalLoader(CXFA_Node* pXFANode, + CFDE_XMLNode* pXMLDoc, + XFA_XDPPACKET ePacketID, + FX_BOOL bUseAttribute) { + FX_BOOL bOneOfPropertyFound = FALSE; + for (CFDE_XMLNode* pXMLChild = pXMLDoc->GetNodeItem(CFDE_XMLNode::FirstChild); + pXMLChild; + pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { + switch (pXMLChild->GetType()) { + case FDE_XMLNODE_Element: { + CFDE_XMLElement* pXMLElement = static_cast(pXMLChild); + CFX_WideString wsTagName; + pXMLElement->GetLocalTagName(wsTagName); + XFA_Element eType = XFA_GetElementTypeForName(wsTagName.AsStringC()); + if (eType == XFA_Element::Unknown) + continue; + + const XFA_PROPERTY* pPropertyInfo = XFA_GetPropertyOfElement( + pXFANode->GetElementType(), eType, ePacketID); + if (pPropertyInfo && + ((pPropertyInfo->uFlags & + (XFA_PROPERTYFLAG_OneOf | XFA_PROPERTYFLAG_DefaultOneOf)) != 0)) { + if (bOneOfPropertyFound) { + break; + } + bOneOfPropertyFound = TRUE; + } + CXFA_Node* pXFAChild = m_pFactory->CreateNode(ePacketID, eType); + if (!pXFAChild) + return nullptr; + if (ePacketID == XFA_XDPPACKET_Config) + pXFAChild->SetAttribute(XFA_ATTRIBUTE_Name, wsTagName.AsStringC()); + + FX_BOOL IsNeedValue = TRUE; + for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count; + i++) { + CFX_WideString wsAttrQualifiedName; + CFX_WideString wsAttrName; + CFX_WideString wsAttrValue; + pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue); + XFA_FDEExtension_GetAttributeLocalName( + wsAttrQualifiedName.AsStringC(), wsAttrName); + if (wsAttrName == FX_WSTRC(L"nil") && + wsAttrValue == FX_WSTRC(L"true")) { + IsNeedValue = FALSE; + } + const XFA_ATTRIBUTEINFO* lpAttrInfo = + XFA_GetAttributeByName(wsAttrName.AsStringC()); + if (!lpAttrInfo) { + continue; + } + if (!bUseAttribute && lpAttrInfo->eName != XFA_ATTRIBUTE_Name && + lpAttrInfo->eName != XFA_ATTRIBUTE_Save) { + continue; + } + pXFAChild->SetAttribute(lpAttrInfo->eName, wsAttrValue.AsStringC()); + } + pXFANode->InsertChild(pXFAChild); + if (eType == XFA_Element::Validate || eType == XFA_Element::Locale) { + if (ePacketID == XFA_XDPPACKET_Config) { + ParseContentNode(pXFAChild, pXMLElement, ePacketID); + } else { + NormalLoader(pXFAChild, pXMLElement, ePacketID, bUseAttribute); + } + break; + } + switch (pXFAChild->GetObjectType()) { + case XFA_ObjectType::ContentNode: + case XFA_ObjectType::TextNode: + case XFA_ObjectType::NodeC: + case XFA_ObjectType::NodeV: + if (IsNeedValue) { + ParseContentNode(pXFAChild, pXMLElement, ePacketID); + } + break; + default: + NormalLoader(pXFAChild, pXMLElement, ePacketID, bUseAttribute); + break; + } + } break; + case FDE_XMLNODE_Instruction: + ParseInstruction(pXFANode, static_cast(pXMLChild), + ePacketID); + break; + default: + break; + } + } + return pXFANode; +} +FX_BOOL XFA_RecognizeRichText(CFDE_XMLElement* pRichTextXMLNode) { + if (pRichTextXMLNode) { + CFX_WideString wsNamespaceURI; + XFA_FDEExtension_GetElementTagNamespaceURI(pRichTextXMLNode, + wsNamespaceURI); + if (wsNamespaceURI == FX_WSTRC(L"http://www.w3.org/1999/xhtml")) { + return TRUE; + } + } + return FALSE; +} +class RichTextNodeVisitor { + public: + static inline CFDE_XMLNode* GetFirstChild(CFDE_XMLNode* pNode) { + return pNode->GetNodeItem(CFDE_XMLNode::FirstChild); + } + static inline CFDE_XMLNode* GetNextSibling(CFDE_XMLNode* pNode) { + return pNode->GetNodeItem(CFDE_XMLNode::NextSibling); + } + static inline CFDE_XMLNode* GetParent(CFDE_XMLNode* pNode) { + return pNode->GetNodeItem(CFDE_XMLNode::Parent); + } +}; + +void XFA_ConvertXMLToPlainText(CFDE_XMLElement* pRootXMLNode, + CFX_WideString& wsOutput) { + for (CFDE_XMLNode* pXMLChild = + pRootXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); + pXMLChild; + pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { + switch (pXMLChild->GetType()) { + case FDE_XMLNODE_Element: { + CFX_WideString wsTextData; + static_cast(pXMLChild)->GetTextData(wsTextData); + wsTextData += FX_WSTRC(L"\n"); + wsOutput += wsTextData; + } break; + case FDE_XMLNODE_Text: { + CFX_WideString wsText; + static_cast(pXMLChild)->GetText(wsText); + if (XFA_FDEExtension_IsStringAllWhitespace(wsText)) { + continue; + } else { + wsOutput = wsText; + } + } break; + case FDE_XMLNODE_CharData: { + CFX_WideString wsCharData; + static_cast(pXMLChild)->GetCharData(wsCharData); + if (XFA_FDEExtension_IsStringAllWhitespace(wsCharData)) { + continue; + } else { + wsOutput = wsCharData; + } + } break; + default: + ASSERT(FALSE); + break; + } + } +} + +void CXFA_SimpleParser::ParseContentNode(CXFA_Node* pXFANode, + CFDE_XMLNode* pXMLNode, + XFA_XDPPACKET ePacketID) { + XFA_Element element = XFA_Element::Sharptext; + if (pXFANode->GetElementType() == XFA_Element::ExData) { + CFX_WideStringC wsContentType = + pXFANode->GetCData(XFA_ATTRIBUTE_ContentType); + if (wsContentType == FX_WSTRC(L"text/html")) + element = XFA_Element::SharpxHTML; + else if (wsContentType == FX_WSTRC(L"text/xml")) + element = XFA_Element::Sharpxml; + } + if (element == XFA_Element::SharpxHTML) + pXFANode->SetXMLMappingNode(pXMLNode); + + CFX_WideString wsValue; + for (CFDE_XMLNode* pXMLChild = + pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); + pXMLChild; + pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { + FDE_XMLNODETYPE eNodeType = pXMLChild->GetType(); + if (eNodeType == FDE_XMLNODE_Instruction) + continue; + + if (element == XFA_Element::SharpxHTML) { + if (eNodeType != FDE_XMLNODE_Element) + break; + + if (XFA_RecognizeRichText(static_cast(pXMLChild))) + XFA_GetPlainTextFromRichText(static_cast(pXMLChild), + wsValue); + } else if (element == XFA_Element::Sharpxml) { + if (eNodeType != FDE_XMLNODE_Element) + break; + XFA_ConvertXMLToPlainText(static_cast(pXMLChild), + wsValue); + } else { + if (eNodeType == FDE_XMLNODE_Element) + break; + if (eNodeType == FDE_XMLNODE_Text) + static_cast(pXMLChild)->GetText(wsValue); + else if (eNodeType == FDE_XMLNODE_CharData) + static_cast(pXMLChild)->GetCharData(wsValue); + } + break; + } + if (!wsValue.IsEmpty()) { + if (pXFANode->IsContentNode()) { + CXFA_Node* pContentRawDataNode = + m_pFactory->CreateNode(ePacketID, element); + ASSERT(pContentRawDataNode); + pContentRawDataNode->SetCData(XFA_ATTRIBUTE_Value, wsValue); + pXFANode->InsertChild(pContentRawDataNode); + } else { + pXFANode->SetCData(XFA_ATTRIBUTE_Value, wsValue); + } + } +} + +void CXFA_SimpleParser::ParseDataGroup(CXFA_Node* pXFANode, + CFDE_XMLNode* pXMLNode, + XFA_XDPPACKET ePacketID) { + for (CFDE_XMLNode* pXMLChild = + pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); + pXMLChild; + pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { + switch (pXMLChild->GetType()) { + case FDE_XMLNODE_Element: { + CFDE_XMLElement* pXMLElement = static_cast(pXMLChild); + { + CFX_WideString wsNamespaceURI; + XFA_FDEExtension_GetElementTagNamespaceURI(pXMLElement, + wsNamespaceURI); + if (wsNamespaceURI == + FX_WSTRC(L"http://www.xfa.com/schema/xfa-package/") || + wsNamespaceURI == + FX_WSTRC(L"http://www.xfa.org/schema/xfa-package/") || + wsNamespaceURI == + FX_WSTRC(L"http://www.w3.org/2001/XMLSchema-instance")) { + continue; + } + } + XFA_Element eNodeType = XFA_Element::DataModel; + if (eNodeType == XFA_Element::DataModel) { + CFX_WideString wsDataNodeAttr; + if (XFA_FDEExtension_FindAttributeWithNS( + pXMLElement, FX_WSTRC(L"dataNode"), + FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/"), + wsDataNodeAttr)) { + if (wsDataNodeAttr == FX_WSTRC(L"dataGroup")) { + eNodeType = XFA_Element::DataGroup; + } else if (wsDataNodeAttr == FX_WSTRC(L"dataValue")) { + eNodeType = XFA_Element::DataValue; + } + } + } + CFX_WideString wsContentType; + if (eNodeType == XFA_Element::DataModel) { + if (XFA_FDEExtension_FindAttributeWithNS( + pXMLElement, FX_WSTRC(L"contentType"), + FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/"), + wsContentType)) { + if (!wsContentType.IsEmpty()) { + eNodeType = XFA_Element::DataValue; + } + } + } + if (eNodeType == XFA_Element::DataModel) { + for (CFDE_XMLNode* pXMLDataChild = + pXMLElement->GetNodeItem(CFDE_XMLNode::FirstChild); + pXMLDataChild; pXMLDataChild = pXMLDataChild->GetNodeItem( + CFDE_XMLNode::NextSibling)) { + if (pXMLDataChild->GetType() == FDE_XMLNODE_Element) { + if (!XFA_RecognizeRichText( + static_cast(pXMLDataChild))) { + eNodeType = XFA_Element::DataGroup; + break; + } + } + } + } + if (eNodeType == XFA_Element::DataModel) { + eNodeType = XFA_Element::DataValue; + } + CXFA_Node* pXFAChild = + m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, eNodeType); + if (!pXFAChild) { + return; + } + CFX_WideString wsNodeName; + pXMLElement->GetLocalTagName(wsNodeName); + pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeName); + bool bNeedValue = true; + for (int32_t i = 0; i < pXMLElement->CountAttributes(); ++i) { + CFX_WideString wsQualifiedName; + CFX_WideString wsValue; + CFX_WideString wsName; + CFX_WideString wsNS; + pXMLElement->GetAttribute(i, wsQualifiedName, wsValue); + if (!XFA_FDEExtension_ResolveAttribute( + pXMLElement, wsQualifiedName.AsStringC(), wsName, wsNS)) { + continue; + } + if (wsName == FX_WSTRC(L"nil") && wsValue == FX_WSTRC(L"true")) { + bNeedValue = false; + continue; + } + if (wsNS == FX_WSTRC(L"http://www.xfa.com/schema/xfa-package/") || + wsNS == FX_WSTRC(L"http://www.xfa.org/schema/xfa-package/") || + wsNS == FX_WSTRC(L"http://www.w3.org/2001/XMLSchema-instance") || + wsNS == FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/")) { + continue; + } + CXFA_Node* pXFAMetaData = m_pFactory->CreateNode( + XFA_XDPPACKET_Datasets, XFA_Element::DataValue); + if (!pXFAMetaData) { + return; + } + pXFAMetaData->SetCData(XFA_ATTRIBUTE_Name, wsName); + pXFAMetaData->SetCData(XFA_ATTRIBUTE_QualifiedName, wsQualifiedName); + pXFAMetaData->SetCData(XFA_ATTRIBUTE_Value, wsValue); + pXFAMetaData->SetEnum(XFA_ATTRIBUTE_Contains, + XFA_ATTRIBUTEENUM_MetaData); + pXFAChild->InsertChild(pXFAMetaData); + pXFAMetaData->SetXMLMappingNode(pXMLElement); + pXFAMetaData->SetFlag(XFA_NodeFlag_Initialized, false); + } + if (!bNeedValue) { + CFX_WideString wsNilName(L"xsi:nil"); + pXMLElement->RemoveAttribute(wsNilName.c_str()); + } + pXFANode->InsertChild(pXFAChild); + if (eNodeType == XFA_Element::DataGroup) { + ParseDataGroup(pXFAChild, pXMLElement, ePacketID); + } else if (bNeedValue) { + ParseDataValue(pXFAChild, pXMLChild, XFA_XDPPACKET_Datasets); + } + pXFAChild->SetXMLMappingNode(pXMLElement); + pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); + continue; + } + case FDE_XMLNODE_CharData: { + CFDE_XMLCharData* pXMLCharData = + static_cast(pXMLChild); + CFX_WideString wsCharData; + pXMLCharData->GetCharData(wsCharData); + if (XFA_FDEExtension_IsStringAllWhitespace(wsCharData)) { + continue; + } + CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, + XFA_Element::DataValue); + if (!pXFAChild) { + return; + } + pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCharData); + pXFANode->InsertChild(pXFAChild); + pXFAChild->SetXMLMappingNode(pXMLCharData); + pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); + continue; + } + case FDE_XMLNODE_Text: { + CFDE_XMLText* pXMLText = static_cast(pXMLChild); + CFX_WideString wsText; + pXMLText->GetText(wsText); + if (XFA_FDEExtension_IsStringAllWhitespace(wsText)) { + continue; + } + CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, + XFA_Element::DataValue); + if (!pXFAChild) { + return; + } + pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsText); + pXFANode->InsertChild(pXFAChild); + pXFAChild->SetXMLMappingNode(pXMLText); + pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); + continue; + } + default: + continue; + } + } +} + +void CXFA_SimpleParser::ParseDataValue(CXFA_Node* pXFANode, + CFDE_XMLNode* pXMLNode, + XFA_XDPPACKET ePacketID) { + CFX_WideTextBuf wsValueTextBuf; + CFX_WideTextBuf wsCurValueTextBuf; + FX_BOOL bMarkAsCompound = FALSE; + CFDE_XMLNode* pXMLCurValueNode = nullptr; + for (CFDE_XMLNode* pXMLChild = + pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); + pXMLChild; + pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { + FDE_XMLNODETYPE eNodeType = pXMLChild->GetType(); + if (eNodeType == FDE_XMLNODE_Instruction) + continue; + + CFX_WideString wsText; + if (eNodeType == FDE_XMLNODE_Text) { + static_cast(pXMLChild)->GetText(wsText); + if (!pXMLCurValueNode) + pXMLCurValueNode = pXMLChild; + + wsCurValueTextBuf << wsText; + } else if (eNodeType == FDE_XMLNODE_CharData) { + static_cast(pXMLChild)->GetCharData(wsText); + if (!pXMLCurValueNode) + pXMLCurValueNode = pXMLChild; + + wsCurValueTextBuf << wsText; + } else if (XFA_RecognizeRichText( + static_cast(pXMLChild))) { + XFA_GetPlainTextFromRichText(static_cast(pXMLChild), + wsText); + if (!pXMLCurValueNode) + pXMLCurValueNode = pXMLChild; + + wsCurValueTextBuf << wsText; + } else { + bMarkAsCompound = TRUE; + if (pXMLCurValueNode) { + CFX_WideString wsCurValue = wsCurValueTextBuf.MakeString(); + if (!wsCurValue.IsEmpty()) { + CXFA_Node* pXFAChild = + m_pFactory->CreateNode(ePacketID, XFA_Element::DataValue); + if (!pXFAChild) + return; + + pXFAChild->SetCData(XFA_ATTRIBUTE_Name, L""); + pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCurValue); + pXFANode->InsertChild(pXFAChild); + pXFAChild->SetXMLMappingNode(pXMLCurValueNode); + pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); + wsValueTextBuf << wsCurValue; + wsCurValueTextBuf.Clear(); + } + pXMLCurValueNode = nullptr; + } + CXFA_Node* pXFAChild = + m_pFactory->CreateNode(ePacketID, XFA_Element::DataValue); + if (!pXFAChild) + return; + + CFX_WideString wsNodeStr; + static_cast(pXMLChild)->GetLocalTagName(wsNodeStr); + pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr); + ParseDataValue(pXFAChild, pXMLChild, ePacketID); + pXFANode->InsertChild(pXFAChild); + pXFAChild->SetXMLMappingNode(pXMLChild); + pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); + CFX_WideStringC wsCurValue = pXFAChild->GetCData(XFA_ATTRIBUTE_Value); + wsValueTextBuf << wsCurValue; + } + } + if (pXMLCurValueNode) { + CFX_WideString wsCurValue = wsCurValueTextBuf.MakeString(); + if (!wsCurValue.IsEmpty()) { + if (bMarkAsCompound) { + CXFA_Node* pXFAChild = + m_pFactory->CreateNode(ePacketID, XFA_Element::DataValue); + if (!pXFAChild) + return; + + pXFAChild->SetCData(XFA_ATTRIBUTE_Name, L""); + pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCurValue); + pXFANode->InsertChild(pXFAChild); + pXFAChild->SetXMLMappingNode(pXMLCurValueNode); + pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); + } + wsValueTextBuf << wsCurValue; + wsCurValueTextBuf.Clear(); + } + pXMLCurValueNode = nullptr; + } + CFX_WideString wsNodeValue = wsValueTextBuf.MakeString(); + pXFANode->SetCData(XFA_ATTRIBUTE_Value, wsNodeValue); +} + +void CXFA_SimpleParser::ParseInstruction(CXFA_Node* pXFANode, + CFDE_XMLInstruction* pXMLInstruction, + XFA_XDPPACKET ePacketID) { + if (!m_bDocumentParser) { + return; + } + CFX_WideString wsTargetName; + pXMLInstruction->GetTargetName(wsTargetName); + if (wsTargetName == FX_WSTRC(L"originalXFAVersion")) { + CFX_WideString wsData; + if (pXMLInstruction->GetData(0, wsData) && + (pXFANode->GetDocument()->RecognizeXFAVersionNumber(wsData) != + XFA_VERSION_UNKNOWN)) { + wsData.clear(); + if (pXMLInstruction->GetData(1, wsData) && + wsData == FX_WSTRC(L"v2.7-scripting:1")) { + pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_Scripting, TRUE); + } + } + } else if (wsTargetName == FX_WSTRC(L"acrobat")) { + CFX_WideString wsData; + if (pXMLInstruction->GetData(0, wsData) && + wsData == FX_WSTRC(L"JavaScript")) { + if (pXMLInstruction->GetData(1, wsData) && + wsData == FX_WSTRC(L"strictScoping")) { + pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, TRUE); + } + } + } +} +void CXFA_SimpleParser::CloseParser() { + if (m_pXMLDoc) { + m_pXMLDoc->Release(); + m_pXMLDoc = nullptr; + } + if (m_pStream) { + m_pStream->Release(); + m_pStream = nullptr; + } +} diff --git a/xfa/fxfa/parser/cxfa_simple_parser.h b/xfa/fxfa/parser/cxfa_simple_parser.h new file mode 100644 index 0000000000..d49008da91 --- /dev/null +++ b/xfa/fxfa/parser/cxfa_simple_parser.h @@ -0,0 +1,86 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_SIMPLE_PARSER_H_ +#define XFA_FXFA_PARSER_CXFA_SIMPLE_PARSER_H_ + +#include "xfa/fde/xml/fde_xml_imp.h" +#include "xfa/fxfa/include/fxfa_basic.h" + +class CXFA_Document; +class CXFA_Node; +class CXFA_XMLParser; +class IFX_FileRead; +class IFX_Pause; +class IFX_Stream; + +class CXFA_SimpleParser { + public: + CXFA_SimpleParser(CXFA_Document* pFactory, bool bDocumentParser); + ~CXFA_SimpleParser(); + + int32_t StartParse(IFX_FileRead* pStream, XFA_XDPPACKET ePacketID); + int32_t DoParse(IFX_Pause* pPause = nullptr); + int32_t ParseXMLData(const CFX_WideString& wsXML, + CFDE_XMLNode*& pXMLNode, + IFX_Pause* pPause = nullptr); + void ConstructXFANode(CXFA_Node* pXFANode, CFDE_XMLNode* pXMLNode); + CXFA_Node* GetRootNode() const; + CFDE_XMLDoc* GetXMLDoc() const; + void CloseParser(); + + protected: + CXFA_Node* ParseAsXDPPacket(CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID); + CXFA_Node* ParseAsXDPPacket_XDP(CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID); + CXFA_Node* ParseAsXDPPacket_Config(CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID); + CXFA_Node* ParseAsXDPPacket_TemplateForm(CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID); + CXFA_Node* ParseAsXDPPacket_Data(CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID); + CXFA_Node* ParseAsXDPPacket_LocaleConnectionSourceSet( + CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID); + CXFA_Node* ParseAsXDPPacket_Xdc(CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID); + CXFA_Node* ParseAsXDPPacket_User(CFDE_XMLNode* pXMLDocumentNode, + XFA_XDPPACKET ePacketID); + CXFA_Node* NormalLoader(CXFA_Node* pXFANode, + CFDE_XMLNode* pXMLDoc, + XFA_XDPPACKET ePacketID, + FX_BOOL bUseAttribute = TRUE); + CXFA_Node* DataLoader(CXFA_Node* pXFANode, + CFDE_XMLNode* pXMLDoc, + FX_BOOL bDoTransform); + CXFA_Node* UserPacketLoader(CXFA_Node* pXFANode, CFDE_XMLNode* pXMLDoc); + void ParseContentNode(CXFA_Node* pXFANode, + CFDE_XMLNode* pXMLNode, + XFA_XDPPACKET ePacketID); + void ParseDataValue(CXFA_Node* pXFANode, + CFDE_XMLNode* pXMLNode, + XFA_XDPPACKET ePacketID); + void ParseDataGroup(CXFA_Node* pXFANode, + CFDE_XMLNode* pXMLNode, + XFA_XDPPACKET ePacketID); + void ParseInstruction(CXFA_Node* pXFANode, + CFDE_XMLInstruction* pXMLInstruction, + XFA_XDPPACKET ePacketID); + void SetFactory(CXFA_Document* pFactory); + + CXFA_XMLParser* m_pXMLParser; + CFDE_XMLDoc* m_pXMLDoc; + IFX_Stream* m_pStream; + IFX_FileRead* m_pFileRead; + CXFA_Document* m_pFactory; + CXFA_Node* m_pRootNode; + XFA_XDPPACKET m_ePacketID; + FX_BOOL m_bDocumentParser; + friend class CXFA_DocumentParser; +}; + +#endif // XFA_FXFA_PARSER_CXFA_SIMPLE_PARSER_H_ diff --git a/xfa/fxfa/parser/cxfa_simple_parser_embeddertest.cpp b/xfa/fxfa/parser/cxfa_simple_parser_embeddertest.cpp new file mode 100644 index 0000000000..a33169646d --- /dev/null +++ b/xfa/fxfa/parser/cxfa_simple_parser_embeddertest.cpp @@ -0,0 +1,15 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "testing/embedder_test.h" +#include "testing/gtest/include/gtest/gtest.h" + +class CXFASimpleParserEmbeddertest : public EmbedderTest {}; + +TEST_F(CXFASimpleParserEmbeddertest, Bug_216) { + EXPECT_TRUE(OpenDocument("bug_216.pdf")); + FPDF_PAGE page = LoadPage(0); + EXPECT_NE(nullptr, page); + UnloadPage(page); +} diff --git a/xfa/fxfa/parser/cxfa_xml_parser.cpp b/xfa/fxfa/parser/cxfa_xml_parser.cpp new file mode 100644 index 0000000000..268c8b1416 --- /dev/null +++ b/xfa/fxfa/parser/cxfa_xml_parser.cpp @@ -0,0 +1,176 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/parser/cxfa_xml_parser.h" + +CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pRoot, IFX_Stream* pStream) + : m_nElementStart(0), + m_dwCheckStatus(0), + m_dwCurrentCheckStatus(0), + m_pRoot(pRoot), + m_pStream(pStream), + m_pParser(new CFDE_XMLSyntaxParser), + m_pParent(pRoot), + m_pChild(nullptr), + m_NodeStack(16), + m_syntaxParserResult(FDE_XmlSyntaxResult::None) { + ASSERT(m_pParent && m_pStream); + m_NodeStack.Push(m_pParent); + m_pParser->Init(m_pStream, 32 * 1024, 1024 * 1024); +} + +CXFA_XMLParser::~CXFA_XMLParser() { + m_NodeStack.RemoveAll(); + m_ws1.clear(); + m_ws2.clear(); +} + +void CXFA_XMLParser::Release() { + delete this; +} + +int32_t CXFA_XMLParser::DoParser(IFX_Pause* pPause) { + if (m_syntaxParserResult == FDE_XmlSyntaxResult::Error) + return -1; + if (m_syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) + return 100; + + int32_t iCount = 0; + while (TRUE) { + m_syntaxParserResult = m_pParser->DoSyntaxParse(); + switch (m_syntaxParserResult) { + case FDE_XmlSyntaxResult::InstructionOpen: + break; + case FDE_XmlSyntaxResult::InstructionClose: + if (m_pChild) { + if (m_pChild->GetType() != FDE_XMLNODE_Instruction) { + m_syntaxParserResult = FDE_XmlSyntaxResult::Error; + break; + } + } + m_pChild = m_pParent; + break; + case FDE_XmlSyntaxResult::ElementOpen: + if (m_dwCheckStatus != 0x03 && m_NodeStack.GetSize() == 2) { + m_nElementStart = m_pParser->GetCurrentPos() - 1; + } + break; + case FDE_XmlSyntaxResult::ElementBreak: + break; + case FDE_XmlSyntaxResult::ElementClose: + if (m_pChild->GetType() != FDE_XMLNODE_Element) { + m_syntaxParserResult = FDE_XmlSyntaxResult::Error; + break; + } + m_pParser->GetTagName(m_ws1); + static_cast(m_pChild)->GetTagName(m_ws2); + if (m_ws1.GetLength() > 0 && m_ws1 != m_ws2) { + m_syntaxParserResult = FDE_XmlSyntaxResult::Error; + break; + } + m_NodeStack.Pop(); + if (m_NodeStack.GetSize() < 1) { + m_syntaxParserResult = FDE_XmlSyntaxResult::Error; + break; + } else if (m_dwCurrentCheckStatus != 0 && m_NodeStack.GetSize() == 2) { + m_nSize[m_dwCurrentCheckStatus - 1] = + m_pParser->GetCurrentBinaryPos() - + m_nStart[m_dwCurrentCheckStatus - 1]; + m_dwCurrentCheckStatus = 0; + } + + m_pParent = static_cast(*m_NodeStack.GetTopElement()); + m_pChild = m_pParent; + iCount++; + break; + case FDE_XmlSyntaxResult::TargetName: + m_pParser->GetTargetName(m_ws1); + if (m_ws1 == FX_WSTRC(L"originalXFAVersion") || + m_ws1 == FX_WSTRC(L"acrobat")) { + m_pChild = new CFDE_XMLInstruction(m_ws1); + m_pParent->InsertChildNode(m_pChild); + } else { + m_pChild = nullptr; + } + m_ws1.clear(); + break; + case FDE_XmlSyntaxResult::TagName: + m_pParser->GetTagName(m_ws1); + m_pChild = new CFDE_XMLElement(m_ws1); + m_pParent->InsertChildNode(m_pChild); + m_NodeStack.Push(m_pChild); + m_pParent = m_pChild; + + if (m_dwCheckStatus != 0x03 && m_NodeStack.GetSize() == 3) { + CFX_WideString wsTag; + static_cast(m_pChild)->GetLocalTagName(wsTag); + if (wsTag == FX_WSTRC(L"template")) { + m_dwCheckStatus |= 0x01; + m_dwCurrentCheckStatus = 0x01; + m_nStart[0] = m_pParser->GetCurrentBinaryPos() - + (m_pParser->GetCurrentPos() - m_nElementStart); + } else if (wsTag == FX_WSTRC(L"datasets")) { + m_dwCheckStatus |= 0x02; + m_dwCurrentCheckStatus = 0x02; + m_nStart[1] = m_pParser->GetCurrentBinaryPos() - + (m_pParser->GetCurrentPos() - m_nElementStart); + } + } + break; + case FDE_XmlSyntaxResult::AttriName: + m_pParser->GetAttributeName(m_ws1); + break; + case FDE_XmlSyntaxResult::AttriValue: + if (m_pChild) { + m_pParser->GetAttributeName(m_ws2); + if (m_pChild->GetType() == FDE_XMLNODE_Element) { + static_cast(m_pChild)->SetString(m_ws1, m_ws2); + } + } + m_ws1.clear(); + break; + case FDE_XmlSyntaxResult::Text: + m_pParser->GetTextData(m_ws1); + m_pChild = new CFDE_XMLText(m_ws1); + m_pParent->InsertChildNode(m_pChild); + m_pChild = m_pParent; + break; + case FDE_XmlSyntaxResult::CData: + m_pParser->GetTextData(m_ws1); + m_pChild = new CFDE_XMLCharData(m_ws1); + m_pParent->InsertChildNode(m_pChild); + m_pChild = m_pParent; + break; + case FDE_XmlSyntaxResult::TargetData: + if (m_pChild) { + if (m_pChild->GetType() != FDE_XMLNODE_Instruction) { + m_syntaxParserResult = FDE_XmlSyntaxResult::Error; + break; + } + if (!m_ws1.IsEmpty()) { + static_cast(m_pChild)->AppendData(m_ws1); + } + m_pParser->GetTargetData(m_ws1); + static_cast(m_pChild)->AppendData(m_ws1); + } + m_ws1.clear(); + break; + default: + break; + } + if (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || + m_syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) { + break; + } + if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { + break; + } + } + return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || + m_NodeStack.GetSize() != 1) + ? -1 + : m_pParser->GetStatus(); +} diff --git a/xfa/fxfa/parser/cxfa_xml_parser.h b/xfa/fxfa/parser/cxfa_xml_parser.h new file mode 100644 index 0000000000..1fdf06b5a8 --- /dev/null +++ b/xfa/fxfa/parser/cxfa_xml_parser.h @@ -0,0 +1,43 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_XML_PARSER_H_ +#define XFA_FXFA_PARSER_CXFA_XML_PARSER_H_ + +#include "xfa/fde/xml/fde_xml_imp.h" + +class IFX_Stream; +class IFX_Pause; + +class CXFA_XMLParser : public CFDE_XMLParser { + public: + CXFA_XMLParser(CFDE_XMLNode* pRoot, IFX_Stream* pStream); + ~CXFA_XMLParser() override; + + // CFDE_XMLParser + void Release() override; + int32_t DoParser(IFX_Pause* pPause) override; + + FX_FILESIZE m_nStart[2]; + size_t m_nSize[2]; + FX_FILESIZE m_nElementStart; + uint16_t m_dwCheckStatus; + uint16_t m_dwCurrentCheckStatus; + + protected: + CFDE_XMLNode* m_pRoot; + IFX_Stream* m_pStream; + std::unique_ptr> + m_pParser; + CFDE_XMLNode* m_pParent; + CFDE_XMLNode* m_pChild; + CFX_StackTemplate m_NodeStack; + CFX_WideString m_ws1; + CFX_WideString m_ws2; + FDE_XmlSyntaxResult m_syntaxParserResult; +}; + +#endif // XFA_FXFA_PARSER_CXFA_XML_PARSER_H_ diff --git a/xfa/fxfa/parser/xfa_document.h b/xfa/fxfa/parser/xfa_document.h index 328f1bcdd2..176f0c7b98 100644 --- a/xfa/fxfa/parser/xfa_document.h +++ b/xfa/fxfa/parser/xfa_document.h @@ -10,8 +10,8 @@ #include "xfa/fxfa/include/fxfa.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" +class CFDE_XMLDoc; class CXFA_Document; class CXFA_LayoutItem; class CXFA_LayoutProcessor; diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp index dd1fce6eed..55718e2c88 100644 --- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp @@ -15,7 +15,6 @@ #include "xfa/fxfa/parser/xfa_document_layout_imp.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" #include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_script_imp.h" #include "xfa/fxfa/parser/xfa_utils.h" diff --git a/xfa/fxfa/parser/xfa_document_imp.cpp b/xfa/fxfa/parser/xfa_document_imp.cpp index efd48e66a1..4c8b4dba1d 100644 --- a/xfa/fxfa/parser/xfa_document_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_imp.cpp @@ -6,13 +6,13 @@ #include "core/fxcrt/include/fx_ext.h" #include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/parser/cxfa_document_parser.h" #include "xfa/fxfa/parser/xfa_basic_imp.h" #include "xfa/fxfa/parser/xfa_doclayout.h" #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_document_layout_imp.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" #include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_script_datawindow.h" #include "xfa/fxfa/parser/xfa_script_eventpseudomodel.h" diff --git a/xfa/fxfa/parser/xfa_document_serialize.cpp b/xfa/fxfa/parser/xfa_document_serialize.cpp index 428b470c13..a8c4cde4ac 100644 --- a/xfa/fxfa/parser/xfa_document_serialize.cpp +++ b/xfa/fxfa/parser/xfa_document_serialize.cpp @@ -8,11 +8,11 @@ #include "xfa/fde/xml/fde_xml_imp.h" #include "xfa/fgas/crt/fgas_codepage.h" +#include "xfa/fxfa/parser/cxfa_simple_parser.h" #include "xfa/fxfa/parser/xfa_doclayout.h" #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" #include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" diff --git a/xfa/fxfa/parser/xfa_layout_appadapter.cpp b/xfa/fxfa/parser/xfa_layout_appadapter.cpp index 0b94c644c4..a28987cfb8 100644 --- a/xfa/fxfa/parser/xfa_layout_appadapter.cpp +++ b/xfa/fxfa/parser/xfa_layout_appadapter.cpp @@ -14,7 +14,6 @@ #include "xfa/fxfa/parser/xfa_layout_pagemgr_new.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" #include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" diff --git a/xfa/fxfa/parser/xfa_layout_itemlayout.cpp b/xfa/fxfa/parser/xfa_layout_itemlayout.cpp index fb024ab8db..b834267f09 100644 --- a/xfa/fxfa/parser/xfa_layout_itemlayout.cpp +++ b/xfa/fxfa/parser/xfa_layout_itemlayout.cpp @@ -18,7 +18,6 @@ #include "xfa/fxfa/parser/xfa_layout_pagemgr_new.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" #include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" diff --git a/xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp b/xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp index 14329c68fb..5055000a6b 100644 --- a/xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp +++ b/xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp @@ -15,7 +15,6 @@ #include "xfa/fxfa/parser/xfa_layout_itemlayout.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" #include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_script_imp.h" #include "xfa/fxfa/parser/xfa_utils.h" diff --git a/xfa/fxfa/parser/xfa_object_imp.cpp b/xfa/fxfa/parser/xfa_object_imp.cpp index 5ada3bd197..871286d24e 100644 --- a/xfa/fxfa/parser/xfa_object_imp.cpp +++ b/xfa/fxfa/parser/xfa_object_imp.cpp @@ -16,12 +16,12 @@ #include "xfa/fgas/crt/fgas_system.h" #include "xfa/fxfa/app/xfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_occur.h" +#include "xfa/fxfa/parser/cxfa_simple_parser.h" #include "xfa/fxfa/parser/xfa_basic_imp.h" #include "xfa/fxfa/parser/xfa_doclayout.h" #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_document_layout_imp.h" #include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" #include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_script_imp.h" #include "xfa/fxfa/parser/xfa_utils.h" diff --git a/xfa/fxfa/parser/xfa_parser_imp.cpp b/xfa/fxfa/parser/xfa_parser_imp.cpp deleted file mode 100644 index e4387a7838..0000000000 --- a/xfa/fxfa/parser/xfa_parser_imp.cpp +++ /dev/null @@ -1,1542 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/parser/xfa_parser_imp.h" - -#include - -#include "xfa/fde/xml/fde_xml_imp.h" -#include "xfa/fgas/crt/fgas_codepage.h" -#include "xfa/fxfa/include/xfa_checksum.h" -#include "xfa/fxfa/parser/xfa_basic_imp.h" -#include "xfa/fxfa/parser/xfa_doclayout.h" -#include "xfa/fxfa/parser/xfa_document.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_utils.h" - -CXFA_SimpleParser::CXFA_SimpleParser(CXFA_Document* pFactory, - bool bDocumentParser) - : m_pXMLParser(nullptr), - m_pXMLDoc(nullptr), - m_pStream(nullptr), - m_pFileRead(nullptr), - m_pFactory(pFactory), - m_pRootNode(nullptr), - m_ePacketID(XFA_XDPPACKET_UNKNOWN), - m_bDocumentParser(bDocumentParser) {} - -CXFA_SimpleParser::~CXFA_SimpleParser() { - CloseParser(); -} - -void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { - m_pFactory = pFactory; -} - -static CFDE_XMLNode* XFA_FDEExtension_GetDocumentNode( - CFDE_XMLDoc* pXMLDoc, - FX_BOOL bVerifyWellFormness = FALSE) { - if (!pXMLDoc) { - return nullptr; - } - CFDE_XMLNode* pXMLFakeRoot = pXMLDoc->GetRoot(); - for (CFDE_XMLNode* pXMLNode = - pXMLFakeRoot->GetNodeItem(CFDE_XMLNode::FirstChild); - pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { - if (pXMLNode->GetType() == FDE_XMLNODE_Element) { - if (bVerifyWellFormness) { - for (CFDE_XMLNode* pNextNode = - pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling); - pNextNode; - pNextNode = pNextNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { - if (pNextNode->GetType() == FDE_XMLNODE_Element) { - return FALSE; - } - } - } - return pXMLNode; - } - } - return nullptr; -} -int32_t CXFA_SimpleParser::StartParse(IFX_FileRead* pStream, - XFA_XDPPACKET ePacketID) { - CloseParser(); - m_pFileRead = pStream; - m_pStream = IFX_Stream::CreateStream( - pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text); - if (!m_pStream) { - return XFA_PARSESTATUS_StreamErr; - } - uint16_t wCodePage = m_pStream->GetCodePage(); - if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && - wCodePage != FX_CODEPAGE_UTF8) { - m_pStream->SetCodePage(FX_CODEPAGE_UTF8); - } - m_pXMLDoc = new CFDE_XMLDoc; - m_pXMLParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream); - if (!m_pXMLDoc->LoadXML(m_pXMLParser)) { - return XFA_PARSESTATUS_StatusErr; - } - m_ePacketID = ePacketID; - return XFA_PARSESTATUS_Ready; -} -int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) { - if (!m_pXMLDoc || m_ePacketID == XFA_XDPPACKET_UNKNOWN) { - return XFA_PARSESTATUS_StatusErr; - } - int32_t iRet = m_pXMLDoc->DoLoad(pPause); - if (iRet < 0) { - return XFA_PARSESTATUS_SyntaxErr; - } - if (iRet < 100) { - return iRet / 2; - } - m_pRootNode = ParseAsXDPPacket(XFA_FDEExtension_GetDocumentNode(m_pXMLDoc), - m_ePacketID); - m_pXMLDoc->CloseXML(); - if (m_pStream) { - m_pStream->Release(); - m_pStream = nullptr; - } - if (!m_pRootNode) { - return XFA_PARSESTATUS_StatusErr; - } - return XFA_PARSESTATUS_Done; -} -int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML, - CFDE_XMLNode*& pXMLNode, - IFX_Pause* pPause) { - CloseParser(); - pXMLNode = nullptr; - IFX_Stream* pStream = XFA_CreateWideTextRead(wsXML); - if (!pStream) { - return XFA_PARSESTATUS_StreamErr; - } - m_pStream = pStream; - m_pXMLDoc = new CFDE_XMLDoc; - CXFA_XMLParser* pParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream); - pParser->m_dwCheckStatus = 0x03; - if (!m_pXMLDoc->LoadXML(pParser)) { - return XFA_PARSESTATUS_StatusErr; - } - int32_t iRet = m_pXMLDoc->DoLoad(pPause); - if (iRet < 0 || iRet >= 100) { - m_pXMLDoc->CloseXML(); - } - if (iRet < 0) { - return XFA_PARSESTATUS_SyntaxErr; - } - if (iRet < 100) { - return iRet / 2; - } - if (m_pStream) { - m_pStream->Release(); - m_pStream = nullptr; - } - pXMLNode = XFA_FDEExtension_GetDocumentNode(m_pXMLDoc); - return XFA_PARSESTATUS_Done; -} - -void CXFA_SimpleParser::ConstructXFANode(CXFA_Node* pXFANode, - CFDE_XMLNode* pXMLNode) { - XFA_XDPPACKET ePacketID = (XFA_XDPPACKET)pXFANode->GetPacketID(); - if (ePacketID == XFA_XDPPACKET_Datasets) { - if (pXFANode->GetElementType() == XFA_Element::DataValue) { - for (CFDE_XMLNode* pXMLChild = - pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); - pXMLChild; - pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { - FDE_XMLNODETYPE eNodeType = pXMLChild->GetType(); - if (eNodeType == FDE_XMLNODE_Instruction) - continue; - - if (eNodeType == FDE_XMLNODE_Element) { - CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, - XFA_Element::DataValue); - if (!pXFAChild) - return; - - CFX_WideString wsNodeStr; - CFDE_XMLElement* child = static_cast(pXMLChild); - child->GetLocalTagName(wsNodeStr); - pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr); - CFX_WideString wsChildValue; - XFA_GetPlainTextFromRichText(child, wsChildValue); - if (!wsChildValue.IsEmpty()) - pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsChildValue); - - pXFANode->InsertChild(pXFAChild); - pXFAChild->SetXMLMappingNode(pXMLChild); - pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); - break; - } - } - m_pRootNode = pXFANode; - } else { - m_pRootNode = DataLoader(pXFANode, pXMLNode, TRUE); - } - } else if (pXFANode->IsContentNode()) { - ParseContentNode(pXFANode, pXMLNode, ePacketID); - m_pRootNode = pXFANode; - } else { - m_pRootNode = NormalLoader(pXFANode, pXMLNode, ePacketID); - } -} - -CXFA_Node* CXFA_SimpleParser::GetRootNode() const { - return m_pRootNode; -} - -CFDE_XMLDoc* CXFA_SimpleParser::GetXMLDoc() const { - return m_pXMLDoc; -} - -FX_BOOL XFA_FDEExtension_ResolveNamespaceQualifier( - CFDE_XMLElement* pNode, - const CFX_WideStringC& wsQualifier, - CFX_WideString& wsNamespaceURI) { - if (!pNode) { - return FALSE; - } - CFDE_XMLNode* pFakeRoot = pNode->GetNodeItem(CFDE_XMLNode::Root); - CFX_WideString wsNSAttribute; - FX_BOOL bRet = FALSE; - if (wsQualifier.IsEmpty()) { - wsNSAttribute = FX_WSTRC(L"xmlns"); - bRet = TRUE; - } else { - wsNSAttribute = FX_WSTRC(L"xmlns:") + wsQualifier; - } - for (; pNode != pFakeRoot; pNode = static_cast( - pNode->GetNodeItem(CFDE_XMLNode::Parent))) { - if (pNode->GetType() != FDE_XMLNODE_Element) { - continue; - } - if (pNode->HasAttribute(wsNSAttribute.c_str())) { - pNode->GetString(wsNSAttribute.c_str(), wsNamespaceURI); - return TRUE; - } - } - wsNamespaceURI.clear(); - return bRet; -} -static inline void XFA_FDEExtension_GetElementTagNamespaceURI( - CFDE_XMLElement* pElement, - CFX_WideString& wsNamespaceURI) { - CFX_WideString wsNodeStr; - pElement->GetNamespacePrefix(wsNodeStr); - if (!XFA_FDEExtension_ResolveNamespaceQualifier( - pElement, wsNodeStr.AsStringC(), wsNamespaceURI)) { - wsNamespaceURI.clear(); - } -} -static FX_BOOL XFA_FDEExtension_MatchNodeName( - CFDE_XMLNode* pNode, - const CFX_WideStringC& wsLocalTagName, - const CFX_WideStringC& wsNamespaceURIPrefix, - uint32_t eMatchFlags = XFA_XDPPACKET_FLAGS_NOMATCH) { - if (!pNode || pNode->GetType() != FDE_XMLNODE_Element) { - return FALSE; - } - CFDE_XMLElement* pElement = reinterpret_cast(pNode); - CFX_WideString wsNodeStr; - pElement->GetLocalTagName(wsNodeStr); - if (wsNodeStr != wsLocalTagName) { - return FALSE; - } - XFA_FDEExtension_GetElementTagNamespaceURI(pElement, wsNodeStr); - if (eMatchFlags & XFA_XDPPACKET_FLAGS_NOMATCH) { - return TRUE; - } - if (eMatchFlags & XFA_XDPPACKET_FLAGS_PREFIXMATCH) { - return wsNodeStr.Left(wsNamespaceURIPrefix.GetLength()) == - wsNamespaceURIPrefix; - } - return wsNodeStr == wsNamespaceURIPrefix; -} -static FX_BOOL XFA_FDEExtension_GetAttributeLocalName( - const CFX_WideStringC& wsAttributeName, - CFX_WideString& wsLocalAttrName) { - CFX_WideString wsAttrName(wsAttributeName); - FX_STRSIZE iFind = wsAttrName.Find(L':', 0); - if (iFind < 0) { - wsLocalAttrName = wsAttrName; - return FALSE; - } else { - wsLocalAttrName = wsAttrName.Right(wsAttrName.GetLength() - iFind - 1); - return TRUE; - } -} -static FX_BOOL XFA_FDEExtension_ResolveAttribute( - CFDE_XMLElement* pElement, - const CFX_WideStringC& wsAttributeName, - CFX_WideString& wsLocalAttrName, - CFX_WideString& wsNamespaceURI) { - CFX_WideString wsAttrName(wsAttributeName); - CFX_WideString wsNSPrefix; - if (XFA_FDEExtension_GetAttributeLocalName(wsAttributeName, - wsLocalAttrName)) { - wsNSPrefix = wsAttrName.Left(wsAttributeName.GetLength() - - wsLocalAttrName.GetLength() - 1); - } - if (wsLocalAttrName == FX_WSTRC(L"xmlns") || - wsNSPrefix == FX_WSTRC(L"xmlns") || wsNSPrefix == FX_WSTRC(L"xml")) { - return FALSE; - } - if (!XFA_FDEExtension_ResolveNamespaceQualifier( - pElement, wsNSPrefix.AsStringC(), wsNamespaceURI)) { - wsNamespaceURI.clear(); - return FALSE; - } - return TRUE; -} -static FX_BOOL XFA_FDEExtension_FindAttributeWithNS( - CFDE_XMLElement* pElement, - const CFX_WideStringC& wsLocalAttributeName, - const CFX_WideStringC& wsNamespaceURIPrefix, - CFX_WideString& wsValue, - FX_BOOL bMatchNSAsPrefix = FALSE) { - if (!pElement) { - return FALSE; - } - CFX_WideString wsAttrName; - CFX_WideString wsAttrValue; - CFX_WideString wsAttrNS; - for (int32_t iAttrCount = pElement->CountAttributes(), i = 0; i < iAttrCount; - i++) { - pElement->GetAttribute(i, wsAttrName, wsAttrValue); - FX_STRSIZE iFind = wsAttrName.Find(L':', 0); - CFX_WideString wsNSPrefix; - if (iFind < 0) { - if (wsLocalAttributeName != wsAttrName) { - continue; - } - } else { - if (wsLocalAttributeName != - wsAttrName.Right(wsAttrName.GetLength() - iFind - 1)) { - continue; - } - wsNSPrefix = wsAttrName.Left(iFind); - } - if (!XFA_FDEExtension_ResolveNamespaceQualifier( - pElement, wsNSPrefix.AsStringC(), wsAttrNS)) { - continue; - } - if (bMatchNSAsPrefix) { - if (wsAttrNS.Left(wsNamespaceURIPrefix.GetLength()) != - wsNamespaceURIPrefix) { - continue; - } - } else { - if (wsAttrNS != wsNamespaceURIPrefix) { - continue; - } - } - wsValue = wsAttrValue; - return TRUE; - } - return FALSE; -} -CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket(CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID) { - switch (ePacketID) { - case XFA_XDPPACKET_UNKNOWN: - return nullptr; - case XFA_XDPPACKET_XDP: - return ParseAsXDPPacket_XDP(pXMLDocumentNode, ePacketID); - case XFA_XDPPACKET_Config: - return ParseAsXDPPacket_Config(pXMLDocumentNode, ePacketID); - case XFA_XDPPACKET_Template: - case XFA_XDPPACKET_Form: - return ParseAsXDPPacket_TemplateForm(pXMLDocumentNode, ePacketID); - case XFA_XDPPACKET_Datasets: - return ParseAsXDPPacket_Data(pXMLDocumentNode, ePacketID); - case XFA_XDPPACKET_Xdc: - return ParseAsXDPPacket_Xdc(pXMLDocumentNode, ePacketID); - case XFA_XDPPACKET_LocaleSet: - case XFA_XDPPACKET_ConnectionSet: - case XFA_XDPPACKET_SourceSet: - return ParseAsXDPPacket_LocaleConnectionSourceSet(pXMLDocumentNode, - ePacketID); - default: - return ParseAsXDPPacket_User(pXMLDocumentNode, ePacketID); - } -} -CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP( - CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID) { - if (!XFA_FDEExtension_MatchNodeName( - pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_XDP)->pName, - XFA_GetPacketByIndex(XFA_PACKET_XDP)->pURI, - XFA_GetPacketByIndex(XFA_PACKET_XDP)->eFlags)) { - return nullptr; - } - CXFA_Node* pXFARootNode = - m_pFactory->CreateNode(XFA_XDPPACKET_XDP, XFA_Element::Xfa); - if (!pXFARootNode) { - return nullptr; - } - m_pRootNode = pXFARootNode; - pXFARootNode->SetCData(XFA_ATTRIBUTE_Name, L"xfa"); - { - CFDE_XMLElement* pElement = static_cast(pXMLDocumentNode); - int32_t iAttributeCount = pElement->CountAttributes(); - for (int32_t i = 0; i < iAttributeCount; i++) { - CFX_WideString wsAttriName, wsAttriValue; - pElement->GetAttribute(i, wsAttriName, wsAttriValue); - if (wsAttriName == FX_WSTRC(L"uuid")) { - pXFARootNode->SetCData(XFA_ATTRIBUTE_Uuid, wsAttriValue); - } else if (wsAttriName == FX_WSTRC(L"timeStamp")) { - pXFARootNode->SetCData(XFA_ATTRIBUTE_TimeStamp, wsAttriValue); - } - } - } - CFDE_XMLNode* pXMLConfigDOMRoot = nullptr; - CXFA_Node* pXFAConfigDOMRoot = nullptr; - { - for (CFDE_XMLNode* pChildItem = - pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); - pChildItem; - pChildItem = pChildItem->GetNodeItem(CFDE_XMLNode::NextSibling)) { - const XFA_PACKETINFO* pPacketInfo = - XFA_GetPacketByIndex(XFA_PACKET_Config); - if (!XFA_FDEExtension_MatchNodeName(pChildItem, pPacketInfo->pName, - pPacketInfo->pURI, - pPacketInfo->eFlags)) { - continue; - } - if (pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) { - return nullptr; - } - pXMLConfigDOMRoot = pChildItem; - pXFAConfigDOMRoot = - ParseAsXDPPacket_Config(pXMLConfigDOMRoot, XFA_XDPPACKET_Config); - pXFARootNode->InsertChild(pXFAConfigDOMRoot, nullptr); - } - } - CFDE_XMLNode* pXMLDatasetsDOMRoot = nullptr; - CFDE_XMLNode* pXMLFormDOMRoot = nullptr; - CFDE_XMLNode* pXMLTemplateDOMRoot = nullptr; - { - for (CFDE_XMLNode* pChildItem = - pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); - pChildItem; - pChildItem = pChildItem->GetNodeItem(CFDE_XMLNode::NextSibling)) { - if (!pChildItem || pChildItem->GetType() != FDE_XMLNODE_Element) { - continue; - } - if (pChildItem == pXMLConfigDOMRoot) { - continue; - } - CFDE_XMLElement* pElement = - reinterpret_cast(pChildItem); - CFX_WideString wsPacketName; - pElement->GetLocalTagName(wsPacketName); - const XFA_PACKETINFO* pPacketInfo = - XFA_GetPacketByName(wsPacketName.AsStringC()); - if (pPacketInfo && pPacketInfo->pURI) { - if (!XFA_FDEExtension_MatchNodeName(pElement, pPacketInfo->pName, - pPacketInfo->pURI, - pPacketInfo->eFlags)) { - pPacketInfo = nullptr; - } - } - XFA_XDPPACKET ePacket = - pPacketInfo ? pPacketInfo->eName : XFA_XDPPACKET_USER; - if (ePacket == XFA_XDPPACKET_XDP) { - continue; - } - if (ePacket == XFA_XDPPACKET_Datasets) { - if (pXMLDatasetsDOMRoot) { - return nullptr; - } - pXMLDatasetsDOMRoot = pElement; - } else if (ePacket == XFA_XDPPACKET_Form) { - if (pXMLFormDOMRoot) { - return nullptr; - } - pXMLFormDOMRoot = pElement; - } else if (ePacket == XFA_XDPPACKET_Template) { - if (pXMLTemplateDOMRoot) { - // Found a duplicate template packet. - return nullptr; - } - CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket); - if (pPacketNode) { - pXMLTemplateDOMRoot = pElement; - pXFARootNode->InsertChild(pPacketNode); - } - } else { - CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket); - if (pPacketNode) { - if (pPacketInfo && - (pPacketInfo->eFlags & XFA_XDPPACKET_FLAGS_SUPPORTONE) && - pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) { - return nullptr; - } - pXFARootNode->InsertChild(pPacketNode); - } - } - } - } - if (!pXMLTemplateDOMRoot) { - // No template is found. - return nullptr; - } - if (pXMLDatasetsDOMRoot) { - CXFA_Node* pPacketNode = - ParseAsXDPPacket(pXMLDatasetsDOMRoot, XFA_XDPPACKET_Datasets); - if (pPacketNode) { - pXFARootNode->InsertChild(pPacketNode); - } - } - if (pXMLFormDOMRoot) { - CXFA_Node* pPacketNode = - ParseAsXDPPacket(pXMLFormDOMRoot, XFA_XDPPACKET_Form); - if (pPacketNode) { - pXFARootNode->InsertChild(pPacketNode); - } - } - pXFARootNode->SetXMLMappingNode(pXMLDocumentNode); - return pXFARootNode; -} -CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Config( - CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID) { - if (!XFA_FDEExtension_MatchNodeName( - pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Config)->pName, - XFA_GetPacketByIndex(XFA_PACKET_Config)->pURI, - XFA_GetPacketByIndex(XFA_PACKET_Config)->eFlags)) { - return nullptr; - } - CXFA_Node* pNode = - m_pFactory->CreateNode(XFA_XDPPACKET_Config, XFA_Element::Config); - if (!pNode) { - return nullptr; - } - pNode->SetCData(XFA_ATTRIBUTE_Name, - XFA_GetPacketByIndex(XFA_PACKET_Config)->pName); - if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { - return nullptr; - } - pNode->SetXMLMappingNode(pXMLDocumentNode); - return pNode; -} -CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm( - CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID) { - CXFA_Node* pNode = nullptr; - if (ePacketID == XFA_XDPPACKET_Template) { - if (XFA_FDEExtension_MatchNodeName( - pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Template)->pName, - XFA_GetPacketByIndex(XFA_PACKET_Template)->pURI, - XFA_GetPacketByIndex(XFA_PACKET_Template)->eFlags)) { - pNode = - m_pFactory->CreateNode(XFA_XDPPACKET_Template, XFA_Element::Template); - if (!pNode) { - return nullptr; - } - pNode->SetCData(XFA_ATTRIBUTE_Name, - XFA_GetPacketByIndex(XFA_PACKET_Template)->pName); - if (m_bDocumentParser) { - CFX_WideString wsNamespaceURI; - CFDE_XMLElement* pXMLDocumentElement = - static_cast(pXMLDocumentNode); - pXMLDocumentElement->GetNamespaceURI(wsNamespaceURI); - if (wsNamespaceURI.IsEmpty()) { - pXMLDocumentElement->GetString(L"xmlns:xfa", wsNamespaceURI); - } - pNode->GetDocument()->RecognizeXFAVersionNumber(wsNamespaceURI); - } - if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { - return nullptr; - } - } - } else if (ePacketID == XFA_XDPPACKET_Form) { - if (XFA_FDEExtension_MatchNodeName( - pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Form)->pName, - XFA_GetPacketByIndex(XFA_PACKET_Form)->pURI, - XFA_GetPacketByIndex(XFA_PACKET_Form)->eFlags)) { - CFDE_XMLElement* pXMLDocumentElement = - static_cast(pXMLDocumentNode); - CFX_WideString wsChecksum; - pXMLDocumentElement->GetString(L"checksum", wsChecksum); - if (wsChecksum.GetLength() != 28 || - m_pXMLParser->m_dwCheckStatus != 0x03) { - return nullptr; - } - std::unique_ptr pChecksum(new CXFA_ChecksumContext); - pChecksum->StartChecksum(); - pChecksum->UpdateChecksum(m_pFileRead, m_pXMLParser->m_nStart[0], - m_pXMLParser->m_nSize[0]); - pChecksum->UpdateChecksum(m_pFileRead, m_pXMLParser->m_nStart[1], - m_pXMLParser->m_nSize[1]); - pChecksum->FinishChecksum(); - CFX_ByteString bsCheck = pChecksum->GetChecksum(); - if (bsCheck != wsChecksum.UTF8Encode()) - return nullptr; - - pNode = m_pFactory->CreateNode(XFA_XDPPACKET_Form, XFA_Element::Form); - if (!pNode) - return nullptr; - - pNode->SetCData(XFA_ATTRIBUTE_Name, - XFA_GetPacketByIndex(XFA_PACKET_Form)->pName); - pNode->SetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum.AsStringC()); - CXFA_Node* pTemplateRoot = - m_pRootNode->GetFirstChildByClass(XFA_Element::Template); - CXFA_Node* pTemplateChosen = - pTemplateRoot - ? pTemplateRoot->GetFirstChildByClass(XFA_Element::Subform) - : nullptr; - FX_BOOL bUseAttribute = TRUE; - if (pTemplateChosen && - pTemplateChosen->GetEnum(XFA_ATTRIBUTE_RestoreState) != - XFA_ATTRIBUTEENUM_Auto) { - bUseAttribute = FALSE; - } - if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID, bUseAttribute)) { - return nullptr; - } - } - } - if (pNode) { - pNode->SetXMLMappingNode(pXMLDocumentNode); - } - return pNode; -} -static CFDE_XMLNode* XFA_GetDataSetsFromXDP(CFDE_XMLNode* pXMLDocumentNode) { - if (XFA_FDEExtension_MatchNodeName( - pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName, - XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI, - XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) { - return pXMLDocumentNode; - } - if (!XFA_FDEExtension_MatchNodeName( - pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_XDP)->pName, - XFA_GetPacketByIndex(XFA_PACKET_XDP)->pURI, - XFA_GetPacketByIndex(XFA_PACKET_XDP)->eFlags)) { - return nullptr; - } - for (CFDE_XMLNode* pDatasetsNode = - pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); - pDatasetsNode; - pDatasetsNode = pDatasetsNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { - if (!XFA_FDEExtension_MatchNodeName( - pDatasetsNode, XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName, - XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI, - XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) { - continue; - } - return pDatasetsNode; - } - return nullptr; -} -CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Data( - CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID) { - CFDE_XMLNode* pDatasetsXMLNode = XFA_GetDataSetsFromXDP(pXMLDocumentNode); - if (pDatasetsXMLNode) { - CXFA_Node* pNode = - m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, XFA_Element::DataModel); - if (!pNode) { - return nullptr; - } - pNode->SetCData(XFA_ATTRIBUTE_Name, - XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName); - if (!DataLoader(pNode, pDatasetsXMLNode, FALSE)) { - return nullptr; - } - pNode->SetXMLMappingNode(pDatasetsXMLNode); - return pNode; - } - CFDE_XMLNode* pDataXMLNode = nullptr; - if (XFA_FDEExtension_MatchNodeName( - pXMLDocumentNode, FX_WSTRC(L"data"), - XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI, - XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) { - static_cast(pXMLDocumentNode) - ->RemoveAttribute(L"xmlns:xfa"); - pDataXMLNode = pXMLDocumentNode; - } else { - CFDE_XMLElement* pDataElement = new CFDE_XMLElement(L"xfa:data"); - CFDE_XMLNode* pParentXMLNode = - pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::Parent); - if (pParentXMLNode) { - pParentXMLNode->RemoveChildNode(pXMLDocumentNode); - } - ASSERT(pXMLDocumentNode->GetType() == FDE_XMLNODE_Element); - if (pXMLDocumentNode->GetType() == FDE_XMLNODE_Element) { - static_cast(pXMLDocumentNode) - ->RemoveAttribute(L"xmlns:xfa"); - } - pDataElement->InsertChildNode(pXMLDocumentNode); - pDataXMLNode = pDataElement; - } - if (pDataXMLNode) { - CXFA_Node* pNode = - m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, XFA_Element::DataGroup); - if (!pNode) { - if (pDataXMLNode != pXMLDocumentNode) { - pDataXMLNode->Release(); - } - return nullptr; - } - CFX_WideString wsLocalName; - static_cast(pDataXMLNode)->GetLocalTagName(wsLocalName); - pNode->SetCData(XFA_ATTRIBUTE_Name, wsLocalName); - if (!DataLoader(pNode, pDataXMLNode, TRUE)) { - return nullptr; - } - pNode->SetXMLMappingNode(pDataXMLNode); - if (pDataXMLNode != pXMLDocumentNode) { - pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false); - } - return pNode; - } - return nullptr; -} -CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_LocaleConnectionSourceSet( - CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID) { - CXFA_Node* pNode = nullptr; - if (ePacketID == XFA_XDPPACKET_LocaleSet) { - if (XFA_FDEExtension_MatchNodeName( - pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pName, - XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pURI, - XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->eFlags)) { - pNode = m_pFactory->CreateNode(XFA_XDPPACKET_LocaleSet, - XFA_Element::LocaleSet); - if (!pNode) { - return nullptr; - } - pNode->SetCData(XFA_ATTRIBUTE_Name, - XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pName); - if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { - return nullptr; - } - } - } else if (ePacketID == XFA_XDPPACKET_ConnectionSet) { - if (XFA_FDEExtension_MatchNodeName( - pXMLDocumentNode, - XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pName, - XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pURI, - XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->eFlags)) { - pNode = m_pFactory->CreateNode(XFA_XDPPACKET_ConnectionSet, - XFA_Element::ConnectionSet); - if (!pNode) { - return nullptr; - } - pNode->SetCData(XFA_ATTRIBUTE_Name, - XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pName); - if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { - return nullptr; - } - } - } else if (ePacketID == XFA_XDPPACKET_SourceSet) { - if (XFA_FDEExtension_MatchNodeName( - pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pName, - XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pURI, - XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->eFlags)) { - pNode = m_pFactory->CreateNode(XFA_XDPPACKET_SourceSet, - XFA_Element::SourceSet); - if (!pNode) { - return nullptr; - } - pNode->SetCData(XFA_ATTRIBUTE_Name, - XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pName); - if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { - return nullptr; - } - } - } - if (pNode) { - pNode->SetXMLMappingNode(pXMLDocumentNode); - } - return pNode; -} -CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Xdc( - CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID) { - if (XFA_FDEExtension_MatchNodeName( - pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pName, - XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pURI, - XFA_GetPacketByIndex(XFA_PACKET_Xdc)->eFlags)) { - CXFA_Node* pNode = - m_pFactory->CreateNode(XFA_XDPPACKET_Xdc, XFA_Element::Xdc); - if (!pNode) { - return nullptr; - } - pNode->SetCData(XFA_ATTRIBUTE_Name, - XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pName); - pNode->SetXMLMappingNode(pXMLDocumentNode); - return pNode; - } - return nullptr; -} -CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_User( - CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID) { - CXFA_Node* pNode = - m_pFactory->CreateNode(XFA_XDPPACKET_XDP, XFA_Element::Packet); - if (!pNode) { - return nullptr; - } - CFX_WideString wsName; - static_cast(pXMLDocumentNode)->GetLocalTagName(wsName); - pNode->SetCData(XFA_ATTRIBUTE_Name, wsName); - if (!UserPacketLoader(pNode, pXMLDocumentNode)) { - return nullptr; - } - pNode->SetXMLMappingNode(pXMLDocumentNode); - return pNode; -} -CXFA_Node* CXFA_SimpleParser::UserPacketLoader(CXFA_Node* pXFANode, - CFDE_XMLNode* pXMLDoc) { - return pXFANode; -} -static FX_BOOL XFA_FDEExtension_IsStringAllWhitespace(CFX_WideString wsText) { - wsText.TrimRight(L"\x20\x9\xD\xA"); - return wsText.IsEmpty(); -} -CXFA_Node* CXFA_SimpleParser::DataLoader(CXFA_Node* pXFANode, - CFDE_XMLNode* pXMLDoc, - FX_BOOL bDoTransform) { - ParseDataGroup(pXFANode, pXMLDoc, XFA_XDPPACKET_Datasets); - return pXFANode; -} -CXFA_Node* CXFA_SimpleParser::NormalLoader(CXFA_Node* pXFANode, - CFDE_XMLNode* pXMLDoc, - XFA_XDPPACKET ePacketID, - FX_BOOL bUseAttribute) { - FX_BOOL bOneOfPropertyFound = FALSE; - for (CFDE_XMLNode* pXMLChild = pXMLDoc->GetNodeItem(CFDE_XMLNode::FirstChild); - pXMLChild; - pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { - switch (pXMLChild->GetType()) { - case FDE_XMLNODE_Element: { - CFDE_XMLElement* pXMLElement = static_cast(pXMLChild); - CFX_WideString wsTagName; - pXMLElement->GetLocalTagName(wsTagName); - XFA_Element eType = XFA_GetElementTypeForName(wsTagName.AsStringC()); - if (eType == XFA_Element::Unknown) - continue; - - const XFA_PROPERTY* pPropertyInfo = XFA_GetPropertyOfElement( - pXFANode->GetElementType(), eType, ePacketID); - if (pPropertyInfo && - ((pPropertyInfo->uFlags & - (XFA_PROPERTYFLAG_OneOf | XFA_PROPERTYFLAG_DefaultOneOf)) != 0)) { - if (bOneOfPropertyFound) { - break; - } - bOneOfPropertyFound = TRUE; - } - CXFA_Node* pXFAChild = m_pFactory->CreateNode(ePacketID, eType); - if (!pXFAChild) - return nullptr; - if (ePacketID == XFA_XDPPACKET_Config) - pXFAChild->SetAttribute(XFA_ATTRIBUTE_Name, wsTagName.AsStringC()); - - FX_BOOL IsNeedValue = TRUE; - for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count; - i++) { - CFX_WideString wsAttrQualifiedName; - CFX_WideString wsAttrName; - CFX_WideString wsAttrValue; - pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue); - XFA_FDEExtension_GetAttributeLocalName( - wsAttrQualifiedName.AsStringC(), wsAttrName); - if (wsAttrName == FX_WSTRC(L"nil") && - wsAttrValue == FX_WSTRC(L"true")) { - IsNeedValue = FALSE; - } - const XFA_ATTRIBUTEINFO* lpAttrInfo = - XFA_GetAttributeByName(wsAttrName.AsStringC()); - if (!lpAttrInfo) { - continue; - } - if (!bUseAttribute && lpAttrInfo->eName != XFA_ATTRIBUTE_Name && - lpAttrInfo->eName != XFA_ATTRIBUTE_Save) { - continue; - } - pXFAChild->SetAttribute(lpAttrInfo->eName, wsAttrValue.AsStringC()); - } - pXFANode->InsertChild(pXFAChild); - if (eType == XFA_Element::Validate || eType == XFA_Element::Locale) { - if (ePacketID == XFA_XDPPACKET_Config) { - ParseContentNode(pXFAChild, pXMLElement, ePacketID); - } else { - NormalLoader(pXFAChild, pXMLElement, ePacketID, bUseAttribute); - } - break; - } - switch (pXFAChild->GetObjectType()) { - case XFA_ObjectType::ContentNode: - case XFA_ObjectType::TextNode: - case XFA_ObjectType::NodeC: - case XFA_ObjectType::NodeV: - if (IsNeedValue) { - ParseContentNode(pXFAChild, pXMLElement, ePacketID); - } - break; - default: - NormalLoader(pXFAChild, pXMLElement, ePacketID, bUseAttribute); - break; - } - } break; - case FDE_XMLNODE_Instruction: - ParseInstruction(pXFANode, static_cast(pXMLChild), - ePacketID); - break; - default: - break; - } - } - return pXFANode; -} -FX_BOOL XFA_RecognizeRichText(CFDE_XMLElement* pRichTextXMLNode) { - if (pRichTextXMLNode) { - CFX_WideString wsNamespaceURI; - XFA_FDEExtension_GetElementTagNamespaceURI(pRichTextXMLNode, - wsNamespaceURI); - if (wsNamespaceURI == FX_WSTRC(L"http://www.w3.org/1999/xhtml")) { - return TRUE; - } - } - return FALSE; -} -class RichTextNodeVisitor { - public: - static inline CFDE_XMLNode* GetFirstChild(CFDE_XMLNode* pNode) { - return pNode->GetNodeItem(CFDE_XMLNode::FirstChild); - } - static inline CFDE_XMLNode* GetNextSibling(CFDE_XMLNode* pNode) { - return pNode->GetNodeItem(CFDE_XMLNode::NextSibling); - } - static inline CFDE_XMLNode* GetParent(CFDE_XMLNode* pNode) { - return pNode->GetNodeItem(CFDE_XMLNode::Parent); - } -}; - -void XFA_ConvertXMLToPlainText(CFDE_XMLElement* pRootXMLNode, - CFX_WideString& wsOutput) { - for (CFDE_XMLNode* pXMLChild = - pRootXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); - pXMLChild; - pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { - switch (pXMLChild->GetType()) { - case FDE_XMLNODE_Element: { - CFX_WideString wsTextData; - static_cast(pXMLChild)->GetTextData(wsTextData); - wsTextData += FX_WSTRC(L"\n"); - wsOutput += wsTextData; - } break; - case FDE_XMLNODE_Text: { - CFX_WideString wsText; - static_cast(pXMLChild)->GetText(wsText); - if (XFA_FDEExtension_IsStringAllWhitespace(wsText)) { - continue; - } else { - wsOutput = wsText; - } - } break; - case FDE_XMLNODE_CharData: { - CFX_WideString wsCharData; - static_cast(pXMLChild)->GetCharData(wsCharData); - if (XFA_FDEExtension_IsStringAllWhitespace(wsCharData)) { - continue; - } else { - wsOutput = wsCharData; - } - } break; - default: - ASSERT(FALSE); - break; - } - } -} - -void CXFA_SimpleParser::ParseContentNode(CXFA_Node* pXFANode, - CFDE_XMLNode* pXMLNode, - XFA_XDPPACKET ePacketID) { - XFA_Element element = XFA_Element::Sharptext; - if (pXFANode->GetElementType() == XFA_Element::ExData) { - CFX_WideStringC wsContentType = - pXFANode->GetCData(XFA_ATTRIBUTE_ContentType); - if (wsContentType == FX_WSTRC(L"text/html")) - element = XFA_Element::SharpxHTML; - else if (wsContentType == FX_WSTRC(L"text/xml")) - element = XFA_Element::Sharpxml; - } - if (element == XFA_Element::SharpxHTML) - pXFANode->SetXMLMappingNode(pXMLNode); - - CFX_WideString wsValue; - for (CFDE_XMLNode* pXMLChild = - pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); - pXMLChild; - pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { - FDE_XMLNODETYPE eNodeType = pXMLChild->GetType(); - if (eNodeType == FDE_XMLNODE_Instruction) - continue; - - if (element == XFA_Element::SharpxHTML) { - if (eNodeType != FDE_XMLNODE_Element) - break; - - if (XFA_RecognizeRichText(static_cast(pXMLChild))) - XFA_GetPlainTextFromRichText(static_cast(pXMLChild), - wsValue); - } else if (element == XFA_Element::Sharpxml) { - if (eNodeType != FDE_XMLNODE_Element) - break; - XFA_ConvertXMLToPlainText(static_cast(pXMLChild), - wsValue); - } else { - if (eNodeType == FDE_XMLNODE_Element) - break; - if (eNodeType == FDE_XMLNODE_Text) - static_cast(pXMLChild)->GetText(wsValue); - else if (eNodeType == FDE_XMLNODE_CharData) - static_cast(pXMLChild)->GetCharData(wsValue); - } - break; - } - if (!wsValue.IsEmpty()) { - if (pXFANode->IsContentNode()) { - CXFA_Node* pContentRawDataNode = - m_pFactory->CreateNode(ePacketID, element); - ASSERT(pContentRawDataNode); - pContentRawDataNode->SetCData(XFA_ATTRIBUTE_Value, wsValue); - pXFANode->InsertChild(pContentRawDataNode); - } else { - pXFANode->SetCData(XFA_ATTRIBUTE_Value, wsValue); - } - } -} - -void CXFA_SimpleParser::ParseDataGroup(CXFA_Node* pXFANode, - CFDE_XMLNode* pXMLNode, - XFA_XDPPACKET ePacketID) { - for (CFDE_XMLNode* pXMLChild = - pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); - pXMLChild; - pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { - switch (pXMLChild->GetType()) { - case FDE_XMLNODE_Element: { - CFDE_XMLElement* pXMLElement = static_cast(pXMLChild); - { - CFX_WideString wsNamespaceURI; - XFA_FDEExtension_GetElementTagNamespaceURI(pXMLElement, - wsNamespaceURI); - if (wsNamespaceURI == - FX_WSTRC(L"http://www.xfa.com/schema/xfa-package/") || - wsNamespaceURI == - FX_WSTRC(L"http://www.xfa.org/schema/xfa-package/") || - wsNamespaceURI == - FX_WSTRC(L"http://www.w3.org/2001/XMLSchema-instance")) { - continue; - } - } - XFA_Element eNodeType = XFA_Element::DataModel; - if (eNodeType == XFA_Element::DataModel) { - CFX_WideString wsDataNodeAttr; - if (XFA_FDEExtension_FindAttributeWithNS( - pXMLElement, FX_WSTRC(L"dataNode"), - FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/"), - wsDataNodeAttr)) { - if (wsDataNodeAttr == FX_WSTRC(L"dataGroup")) { - eNodeType = XFA_Element::DataGroup; - } else if (wsDataNodeAttr == FX_WSTRC(L"dataValue")) { - eNodeType = XFA_Element::DataValue; - } - } - } - CFX_WideString wsContentType; - if (eNodeType == XFA_Element::DataModel) { - if (XFA_FDEExtension_FindAttributeWithNS( - pXMLElement, FX_WSTRC(L"contentType"), - FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/"), - wsContentType)) { - if (!wsContentType.IsEmpty()) { - eNodeType = XFA_Element::DataValue; - } - } - } - if (eNodeType == XFA_Element::DataModel) { - for (CFDE_XMLNode* pXMLDataChild = - pXMLElement->GetNodeItem(CFDE_XMLNode::FirstChild); - pXMLDataChild; pXMLDataChild = pXMLDataChild->GetNodeItem( - CFDE_XMLNode::NextSibling)) { - if (pXMLDataChild->GetType() == FDE_XMLNODE_Element) { - if (!XFA_RecognizeRichText( - static_cast(pXMLDataChild))) { - eNodeType = XFA_Element::DataGroup; - break; - } - } - } - } - if (eNodeType == XFA_Element::DataModel) { - eNodeType = XFA_Element::DataValue; - } - CXFA_Node* pXFAChild = - m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, eNodeType); - if (!pXFAChild) { - return; - } - CFX_WideString wsNodeName; - pXMLElement->GetLocalTagName(wsNodeName); - pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeName); - bool bNeedValue = true; - for (int32_t i = 0; i < pXMLElement->CountAttributes(); ++i) { - CFX_WideString wsQualifiedName; - CFX_WideString wsValue; - CFX_WideString wsName; - CFX_WideString wsNS; - pXMLElement->GetAttribute(i, wsQualifiedName, wsValue); - if (!XFA_FDEExtension_ResolveAttribute( - pXMLElement, wsQualifiedName.AsStringC(), wsName, wsNS)) { - continue; - } - if (wsName == FX_WSTRC(L"nil") && wsValue == FX_WSTRC(L"true")) { - bNeedValue = false; - continue; - } - if (wsNS == FX_WSTRC(L"http://www.xfa.com/schema/xfa-package/") || - wsNS == FX_WSTRC(L"http://www.xfa.org/schema/xfa-package/") || - wsNS == FX_WSTRC(L"http://www.w3.org/2001/XMLSchema-instance") || - wsNS == FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/")) { - continue; - } - CXFA_Node* pXFAMetaData = m_pFactory->CreateNode( - XFA_XDPPACKET_Datasets, XFA_Element::DataValue); - if (!pXFAMetaData) { - return; - } - pXFAMetaData->SetCData(XFA_ATTRIBUTE_Name, wsName); - pXFAMetaData->SetCData(XFA_ATTRIBUTE_QualifiedName, wsQualifiedName); - pXFAMetaData->SetCData(XFA_ATTRIBUTE_Value, wsValue); - pXFAMetaData->SetEnum(XFA_ATTRIBUTE_Contains, - XFA_ATTRIBUTEENUM_MetaData); - pXFAChild->InsertChild(pXFAMetaData); - pXFAMetaData->SetXMLMappingNode(pXMLElement); - pXFAMetaData->SetFlag(XFA_NodeFlag_Initialized, false); - } - if (!bNeedValue) { - CFX_WideString wsNilName(L"xsi:nil"); - pXMLElement->RemoveAttribute(wsNilName.c_str()); - } - pXFANode->InsertChild(pXFAChild); - if (eNodeType == XFA_Element::DataGroup) { - ParseDataGroup(pXFAChild, pXMLElement, ePacketID); - } else if (bNeedValue) { - ParseDataValue(pXFAChild, pXMLChild, XFA_XDPPACKET_Datasets); - } - pXFAChild->SetXMLMappingNode(pXMLElement); - pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); - continue; - } - case FDE_XMLNODE_CharData: { - CFDE_XMLCharData* pXMLCharData = - static_cast(pXMLChild); - CFX_WideString wsCharData; - pXMLCharData->GetCharData(wsCharData); - if (XFA_FDEExtension_IsStringAllWhitespace(wsCharData)) { - continue; - } - CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, - XFA_Element::DataValue); - if (!pXFAChild) { - return; - } - pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCharData); - pXFANode->InsertChild(pXFAChild); - pXFAChild->SetXMLMappingNode(pXMLCharData); - pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); - continue; - } - case FDE_XMLNODE_Text: { - CFDE_XMLText* pXMLText = static_cast(pXMLChild); - CFX_WideString wsText; - pXMLText->GetText(wsText); - if (XFA_FDEExtension_IsStringAllWhitespace(wsText)) { - continue; - } - CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, - XFA_Element::DataValue); - if (!pXFAChild) { - return; - } - pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsText); - pXFANode->InsertChild(pXFAChild); - pXFAChild->SetXMLMappingNode(pXMLText); - pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); - continue; - } - default: - continue; - } - } -} - -void CXFA_SimpleParser::ParseDataValue(CXFA_Node* pXFANode, - CFDE_XMLNode* pXMLNode, - XFA_XDPPACKET ePacketID) { - CFX_WideTextBuf wsValueTextBuf; - CFX_WideTextBuf wsCurValueTextBuf; - FX_BOOL bMarkAsCompound = FALSE; - CFDE_XMLNode* pXMLCurValueNode = nullptr; - for (CFDE_XMLNode* pXMLChild = - pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); - pXMLChild; - pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { - FDE_XMLNODETYPE eNodeType = pXMLChild->GetType(); - if (eNodeType == FDE_XMLNODE_Instruction) - continue; - - CFX_WideString wsText; - if (eNodeType == FDE_XMLNODE_Text) { - static_cast(pXMLChild)->GetText(wsText); - if (!pXMLCurValueNode) - pXMLCurValueNode = pXMLChild; - - wsCurValueTextBuf << wsText; - } else if (eNodeType == FDE_XMLNODE_CharData) { - static_cast(pXMLChild)->GetCharData(wsText); - if (!pXMLCurValueNode) - pXMLCurValueNode = pXMLChild; - - wsCurValueTextBuf << wsText; - } else if (XFA_RecognizeRichText( - static_cast(pXMLChild))) { - XFA_GetPlainTextFromRichText(static_cast(pXMLChild), - wsText); - if (!pXMLCurValueNode) - pXMLCurValueNode = pXMLChild; - - wsCurValueTextBuf << wsText; - } else { - bMarkAsCompound = TRUE; - if (pXMLCurValueNode) { - CFX_WideString wsCurValue = wsCurValueTextBuf.MakeString(); - if (!wsCurValue.IsEmpty()) { - CXFA_Node* pXFAChild = - m_pFactory->CreateNode(ePacketID, XFA_Element::DataValue); - if (!pXFAChild) - return; - - pXFAChild->SetCData(XFA_ATTRIBUTE_Name, L""); - pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCurValue); - pXFANode->InsertChild(pXFAChild); - pXFAChild->SetXMLMappingNode(pXMLCurValueNode); - pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); - wsValueTextBuf << wsCurValue; - wsCurValueTextBuf.Clear(); - } - pXMLCurValueNode = nullptr; - } - CXFA_Node* pXFAChild = - m_pFactory->CreateNode(ePacketID, XFA_Element::DataValue); - if (!pXFAChild) - return; - - CFX_WideString wsNodeStr; - static_cast(pXMLChild)->GetLocalTagName(wsNodeStr); - pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr); - ParseDataValue(pXFAChild, pXMLChild, ePacketID); - pXFANode->InsertChild(pXFAChild); - pXFAChild->SetXMLMappingNode(pXMLChild); - pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); - CFX_WideStringC wsCurValue = pXFAChild->GetCData(XFA_ATTRIBUTE_Value); - wsValueTextBuf << wsCurValue; - } - } - if (pXMLCurValueNode) { - CFX_WideString wsCurValue = wsCurValueTextBuf.MakeString(); - if (!wsCurValue.IsEmpty()) { - if (bMarkAsCompound) { - CXFA_Node* pXFAChild = - m_pFactory->CreateNode(ePacketID, XFA_Element::DataValue); - if (!pXFAChild) - return; - - pXFAChild->SetCData(XFA_ATTRIBUTE_Name, L""); - pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCurValue); - pXFANode->InsertChild(pXFAChild); - pXFAChild->SetXMLMappingNode(pXMLCurValueNode); - pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); - } - wsValueTextBuf << wsCurValue; - wsCurValueTextBuf.Clear(); - } - pXMLCurValueNode = nullptr; - } - CFX_WideString wsNodeValue = wsValueTextBuf.MakeString(); - pXFANode->SetCData(XFA_ATTRIBUTE_Value, wsNodeValue); -} - -void CXFA_SimpleParser::ParseInstruction(CXFA_Node* pXFANode, - CFDE_XMLInstruction* pXMLInstruction, - XFA_XDPPACKET ePacketID) { - if (!m_bDocumentParser) { - return; - } - CFX_WideString wsTargetName; - pXMLInstruction->GetTargetName(wsTargetName); - if (wsTargetName == FX_WSTRC(L"originalXFAVersion")) { - CFX_WideString wsData; - if (pXMLInstruction->GetData(0, wsData) && - (pXFANode->GetDocument()->RecognizeXFAVersionNumber(wsData) != - XFA_VERSION_UNKNOWN)) { - wsData.clear(); - if (pXMLInstruction->GetData(1, wsData) && - wsData == FX_WSTRC(L"v2.7-scripting:1")) { - pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_Scripting, TRUE); - } - } - } else if (wsTargetName == FX_WSTRC(L"acrobat")) { - CFX_WideString wsData; - if (pXMLInstruction->GetData(0, wsData) && - wsData == FX_WSTRC(L"JavaScript")) { - if (pXMLInstruction->GetData(1, wsData) && - wsData == FX_WSTRC(L"strictScoping")) { - pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, TRUE); - } - } - } -} -void CXFA_SimpleParser::CloseParser() { - if (m_pXMLDoc) { - m_pXMLDoc->Release(); - m_pXMLDoc = nullptr; - } - if (m_pStream) { - m_pStream->Release(); - m_pStream = nullptr; - } -} - -CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify) - : m_nodeParser(nullptr, TRUE), m_pNotify(pNotify), m_pDocument(nullptr) {} - -CXFA_DocumentParser::~CXFA_DocumentParser() { - CloseParser(); -} - -int32_t CXFA_DocumentParser::StartParse(IFX_FileRead* pStream, - XFA_XDPPACKET ePacketID) { - CloseParser(); - int32_t nRetStatus = m_nodeParser.StartParse(pStream, ePacketID); - if (nRetStatus == XFA_PARSESTATUS_Ready) { - m_pDocument.reset(new CXFA_Document(this)); - m_nodeParser.SetFactory(m_pDocument.get()); - } - return nRetStatus; -} - -int32_t CXFA_DocumentParser::DoParse(IFX_Pause* pPause) { - int32_t nRetStatus = m_nodeParser.DoParse(pPause); - if (nRetStatus >= XFA_PARSESTATUS_Done) { - ASSERT(m_pDocument); - m_pDocument->SetRoot(m_nodeParser.GetRootNode()); - } - return nRetStatus; -} - -CFDE_XMLDoc* CXFA_DocumentParser::GetXMLDoc() const { - return m_nodeParser.GetXMLDoc(); -} - -CXFA_FFNotify* CXFA_DocumentParser::GetNotify() const { - return m_pNotify; -} - -CXFA_Document* CXFA_DocumentParser::GetDocument() const { - return m_pDocument.get(); -} - -void CXFA_DocumentParser::CloseParser() { - m_pDocument.reset(); - m_nodeParser.CloseParser(); -} - -CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pRoot, IFX_Stream* pStream) - : m_nElementStart(0), - m_dwCheckStatus(0), - m_dwCurrentCheckStatus(0), - m_pRoot(pRoot), - m_pStream(pStream), - m_pParser(nullptr), - m_pParent(pRoot), - m_pChild(nullptr), - m_NodeStack(16), - m_syntaxParserResult(FDE_XmlSyntaxResult::None) { - ASSERT(m_pParent && m_pStream); - m_NodeStack.Push(m_pParent); - m_pParser = new CFDE_XMLSyntaxParser; - m_pParser->Init(m_pStream, 32 * 1024, 1024 * 1024); -} - -CXFA_XMLParser::~CXFA_XMLParser() { - if (m_pParser) { - m_pParser->Release(); - } - m_NodeStack.RemoveAll(); - m_ws1.clear(); - m_ws2.clear(); -} - -void CXFA_XMLParser::Release() { - delete this; -} - -int32_t CXFA_XMLParser::DoParser(IFX_Pause* pPause) { - if (m_syntaxParserResult == FDE_XmlSyntaxResult::Error) - return -1; - if (m_syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) - return 100; - - int32_t iCount = 0; - while (TRUE) { - m_syntaxParserResult = m_pParser->DoSyntaxParse(); - switch (m_syntaxParserResult) { - case FDE_XmlSyntaxResult::InstructionOpen: - break; - case FDE_XmlSyntaxResult::InstructionClose: - if (m_pChild) { - if (m_pChild->GetType() != FDE_XMLNODE_Instruction) { - m_syntaxParserResult = FDE_XmlSyntaxResult::Error; - break; - } - } - m_pChild = m_pParent; - break; - case FDE_XmlSyntaxResult::ElementOpen: - if (m_dwCheckStatus != 0x03 && m_NodeStack.GetSize() == 2) { - m_nElementStart = m_pParser->GetCurrentPos() - 1; - } - break; - case FDE_XmlSyntaxResult::ElementBreak: - break; - case FDE_XmlSyntaxResult::ElementClose: - if (m_pChild->GetType() != FDE_XMLNODE_Element) { - m_syntaxParserResult = FDE_XmlSyntaxResult::Error; - break; - } - m_pParser->GetTagName(m_ws1); - static_cast(m_pChild)->GetTagName(m_ws2); - if (m_ws1.GetLength() > 0 && m_ws1 != m_ws2) { - m_syntaxParserResult = FDE_XmlSyntaxResult::Error; - break; - } - m_NodeStack.Pop(); - if (m_NodeStack.GetSize() < 1) { - m_syntaxParserResult = FDE_XmlSyntaxResult::Error; - break; - } else if (m_dwCurrentCheckStatus != 0 && m_NodeStack.GetSize() == 2) { - m_nSize[m_dwCurrentCheckStatus - 1] = - m_pParser->GetCurrentBinaryPos() - - m_nStart[m_dwCurrentCheckStatus - 1]; - m_dwCurrentCheckStatus = 0; - } - - m_pParent = static_cast(*m_NodeStack.GetTopElement()); - m_pChild = m_pParent; - iCount++; - break; - case FDE_XmlSyntaxResult::TargetName: - m_pParser->GetTargetName(m_ws1); - if (m_ws1 == FX_WSTRC(L"originalXFAVersion") || - m_ws1 == FX_WSTRC(L"acrobat")) { - m_pChild = new CFDE_XMLInstruction(m_ws1); - m_pParent->InsertChildNode(m_pChild); - } else { - m_pChild = nullptr; - } - m_ws1.clear(); - break; - case FDE_XmlSyntaxResult::TagName: - m_pParser->GetTagName(m_ws1); - m_pChild = new CFDE_XMLElement(m_ws1); - m_pParent->InsertChildNode(m_pChild); - m_NodeStack.Push(m_pChild); - m_pParent = m_pChild; - - if (m_dwCheckStatus != 0x03 && m_NodeStack.GetSize() == 3) { - CFX_WideString wsTag; - static_cast(m_pChild)->GetLocalTagName(wsTag); - if (wsTag == FX_WSTRC(L"template")) { - m_dwCheckStatus |= 0x01; - m_dwCurrentCheckStatus = 0x01; - m_nStart[0] = m_pParser->GetCurrentBinaryPos() - - (m_pParser->GetCurrentPos() - m_nElementStart); - } else if (wsTag == FX_WSTRC(L"datasets")) { - m_dwCheckStatus |= 0x02; - m_dwCurrentCheckStatus = 0x02; - m_nStart[1] = m_pParser->GetCurrentBinaryPos() - - (m_pParser->GetCurrentPos() - m_nElementStart); - } - } - break; - case FDE_XmlSyntaxResult::AttriName: - m_pParser->GetAttributeName(m_ws1); - break; - case FDE_XmlSyntaxResult::AttriValue: - if (m_pChild) { - m_pParser->GetAttributeName(m_ws2); - if (m_pChild->GetType() == FDE_XMLNODE_Element) { - static_cast(m_pChild)->SetString(m_ws1, m_ws2); - } - } - m_ws1.clear(); - break; - case FDE_XmlSyntaxResult::Text: - m_pParser->GetTextData(m_ws1); - m_pChild = new CFDE_XMLText(m_ws1); - m_pParent->InsertChildNode(m_pChild); - m_pChild = m_pParent; - break; - case FDE_XmlSyntaxResult::CData: - m_pParser->GetTextData(m_ws1); - m_pChild = new CFDE_XMLCharData(m_ws1); - m_pParent->InsertChildNode(m_pChild); - m_pChild = m_pParent; - break; - case FDE_XmlSyntaxResult::TargetData: - if (m_pChild) { - if (m_pChild->GetType() != FDE_XMLNODE_Instruction) { - m_syntaxParserResult = FDE_XmlSyntaxResult::Error; - break; - } - if (!m_ws1.IsEmpty()) { - static_cast(m_pChild)->AppendData(m_ws1); - } - m_pParser->GetTargetData(m_ws1); - static_cast(m_pChild)->AppendData(m_ws1); - } - m_ws1.clear(); - break; - default: - break; - } - if (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || - m_syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) { - break; - } - if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { - break; - } - } - return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || - m_NodeStack.GetSize() != 1) - ? -1 - : m_pParser->GetStatus(); -} diff --git a/xfa/fxfa/parser/xfa_parser_imp.h b/xfa/fxfa/parser/xfa_parser_imp.h deleted file mode 100644 index c10ab4dfdc..0000000000 --- a/xfa/fxfa/parser/xfa_parser_imp.h +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_PARSER_XFA_PARSER_IMP_H_ -#define XFA_FXFA_PARSER_XFA_PARSER_IMP_H_ - -#include "xfa/fde/xml/fde_xml_imp.h" -#include "xfa/fxfa/include/fxfa_basic.h" - -class CXFA_Document; -class CXFA_FFNotify; -class CXFA_Node; -class CXFA_XMLParser; - -class CXFA_SimpleParser { - public: - CXFA_SimpleParser(CXFA_Document* pFactory, bool bDocumentParser); - ~CXFA_SimpleParser(); - - int32_t StartParse(IFX_FileRead* pStream, - XFA_XDPPACKET ePacketID = XFA_XDPPACKET_XDP); - int32_t DoParse(IFX_Pause* pPause = nullptr); - int32_t ParseXMLData(const CFX_WideString& wsXML, - CFDE_XMLNode*& pXMLNode, - IFX_Pause* pPause = nullptr); - void ConstructXFANode(CXFA_Node* pXFANode, CFDE_XMLNode* pXMLNode); - CXFA_Node* GetRootNode() const; - CFDE_XMLDoc* GetXMLDoc() const; - void CloseParser(); - - protected: - CXFA_Node* ParseAsXDPPacket(CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID); - CXFA_Node* ParseAsXDPPacket_XDP(CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID); - CXFA_Node* ParseAsXDPPacket_Config(CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID); - CXFA_Node* ParseAsXDPPacket_TemplateForm(CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID); - CXFA_Node* ParseAsXDPPacket_Data(CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID); - CXFA_Node* ParseAsXDPPacket_LocaleConnectionSourceSet( - CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID); - CXFA_Node* ParseAsXDPPacket_Xdc(CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID); - CXFA_Node* ParseAsXDPPacket_User(CFDE_XMLNode* pXMLDocumentNode, - XFA_XDPPACKET ePacketID); - CXFA_Node* NormalLoader(CXFA_Node* pXFANode, - CFDE_XMLNode* pXMLDoc, - XFA_XDPPACKET ePacketID, - FX_BOOL bUseAttribute = TRUE); - CXFA_Node* DataLoader(CXFA_Node* pXFANode, - CFDE_XMLNode* pXMLDoc, - FX_BOOL bDoTransform); - CXFA_Node* UserPacketLoader(CXFA_Node* pXFANode, CFDE_XMLNode* pXMLDoc); - void ParseContentNode(CXFA_Node* pXFANode, - CFDE_XMLNode* pXMLNode, - XFA_XDPPACKET ePacketID); - void ParseDataValue(CXFA_Node* pXFANode, - CFDE_XMLNode* pXMLNode, - XFA_XDPPACKET ePacketID); - void ParseDataGroup(CXFA_Node* pXFANode, - CFDE_XMLNode* pXMLNode, - XFA_XDPPACKET ePacketID); - void ParseInstruction(CXFA_Node* pXFANode, - CFDE_XMLInstruction* pXMLInstruction, - XFA_XDPPACKET ePacketID); - void SetFactory(CXFA_Document* pFactory); - - CXFA_XMLParser* m_pXMLParser; - CFDE_XMLDoc* m_pXMLDoc; - IFX_Stream* m_pStream; - IFX_FileRead* m_pFileRead; - CXFA_Document* m_pFactory; - CXFA_Node* m_pRootNode; - XFA_XDPPACKET m_ePacketID; - FX_BOOL m_bDocumentParser; - friend class CXFA_DocumentParser; -}; - -class CXFA_DocumentParser { - public: - explicit CXFA_DocumentParser(CXFA_FFNotify* pNotify); - ~CXFA_DocumentParser(); - - int32_t StartParse(IFX_FileRead* pStream, - XFA_XDPPACKET ePacketID = XFA_XDPPACKET_XDP); - int32_t DoParse(IFX_Pause* pPause = nullptr); - - CFDE_XMLDoc* GetXMLDoc() const; - CXFA_FFNotify* GetNotify() const; - CXFA_Document* GetDocument() const; - void CloseParser(); - - protected: - CXFA_SimpleParser m_nodeParser; - CXFA_FFNotify* m_pNotify; - std::unique_ptr m_pDocument; -}; - -class CXFA_XMLParser : public CFDE_XMLParser { - public: - CXFA_XMLParser(CFDE_XMLNode* pRoot, IFX_Stream* pStream); - ~CXFA_XMLParser() override; - - // CFDE_XMLParser - void Release() override; - int32_t DoParser(IFX_Pause* pPause) override; - - FX_FILESIZE m_nStart[2]; - size_t m_nSize[2]; - FX_FILESIZE m_nElementStart; - uint16_t m_dwCheckStatus; - uint16_t m_dwCurrentCheckStatus; - - protected: - CFDE_XMLNode* m_pRoot; - IFX_Stream* m_pStream; - CFDE_XMLSyntaxParser* m_pParser; - CFDE_XMLNode* m_pParent; - CFDE_XMLNode* m_pChild; - CFX_StackTemplate m_NodeStack; - CFX_WideString m_ws1; - CFX_WideString m_ws2; - FDE_XmlSyntaxResult m_syntaxParserResult; -}; - -#endif // XFA_FXFA_PARSER_XFA_PARSER_IMP_H_ diff --git a/xfa/fxfa/parser/xfa_parser_imp_embeddertest.cpp b/xfa/fxfa/parser/xfa_parser_imp_embeddertest.cpp deleted file mode 100644 index 63fe272872..0000000000 --- a/xfa/fxfa/parser/xfa_parser_imp_embeddertest.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2015 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "testing/embedder_test.h" -#include "testing/gtest/include/gtest/gtest.h" - -class XFAParserImpEmbeddertest : public EmbedderTest {}; - -TEST_F(XFAParserImpEmbeddertest, Bug_216) { - EXPECT_TRUE(OpenDocument("bug_216.pdf")); - FPDF_PAGE page = LoadPage(0); - EXPECT_NE(nullptr, page); - UnloadPage(page); -} diff --git a/xfa/fxfa/parser/xfa_script_eventpseudomodel.cpp b/xfa/fxfa/parser/xfa_script_eventpseudomodel.cpp index a08b512591..ef724e49f2 100644 --- a/xfa/fxfa/parser/xfa_script_eventpseudomodel.cpp +++ b/xfa/fxfa/parser/xfa_script_eventpseudomodel.cpp @@ -14,7 +14,6 @@ #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" #include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_script_imp.h" #include "xfa/fxfa/parser/xfa_utils.h" diff --git a/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp b/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp index b699c1f3ca..37ed181714 100644 --- a/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp +++ b/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp @@ -13,7 +13,6 @@ #include "xfa/fxfa/parser/xfa_document_layout_imp.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" #include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_script_imp.h" #include "xfa/fxfa/parser/xfa_utils.h" diff --git a/xfa/fxfa/parser/xfa_script_layoutpseudomodel.cpp b/xfa/fxfa/parser/xfa_script_layoutpseudomodel.cpp index 5b24e3ae2e..3567a5a138 100644 --- a/xfa/fxfa/parser/xfa_script_layoutpseudomodel.cpp +++ b/xfa/fxfa/parser/xfa_script_layoutpseudomodel.cpp @@ -17,7 +17,6 @@ #include "xfa/fxfa/parser/xfa_layout_appadapter.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" #include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_script_imp.h" #include "xfa/fxfa/parser/xfa_utils.h" diff --git a/xfa/fxfa/parser/xfa_script_signaturepseudomodel.cpp b/xfa/fxfa/parser/xfa_script_signaturepseudomodel.cpp index c328396e79..45c0f7c0d0 100644 --- a/xfa/fxfa/parser/xfa_script_signaturepseudomodel.cpp +++ b/xfa/fxfa/parser/xfa_script_signaturepseudomodel.cpp @@ -12,7 +12,6 @@ #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_parser_imp.h" #include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_script_imp.h" #include "xfa/fxfa/parser/xfa_utils.h" -- cgit v1.2.3