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

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

Issue 2467203003: Remove FX_BOOL from xfa. (Closed)
Patch Set: Created 4 years, 1 month 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/cxfa_dataexporter.h ('k') | xfa/fxfa/parser/cxfa_dataimporter.h » ('j') | 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/cxfa_dataexporter.h" 7 #include "xfa/fxfa/parser/cxfa_dataexporter.h"
8 8
9 #include "core/fxcrt/fx_basic.h" 9 #include "core/fxcrt/fx_basic.h"
10 #include "xfa/fde/xml/fde_xml_imp.h" 10 #include "xfa/fde/xml/fde_xml_imp.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } else { 69 } else {
70 textBuf.AppendChar(str.GetAt(i)); 70 textBuf.AppendChar(str.GetAt(i));
71 } 71 }
72 } 72 }
73 return textBuf.MakeString(); 73 return textBuf.MakeString();
74 } 74 }
75 75
76 void SaveAttribute(CXFA_Node* pNode, 76 void SaveAttribute(CXFA_Node* pNode,
77 XFA_ATTRIBUTE eName, 77 XFA_ATTRIBUTE eName,
78 const CFX_WideStringC& wsName, 78 const CFX_WideStringC& wsName,
79 FX_BOOL bProto, 79 bool bProto,
80 CFX_WideString& wsOutput) { 80 CFX_WideString& wsOutput) {
81 CFX_WideString wsValue; 81 CFX_WideString wsValue;
82 if ((!bProto && !pNode->HasAttribute((XFA_ATTRIBUTE)eName, bProto)) || 82 if ((!bProto && !pNode->HasAttribute((XFA_ATTRIBUTE)eName, bProto)) ||
83 !pNode->GetAttribute((XFA_ATTRIBUTE)eName, wsValue, FALSE)) { 83 !pNode->GetAttribute((XFA_ATTRIBUTE)eName, wsValue, false)) {
84 return; 84 return;
85 } 85 }
86 wsValue = ExportEncodeAttribute(wsValue); 86 wsValue = ExportEncodeAttribute(wsValue);
87 wsOutput += FX_WSTRC(L" "); 87 wsOutput += FX_WSTRC(L" ");
88 wsOutput += wsName; 88 wsOutput += wsName;
89 wsOutput += FX_WSTRC(L"=\""); 89 wsOutput += FX_WSTRC(L"=\"");
90 wsOutput += wsValue; 90 wsOutput += wsValue;
91 wsOutput += FX_WSTRC(L"\""); 91 wsOutput += FX_WSTRC(L"\"");
92 } 92 }
93 93
94 FX_BOOL AttributeSaveInDataModel(CXFA_Node* pNode, XFA_ATTRIBUTE eAttribute) { 94 bool AttributeSaveInDataModel(CXFA_Node* pNode, XFA_ATTRIBUTE eAttribute) {
95 FX_BOOL bSaveInDataModel = FALSE; 95 bool bSaveInDataModel = false;
96 if (pNode->GetElementType() != XFA_Element::Image) 96 if (pNode->GetElementType() != XFA_Element::Image)
97 return bSaveInDataModel; 97 return bSaveInDataModel;
98 98
99 CXFA_Node* pValueNode = pNode->GetNodeItem(XFA_NODEITEM_Parent); 99 CXFA_Node* pValueNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
100 if (!pValueNode || pValueNode->GetElementType() != XFA_Element::Value) 100 if (!pValueNode || pValueNode->GetElementType() != XFA_Element::Value)
101 return bSaveInDataModel; 101 return bSaveInDataModel;
102 102
103 CXFA_Node* pFieldNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent); 103 CXFA_Node* pFieldNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
104 if (pFieldNode && pFieldNode->GetBindData() && 104 if (pFieldNode && pFieldNode->GetBindData() &&
105 eAttribute == XFA_ATTRIBUTE_Href) { 105 eAttribute == XFA_ATTRIBUTE_Href) {
106 bSaveInDataModel = TRUE; 106 bSaveInDataModel = true;
107 } 107 }
108 return bSaveInDataModel; 108 return bSaveInDataModel;
109 } 109 }
110 110
111 FX_BOOL ContentNodeNeedtoExport(CXFA_Node* pContentNode) { 111 bool ContentNodeNeedtoExport(CXFA_Node* pContentNode) {
112 CFX_WideString wsContent; 112 CFX_WideString wsContent;
113 if (!pContentNode->TryContent(wsContent, FALSE, FALSE)) 113 if (!pContentNode->TryContent(wsContent, false, false))
114 return FALSE; 114 return false;
115 115
116 ASSERT(pContentNode->IsContentNode()); 116 ASSERT(pContentNode->IsContentNode());
117 CXFA_Node* pParentNode = pContentNode->GetNodeItem(XFA_NODEITEM_Parent); 117 CXFA_Node* pParentNode = pContentNode->GetNodeItem(XFA_NODEITEM_Parent);
118 if (!pParentNode || pParentNode->GetElementType() != XFA_Element::Value) 118 if (!pParentNode || pParentNode->GetElementType() != XFA_Element::Value)
119 return TRUE; 119 return true;
120 120
121 CXFA_Node* pGrandParentNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent); 121 CXFA_Node* pGrandParentNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
122 if (!pGrandParentNode || !pGrandParentNode->IsContainerNode()) 122 if (!pGrandParentNode || !pGrandParentNode->IsContainerNode())
123 return TRUE; 123 return true;
124 if (pGrandParentNode->GetBindData()) 124 if (pGrandParentNode->GetBindData())
125 return FALSE; 125 return false;
126 126
127 CXFA_WidgetData* pWidgetData = pGrandParentNode->GetWidgetData(); 127 CXFA_WidgetData* pWidgetData = pGrandParentNode->GetWidgetData();
128 XFA_Element eUIType = pWidgetData->GetUIType(); 128 XFA_Element eUIType = pWidgetData->GetUIType();
129 if (eUIType == XFA_Element::PasswordEdit) 129 if (eUIType == XFA_Element::PasswordEdit)
130 return FALSE; 130 return false;
131 return TRUE; 131 return true;
132 } 132 }
133 133
134 void RecognizeXFAVersionNumber(CXFA_Node* pTemplateRoot, 134 void RecognizeXFAVersionNumber(CXFA_Node* pTemplateRoot,
135 CFX_WideString& wsVersionNumber) { 135 CFX_WideString& wsVersionNumber) {
136 wsVersionNumber.clear(); 136 wsVersionNumber.clear();
137 if (!pTemplateRoot) 137 if (!pTemplateRoot)
138 return; 138 return;
139 139
140 CFX_WideString wsTemplateNS; 140 CFX_WideString wsTemplateNS;
141 if (!pTemplateRoot->TryNamespace(wsTemplateNS)) 141 if (!pTemplateRoot->TryNamespace(wsTemplateNS))
142 return; 142 return;
143 143
144 XFA_VERSION eVersion = 144 XFA_VERSION eVersion =
145 pTemplateRoot->GetDocument()->RecognizeXFAVersionNumber(wsTemplateNS); 145 pTemplateRoot->GetDocument()->RecognizeXFAVersionNumber(wsTemplateNS);
146 if (eVersion == XFA_VERSION_UNKNOWN) 146 if (eVersion == XFA_VERSION_UNKNOWN)
147 eVersion = XFA_VERSION_DEFAULT; 147 eVersion = XFA_VERSION_DEFAULT;
148 148
149 wsVersionNumber.Format(L"%i.%i", eVersion / 100, eVersion % 100); 149 wsVersionNumber.Format(L"%i.%i", eVersion / 100, eVersion % 100);
150 } 150 }
151 151
152 void RegenerateFormFile_Changed(CXFA_Node* pNode, 152 void RegenerateFormFile_Changed(CXFA_Node* pNode,
153 CFX_WideTextBuf& buf, 153 CFX_WideTextBuf& buf,
154 FX_BOOL bSaveXML) { 154 bool bSaveXML) {
155 CFX_WideString wsAttrs; 155 CFX_WideString wsAttrs;
156 int32_t iAttrs = 0; 156 int32_t iAttrs = 0;
157 const uint8_t* pAttrs = 157 const uint8_t* pAttrs =
158 XFA_GetElementAttributes(pNode->GetElementType(), iAttrs); 158 XFA_GetElementAttributes(pNode->GetElementType(), iAttrs);
159 while (iAttrs--) { 159 while (iAttrs--) {
160 const XFA_ATTRIBUTEINFO* pAttr = 160 const XFA_ATTRIBUTEINFO* pAttr =
161 XFA_GetAttributeByID((XFA_ATTRIBUTE)pAttrs[iAttrs]); 161 XFA_GetAttributeByID((XFA_ATTRIBUTE)pAttrs[iAttrs]);
162 if (pAttr->eName == XFA_ATTRIBUTE_Name || 162 if (pAttr->eName == XFA_ATTRIBUTE_Name ||
163 (AttributeSaveInDataModel(pNode, pAttr->eName) && !bSaveXML)) { 163 (AttributeSaveInDataModel(pNode, pAttr->eName) && !bSaveXML)) {
164 continue; 164 continue;
(...skipping 13 matching lines...) Expand all
178 while (pRawValueNode && 178 while (pRawValueNode &&
179 pRawValueNode->GetElementType() != XFA_Element::SharpxHTML && 179 pRawValueNode->GetElementType() != XFA_Element::SharpxHTML &&
180 pRawValueNode->GetElementType() != XFA_Element::Sharptext && 180 pRawValueNode->GetElementType() != XFA_Element::Sharptext &&
181 pRawValueNode->GetElementType() != XFA_Element::Sharpxml) { 181 pRawValueNode->GetElementType() != XFA_Element::Sharpxml) {
182 pRawValueNode = pRawValueNode->GetNodeItem(XFA_NODEITEM_NextSibling); 182 pRawValueNode = pRawValueNode->GetNodeItem(XFA_NODEITEM_NextSibling);
183 } 183 }
184 if (!pRawValueNode) 184 if (!pRawValueNode)
185 break; 185 break;
186 186
187 CFX_WideString wsContentType; 187 CFX_WideString wsContentType;
188 pNode->GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE); 188 pNode->GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
189 if (pRawValueNode->GetElementType() == XFA_Element::SharpxHTML && 189 if (pRawValueNode->GetElementType() == XFA_Element::SharpxHTML &&
190 wsContentType == FX_WSTRC(L"text/html")) { 190 wsContentType == FX_WSTRC(L"text/html")) {
191 CFDE_XMLNode* pExDataXML = pNode->GetXMLMappingNode(); 191 CFDE_XMLNode* pExDataXML = pNode->GetXMLMappingNode();
192 if (!pExDataXML) 192 if (!pExDataXML)
193 break; 193 break;
194 194
195 CFDE_XMLNode* pRichTextXML = 195 CFDE_XMLNode* pRichTextXML =
196 pExDataXML->GetNodeItem(CFDE_XMLNode::FirstChild); 196 pExDataXML->GetNodeItem(CFDE_XMLNode::FirstChild);
197 if (!pRichTextXML) 197 if (!pRichTextXML)
198 break; 198 break;
199 199
200 IFX_MemoryStream* pMemStream = FX_CreateMemoryStream(TRUE); 200 IFX_MemoryStream* pMemStream = FX_CreateMemoryStream(true);
201 IFX_Stream* pTempStream = IFX_Stream::CreateStream( 201 IFX_Stream* pTempStream = IFX_Stream::CreateStream(
202 (IFX_SeekableWriteStream*)pMemStream, FX_STREAMACCESS_Text | 202 (IFX_SeekableWriteStream*)pMemStream, FX_STREAMACCESS_Text |
203 FX_STREAMACCESS_Write | 203 FX_STREAMACCESS_Write |
204 FX_STREAMACCESS_Append); 204 FX_STREAMACCESS_Append);
205 pTempStream->SetCodePage(FX_CODEPAGE_UTF8); 205 pTempStream->SetCodePage(FX_CODEPAGE_UTF8);
206 pRichTextXML->SaveXMLNode(pTempStream); 206 pRichTextXML->SaveXMLNode(pTempStream);
207 wsChildren += CFX_WideString::FromUTF8( 207 wsChildren += CFX_WideString::FromUTF8(
208 CFX_ByteStringC(pMemStream->GetBuffer(), pMemStream->GetSize())); 208 CFX_ByteStringC(pMemStream->GetBuffer(), pMemStream->GetSize()));
209 pTempStream->Release(); 209 pTempStream->Release();
210 pMemStream->Release(); 210 pMemStream->Release();
211 } else if (pRawValueNode->GetElementType() == XFA_Element::Sharpxml && 211 } else if (pRawValueNode->GetElementType() == XFA_Element::Sharpxml &&
212 wsContentType == FX_WSTRC(L"text/xml")) { 212 wsContentType == FX_WSTRC(L"text/xml")) {
213 CFX_WideString wsRawValue; 213 CFX_WideString wsRawValue;
214 pRawValueNode->GetAttribute(XFA_ATTRIBUTE_Value, wsRawValue, FALSE); 214 pRawValueNode->GetAttribute(XFA_ATTRIBUTE_Value, wsRawValue, false);
215 if (wsRawValue.IsEmpty()) 215 if (wsRawValue.IsEmpty())
216 break; 216 break;
217 217
218 CFX_WideStringArray wsSelTextArray; 218 CFX_WideStringArray wsSelTextArray;
219 int32_t iStart = 0; 219 int32_t iStart = 0;
220 int32_t iEnd = wsRawValue.Find(L'\n', iStart); 220 int32_t iEnd = wsRawValue.Find(L'\n', iStart);
221 iEnd = (iEnd == -1) ? wsRawValue.GetLength() : iEnd; 221 iEnd = (iEnd == -1) ? wsRawValue.GetLength() : iEnd;
222 while (iEnd >= iStart) { 222 while (iEnd >= iStart) {
223 wsSelTextArray.Add(wsRawValue.Mid(iStart, iEnd - iStart)); 223 wsSelTextArray.Add(wsRawValue.Mid(iStart, iEnd - iStart));
224 iStart = iEnd + 1; 224 iStart = iEnd + 1;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 CFX_WideStringC wsValue = pNode->GetCData(XFA_ATTRIBUTE_Value); 262 CFX_WideStringC wsValue = pNode->GetCData(XFA_ATTRIBUTE_Value);
263 wsChildren += ExportEncodeContent(wsValue); 263 wsChildren += ExportEncodeContent(wsValue);
264 break; 264 break;
265 } 265 }
266 default: 266 default:
267 if (pNode->GetElementType() == XFA_Element::Items) { 267 if (pNode->GetElementType() == XFA_Element::Items) {
268 CXFA_Node* pTemplateNode = pNode->GetTemplateNode(); 268 CXFA_Node* pTemplateNode = pNode->GetTemplateNode();
269 if (!pTemplateNode || 269 if (!pTemplateNode ||
270 pTemplateNode->CountChildren(XFA_Element::Unknown) != 270 pTemplateNode->CountChildren(XFA_Element::Unknown) !=
271 pNode->CountChildren(XFA_Element::Unknown)) { 271 pNode->CountChildren(XFA_Element::Unknown)) {
272 bSaveXML = TRUE; 272 bSaveXML = true;
273 } 273 }
274 } 274 }
275 CFX_WideTextBuf newBuf; 275 CFX_WideTextBuf newBuf;
276 CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); 276 CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
277 while (pChildNode) { 277 while (pChildNode) {
278 RegenerateFormFile_Changed(pChildNode, newBuf, bSaveXML); 278 RegenerateFormFile_Changed(pChildNode, newBuf, bSaveXML);
279 wsChildren += newBuf.AsStringC(); 279 wsChildren += newBuf.AsStringC();
280 newBuf.Clear(); 280 newBuf.Clear();
281 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); 281 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling);
282 } 282 }
283 if (!bSaveXML && !wsChildren.IsEmpty() && 283 if (!bSaveXML && !wsChildren.IsEmpty() &&
284 pNode->GetElementType() == XFA_Element::Items) { 284 pNode->GetElementType() == XFA_Element::Items) {
285 wsChildren.clear(); 285 wsChildren.clear();
286 bSaveXML = TRUE; 286 bSaveXML = true;
287 CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); 287 CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
288 while (pChild) { 288 while (pChild) {
289 RegenerateFormFile_Changed(pChild, newBuf, bSaveXML); 289 RegenerateFormFile_Changed(pChild, newBuf, bSaveXML);
290 wsChildren += newBuf.AsStringC(); 290 wsChildren += newBuf.AsStringC();
291 newBuf.Clear(); 291 newBuf.Clear();
292 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); 292 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
293 } 293 }
294 } 294 }
295 break; 295 break;
296 } 296 }
297 297
298 if (!wsChildren.IsEmpty() || !wsAttrs.IsEmpty() || 298 if (!wsChildren.IsEmpty() || !wsAttrs.IsEmpty() ||
299 pNode->HasAttribute(XFA_ATTRIBUTE_Name)) { 299 pNode->HasAttribute(XFA_ATTRIBUTE_Name)) {
300 CFX_WideStringC wsElement = pNode->GetClassName(); 300 CFX_WideStringC wsElement = pNode->GetClassName();
301 CFX_WideString wsName; 301 CFX_WideString wsName;
302 SaveAttribute(pNode, XFA_ATTRIBUTE_Name, FX_WSTRC(L"name"), TRUE, wsName); 302 SaveAttribute(pNode, XFA_ATTRIBUTE_Name, FX_WSTRC(L"name"), true, wsName);
303 buf << FX_WSTRC(L"<"); 303 buf << FX_WSTRC(L"<");
304 buf << wsElement; 304 buf << wsElement;
305 buf << wsName; 305 buf << wsName;
306 buf << wsAttrs; 306 buf << wsAttrs;
307 if (wsChildren.IsEmpty()) { 307 if (wsChildren.IsEmpty()) {
308 buf << FX_WSTRC(L"\n/>"); 308 buf << FX_WSTRC(L"\n/>");
309 } else { 309 } else {
310 buf << FX_WSTRC(L"\n>"); 310 buf << FX_WSTRC(L"\n>");
311 buf << wsChildren; 311 buf << wsChildren;
312 buf << FX_WSTRC(L"</"); 312 buf << FX_WSTRC(L"</");
313 buf << wsElement; 313 buf << wsElement;
314 buf << FX_WSTRC(L"\n>"); 314 buf << FX_WSTRC(L"\n>");
315 } 315 }
316 } 316 }
317 } 317 }
318 318
319 void RegenerateFormFile_Container(CXFA_Node* pNode, 319 void RegenerateFormFile_Container(CXFA_Node* pNode,
320 IFX_Stream* pStream, 320 IFX_Stream* pStream,
321 FX_BOOL bSaveXML = FALSE) { 321 bool bSaveXML = false) {
322 XFA_Element eType = pNode->GetElementType(); 322 XFA_Element eType = pNode->GetElementType();
323 if (eType == XFA_Element::Field || eType == XFA_Element::Draw || 323 if (eType == XFA_Element::Field || eType == XFA_Element::Draw ||
324 !pNode->IsContainerNode()) { 324 !pNode->IsContainerNode()) {
325 CFX_WideTextBuf buf; 325 CFX_WideTextBuf buf;
326 RegenerateFormFile_Changed(pNode, buf, bSaveXML); 326 RegenerateFormFile_Changed(pNode, buf, bSaveXML);
327 FX_STRSIZE nLen = buf.GetLength(); 327 FX_STRSIZE nLen = buf.GetLength();
328 if (nLen > 0) 328 if (nLen > 0)
329 pStream->WriteString((const FX_WCHAR*)buf.GetBuffer(), nLen); 329 pStream->WriteString((const FX_WCHAR*)buf.GetBuffer(), nLen);
330 return; 330 return;
331 } 331 }
332 332
333 CFX_WideStringC wsElement = pNode->GetClassName(); 333 CFX_WideStringC wsElement = pNode->GetClassName();
334 pStream->WriteString(L"<", 1); 334 pStream->WriteString(L"<", 1);
335 pStream->WriteString(wsElement.c_str(), wsElement.GetLength()); 335 pStream->WriteString(wsElement.c_str(), wsElement.GetLength());
336 CFX_WideString wsOutput; 336 CFX_WideString wsOutput;
337 SaveAttribute(pNode, XFA_ATTRIBUTE_Name, FX_WSTRC(L"name"), TRUE, wsOutput); 337 SaveAttribute(pNode, XFA_ATTRIBUTE_Name, FX_WSTRC(L"name"), true, wsOutput);
338 CFX_WideString wsAttrs; 338 CFX_WideString wsAttrs;
339 int32_t iAttrs = 0; 339 int32_t iAttrs = 0;
340 const uint8_t* pAttrs = 340 const uint8_t* pAttrs =
341 XFA_GetElementAttributes(pNode->GetElementType(), iAttrs); 341 XFA_GetElementAttributes(pNode->GetElementType(), iAttrs);
342 while (iAttrs--) { 342 while (iAttrs--) {
343 const XFA_ATTRIBUTEINFO* pAttr = 343 const XFA_ATTRIBUTEINFO* pAttr =
344 XFA_GetAttributeByID((XFA_ATTRIBUTE)pAttrs[iAttrs]); 344 XFA_GetAttributeByID((XFA_ATTRIBUTE)pAttrs[iAttrs]);
345 if (pAttr->eName == XFA_ATTRIBUTE_Name) 345 if (pAttr->eName == XFA_ATTRIBUTE_Name)
346 continue; 346 continue;
347 347
348 CFX_WideString wsAttr; 348 CFX_WideString wsAttr;
349 SaveAttribute(pNode, pAttr->eName, pAttr->pName, FALSE, wsAttr); 349 SaveAttribute(pNode, pAttr->eName, pAttr->pName, false, wsAttr);
350 wsOutput += wsAttr; 350 wsOutput += wsAttr;
351 } 351 }
352 352
353 if (!wsOutput.IsEmpty()) 353 if (!wsOutput.IsEmpty())
354 pStream->WriteString(wsOutput.c_str(), wsOutput.GetLength()); 354 pStream->WriteString(wsOutput.c_str(), wsOutput.GetLength());
355 355
356 CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); 356 CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
357 if (pChildNode) { 357 if (pChildNode) {
358 pStream->WriteString(L"\n>", 2); 358 pStream->WriteString(L"\n>", 2);
359 while (pChildNode) { 359 while (pChildNode) {
360 RegenerateFormFile_Container(pChildNode, pStream, bSaveXML); 360 RegenerateFormFile_Container(pChildNode, pStream, bSaveXML);
361 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); 361 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling);
362 } 362 }
363 pStream->WriteString(L"</", 2); 363 pStream->WriteString(L"</", 2);
364 pStream->WriteString(wsElement.c_str(), wsElement.GetLength()); 364 pStream->WriteString(wsElement.c_str(), wsElement.GetLength());
365 pStream->WriteString(L"\n>", 2); 365 pStream->WriteString(L"\n>", 2);
366 } else { 366 } else {
367 pStream->WriteString(L"\n/>", 3); 367 pStream->WriteString(L"\n/>", 3);
368 } 368 }
369 } 369 }
370 370
371 } // namespace 371 } // namespace
372 372
373 void XFA_DataExporter_RegenerateFormFile(CXFA_Node* pNode, 373 void XFA_DataExporter_RegenerateFormFile(CXFA_Node* pNode,
374 IFX_Stream* pStream, 374 IFX_Stream* pStream,
375 const FX_CHAR* pChecksum, 375 const FX_CHAR* pChecksum,
376 FX_BOOL bSaveXML) { 376 bool bSaveXML) {
377 if (pNode->IsModelNode()) { 377 if (pNode->IsModelNode()) {
378 static const FX_WCHAR s_pwsTagName[] = L"<form"; 378 static const FX_WCHAR s_pwsTagName[] = L"<form";
379 static const FX_WCHAR s_pwsClose[] = L"</form\n>"; 379 static const FX_WCHAR s_pwsClose[] = L"</form\n>";
380 pStream->WriteString(s_pwsTagName, FXSYS_wcslen(s_pwsTagName)); 380 pStream->WriteString(s_pwsTagName, FXSYS_wcslen(s_pwsTagName));
381 if (pChecksum) { 381 if (pChecksum) {
382 static const FX_WCHAR s_pwChecksum[] = L" checksum=\""; 382 static const FX_WCHAR s_pwChecksum[] = L" checksum=\"";
383 CFX_WideString wsChecksum = CFX_WideString::FromUTF8(pChecksum); 383 CFX_WideString wsChecksum = CFX_WideString::FromUTF8(pChecksum);
384 pStream->WriteString(s_pwChecksum, FXSYS_wcslen(s_pwChecksum)); 384 pStream->WriteString(s_pwChecksum, FXSYS_wcslen(s_pwChecksum));
385 pStream->WriteString(wsChecksum.c_str(), wsChecksum.GetLength()); 385 pStream->WriteString(wsChecksum.c_str(), wsChecksum.GetLength());
386 pStream->WriteString(L"\"", 1); 386 pStream->WriteString(L"\"", 1);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element); 437 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element);
438 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"xfa:dataNode", 438 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"xfa:dataNode",
439 L"dataGroup"); 439 L"dataGroup");
440 } 440 }
441 441
442 CXFA_DataExporter::CXFA_DataExporter(CXFA_Document* pDocument) 442 CXFA_DataExporter::CXFA_DataExporter(CXFA_Document* pDocument)
443 : m_pDocument(pDocument) { 443 : m_pDocument(pDocument) {
444 ASSERT(m_pDocument); 444 ASSERT(m_pDocument);
445 } 445 }
446 446
447 FX_BOOL CXFA_DataExporter::Export(IFX_SeekableWriteStream* pWrite) { 447 bool CXFA_DataExporter::Export(IFX_SeekableWriteStream* pWrite) {
448 return Export(pWrite, m_pDocument->GetRoot(), 0, nullptr); 448 return Export(pWrite, m_pDocument->GetRoot(), 0, nullptr);
449 } 449 }
450 450
451 FX_BOOL CXFA_DataExporter::Export(IFX_SeekableWriteStream* pWrite, 451 bool CXFA_DataExporter::Export(IFX_SeekableWriteStream* pWrite,
452 CXFA_Node* pNode, 452 CXFA_Node* pNode,
453 uint32_t dwFlag, 453 uint32_t dwFlag,
454 const FX_CHAR* pChecksum) { 454 const FX_CHAR* pChecksum) {
455 if (!pWrite) { 455 if (!pWrite) {
456 ASSERT(false); 456 ASSERT(false);
457 return FALSE; 457 return false;
458 } 458 }
459 IFX_Stream* pStream = IFX_Stream::CreateStream( 459 IFX_Stream* pStream = IFX_Stream::CreateStream(
460 pWrite, 460 pWrite,
461 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); 461 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
462 if (!pStream) 462 if (!pStream)
463 return FALSE; 463 return false;
464 464
465 pStream->SetCodePage(FX_CODEPAGE_UTF8); 465 pStream->SetCodePage(FX_CODEPAGE_UTF8);
466 FX_BOOL bRet = Export(pStream, pNode, dwFlag, pChecksum); 466 bool bRet = Export(pStream, pNode, dwFlag, pChecksum);
467 pStream->Release(); 467 pStream->Release();
468 return bRet; 468 return bRet;
469 } 469 }
470 470
471 FX_BOOL CXFA_DataExporter::Export(IFX_Stream* pStream, 471 bool CXFA_DataExporter::Export(IFX_Stream* pStream,
472 CXFA_Node* pNode, 472 CXFA_Node* pNode,
473 uint32_t dwFlag, 473 uint32_t dwFlag,
474 const FX_CHAR* pChecksum) { 474 const FX_CHAR* pChecksum) {
475 CFDE_XMLDoc* pXMLDoc = m_pDocument->GetXMLDoc(); 475 CFDE_XMLDoc* pXMLDoc = m_pDocument->GetXMLDoc();
476 if (pNode->IsModelNode()) { 476 if (pNode->IsModelNode()) {
477 switch (pNode->GetPacketID()) { 477 switch (pNode->GetPacketID()) {
478 case XFA_XDPPACKET_XDP: { 478 case XFA_XDPPACKET_XDP: {
479 static const FX_WCHAR s_pwsPreamble[] = 479 static const FX_WCHAR s_pwsPreamble[] =
480 L"<xdp:xdp xmlns:xdp=\"http://ns.adobe.com/xdp/\">"; 480 L"<xdp:xdp xmlns:xdp=\"http://ns.adobe.com/xdp/\">";
481 pStream->WriteString(s_pwsPreamble, FXSYS_wcslen(s_pwsPreamble)); 481 pStream->WriteString(s_pwsPreamble, FXSYS_wcslen(s_pwsPreamble));
482 for (CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); 482 for (CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
483 pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { 483 pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
484 Export(pStream, pChild, dwFlag, pChecksum); 484 Export(pStream, pChild, dwFlag, pChecksum);
485 } 485 }
486 static const FX_WCHAR s_pwsPostamble[] = L"</xdp:xdp\n>"; 486 static const FX_WCHAR s_pwsPostamble[] = L"</xdp:xdp\n>";
487 pStream->WriteString(s_pwsPostamble, FXSYS_wcslen(s_pwsPostamble)); 487 pStream->WriteString(s_pwsPostamble, FXSYS_wcslen(s_pwsPostamble));
488 break; 488 break;
489 } 489 }
490 case XFA_XDPPACKET_Datasets: { 490 case XFA_XDPPACKET_Datasets: {
491 CFDE_XMLElement* pElement = 491 CFDE_XMLElement* pElement =
492 static_cast<CFDE_XMLElement*>(pNode->GetXMLMappingNode()); 492 static_cast<CFDE_XMLElement*>(pNode->GetXMLMappingNode());
493 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) 493 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element)
494 return FALSE; 494 return false;
495 495
496 CXFA_Node* pDataNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); 496 CXFA_Node* pDataNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
497 ASSERT(pDataNode); 497 ASSERT(pDataNode);
498 XFA_DataExporter_DealWithDataGroupNode(pDataNode); 498 XFA_DataExporter_DealWithDataGroupNode(pDataNode);
499 pXMLDoc->SaveXMLNode(pStream, pElement); 499 pXMLDoc->SaveXMLNode(pStream, pElement);
500 break; 500 break;
501 } 501 }
502 case XFA_XDPPACKET_Form: { 502 case XFA_XDPPACKET_Form: {
503 XFA_DataExporter_RegenerateFormFile(pNode, pStream, pChecksum); 503 XFA_DataExporter_RegenerateFormFile(pNode, pStream, pChecksum);
504 break; 504 break;
505 } 505 }
506 case XFA_XDPPACKET_Template: 506 case XFA_XDPPACKET_Template:
507 default: { 507 default: {
508 CFDE_XMLElement* pElement = 508 CFDE_XMLElement* pElement =
509 static_cast<CFDE_XMLElement*>(pNode->GetXMLMappingNode()); 509 static_cast<CFDE_XMLElement*>(pNode->GetXMLMappingNode());
510 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) 510 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element)
511 return FALSE; 511 return false;
512 512
513 pXMLDoc->SaveXMLNode(pStream, pElement); 513 pXMLDoc->SaveXMLNode(pStream, pElement);
514 break; 514 break;
515 } 515 }
516 } 516 }
517 return TRUE; 517 return true;
518 } 518 }
519 519
520 CXFA_Node* pDataNode = pNode->GetNodeItem(XFA_NODEITEM_Parent); 520 CXFA_Node* pDataNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
521 CXFA_Node* pExportNode = pNode; 521 CXFA_Node* pExportNode = pNode;
522 for (CXFA_Node* pChildNode = pDataNode->GetNodeItem(XFA_NODEITEM_FirstChild); 522 for (CXFA_Node* pChildNode = pDataNode->GetNodeItem(XFA_NODEITEM_FirstChild);
523 pChildNode; 523 pChildNode;
524 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { 524 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
525 if (pChildNode != pNode) { 525 if (pChildNode != pNode) {
526 pExportNode = pDataNode; 526 pExportNode = pDataNode;
527 break; 527 break;
528 } 528 }
529 } 529 }
530 CFDE_XMLElement* pElement = 530 CFDE_XMLElement* pElement =
531 static_cast<CFDE_XMLElement*>(pExportNode->GetXMLMappingNode()); 531 static_cast<CFDE_XMLElement*>(pExportNode->GetXMLMappingNode());
532 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) 532 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element)
533 return FALSE; 533 return false;
534 534
535 XFA_DataExporter_DealWithDataGroupNode(pExportNode); 535 XFA_DataExporter_DealWithDataGroupNode(pExportNode);
536 pElement->SetString(L"xmlns:xfa", L"http://www.xfa.org/schema/xfa-data/1.0/"); 536 pElement->SetString(L"xmlns:xfa", L"http://www.xfa.org/schema/xfa-data/1.0/");
537 pXMLDoc->SaveXMLNode(pStream, pElement); 537 pXMLDoc->SaveXMLNode(pStream, pElement);
538 pElement->RemoveAttribute(L"xmlns:xfa"); 538 pElement->RemoveAttribute(L"xmlns:xfa");
539 539
540 return TRUE; 540 return true;
541 } 541 }
OLDNEW
« no previous file with comments | « xfa/fxfa/parser/cxfa_dataexporter.h ('k') | xfa/fxfa/parser/cxfa_dataimporter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698