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/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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 CFX_RetainPtr<IFX_MemoryStream> pMemStream = | 200 CFX_RetainPtr<IFX_MemoryStream> pMemStream = |
201 IFX_MemoryStream::Create(true); | 201 IFX_MemoryStream::Create(true); |
202 | 202 |
203 // Note: ambiguous without cast below. | 203 // Note: ambiguous without cast below. |
204 IFGAS_Stream* pTempStream = IFGAS_Stream::CreateStream( | 204 CFX_RetainPtr<IFGAS_Stream> pTempStream = IFGAS_Stream::CreateStream( |
205 CFX_RetainPtr<IFX_SeekableWriteStream>(pMemStream), | 205 CFX_RetainPtr<IFX_SeekableWriteStream>(pMemStream), |
206 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | | 206 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | |
207 FX_STREAMACCESS_Append); | 207 FX_STREAMACCESS_Append); |
208 | 208 |
209 pTempStream->SetCodePage(FX_CODEPAGE_UTF8); | 209 pTempStream->SetCodePage(FX_CODEPAGE_UTF8); |
210 pRichTextXML->SaveXMLNode(pTempStream); | 210 pRichTextXML->SaveXMLNode(pTempStream); |
211 wsChildren += CFX_WideString::FromUTF8( | 211 wsChildren += CFX_WideString::FromUTF8( |
212 CFX_ByteStringC(pMemStream->GetBuffer(), pMemStream->GetSize())); | 212 CFX_ByteStringC(pMemStream->GetBuffer(), pMemStream->GetSize())); |
213 pTempStream->Release(); | |
214 } else if (pRawValueNode->GetElementType() == XFA_Element::Sharpxml && | 213 } else if (pRawValueNode->GetElementType() == XFA_Element::Sharpxml && |
215 wsContentType == FX_WSTRC(L"text/xml")) { | 214 wsContentType == FX_WSTRC(L"text/xml")) { |
216 CFX_WideString wsRawValue; | 215 CFX_WideString wsRawValue; |
217 pRawValueNode->GetAttribute(XFA_ATTRIBUTE_Value, wsRawValue, false); | 216 pRawValueNode->GetAttribute(XFA_ATTRIBUTE_Value, wsRawValue, false); |
218 if (wsRawValue.IsEmpty()) | 217 if (wsRawValue.IsEmpty()) |
219 break; | 218 break; |
220 | 219 |
221 CFX_WideStringArray wsSelTextArray; | 220 CFX_WideStringArray wsSelTextArray; |
222 int32_t iStart = 0; | 221 int32_t iStart = 0; |
223 int32_t iEnd = wsRawValue.Find(L'\n', iStart); | 222 int32_t iEnd = wsRawValue.Find(L'\n', iStart); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 buf << FX_WSTRC(L"\n>"); | 312 buf << FX_WSTRC(L"\n>"); |
314 buf << wsChildren; | 313 buf << wsChildren; |
315 buf << FX_WSTRC(L"</"); | 314 buf << FX_WSTRC(L"</"); |
316 buf << wsElement; | 315 buf << wsElement; |
317 buf << FX_WSTRC(L"\n>"); | 316 buf << FX_WSTRC(L"\n>"); |
318 } | 317 } |
319 } | 318 } |
320 } | 319 } |
321 | 320 |
322 void RegenerateFormFile_Container(CXFA_Node* pNode, | 321 void RegenerateFormFile_Container(CXFA_Node* pNode, |
323 IFGAS_Stream* pStream, | 322 const CFX_RetainPtr<IFGAS_Stream>& pStream, |
324 bool bSaveXML = false) { | 323 bool bSaveXML = false) { |
325 XFA_Element eType = pNode->GetElementType(); | 324 XFA_Element eType = pNode->GetElementType(); |
326 if (eType == XFA_Element::Field || eType == XFA_Element::Draw || | 325 if (eType == XFA_Element::Field || eType == XFA_Element::Draw || |
327 !pNode->IsContainerNode()) { | 326 !pNode->IsContainerNode()) { |
328 CFX_WideTextBuf buf; | 327 CFX_WideTextBuf buf; |
329 RegenerateFormFile_Changed(pNode, buf, bSaveXML); | 328 RegenerateFormFile_Changed(pNode, buf, bSaveXML); |
330 FX_STRSIZE nLen = buf.GetLength(); | 329 FX_STRSIZE nLen = buf.GetLength(); |
331 if (nLen > 0) | 330 if (nLen > 0) |
332 pStream->WriteString((const FX_WCHAR*)buf.GetBuffer(), nLen); | 331 pStream->WriteString((const FX_WCHAR*)buf.GetBuffer(), nLen); |
333 return; | 332 return; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 pStream->WriteString(L"</", 2); | 365 pStream->WriteString(L"</", 2); |
367 pStream->WriteString(wsElement.c_str(), wsElement.GetLength()); | 366 pStream->WriteString(wsElement.c_str(), wsElement.GetLength()); |
368 pStream->WriteString(L"\n>", 2); | 367 pStream->WriteString(L"\n>", 2); |
369 } else { | 368 } else { |
370 pStream->WriteString(L"\n/>", 3); | 369 pStream->WriteString(L"\n/>", 3); |
371 } | 370 } |
372 } | 371 } |
373 | 372 |
374 } // namespace | 373 } // namespace |
375 | 374 |
376 void XFA_DataExporter_RegenerateFormFile(CXFA_Node* pNode, | 375 void XFA_DataExporter_RegenerateFormFile( |
377 IFGAS_Stream* pStream, | 376 CXFA_Node* pNode, |
378 const FX_CHAR* pChecksum, | 377 const CFX_RetainPtr<IFGAS_Stream>& pStream, |
379 bool bSaveXML) { | 378 const FX_CHAR* pChecksum, |
| 379 bool bSaveXML) { |
380 if (pNode->IsModelNode()) { | 380 if (pNode->IsModelNode()) { |
381 static const FX_WCHAR s_pwsTagName[] = L"<form"; | 381 static const FX_WCHAR s_pwsTagName[] = L"<form"; |
382 static const FX_WCHAR s_pwsClose[] = L"</form\n>"; | 382 static const FX_WCHAR s_pwsClose[] = L"</form\n>"; |
383 pStream->WriteString(s_pwsTagName, FXSYS_wcslen(s_pwsTagName)); | 383 pStream->WriteString(s_pwsTagName, FXSYS_wcslen(s_pwsTagName)); |
384 if (pChecksum) { | 384 if (pChecksum) { |
385 static const FX_WCHAR s_pwChecksum[] = L" checksum=\""; | 385 static const FX_WCHAR s_pwChecksum[] = L" checksum=\""; |
386 CFX_WideString wsChecksum = CFX_WideString::FromUTF8(pChecksum); | 386 CFX_WideString wsChecksum = CFX_WideString::FromUTF8(pChecksum); |
387 pStream->WriteString(s_pwChecksum, FXSYS_wcslen(s_pwChecksum)); | 387 pStream->WriteString(s_pwChecksum, FXSYS_wcslen(s_pwChecksum)); |
388 pStream->WriteString(wsChecksum.c_str(), wsChecksum.GetLength()); | 388 pStream->WriteString(wsChecksum.c_str(), wsChecksum.GetLength()); |
389 pStream->WriteString(L"\"", 1); | 389 pStream->WriteString(L"\"", 1); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 | 454 |
455 bool CXFA_DataExporter::Export( | 455 bool CXFA_DataExporter::Export( |
456 const CFX_RetainPtr<IFX_SeekableWriteStream>& pWrite, | 456 const CFX_RetainPtr<IFX_SeekableWriteStream>& pWrite, |
457 CXFA_Node* pNode, | 457 CXFA_Node* pNode, |
458 uint32_t dwFlag, | 458 uint32_t dwFlag, |
459 const FX_CHAR* pChecksum) { | 459 const FX_CHAR* pChecksum) { |
460 ASSERT(pWrite); | 460 ASSERT(pWrite); |
461 if (!pWrite) | 461 if (!pWrite) |
462 return false; | 462 return false; |
463 | 463 |
464 IFGAS_Stream* pStream = IFGAS_Stream::CreateStream( | 464 CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream( |
465 pWrite, | 465 pWrite, |
466 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); | 466 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); |
467 if (!pStream) | 467 if (!pStream) |
468 return false; | 468 return false; |
469 | 469 |
470 pStream->SetCodePage(FX_CODEPAGE_UTF8); | 470 pStream->SetCodePage(FX_CODEPAGE_UTF8); |
471 bool bRet = Export(pStream, pNode, dwFlag, pChecksum); | 471 return Export(pStream, pNode, dwFlag, pChecksum); |
472 pStream->Release(); | |
473 return bRet; | |
474 } | 472 } |
475 | 473 |
476 bool CXFA_DataExporter::Export(IFGAS_Stream* pStream, | 474 bool CXFA_DataExporter::Export(const CFX_RetainPtr<IFGAS_Stream>& pStream, |
477 CXFA_Node* pNode, | 475 CXFA_Node* pNode, |
478 uint32_t dwFlag, | 476 uint32_t dwFlag, |
479 const FX_CHAR* pChecksum) { | 477 const FX_CHAR* pChecksum) { |
480 CFDE_XMLDoc* pXMLDoc = m_pDocument->GetXMLDoc(); | 478 CFDE_XMLDoc* pXMLDoc = m_pDocument->GetXMLDoc(); |
481 if (pNode->IsModelNode()) { | 479 if (pNode->IsModelNode()) { |
482 switch (pNode->GetPacketID()) { | 480 switch (pNode->GetPacketID()) { |
483 case XFA_XDPPACKET_XDP: { | 481 case XFA_XDPPACKET_XDP: { |
484 static const FX_WCHAR s_pwsPreamble[] = | 482 static const FX_WCHAR s_pwsPreamble[] = |
485 L"<xdp:xdp xmlns:xdp=\"http://ns.adobe.com/xdp/\">"; | 483 L"<xdp:xdp xmlns:xdp=\"http://ns.adobe.com/xdp/\">"; |
486 pStream->WriteString(s_pwsPreamble, FXSYS_wcslen(s_pwsPreamble)); | 484 pStream->WriteString(s_pwsPreamble, FXSYS_wcslen(s_pwsPreamble)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) | 535 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) |
538 return false; | 536 return false; |
539 | 537 |
540 XFA_DataExporter_DealWithDataGroupNode(pExportNode); | 538 XFA_DataExporter_DealWithDataGroupNode(pExportNode); |
541 pElement->SetString(L"xmlns:xfa", L"http://www.xfa.org/schema/xfa-data/1.0/"); | 539 pElement->SetString(L"xmlns:xfa", L"http://www.xfa.org/schema/xfa-data/1.0/"); |
542 pXMLDoc->SaveXMLNode(pStream, pElement); | 540 pXMLDoc->SaveXMLNode(pStream, pElement); |
543 pElement->RemoveAttribute(L"xmlns:xfa"); | 541 pElement->RemoveAttribute(L"xmlns:xfa"); |
544 | 542 |
545 return true; | 543 return true; |
546 } | 544 } |
OLD | NEW |