summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-05-25 15:47:43 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-25 15:47:44 -0700
commit65be4b1818ab99df2bf5b6265604fc25456db49d (patch)
treee191cc71c483d75d3226e6705ed79b3489fa31e9 /xfa/fxfa/parser
parent648575aaa8989be7071e7ec61293470a44cf2d94 (diff)
downloadpdfium-65be4b1818ab99df2bf5b6265604fc25456db49d.tar.xz
Complete or comment a couple Script_NodeClass functions
There are a few functions which are not completed in CXFA_Node class. Complete or comment two functions in this change list. The implementation follows Adobe's XFA 2.1 references here: http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=001363.html. Also, remove a data structure no longer needed -- the code which used it has been removed. BUG=pdfium:29 Review-Url: https://codereview.chromium.org/2011553004
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/xfa_object_imp.cpp95
1 files changed, 40 insertions, 55 deletions
diff --git a/xfa/fxfa/parser/xfa_object_imp.cpp b/xfa/fxfa/parser/xfa_object_imp.cpp
index 6a6303e64e..1d1a5a2290 100644
--- a/xfa/fxfa/parser/xfa_object_imp.cpp
+++ b/xfa/fxfa/parser/xfa_object_imp.cpp
@@ -902,6 +902,7 @@ void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
FXJSE_Value_Set(pArguments->GetReturnValue(),
m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
}
+
void CXFA_Node::Script_NodeClass_IsPropertySpecified(
CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
@@ -914,32 +915,35 @@ void CXFA_Node::Script_NodeClass_IsPropertySpecified(
FX_BOOL bParent = TRUE;
int32_t iIndex = 0;
if (iLength >= 1) {
- CFX_ByteString bsExpression = pArguments->GetUTF8String(0);
- wsExpression = CFX_WideString::FromUTF8(bsExpression.AsStringC());
+ wsExpression =
+ CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
}
- if (iLength >= 2) {
- bParent = pArguments->GetInt32(1) == 0 ? FALSE : TRUE;
- }
- if (iLength >= 3) {
+ if (iLength >= 2)
+ bParent = !!pArguments->GetInt32(1) ? TRUE : FALSE;
+ if (iLength >= 3)
iIndex = pArguments->GetInt32(2);
- }
FX_BOOL bHas = FALSE;
const XFA_ATTRIBUTEINFO* pAttributeInfo =
XFA_GetAttributeByName(wsExpression.AsStringC());
CFX_WideString wsValue;
- if (pAttributeInfo) {
+ if (pAttributeInfo)
bHas = HasAttribute(pAttributeInfo->eName);
- }
if (!bHas) {
const XFA_ELEMENTINFO* pElementInfo =
XFA_GetElementByName(wsExpression.AsStringC());
- bHas = (GetProperty(iIndex, pElementInfo->eName) != NULL);
+ bHas = !!GetProperty(iIndex, pElementInfo->eName);
+ if (!bHas && bParent && m_pParent) {
+ // Also check on the parent.
+ bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
+ if (!bHas)
+ bHas = !!m_pParent->GetProperty(iIndex, pElementInfo->eName);
+ }
}
FXJSE_HVALUE hValue = pArguments->GetReturnValue();
- if (hValue) {
+ if (hValue)
FXJSE_Value_SetBoolean(hValue, bHas);
- }
}
+
void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength < 1 || iLength > 3) {
@@ -1078,64 +1082,45 @@ void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
}
FX_BOOL bPrettyMode = FALSE;
if (iLength == 1) {
- CFX_ByteString bsPretty = pArguments->GetUTF8String(0);
- if (bsPretty != "pretty") {
+ if (pArguments->GetUTF8String(0) != "pretty") {
ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
return;
}
bPrettyMode = TRUE;
}
CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
- if (GetPacketID() == XFA_XDPPACKET_Form) {
- IFX_MemoryStream* pMemoryStream = FX_CreateMemoryStream(TRUE);
- IFX_Stream* pStream = IFX_Stream::CreateStream(
- (IFX_FileWrite*)pMemoryStream,
- FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
+ if (GetPacketID() == XFA_XDPPACKET_Form ||
+ GetPacketID() == XFA_XDPPACKET_Datasets) {
+ CFDE_XMLNode* pElement = nullptr;
+ if (GetPacketID() == XFA_XDPPACKET_Datasets) {
+ pElement = GetXMLMappingNode();
+ if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
+ FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader);
+ return;
+ }
+ XFA_DataExporter_DealWithDataGroupNode(this);
+ }
+ std::unique_ptr<IFX_MemoryStream> pMemoryStream(
+ FX_CreateMemoryStream(TRUE));
+ std::unique_ptr<IFX_Stream> pStream(IFX_Stream::CreateStream(
+ (IFX_FileWrite*)pMemoryStream.get(),
+ FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append));
if (!pStream) {
FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader);
- pMemoryStream->Release();
- pMemoryStream = NULL;
return;
}
pStream->SetCodePage(FX_CODEPAGE_UTF8);
pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
- XFA_DataExporter_RegenerateFormFile(this, pStream, NULL, TRUE);
+ if (GetPacketID() == XFA_XDPPACKET_Form)
+ XFA_DataExporter_RegenerateFormFile(this, pStream.get(), NULL, TRUE);
+ else
+ pElement->SaveXMLNode(pStream.get());
+ // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
+ // For now, just put it here to avoid unused variable warning.
+ (void)bPrettyMode;
FXJSE_Value_SetUTF8String(
pArguments->GetReturnValue(),
CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
- pStream->Release();
- pStream = NULL;
- if (pMemoryStream) {
- pMemoryStream->Release();
- pMemoryStream = NULL;
- }
- return;
- }
- if (GetPacketID() == XFA_XDPPACKET_Datasets) {
- CFDE_XMLNode* pElement = GetXMLMappingNode();
- if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
- FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader);
- return;
- }
- XFA_DataExporter_DealWithDataGroupNode(this);
- IFX_MemoryStream* pMemoryStream = FX_CreateMemoryStream(TRUE);
- IFX_Stream* pStream = IFX_Stream::CreateStream(
- (IFX_FileWrite*)pMemoryStream,
- FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
- if (pStream) {
- pStream->SetCodePage(FX_CODEPAGE_UTF8);
- pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
- pElement->SaveXMLNode(pStream);
- FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(),
- CFX_ByteStringC(pMemoryStream->GetBuffer(),
- pMemoryStream->GetSize()));
- pStream->Release();
- pStream = NULL;
- }
- if (pMemoryStream) {
- pMemoryStream->Release();
- pMemoryStream = NULL;
- }
return;
}
FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), "");