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

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

Issue 2164663004: Split xfa_document_serialize into class files (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa_parser_III
Patch Set: Review fixes Created 4 years, 5 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/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/xfa_document_serialize.h" 7 #include "xfa/fxfa/parser/cxfa_dataexporter.h"
8 8
9 #include "core/fxcrt/include/fx_basic.h"
9 #include "xfa/fde/xml/fde_xml_imp.h" 10 #include "xfa/fde/xml/fde_xml_imp.h"
10 #include "xfa/fgas/crt/fgas_codepage.h" 11 #include "xfa/fgas/crt/fgas_codepage.h"
11 #include "xfa/fxfa/parser/cxfa_document.h" 12 #include "xfa/fxfa/parser/cxfa_document.h"
12 #include "xfa/fxfa/parser/cxfa_simple_parser.h" 13 #include "xfa/fxfa/parser/cxfa_widgetdata.h"
13 #include "xfa/fxfa/parser/xfa_localemgr.h"
14 #include "xfa/fxfa/parser/xfa_object.h" 14 #include "xfa/fxfa/parser/xfa_object.h"
15 #include "xfa/fxfa/parser/xfa_utils.h"
16 15
17 CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument) 16 namespace {
18 : m_pDocument(pDocument) {
19 ASSERT(m_pDocument);
20 }
21 FX_BOOL CXFA_DataImporter::ImportData(IFX_FileRead* pDataDocument) {
22 std::unique_ptr<CXFA_SimpleParser> pDataDocumentParser(
23 new CXFA_SimpleParser(m_pDocument, false));
24 if (!pDataDocumentParser)
25 return FALSE;
26 17
27 if (pDataDocumentParser->StartParse(pDataDocument, XFA_XDPPACKET_Datasets) != 18 CFX_WideString ExportEncodeAttribute(const CFX_WideString& str) {
28 XFA_PARSESTATUS_Ready) {
29 return FALSE;
30 }
31 if (pDataDocumentParser->DoParse(nullptr) < XFA_PARSESTATUS_Done)
32 return FALSE;
33
34 CXFA_Node* pImportDataRoot = pDataDocumentParser->GetRootNode();
35 if (!pImportDataRoot)
36 return FALSE;
37
38 CXFA_Node* pDataModel =
39 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
40 if (!pDataModel)
41 return FALSE;
42
43 CXFA_Node* pDataNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Data));
44 if (pDataNode)
45 pDataModel->RemoveChild(pDataNode);
46
47 if (pImportDataRoot->GetElementType() == XFA_Element::DataModel) {
48 while (CXFA_Node* pChildNode =
49 pImportDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) {
50 pImportDataRoot->RemoveChild(pChildNode);
51 pDataModel->InsertChild(pChildNode);
52 }
53 } else {
54 CFDE_XMLNode* pXMLNode = pImportDataRoot->GetXMLMappingNode();
55 CFDE_XMLNode* pParentXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
56 if (pParentXMLNode)
57 pParentXMLNode->RemoveChildNode(pXMLNode);
58 pDataModel->InsertChild(pImportDataRoot);
59 }
60 m_pDocument->DoDataRemerge(FALSE);
61 return TRUE;
62 }
63
64 CFX_WideString XFA_ExportEncodeAttribute(const CFX_WideString& str) {
65 CFX_WideTextBuf textBuf; 19 CFX_WideTextBuf textBuf;
66 int32_t iLen = str.GetLength(); 20 int32_t iLen = str.GetLength();
67 for (int32_t i = 0; i < iLen; i++) { 21 for (int32_t i = 0; i < iLen; i++) {
68 switch (str[i]) { 22 switch (str[i]) {
69 case '&': 23 case '&':
70 textBuf << FX_WSTRC(L"&amp;"); 24 textBuf << FX_WSTRC(L"&amp;");
71 break; 25 break;
72 case '<': 26 case '<':
73 textBuf << FX_WSTRC(L"&lt;"); 27 textBuf << FX_WSTRC(L"&lt;");
74 break; 28 break;
75 case '>': 29 case '>':
76 textBuf << FX_WSTRC(L"&gt;"); 30 textBuf << FX_WSTRC(L"&gt;");
77 break; 31 break;
78 case '\'': 32 case '\'':
79 textBuf << FX_WSTRC(L"&apos;"); 33 textBuf << FX_WSTRC(L"&apos;");
80 break; 34 break;
81 case '\"': 35 case '\"':
82 textBuf << FX_WSTRC(L"&quot;"); 36 textBuf << FX_WSTRC(L"&quot;");
83 break; 37 break;
84 default: 38 default:
85 textBuf.AppendChar(str[i]); 39 textBuf.AppendChar(str[i]);
86 } 40 }
87 } 41 }
88 return textBuf.MakeString(); 42 return textBuf.MakeString();
89 } 43 }
90 CFX_WideString XFA_ExportEncodeContent(const CFX_WideStringC& str) { 44
45 CFX_WideString ExportEncodeContent(const CFX_WideStringC& str) {
91 CFX_WideTextBuf textBuf; 46 CFX_WideTextBuf textBuf;
92 int32_t iLen = str.GetLength(); 47 int32_t iLen = str.GetLength();
93 for (int32_t i = 0; i < iLen; i++) { 48 for (int32_t i = 0; i < iLen; i++) {
94 FX_WCHAR ch = str.GetAt(i); 49 FX_WCHAR ch = str.GetAt(i);
95 if (!FDE_IsXMLValidChar(ch)) { 50 if (!FDE_IsXMLValidChar(ch))
96 continue; 51 continue;
97 } 52
98 if (ch == '&') { 53 if (ch == '&') {
99 textBuf << FX_WSTRC(L"&amp;"); 54 textBuf << FX_WSTRC(L"&amp;");
100 } else if (ch == '<') { 55 } else if (ch == '<') {
101 textBuf << FX_WSTRC(L"&lt;"); 56 textBuf << FX_WSTRC(L"&lt;");
102 } else if (ch == '>') { 57 } else if (ch == '>') {
103 textBuf << FX_WSTRC(L"&gt;"); 58 textBuf << FX_WSTRC(L"&gt;");
104 } else if (ch == '\'') { 59 } else if (ch == '\'') {
105 textBuf << FX_WSTRC(L"&apos;"); 60 textBuf << FX_WSTRC(L"&apos;");
106 } else if (ch == '\"') { 61 } else if (ch == '\"') {
107 textBuf << FX_WSTRC(L"&quot;"); 62 textBuf << FX_WSTRC(L"&quot;");
108 } else if (ch == ' ') { 63 } else if (ch == ' ') {
109 if (i && str.GetAt(i - 1) != ' ') { 64 if (i && str.GetAt(i - 1) != ' ') {
110 textBuf.AppendChar(' '); 65 textBuf.AppendChar(' ');
111 } else { 66 } else {
112 textBuf << FX_WSTRC(L"&#x20;"); 67 textBuf << FX_WSTRC(L"&#x20;");
113 } 68 }
114 } else { 69 } else {
115 textBuf.AppendChar(str.GetAt(i)); 70 textBuf.AppendChar(str.GetAt(i));
116 } 71 }
117 } 72 }
118 return textBuf.MakeString(); 73 return textBuf.MakeString();
119 } 74 }
120 static void XFA_SaveAttribute(CXFA_Node* pNode, 75
121 XFA_ATTRIBUTE eName, 76 void SaveAttribute(CXFA_Node* pNode,
122 const CFX_WideStringC& wsName, 77 XFA_ATTRIBUTE eName,
123 FX_BOOL bProto, 78 const CFX_WideStringC& wsName,
124 CFX_WideString& wsOutput) { 79 FX_BOOL bProto,
80 CFX_WideString& wsOutput) {
125 CFX_WideString wsValue; 81 CFX_WideString wsValue;
126 if ((!bProto && !pNode->HasAttribute((XFA_ATTRIBUTE)eName, bProto)) || 82 if ((!bProto && !pNode->HasAttribute((XFA_ATTRIBUTE)eName, bProto)) ||
127 !pNode->GetAttribute((XFA_ATTRIBUTE)eName, wsValue, FALSE)) { 83 !pNode->GetAttribute((XFA_ATTRIBUTE)eName, wsValue, FALSE)) {
128 return; 84 return;
129 } 85 }
130 wsValue = XFA_ExportEncodeAttribute(wsValue); 86 wsValue = ExportEncodeAttribute(wsValue);
131 wsOutput += FX_WSTRC(L" "); 87 wsOutput += FX_WSTRC(L" ");
132 wsOutput += wsName; 88 wsOutput += wsName;
133 wsOutput += FX_WSTRC(L"=\""); 89 wsOutput += FX_WSTRC(L"=\"");
134 wsOutput += wsValue; 90 wsOutput += wsValue;
135 wsOutput += FX_WSTRC(L"\""); 91 wsOutput += FX_WSTRC(L"\"");
136 } 92 }
137 static FX_BOOL XFA_DataExporter_AttributeSaveInDataModel( 93
138 CXFA_Node* pNode, 94 FX_BOOL AttributeSaveInDataModel(CXFA_Node* pNode, XFA_ATTRIBUTE eAttribute) {
139 XFA_ATTRIBUTE eAttribute) {
140 FX_BOOL bSaveInDataModel = FALSE; 95 FX_BOOL bSaveInDataModel = FALSE;
141 if (pNode->GetElementType() != XFA_Element::Image) { 96 if (pNode->GetElementType() != XFA_Element::Image)
142 return bSaveInDataModel; 97 return bSaveInDataModel;
143 } 98
144 CXFA_Node* pValueNode = pNode->GetNodeItem(XFA_NODEITEM_Parent); 99 CXFA_Node* pValueNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
145 if (!pValueNode || pValueNode->GetElementType() != XFA_Element::Value) { 100 if (!pValueNode || pValueNode->GetElementType() != XFA_Element::Value)
146 return bSaveInDataModel; 101 return bSaveInDataModel;
147 } 102
148 CXFA_Node* pFieldNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent); 103 CXFA_Node* pFieldNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
149 if (pFieldNode && pFieldNode->GetBindData() && 104 if (pFieldNode && pFieldNode->GetBindData() &&
150 eAttribute == XFA_ATTRIBUTE_Href) { 105 eAttribute == XFA_ATTRIBUTE_Href) {
151 bSaveInDataModel = TRUE; 106 bSaveInDataModel = TRUE;
152 } 107 }
153 return bSaveInDataModel; 108 return bSaveInDataModel;
154 } 109 }
155 FX_BOOL XFA_DataExporter_ContentNodeNeedtoExport(CXFA_Node* pContentNode) { 110
111 FX_BOOL ContentNodeNeedtoExport(CXFA_Node* pContentNode) {
156 CFX_WideString wsContent; 112 CFX_WideString wsContent;
157 if (!pContentNode->TryContent(wsContent, FALSE, FALSE)) 113 if (!pContentNode->TryContent(wsContent, FALSE, FALSE))
158 return FALSE; 114 return FALSE;
159 115
160 ASSERT(pContentNode->IsContentNode()); 116 ASSERT(pContentNode->IsContentNode());
161 CXFA_Node* pParentNode = pContentNode->GetNodeItem(XFA_NODEITEM_Parent); 117 CXFA_Node* pParentNode = pContentNode->GetNodeItem(XFA_NODEITEM_Parent);
162 if (!pParentNode || pParentNode->GetElementType() != XFA_Element::Value) 118 if (!pParentNode || pParentNode->GetElementType() != XFA_Element::Value)
163 return TRUE; 119 return TRUE;
164 120
165 CXFA_Node* pGrandParentNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent); 121 CXFA_Node* pGrandParentNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
166 if (!pGrandParentNode || !pGrandParentNode->IsContainerNode()) 122 if (!pGrandParentNode || !pGrandParentNode->IsContainerNode())
167 return TRUE; 123 return TRUE;
168 if (pGrandParentNode->GetBindData()) 124 if (pGrandParentNode->GetBindData())
169 return FALSE; 125 return FALSE;
170 126
171 CXFA_WidgetData* pWidgetData = pGrandParentNode->GetWidgetData(); 127 CXFA_WidgetData* pWidgetData = pGrandParentNode->GetWidgetData();
172 XFA_Element eUIType = pWidgetData->GetUIType(); 128 XFA_Element eUIType = pWidgetData->GetUIType();
173 if (eUIType == XFA_Element::PasswordEdit) { 129 if (eUIType == XFA_Element::PasswordEdit)
174 return FALSE; 130 return FALSE;
175 }
176 return TRUE; 131 return TRUE;
177 } 132 }
178 static void XFA_DataExporter_RecognizeXFAVersionNumber( 133
179 CXFA_Node* pTemplateRoot, 134 void RecognizeXFAVersionNumber(CXFA_Node* pTemplateRoot,
180 CFX_WideString& wsVersionNumber) { 135 CFX_WideString& wsVersionNumber) {
181 wsVersionNumber.clear(); 136 wsVersionNumber.clear();
182 if (!pTemplateRoot) { 137 if (!pTemplateRoot)
183 return; 138 return;
184 } 139
185 CFX_WideString wsTemplateNS; 140 CFX_WideString wsTemplateNS;
186 if (!pTemplateRoot->TryNamespace(wsTemplateNS)) { 141 if (!pTemplateRoot->TryNamespace(wsTemplateNS))
187 return; 142 return;
188 } 143
189 XFA_VERSION eVersion = 144 XFA_VERSION eVersion =
190 pTemplateRoot->GetDocument()->RecognizeXFAVersionNumber(wsTemplateNS); 145 pTemplateRoot->GetDocument()->RecognizeXFAVersionNumber(wsTemplateNS);
191 if (eVersion == XFA_VERSION_UNKNOWN) { 146 if (eVersion == XFA_VERSION_UNKNOWN)
192 eVersion = XFA_VERSION_DEFAULT; 147 eVersion = XFA_VERSION_DEFAULT;
193 } 148
194 wsVersionNumber.Format(L"%i.%i", eVersion / 100, eVersion % 100); 149 wsVersionNumber.Format(L"%i.%i", eVersion / 100, eVersion % 100);
195 } 150 }
196 static void XFA_DataExporter_RegenerateFormFile_Changed( 151
197 CXFA_Node* pNode, 152 void RegenerateFormFile_Changed(CXFA_Node* pNode,
198 CFX_WideTextBuf& buf, 153 CFX_WideTextBuf& buf,
199 FX_BOOL bSaveXML = FALSE) { 154 FX_BOOL bSaveXML) {
200 CFX_WideString wsAttrs; 155 CFX_WideString wsAttrs;
201 int32_t iAttrs = 0; 156 int32_t iAttrs = 0;
202 const uint8_t* pAttrs = 157 const uint8_t* pAttrs =
203 XFA_GetElementAttributes(pNode->GetElementType(), iAttrs); 158 XFA_GetElementAttributes(pNode->GetElementType(), iAttrs);
204 while (iAttrs--) { 159 while (iAttrs--) {
205 const XFA_ATTRIBUTEINFO* pAttr = 160 const XFA_ATTRIBUTEINFO* pAttr =
206 XFA_GetAttributeByID((XFA_ATTRIBUTE)pAttrs[iAttrs]); 161 XFA_GetAttributeByID((XFA_ATTRIBUTE)pAttrs[iAttrs]);
207 if (pAttr->eName == XFA_ATTRIBUTE_Name || 162 if (pAttr->eName == XFA_ATTRIBUTE_Name ||
208 (XFA_DataExporter_AttributeSaveInDataModel(pNode, pAttr->eName) && 163 (AttributeSaveInDataModel(pNode, pAttr->eName) && !bSaveXML)) {
209 !bSaveXML)) {
210 continue; 164 continue;
211 } 165 }
212 CFX_WideString wsAttr; 166 CFX_WideString wsAttr;
213 XFA_SaveAttribute(pNode, pAttr->eName, pAttr->pName, bSaveXML, wsAttr); 167 SaveAttribute(pNode, pAttr->eName, pAttr->pName, bSaveXML, wsAttr);
214 wsAttrs += wsAttr; 168 wsAttrs += wsAttr;
215 } 169 }
170
216 CFX_WideString wsChildren; 171 CFX_WideString wsChildren;
217 switch (pNode->GetObjectType()) { 172 switch (pNode->GetObjectType()) {
218 case XFA_ObjectType::ContentNode: { 173 case XFA_ObjectType::ContentNode: {
219 if (!bSaveXML && !XFA_DataExporter_ContentNodeNeedtoExport(pNode)) { 174 if (!bSaveXML && !ContentNodeNeedtoExport(pNode))
220 break; 175 break;
221 } 176
222 CXFA_Node* pRawValueNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); 177 CXFA_Node* pRawValueNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
223 while (pRawValueNode && 178 while (pRawValueNode &&
224 pRawValueNode->GetElementType() != XFA_Element::SharpxHTML && 179 pRawValueNode->GetElementType() != XFA_Element::SharpxHTML &&
225 pRawValueNode->GetElementType() != XFA_Element::Sharptext && 180 pRawValueNode->GetElementType() != XFA_Element::Sharptext &&
226 pRawValueNode->GetElementType() != XFA_Element::Sharpxml) { 181 pRawValueNode->GetElementType() != XFA_Element::Sharpxml) {
227 pRawValueNode = pRawValueNode->GetNodeItem(XFA_NODEITEM_NextSibling); 182 pRawValueNode = pRawValueNode->GetNodeItem(XFA_NODEITEM_NextSibling);
228 } 183 }
229 if (!pRawValueNode) { 184 if (!pRawValueNode)
230 break; 185 break;
231 } 186
232 CFX_WideString wsContentType; 187 CFX_WideString wsContentType;
233 pNode->GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE); 188 pNode->GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE);
234 if (pRawValueNode->GetElementType() == XFA_Element::SharpxHTML && 189 if (pRawValueNode->GetElementType() == XFA_Element::SharpxHTML &&
235 wsContentType == FX_WSTRC(L"text/html")) { 190 wsContentType == FX_WSTRC(L"text/html")) {
236 CFDE_XMLNode* pExDataXML = pNode->GetXMLMappingNode(); 191 CFDE_XMLNode* pExDataXML = pNode->GetXMLMappingNode();
237 if (!pExDataXML) { 192 if (!pExDataXML)
238 break; 193 break;
239 } 194
240 CFDE_XMLNode* pRichTextXML = 195 CFDE_XMLNode* pRichTextXML =
241 pExDataXML->GetNodeItem(CFDE_XMLNode::FirstChild); 196 pExDataXML->GetNodeItem(CFDE_XMLNode::FirstChild);
242 if (!pRichTextXML) { 197 if (!pRichTextXML)
243 break; 198 break;
244 } 199
245 IFX_MemoryStream* pMemStream = FX_CreateMemoryStream(TRUE); 200 IFX_MemoryStream* pMemStream = FX_CreateMemoryStream(TRUE);
246 IFX_Stream* pTempStream = IFX_Stream::CreateStream( 201 IFX_Stream* pTempStream = IFX_Stream::CreateStream(
247 (IFX_FileWrite*)pMemStream, FX_STREAMACCESS_Text | 202 (IFX_FileWrite*)pMemStream, FX_STREAMACCESS_Text |
248 FX_STREAMACCESS_Write | 203 FX_STREAMACCESS_Write |
249 FX_STREAMACCESS_Append); 204 FX_STREAMACCESS_Append);
250 pTempStream->SetCodePage(FX_CODEPAGE_UTF8); 205 pTempStream->SetCodePage(FX_CODEPAGE_UTF8);
251 pRichTextXML->SaveXMLNode(pTempStream); 206 pRichTextXML->SaveXMLNode(pTempStream);
252 wsChildren += CFX_WideString::FromUTF8( 207 wsChildren += CFX_WideString::FromUTF8(
253 CFX_ByteStringC(pMemStream->GetBuffer(), pMemStream->GetSize())); 208 CFX_ByteStringC(pMemStream->GetBuffer(), pMemStream->GetSize()));
254 pTempStream->Release(); 209 pTempStream->Release();
255 pMemStream->Release(); 210 pMemStream->Release();
256 } else if (pRawValueNode->GetElementType() == XFA_Element::Sharpxml && 211 } else if (pRawValueNode->GetElementType() == XFA_Element::Sharpxml &&
257 wsContentType == FX_WSTRC(L"text/xml")) { 212 wsContentType == FX_WSTRC(L"text/xml")) {
258 CFX_WideString wsRawValue; 213 CFX_WideString wsRawValue;
259 pRawValueNode->GetAttribute(XFA_ATTRIBUTE_Value, wsRawValue, FALSE); 214 pRawValueNode->GetAttribute(XFA_ATTRIBUTE_Value, wsRawValue, FALSE);
260 if (wsRawValue.IsEmpty()) { 215 if (wsRawValue.IsEmpty())
261 break; 216 break;
262 } 217
263 CFX_WideStringArray wsSelTextArray; 218 CFX_WideStringArray wsSelTextArray;
264 int32_t iStart = 0; 219 int32_t iStart = 0;
265 int32_t iEnd = wsRawValue.Find(L'\n', iStart); 220 int32_t iEnd = wsRawValue.Find(L'\n', iStart);
266 iEnd = (iEnd == -1) ? wsRawValue.GetLength() : iEnd; 221 iEnd = (iEnd == -1) ? wsRawValue.GetLength() : iEnd;
267 while (iEnd >= iStart) { 222 while (iEnd >= iStart) {
268 wsSelTextArray.Add(wsRawValue.Mid(iStart, iEnd - iStart)); 223 wsSelTextArray.Add(wsRawValue.Mid(iStart, iEnd - iStart));
269 iStart = iEnd + 1; 224 iStart = iEnd + 1;
270 if (iStart >= wsRawValue.GetLength()) { 225 if (iStart >= wsRawValue.GetLength())
271 break; 226 break;
272 } 227
273 iEnd = wsRawValue.Find(L'\n', iStart); 228 iEnd = wsRawValue.Find(L'\n', iStart);
274 } 229 }
275 CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent); 230 CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
276 ASSERT(pParentNode); 231 ASSERT(pParentNode);
277 CXFA_Node* pGrandparentNode = 232 CXFA_Node* pGrandparentNode =
278 pParentNode->GetNodeItem(XFA_NODEITEM_Parent); 233 pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
279 ASSERT(pGrandparentNode); 234 ASSERT(pGrandparentNode);
280 CFX_WideString bodyTagName; 235 CFX_WideString bodyTagName;
281 bodyTagName = pGrandparentNode->GetCData(XFA_ATTRIBUTE_Name); 236 bodyTagName = pGrandparentNode->GetCData(XFA_ATTRIBUTE_Name);
282 if (bodyTagName.IsEmpty()) { 237 if (bodyTagName.IsEmpty())
283 bodyTagName = FX_WSTRC(L"ListBox1"); 238 bodyTagName = FX_WSTRC(L"ListBox1");
284 } 239
285 buf << FX_WSTRC(L"<"); 240 buf << FX_WSTRC(L"<");
286 buf << bodyTagName; 241 buf << bodyTagName;
287 buf << FX_WSTRC(L" xmlns=\"\"\n>"); 242 buf << FX_WSTRC(L" xmlns=\"\"\n>");
288 for (int32_t i = 0; i < wsSelTextArray.GetSize(); i++) { 243 for (int32_t i = 0; i < wsSelTextArray.GetSize(); i++) {
289 buf << FX_WSTRC(L"<value\n>"); 244 buf << FX_WSTRC(L"<value\n>");
290 buf << XFA_ExportEncodeContent(wsSelTextArray[i].AsStringC()); 245 buf << ExportEncodeContent(wsSelTextArray[i].AsStringC());
291 buf << FX_WSTRC(L"</value\n>"); 246 buf << FX_WSTRC(L"</value\n>");
292 } 247 }
293 buf << FX_WSTRC(L"</"); 248 buf << FX_WSTRC(L"</");
294 buf << bodyTagName; 249 buf << bodyTagName;
295 buf << FX_WSTRC(L"\n>"); 250 buf << FX_WSTRC(L"\n>");
296 wsChildren += buf.AsStringC(); 251 wsChildren += buf.AsStringC();
297 buf.Clear(); 252 buf.Clear();
298 } else { 253 } else {
299 CFX_WideStringC wsValue = pRawValueNode->GetCData(XFA_ATTRIBUTE_Value); 254 CFX_WideStringC wsValue = pRawValueNode->GetCData(XFA_ATTRIBUTE_Value);
300 wsChildren += XFA_ExportEncodeContent(wsValue); 255 wsChildren += ExportEncodeContent(wsValue);
301 } 256 }
302 } break; 257 break;
258 }
303 case XFA_ObjectType::TextNode: 259 case XFA_ObjectType::TextNode:
304 case XFA_ObjectType::NodeC: 260 case XFA_ObjectType::NodeC:
305 case XFA_ObjectType::NodeV: { 261 case XFA_ObjectType::NodeV: {
306 CFX_WideStringC wsValue = pNode->GetCData(XFA_ATTRIBUTE_Value); 262 CFX_WideStringC wsValue = pNode->GetCData(XFA_ATTRIBUTE_Value);
307 wsChildren += XFA_ExportEncodeContent(wsValue); 263 wsChildren += ExportEncodeContent(wsValue);
308 } break; 264 break;
265 }
309 default: 266 default:
310 if (pNode->GetElementType() == XFA_Element::Items) { 267 if (pNode->GetElementType() == XFA_Element::Items) {
311 CXFA_Node* pTemplateNode = pNode->GetTemplateNode(); 268 CXFA_Node* pTemplateNode = pNode->GetTemplateNode();
312 if (!pTemplateNode || 269 if (!pTemplateNode ||
313 pTemplateNode->CountChildren(XFA_Element::Unknown) != 270 pTemplateNode->CountChildren(XFA_Element::Unknown) !=
314 pNode->CountChildren(XFA_Element::Unknown)) { 271 pNode->CountChildren(XFA_Element::Unknown)) {
315 bSaveXML = TRUE; 272 bSaveXML = TRUE;
316 } 273 }
317 } 274 }
318 CFX_WideTextBuf newBuf; 275 CFX_WideTextBuf newBuf;
319 CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); 276 CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
320 while (pChildNode) { 277 while (pChildNode) {
321 XFA_DataExporter_RegenerateFormFile_Changed(pChildNode, newBuf, 278 RegenerateFormFile_Changed(pChildNode, newBuf, bSaveXML);
322 bSaveXML);
323 wsChildren += newBuf.AsStringC(); 279 wsChildren += newBuf.AsStringC();
324 newBuf.Clear(); 280 newBuf.Clear();
325 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); 281 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling);
326 } 282 }
327 if (!bSaveXML && !wsChildren.IsEmpty() && 283 if (!bSaveXML && !wsChildren.IsEmpty() &&
328 pNode->GetElementType() == XFA_Element::Items) { 284 pNode->GetElementType() == XFA_Element::Items) {
329 wsChildren.clear(); 285 wsChildren.clear();
330 bSaveXML = TRUE; 286 bSaveXML = TRUE;
331 CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); 287 CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
332 while (pChild) { 288 while (pChild) {
333 XFA_DataExporter_RegenerateFormFile_Changed(pChild, newBuf, bSaveXML); 289 RegenerateFormFile_Changed(pChild, newBuf, bSaveXML);
334 wsChildren += newBuf.AsStringC(); 290 wsChildren += newBuf.AsStringC();
335 newBuf.Clear(); 291 newBuf.Clear();
336 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); 292 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
337 } 293 }
338 } 294 }
339 break; 295 break;
340 } 296 }
297
341 if (!wsChildren.IsEmpty() || !wsAttrs.IsEmpty() || 298 if (!wsChildren.IsEmpty() || !wsAttrs.IsEmpty() ||
342 pNode->HasAttribute(XFA_ATTRIBUTE_Name)) { 299 pNode->HasAttribute(XFA_ATTRIBUTE_Name)) {
343 CFX_WideStringC wsElement = pNode->GetClassName(); 300 CFX_WideStringC wsElement = pNode->GetClassName();
344 CFX_WideString wsName; 301 CFX_WideString wsName;
345 XFA_SaveAttribute(pNode, XFA_ATTRIBUTE_Name, FX_WSTRC(L"name"), TRUE, 302 SaveAttribute(pNode, XFA_ATTRIBUTE_Name, FX_WSTRC(L"name"), TRUE, wsName);
346 wsName);
347 buf << FX_WSTRC(L"<"); 303 buf << FX_WSTRC(L"<");
348 buf << wsElement; 304 buf << wsElement;
349 buf << wsName; 305 buf << wsName;
350 buf << wsAttrs; 306 buf << wsAttrs;
351 if (wsChildren.IsEmpty()) { 307 if (wsChildren.IsEmpty()) {
352 buf << FX_WSTRC(L"\n/>"); 308 buf << FX_WSTRC(L"\n/>");
353 } else { 309 } else {
354 buf << FX_WSTRC(L"\n>"); 310 buf << FX_WSTRC(L"\n>");
355 buf << wsChildren; 311 buf << wsChildren;
356 buf << FX_WSTRC(L"</"); 312 buf << FX_WSTRC(L"</");
357 buf << wsElement; 313 buf << wsElement;
358 buf << FX_WSTRC(L"\n>"); 314 buf << FX_WSTRC(L"\n>");
359 } 315 }
360 } 316 }
361 } 317 }
362 static void XFA_DataExporter_RegenerateFormFile_Container( 318
363 CXFA_Node* pNode, 319 void RegenerateFormFile_Container(CXFA_Node* pNode,
364 IFX_Stream* pStream, 320 IFX_Stream* pStream,
365 FX_BOOL bSaveXML = FALSE) { 321 FX_BOOL bSaveXML = FALSE) {
366 XFA_Element eType = pNode->GetElementType(); 322 XFA_Element eType = pNode->GetElementType();
367 if (eType == XFA_Element::Field || eType == XFA_Element::Draw || 323 if (eType == XFA_Element::Field || eType == XFA_Element::Draw ||
368 !pNode->IsContainerNode()) { 324 !pNode->IsContainerNode()) {
369 CFX_WideTextBuf buf; 325 CFX_WideTextBuf buf;
370 XFA_DataExporter_RegenerateFormFile_Changed(pNode, buf, bSaveXML); 326 RegenerateFormFile_Changed(pNode, buf, bSaveXML);
371 FX_STRSIZE nLen = buf.GetLength(); 327 FX_STRSIZE nLen = buf.GetLength();
372 if (nLen > 0) { 328 if (nLen > 0)
373 pStream->WriteString((const FX_WCHAR*)buf.GetBuffer(), nLen); 329 pStream->WriteString((const FX_WCHAR*)buf.GetBuffer(), nLen);
374 }
375 return; 330 return;
376 } 331 }
332
377 CFX_WideStringC wsElement = pNode->GetClassName(); 333 CFX_WideStringC wsElement = pNode->GetClassName();
378 pStream->WriteString(L"<", 1); 334 pStream->WriteString(L"<", 1);
379 pStream->WriteString(wsElement.c_str(), wsElement.GetLength()); 335 pStream->WriteString(wsElement.c_str(), wsElement.GetLength());
380 CFX_WideString wsOutput; 336 CFX_WideString wsOutput;
381 XFA_SaveAttribute(pNode, XFA_ATTRIBUTE_Name, FX_WSTRC(L"name"), TRUE, 337 SaveAttribute(pNode, XFA_ATTRIBUTE_Name, FX_WSTRC(L"name"), TRUE, wsOutput);
382 wsOutput);
383 CFX_WideString wsAttrs; 338 CFX_WideString wsAttrs;
384 int32_t iAttrs = 0; 339 int32_t iAttrs = 0;
385 const uint8_t* pAttrs = 340 const uint8_t* pAttrs =
386 XFA_GetElementAttributes(pNode->GetElementType(), iAttrs); 341 XFA_GetElementAttributes(pNode->GetElementType(), iAttrs);
387 while (iAttrs--) { 342 while (iAttrs--) {
388 const XFA_ATTRIBUTEINFO* pAttr = 343 const XFA_ATTRIBUTEINFO* pAttr =
389 XFA_GetAttributeByID((XFA_ATTRIBUTE)pAttrs[iAttrs]); 344 XFA_GetAttributeByID((XFA_ATTRIBUTE)pAttrs[iAttrs]);
390 if (pAttr->eName == XFA_ATTRIBUTE_Name) { 345 if (pAttr->eName == XFA_ATTRIBUTE_Name)
391 continue; 346 continue;
392 } 347
393 CFX_WideString wsAttr; 348 CFX_WideString wsAttr;
394 XFA_SaveAttribute(pNode, pAttr->eName, pAttr->pName, FALSE, wsAttr); 349 SaveAttribute(pNode, pAttr->eName, pAttr->pName, FALSE, wsAttr);
395 wsOutput += wsAttr; 350 wsOutput += wsAttr;
396 } 351 }
397 if (!wsOutput.IsEmpty()) { 352
353 if (!wsOutput.IsEmpty())
398 pStream->WriteString(wsOutput.c_str(), wsOutput.GetLength()); 354 pStream->WriteString(wsOutput.c_str(), wsOutput.GetLength());
399 } 355
400 CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); 356 CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
401 if (pChildNode) { 357 if (pChildNode) {
402 pStream->WriteString(L"\n>", 2); 358 pStream->WriteString(L"\n>", 2);
403 while (pChildNode) { 359 while (pChildNode) {
404 XFA_DataExporter_RegenerateFormFile_Container(pChildNode, pStream, 360 RegenerateFormFile_Container(pChildNode, pStream, bSaveXML);
405 bSaveXML);
406 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); 361 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling);
407 } 362 }
408 pStream->WriteString(L"</", 2); 363 pStream->WriteString(L"</", 2);
409 pStream->WriteString(wsElement.c_str(), wsElement.GetLength()); 364 pStream->WriteString(wsElement.c_str(), wsElement.GetLength());
410 pStream->WriteString(L"\n>", 2); 365 pStream->WriteString(L"\n>", 2);
411 } else { 366 } else {
412 pStream->WriteString(L"\n/>", 3); 367 pStream->WriteString(L"\n/>", 3);
413 } 368 }
414 } 369 }
370
371 } // namespace
372
415 void XFA_DataExporter_RegenerateFormFile(CXFA_Node* pNode, 373 void XFA_DataExporter_RegenerateFormFile(CXFA_Node* pNode,
416 IFX_Stream* pStream, 374 IFX_Stream* pStream,
417 const FX_CHAR* pChecksum, 375 const FX_CHAR* pChecksum,
418 FX_BOOL bSaveXML) { 376 FX_BOOL bSaveXML) {
419 if (pNode->IsModelNode()) { 377 if (pNode->IsModelNode()) {
420 static const FX_WCHAR s_pwsTagName[] = L"<form"; 378 static const FX_WCHAR s_pwsTagName[] = L"<form";
421 static const FX_WCHAR s_pwsClose[] = L"</form\n>"; 379 static const FX_WCHAR s_pwsClose[] = L"</form\n>";
422 pStream->WriteString(s_pwsTagName, FXSYS_wcslen(s_pwsTagName)); 380 pStream->WriteString(s_pwsTagName, FXSYS_wcslen(s_pwsTagName));
423 if (pChecksum) { 381 if (pChecksum) {
424 static const FX_WCHAR s_pwChecksum[] = L" checksum=\""; 382 static const FX_WCHAR s_pwChecksum[] = L" checksum=\"";
425 CFX_WideString wsChecksum = CFX_WideString::FromUTF8(pChecksum); 383 CFX_WideString wsChecksum = CFX_WideString::FromUTF8(pChecksum);
426 pStream->WriteString(s_pwChecksum, FXSYS_wcslen(s_pwChecksum)); 384 pStream->WriteString(s_pwChecksum, FXSYS_wcslen(s_pwChecksum));
427 pStream->WriteString(wsChecksum.c_str(), wsChecksum.GetLength()); 385 pStream->WriteString(wsChecksum.c_str(), wsChecksum.GetLength());
428 pStream->WriteString(L"\"", 1); 386 pStream->WriteString(L"\"", 1);
429 } 387 }
430 pStream->WriteString(L" xmlns=\"", FXSYS_wcslen(L" xmlns=\"")); 388 pStream->WriteString(L" xmlns=\"", FXSYS_wcslen(L" xmlns=\""));
431 const FX_WCHAR* pURI = XFA_GetPacketByIndex(XFA_PACKET_Form)->pURI; 389 const FX_WCHAR* pURI = XFA_GetPacketByIndex(XFA_PACKET_Form)->pURI;
432 pStream->WriteString(pURI, FXSYS_wcslen(pURI)); 390 pStream->WriteString(pURI, FXSYS_wcslen(pURI));
433 CFX_WideString wsVersionNumber; 391 CFX_WideString wsVersionNumber;
434 XFA_DataExporter_RecognizeXFAVersionNumber( 392 RecognizeXFAVersionNumber(
435 ToNode(pNode->GetDocument()->GetXFAObject(XFA_HASHCODE_Template)), 393 ToNode(pNode->GetDocument()->GetXFAObject(XFA_HASHCODE_Template)),
436 wsVersionNumber); 394 wsVersionNumber);
437 if (wsVersionNumber.IsEmpty()) { 395 if (wsVersionNumber.IsEmpty()) {
438 wsVersionNumber = FX_WSTRC(L"2.8"); 396 wsVersionNumber = FX_WSTRC(L"2.8");
439 } 397 }
440 wsVersionNumber += FX_WSTRC(L"/\"\n>"); 398 wsVersionNumber += FX_WSTRC(L"/\"\n>");
441 pStream->WriteString(wsVersionNumber.c_str(), wsVersionNumber.GetLength()); 399 pStream->WriteString(wsVersionNumber.c_str(), wsVersionNumber.GetLength());
442 CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); 400 CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
443 while (pChildNode) { 401 while (pChildNode) {
444 XFA_DataExporter_RegenerateFormFile_Container(pChildNode, pStream); 402 RegenerateFormFile_Container(pChildNode, pStream);
445 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); 403 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling);
446 } 404 }
447 pStream->WriteString(s_pwsClose, FXSYS_wcslen(s_pwsClose)); 405 pStream->WriteString(s_pwsClose, FXSYS_wcslen(s_pwsClose));
448 } else { 406 } else {
449 XFA_DataExporter_RegenerateFormFile_Container(pNode, pStream, bSaveXML); 407 RegenerateFormFile_Container(pNode, pStream, bSaveXML);
450 } 408 }
451 } 409 }
452 410
411 void XFA_DataExporter_DealWithDataGroupNode(CXFA_Node* pDataNode) {
412 if (!pDataNode || pDataNode->GetElementType() == XFA_Element::DataValue)
413 return;
414
415 int32_t iChildNum = 0;
416 for (CXFA_Node* pChildNode = pDataNode->GetNodeItem(XFA_NODEITEM_FirstChild);
417 pChildNode;
418 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
419 iChildNum++;
420 XFA_DataExporter_DealWithDataGroupNode(pChildNode);
421 }
422
423 if (pDataNode->GetElementType() != XFA_Element::DataGroup)
424 return;
425
426 if (iChildNum > 0) {
427 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode();
428 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element);
429 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
430 if (pXMLElement->HasAttribute(L"xfa:dataNode"))
431 pXMLElement->RemoveAttribute(L"xfa:dataNode");
432
433 return;
434 }
435
436 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode();
437 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element);
438 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"xfa:dataNode",
439 L"dataGroup");
440 }
441
453 CXFA_DataExporter::CXFA_DataExporter(CXFA_Document* pDocument) 442 CXFA_DataExporter::CXFA_DataExporter(CXFA_Document* pDocument)
454 : m_pDocument(pDocument) { 443 : m_pDocument(pDocument) {
455 ASSERT(m_pDocument); 444 ASSERT(m_pDocument);
456 } 445 }
446
457 FX_BOOL CXFA_DataExporter::Export(IFX_FileWrite* pWrite) { 447 FX_BOOL CXFA_DataExporter::Export(IFX_FileWrite* pWrite) {
458 return Export(pWrite, m_pDocument->GetRoot()); 448 return Export(pWrite, m_pDocument->GetRoot(), 0, nullptr);
459 } 449 }
450
460 FX_BOOL CXFA_DataExporter::Export(IFX_FileWrite* pWrite, 451 FX_BOOL CXFA_DataExporter::Export(IFX_FileWrite* pWrite,
461 CXFA_Node* pNode, 452 CXFA_Node* pNode,
462 uint32_t dwFlag, 453 uint32_t dwFlag,
463 const FX_CHAR* pChecksum) { 454 const FX_CHAR* pChecksum) {
464 if (!pWrite) { 455 if (!pWrite) {
465 ASSERT(false); 456 ASSERT(false);
466 return FALSE; 457 return FALSE;
467 } 458 }
468 IFX_Stream* pStream = IFX_Stream::CreateStream( 459 IFX_Stream* pStream = IFX_Stream::CreateStream(
469 pWrite, 460 pWrite,
470 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); 461 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
471 if (!pStream) { 462 if (!pStream)
472 return FALSE; 463 return FALSE;
473 } 464
474 pStream->SetCodePage(FX_CODEPAGE_UTF8); 465 pStream->SetCodePage(FX_CODEPAGE_UTF8);
475 FX_BOOL bRet = Export(pStream, pNode, dwFlag, pChecksum); 466 FX_BOOL bRet = Export(pStream, pNode, dwFlag, pChecksum);
476 pStream->Release(); 467 pStream->Release();
477 return bRet; 468 return bRet;
478 } 469 }
470
479 FX_BOOL CXFA_DataExporter::Export(IFX_Stream* pStream, 471 FX_BOOL CXFA_DataExporter::Export(IFX_Stream* pStream,
480 CXFA_Node* pNode, 472 CXFA_Node* pNode,
481 uint32_t dwFlag, 473 uint32_t dwFlag,
482 const FX_CHAR* pChecksum) { 474 const FX_CHAR* pChecksum) {
483 CFDE_XMLDoc* pXMLDoc = m_pDocument->GetXMLDoc(); 475 CFDE_XMLDoc* pXMLDoc = m_pDocument->GetXMLDoc();
484 if (pNode->IsModelNode()) { 476 if (pNode->IsModelNode()) {
485 switch (pNode->GetPacketID()) { 477 switch (pNode->GetPacketID()) {
486 case XFA_XDPPACKET_XDP: { 478 case XFA_XDPPACKET_XDP: {
487 static const FX_WCHAR s_pwsPreamble[] = 479 static const FX_WCHAR s_pwsPreamble[] =
488 L"<xdp:xdp xmlns:xdp=\"http://ns.adobe.com/xdp/\">"; 480 L"<xdp:xdp xmlns:xdp=\"http://ns.adobe.com/xdp/\">";
489 pStream->WriteString(s_pwsPreamble, FXSYS_wcslen(s_pwsPreamble)); 481 pStream->WriteString(s_pwsPreamble, FXSYS_wcslen(s_pwsPreamble));
490 for (CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); 482 for (CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
491 pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { 483 pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
492 Export(pStream, pChild, dwFlag, pChecksum); 484 Export(pStream, pChild, dwFlag, pChecksum);
493 } 485 }
494 static const FX_WCHAR s_pwsPostamble[] = L"</xdp:xdp\n>"; 486 static const FX_WCHAR s_pwsPostamble[] = L"</xdp:xdp\n>";
495 pStream->WriteString(s_pwsPostamble, FXSYS_wcslen(s_pwsPostamble)); 487 pStream->WriteString(s_pwsPostamble, FXSYS_wcslen(s_pwsPostamble));
496 } break; 488 break;
489 }
497 case XFA_XDPPACKET_Datasets: { 490 case XFA_XDPPACKET_Datasets: {
498 CFDE_XMLElement* pElement = 491 CFDE_XMLElement* pElement =
499 static_cast<CFDE_XMLElement*>(pNode->GetXMLMappingNode()); 492 static_cast<CFDE_XMLElement*>(pNode->GetXMLMappingNode());
500 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) { 493 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element)
501 return FALSE; 494 return FALSE;
502 } 495
503 CXFA_Node* pDataNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); 496 CXFA_Node* pDataNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
504 ASSERT(pDataNode); 497 ASSERT(pDataNode);
505 XFA_DataExporter_DealWithDataGroupNode(pDataNode); 498 XFA_DataExporter_DealWithDataGroupNode(pDataNode);
506 pXMLDoc->SaveXMLNode(pStream, pElement); 499 pXMLDoc->SaveXMLNode(pStream, pElement);
507 } break; 500 break;
501 }
508 case XFA_XDPPACKET_Form: { 502 case XFA_XDPPACKET_Form: {
509 XFA_DataExporter_RegenerateFormFile(pNode, pStream, pChecksum); 503 XFA_DataExporter_RegenerateFormFile(pNode, pStream, pChecksum);
510 } break; 504 break;
505 }
511 case XFA_XDPPACKET_Template: 506 case XFA_XDPPACKET_Template:
512 default: { 507 default: {
513 CFDE_XMLElement* pElement = 508 CFDE_XMLElement* pElement =
514 static_cast<CFDE_XMLElement*>(pNode->GetXMLMappingNode()); 509 static_cast<CFDE_XMLElement*>(pNode->GetXMLMappingNode());
515 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) { 510 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element)
516 return FALSE; 511 return FALSE;
517 } 512
518 pXMLDoc->SaveXMLNode(pStream, pElement); 513 pXMLDoc->SaveXMLNode(pStream, pElement);
519 } break;
520 }
521 } else {
522 CXFA_Node* pDataNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
523 CXFA_Node* pExportNode = pNode;
524 for (CXFA_Node* pChildNode =
525 pDataNode->GetNodeItem(XFA_NODEITEM_FirstChild);
526 pChildNode;
527 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
528 if (pChildNode != pNode) {
529 pExportNode = pDataNode;
530 break; 514 break;
531 } 515 }
532 } 516 }
533 CFDE_XMLElement* pElement = 517 return TRUE;
534 static_cast<CFDE_XMLElement*>(pExportNode->GetXMLMappingNode());
535 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
536 return FALSE;
537 }
538 XFA_DataExporter_DealWithDataGroupNode(pExportNode);
539 pElement->SetString(L"xmlns:xfa",
540 L"http://www.xfa.org/schema/xfa-data/1.0/");
541 pXMLDoc->SaveXMLNode(pStream, pElement);
542 pElement->RemoveAttribute(L"xmlns:xfa");
543 } 518 }
544 return TRUE; 519
545 } 520 CXFA_Node* pDataNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
546 void XFA_DataExporter_DealWithDataGroupNode(CXFA_Node* pDataNode) { 521 CXFA_Node* pExportNode = pNode;
547 if (!pDataNode || pDataNode->GetElementType() == XFA_Element::DataValue) {
548 return;
549 }
550 int32_t iChildNum = 0;
551 for (CXFA_Node* pChildNode = pDataNode->GetNodeItem(XFA_NODEITEM_FirstChild); 522 for (CXFA_Node* pChildNode = pDataNode->GetNodeItem(XFA_NODEITEM_FirstChild);
552 pChildNode; 523 pChildNode;
553 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { 524 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
554 iChildNum++; 525 if (pChildNode != pNode) {
555 XFA_DataExporter_DealWithDataGroupNode(pChildNode); 526 pExportNode = pDataNode;
556 } 527 break;
557 if (pDataNode->GetElementType() == XFA_Element::DataGroup) {
558 if (iChildNum > 0) {
559 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode();
560 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element);
561 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
562 if (pXMLElement->HasAttribute(L"xfa:dataNode")) {
563 pXMLElement->RemoveAttribute(L"xfa:dataNode");
564 }
565 } else {
566 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode();
567 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element);
568 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"xfa:dataNode",
569 L"dataGroup");
570 } 528 }
571 } 529 }
530 CFDE_XMLElement* pElement =
531 static_cast<CFDE_XMLElement*>(pExportNode->GetXMLMappingNode());
532 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element)
533 return FALSE;
534
535 XFA_DataExporter_DealWithDataGroupNode(pExportNode);
536 pElement->SetString(L"xmlns:xfa", L"http://www.xfa.org/schema/xfa-data/1.0/");
537 pXMLDoc->SaveXMLNode(pStream, pElement);
538 pElement->RemoveAttribute(L"xmlns:xfa");
539
540 return TRUE;
572 } 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