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_object.h" | 7 #include "xfa/fxfa/parser/xfa_object.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 } | 895 } |
896 if (iLength >= 2) { | 896 if (iLength >= 2) { |
897 iValue = pArguments->GetInt32(1); | 897 iValue = pArguments->GetInt32(1); |
898 } | 898 } |
899 const XFA_ELEMENTINFO* pElementInfo = | 899 const XFA_ELEMENTINFO* pElementInfo = |
900 XFA_GetElementByName(wsExpression.AsStringC()); | 900 XFA_GetElementByName(wsExpression.AsStringC()); |
901 CXFA_Node* pNode = GetProperty(iValue, pElementInfo->eName); | 901 CXFA_Node* pNode = GetProperty(iValue, pElementInfo->eName); |
902 FXJSE_Value_Set(pArguments->GetReturnValue(), | 902 FXJSE_Value_Set(pArguments->GetReturnValue(), |
903 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); | 903 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); |
904 } | 904 } |
| 905 |
905 void CXFA_Node::Script_NodeClass_IsPropertySpecified( | 906 void CXFA_Node::Script_NodeClass_IsPropertySpecified( |
906 CFXJSE_Arguments* pArguments) { | 907 CFXJSE_Arguments* pArguments) { |
907 int32_t iLength = pArguments->GetLength(); | 908 int32_t iLength = pArguments->GetLength(); |
908 if (iLength < 1 || iLength > 3) { | 909 if (iLength < 1 || iLength > 3) { |
909 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, | 910 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, |
910 L"isPropertySpecified"); | 911 L"isPropertySpecified"); |
911 return; | 912 return; |
912 } | 913 } |
913 CFX_WideString wsExpression; | 914 CFX_WideString wsExpression; |
914 FX_BOOL bParent = TRUE; | 915 FX_BOOL bParent = TRUE; |
915 int32_t iIndex = 0; | 916 int32_t iIndex = 0; |
916 if (iLength >= 1) { | 917 if (iLength >= 1) { |
917 CFX_ByteString bsExpression = pArguments->GetUTF8String(0); | 918 wsExpression = |
918 wsExpression = CFX_WideString::FromUTF8(bsExpression.AsStringC()); | 919 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
919 } | 920 } |
920 if (iLength >= 2) { | 921 if (iLength >= 2) |
921 bParent = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; | 922 bParent = !!pArguments->GetInt32(1) ? TRUE : FALSE; |
922 } | 923 if (iLength >= 3) |
923 if (iLength >= 3) { | |
924 iIndex = pArguments->GetInt32(2); | 924 iIndex = pArguments->GetInt32(2); |
925 } | |
926 FX_BOOL bHas = FALSE; | 925 FX_BOOL bHas = FALSE; |
927 const XFA_ATTRIBUTEINFO* pAttributeInfo = | 926 const XFA_ATTRIBUTEINFO* pAttributeInfo = |
928 XFA_GetAttributeByName(wsExpression.AsStringC()); | 927 XFA_GetAttributeByName(wsExpression.AsStringC()); |
929 CFX_WideString wsValue; | 928 CFX_WideString wsValue; |
930 if (pAttributeInfo) { | 929 if (pAttributeInfo) |
931 bHas = HasAttribute(pAttributeInfo->eName); | 930 bHas = HasAttribute(pAttributeInfo->eName); |
932 } | |
933 if (!bHas) { | 931 if (!bHas) { |
934 const XFA_ELEMENTINFO* pElementInfo = | 932 const XFA_ELEMENTINFO* pElementInfo = |
935 XFA_GetElementByName(wsExpression.AsStringC()); | 933 XFA_GetElementByName(wsExpression.AsStringC()); |
936 bHas = (GetProperty(iIndex, pElementInfo->eName) != NULL); | 934 bHas = !!GetProperty(iIndex, pElementInfo->eName); |
| 935 if (!bHas && bParent && m_pParent) { |
| 936 // Also check on the parent. |
| 937 bHas = m_pParent->HasAttribute(pAttributeInfo->eName); |
| 938 if (!bHas) |
| 939 bHas = !!m_pParent->GetProperty(iIndex, pElementInfo->eName); |
| 940 } |
937 } | 941 } |
938 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); | 942 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); |
939 if (hValue) { | 943 if (hValue) |
940 FXJSE_Value_SetBoolean(hValue, bHas); | 944 FXJSE_Value_SetBoolean(hValue, bHas); |
941 } | |
942 } | 945 } |
| 946 |
943 void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { | 947 void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { |
944 int32_t iLength = pArguments->GetLength(); | 948 int32_t iLength = pArguments->GetLength(); |
945 if (iLength < 1 || iLength > 3) { | 949 if (iLength < 1 || iLength > 3) { |
946 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML"); | 950 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML"); |
947 return; | 951 return; |
948 } | 952 } |
949 CFX_WideString wsExpression; | 953 CFX_WideString wsExpression; |
950 FX_BOOL bIgnoreRoot = TRUE; | 954 FX_BOOL bIgnoreRoot = TRUE; |
951 FX_BOOL bOverwrite = 0; | 955 FX_BOOL bOverwrite = 0; |
952 if (iLength >= 1) { | 956 if (iLength >= 1) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 } | 1075 } |
1072 | 1076 |
1073 void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { | 1077 void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { |
1074 int32_t iLength = pArguments->GetLength(); | 1078 int32_t iLength = pArguments->GetLength(); |
1075 if (iLength < 0 || iLength > 1) { | 1079 if (iLength < 0 || iLength > 1) { |
1076 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML"); | 1080 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML"); |
1077 return; | 1081 return; |
1078 } | 1082 } |
1079 FX_BOOL bPrettyMode = FALSE; | 1083 FX_BOOL bPrettyMode = FALSE; |
1080 if (iLength == 1) { | 1084 if (iLength == 1) { |
1081 CFX_ByteString bsPretty = pArguments->GetUTF8String(0); | 1085 if (pArguments->GetUTF8String(0) != "pretty") { |
1082 if (bsPretty != "pretty") { | |
1083 ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH); | 1086 ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH); |
1084 return; | 1087 return; |
1085 } | 1088 } |
1086 bPrettyMode = TRUE; | 1089 bPrettyMode = TRUE; |
1087 } | 1090 } |
1088 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; | 1091 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
1089 if (GetPacketID() == XFA_XDPPACKET_Form) { | 1092 if (GetPacketID() == XFA_XDPPACKET_Form || |
1090 IFX_MemoryStream* pMemoryStream = FX_CreateMemoryStream(TRUE); | 1093 GetPacketID() == XFA_XDPPACKET_Datasets) { |
1091 IFX_Stream* pStream = IFX_Stream::CreateStream( | 1094 CFDE_XMLNode* pElement = nullptr; |
1092 (IFX_FileWrite*)pMemoryStream, | 1095 if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
1093 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); | 1096 pElement = GetXMLMappingNode(); |
| 1097 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) { |
| 1098 FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader); |
| 1099 return; |
| 1100 } |
| 1101 XFA_DataExporter_DealWithDataGroupNode(this); |
| 1102 } |
| 1103 std::unique_ptr<IFX_MemoryStream> pMemoryStream( |
| 1104 FX_CreateMemoryStream(TRUE)); |
| 1105 std::unique_ptr<IFX_Stream> pStream(IFX_Stream::CreateStream( |
| 1106 (IFX_FileWrite*)pMemoryStream.get(), |
| 1107 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append)); |
1094 if (!pStream) { | 1108 if (!pStream) { |
1095 FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader); | 1109 FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader); |
1096 pMemoryStream->Release(); | |
1097 pMemoryStream = NULL; | |
1098 return; | 1110 return; |
1099 } | 1111 } |
1100 pStream->SetCodePage(FX_CODEPAGE_UTF8); | 1112 pStream->SetCodePage(FX_CODEPAGE_UTF8); |
1101 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength()); | 1113 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength()); |
1102 XFA_DataExporter_RegenerateFormFile(this, pStream, NULL, TRUE); | 1114 if (GetPacketID() == XFA_XDPPACKET_Form) |
| 1115 XFA_DataExporter_RegenerateFormFile(this, pStream.get(), NULL, TRUE); |
| 1116 else |
| 1117 pElement->SaveXMLNode(pStream.get()); |
| 1118 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501. |
| 1119 // For now, just put it here to avoid unused variable warning. |
| 1120 (void)bPrettyMode; |
1103 FXJSE_Value_SetUTF8String( | 1121 FXJSE_Value_SetUTF8String( |
1104 pArguments->GetReturnValue(), | 1122 pArguments->GetReturnValue(), |
1105 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize())); | 1123 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize())); |
1106 pStream->Release(); | |
1107 pStream = NULL; | |
1108 if (pMemoryStream) { | |
1109 pMemoryStream->Release(); | |
1110 pMemoryStream = NULL; | |
1111 } | |
1112 return; | |
1113 } | |
1114 if (GetPacketID() == XFA_XDPPACKET_Datasets) { | |
1115 CFDE_XMLNode* pElement = GetXMLMappingNode(); | |
1116 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) { | |
1117 FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader); | |
1118 return; | |
1119 } | |
1120 XFA_DataExporter_DealWithDataGroupNode(this); | |
1121 IFX_MemoryStream* pMemoryStream = FX_CreateMemoryStream(TRUE); | |
1122 IFX_Stream* pStream = IFX_Stream::CreateStream( | |
1123 (IFX_FileWrite*)pMemoryStream, | |
1124 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); | |
1125 if (pStream) { | |
1126 pStream->SetCodePage(FX_CODEPAGE_UTF8); | |
1127 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength()); | |
1128 pElement->SaveXMLNode(pStream); | |
1129 FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), | |
1130 CFX_ByteStringC(pMemoryStream->GetBuffer(), | |
1131 pMemoryStream->GetSize())); | |
1132 pStream->Release(); | |
1133 pStream = NULL; | |
1134 } | |
1135 if (pMemoryStream) { | |
1136 pMemoryStream->Release(); | |
1137 pMemoryStream = NULL; | |
1138 } | |
1139 return; | 1124 return; |
1140 } | 1125 } |
1141 FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), ""); | 1126 FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), ""); |
1142 } | 1127 } |
1143 | 1128 |
1144 void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) { | 1129 void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) { |
1145 int32_t iLength = pArguments->GetLength(); | 1130 int32_t iLength = pArguments->GetLength(); |
1146 if (iLength != 2) { | 1131 if (iLength != 2) { |
1147 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, | 1132 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, |
1148 L"setAttribute"); | 1133 L"setAttribute"); |
(...skipping 4216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5365 return m_pAttachNode->InsertChild(pNewNode, pBeforeNode); | 5350 return m_pAttachNode->InsertChild(pNewNode, pBeforeNode); |
5366 } | 5351 } |
5367 FX_BOOL CXFA_AttachNodeList::Remove(CXFA_Node* pNode) { | 5352 FX_BOOL CXFA_AttachNodeList::Remove(CXFA_Node* pNode) { |
5368 return m_pAttachNode->RemoveChild(pNode); | 5353 return m_pAttachNode->RemoveChild(pNode); |
5369 } | 5354 } |
5370 CXFA_Node* CXFA_AttachNodeList::Item(int32_t iIndex) { | 5355 CXFA_Node* CXFA_AttachNodeList::Item(int32_t iIndex) { |
5371 return m_pAttachNode->GetChild( | 5356 return m_pAttachNode->GetChild( |
5372 iIndex, XFA_ELEMENT_UNKNOWN, | 5357 iIndex, XFA_ELEMENT_UNKNOWN, |
5373 m_pAttachNode->GetClassID() == XFA_ELEMENT_Subform); | 5358 m_pAttachNode->GetClassID() == XFA_ELEMENT_Subform); |
5374 } | 5359 } |
OLD | NEW |