| 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/fde/xml/fde_xml_imp.h" | 7 #include "xfa/fde/xml/fde_xml_imp.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 return FALSE; | 72 return FALSE; |
| 73 } | 73 } |
| 74 | 74 |
| 75 CFDE_XMLNode::CFDE_XMLNode() | 75 CFDE_XMLNode::CFDE_XMLNode() |
| 76 : m_pParent(NULL), m_pChild(NULL), m_pPrior(NULL), m_pNext(NULL) {} | 76 : m_pParent(NULL), m_pChild(NULL), m_pPrior(NULL), m_pNext(NULL) {} |
| 77 CFDE_XMLNode::~CFDE_XMLNode() { | 77 CFDE_XMLNode::~CFDE_XMLNode() { |
| 78 DeleteChildren(); | 78 DeleteChildren(); |
| 79 } | 79 } |
| 80 |
| 80 void CFDE_XMLNode::DeleteChildren() { | 81 void CFDE_XMLNode::DeleteChildren() { |
| 81 CFDE_XMLNode *pChild = m_pChild, *pTemp; | 82 CFDE_XMLNode* pChild = m_pChild; |
| 82 while (pChild != NULL) { | 83 while (pChild) { |
| 83 pTemp = pChild->m_pNext; | 84 CFDE_XMLNode* pNext = pChild->m_pNext; |
| 84 pChild->Release(); | 85 delete pChild; |
| 85 pChild = pTemp; | 86 pChild = pNext; |
| 86 } | 87 } |
| 87 m_pChild = NULL; | 88 m_pChild = nullptr; |
| 88 } | 89 } |
| 90 |
| 89 int32_t CFDE_XMLNode::CountChildNodes() const { | 91 int32_t CFDE_XMLNode::CountChildNodes() const { |
| 90 int32_t iCount = 0; | 92 int32_t iCount = 0; |
| 91 CFDE_XMLNode* pChild = m_pChild; | 93 CFDE_XMLNode* pChild = m_pChild; |
| 92 while (pChild != NULL) { | 94 while (pChild != NULL) { |
| 93 iCount++; | 95 iCount++; |
| 94 pChild = pChild->m_pNext; | 96 pChild = pChild->m_pNext; |
| 95 } | 97 } |
| 96 return iCount; | 98 return iCount; |
| 97 } | 99 } |
| 98 CFDE_XMLNode* CFDE_XMLNode::GetChildNode(int32_t index) const { | 100 CFDE_XMLNode* CFDE_XMLNode::GetChildNode(int32_t index) const { |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 pCloneNext->InsertNodeItem(CFDE_XMLNode::NextSibling, pChild); | 505 pCloneNext->InsertNodeItem(CFDE_XMLNode::NextSibling, pChild); |
| 504 pCloneNext = pChild; | 506 pCloneNext = pChild; |
| 505 pNext = pNext->m_pNext; | 507 pNext = pNext->m_pNext; |
| 506 } | 508 } |
| 507 } | 509 } |
| 508 | 510 |
| 509 CFDE_XMLInstruction::CFDE_XMLInstruction(const CFX_WideString& wsTarget) | 511 CFDE_XMLInstruction::CFDE_XMLInstruction(const CFX_WideString& wsTarget) |
| 510 : m_wsTarget(wsTarget) { | 512 : m_wsTarget(wsTarget) { |
| 511 ASSERT(m_wsTarget.GetLength() > 0); | 513 ASSERT(m_wsTarget.GetLength() > 0); |
| 512 } | 514 } |
| 515 |
| 516 CFDE_XMLInstruction::~CFDE_XMLInstruction() {} |
| 517 |
| 513 CFDE_XMLNode* CFDE_XMLInstruction::Clone(FX_BOOL bRecursive) { | 518 CFDE_XMLNode* CFDE_XMLInstruction::Clone(FX_BOOL bRecursive) { |
| 514 CFDE_XMLInstruction* pClone = new CFDE_XMLInstruction(m_wsTarget); | 519 CFDE_XMLInstruction* pClone = new CFDE_XMLInstruction(m_wsTarget); |
| 515 if (!pClone) { | 520 if (!pClone) { |
| 516 return pClone; | 521 return pClone; |
| 517 } | 522 } |
| 518 pClone->m_Attributes.Copy(m_Attributes); | 523 pClone->m_Attributes.Copy(m_Attributes); |
| 519 pClone->m_TargetData.Copy(m_TargetData); | 524 pClone->m_TargetData.Copy(m_TargetData); |
| 520 if (bRecursive) { | 525 if (bRecursive) { |
| 521 CloneChildren(pClone); | 526 CloneChildren(pClone); |
| 522 } | 527 } |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 pChild = pChild->m_pNext; | 825 pChild = pChild->m_pNext; |
| 821 } | 826 } |
| 822 wsText = buffer.AsStringC(); | 827 wsText = buffer.AsStringC(); |
| 823 } | 828 } |
| 824 void CFDE_XMLElement::SetTextData(const CFX_WideString& wsText) { | 829 void CFDE_XMLElement::SetTextData(const CFX_WideString& wsText) { |
| 825 if (wsText.GetLength() < 1) { | 830 if (wsText.GetLength() < 1) { |
| 826 return; | 831 return; |
| 827 } | 832 } |
| 828 InsertChildNode(new CFDE_XMLText(wsText)); | 833 InsertChildNode(new CFDE_XMLText(wsText)); |
| 829 } | 834 } |
| 835 |
| 830 CFDE_XMLText::CFDE_XMLText(const CFX_WideString& wsText) | 836 CFDE_XMLText::CFDE_XMLText(const CFX_WideString& wsText) |
| 831 : CFDE_XMLNode(), m_wsText(wsText) {} | 837 : CFDE_XMLNode(), m_wsText(wsText) {} |
| 838 |
| 839 CFDE_XMLText::~CFDE_XMLText() {} |
| 840 |
| 832 CFDE_XMLNode* CFDE_XMLText::Clone(FX_BOOL bRecursive) { | 841 CFDE_XMLNode* CFDE_XMLText::Clone(FX_BOOL bRecursive) { |
| 833 CFDE_XMLText* pClone = new CFDE_XMLText(m_wsText); | 842 CFDE_XMLText* pClone = new CFDE_XMLText(m_wsText); |
| 834 return pClone; | 843 return pClone; |
| 835 } | 844 } |
| 836 | 845 |
| 837 CFDE_XMLCharData::CFDE_XMLCharData(const CFX_WideString& wsCData) | 846 CFDE_XMLCharData::CFDE_XMLCharData(const CFX_WideString& wsCData) |
| 838 : CFDE_XMLDeclaration(), m_wsCharData(wsCData) {} | 847 : CFDE_XMLDeclaration(), m_wsCharData(wsCData) {} |
| 848 |
| 849 CFDE_XMLCharData::~CFDE_XMLCharData() {} |
| 850 |
| 839 CFDE_XMLNode* CFDE_XMLCharData::Clone(FX_BOOL bRecursive) { | 851 CFDE_XMLNode* CFDE_XMLCharData::Clone(FX_BOOL bRecursive) { |
| 840 CFDE_XMLCharData* pClone = new CFDE_XMLCharData(m_wsCharData); | 852 CFDE_XMLCharData* pClone = new CFDE_XMLCharData(m_wsCharData); |
| 841 return pClone; | 853 return pClone; |
| 842 } | 854 } |
| 843 | 855 |
| 844 CFDE_XMLDoc::CFDE_XMLDoc() | 856 CFDE_XMLDoc::CFDE_XMLDoc() |
| 845 : m_pRoot(NULL), m_pSyntaxParser(NULL), m_pXMLParser(NULL) { | 857 : m_pRoot(NULL), m_pSyntaxParser(NULL), m_pXMLParser(NULL) { |
| 846 Reset(TRUE); | 858 Reset(TRUE); |
| 847 CFDE_XMLInstruction* pXML = new CFDE_XMLInstruction(L"xml"); | 859 CFDE_XMLInstruction* pXML = new CFDE_XMLInstruction(L"xml"); |
| 848 m_pRoot->InsertChildNode(pXML); | 860 m_pRoot->InsertChildNode(pXML); |
| 849 } | 861 } |
| 850 CFDE_XMLDoc::~CFDE_XMLDoc() { | 862 CFDE_XMLDoc::~CFDE_XMLDoc() { |
| 851 Reset(FALSE); | 863 Reset(FALSE); |
| 852 } | 864 } |
| 853 void CFDE_XMLDoc::Reset(FX_BOOL bInitRoot) { | 865 void CFDE_XMLDoc::Reset(FX_BOOL bInitRoot) { |
| 854 m_iStatus = 0; | 866 m_iStatus = 0; |
| 855 m_pStream = NULL; | 867 m_pStream = NULL; |
| 856 if (bInitRoot) { | 868 if (bInitRoot) { |
| 857 if (m_pRoot == NULL) { | 869 if (m_pRoot == NULL) { |
| 858 m_pRoot = new CFDE_XMLNode; | 870 m_pRoot = new CFDE_XMLNode; |
| 859 } else { | 871 } else { |
| 860 m_pRoot->DeleteChildren(); | 872 m_pRoot->DeleteChildren(); |
| 861 } | 873 } |
| 862 } else { | 874 } else { |
| 863 if (m_pRoot != NULL) { | 875 delete m_pRoot; |
| 864 m_pRoot->Release(); | 876 m_pRoot = nullptr; |
| 865 m_pRoot = NULL; | |
| 866 } | |
| 867 } | 877 } |
| 868 ReleaseParser(); | 878 ReleaseParser(); |
| 869 } | 879 } |
| 880 |
| 870 void CFDE_XMLDoc::ReleaseParser() { | 881 void CFDE_XMLDoc::ReleaseParser() { |
| 871 if (m_pXMLParser != NULL) { | 882 delete m_pXMLParser; |
| 872 m_pXMLParser->Release(); | 883 m_pXMLParser = nullptr; |
| 873 m_pXMLParser = NULL; | 884 delete m_pSyntaxParser; |
| 874 } | 885 m_pSyntaxParser = nullptr; |
| 875 if (m_pSyntaxParser != NULL) { | |
| 876 m_pSyntaxParser->Release(); | |
| 877 m_pSyntaxParser = NULL; | |
| 878 } | |
| 879 } | 886 } |
| 887 |
| 880 FX_BOOL CFDE_XMLDoc::LoadXML(IFX_Stream* pXMLStream, | 888 FX_BOOL CFDE_XMLDoc::LoadXML(IFX_Stream* pXMLStream, |
| 881 int32_t iXMLPlaneSize, | 889 int32_t iXMLPlaneSize, |
| 882 int32_t iTextDataSize, | 890 int32_t iTextDataSize, |
| 883 FDE_XMLREADERHANDLER* pHandler) { | 891 FDE_XMLREADERHANDLER* pHandler) { |
| 884 if (pXMLStream == NULL) { | 892 if (pXMLStream == NULL) { |
| 885 return FALSE; | 893 return FALSE; |
| 886 } | 894 } |
| 887 Reset(TRUE); | 895 Reset(TRUE); |
| 888 iXMLPlaneSize = iXMLPlaneSize / 1024; | 896 iXMLPlaneSize = iXMLPlaneSize / 1024; |
| 889 if (iXMLPlaneSize < 1) { | 897 if (iXMLPlaneSize < 1) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 912 return FALSE; | 920 return FALSE; |
| 913 } | 921 } |
| 914 m_pSyntaxParser->Init(m_pStream, iXMLPlaneSize, iTextDataSize); | 922 m_pSyntaxParser->Init(m_pStream, iXMLPlaneSize, iTextDataSize); |
| 915 if (pHandler == NULL) { | 923 if (pHandler == NULL) { |
| 916 m_pXMLParser = new CFDE_XMLDOMParser(m_pRoot, m_pSyntaxParser); | 924 m_pXMLParser = new CFDE_XMLDOMParser(m_pRoot, m_pSyntaxParser); |
| 917 } else { | 925 } else { |
| 918 m_pXMLParser = new CFDE_XMLSAXParser(pHandler, m_pSyntaxParser); | 926 m_pXMLParser = new CFDE_XMLSAXParser(pHandler, m_pSyntaxParser); |
| 919 } | 927 } |
| 920 return TRUE; | 928 return TRUE; |
| 921 } | 929 } |
| 922 FX_BOOL CFDE_XMLDoc::LoadXML(CFDE_XMLParser* pXMLParser) { | 930 |
| 923 if (pXMLParser == NULL) { | 931 FX_BOOL CFDE_XMLDoc::LoadXML(IFDE_XMLParser* pXMLParser) { |
| 932 if (!pXMLParser) |
| 924 return FALSE; | 933 return FALSE; |
| 925 } | 934 |
| 926 Reset(TRUE); | 935 Reset(TRUE); |
| 927 m_pXMLParser = pXMLParser; | 936 m_pXMLParser = pXMLParser; |
| 928 return m_pXMLParser != NULL; | 937 return TRUE; |
| 929 } | 938 } |
| 939 |
| 930 int32_t CFDE_XMLDoc::DoLoad(IFX_Pause* pPause) { | 940 int32_t CFDE_XMLDoc::DoLoad(IFX_Pause* pPause) { |
| 931 if (m_iStatus >= 100) { | 941 if (m_iStatus >= 100) { |
| 932 return m_iStatus; | 942 return m_iStatus; |
| 933 } | 943 } |
| 934 ASSERT(m_pXMLParser != NULL); | |
| 935 return m_iStatus = m_pXMLParser->DoParser(pPause); | 944 return m_iStatus = m_pXMLParser->DoParser(pPause); |
| 936 } | 945 } |
| 946 |
| 937 void CFDE_XMLDoc::CloseXML() { | 947 void CFDE_XMLDoc::CloseXML() { |
| 938 ReleaseParser(); | 948 ReleaseParser(); |
| 939 } | 949 } |
| 940 void CFDE_XMLDoc::SaveXMLNode(IFX_Stream* pXMLStream, CFDE_XMLNode* pINode) { | 950 void CFDE_XMLDoc::SaveXMLNode(IFX_Stream* pXMLStream, CFDE_XMLNode* pINode) { |
| 941 CFDE_XMLNode* pNode = (CFDE_XMLNode*)pINode; | 951 CFDE_XMLNode* pNode = (CFDE_XMLNode*)pINode; |
| 942 ASSERT(pXMLStream != NULL && pNode != NULL); | 952 ASSERT(pXMLStream != NULL && pNode != NULL); |
| 943 switch (pNode->GetType()) { | 953 switch (pNode->GetType()) { |
| 944 case FDE_XMLNODE_Instruction: { | 954 case FDE_XMLNODE_Instruction: { |
| 945 CFX_WideString ws; | 955 CFX_WideString ws; |
| 946 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; | 956 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; |
| (...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2073 m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart, FALSE); | 2083 m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart, FALSE); |
| 2074 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); | 2084 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); |
| 2075 m_iEntityStart = -1; | 2085 m_iEntityStart = -1; |
| 2076 } else { | 2086 } else { |
| 2077 if (m_iEntityStart < 0 && ch == L'&') { | 2087 if (m_iEntityStart < 0 && ch == L'&') { |
| 2078 m_iEntityStart = m_iDataLength - 1; | 2088 m_iEntityStart = m_iDataLength - 1; |
| 2079 } | 2089 } |
| 2080 } | 2090 } |
| 2081 m_pStart++; | 2091 m_pStart++; |
| 2082 } | 2092 } |
| OLD | NEW |