Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: xfa/fxfa/parser/xfa_parser_imp.cpp

Issue 1890563003: Simplify XFA event handling. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: address comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fxfa/parser/xfa_object_imp.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/fxfa/parser/xfa_parser_imp.h" 7 #include "xfa/fxfa/parser/xfa_parser_imp.h"
8 8
9 #include "xfa/fde/xml/fde_xml_imp.h" 9 #include "xfa/fde/xml/fde_xml_imp.h"
10 #include "xfa/fgas/crt/fgas_codepage.h" 10 #include "xfa/fgas/crt/fgas_codepage.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 CFDE_XMLElement* child = static_cast<CFDE_XMLElement*>(pXMLChild); 168 CFDE_XMLElement* child = static_cast<CFDE_XMLElement*>(pXMLChild);
169 child->GetLocalTagName(wsNodeStr); 169 child->GetLocalTagName(wsNodeStr);
170 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr); 170 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr);
171 CFX_WideString wsChildValue; 171 CFX_WideString wsChildValue;
172 XFA_GetPlainTextFromRichText(child, wsChildValue); 172 XFA_GetPlainTextFromRichText(child, wsChildValue);
173 if (!wsChildValue.IsEmpty()) 173 if (!wsChildValue.IsEmpty())
174 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsChildValue); 174 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsChildValue);
175 175
176 pXFANode->InsertChild(pXFAChild); 176 pXFANode->InsertChild(pXFAChild);
177 pXFAChild->SetXMLMappingNode(pXMLChild); 177 pXFAChild->SetXMLMappingNode(pXMLChild);
178 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE); 178 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, false);
179 break; 179 break;
180 } 180 }
181 } 181 }
182 m_pRootNode = pXFANode; 182 m_pRootNode = pXFANode;
183 } else { 183 } else {
184 m_pRootNode = DataLoader(pXFANode, pXMLNode, TRUE); 184 m_pRootNode = DataLoader(pXFANode, pXMLNode, TRUE);
185 } 185 }
186 } else if (pXFANode->GetObjectType() == XFA_OBJECTTYPE_ContentNode) { 186 } else if (pXFANode->GetObjectType() == XFA_OBJECTTYPE_ContentNode) {
187 ParseContentNode(pXFANode, pXMLNode, ePacketID); 187 ParseContentNode(pXFANode, pXMLNode, ePacketID);
188 m_pRootNode = pXFANode; 188 m_pRootNode = pXFANode;
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 return NULL; 687 return NULL;
688 } 688 }
689 CFX_WideString wsLocalName; 689 CFX_WideString wsLocalName;
690 static_cast<CFDE_XMLElement*>(pDataXMLNode)->GetLocalTagName(wsLocalName); 690 static_cast<CFDE_XMLElement*>(pDataXMLNode)->GetLocalTagName(wsLocalName);
691 pNode->SetCData(XFA_ATTRIBUTE_Name, wsLocalName); 691 pNode->SetCData(XFA_ATTRIBUTE_Name, wsLocalName);
692 if (!DataLoader(pNode, pDataXMLNode, TRUE)) { 692 if (!DataLoader(pNode, pDataXMLNode, TRUE)) {
693 return NULL; 693 return NULL;
694 } 694 }
695 pNode->SetXMLMappingNode(pDataXMLNode); 695 pNode->SetXMLMappingNode(pDataXMLNode);
696 if (pDataXMLNode != pXMLDocumentNode) { 696 if (pDataXMLNode != pXMLDocumentNode) {
697 pNode->SetFlag(XFA_NODEFLAG_OwnXMLNode, TRUE, FALSE); 697 pNode->SetFlag(XFA_NODEFLAG_OwnXMLNode, false);
698 } 698 }
699 return pNode; 699 return pNode;
700 } 700 }
701 return NULL; 701 return NULL;
702 } 702 }
703 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_LocaleConnectionSourceSet( 703 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_LocaleConnectionSourceSet(
704 CFDE_XMLNode* pXMLDocumentNode, 704 CFDE_XMLNode* pXMLDocumentNode,
705 XFA_XDPPACKET ePacketID) { 705 XFA_XDPPACKET ePacketID) {
706 CXFA_Node* pNode = NULL; 706 CXFA_Node* pNode = NULL;
707 if (ePacketID == XFA_XDPPACKET_LocaleSet) { 707 if (ePacketID == XFA_XDPPACKET_LocaleSet) {
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 return; 1138 return;
1139 } 1139 }
1140 pXFAMetaData->SetCData(XFA_ATTRIBUTE_Name, wsAttrName); 1140 pXFAMetaData->SetCData(XFA_ATTRIBUTE_Name, wsAttrName);
1141 pXFAMetaData->SetCData(XFA_ATTRIBUTE_QualifiedName, 1141 pXFAMetaData->SetCData(XFA_ATTRIBUTE_QualifiedName,
1142 wsAttrQualifiedName); 1142 wsAttrQualifiedName);
1143 pXFAMetaData->SetCData(XFA_ATTRIBUTE_Value, wsAttrValue); 1143 pXFAMetaData->SetCData(XFA_ATTRIBUTE_Value, wsAttrValue);
1144 pXFAMetaData->SetEnum(XFA_ATTRIBUTE_Contains, 1144 pXFAMetaData->SetEnum(XFA_ATTRIBUTE_Contains,
1145 XFA_ATTRIBUTEENUM_MetaData); 1145 XFA_ATTRIBUTEENUM_MetaData);
1146 pXFAChild->InsertChild(pXFAMetaData); 1146 pXFAChild->InsertChild(pXFAMetaData);
1147 pXFAMetaData->SetXMLMappingNode(pXMLElement); 1147 pXFAMetaData->SetXMLMappingNode(pXMLElement);
1148 pXFAMetaData->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE); 1148 pXFAMetaData->SetFlag(XFA_NODEFLAG_Initialized, false);
1149 } 1149 }
1150 if (!bNeedValue) { 1150 if (!bNeedValue) {
1151 CFX_WideString wsNilName = FX_WSTRC(L"xsi:nil"); 1151 CFX_WideString wsNilName = FX_WSTRC(L"xsi:nil");
1152 pXMLElement->RemoveAttribute(wsNilName.c_str()); 1152 pXMLElement->RemoveAttribute(wsNilName.c_str());
1153 } 1153 }
1154 } 1154 }
1155 pXFANode->InsertChild(pXFAChild); 1155 pXFANode->InsertChild(pXFAChild);
1156 if (eNodeType == XFA_ELEMENT_DataGroup) { 1156 if (eNodeType == XFA_ELEMENT_DataGroup) {
1157 ParseDataGroup(pXFAChild, pXMLElement, ePacketID); 1157 ParseDataGroup(pXFAChild, pXMLElement, ePacketID);
1158 } else { 1158 } else {
1159 if (bNeedValue) { 1159 if (bNeedValue) {
1160 ParseDataValue(pXFAChild, pXMLChild, XFA_XDPPACKET_Datasets); 1160 ParseDataValue(pXFAChild, pXMLChild, XFA_XDPPACKET_Datasets);
1161 } 1161 }
1162 } 1162 }
1163 pXFAChild->SetXMLMappingNode(pXMLElement); 1163 pXFAChild->SetXMLMappingNode(pXMLElement);
1164 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE); 1164 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, false);
1165 } 1165 }
1166 continue; 1166 continue;
1167 case FDE_XMLNODE_CharData: { 1167 case FDE_XMLNODE_CharData: {
1168 CFDE_XMLCharData* pXMLCharData = 1168 CFDE_XMLCharData* pXMLCharData =
1169 static_cast<CFDE_XMLCharData*>(pXMLChild); 1169 static_cast<CFDE_XMLCharData*>(pXMLChild);
1170 CFX_WideString wsCharData; 1170 CFX_WideString wsCharData;
1171 pXMLCharData->GetCharData(wsCharData); 1171 pXMLCharData->GetCharData(wsCharData);
1172 if (XFA_FDEExtension_IsStringAllWhitespace(wsCharData)) { 1172 if (XFA_FDEExtension_IsStringAllWhitespace(wsCharData)) {
1173 continue; 1173 continue;
1174 } 1174 }
1175 CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, 1175 CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets,
1176 XFA_ELEMENT_DataValue); 1176 XFA_ELEMENT_DataValue);
1177 if (pXFAChild == NULL) { 1177 if (pXFAChild == NULL) {
1178 return; 1178 return;
1179 } 1179 }
1180 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCharData); 1180 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCharData);
1181 pXFANode->InsertChild(pXFAChild); 1181 pXFANode->InsertChild(pXFAChild);
1182 pXFAChild->SetXMLMappingNode(pXMLCharData); 1182 pXFAChild->SetXMLMappingNode(pXMLCharData);
1183 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE); 1183 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, false);
1184 } 1184 }
1185 continue; 1185 continue;
1186 case FDE_XMLNODE_Text: { 1186 case FDE_XMLNODE_Text: {
1187 CFDE_XMLText* pXMLText = static_cast<CFDE_XMLText*>(pXMLChild); 1187 CFDE_XMLText* pXMLText = static_cast<CFDE_XMLText*>(pXMLChild);
1188 CFX_WideString wsText; 1188 CFX_WideString wsText;
1189 pXMLText->GetText(wsText); 1189 pXMLText->GetText(wsText);
1190 if (XFA_FDEExtension_IsStringAllWhitespace(wsText)) { 1190 if (XFA_FDEExtension_IsStringAllWhitespace(wsText)) {
1191 continue; 1191 continue;
1192 } 1192 }
1193 CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, 1193 CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets,
1194 XFA_ELEMENT_DataValue); 1194 XFA_ELEMENT_DataValue);
1195 if (pXFAChild == NULL) { 1195 if (pXFAChild == NULL) {
1196 return; 1196 return;
1197 } 1197 }
1198 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsText); 1198 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsText);
1199 pXFANode->InsertChild(pXFAChild); 1199 pXFANode->InsertChild(pXFAChild);
1200 pXFAChild->SetXMLMappingNode(pXMLText); 1200 pXFAChild->SetXMLMappingNode(pXMLText);
1201 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE); 1201 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, false);
1202 } 1202 }
1203 continue; 1203 continue;
1204 case FDE_XMLNODE_Instruction: 1204 case FDE_XMLNODE_Instruction:
1205 continue; 1205 continue;
1206 default: 1206 default:
1207 continue; 1207 continue;
1208 } 1208 }
1209 } 1209 }
1210 } 1210 }
1211 1211
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 if (!wsCurValue.IsEmpty()) { 1252 if (!wsCurValue.IsEmpty()) {
1253 CXFA_Node* pXFAChild = 1253 CXFA_Node* pXFAChild =
1254 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue); 1254 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue);
1255 if (!pXFAChild) 1255 if (!pXFAChild)
1256 return; 1256 return;
1257 1257
1258 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L"")); 1258 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L""));
1259 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCurValue); 1259 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCurValue);
1260 pXFANode->InsertChild(pXFAChild); 1260 pXFANode->InsertChild(pXFAChild);
1261 pXFAChild->SetXMLMappingNode(pXMLCurValueNode); 1261 pXFAChild->SetXMLMappingNode(pXMLCurValueNode);
1262 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE); 1262 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, false);
1263 wsValueTextBuf << wsCurValue; 1263 wsValueTextBuf << wsCurValue;
1264 wsCurValueTextBuf.Clear(); 1264 wsCurValueTextBuf.Clear();
1265 } 1265 }
1266 pXMLCurValueNode = nullptr; 1266 pXMLCurValueNode = nullptr;
1267 } 1267 }
1268 CXFA_Node* pXFAChild = 1268 CXFA_Node* pXFAChild =
1269 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue); 1269 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue);
1270 if (!pXFAChild) 1270 if (!pXFAChild)
1271 return; 1271 return;
1272 1272
1273 CFX_WideString wsNodeStr; 1273 CFX_WideString wsNodeStr;
1274 static_cast<CFDE_XMLElement*>(pXMLChild)->GetLocalTagName(wsNodeStr); 1274 static_cast<CFDE_XMLElement*>(pXMLChild)->GetLocalTagName(wsNodeStr);
1275 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr); 1275 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr);
1276 ParseDataValue(pXFAChild, pXMLChild, ePacketID); 1276 ParseDataValue(pXFAChild, pXMLChild, ePacketID);
1277 pXFANode->InsertChild(pXFAChild); 1277 pXFANode->InsertChild(pXFAChild);
1278 pXFAChild->SetXMLMappingNode(pXMLChild); 1278 pXFAChild->SetXMLMappingNode(pXMLChild);
1279 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE); 1279 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, false);
1280 CFX_WideStringC wsCurValue = pXFAChild->GetCData(XFA_ATTRIBUTE_Value); 1280 CFX_WideStringC wsCurValue = pXFAChild->GetCData(XFA_ATTRIBUTE_Value);
1281 wsValueTextBuf << wsCurValue; 1281 wsValueTextBuf << wsCurValue;
1282 } 1282 }
1283 } 1283 }
1284 if (pXMLCurValueNode) { 1284 if (pXMLCurValueNode) {
1285 CFX_WideStringC wsCurValue = wsCurValueTextBuf.GetWideString(); 1285 CFX_WideStringC wsCurValue = wsCurValueTextBuf.GetWideString();
1286 if (!wsCurValue.IsEmpty()) { 1286 if (!wsCurValue.IsEmpty()) {
1287 if (bMarkAsCompound) { 1287 if (bMarkAsCompound) {
1288 CXFA_Node* pXFAChild = 1288 CXFA_Node* pXFAChild =
1289 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue); 1289 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue);
1290 if (!pXFAChild) 1290 if (!pXFAChild)
1291 return; 1291 return;
1292 1292
1293 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L"")); 1293 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L""));
1294 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCurValue); 1294 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCurValue);
1295 pXFANode->InsertChild(pXFAChild); 1295 pXFANode->InsertChild(pXFAChild);
1296 pXFAChild->SetXMLMappingNode(pXMLCurValueNode); 1296 pXFAChild->SetXMLMappingNode(pXMLCurValueNode);
1297 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE); 1297 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, false);
1298 } 1298 }
1299 wsValueTextBuf << wsCurValue; 1299 wsValueTextBuf << wsCurValue;
1300 wsCurValueTextBuf.Clear(); 1300 wsCurValueTextBuf.Clear();
1301 } 1301 }
1302 pXMLCurValueNode = nullptr; 1302 pXMLCurValueNode = nullptr;
1303 } 1303 }
1304 CFX_WideStringC wsNodeValue = wsValueTextBuf.GetWideString(); 1304 CFX_WideStringC wsNodeValue = wsValueTextBuf.GetWideString();
1305 pXFANode->SetCData(XFA_ATTRIBUTE_Value, wsNodeValue); 1305 pXFANode->SetCData(XFA_ATTRIBUTE_Value, wsNodeValue);
1306 } 1306 }
1307 1307
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 } 1557 }
1558 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { 1558 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) {
1559 break; 1559 break;
1560 } 1560 }
1561 } 1561 }
1562 return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || 1562 return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error ||
1563 m_NodeStack.GetSize() != 1) 1563 m_NodeStack.GetSize() != 1)
1564 ? -1 1564 ? -1
1565 : m_pParser->GetStatus(); 1565 : m_pParser->GetStatus();
1566 } 1566 }
OLDNEW
« no previous file with comments | « xfa/fxfa/parser/xfa_object_imp.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698