diff options
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r-- | xfa/fxfa/parser/cxfa_validatedata.cpp | 81 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_validatedata.h | 34 |
2 files changed, 65 insertions, 50 deletions
diff --git a/xfa/fxfa/parser/cxfa_validatedata.cpp b/xfa/fxfa/parser/cxfa_validatedata.cpp index 94c5829288..8b3f539d48 100644 --- a/xfa/fxfa/parser/cxfa_validatedata.cpp +++ b/xfa/fxfa/parser/cxfa_validatedata.cpp @@ -9,35 +9,42 @@ #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/xfa_utils.h" +namespace { + +constexpr wchar_t kFormatTest[] = L"formatTest"; +constexpr wchar_t kNullTest[] = L"nullTest"; +constexpr wchar_t kScriptTest[] = L"scriptTest"; + +} // namespace + CXFA_ValidateData::CXFA_ValidateData(CXFA_Node* pNode) : CXFA_DataData(pNode) {} -int32_t CXFA_ValidateData::GetFormatTest() { +XFA_ATTRIBUTEENUM CXFA_ValidateData::GetFormatTest() const { return m_pNode->JSNode()->GetEnum(XFA_Attribute::FormatTest); } -bool CXFA_ValidateData::SetNullTest(WideString wsValue) { +void CXFA_ValidateData::SetNullTest(const WideString& wsValue) { const XFA_ATTRIBUTEENUMINFO* pInfo = XFA_GetAttributeEnumByName(wsValue.AsStringView()); m_pNode->JSNode()->SetEnum(XFA_Attribute::NullTest, pInfo ? pInfo->eName : XFA_ATTRIBUTEENUM_Disabled, false); - return true; } -int32_t CXFA_ValidateData::GetNullTest() { +XFA_ATTRIBUTEENUM CXFA_ValidateData::GetNullTest() const { return m_pNode->JSNode()->GetEnum(XFA_Attribute::NullTest); } -int32_t CXFA_ValidateData::GetScriptTest() { +XFA_ATTRIBUTEENUM CXFA_ValidateData::GetScriptTest() const { return m_pNode->JSNode()->GetEnum(XFA_Attribute::ScriptTest); } -void CXFA_ValidateData::GetMessageText(WideString& wsMessage, - const WideString& wsMessageType) { +WideString CXFA_ValidateData::GetMessageText( + const WideString& wsMessageType) const { CXFA_Node* pNode = m_pNode->JSNode()->GetProperty(0, XFA_Element::Message, false); if (!pNode) - return; + return L""; for (CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pItemNode; @@ -46,38 +53,45 @@ void CXFA_ValidateData::GetMessageText(WideString& wsMessage, continue; WideString wsName = pItemNode->JSNode()->GetCData(XFA_Attribute::Name); - if (wsName.IsEmpty() || wsName == wsMessageType) { - wsMessage = pItemNode->JSNode()->GetContent(false); - return; - } + if (wsName.IsEmpty() || wsName == wsMessageType) + return pItemNode->JSNode()->GetContent(false); } + return L""; +} + +void CXFA_ValidateData::SetFormatMessageText(const WideString& wsMessage) { + SetMessageText(kFormatTest, wsMessage); } -void CXFA_ValidateData::SetFormatMessageText(WideString wsMessage) { - SetMessageText(wsMessage, L"formatTest"); +WideString CXFA_ValidateData::GetFormatMessageText() const { + return GetMessageText(kFormatTest); } -void CXFA_ValidateData::GetFormatMessageText(WideString& wsMessage) { - GetMessageText(wsMessage, L"formatTest"); +void CXFA_ValidateData::SetNullMessageText(const WideString& wsMessage) { + SetMessageText(kNullTest, wsMessage); } -void CXFA_ValidateData::SetNullMessageText(WideString wsMessage) { - SetMessageText(wsMessage, L"nullTest"); +WideString CXFA_ValidateData::GetNullMessageText() const { + return GetMessageText(kNullTest); } -void CXFA_ValidateData::GetNullMessageText(WideString& wsMessage) { - GetMessageText(wsMessage, L"nullTest"); +WideString CXFA_ValidateData::GetScriptMessageText() const { + return GetMessageText(kScriptTest); } -void CXFA_ValidateData::SetMessageText(WideString& wsMessage, - const WideString& wsMessageType) { +void CXFA_ValidateData::SetScriptMessageText(const WideString& wsMessage) { + SetMessageText(kScriptTest, wsMessage); +} + +void CXFA_ValidateData::SetMessageText(const WideString& wsMessageType, + const WideString& wsMessage) { CXFA_Node* pNode = m_pNode->JSNode()->GetProperty(0, XFA_Element::Message, true); if (!pNode) return; - CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pItemNode; + for (CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); + pItemNode; pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { if (pItemNode->GetElementType() != XFA_Element::Text) continue; @@ -88,6 +102,7 @@ void CXFA_ValidateData::SetMessageText(WideString& wsMessage, return; } } + CXFA_Node* pTextNode = pNode->CreateSamePacketNode(XFA_Element::Text); pNode->InsertChild(pTextNode, nullptr); pTextNode->JSNode()->SetCData(XFA_Attribute::Name, wsMessageType, false, @@ -95,19 +110,13 @@ void CXFA_ValidateData::SetMessageText(WideString& wsMessage, pTextNode->JSNode()->SetContent(wsMessage, wsMessage, false, false, true); } -void CXFA_ValidateData::GetScriptMessageText(WideString& wsMessage) { - GetMessageText(wsMessage, L"scriptTest"); -} - -void CXFA_ValidateData::SetScriptMessageText(WideString wsMessage) { - SetMessageText(wsMessage, L"scriptTest"); -} - -void CXFA_ValidateData::GetPicture(WideString& wsPicture) { - if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Picture, false)) - wsPicture = pNode->JSNode()->GetContent(false); +WideString CXFA_ValidateData::GetPicture() const { + CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Picture, false); + if (pNode) + return pNode->JSNode()->GetContent(false); + return L""; } -CXFA_ScriptData CXFA_ValidateData::GetScriptData() { +CXFA_ScriptData CXFA_ValidateData::GetScriptData() const { return CXFA_ScriptData(m_pNode->GetChild(0, XFA_Element::Script, false)); } diff --git a/xfa/fxfa/parser/cxfa_validatedata.h b/xfa/fxfa/parser/cxfa_validatedata.h index a431cbdf20..e18fcadeaf 100644 --- a/xfa/fxfa/parser/cxfa_validatedata.h +++ b/xfa/fxfa/parser/cxfa_validatedata.h @@ -18,22 +18,28 @@ class CXFA_ValidateData : public CXFA_DataData { public: explicit CXFA_ValidateData(CXFA_Node* pNode); - int32_t GetFormatTest(); - int32_t GetNullTest(); - bool SetNullTest(WideString wsValue); - int32_t GetScriptTest(); - void GetFormatMessageText(WideString& wsMessage); - void SetFormatMessageText(WideString wsMessage); - void GetNullMessageText(WideString& wsMessage); - void SetNullMessageText(WideString wsMessage); - void GetScriptMessageText(WideString& wsMessage); - void SetScriptMessageText(WideString wsMessage); - void GetPicture(WideString& wsPicture); - CXFA_ScriptData GetScriptData(); + XFA_ATTRIBUTEENUM GetFormatTest() const; + WideString GetFormatMessageText() const; + void SetFormatMessageText(const WideString& wsMessage); + + XFA_ATTRIBUTEENUM GetNullTest() const; + void SetNullTest(const WideString& wsValue); + + WideString GetNullMessageText() const; + void SetNullMessageText(const WideString& wsMessage); + + XFA_ATTRIBUTEENUM GetScriptTest() const; + WideString GetScriptMessageText() const; + void SetScriptMessageText(const WideString& wsMessage); + + WideString GetPicture() const; + + CXFA_ScriptData GetScriptData() const; private: - void GetMessageText(WideString& wsMessage, const WideString& wsMessageType); - void SetMessageText(WideString& wsMessage, const WideString& wsMessageType); + WideString GetMessageText(const WideString& wsMessageType) const; + void SetMessageText(const WideString& wsMessageType, + const WideString& wsMessage); }; #endif // XFA_FXFA_PARSER_CXFA_VALIDATEDATA_H_ |