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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 case '\'': | 86 case '\'': |
87 textBuf << FX_WSTRC(L"'"); | 87 textBuf << FX_WSTRC(L"'"); |
88 break; | 88 break; |
89 case '\"': | 89 case '\"': |
90 textBuf << FX_WSTRC(L"""); | 90 textBuf << FX_WSTRC(L"""); |
91 break; | 91 break; |
92 default: | 92 default: |
93 textBuf.AppendChar(str[i]); | 93 textBuf.AppendChar(str[i]); |
94 } | 94 } |
95 } | 95 } |
96 return textBuf.AsStringC(); | 96 return textBuf.MakeString(); |
97 } | 97 } |
98 CFX_WideString XFA_ExportEncodeContent(const CFX_WideStringC& str) { | 98 CFX_WideString XFA_ExportEncodeContent(const CFX_WideStringC& str) { |
99 CFX_WideTextBuf textBuf; | 99 CFX_WideTextBuf textBuf; |
100 int32_t iLen = str.GetLength(); | 100 int32_t iLen = str.GetLength(); |
101 for (int32_t i = 0; i < iLen; i++) { | 101 for (int32_t i = 0; i < iLen; i++) { |
102 FX_WCHAR ch = str.GetAt(i); | 102 FX_WCHAR ch = str.GetAt(i); |
103 if (!FDE_IsXMLValidChar(ch)) { | 103 if (!FDE_IsXMLValidChar(ch)) { |
104 continue; | 104 continue; |
105 } | 105 } |
106 if (ch == '&') { | 106 if (ch == '&') { |
107 textBuf << FX_WSTRC(L"&"); | 107 textBuf << FX_WSTRC(L"&"); |
108 } else if (ch == '<') { | 108 } else if (ch == '<') { |
109 textBuf << FX_WSTRC(L"<"); | 109 textBuf << FX_WSTRC(L"<"); |
110 } else if (ch == '>') { | 110 } else if (ch == '>') { |
111 textBuf << FX_WSTRC(L">"); | 111 textBuf << FX_WSTRC(L">"); |
112 } else if (ch == '\'') { | 112 } else if (ch == '\'') { |
113 textBuf << FX_WSTRC(L"'"); | 113 textBuf << FX_WSTRC(L"'"); |
114 } else if (ch == '\"') { | 114 } else if (ch == '\"') { |
115 textBuf << FX_WSTRC(L"""); | 115 textBuf << FX_WSTRC(L"""); |
116 } else if (ch == ' ') { | 116 } else if (ch == ' ') { |
117 if (i && str.GetAt(i - 1) != ' ') { | 117 if (i && str.GetAt(i - 1) != ' ') { |
118 textBuf.AppendChar(' '); | 118 textBuf.AppendChar(' '); |
119 } else { | 119 } else { |
120 textBuf << FX_WSTRC(L" "); | 120 textBuf << FX_WSTRC(L" "); |
121 } | 121 } |
122 } else { | 122 } else { |
123 textBuf.AppendChar(str.GetAt(i)); | 123 textBuf.AppendChar(str.GetAt(i)); |
124 } | 124 } |
125 } | 125 } |
126 return textBuf.AsStringC(); | 126 return textBuf.MakeString(); |
127 } | 127 } |
128 static void XFA_SaveAttribute(CXFA_Node* pNode, | 128 static void XFA_SaveAttribute(CXFA_Node* pNode, |
129 XFA_ATTRIBUTE eName, | 129 XFA_ATTRIBUTE eName, |
130 const CFX_WideStringC& wsName, | 130 const CFX_WideStringC& wsName, |
131 FX_BOOL bProto, | 131 FX_BOOL bProto, |
132 CFX_WideString& wsOutput) { | 132 CFX_WideString& wsOutput) { |
133 CFX_WideString wsValue; | 133 CFX_WideString wsValue; |
134 if ((!bProto && !pNode->HasAttribute((XFA_ATTRIBUTE)eName, bProto)) || | 134 if ((!bProto && !pNode->HasAttribute((XFA_ATTRIBUTE)eName, bProto)) || |
135 !pNode->GetAttribute((XFA_ATTRIBUTE)eName, wsValue, FALSE)) { | 135 !pNode->GetAttribute((XFA_ATTRIBUTE)eName, wsValue, FALSE)) { |
136 return; | 136 return; |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 pExportNode = pDataNode; | 540 pExportNode = pDataNode; |
541 break; | 541 break; |
542 } | 542 } |
543 } | 543 } |
544 CFDE_XMLElement* pElement = | 544 CFDE_XMLElement* pElement = |
545 static_cast<CFDE_XMLElement*>(pExportNode->GetXMLMappingNode()); | 545 static_cast<CFDE_XMLElement*>(pExportNode->GetXMLMappingNode()); |
546 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) { | 546 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) { |
547 return FALSE; | 547 return FALSE; |
548 } | 548 } |
549 XFA_DataExporter_DealWithDataGroupNode(pExportNode); | 549 XFA_DataExporter_DealWithDataGroupNode(pExportNode); |
550 pElement->SetString(FX_WSTRC(L"xmlns:xfa"), | 550 pElement->SetString(L"xmlns:xfa", |
551 FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/")); | 551 L"http://www.xfa.org/schema/xfa-data/1.0/"); |
552 pXMLDoc->SaveXMLNode(pStream, pElement); | 552 pXMLDoc->SaveXMLNode(pStream, pElement); |
553 pElement->RemoveAttribute(L"xmlns:xfa"); | 553 pElement->RemoveAttribute(L"xmlns:xfa"); |
554 } | 554 } |
555 return TRUE; | 555 return TRUE; |
556 } | 556 } |
557 void XFA_DataExporter_DealWithDataGroupNode(CXFA_Node* pDataNode) { | 557 void XFA_DataExporter_DealWithDataGroupNode(CXFA_Node* pDataNode) { |
558 if (!pDataNode || pDataNode->GetClassID() == XFA_ELEMENT_DataValue) { | 558 if (!pDataNode || pDataNode->GetClassID() == XFA_ELEMENT_DataValue) { |
559 return; | 559 return; |
560 } | 560 } |
561 int32_t iChildNum = 0; | 561 int32_t iChildNum = 0; |
562 for (CXFA_Node* pChildNode = pDataNode->GetNodeItem(XFA_NODEITEM_FirstChild); | 562 for (CXFA_Node* pChildNode = pDataNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
563 pChildNode; | 563 pChildNode; |
564 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { | 564 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
565 iChildNum++; | 565 iChildNum++; |
566 XFA_DataExporter_DealWithDataGroupNode(pChildNode); | 566 XFA_DataExporter_DealWithDataGroupNode(pChildNode); |
567 } | 567 } |
568 if (pDataNode->GetClassID() == XFA_ELEMENT_DataGroup) { | 568 if (pDataNode->GetClassID() == XFA_ELEMENT_DataGroup) { |
569 if (iChildNum > 0) { | 569 if (iChildNum > 0) { |
570 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode(); | 570 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode(); |
571 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element); | 571 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element); |
572 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); | 572 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
573 if (pXMLElement->HasAttribute(L"xfa:dataNode")) { | 573 if (pXMLElement->HasAttribute(L"xfa:dataNode")) { |
574 pXMLElement->RemoveAttribute(L"xfa:dataNode"); | 574 pXMLElement->RemoveAttribute(L"xfa:dataNode"); |
575 } | 575 } |
576 } else { | 576 } else { |
577 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode(); | 577 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode(); |
578 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element); | 578 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element); |
579 static_cast<CFDE_XMLElement*>(pXMLNode) | 579 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"xfa:dataNode", |
580 ->SetString(FX_WSTRC(L"xfa:dataNode"), FX_WSTRC(L"dataGroup")); | 580 L"dataGroup"); |
581 } | 581 } |
582 } | 582 } |
583 } | 583 } |
OLD | NEW |