Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cxfa_validate.cpp
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
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 "fxjs/xfa/cjx_node.h"
10#include "fxjs/xfa/cjx_object.h"
11#include "xfa/fxfa/parser/cxfa_document.h"
12#include "xfa/fxfa/parser/cxfa_message.h"
13#include "xfa/fxfa/parser/cxfa_picture.h"
14#include "xfa/fxfa/parser/cxfa_script.h"
15#include "xfa/fxfa/parser/xfa_basic_data.h"
16
17namespace {
18
19const CXFA_Node::PropertyData kValidatePropertyData[] = {
20 {XFA_Element::Message, 1, {}},
21 {XFA_Element::Picture, 1, {}},
22 {XFA_Element::Script, 1, {}},
23 {XFA_Element::Extras, 1, {}},
24};
25const CXFA_Node::AttributeData kValidateAttributeData[] = {
29 (void*)XFA_AttributeValue::Error},
31 (void*)XFA_AttributeValue::Disabled},
32 {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
35 (void*)XFA_AttributeValue::Warning},
37};
38
39constexpr wchar_t kFormatTest[] = L"formatTest";
40constexpr wchar_t kNullTest[] = L"nullTest";
41constexpr wchar_t kScriptTest[] = L"scriptTest";
42
43} // namespace
44
45CXFA_Validate::CXFA_Validate(CXFA_Document* doc, XFA_PacketType packet)
46 : CXFA_Node(doc,
47 packet,
48 {XFA_XDPPACKET::kConfig, XFA_XDPPACKET::kTemplate,
49 XFA_XDPPACKET::kForm},
50 XFA_ObjectType::ContentNode,
51 XFA_Element::Validate,
52 kValidatePropertyData,
53 kValidateAttributeData,
54 cppgc::MakeGarbageCollected<CJX_Node>(
55 doc->GetHeap()->GetAllocationHandle(),
56 this)) {}
57
58CXFA_Validate::~CXFA_Validate() = default;
59
61 return JSObject()->GetEnum(XFA_Attribute::FormatTest);
62}
63
64void CXFA_Validate::SetNullTest(const WideString& wsValue) {
65 absl::optional<XFA_AttributeValue> item =
66 XFA_GetAttributeValueByName(wsValue.AsStringView());
67 JSObject()->SetEnum(
68 XFA_Attribute::NullTest,
69 item.has_value() ? item.value() : XFA_AttributeValue::Disabled, false);
70}
71
73 return JSObject()->GetEnum(XFA_Attribute::NullTest);
74}
75
77 return JSObject()->GetEnum(XFA_Attribute::ScriptTest);
78}
79
80WideString CXFA_Validate::GetMessageText(const WideString& wsMessageType) {
81 CXFA_Message* pNode =
82 JSObject()->GetProperty<CXFA_Message>(0, XFA_Element::Message);
83 if (!pNode)
84 return WideString();
85
86 for (CXFA_Node* pItemNode = pNode->GetFirstChild(); pItemNode;
87 pItemNode = pItemNode->GetNextSibling()) {
88 if (pItemNode->GetElementType() != XFA_Element::Text)
89 continue;
90
91 WideString wsName = pItemNode->JSObject()->GetCData(XFA_Attribute::Name);
92 if (wsName.IsEmpty() || wsName == wsMessageType)
93 return pItemNode->JSObject()->GetContent(false);
94 }
95 return WideString();
96}
97
98void CXFA_Validate::SetFormatMessageText(const WideString& wsMessage) {
99 SetMessageText(kFormatTest, wsMessage);
100}
101
102WideString CXFA_Validate::GetFormatMessageText() {
103 return GetMessageText(kFormatTest);
104}
105
106void CXFA_Validate::SetNullMessageText(const WideString& wsMessage) {
107 SetMessageText(kNullTest, wsMessage);
108}
109
110WideString CXFA_Validate::GetNullMessageText() {
111 return GetMessageText(kNullTest);
112}
113
114WideString CXFA_Validate::GetScriptMessageText() {
115 return GetMessageText(kScriptTest);
116}
117
118void CXFA_Validate::SetScriptMessageText(const WideString& wsMessage) {
119 SetMessageText(kScriptTest, wsMessage);
120}
121
122void CXFA_Validate::SetMessageText(const WideString& wsMessageType,
123 const WideString& wsMessage) {
124 CXFA_Message* pNode =
125 JSObject()->GetOrCreateProperty<CXFA_Message>(0, XFA_Element::Message);
126 if (!pNode)
127 return;
128
129 for (CXFA_Node* pItemNode = pNode->GetFirstChild(); pItemNode;
130 pItemNode = pItemNode->GetNextSibling()) {
131 if (pItemNode->GetElementType() != XFA_Element::Text)
132 continue;
133
134 WideString wsName = pItemNode->JSObject()->GetCData(XFA_Attribute::Name);
135 if (wsName.IsEmpty() || wsName == wsMessageType) {
136 pItemNode->JSObject()->SetContent(wsMessage, wsMessage, false, false,
137 true);
138 return;
139 }
140 }
141
142 CXFA_Node* pTextNode = pNode->CreateSamePacketNode(XFA_Element::Text);
143 pNode->InsertChildAndNotify(pTextNode, nullptr);
144 pTextNode->JSObject()->SetCData(XFA_Attribute::Name, wsMessageType);
145 pTextNode->JSObject()->SetContent(wsMessage, wsMessage, false, false, true);
146}
147
148WideString CXFA_Validate::GetPicture() const {
149 const auto* pNode = GetChild<CXFA_Picture>(0, XFA_Element::Picture, false);
150 return pNode ? pNode->JSObject()->GetContent(false) : WideString();
151}
152
153CXFA_Script* CXFA_Validate::GetScriptIfExists() {
154 return GetChild<CXFA_Script>(0, XFA_Element::Script, false);
155}
CXFA_Node * CreateSamePacketNode(XFA_Element eType)
XFA_Element GetElementType() const
Definition cxfa_object.h:91
XFA_AttributeValue GetNullTest()
~CXFA_Validate() override
XFA_AttributeValue GetFormatTest()
void SetScriptMessageText(const WideString &wsMessage)
WideString GetNullMessageText()
WideString GetScriptMessageText()
CXFA_Script * GetScriptIfExists()
void SetNullTest(const WideString &wsValue)
XFA_AttributeValue GetScriptTest()
WideString GetPicture() const
void SetNullMessageText(const WideString &wsMessage)
WideString GetFormatMessageText()
void SetFormatMessageText(const WideString &wsMessage)
bool operator==(const WideString &other) const
bool IsEmpty() const
Definition widestring.h:118
XFA_AttributeType
Definition fxfa_basic.h:83
XFA_Attribute
Definition fxfa_basic.h:67
XFA_Element
Definition fxfa_basic.h:75
XFA_AttributeValue
Definition fxfa_basic.h:60
XFA_PacketType
Definition fxfa_basic.h:44