blob: 0aa9064288a2dac08cbda524f62656b40a61d6c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#ifndef XFA_FXFA_PARSER_XFA_UTILS_H_
#define XFA_FXFA_PARSER_XFA_UTILS_H_
#include "xfa/fde/xml/fde_xml.h"
#include "xfa/fgas/crt/fgas_stream.h"
#include "xfa/fgas/crt/fgas_utils.h"
#include "xfa/fxfa/include/fxfa_basic.h"
class CFDE_XMLElement;
class CFDE_XMLNode;
class CXFA_LocaleValue;
class CXFA_Node;
class CXFA_WidgetData;
FX_BOOL XFA_FDEExtension_ResolveNamespaceQualifier(
CFDE_XMLElement* pNode,
const CFX_WideStringC& wsQualifier,
CFX_WideString& wsNamespaceURI);
template <class NodeType, class TraverseStrategy>
class CXFA_NodeIteratorTemplate {
public:
CXFA_NodeIteratorTemplate(NodeType* pRootNode = nullptr)
: m_pRoot(pRootNode) {
if (pRootNode) {
m_NodeStack.Push(pRootNode);
}
}
FX_BOOL Init(NodeType* pRootNode) {
if (!pRootNode) {
return FALSE;
}
m_pRoot = pRootNode;
m_NodeStack.RemoveAll();
m_NodeStack.Push(pRootNode);
return TRUE;
}
void Clear() { m_NodeStack.RemoveAll(); }
void Reset() {
Clear();
if (m_pRoot) {
m_NodeStack.Push(m_pRoot);
}
}
FX_BOOL SetCurrent(NodeType* pCurNode) {
m_NodeStack.RemoveAll();
if (pCurNode) {
CFX_StackTemplate<NodeType*> revStack;
NodeType* pNode;
for (pNode = pCurNode; pNode && pNode != m_pRoot;
pNode = TraverseStrategy::GetParent(pNode)) {
revStack.Push(pNode);
}
if (!pNode) {
return FALSE;
}
revStack.Push(m_pRoot);
while (revStack.GetSize()) {
m_NodeStack.Push(*revStack.GetTopElement());
revStack.Pop();
}
}
return TRUE;
}
NodeType* GetCurrent() const {
return m_NodeStack.GetSize() ? *m_NodeStack.GetTopElement() : nullptr;
}
NodeType* GetRoot() const { return m_pRoot; }
NodeType* MoveToPrev() {
int32_t nStackLength = m_NodeStack.GetSize();
if (nStackLength == 1) {
return nullptr;
} else if (nStackLength > 1) {
NodeType* pCurItem = *m_NodeStack.GetTopElement();
m_NodeStack.Pop();
NodeType* pParentItem = *m_NodeStack.GetTopElement();
NodeType* pParentFirstChildItem =
TraverseStrategy::GetFirstChild(pParentItem);
if (pCurItem == pParentFirstChildItem) {
return pParentItem;
}
NodeType *pPrevItem = pParentFirstChildItem, *pPrevItemNext = nullptr;
for (; pPrevItem; pPrevItem = pPrevItemNext) {
pPrevItemNext = TraverseStrategy::GetNextSibling(pPrevItem);
if (!pPrevItemNext || pPrevItemNext == pCurItem) {
break;
}
}
m_NodeStack.Push(pPrevItem);
} else {
m_NodeStack.RemoveAll();
if (m_pRoot) {
m_NodeStack.Push(m_pRoot);
}
}
if (m_NodeStack.GetSize() > 0) {
NodeType* pChildItem = *m_NodeStack.GetTopElement();
while ((pChildItem = TraverseStrategy::GetFirstChild(pChildItem)) !=
nullptr) {
while (NodeType* pNextItem =
TraverseStrategy::GetNextSibling(pChildItem)) {
pChildItem = pNextItem;
}
m_NodeStack.Push(pChildItem);
}
return *m_NodeStack.GetTopElement();
}
return nullptr;
}
NodeType* MoveToNext() {
NodeType** ppNode = nullptr;
NodeType* pCurrent = GetCurrent();
while (m_NodeStack.GetSize() > 0) {
while ((ppNode = m_NodeStack.GetTopElement()) != nullptr) {
if (pCurrent != *ppNode) {
return *ppNode;
}
NodeType* pChild = TraverseStrategy::GetFirstChild(*ppNode);
if (!pChild) {
break;
}
m_NodeStack.Push(pChild);
}
while ((ppNode = m_NodeStack.GetTopElement()) != nullptr) {
NodeType* pNext = TraverseStrategy::GetNextSibling(*ppNode);
m_NodeStack.Pop();
if (m_NodeStack.GetSize() == 0) {
break;
}
if (pNext) {
m_NodeStack.Push(pNext);
break;
}
}
}
return nullptr;
}
NodeType* SkipChildrenAndMoveToNext() {
NodeType** ppNode = nullptr;
while ((ppNode = m_NodeStack.GetTopElement()) != nullptr) {
NodeType* pNext = TraverseStrategy::GetNextSibling(*ppNode);
m_NodeStack.Pop();
if (m_NodeStack.GetSize() == 0) {
break;
}
if (pNext) {
m_NodeStack.Push(pNext);
break;
}
}
return GetCurrent();
}
protected:
NodeType* m_pRoot;
CFX_StackTemplate<NodeType*> m_NodeStack;
};
CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetData* pWidgetData);
FX_DOUBLE XFA_ByteStringToDouble(const CFX_ByteStringC& szStringVal);
int32_t XFA_MapRotation(int32_t nRotation);
FX_BOOL XFA_RecognizeRichText(CFDE_XMLElement* pRichTextXMLNode);
void XFA_GetPlainTextFromRichText(CFDE_XMLNode* pXMLNode,
CFX_WideString& wsPlainText);
FX_BOOL XFA_FieldIsMultiListBox(CXFA_Node* pFieldNode);
IFX_Stream* XFA_CreateWideTextRead(const CFX_WideString& wsBuffer);
void XFA_DataExporter_DealWithDataGroupNode(CXFA_Node* pDataNode);
void XFA_DataExporter_RegenerateFormFile(CXFA_Node* pNode,
IFX_Stream* pStream,
const FX_CHAR* pChecksum = nullptr,
FX_BOOL bSaveXML = FALSE);
#endif // XFA_FXFA_PARSER_XFA_UTILS_H_
|