Home | History | Annotate | Download | only in parser
      1 // Copyright 2016 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #include "xfa/fxfa/parser/cxfa_document_parser.h"
      8 
      9 #include "core/fxcrt/xml/cfx_xmldoc.h"
     10 #include "third_party/base/ptr_util.h"
     11 #include "xfa/fxfa/fxfa.h"
     12 #include "xfa/fxfa/parser/cxfa_document.h"
     13 
     14 CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify)
     15     : m_pNotify(pNotify) {}
     16 
     17 CXFA_DocumentParser::~CXFA_DocumentParser() {
     18 }
     19 
     20 int32_t CXFA_DocumentParser::StartParse(
     21     const RetainPtr<IFX_SeekableStream>& pStream,
     22     XFA_PacketType ePacketID) {
     23   m_pDocument.reset();
     24   m_nodeParser.CloseParser();
     25 
     26   int32_t nRetStatus = m_nodeParser.StartParse(pStream, ePacketID);
     27   if (nRetStatus == XFA_PARSESTATUS_Ready) {
     28     m_pDocument = pdfium::MakeUnique<CXFA_Document>(this);
     29     m_nodeParser.SetFactory(m_pDocument.get());
     30   }
     31   return nRetStatus;
     32 }
     33 
     34 int32_t CXFA_DocumentParser::DoParse() {
     35   int32_t nRetStatus = m_nodeParser.DoParse();
     36   if (nRetStatus >= XFA_PARSESTATUS_Done) {
     37     ASSERT(m_pDocument);
     38     m_pDocument->SetRoot(m_nodeParser.GetRootNode());
     39   }
     40   return nRetStatus;
     41 }
     42 
     43 CFX_XMLDoc* CXFA_DocumentParser::GetXMLDoc() const {
     44   return m_nodeParser.GetXMLDoc();
     45 }
     46 
     47 CXFA_FFNotify* CXFA_DocumentParser::GetNotify() const {
     48   return m_pNotify.Get();
     49 }
     50 
     51 CXFA_Document* CXFA_DocumentParser::GetDocument() const {
     52   return m_pDocument.get();
     53 }
     54