| 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/xfa_document_serialize.h" | 7 #include "xfa/fxfa/parser/xfa_document_serialize.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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 case '\'': | 87 case '\'': |
| 88 textBuf << FX_WSTRC(L"'"); | 88 textBuf << FX_WSTRC(L"'"); |
| 89 break; | 89 break; |
| 90 case '\"': | 90 case '\"': |
| 91 textBuf << FX_WSTRC(L"""); | 91 textBuf << FX_WSTRC(L"""); |
| 92 break; | 92 break; |
| 93 default: | 93 default: |
| 94 textBuf.AppendChar(str[i]); | 94 textBuf.AppendChar(str[i]); |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 return textBuf.GetWideString(); | 97 return textBuf.AsStringC(); |
| 98 } | 98 } |
| 99 CFX_WideString XFA_ExportEncodeContent(const CFX_WideStringC& str) { | 99 CFX_WideString XFA_ExportEncodeContent(const CFX_WideStringC& str) { |
| 100 CFX_WideTextBuf textBuf; | 100 CFX_WideTextBuf textBuf; |
| 101 int32_t iLen = str.GetLength(); | 101 int32_t iLen = str.GetLength(); |
| 102 for (int32_t i = 0; i < iLen; i++) { | 102 for (int32_t i = 0; i < iLen; i++) { |
| 103 FX_WCHAR ch = str.GetAt(i); | 103 FX_WCHAR ch = str.GetAt(i); |
| 104 if (!FDE_IsXMLValidChar(ch)) { | 104 if (!FDE_IsXMLValidChar(ch)) { |
| 105 continue; | 105 continue; |
| 106 } | 106 } |
| 107 if (ch == '&') { | 107 if (ch == '&') { |
| 108 textBuf << FX_WSTRC(L"&"); | 108 textBuf << FX_WSTRC(L"&"); |
| 109 } else if (ch == '<') { | 109 } else if (ch == '<') { |
| 110 textBuf << FX_WSTRC(L"<"); | 110 textBuf << FX_WSTRC(L"<"); |
| 111 } else if (ch == '>') { | 111 } else if (ch == '>') { |
| 112 textBuf << FX_WSTRC(L">"); | 112 textBuf << FX_WSTRC(L">"); |
| 113 } else if (ch == '\'') { | 113 } else if (ch == '\'') { |
| 114 textBuf << FX_WSTRC(L"'"); | 114 textBuf << FX_WSTRC(L"'"); |
| 115 } else if (ch == '\"') { | 115 } else if (ch == '\"') { |
| 116 textBuf << FX_WSTRC(L"""); | 116 textBuf << FX_WSTRC(L"""); |
| 117 } else if (ch == ' ') { | 117 } else if (ch == ' ') { |
| 118 if (i && str.GetAt(i - 1) != ' ') { | 118 if (i && str.GetAt(i - 1) != ' ') { |
| 119 textBuf.AppendChar(' '); | 119 textBuf.AppendChar(' '); |
| 120 } else { | 120 } else { |
| 121 textBuf << FX_WSTRC(L" "); | 121 textBuf << FX_WSTRC(L" "); |
| 122 } | 122 } |
| 123 } else { | 123 } else { |
| 124 textBuf.AppendChar(str.GetAt(i)); | 124 textBuf.AppendChar(str.GetAt(i)); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 return textBuf.GetWideString(); | 127 return textBuf.AsStringC(); |
| 128 } | 128 } |
| 129 static void XFA_SaveAttribute(CXFA_Node* pNode, | 129 static void XFA_SaveAttribute(CXFA_Node* pNode, |
| 130 XFA_ATTRIBUTE eName, | 130 XFA_ATTRIBUTE eName, |
| 131 const CFX_WideStringC& wsName, | 131 const CFX_WideStringC& wsName, |
| 132 FX_BOOL bProto, | 132 FX_BOOL bProto, |
| 133 CFX_WideString& wsOutput) { | 133 CFX_WideString& wsOutput) { |
| 134 CFX_WideString wsValue; | 134 CFX_WideString wsValue; |
| 135 if ((!bProto && !pNode->HasAttribute((XFA_ATTRIBUTE)eName, bProto)) || | 135 if ((!bProto && !pNode->HasAttribute((XFA_ATTRIBUTE)eName, bProto)) || |
| 136 !pNode->GetAttribute((XFA_ATTRIBUTE)eName, wsValue, FALSE)) { | 136 !pNode->GetAttribute((XFA_ATTRIBUTE)eName, wsValue, FALSE)) { |
| 137 return; | 137 return; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 buf << bodyTagName; | 296 buf << bodyTagName; |
| 297 buf << FX_WSTRC(L" xmlns=\"\"\n>"); | 297 buf << FX_WSTRC(L" xmlns=\"\"\n>"); |
| 298 for (int32_t i = 0; i < wsSelTextArray.GetSize(); i++) { | 298 for (int32_t i = 0; i < wsSelTextArray.GetSize(); i++) { |
| 299 buf << FX_WSTRC(L"<value\n>"); | 299 buf << FX_WSTRC(L"<value\n>"); |
| 300 buf << XFA_ExportEncodeContent(wsSelTextArray[i].AsStringC()); | 300 buf << XFA_ExportEncodeContent(wsSelTextArray[i].AsStringC()); |
| 301 buf << FX_WSTRC(L"</value\n>"); | 301 buf << FX_WSTRC(L"</value\n>"); |
| 302 } | 302 } |
| 303 buf << FX_WSTRC(L"</"); | 303 buf << FX_WSTRC(L"</"); |
| 304 buf << bodyTagName; | 304 buf << bodyTagName; |
| 305 buf << FX_WSTRC(L"\n>"); | 305 buf << FX_WSTRC(L"\n>"); |
| 306 wsChildren += buf.GetWideString(); | 306 wsChildren += buf.AsStringC(); |
| 307 buf.Clear(); | 307 buf.Clear(); |
| 308 } else { | 308 } else { |
| 309 CFX_WideStringC wsValue = pRawValueNode->GetCData(XFA_ATTRIBUTE_Value); | 309 CFX_WideStringC wsValue = pRawValueNode->GetCData(XFA_ATTRIBUTE_Value); |
| 310 wsChildren += XFA_ExportEncodeContent(wsValue); | 310 wsChildren += XFA_ExportEncodeContent(wsValue); |
| 311 } | 311 } |
| 312 } break; | 312 } break; |
| 313 case XFA_OBJECTTYPE_TextNode: | 313 case XFA_OBJECTTYPE_TextNode: |
| 314 case XFA_OBJECTTYPE_NodeC: | 314 case XFA_OBJECTTYPE_NodeC: |
| 315 case XFA_OBJECTTYPE_NodeV: { | 315 case XFA_OBJECTTYPE_NodeV: { |
| 316 CFX_WideStringC wsValue = pNode->GetCData(XFA_ATTRIBUTE_Value); | 316 CFX_WideStringC wsValue = pNode->GetCData(XFA_ATTRIBUTE_Value); |
| 317 wsChildren += XFA_ExportEncodeContent(wsValue); | 317 wsChildren += XFA_ExportEncodeContent(wsValue); |
| 318 } break; | 318 } break; |
| 319 default: | 319 default: |
| 320 if (pNode->GetClassID() == XFA_ELEMENT_Items) { | 320 if (pNode->GetClassID() == XFA_ELEMENT_Items) { |
| 321 CXFA_Node* pTemplateNode = pNode->GetTemplateNode(); | 321 CXFA_Node* pTemplateNode = pNode->GetTemplateNode(); |
| 322 if (!pTemplateNode || | 322 if (!pTemplateNode || |
| 323 pTemplateNode->CountChildren(XFA_ELEMENT_UNKNOWN) != | 323 pTemplateNode->CountChildren(XFA_ELEMENT_UNKNOWN) != |
| 324 pNode->CountChildren(XFA_ELEMENT_UNKNOWN)) { | 324 pNode->CountChildren(XFA_ELEMENT_UNKNOWN)) { |
| 325 bSaveXML = TRUE; | 325 bSaveXML = TRUE; |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 CFX_WideTextBuf newBuf; | 328 CFX_WideTextBuf newBuf; |
| 329 CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); | 329 CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 330 while (pChildNode) { | 330 while (pChildNode) { |
| 331 XFA_DataExporter_RegenerateFormFile_Changed(pChildNode, newBuf, | 331 XFA_DataExporter_RegenerateFormFile_Changed(pChildNode, newBuf, |
| 332 bSaveXML); | 332 bSaveXML); |
| 333 wsChildren += newBuf.GetWideString(); | 333 wsChildren += newBuf.AsStringC(); |
| 334 newBuf.Clear(); | 334 newBuf.Clear(); |
| 335 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); | 335 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 336 } | 336 } |
| 337 if (!bSaveXML && !wsChildren.IsEmpty() && | 337 if (!bSaveXML && !wsChildren.IsEmpty() && |
| 338 pNode->GetClassID() == XFA_ELEMENT_Items) { | 338 pNode->GetClassID() == XFA_ELEMENT_Items) { |
| 339 wsChildren.clear(); | 339 wsChildren.clear(); |
| 340 bSaveXML = TRUE; | 340 bSaveXML = TRUE; |
| 341 CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); | 341 CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 342 while (pChildNode) { | 342 while (pChildNode) { |
| 343 XFA_DataExporter_RegenerateFormFile_Changed(pChildNode, newBuf, | 343 XFA_DataExporter_RegenerateFormFile_Changed(pChildNode, newBuf, |
| 344 bSaveXML); | 344 bSaveXML); |
| 345 wsChildren += newBuf.GetWideString(); | 345 wsChildren += newBuf.AsStringC(); |
| 346 newBuf.Clear(); | 346 newBuf.Clear(); |
| 347 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); | 347 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 348 } | 348 } |
| 349 } | 349 } |
| 350 break; | 350 break; |
| 351 } | 351 } |
| 352 if (!wsChildren.IsEmpty() || !wsAttrs.IsEmpty() || | 352 if (!wsChildren.IsEmpty() || !wsAttrs.IsEmpty() || |
| 353 pNode->HasAttribute(XFA_ATTRIBUTE_Name)) { | 353 pNode->HasAttribute(XFA_ATTRIBUTE_Name)) { |
| 354 CFX_WideStringC wsElement; | 354 CFX_WideStringC wsElement; |
| 355 pNode->GetClassName(wsElement); | 355 pNode->GetClassName(wsElement); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 pXMLElement->RemoveAttribute(L"xfa:dataNode"); | 575 pXMLElement->RemoveAttribute(L"xfa:dataNode"); |
| 576 } | 576 } |
| 577 } else { | 577 } else { |
| 578 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode(); | 578 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode(); |
| 579 FXSYS_assert(pXMLNode->GetType() == FDE_XMLNODE_Element); | 579 FXSYS_assert(pXMLNode->GetType() == FDE_XMLNODE_Element); |
| 580 static_cast<CFDE_XMLElement*>(pXMLNode) | 580 static_cast<CFDE_XMLElement*>(pXMLNode) |
| 581 ->SetString(FX_WSTRC(L"xfa:dataNode"), FX_WSTRC(L"dataGroup")); | 581 ->SetString(FX_WSTRC(L"xfa:dataNode"), FX_WSTRC(L"dataGroup")); |
| 582 } | 582 } |
| 583 } | 583 } |
| 584 } | 584 } |
| OLD | NEW |