OLD | NEW |
(Empty) | |
| 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 |
| 11 CXFA_Validate::CXFA_Validate(CXFA_Node* pNode) : CXFA_Data(pNode) {} |
| 12 |
| 13 int32_t CXFA_Validate::GetFormatTest() { |
| 14 return m_pNode->GetEnum(XFA_ATTRIBUTE_FormatTest); |
| 15 } |
| 16 |
| 17 FX_BOOL CXFA_Validate::SetTestValue(int32_t iType, |
| 18 CFX_WideString& wsValue, |
| 19 XFA_ATTRIBUTEENUM eName) { |
| 20 const XFA_ATTRIBUTEENUMINFO* pInfo = |
| 21 XFA_GetAttributeEnumByName(wsValue.AsWideStringC()); |
| 22 if (pInfo) |
| 23 eName = pInfo->eName; |
| 24 |
| 25 m_pNode->SetEnum((XFA_ATTRIBUTE)iType, eName, FALSE); |
| 26 return TRUE; |
| 27 } |
| 28 |
| 29 FX_BOOL CXFA_Validate::SetNullTest(CFX_WideString wsValue) { |
| 30 return SetTestValue(XFA_ATTRIBUTE_NullTest, wsValue, |
| 31 XFA_ATTRIBUTEENUM_Disabled); |
| 32 } |
| 33 |
| 34 int32_t CXFA_Validate::GetNullTest() { |
| 35 return m_pNode->GetEnum(XFA_ATTRIBUTE_NullTest); |
| 36 } |
| 37 |
| 38 int32_t CXFA_Validate::GetScriptTest() { |
| 39 return m_pNode->GetEnum(XFA_ATTRIBUTE_ScriptTest); |
| 40 } |
| 41 |
| 42 void CXFA_Validate::GetMessageText(CFX_WideString& wsMessage, |
| 43 const CFX_WideStringC& 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->GetClassID() != 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 |
| 63 void CXFA_Validate::SetFormatMessageText(CFX_WideString wsMessage) { |
| 64 SetMessageText(wsMessage, FX_WSTRC(L"formatTest")); |
| 65 } |
| 66 |
| 67 void CXFA_Validate::GetFormatMessageText(CFX_WideString& wsMessage) { |
| 68 GetMessageText(wsMessage, FX_WSTRC(L"formatTest")); |
| 69 } |
| 70 |
| 71 void CXFA_Validate::SetNullMessageText(CFX_WideString wsMessage) { |
| 72 SetMessageText(wsMessage, FX_WSTRC(L"nullTest")); |
| 73 } |
| 74 |
| 75 void CXFA_Validate::GetNullMessageText(CFX_WideString& wsMessage) { |
| 76 GetMessageText(wsMessage, FX_WSTRC(L"nullTest")); |
| 77 } |
| 78 |
| 79 void CXFA_Validate::SetMessageText(CFX_WideString& wsMessage, |
| 80 const CFX_WideStringC& 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->GetClassID() != 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 |
| 104 void CXFA_Validate::GetScriptMessageText(CFX_WideString& wsMessage) { |
| 105 GetMessageText(wsMessage, FX_WSTRC(L"scriptTest")); |
| 106 } |
| 107 |
| 108 void CXFA_Validate::SetScriptMessageText(CFX_WideString wsMessage) { |
| 109 SetMessageText(wsMessage, FX_WSTRC(L"scriptTest")); |
| 110 } |
| 111 |
| 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 |
| 117 CXFA_Script CXFA_Validate::GetScript() { |
| 118 return CXFA_Script(m_pNode->GetChild(0, XFA_ELEMENT_Script)); |
| 119 } |
OLD | NEW |