OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fgas/xml/fgas_sax_imp.h" | 7 #include "xfa/fgas/xml/fgas_sax.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
| 11 #include "xfa/fxfa/include/xfa_checksum.h" |
| 12 |
11 namespace { | 13 namespace { |
12 | 14 |
13 const uint32_t kSaxFileBufSize = 32768; | 15 const uint32_t kSaxFileBufSize = 32768; |
14 | 16 |
15 } // namespace | 17 } // namespace |
16 | 18 |
17 IFX_SAXReader* FX_SAXReader_Create() { | |
18 return new CFX_SAXReader; | |
19 } | |
20 CFX_SAXFile::CFX_SAXFile() | 19 CFX_SAXFile::CFX_SAXFile() |
21 : m_pFile(NULL), | 20 : m_pFile(NULL), |
22 m_dwStart(0), | 21 m_dwStart(0), |
23 m_dwEnd(0), | 22 m_dwEnd(0), |
24 m_dwCur(0), | 23 m_dwCur(0), |
25 m_pBuf(NULL), | 24 m_pBuf(NULL), |
26 m_dwBufSize(0), | 25 m_dwBufSize(0), |
27 m_dwBufIndex(0) {} | 26 m_dwBufIndex(0) {} |
28 FX_BOOL CFX_SAXFile::StartFile(IFX_FileRead* pFile, | 27 FX_BOOL CFX_SAXFile::StartFile(IFX_FileRead* pFile, |
29 uint32_t dwStart, | 28 uint32_t dwStart, |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 } | 610 } |
612 m_eMode = FX_SAXMODE_Text; | 611 m_eMode = FX_SAXMODE_Text; |
613 } | 612 } |
614 } | 613 } |
615 break; | 614 break; |
616 } | 615 } |
617 if (iLen > 0) { | 616 if (iLen > 0) { |
618 ParseChar(m_CurByte); | 617 ParseChar(m_CurByte); |
619 } | 618 } |
620 } | 619 } |
| 620 |
621 void CFX_SAXReader::NotifyData() { | 621 void CFX_SAXReader::NotifyData() { |
622 ASSERT(m_pHandler != NULL); | |
623 if (m_pCurItem->m_eNode == FX_SAXNODE_Tag) | 622 if (m_pCurItem->m_eNode == FX_SAXNODE_Tag) |
624 m_pHandler->OnTagData(m_pCurItem->m_pNode, | 623 m_pHandler->OnTagData(m_pCurItem->m_pNode, |
625 m_bCharData ? FX_SAXNODE_CharData : FX_SAXNODE_Text, | 624 m_bCharData ? FX_SAXNODE_CharData : FX_SAXNODE_Text, |
626 CFX_ByteStringC(m_pszData, m_iDataLength), | 625 CFX_ByteStringC(m_pszData, m_iDataLength), |
627 m_File.m_dwCur + m_dwDataOffset); | 626 m_File.m_dwCur + m_dwDataOffset); |
628 } | 627 } |
| 628 |
629 void CFX_SAXReader::NotifyEnter() { | 629 void CFX_SAXReader::NotifyEnter() { |
630 ASSERT(m_pHandler != NULL); | |
631 if (m_pCurItem->m_eNode == FX_SAXNODE_Tag || | 630 if (m_pCurItem->m_eNode == FX_SAXNODE_Tag || |
632 m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { | 631 m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { |
633 m_pCurItem->m_pNode = | 632 m_pCurItem->m_pNode = |
634 m_pHandler->OnTagEnter(CFX_ByteStringC(m_pszData, m_iDataLength), | 633 m_pHandler->OnTagEnter(CFX_ByteStringC(m_pszData, m_iDataLength), |
635 m_pCurItem->m_eNode, m_dwNodePos); | 634 m_pCurItem->m_eNode, m_dwNodePos); |
636 } | 635 } |
637 } | 636 } |
| 637 |
638 void CFX_SAXReader::NotifyAttribute() { | 638 void CFX_SAXReader::NotifyAttribute() { |
639 ASSERT(m_pHandler != NULL); | |
640 if (m_pCurItem->m_eNode == FX_SAXNODE_Tag || | 639 if (m_pCurItem->m_eNode == FX_SAXNODE_Tag || |
641 m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { | 640 m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { |
642 m_pHandler->OnTagAttribute(m_pCurItem->m_pNode, | 641 m_pHandler->OnTagAttribute(m_pCurItem->m_pNode, |
643 CFX_ByteStringC(m_pszName, m_iNameLength), | 642 CFX_ByteStringC(m_pszName, m_iNameLength), |
644 CFX_ByteStringC(m_pszData, m_iDataLength)); | 643 CFX_ByteStringC(m_pszData, m_iDataLength)); |
645 } | 644 } |
646 } | 645 } |
| 646 |
647 void CFX_SAXReader::NotifyBreak() { | 647 void CFX_SAXReader::NotifyBreak() { |
648 ASSERT(m_pHandler != NULL); | 648 if (m_pCurItem->m_eNode == FX_SAXNODE_Tag) |
649 if (m_pCurItem->m_eNode == FX_SAXNODE_Tag) { | |
650 m_pHandler->OnTagBreak(m_pCurItem->m_pNode); | 649 m_pHandler->OnTagBreak(m_pCurItem->m_pNode); |
651 } | |
652 } | 650 } |
| 651 |
653 void CFX_SAXReader::NotifyClose() { | 652 void CFX_SAXReader::NotifyClose() { |
654 ASSERT(m_pHandler != NULL); | |
655 if (m_pCurItem->m_eNode == FX_SAXNODE_Tag || | 653 if (m_pCurItem->m_eNode == FX_SAXNODE_Tag || |
656 m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { | 654 m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { |
657 m_pHandler->OnTagClose(m_pCurItem->m_pNode, m_dwNodePos); | 655 m_pHandler->OnTagClose(m_pCurItem->m_pNode, m_dwNodePos); |
658 } | 656 } |
659 } | 657 } |
| 658 |
660 void CFX_SAXReader::NotifyEnd() { | 659 void CFX_SAXReader::NotifyEnd() { |
661 ASSERT(m_pHandler != NULL); | 660 if (m_pCurItem->m_eNode != FX_SAXNODE_Tag) |
662 if (m_pCurItem->m_eNode == FX_SAXNODE_Tag) { | 661 return; |
663 m_pHandler->OnTagEnd(m_pCurItem->m_pNode, | 662 |
664 CFX_ByteStringC(m_pszData, m_iDataLength), | 663 m_pHandler->OnTagEnd(m_pCurItem->m_pNode, |
665 m_dwNodePos); | 664 CFX_ByteStringC(m_pszData, m_iDataLength), m_dwNodePos); |
666 } | |
667 } | 665 } |
| 666 |
668 void CFX_SAXReader::NotifyTargetData() { | 667 void CFX_SAXReader::NotifyTargetData() { |
669 ASSERT(m_pHandler != NULL); | |
670 if (m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { | 668 if (m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { |
671 m_pHandler->OnTargetData(m_pCurItem->m_pNode, m_pCurItem->m_eNode, | 669 m_pHandler->OnTargetData(m_pCurItem->m_pNode, m_pCurItem->m_eNode, |
672 CFX_ByteStringC(m_pszName, m_iNameLength), | 670 CFX_ByteStringC(m_pszName, m_iNameLength), |
673 m_dwNodePos); | 671 m_dwNodePos); |
674 } else if (m_pCurItem->m_eNode == FX_SAXNODE_Comment) { | 672 } else if (m_pCurItem->m_eNode == FX_SAXNODE_Comment) { |
675 m_pHandler->OnTargetData(m_pCurItem->m_pNode, m_pCurItem->m_eNode, | 673 m_pHandler->OnTargetData(m_pCurItem->m_pNode, m_pCurItem->m_eNode, |
676 CFX_ByteStringC(m_pszData, m_iDataLength), | 674 CFX_ByteStringC(m_pszData, m_iDataLength), |
677 m_dwNodePos); | 675 m_dwNodePos); |
678 } | 676 } |
679 } | 677 } |
| 678 |
680 void CFX_SAXReader::SkipCurrentNode() { | 679 void CFX_SAXReader::SkipCurrentNode() { |
681 if (!m_pCurItem) { | 680 if (!m_pCurItem) |
682 return; | 681 return; |
683 } | 682 |
684 m_pCurItem->m_bSkip = TRUE; | 683 m_pCurItem->m_bSkip = TRUE; |
685 } | 684 } |
686 void CFX_SAXReader::SetHandler(IFX_SAXReaderHandler* pHandler) { | 685 |
| 686 void CFX_SAXReader::SetHandler(CXFA_SAXReaderHandler* pHandler) { |
687 m_pHandler = pHandler; | 687 m_pHandler = pHandler; |
688 } | 688 } |
OLD | NEW |