summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-03-30 16:49:42 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-03-30 21:15:09 +0000
commitbd9237eb346946b0caa291504c3a5f54e9b1bb3f (patch)
tree0836e4e33080823c4562390ada7c57004fefc5c6 /xfa/fxfa/parser
parent574b574064af5ec0dabf8d49d98d25af6c5d5925 (diff)
downloadpdfium-bd9237eb346946b0caa291504c3a5f54e9b1bb3f.tar.xz
Move CXFA_XMLParser to CFDE_XMLParser
There is nothing XFA specific in the CXFA_XMLParser. This Cl moves it to the CFDE_XMLParser and co-locates with the other XML code. Change-Id: I86c12da3f6f5732be54b8019562978f88234e2fc Reviewed-on: https://pdfium-review.googlesource.com/3432 Reviewed-by: Nicolás Peña <npm@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/cxfa_simple_parser.cpp6
-rw-r--r--xfa/fxfa/parser/cxfa_simple_parser.h4
-rw-r--r--xfa/fxfa/parser/cxfa_xml_parser.cpp167
-rw-r--r--xfa/fxfa/parser/cxfa_xml_parser.h44
4 files changed, 5 insertions, 216 deletions
diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp
index 574ef3a458..9204660388 100644
--- a/xfa/fxfa/parser/cxfa_simple_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp
@@ -11,12 +11,12 @@
#include "core/fxcrt/cfx_checksumcontext.h"
#include "core/fxcrt/fx_ext.h"
#include "third_party/base/ptr_util.h"
+#include "xfa/fde/xml/cfde_xml_parser.h"
#include "xfa/fgas/crt/fgas_codepage.h"
#include "xfa/fxfa/fxfa.h"
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/cxfa_node.h"
#include "xfa/fxfa/parser/cxfa_widetextread.h"
-#include "xfa/fxfa/parser/cxfa_xml_parser.h"
#include "xfa/fxfa/parser/xfa_basic_data.h"
#include "xfa/fxfa/parser/xfa_utils.h"
@@ -298,7 +298,7 @@ int32_t CXFA_SimpleParser::StartParse(
}
m_pXMLDoc = pdfium::MakeUnique<CFDE_XMLDoc>();
auto pNewParser =
- pdfium::MakeUnique<CXFA_XMLParser>(m_pXMLDoc->GetRoot(), m_pStream);
+ pdfium::MakeUnique<CFDE_XMLParser>(m_pXMLDoc->GetRoot(), m_pStream);
m_pXMLParser = pNewParser.get();
if (!m_pXMLDoc->LoadXML(std::move(pNewParser)))
return XFA_PARSESTATUS_StatusErr;
@@ -334,7 +334,7 @@ int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML,
m_pXMLDoc = pdfium::MakeUnique<CFDE_XMLDoc>();
auto pStream = pdfium::MakeRetain<CXFA_WideTextRead>(wsXML);
auto pParser =
- pdfium::MakeUnique<CXFA_XMLParser>(m_pXMLDoc->GetRoot(), pStream);
+ pdfium::MakeUnique<CFDE_XMLParser>(m_pXMLDoc->GetRoot(), pStream);
pParser->m_dwCheckStatus = 0x03;
if (!m_pXMLDoc->LoadXML(std::move(pParser)))
return XFA_PARSESTATUS_StatusErr;
diff --git a/xfa/fxfa/parser/cxfa_simple_parser.h b/xfa/fxfa/parser/cxfa_simple_parser.h
index 5f61ad7d28..350104161c 100644
--- a/xfa/fxfa/parser/cxfa_simple_parser.h
+++ b/xfa/fxfa/parser/cxfa_simple_parser.h
@@ -14,7 +14,7 @@
class CXFA_Document;
class CXFA_Node;
-class CXFA_XMLParser;
+class CFDE_XMLParser;
class IFX_SeekableReadStream;
class IFX_Pause;
class IFGAS_Stream;
@@ -76,7 +76,7 @@ class CXFA_SimpleParser {
CFDE_XMLInstruction* pXMLInstruction,
XFA_XDPPACKET ePacketID);
- CXFA_XMLParser* m_pXMLParser;
+ CFDE_XMLParser* m_pXMLParser;
std::unique_ptr<CFDE_XMLDoc> m_pXMLDoc;
CFX_RetainPtr<IFGAS_Stream> m_pStream;
CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead;
diff --git a/xfa/fxfa/parser/cxfa_xml_parser.cpp b/xfa/fxfa/parser/cxfa_xml_parser.cpp
deleted file mode 100644
index 72564d9fe5..0000000000
--- a/xfa/fxfa/parser/cxfa_xml_parser.cpp
+++ /dev/null
@@ -1,167 +0,0 @@
-// 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"
-
-#include "third_party/base/ptr_util.h"
-
-CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pParent,
- const CFX_RetainPtr<IFGAS_Stream>& pStream)
- : m_nElementStart(0),
- m_dwCheckStatus(0),
- m_dwCurrentCheckStatus(0),
- m_pStream(pStream),
- m_pParser(pdfium::MakeUnique<CFDE_XMLSyntaxParser>()),
- m_pParent(pParent),
- m_pChild(nullptr),
- 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() {}
-
-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.size() == 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<CFDE_XMLElement*>(m_pChild)->GetTagName(m_ws2);
- if (m_ws1.GetLength() > 0 && m_ws1 != m_ws2) {
- m_syntaxParserResult = FDE_XmlSyntaxResult::Error;
- break;
- }
- if (!m_NodeStack.empty())
- m_NodeStack.pop();
- if (m_NodeStack.empty()) {
- m_syntaxParserResult = FDE_XmlSyntaxResult::Error;
- break;
- } else if (m_dwCurrentCheckStatus != 0 && m_NodeStack.size() == 2) {
- m_nSize[m_dwCurrentCheckStatus - 1] =
- m_pParser->GetCurrentBinaryPos() -
- m_nStart[m_dwCurrentCheckStatus - 1];
- m_dwCurrentCheckStatus = 0;
- }
- m_pParent = m_NodeStack.top();
- m_pChild = m_pParent;
- iCount++;
- break;
- case FDE_XmlSyntaxResult::TargetName:
- m_pParser->GetTargetName(m_ws1);
- if (m_ws1 == L"originalXFAVersion" || m_ws1 == 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.size() == 3) {
- CFX_WideString wsTag;
- static_cast<CFDE_XMLElement*>(m_pChild)->GetLocalTagName(wsTag);
- if (wsTag == L"template") {
- m_dwCheckStatus |= 0x01;
- m_dwCurrentCheckStatus = 0x01;
- m_nStart[0] = m_pParser->GetCurrentBinaryPos() -
- (m_pParser->GetCurrentPos() - m_nElementStart);
- } else if (wsTag == 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<CFDE_XMLElement*>(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<CFDE_XMLInstruction*>(m_pChild)->AppendData(m_ws1);
- }
- m_pParser->GetTargetData(m_ws1);
- static_cast<CFDE_XMLInstruction*>(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.size() != 1)
- ? -1
- : m_pParser->GetStatus();
-}
diff --git a/xfa/fxfa/parser/cxfa_xml_parser.h b/xfa/fxfa/parser/cxfa_xml_parser.h
deleted file mode 100644
index a631df02dc..0000000000
--- a/xfa/fxfa/parser/cxfa_xml_parser.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// 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 <memory>
-#include <stack>
-
-#include "xfa/fde/xml/fde_xml_imp.h"
-
-class IFGAS_Stream;
-class IFX_Pause;
-
-class CXFA_XMLParser : public IFDE_XMLParser {
- public:
- CXFA_XMLParser(CFDE_XMLNode* pParent,
- const CFX_RetainPtr<IFGAS_Stream>& pStream);
- ~CXFA_XMLParser() override;
-
- // IFDE_XMLParser
- 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;
-
- private:
- CFX_RetainPtr<IFGAS_Stream> m_pStream;
- std::unique_ptr<CFDE_XMLSyntaxParser> m_pParser;
- CFDE_XMLNode* m_pParent;
- CFDE_XMLNode* m_pChild;
- std::stack<CFDE_XMLNode*> m_NodeStack;
- CFX_WideString m_ws1;
- CFX_WideString m_ws2;
- FDE_XmlSyntaxResult m_syntaxParserResult;
-};
-
-#endif // XFA_FXFA_PARSER_CXFA_XML_PARSER_H_