1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/fxfa/parser/cxfa_validate.h"
8
9 #include "xfa/fxfa/parser/xfa_object.h"
10
CXFA_Validate(CXFA_Node * pNode)11 CXFA_Validate::CXFA_Validate(CXFA_Node* pNode) : CXFA_Data(pNode) {}
12
GetFormatTest()13 int32_t CXFA_Validate::GetFormatTest() {
14 return m_pNode->GetEnum(XFA_ATTRIBUTE_FormatTest);
15 }
16
SetTestValue(int32_t iType,CFX_WideString & wsValue,XFA_ATTRIBUTEENUM eName)17 bool CXFA_Validate::SetTestValue(int32_t iType,
18 CFX_WideString& wsValue,
19 XFA_ATTRIBUTEENUM eName) {
20 const XFA_ATTRIBUTEENUMINFO* pInfo =
21 XFA_GetAttributeEnumByName(wsValue.AsStringC());
22 if (pInfo)
23 eName = pInfo->eName;
24
25 m_pNode->SetEnum((XFA_ATTRIBUTE)iType, eName, false);
26 return true;
27 }
28
SetNullTest(CFX_WideString wsValue)29 bool CXFA_Validate::SetNullTest(CFX_WideString wsValue) {
30 return SetTestValue(XFA_ATTRIBUTE_NullTest, wsValue,
31 XFA_ATTRIBUTEENUM_Disabled);
32 }
33
GetNullTest()34 int32_t CXFA_Validate::GetNullTest() {
35 return m_pNode->GetEnum(XFA_ATTRIBUTE_NullTest);
36 }
37
GetScriptTest()38 int32_t CXFA_Validate::GetScriptTest() {
39 return m_pNode->GetEnum(XFA_ATTRIBUTE_ScriptTest);
40 }
41
GetMessageText(CFX_WideString & wsMessage,const CFX_WideString & wsMessageType)42 void CXFA_Validate::GetMessageText(CFX_WideString& wsMessage,
43 const CFX_WideString& wsMessageType) {
44 CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_Element::Message, false);
45 if (!pNode)
46 return;
47
48 CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
49 for (; pItemNode;
50 pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
51 if (pItemNode->GetElementType() != XFA_Element::Text)
52 continue;
53
54 CFX_WideStringC wsName;
55 pItemNode->TryCData(XFA_ATTRIBUTE_Name, wsName);
56 if (wsName.IsEmpty() || wsName == wsMessageType) {
57 pItemNode->TryContent(wsMessage);
58 return;
59 }
60 }
61 }
62
SetFormatMessageText(CFX_WideString wsMessage)63 void CXFA_Validate::SetFormatMessageText(CFX_WideString wsMessage) {
64 SetMessageText(wsMessage, L"formatTest");
65 }
66
GetFormatMessageText(CFX_WideString & wsMessage)67 void CXFA_Validate::GetFormatMessageText(CFX_WideString& wsMessage) {
68 GetMessageText(wsMessage, L"formatTest");
69 }
70
SetNullMessageText(CFX_WideString wsMessage)71 void CXFA_Validate::SetNullMessageText(CFX_WideString wsMessage) {
72 SetMessageText(wsMessage, L"nullTest");
73 }
74
GetNullMessageText(CFX_WideString & wsMessage)75 void CXFA_Validate::GetNullMessageText(CFX_WideString& wsMessage) {
76 GetMessageText(wsMessage, L"nullTest");
77 }
78
SetMessageText(CFX_WideString & wsMessage,const CFX_WideString & wsMessageType)79 void CXFA_Validate::SetMessageText(CFX_WideString& wsMessage,
80 const CFX_WideString& wsMessageType) {
81 CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_Element::Message, true);
82 if (!pNode)
83 return;
84
85 CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
86 for (; pItemNode;
87 pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
88 if (pItemNode->GetElementType() != XFA_Element::Text)
89 continue;
90
91 CFX_WideStringC wsName;
92 pItemNode->TryCData(XFA_ATTRIBUTE_Name, wsName);
93 if (wsName.IsEmpty() || wsName == wsMessageType) {
94 pItemNode->SetContent(wsMessage, wsMessage, false);
95 return;
96 }
97 }
98 CXFA_Node* pTextNode = pNode->CreateSamePacketNode(XFA_Element::Text);
99 pNode->InsertChild(pTextNode);
100 pTextNode->SetCData(XFA_ATTRIBUTE_Name, wsMessageType, false);
101 pTextNode->SetContent(wsMessage, wsMessage, false);
102 }
103
GetScriptMessageText(CFX_WideString & wsMessage)104 void CXFA_Validate::GetScriptMessageText(CFX_WideString& wsMessage) {
105 GetMessageText(wsMessage, L"scriptTest");
106 }
107
SetScriptMessageText(CFX_WideString wsMessage)108 void CXFA_Validate::SetScriptMessageText(CFX_WideString wsMessage) {
109 SetMessageText(wsMessage, L"scriptTest");
110 }
111
GetPicture(CFX_WideString & wsPicture)112 void CXFA_Validate::GetPicture(CFX_WideString& wsPicture) {
113 if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Picture))
114 pNode->TryContent(wsPicture);
115 }
116
GetScript()117 CXFA_Script CXFA_Validate::GetScript() {
118 return CXFA_Script(m_pNode->GetChild(0, XFA_Element::Script));
119 }
120