summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/app/xfa_ffdoc.cpp3
-rw-r--r--xfa/fxfa/parser/cxfa_dataexporter.cpp (renamed from xfa/fxfa/parser/xfa_document_serialize.cpp)335
-rw-r--r--xfa/fxfa/parser/cxfa_dataexporter.h (renamed from xfa/fxfa/parser/xfa_document_serialize.h)23
-rw-r--r--xfa/fxfa/parser/cxfa_dataimporter.cpp62
-rw-r--r--xfa/fxfa/parser/cxfa_dataimporter.h25
5 files changed, 247 insertions, 201 deletions
diff --git a/xfa/fxfa/app/xfa_ffdoc.cpp b/xfa/fxfa/app/xfa_ffdoc.cpp
index 6ca1704fc6..a0e00d3e37 100644
--- a/xfa/fxfa/app/xfa_ffdoc.cpp
+++ b/xfa/fxfa/app/xfa_ffdoc.cpp
@@ -21,8 +21,9 @@
#include "xfa/fxfa/include/xfa_ffdocview.h"
#include "xfa/fxfa/include/xfa_ffwidget.h"
#include "xfa/fxfa/include/xfa_fontmgr.h"
+#include "xfa/fxfa/parser/cxfa_dataexporter.h"
+#include "xfa/fxfa/parser/cxfa_dataimporter.h"
#include "xfa/fxfa/parser/cxfa_document.h"
-#include "xfa/fxfa/parser/xfa_document_serialize.h"
namespace {
diff --git a/xfa/fxfa/parser/xfa_document_serialize.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp
index ae30165a2d..fbb9e70b94 100644
--- a/xfa/fxfa/parser/xfa_document_serialize.cpp
+++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp
@@ -4,64 +4,18 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "xfa/fxfa/parser/xfa_document_serialize.h"
+#include "xfa/fxfa/parser/cxfa_dataexporter.h"
+#include "core/fxcrt/include/fx_basic.h"
#include "xfa/fde/xml/fde_xml_imp.h"
#include "xfa/fgas/crt/fgas_codepage.h"
#include "xfa/fxfa/parser/cxfa_document.h"
-#include "xfa/fxfa/parser/cxfa_simple_parser.h"
-#include "xfa/fxfa/parser/xfa_localemgr.h"
+#include "xfa/fxfa/parser/cxfa_widgetdata.h"
#include "xfa/fxfa/parser/xfa_object.h"
-#include "xfa/fxfa/parser/xfa_utils.h"
-CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument)
- : m_pDocument(pDocument) {
- ASSERT(m_pDocument);
-}
-FX_BOOL CXFA_DataImporter::ImportData(IFX_FileRead* pDataDocument) {
- std::unique_ptr<CXFA_SimpleParser> pDataDocumentParser(
- new CXFA_SimpleParser(m_pDocument, false));
- if (!pDataDocumentParser)
- return FALSE;
-
- if (pDataDocumentParser->StartParse(pDataDocument, XFA_XDPPACKET_Datasets) !=
- XFA_PARSESTATUS_Ready) {
- return FALSE;
- }
- if (pDataDocumentParser->DoParse(nullptr) < XFA_PARSESTATUS_Done)
- return FALSE;
+namespace {
- CXFA_Node* pImportDataRoot = pDataDocumentParser->GetRootNode();
- if (!pImportDataRoot)
- return FALSE;
-
- CXFA_Node* pDataModel =
- ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
- if (!pDataModel)
- return FALSE;
-
- CXFA_Node* pDataNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Data));
- if (pDataNode)
- pDataModel->RemoveChild(pDataNode);
-
- if (pImportDataRoot->GetElementType() == XFA_Element::DataModel) {
- while (CXFA_Node* pChildNode =
- pImportDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) {
- pImportDataRoot->RemoveChild(pChildNode);
- pDataModel->InsertChild(pChildNode);
- }
- } else {
- CFDE_XMLNode* pXMLNode = pImportDataRoot->GetXMLMappingNode();
- CFDE_XMLNode* pParentXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
- if (pParentXMLNode)
- pParentXMLNode->RemoveChildNode(pXMLNode);
- pDataModel->InsertChild(pImportDataRoot);
- }
- m_pDocument->DoDataRemerge(FALSE);
- return TRUE;
-}
-
-CFX_WideString XFA_ExportEncodeAttribute(const CFX_WideString& str) {
+CFX_WideString ExportEncodeAttribute(const CFX_WideString& str) {
CFX_WideTextBuf textBuf;
int32_t iLen = str.GetLength();
for (int32_t i = 0; i < iLen; i++) {
@@ -87,14 +41,15 @@ CFX_WideString XFA_ExportEncodeAttribute(const CFX_WideString& str) {
}
return textBuf.MakeString();
}
-CFX_WideString XFA_ExportEncodeContent(const CFX_WideStringC& str) {
+
+CFX_WideString ExportEncodeContent(const CFX_WideStringC& str) {
CFX_WideTextBuf textBuf;
int32_t iLen = str.GetLength();
for (int32_t i = 0; i < iLen; i++) {
FX_WCHAR ch = str.GetAt(i);
- if (!FDE_IsXMLValidChar(ch)) {
+ if (!FDE_IsXMLValidChar(ch))
continue;
- }
+
if (ch == '&') {
textBuf << FX_WSTRC(L"&amp;");
} else if (ch == '<') {
@@ -117,34 +72,34 @@ CFX_WideString XFA_ExportEncodeContent(const CFX_WideStringC& str) {
}
return textBuf.MakeString();
}
-static void XFA_SaveAttribute(CXFA_Node* pNode,
- XFA_ATTRIBUTE eName,
- const CFX_WideStringC& wsName,
- FX_BOOL bProto,
- CFX_WideString& wsOutput) {
+
+void SaveAttribute(CXFA_Node* pNode,
+ XFA_ATTRIBUTE eName,
+ const CFX_WideStringC& wsName,
+ FX_BOOL bProto,
+ CFX_WideString& wsOutput) {
CFX_WideString wsValue;
if ((!bProto && !pNode->HasAttribute((XFA_ATTRIBUTE)eName, bProto)) ||
!pNode->GetAttribute((XFA_ATTRIBUTE)eName, wsValue, FALSE)) {
return;
}
- wsValue = XFA_ExportEncodeAttribute(wsValue);
+ wsValue = ExportEncodeAttribute(wsValue);
wsOutput += FX_WSTRC(L" ");
wsOutput += wsName;
wsOutput += FX_WSTRC(L"=\"");
wsOutput += wsValue;
wsOutput += FX_WSTRC(L"\"");
}
-static FX_BOOL XFA_DataExporter_AttributeSaveInDataModel(
- CXFA_Node* pNode,
- XFA_ATTRIBUTE eAttribute) {
+
+FX_BOOL AttributeSaveInDataModel(CXFA_Node* pNode, XFA_ATTRIBUTE eAttribute) {
FX_BOOL bSaveInDataModel = FALSE;
- if (pNode->GetElementType() != XFA_Element::Image) {
+ if (pNode->GetElementType() != XFA_Element::Image)
return bSaveInDataModel;
- }
+
CXFA_Node* pValueNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
- if (!pValueNode || pValueNode->GetElementType() != XFA_Element::Value) {
+ if (!pValueNode || pValueNode->GetElementType() != XFA_Element::Value)
return bSaveInDataModel;
- }
+
CXFA_Node* pFieldNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
if (pFieldNode && pFieldNode->GetBindData() &&
eAttribute == XFA_ATTRIBUTE_Href) {
@@ -152,7 +107,8 @@ static FX_BOOL XFA_DataExporter_AttributeSaveInDataModel(
}
return bSaveInDataModel;
}
-FX_BOOL XFA_DataExporter_ContentNodeNeedtoExport(CXFA_Node* pContentNode) {
+
+FX_BOOL ContentNodeNeedtoExport(CXFA_Node* pContentNode) {
CFX_WideString wsContent;
if (!pContentNode->TryContent(wsContent, FALSE, FALSE))
return FALSE;
@@ -170,33 +126,32 @@ FX_BOOL XFA_DataExporter_ContentNodeNeedtoExport(CXFA_Node* pContentNode) {
CXFA_WidgetData* pWidgetData = pGrandParentNode->GetWidgetData();
XFA_Element eUIType = pWidgetData->GetUIType();
- if (eUIType == XFA_Element::PasswordEdit) {
+ if (eUIType == XFA_Element::PasswordEdit)
return FALSE;
- }
return TRUE;
}
-static void XFA_DataExporter_RecognizeXFAVersionNumber(
- CXFA_Node* pTemplateRoot,
- CFX_WideString& wsVersionNumber) {
+
+void RecognizeXFAVersionNumber(CXFA_Node* pTemplateRoot,
+ CFX_WideString& wsVersionNumber) {
wsVersionNumber.clear();
- if (!pTemplateRoot) {
+ if (!pTemplateRoot)
return;
- }
+
CFX_WideString wsTemplateNS;
- if (!pTemplateRoot->TryNamespace(wsTemplateNS)) {
+ if (!pTemplateRoot->TryNamespace(wsTemplateNS))
return;
- }
+
XFA_VERSION eVersion =
pTemplateRoot->GetDocument()->RecognizeXFAVersionNumber(wsTemplateNS);
- if (eVersion == XFA_VERSION_UNKNOWN) {
+ if (eVersion == XFA_VERSION_UNKNOWN)
eVersion = XFA_VERSION_DEFAULT;
- }
+
wsVersionNumber.Format(L"%i.%i", eVersion / 100, eVersion % 100);
}
-static void XFA_DataExporter_RegenerateFormFile_Changed(
- CXFA_Node* pNode,
- CFX_WideTextBuf& buf,
- FX_BOOL bSaveXML = FALSE) {
+
+void RegenerateFormFile_Changed(CXFA_Node* pNode,
+ CFX_WideTextBuf& buf,
+ FX_BOOL bSaveXML) {
CFX_WideString wsAttrs;
int32_t iAttrs = 0;
const uint8_t* pAttrs =
@@ -205,20 +160,20 @@ static void XFA_DataExporter_RegenerateFormFile_Changed(
const XFA_ATTRIBUTEINFO* pAttr =
XFA_GetAttributeByID((XFA_ATTRIBUTE)pAttrs[iAttrs]);
if (pAttr->eName == XFA_ATTRIBUTE_Name ||
- (XFA_DataExporter_AttributeSaveInDataModel(pNode, pAttr->eName) &&
- !bSaveXML)) {
+ (AttributeSaveInDataModel(pNode, pAttr->eName) && !bSaveXML)) {
continue;
}
CFX_WideString wsAttr;
- XFA_SaveAttribute(pNode, pAttr->eName, pAttr->pName, bSaveXML, wsAttr);
+ SaveAttribute(pNode, pAttr->eName, pAttr->pName, bSaveXML, wsAttr);
wsAttrs += wsAttr;
}
+
CFX_WideString wsChildren;
switch (pNode->GetObjectType()) {
case XFA_ObjectType::ContentNode: {
- if (!bSaveXML && !XFA_DataExporter_ContentNodeNeedtoExport(pNode)) {
+ if (!bSaveXML && !ContentNodeNeedtoExport(pNode))
break;
- }
+
CXFA_Node* pRawValueNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
while (pRawValueNode &&
pRawValueNode->GetElementType() != XFA_Element::SharpxHTML &&
@@ -226,22 +181,22 @@ static void XFA_DataExporter_RegenerateFormFile_Changed(
pRawValueNode->GetElementType() != XFA_Element::Sharpxml) {
pRawValueNode = pRawValueNode->GetNodeItem(XFA_NODEITEM_NextSibling);
}
- if (!pRawValueNode) {
+ if (!pRawValueNode)
break;
- }
+
CFX_WideString wsContentType;
pNode->GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE);
if (pRawValueNode->GetElementType() == XFA_Element::SharpxHTML &&
wsContentType == FX_WSTRC(L"text/html")) {
CFDE_XMLNode* pExDataXML = pNode->GetXMLMappingNode();
- if (!pExDataXML) {
+ if (!pExDataXML)
break;
- }
+
CFDE_XMLNode* pRichTextXML =
pExDataXML->GetNodeItem(CFDE_XMLNode::FirstChild);
- if (!pRichTextXML) {
+ if (!pRichTextXML)
break;
- }
+
IFX_MemoryStream* pMemStream = FX_CreateMemoryStream(TRUE);
IFX_Stream* pTempStream = IFX_Stream::CreateStream(
(IFX_FileWrite*)pMemStream, FX_STREAMACCESS_Text |
@@ -257,9 +212,9 @@ static void XFA_DataExporter_RegenerateFormFile_Changed(
wsContentType == FX_WSTRC(L"text/xml")) {
CFX_WideString wsRawValue;
pRawValueNode->GetAttribute(XFA_ATTRIBUTE_Value, wsRawValue, FALSE);
- if (wsRawValue.IsEmpty()) {
+ if (wsRawValue.IsEmpty())
break;
- }
+
CFX_WideStringArray wsSelTextArray;
int32_t iStart = 0;
int32_t iEnd = wsRawValue.Find(L'\n', iStart);
@@ -267,9 +222,9 @@ static void XFA_DataExporter_RegenerateFormFile_Changed(
while (iEnd >= iStart) {
wsSelTextArray.Add(wsRawValue.Mid(iStart, iEnd - iStart));
iStart = iEnd + 1;
- if (iStart >= wsRawValue.GetLength()) {
+ if (iStart >= wsRawValue.GetLength())
break;
- }
+
iEnd = wsRawValue.Find(L'\n', iStart);
}
CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
@@ -279,15 +234,15 @@ static void XFA_DataExporter_RegenerateFormFile_Changed(
ASSERT(pGrandparentNode);
CFX_WideString bodyTagName;
bodyTagName = pGrandparentNode->GetCData(XFA_ATTRIBUTE_Name);
- if (bodyTagName.IsEmpty()) {
+ if (bodyTagName.IsEmpty())
bodyTagName = FX_WSTRC(L"ListBox1");
- }
+
buf << FX_WSTRC(L"<");
buf << bodyTagName;
buf << FX_WSTRC(L" xmlns=\"\"\n>");
for (int32_t i = 0; i < wsSelTextArray.GetSize(); i++) {
buf << FX_WSTRC(L"<value\n>");
- buf << XFA_ExportEncodeContent(wsSelTextArray[i].AsStringC());
+ buf << ExportEncodeContent(wsSelTextArray[i].AsStringC());
buf << FX_WSTRC(L"</value\n>");
}
buf << FX_WSTRC(L"</");
@@ -297,15 +252,17 @@ static void XFA_DataExporter_RegenerateFormFile_Changed(
buf.Clear();
} else {
CFX_WideStringC wsValue = pRawValueNode->GetCData(XFA_ATTRIBUTE_Value);
- wsChildren += XFA_ExportEncodeContent(wsValue);
+ wsChildren += ExportEncodeContent(wsValue);
}
- } break;
+ break;
+ }
case XFA_ObjectType::TextNode:
case XFA_ObjectType::NodeC:
case XFA_ObjectType::NodeV: {
CFX_WideStringC wsValue = pNode->GetCData(XFA_ATTRIBUTE_Value);
- wsChildren += XFA_ExportEncodeContent(wsValue);
- } break;
+ wsChildren += ExportEncodeContent(wsValue);
+ break;
+ }
default:
if (pNode->GetElementType() == XFA_Element::Items) {
CXFA_Node* pTemplateNode = pNode->GetTemplateNode();
@@ -318,8 +275,7 @@ static void XFA_DataExporter_RegenerateFormFile_Changed(
CFX_WideTextBuf newBuf;
CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
while (pChildNode) {
- XFA_DataExporter_RegenerateFormFile_Changed(pChildNode, newBuf,
- bSaveXML);
+ RegenerateFormFile_Changed(pChildNode, newBuf, bSaveXML);
wsChildren += newBuf.AsStringC();
newBuf.Clear();
pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling);
@@ -330,7 +286,7 @@ static void XFA_DataExporter_RegenerateFormFile_Changed(
bSaveXML = TRUE;
CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
while (pChild) {
- XFA_DataExporter_RegenerateFormFile_Changed(pChild, newBuf, bSaveXML);
+ RegenerateFormFile_Changed(pChild, newBuf, bSaveXML);
wsChildren += newBuf.AsStringC();
newBuf.Clear();
pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
@@ -338,12 +294,12 @@ static void XFA_DataExporter_RegenerateFormFile_Changed(
}
break;
}
+
if (!wsChildren.IsEmpty() || !wsAttrs.IsEmpty() ||
pNode->HasAttribute(XFA_ATTRIBUTE_Name)) {
CFX_WideStringC wsElement = pNode->GetClassName();
CFX_WideString wsName;
- XFA_SaveAttribute(pNode, XFA_ATTRIBUTE_Name, FX_WSTRC(L"name"), TRUE,
- wsName);
+ SaveAttribute(pNode, XFA_ATTRIBUTE_Name, FX_WSTRC(L"name"), TRUE, wsName);
buf << FX_WSTRC(L"<");
buf << wsElement;
buf << wsName;
@@ -359,27 +315,26 @@ static void XFA_DataExporter_RegenerateFormFile_Changed(
}
}
}
-static void XFA_DataExporter_RegenerateFormFile_Container(
- CXFA_Node* pNode,
- IFX_Stream* pStream,
- FX_BOOL bSaveXML = FALSE) {
+
+void RegenerateFormFile_Container(CXFA_Node* pNode,
+ IFX_Stream* pStream,
+ FX_BOOL bSaveXML = FALSE) {
XFA_Element eType = pNode->GetElementType();
if (eType == XFA_Element::Field || eType == XFA_Element::Draw ||
!pNode->IsContainerNode()) {
CFX_WideTextBuf buf;
- XFA_DataExporter_RegenerateFormFile_Changed(pNode, buf, bSaveXML);
+ RegenerateFormFile_Changed(pNode, buf, bSaveXML);
FX_STRSIZE nLen = buf.GetLength();
- if (nLen > 0) {
+ if (nLen > 0)
pStream->WriteString((const FX_WCHAR*)buf.GetBuffer(), nLen);
- }
return;
}
+
CFX_WideStringC wsElement = pNode->GetClassName();
pStream->WriteString(L"<", 1);
pStream->WriteString(wsElement.c_str(), wsElement.GetLength());
CFX_WideString wsOutput;
- XFA_SaveAttribute(pNode, XFA_ATTRIBUTE_Name, FX_WSTRC(L"name"), TRUE,
- wsOutput);
+ SaveAttribute(pNode, XFA_ATTRIBUTE_Name, FX_WSTRC(L"name"), TRUE, wsOutput);
CFX_WideString wsAttrs;
int32_t iAttrs = 0;
const uint8_t* pAttrs =
@@ -387,22 +342,22 @@ static void XFA_DataExporter_RegenerateFormFile_Container(
while (iAttrs--) {
const XFA_ATTRIBUTEINFO* pAttr =
XFA_GetAttributeByID((XFA_ATTRIBUTE)pAttrs[iAttrs]);
- if (pAttr->eName == XFA_ATTRIBUTE_Name) {
+ if (pAttr->eName == XFA_ATTRIBUTE_Name)
continue;
- }
+
CFX_WideString wsAttr;
- XFA_SaveAttribute(pNode, pAttr->eName, pAttr->pName, FALSE, wsAttr);
+ SaveAttribute(pNode, pAttr->eName, pAttr->pName, FALSE, wsAttr);
wsOutput += wsAttr;
}
- if (!wsOutput.IsEmpty()) {
+
+ if (!wsOutput.IsEmpty())
pStream->WriteString(wsOutput.c_str(), wsOutput.GetLength());
- }
+
CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
if (pChildNode) {
pStream->WriteString(L"\n>", 2);
while (pChildNode) {
- XFA_DataExporter_RegenerateFormFile_Container(pChildNode, pStream,
- bSaveXML);
+ RegenerateFormFile_Container(pChildNode, pStream, bSaveXML);
pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling);
}
pStream->WriteString(L"</", 2);
@@ -412,6 +367,9 @@ static void XFA_DataExporter_RegenerateFormFile_Container(
pStream->WriteString(L"\n/>", 3);
}
}
+
+} // namespace
+
void XFA_DataExporter_RegenerateFormFile(CXFA_Node* pNode,
IFX_Stream* pStream,
const FX_CHAR* pChecksum,
@@ -431,7 +389,7 @@ void XFA_DataExporter_RegenerateFormFile(CXFA_Node* pNode,
const FX_WCHAR* pURI = XFA_GetPacketByIndex(XFA_PACKET_Form)->pURI;
pStream->WriteString(pURI, FXSYS_wcslen(pURI));
CFX_WideString wsVersionNumber;
- XFA_DataExporter_RecognizeXFAVersionNumber(
+ RecognizeXFAVersionNumber(
ToNode(pNode->GetDocument()->GetXFAObject(XFA_HASHCODE_Template)),
wsVersionNumber);
if (wsVersionNumber.IsEmpty()) {
@@ -441,22 +399,55 @@ void XFA_DataExporter_RegenerateFormFile(CXFA_Node* pNode,
pStream->WriteString(wsVersionNumber.c_str(), wsVersionNumber.GetLength());
CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
while (pChildNode) {
- XFA_DataExporter_RegenerateFormFile_Container(pChildNode, pStream);
+ RegenerateFormFile_Container(pChildNode, pStream);
pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling);
}
pStream->WriteString(s_pwsClose, FXSYS_wcslen(s_pwsClose));
} else {
- XFA_DataExporter_RegenerateFormFile_Container(pNode, pStream, bSaveXML);
+ RegenerateFormFile_Container(pNode, pStream, bSaveXML);
}
}
+void XFA_DataExporter_DealWithDataGroupNode(CXFA_Node* pDataNode) {
+ if (!pDataNode || pDataNode->GetElementType() == XFA_Element::DataValue)
+ return;
+
+ int32_t iChildNum = 0;
+ for (CXFA_Node* pChildNode = pDataNode->GetNodeItem(XFA_NODEITEM_FirstChild);
+ pChildNode;
+ pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
+ iChildNum++;
+ XFA_DataExporter_DealWithDataGroupNode(pChildNode);
+ }
+
+ if (pDataNode->GetElementType() != XFA_Element::DataGroup)
+ return;
+
+ if (iChildNum > 0) {
+ CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode();
+ ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element);
+ CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
+ if (pXMLElement->HasAttribute(L"xfa:dataNode"))
+ pXMLElement->RemoveAttribute(L"xfa:dataNode");
+
+ return;
+ }
+
+ CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode();
+ ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element);
+ static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"xfa:dataNode",
+ L"dataGroup");
+}
+
CXFA_DataExporter::CXFA_DataExporter(CXFA_Document* pDocument)
: m_pDocument(pDocument) {
ASSERT(m_pDocument);
}
+
FX_BOOL CXFA_DataExporter::Export(IFX_FileWrite* pWrite) {
- return Export(pWrite, m_pDocument->GetRoot());
+ return Export(pWrite, m_pDocument->GetRoot(), 0, nullptr);
}
+
FX_BOOL CXFA_DataExporter::Export(IFX_FileWrite* pWrite,
CXFA_Node* pNode,
uint32_t dwFlag,
@@ -468,14 +459,15 @@ FX_BOOL CXFA_DataExporter::Export(IFX_FileWrite* pWrite,
IFX_Stream* pStream = IFX_Stream::CreateStream(
pWrite,
FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
- if (!pStream) {
+ if (!pStream)
return FALSE;
- }
+
pStream->SetCodePage(FX_CODEPAGE_UTF8);
FX_BOOL bRet = Export(pStream, pNode, dwFlag, pChecksum);
pStream->Release();
return bRet;
}
+
FX_BOOL CXFA_DataExporter::Export(IFX_Stream* pStream,
CXFA_Node* pNode,
uint32_t dwFlag,
@@ -493,80 +485,57 @@ FX_BOOL CXFA_DataExporter::Export(IFX_Stream* pStream,
}
static const FX_WCHAR s_pwsPostamble[] = L"</xdp:xdp\n>";
pStream->WriteString(s_pwsPostamble, FXSYS_wcslen(s_pwsPostamble));
- } break;
+ break;
+ }
case XFA_XDPPACKET_Datasets: {
CFDE_XMLElement* pElement =
static_cast<CFDE_XMLElement*>(pNode->GetXMLMappingNode());
- if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
+ if (!pElement || pElement->GetType() != FDE_XMLNODE_Element)
return FALSE;
- }
+
CXFA_Node* pDataNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
ASSERT(pDataNode);
XFA_DataExporter_DealWithDataGroupNode(pDataNode);
pXMLDoc->SaveXMLNode(pStream, pElement);
- } break;
+ break;
+ }
case XFA_XDPPACKET_Form: {
XFA_DataExporter_RegenerateFormFile(pNode, pStream, pChecksum);
- } break;
+ break;
+ }
case XFA_XDPPACKET_Template:
default: {
CFDE_XMLElement* pElement =
static_cast<CFDE_XMLElement*>(pNode->GetXMLMappingNode());
- if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
+ if (!pElement || pElement->GetType() != FDE_XMLNODE_Element)
return FALSE;
- }
+
pXMLDoc->SaveXMLNode(pStream, pElement);
- } break;
- }
- } else {
- CXFA_Node* pDataNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
- CXFA_Node* pExportNode = pNode;
- for (CXFA_Node* pChildNode =
- pDataNode->GetNodeItem(XFA_NODEITEM_FirstChild);
- pChildNode;
- pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
- if (pChildNode != pNode) {
- pExportNode = pDataNode;
break;
}
}
- CFDE_XMLElement* pElement =
- static_cast<CFDE_XMLElement*>(pExportNode->GetXMLMappingNode());
- if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
- return FALSE;
- }
- XFA_DataExporter_DealWithDataGroupNode(pExportNode);
- pElement->SetString(L"xmlns:xfa",
- L"http://www.xfa.org/schema/xfa-data/1.0/");
- pXMLDoc->SaveXMLNode(pStream, pElement);
- pElement->RemoveAttribute(L"xmlns:xfa");
- }
- return TRUE;
-}
-void XFA_DataExporter_DealWithDataGroupNode(CXFA_Node* pDataNode) {
- if (!pDataNode || pDataNode->GetElementType() == XFA_Element::DataValue) {
- return;
+ return TRUE;
}
- int32_t iChildNum = 0;
+
+ CXFA_Node* pDataNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
+ CXFA_Node* pExportNode = pNode;
for (CXFA_Node* pChildNode = pDataNode->GetNodeItem(XFA_NODEITEM_FirstChild);
pChildNode;
pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
- iChildNum++;
- XFA_DataExporter_DealWithDataGroupNode(pChildNode);
- }
- if (pDataNode->GetElementType() == XFA_Element::DataGroup) {
- if (iChildNum > 0) {
- CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode();
- ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element);
- CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
- if (pXMLElement->HasAttribute(L"xfa:dataNode")) {
- pXMLElement->RemoveAttribute(L"xfa:dataNode");
- }
- } else {
- CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode();
- ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element);
- static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"xfa:dataNode",
- L"dataGroup");
+ if (pChildNode != pNode) {
+ pExportNode = pDataNode;
+ break;
}
}
+ CFDE_XMLElement* pElement =
+ static_cast<CFDE_XMLElement*>(pExportNode->GetXMLMappingNode());
+ if (!pElement || pElement->GetType() != FDE_XMLNODE_Element)
+ return FALSE;
+
+ XFA_DataExporter_DealWithDataGroupNode(pExportNode);
+ pElement->SetString(L"xmlns:xfa", L"http://www.xfa.org/schema/xfa-data/1.0/");
+ pXMLDoc->SaveXMLNode(pStream, pElement);
+ pElement->RemoveAttribute(L"xmlns:xfa");
+
+ return TRUE;
}
diff --git a/xfa/fxfa/parser/xfa_document_serialize.h b/xfa/fxfa/parser/cxfa_dataexporter.h
index 276a0d3faa..3049ae2d02 100644
--- a/xfa/fxfa/parser/xfa_document_serialize.h
+++ b/xfa/fxfa/parser/cxfa_dataexporter.h
@@ -1,30 +1,19 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#ifndef XFA_FXFA_PARSER_XFA_DOCUMENT_SERIALIZE_H_
-#define XFA_FXFA_PARSER_XFA_DOCUMENT_SERIALIZE_H_
+#ifndef XFA_FXFA_PARSER_CXFA_DATAEXPORTER_H_
+#define XFA_FXFA_PARSER_CXFA_DATAEXPORTER_H_
#include "core/fxcrt/include/fx_string.h"
class CXFA_Document;
class CXFA_Node;
-class IFX_FileRead;
class IFX_FileWrite;
class IFX_Stream;
-class CXFA_DataImporter {
- public:
- explicit CXFA_DataImporter(CXFA_Document* pDocument);
-
- FX_BOOL ImportData(IFX_FileRead* pDataDocument);
-
- protected:
- CXFA_Document* const m_pDocument;
-};
-
class CXFA_DataExporter {
public:
explicit CXFA_DataExporter(CXFA_Document* pDocument);
@@ -32,8 +21,8 @@ class CXFA_DataExporter {
FX_BOOL Export(IFX_FileWrite* pWrite);
FX_BOOL Export(IFX_FileWrite* pWrite,
CXFA_Node* pNode,
- uint32_t dwFlag = 0,
- const FX_CHAR* pChecksum = nullptr);
+ uint32_t dwFlag,
+ const FX_CHAR* pChecksum);
protected:
FX_BOOL Export(IFX_Stream* pStream,
@@ -44,4 +33,4 @@ class CXFA_DataExporter {
CXFA_Document* const m_pDocument;
};
-#endif // XFA_FXFA_PARSER_XFA_DOCUMENT_SERIALIZE_H_
+#endif // XFA_FXFA_PARSER_CXFA_DATAEXPORTER_H_
diff --git a/xfa/fxfa/parser/cxfa_dataimporter.cpp b/xfa/fxfa/parser/cxfa_dataimporter.cpp
new file mode 100644
index 0000000000..87848ddebb
--- /dev/null
+++ b/xfa/fxfa/parser/cxfa_dataimporter.cpp
@@ -0,0 +1,62 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/fxfa/parser/cxfa_dataimporter.h"
+
+#include <memory>
+
+#include "core/fxcrt/include/fx_stream.h"
+#include "xfa/fde/xml/fde_xml_imp.h"
+#include "xfa/fxfa/include/fxfa.h"
+#include "xfa/fxfa/include/fxfa_basic.h"
+#include "xfa/fxfa/parser/cxfa_document.h"
+#include "xfa/fxfa/parser/cxfa_simple_parser.h"
+#include "xfa/fxfa/parser/xfa_object.h"
+
+CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument)
+ : m_pDocument(pDocument) {
+ ASSERT(m_pDocument);
+}
+
+FX_BOOL CXFA_DataImporter::ImportData(IFX_FileRead* pDataDocument) {
+ std::unique_ptr<CXFA_SimpleParser> pDataDocumentParser(
+ new CXFA_SimpleParser(m_pDocument, false));
+ if (pDataDocumentParser->StartParse(pDataDocument, XFA_XDPPACKET_Datasets) !=
+ XFA_PARSESTATUS_Ready) {
+ return FALSE;
+ }
+ if (pDataDocumentParser->DoParse(nullptr) < XFA_PARSESTATUS_Done)
+ return FALSE;
+
+ CXFA_Node* pImportDataRoot = pDataDocumentParser->GetRootNode();
+ if (!pImportDataRoot)
+ return FALSE;
+
+ CXFA_Node* pDataModel =
+ ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
+ if (!pDataModel)
+ return FALSE;
+
+ CXFA_Node* pDataNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Data));
+ if (pDataNode)
+ pDataModel->RemoveChild(pDataNode);
+
+ if (pImportDataRoot->GetElementType() == XFA_Element::DataModel) {
+ while (CXFA_Node* pChildNode =
+ pImportDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) {
+ pImportDataRoot->RemoveChild(pChildNode);
+ pDataModel->InsertChild(pChildNode);
+ }
+ } else {
+ CFDE_XMLNode* pXMLNode = pImportDataRoot->GetXMLMappingNode();
+ CFDE_XMLNode* pParentXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
+ if (pParentXMLNode)
+ pParentXMLNode->RemoveChildNode(pXMLNode);
+ pDataModel->InsertChild(pImportDataRoot);
+ }
+ m_pDocument->DoDataRemerge(FALSE);
+ return TRUE;
+}
diff --git a/xfa/fxfa/parser/cxfa_dataimporter.h b/xfa/fxfa/parser/cxfa_dataimporter.h
new file mode 100644
index 0000000000..b5648218e9
--- /dev/null
+++ b/xfa/fxfa/parser/cxfa_dataimporter.h
@@ -0,0 +1,25 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef XFA_FXFA_PARSER_CXFA_DATAIMPORTER_H_
+#define XFA_FXFA_PARSER_CXFA_DATAIMPORTER_H_
+
+#include "core/fxcrt/include/fx_system.h"
+
+class CXFA_Document;
+class IFX_FileRead;
+
+class CXFA_DataImporter {
+ public:
+ explicit CXFA_DataImporter(CXFA_Document* pDocument);
+
+ FX_BOOL ImportData(IFX_FileRead* pDataDocument);
+
+ protected:
+ CXFA_Document* const m_pDocument;
+};
+
+#endif // XFA_FXFA_PARSER_CXFA_DATAIMPORTER_H_