diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-04-05 11:48:21 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-05 16:10:44 +0000 |
commit | 5fa4e981ed6c431d86c51a74eba19ea4b816f541 (patch) | |
tree | 4bfa4afc2b89e1a423ec4838937042780eaa6191 /xfa/fxfa | |
parent | ddcb6e7f47e2769fb4565bd4430ecb465a1f5417 (diff) | |
download | pdfium-5fa4e981ed6c431d86c51a74eba19ea4b816f541.tar.xz |
Move XML attribute handling to a base class.
This CL moves the attribute handling out of CFDE_XMLElement and
CFDE_XMLInstruction into a common CFDE_XMLAttributeNode. The handling is
also converted to a std::map from either a) a vector storing
name,value,name,value or b) two vectors one for names and the other for
values.
The unused Get/Set methods for interger and float are removed and the
iteration is converted to use iterators.
Change-Id: Icda00ae898a595d58b06af0ced337f55f47c317c
Reviewed-on: https://pdfium-review.googlesource.com/3753
Reviewed-by: Nicolás Peña <npm@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r-- | xfa/fxfa/app/cxfa_textlayout.cpp | 8 | ||||
-rw-r--r-- | xfa/fxfa/app/cxfa_textparser.cpp | 14 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffdoc.cpp | 9 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_document.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_document.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 21 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_simple_parser.cpp | 306 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_document_datamerger_imp.cpp | 9 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_utils.cpp | 3 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_utils.h | 2 |
10 files changed, 169 insertions, 207 deletions
diff --git a/xfa/fxfa/app/cxfa_textlayout.cpp b/xfa/fxfa/app/cxfa_textlayout.cpp index c32717b523..880bdf4585 100644 --- a/xfa/fxfa/app/cxfa_textlayout.cpp +++ b/xfa/fxfa/app/cxfa_textlayout.cpp @@ -81,8 +81,7 @@ CFDE_XMLNode* CXFA_TextLayout::GetXMLContainerNode() { pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { if (pXMLChild->GetType() == FDE_XMLNODE_Element) { CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLChild); - CFX_WideString wsTag; - pXMLElement->GetLocalTagName(wsTag); + CFX_WideString wsTag = pXMLElement->GetLocalTagName(); if (wsTag == L"body" || wsTag == L"html") { pXMLContainer = pXMLChild; break; @@ -727,7 +726,7 @@ bool CXFA_TextLayout::LoadRichText( bContentNode = true; } else if (pXMLNode->GetType() == FDE_XMLNODE_Element) { pElement = static_cast<CFDE_XMLElement*>(pXMLNode); - pElement->GetLocalTagName(wsName); + wsName = pElement->GetLocalTagName(); } if (wsName == L"ol") { bIsOl = true; @@ -757,9 +756,8 @@ bool CXFA_TextLayout::LoadRichText( } if (wsName == L"a") { - CFX_WideString wsLinkContent; ASSERT(pElement); - pElement->GetString(L"href", wsLinkContent); + CFX_WideString wsLinkContent = pElement->GetString(L"href"); if (!wsLinkContent.IsEmpty()) { pLinkData = pdfium::MakeRetain<CXFA_LinkUserData>( wsLinkContent.GetBuffer(wsLinkContent.GetLength())); diff --git a/xfa/fxfa/app/cxfa_textparser.cpp b/xfa/fxfa/app/cxfa_textparser.cpp index b4032fa5c7..6f394dd5e2 100644 --- a/xfa/fxfa/app/cxfa_textparser.cpp +++ b/xfa/fxfa/app/cxfa_textparser.cpp @@ -277,12 +277,11 @@ std::unique_ptr<CXFA_CSSTagProvider> CXFA_TextParser::ParseTagInfo( CFX_WideString wsName; if (pXMLNode->GetType() == FDE_XMLNODE_Element) { CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); - pXMLElement->GetLocalTagName(wsName); + wsName = pXMLElement->GetLocalTagName(); tagProvider->SetTagName(wsName); tagProvider->m_bTagAvailable = TagValidate(wsName); - CFX_WideString wsValue; - pXMLElement->GetString(L"style", wsValue); + CFX_WideString wsValue = pXMLElement->GetString(L"style"); if (!wsValue.IsEmpty()) tagProvider->SetAttribute(L"style", wsValue); } else if (pXMLNode->GetType() == FDE_XMLNODE_Text) { @@ -500,15 +499,13 @@ bool CXFA_TextParser::GetEmbbedObj(CXFA_TextProvider* pTextProvider, bool bRet = false; if (pXMLNode->GetType() == FDE_XMLNODE_Element) { CFDE_XMLElement* pElement = static_cast<CFDE_XMLElement*>(pXMLNode); - CFX_WideString wsAttr; - pElement->GetString(L"xfa:embed", wsAttr); + CFX_WideString wsAttr = pElement->GetString(L"xfa:embed"); if (wsAttr.IsEmpty()) return false; if (wsAttr.GetAt(0) == L'#') wsAttr.Delete(0); - CFX_WideString ws; - pElement->GetString(L"xfa:embedType", ws); + CFX_WideString ws = pElement->GetString(L"xfa:embedType"); if (ws.IsEmpty()) ws = L"som"; else @@ -518,8 +515,7 @@ bool CXFA_TextParser::GetEmbbedObj(CXFA_TextProvider* pTextProvider, if (!bURI && ws != L"som") return false; - ws.clear(); - pElement->GetString(L"xfa:embedMode", ws); + ws = pElement->GetString(L"xfa:embedMode"); if (ws.IsEmpty()) ws = L"formatted"; else diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp index 993f5bc664..47f089eee0 100644 --- a/xfa/fxfa/cxfa_ffdoc.cpp +++ b/xfa/fxfa/cxfa_ffdoc.cpp @@ -178,9 +178,8 @@ bool XFA_GetPDFContentsFromPDFXML(CFDE_XMLNode* pPDFElement, pPDFElement->GetNodeItem(CFDE_XMLNode::FirstChild); pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { if (pXMLNode->GetType() == FDE_XMLNODE_Element) { - CFX_WideString wsTagName; CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); - pXMLElement->GetTagName(wsTagName); + CFX_WideString wsTagName = pXMLElement->GetName(); if (wsTagName == L"document") { pDocumentElement = pXMLElement; break; @@ -195,9 +194,8 @@ bool XFA_GetPDFContentsFromPDFXML(CFDE_XMLNode* pPDFElement, pDocumentElement->GetNodeItem(CFDE_XMLNode::FirstChild); pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { if (pXMLNode->GetType() == FDE_XMLNODE_Element) { - CFX_WideString wsTagName; CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); - pXMLElement->GetTagName(wsTagName); + CFX_WideString wsTagName = pXMLElement->GetName(); if (wsTagName == L"chunk") { pChunkElement = pXMLElement; break; @@ -207,8 +205,7 @@ bool XFA_GetPDFContentsFromPDFXML(CFDE_XMLNode* pPDFElement, if (!pChunkElement) { return false; } - CFX_WideString wsPDFContent; - pChunkElement->GetTextData(wsPDFContent); + CFX_WideString wsPDFContent = pChunkElement->GetTextData(); iBufferSize = Base64DecodeW(wsPDFContent.c_str(), wsPDFContent.GetLength(), nullptr); pByteBuffer = FX_Alloc(uint8_t, iBufferSize + 1); diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp index 165c0a3ee5..7c979fec22 100644 --- a/xfa/fxfa/parser/cxfa_document.cpp +++ b/xfa/fxfa/parser/cxfa_document.cpp @@ -296,7 +296,7 @@ CXFA_ScriptContext* CXFA_Document::GetScriptContext() { } XFA_VERSION CXFA_Document::RecognizeXFAVersionNumber( - CFX_WideString& wsTemplateNS) { + const CFX_WideString& wsTemplateNS) { CFX_WideStringC wsTemplateURIPrefix = XFA_GetPacketByIndex(XFA_PACKET_Template)->pURI; FX_STRSIZE nPrefixLength = wsTemplateURIPrefix.GetLength(); diff --git a/xfa/fxfa/parser/cxfa_document.h b/xfa/fxfa/parser/cxfa_document.h index 5d9ec1b430..101b23332e 100644 --- a/xfa/fxfa/parser/cxfa_document.h +++ b/xfa/fxfa/parser/cxfa_document.h @@ -87,7 +87,7 @@ class CXFA_Document { bool IsInteractive(); XFA_VERSION GetCurVersionMode() { return m_eCurVersionMode; } - XFA_VERSION RecognizeXFAVersionNumber(CFX_WideString& wsTemplateNS); + XFA_VERSION RecognizeXFAVersionNumber(const CFX_WideString& wsTemplateNS); CXFA_Node* CreateNode(uint32_t dwPacket, XFA_Element eElement); CXFA_Node* CreateNode(const XFA_PACKETINFO* pPacket, XFA_Element eElement); diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 2079127dc9..5ed013c259 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -3378,9 +3378,8 @@ void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) { CFX_WideString wsAttributeValue; CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { - static_cast<CFDE_XMLElement*>(pXMLNode)->GetString( - CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(), - wsAttributeValue); + wsAttributeValue = static_cast<CFDE_XMLElement*>(pXMLNode)->GetString( + CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str()); } pArguments->GetReturnValue()->SetString( wsAttributeValue.UTF8Encode().AsStringC()); @@ -3434,7 +3433,7 @@ void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue, CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); - pXMLElement->GetTextData(wsTextData); + wsTextData = pXMLElement->GetTextData(); } pValue->SetString(wsTextData.UTF8Encode().AsStringC()); } @@ -3981,10 +3980,14 @@ bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr, static_cast<CFDE_XMLElement*>(m_pXMLNode) ->SetString(pInfo->pName, pValue ? L"1" : L"0"); break; - case XFA_ATTRIBUTETYPE_Integer: + case XFA_ATTRIBUTETYPE_Integer: { + CFX_WideString wsValue; + wsValue.Format( + L"%d", static_cast<int32_t>(reinterpret_cast<uintptr_t>(pValue))); static_cast<CFDE_XMLElement*>(m_pXMLNode) - ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue); + ->SetString(pInfo->pName, wsValue); break; + } default: ASSERT(0); } @@ -4304,7 +4307,7 @@ bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) { if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) { return false; } - static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace); + wsNamespace = static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(); return true; } else if (GetPacketID() == XFA_XDPPACKET_Datasets) { CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); @@ -4318,9 +4321,9 @@ bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) { GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) { return XFA_FDEExtension_ResolveNamespaceQualifier( static_cast<CFDE_XMLElement*>(pXMLNode), - GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace); + GetCData(XFA_ATTRIBUTE_QualifiedName), &wsNamespace); } - static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace); + wsNamespace = static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(); return true; } else { CXFA_Node* pModelNode = GetModelNode(); diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp index cb6a90d2a5..b3f1302eae 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.cpp +++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp @@ -7,6 +7,7 @@ #include "xfa/fxfa/parser/cxfa_simple_parser.h" #include <utility> +#include <vector> #include "core/fxcrt/cfx_checksumcontext.h" #include "core/fxcrt/fx_ext.h" @@ -54,14 +55,14 @@ CFDE_XMLNode* GetDocumentNode(CFDE_XMLDoc* pXMLDoc, return nullptr; } -void GetElementTagNamespaceURI(CFDE_XMLElement* pElement, - CFX_WideString& wsNamespaceURI) { - CFX_WideString wsNodeStr; - pElement->GetNamespacePrefix(wsNodeStr); +CFX_WideString GetElementTagNamespaceURI(CFDE_XMLElement* pElement) { + CFX_WideString wsNodeStr = pElement->GetNamespacePrefix(); + CFX_WideString wsNamespaceURI; if (!XFA_FDEExtension_ResolveNamespaceQualifier( - pElement, wsNodeStr.AsStringC(), wsNamespaceURI)) { - wsNamespaceURI.clear(); + pElement, wsNodeStr.AsStringC(), &wsNamespaceURI)) { + return CFX_WideString(); } + return wsNamespaceURI; } bool MatchNodeName(CFDE_XMLNode* pNode, @@ -72,18 +73,18 @@ bool MatchNodeName(CFDE_XMLNode* pNode, return false; CFDE_XMLElement* pElement = reinterpret_cast<CFDE_XMLElement*>(pNode); - CFX_WideString wsNodeStr; - pElement->GetLocalTagName(wsNodeStr); + CFX_WideString wsNodeStr = pElement->GetLocalTagName(); if (wsNodeStr != wsLocalTagName) return false; - GetElementTagNamespaceURI(pElement, wsNodeStr); + wsNodeStr = GetElementTagNamespaceURI(pElement); if (eMatchFlags & XFA_XDPPACKET_FLAGS_NOMATCH) return true; if (eMatchFlags & XFA_XDPPACKET_FLAGS_PREFIXMATCH) { return wsNodeStr.Left(wsNamespaceURIPrefix.GetLength()) == wsNamespaceURIPrefix; } + return wsNodeStr == wsNamespaceURIPrefix; } @@ -114,7 +115,7 @@ bool ResolveAttribute(CFDE_XMLElement* pElement, return false; } if (!XFA_FDEExtension_ResolveNamespaceQualifier( - pElement, wsNSPrefix.AsStringC(), wsNamespaceURI)) { + pElement, wsNSPrefix.AsStringC(), &wsNamespaceURI)) { wsNamespaceURI.clear(); return false; } @@ -129,26 +130,23 @@ bool FindAttributeWithNS(CFDE_XMLElement* pElement, 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); + for (auto it : pElement->GetAttributes()) { + FX_STRSIZE iFind = it.first.Find(L':', 0); CFX_WideString wsNSPrefix; if (iFind < 0) { - if (wsLocalAttributeName != wsAttrName) + if (wsLocalAttributeName != it.first) continue; } else { if (wsLocalAttributeName != - wsAttrName.Right(wsAttrName.GetLength() - iFind - 1)) { + it.first.Right(it.first.GetLength() - iFind - 1)) { continue; } - wsNSPrefix = wsAttrName.Left(iFind); + wsNSPrefix = it.first.Left(iFind); } + if (!XFA_FDEExtension_ResolveNamespaceQualifier( - pElement, wsNSPrefix.AsStringC(), wsAttrNS)) { + pElement, wsNSPrefix.AsStringC(), &wsAttrNS)) { continue; } if (bMatchNSAsPrefix) { @@ -160,7 +158,7 @@ bool FindAttributeWithNS(CFDE_XMLElement* pElement, if (wsAttrNS != wsNamespaceURIPrefix) continue; } - wsValue = wsAttrValue; + wsValue = it.second; return true; } return false; @@ -207,8 +205,8 @@ void ConvertXMLToPlainText(CFDE_XMLElement* pRootXMLNode, pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { switch (pXMLChild->GetType()) { case FDE_XMLNODE_Element: { - CFX_WideString wsTextData; - static_cast<CFDE_XMLElement*>(pXMLChild)->GetTextData(wsTextData); + CFX_WideString wsTextData = + static_cast<CFDE_XMLElement*>(pXMLChild)->GetTextData(); wsTextData += L"\n"; wsOutput += wsTextData; break; @@ -253,13 +251,8 @@ const XFA_PACKETINFO* GetPacketByName(const CFX_WideStringC& wsName) { } // namespace bool XFA_RecognizeRichText(CFDE_XMLElement* pRichTextXMLNode) { - if (pRichTextXMLNode) { - CFX_WideString wsNamespaceURI; - GetElementTagNamespaceURI(pRichTextXMLNode, wsNamespaceURI); - if (wsNamespaceURI == L"http://www.w3.org/1999/xhtml") - return true; - } - return false; + return pRichTextXMLNode && GetElementTagNamespaceURI(pRichTextXMLNode) == + L"http://www.w3.org/1999/xhtml"; } CXFA_SimpleParser::CXFA_SimpleParser(CXFA_Document* pFactory, @@ -318,6 +311,7 @@ int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) { m_pRootNode = ParseAsXDPPacket(GetDocumentNode(m_pXMLDoc.get()), m_ePacketID); m_pXMLDoc->CloseXML(); m_pStream.Reset(); + if (!m_pRootNode) return XFA_PARSESTATUS_StatusErr; @@ -368,9 +362,8 @@ void CXFA_SimpleParser::ConstructXFANode(CXFA_Node* pXFANode, if (!pXFAChild) return; - CFX_WideString wsNodeStr; CFDE_XMLElement* child = static_cast<CFDE_XMLElement*>(pXMLChild); - child->GetLocalTagName(wsNodeStr); + CFX_WideString wsNodeStr = child->GetLocalTagName(); pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr); CFX_WideString wsChildValue; XFA_GetPlainTextFromRichText(child, wsChildValue); @@ -406,7 +399,7 @@ CFDE_XMLDoc* CXFA_SimpleParser::GetXMLDoc() const { bool XFA_FDEExtension_ResolveNamespaceQualifier( CFDE_XMLElement* pNode, const CFX_WideStringC& wsQualifier, - CFX_WideString& wsNamespaceURI) { + CFX_WideString* wsNamespaceURI) { if (!pNode) return false; @@ -425,11 +418,11 @@ bool XFA_FDEExtension_ResolveNamespaceQualifier( continue; if (pNode->HasAttribute(wsNSAttribute.c_str())) { - pNode->GetString(wsNSAttribute.c_str(), wsNamespaceURI); + *wsNamespaceURI = pNode->GetString(wsNSAttribute.c_str()); return true; } } - wsNamespaceURI.clear(); + wsNamespaceURI->clear(); return bRet; } @@ -468,6 +461,7 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP( XFA_GetPacketByIndex(XFA_PACKET_XDP)->eFlags)) { return nullptr; } + CXFA_Node* pXFARootNode = m_pFactory->CreateNode(XFA_XDPPACKET_XDP, XFA_Element::Xfa); if (!pXFARootNode) @@ -475,109 +469,98 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP( m_pRootNode = pXFARootNode; pXFARootNode->SetCData(XFA_ATTRIBUTE_Name, L"xfa"); - { - CFDE_XMLElement* pElement = static_cast<CFDE_XMLElement*>(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 == L"uuid") - pXFARootNode->SetCData(XFA_ATTRIBUTE_Uuid, wsAttriValue); - else if (wsAttriName == L"timeStamp") - pXFARootNode->SetCData(XFA_ATTRIBUTE_TimeStamp, wsAttriValue); - } + + CFDE_XMLElement* pElement = static_cast<CFDE_XMLElement*>(pXMLDocumentNode); + for (auto it : pElement->GetAttributes()) { + if (it.first == L"uuid") + pXFARootNode->SetCData(XFA_ATTRIBUTE_Uuid, it.second); + else if (it.first == L"timeStamp") + pXFARootNode->SetCData(XFA_ATTRIBUTE_TimeStamp, it.second); } 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 (!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); + 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 (!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; + 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<CFDE_XMLElement*>(pChildItem); - CFX_WideString wsPacketName; - pElement->GetLocalTagName(wsPacketName); - const XFA_PACKETINFO* pPacketInfo = - GetPacketByName(wsPacketName.AsStringC()); - if (pPacketInfo && pPacketInfo->pURI) { - if (!MatchNodeName(pElement, pPacketInfo->pName, pPacketInfo->pURI, - pPacketInfo->eFlags)) { - pPacketInfo = nullptr; - } + CFDE_XMLElement* pElement = reinterpret_cast<CFDE_XMLElement*>(pChildItem); + CFX_WideString wsPacketName = pElement->GetLocalTagName(); + const XFA_PACKETINFO* pPacketInfo = + GetPacketByName(wsPacketName.AsStringC()); + if (pPacketInfo && pPacketInfo->pURI) { + if (!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; + } + 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; + 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. + pXMLFormDOMRoot = pElement; + } else if (ePacket == XFA_XDPPACKET_Template) { + // Found a duplicate template packet. + if (pXMLTemplateDOMRoot) + 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; } - 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); - } + pXFARootNode->InsertChild(pPacketNode); } } } - if (!pXMLTemplateDOMRoot) { - // No template is found. + // No template is found. + if (!pXMLTemplateDOMRoot) return nullptr; - } + if (pXMLDatasetsDOMRoot) { CXFA_Node* pPacketNode = ParseAsXDPPacket(pXMLDatasetsDOMRoot, XFA_XDPPACKET_Datasets); @@ -590,6 +573,7 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP( if (pPacketNode) pXFARootNode->InsertChild(pPacketNode); } + pXFARootNode->SetXMLMappingNode(pXMLDocumentNode); return pXFARootNode; } @@ -634,12 +618,11 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm( pNode->SetCData(XFA_ATTRIBUTE_Name, XFA_GetPacketByIndex(XFA_PACKET_Template)->pName); if (m_bDocumentParser) { - CFX_WideString wsNamespaceURI; CFDE_XMLElement* pXMLDocumentElement = static_cast<CFDE_XMLElement*>(pXMLDocumentNode); - pXMLDocumentElement->GetNamespaceURI(wsNamespaceURI); + CFX_WideString wsNamespaceURI = pXMLDocumentElement->GetNamespaceURI(); if (wsNamespaceURI.IsEmpty()) - pXMLDocumentElement->GetString(L"xmlns:xfa", wsNamespaceURI); + wsNamespaceURI = pXMLDocumentElement->GetString(L"xmlns:xfa"); pNode->GetDocument()->RecognizeXFAVersionNumber(wsNamespaceURI); } @@ -653,8 +636,7 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm( XFA_GetPacketByIndex(XFA_PACKET_Form)->eFlags)) { CFDE_XMLElement* pXMLDocumentElement = static_cast<CFDE_XMLElement*>(pXMLDocumentNode); - CFX_WideString wsChecksum; - pXMLDocumentElement->GetString(L"checksum", wsChecksum); + CFX_WideString wsChecksum = pXMLDocumentElement->GetString(L"checksum"); if (wsChecksum.GetLength() != 28 || m_pXMLParser->m_dwCheckStatus != 0x03) { return nullptr; @@ -750,8 +732,8 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Data( delete pDataXMLNode; return nullptr; } - CFX_WideString wsLocalName; - static_cast<CFDE_XMLElement*>(pDataXMLNode)->GetLocalTagName(wsLocalName); + CFX_WideString wsLocalName = + static_cast<CFDE_XMLElement*>(pDataXMLNode)->GetLocalTagName(); pNode->SetCData(XFA_ATTRIBUTE_Name, wsLocalName); if (!DataLoader(pNode, pDataXMLNode, true)) return nullptr; @@ -847,8 +829,8 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_User( if (!pNode) return nullptr; - CFX_WideString wsName; - static_cast<CFDE_XMLElement*>(pXMLDocumentNode)->GetLocalTagName(wsName); + CFX_WideString wsName = + static_cast<CFDE_XMLElement*>(pXMLDocumentNode)->GetLocalTagName(); pNode->SetCData(XFA_ATTRIBUTE_Name, wsName); if (!UserPacketLoader(pNode, pXMLDocumentNode)) return nullptr; @@ -880,8 +862,7 @@ CXFA_Node* CXFA_SimpleParser::NormalLoader(CXFA_Node* pXFANode, switch (pXMLChild->GetType()) { case FDE_XMLNODE_Element: { CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLChild); - CFX_WideString wsTagName; - pXMLElement->GetLocalTagName(wsTagName); + CFX_WideString wsTagName = pXMLElement->GetLocalTagName(); XFA_Element eType = XFA_GetElementTypeForName(wsTagName.AsStringC()); if (eType == XFA_Element::Unknown) continue; @@ -903,16 +884,12 @@ CXFA_Node* CXFA_SimpleParser::NormalLoader(CXFA_Node* pXFANode, pXFAChild->SetAttribute(XFA_ATTRIBUTE_Name, wsTagName.AsStringC()); bool IsNeedValue = true; - for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count; - i++) { - CFX_WideString wsAttrQualifiedName; + for (auto it : pXMLElement->GetAttributes()) { CFX_WideString wsAttrName; - CFX_WideString wsAttrValue; - pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue); - GetAttributeLocalName(wsAttrQualifiedName.AsStringC(), wsAttrName); - if (wsAttrName == L"nil" && wsAttrValue == L"true") { + GetAttributeLocalName(it.first.AsStringC(), wsAttrName); + if (wsAttrName == L"nil" && it.second == L"true") IsNeedValue = false; - } + const XFA_ATTRIBUTEINFO* lpAttrInfo = XFA_GetAttributeByName(wsAttrName.AsStringC()); if (!lpAttrInfo) @@ -922,7 +899,7 @@ CXFA_Node* CXFA_SimpleParser::NormalLoader(CXFA_Node* pXFANode, lpAttrInfo->eName != XFA_ATTRIBUTE_Save) { continue; } - pXFAChild->SetAttribute(lpAttrInfo->eName, wsAttrValue.AsStringC()); + pXFAChild->SetAttribute(lpAttrInfo->eName, it.second.AsStringC()); } pXFANode->InsertChild(pXFAChild); if (eType == XFA_Element::Validate || eType == XFA_Element::Locale) { @@ -1025,8 +1002,8 @@ void CXFA_SimpleParser::ParseDataGroup(CXFA_Node* pXFANode, case FDE_XMLNODE_Element: { CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLChild); { - CFX_WideString wsNamespaceURI; - GetElementTagNamespaceURI(pXMLElement, wsNamespaceURI); + CFX_WideString wsNamespaceURI = + GetElementTagNamespaceURI(pXMLElement); if (wsNamespaceURI == L"http://www.xfa.com/schema/xfa-package/" || wsNamespaceURI == L"http://www.xfa.org/schema/xfa-package/" || wsNamespaceURI == L"http://www.w3.org/2001/XMLSchema-instance") { @@ -1077,21 +1054,17 @@ void CXFA_SimpleParser::ParseDataGroup(CXFA_Node* pXFANode, if (!pXFAChild) return; - CFX_WideString wsNodeName; - pXMLElement->GetLocalTagName(wsNodeName); - pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeName); + pXFAChild->SetCData(XFA_ATTRIBUTE_Name, pXMLElement->GetLocalTagName()); bool bNeedValue = true; - for (int32_t i = 0; i < pXMLElement->CountAttributes(); ++i) { - CFX_WideString wsQualifiedName; - CFX_WideString wsValue; + + for (auto it : pXMLElement->GetAttributes()) { CFX_WideString wsName; CFX_WideString wsNS; - pXMLElement->GetAttribute(i, wsQualifiedName, wsValue); - if (!ResolveAttribute(pXMLElement, wsQualifiedName.AsStringC(), - wsName, wsNS)) { + if (!ResolveAttribute(pXMLElement, it.first.AsStringC(), wsName, + wsNS)) { continue; } - if (wsName == L"nil" && wsValue == L"true") { + if (wsName == L"nil" && it.second == L"true") { bNeedValue = false; continue; } @@ -1107,8 +1080,8 @@ void CXFA_SimpleParser::ParseDataGroup(CXFA_Node* pXFANode, return; pXFAMetaData->SetCData(XFA_ATTRIBUTE_Name, wsName); - pXFAMetaData->SetCData(XFA_ATTRIBUTE_QualifiedName, wsQualifiedName); - pXFAMetaData->SetCData(XFA_ATTRIBUTE_Value, wsValue); + pXFAMetaData->SetCData(XFA_ATTRIBUTE_QualifiedName, it.first); + pXFAMetaData->SetCData(XFA_ATTRIBUTE_Value, it.second); pXFAMetaData->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_MetaData); pXFAChild->InsertChild(pXFAMetaData); @@ -1209,8 +1182,8 @@ void CXFA_SimpleParser::ParseDataValue(CXFA_Node* pXFANode, if (!pXFAChild) return; - CFX_WideString wsNodeStr; - static_cast<CFDE_XMLElement*>(pXMLChild)->GetLocalTagName(wsNodeStr); + CFX_WideString wsNodeStr = + static_cast<CFDE_XMLElement*>(pXMLChild)->GetLocalTagName(); pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr); ParseDataValue(pXFAChild, pXMLChild, ePacketID); pXFANode->InsertChild(pXFAChild); @@ -1250,25 +1223,20 @@ void CXFA_SimpleParser::ParseInstruction(CXFA_Node* pXFANode, if (!m_bDocumentParser) return; - CFX_WideString wsTargetName; - pXMLInstruction->GetTargetName(wsTargetName); + CFX_WideString wsTargetName = pXMLInstruction->GetName(); + const std::vector<CFX_WideString>& target_data = + pXMLInstruction->GetTargetData(); if (wsTargetName == 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 == L"v2.7-scripting:1") { - pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_Scripting, true); - } + if (target_data.size() > 1 && + (pXFANode->GetDocument()->RecognizeXFAVersionNumber(target_data[0]) != + XFA_VERSION_UNKNOWN) && + target_data[1] == L"v2.7-scripting:1") { + pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_Scripting, true); } } else if (wsTargetName == L"acrobat") { - CFX_WideString wsData; - if (pXMLInstruction->GetData(0, wsData) && wsData == L"JavaScript") { - if (pXMLInstruction->GetData(1, wsData) && wsData == L"strictScoping") { - pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, true); - } + if (target_data.size() > 1 && target_data[0] == L"JavaScript" && + target_data[1] == L"strictScoping") { + pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, true); } } } diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp index eb16628a2e..82aec1f00d 100644 --- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp @@ -284,14 +284,15 @@ void CreateDataBinding(CXFA_Node* pFormNode, CFDE_XMLElement* pXMLDataElement = static_cast<CFDE_XMLElement*>(pDataNode->GetXMLMappingNode()); ASSERT(pXMLDataElement); - CFX_WideString wsContentType; - CFX_WideString wsHref; - pXMLDataElement->GetString(L"xfa:contentType", wsContentType); + + CFX_WideString wsContentType = + pXMLDataElement->GetString(L"xfa:contentType"); if (!wsContentType.IsEmpty()) { pDataNode->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType); image.SetContentType(wsContentType); } - pXMLDataElement->GetString(L"href", wsHref); + + CFX_WideString wsHref = pXMLDataElement->GetString(L"href"); if (!wsHref.IsEmpty()) image.SetHref(wsHref); } diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp index 57d97519a1..6bd04c322f 100644 --- a/xfa/fxfa/parser/xfa_utils.cpp +++ b/xfa/fxfa/parser/xfa_utils.cpp @@ -177,8 +177,7 @@ void XFA_GetPlainTextFromRichText(CFDE_XMLNode* pXMLNode, switch (pXMLNode->GetType()) { case FDE_XMLNODE_Element: { CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); - CFX_WideString wsTag; - pXMLElement->GetLocalTagName(wsTag); + CFX_WideString wsTag = pXMLElement->GetLocalTagName(); uint32_t uTag = FX_HashCode_GetW(wsTag.AsStringC(), true); if (uTag == 0x0001f714) { wsPlainText += L"\n"; diff --git a/xfa/fxfa/parser/xfa_utils.h b/xfa/fxfa/parser/xfa_utils.h index d4461a39a7..36d62c7602 100644 --- a/xfa/fxfa/parser/xfa_utils.h +++ b/xfa/fxfa/parser/xfa_utils.h @@ -22,7 +22,7 @@ int XFA_GetMaxFractionalScale(); bool XFA_FDEExtension_ResolveNamespaceQualifier( CFDE_XMLElement* pNode, const CFX_WideStringC& wsQualifier, - CFX_WideString& wsNamespaceURI); + CFX_WideString* wsNamespaceURI); template <class NodeType, class TraverseStrategy> class CXFA_NodeIteratorTemplate { |