OLD | NEW |
| (Empty) |
1 // Copyright 2014 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/src/fxfa/parser/xfa_script_resolveprocessor.h" | |
8 | |
9 #include "core/include/fxcrt/fx_ext.h" | |
10 #include "xfa/src/fxfa/fm2js/xfa_fm2jsapi.h" | |
11 #include "xfa/src/fxfa/parser/xfa_docdata.h" | |
12 #include "xfa/src/fxfa/parser/xfa_doclayout.h" | |
13 #include "xfa/src/fxfa/parser/xfa_document.h" | |
14 #include "xfa/src/fxfa/parser/xfa_localemgr.h" | |
15 #include "xfa/src/fxfa/parser/xfa_script_imp.h" | |
16 #include "xfa/src/fxfa/parser/xfa_script_nodehelper.h" | |
17 #include "xfa/src/fxfa/parser/xfa_object.h" | |
18 #include "xfa/src/fxfa/parser/xfa_parser.h" | |
19 #include "xfa/src/fxfa/parser/xfa_script.h" | |
20 #include "xfa/src/fxfa/parser/xfa_utils.h" | |
21 | |
22 CXFA_ResolveProcessor::CXFA_ResolveProcessor(void) | |
23 : m_pNodeHelper(NULL), m_iCurStart(0) { | |
24 m_pNodeHelper = new CXFA_NodeHelper; | |
25 } | |
26 CXFA_ResolveProcessor::~CXFA_ResolveProcessor(void) { | |
27 if (m_pNodeHelper) { | |
28 delete m_pNodeHelper; | |
29 m_pNodeHelper = NULL; | |
30 } | |
31 } | |
32 int32_t CXFA_ResolveProcessor::XFA_ResolveNodes(CXFA_ResolveNodesData& rnd) { | |
33 if (rnd.m_CurNode == NULL) { | |
34 return -1; | |
35 } | |
36 if (!rnd.m_CurNode->IsNode()) { | |
37 if (rnd.m_dwStyles & XFA_RESOLVENODE_Attributes) { | |
38 return XFA_ResolveNodes_ForAttributeRs(rnd.m_CurNode, rnd, rnd.m_wsName); | |
39 } | |
40 return 0; | |
41 } | |
42 if (rnd.m_dwStyles & XFA_RESOLVENODE_AnyChild) { | |
43 return XFA_ResolveNodes_AnyChild(rnd); | |
44 } | |
45 FX_WCHAR wch = rnd.m_wsName.GetAt(0); | |
46 switch (wch) { | |
47 case '$': | |
48 return XFA_ResolveNodes_Dollar(rnd); | |
49 case '!': | |
50 return XFA_ResolveNodes_Excalmatory(rnd); | |
51 case '#': | |
52 return XFA_ResolveNodes_NumberSign(rnd); | |
53 case '*': | |
54 return XFA_ResolveNodes_Asterisk(rnd); | |
55 case '.': | |
56 return XFA_ResolveNodes_AnyChild(rnd); | |
57 default: | |
58 break; | |
59 } | |
60 if (rnd.m_uHashName == XFA_HASHCODE_This && rnd.m_nLevel == 0) { | |
61 rnd.m_Nodes.Add(rnd.m_pSC->GetThisObject()); | |
62 return 1; | |
63 } else if (rnd.m_CurNode->GetClassID() == XFA_ELEMENT_Xfa) { | |
64 CXFA_Object* pObjNode = | |
65 rnd.m_pSC->GetDocument()->GetXFAObject(rnd.m_uHashName); | |
66 if (pObjNode) { | |
67 rnd.m_Nodes.Add(pObjNode); | |
68 } else if (rnd.m_uHashName == XFA_HASHCODE_Xfa) { | |
69 rnd.m_Nodes.Add(rnd.m_CurNode); | |
70 } else if ((rnd.m_dwStyles & XFA_RESOLVENODE_Attributes) && | |
71 XFA_ResolveNodes_ForAttributeRs(rnd.m_CurNode, rnd, | |
72 rnd.m_wsName)) { | |
73 return 1; | |
74 } | |
75 if (rnd.m_Nodes.GetSize() > 0) { | |
76 XFA_ResolveNode_FilterCondition(rnd, rnd.m_wsCondition); | |
77 } | |
78 return rnd.m_Nodes.GetSize(); | |
79 } | |
80 int32_t nRet = XFA_ResolveNodes_Normal(rnd); | |
81 if (nRet < 1 && rnd.m_uHashName == XFA_HASHCODE_Xfa) { | |
82 rnd.m_Nodes.Add(rnd.m_pSC->GetDocument()->GetRoot()); | |
83 } | |
84 return rnd.m_Nodes.GetSize(); | |
85 } | |
86 int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_AnyChild( | |
87 CXFA_ResolveNodesData& rnd) { | |
88 CFX_WideString wsName = rnd.m_wsName.Right(rnd.m_wsName.GetLength() - 1); | |
89 CFX_WideString wsCondition = rnd.m_wsCondition; | |
90 CXFA_Node* findNode = NULL; | |
91 CXFA_NodeArray siblings; | |
92 FX_BOOL bClassName = FALSE; | |
93 if (wsName.GetAt(0) == '#') { | |
94 bClassName = TRUE; | |
95 wsName = wsName.Right(wsName.GetLength() - 1); | |
96 } | |
97 findNode = m_pNodeHelper->XFA_ResolveNodes_GetOneChild(ToNode(rnd.m_CurNode), | |
98 wsName, bClassName); | |
99 if (findNode == NULL) { | |
100 return 0; | |
101 } | |
102 if (wsCondition.IsEmpty()) { | |
103 rnd.m_Nodes.Add(findNode); | |
104 return rnd.m_Nodes.GetSize(); | |
105 } | |
106 m_pNodeHelper->XFA_CountSiblings(findNode, XFA_LOGIC_Transparent, | |
107 (CXFA_NodeArray*)&rnd.m_Nodes, bClassName); | |
108 XFA_ResolveNode_FilterCondition(rnd, wsCondition); | |
109 return rnd.m_Nodes.GetSize(); | |
110 } | |
111 int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_Dollar( | |
112 CXFA_ResolveNodesData& rnd) { | |
113 CXFA_ObjArray& nodes = rnd.m_Nodes; | |
114 CFX_WideString wsName = rnd.m_wsName; | |
115 CFX_WideString wsCondition = rnd.m_wsCondition; | |
116 int32_t iNameLen = wsName.GetLength(); | |
117 if (iNameLen == 1) { | |
118 nodes.Add(rnd.m_CurNode); | |
119 return 1; | |
120 } | |
121 if (rnd.m_nLevel > 0) { | |
122 return -1; | |
123 } | |
124 FX_DWORD dwNameHash = | |
125 FX_HashCode_String_GetW((const FX_WCHAR*)wsName + 1, iNameLen - 1); | |
126 if (dwNameHash == XFA_HASHCODE_Xfa) { | |
127 nodes.Add(rnd.m_pSC->GetDocument()->GetRoot()); | |
128 } else { | |
129 CXFA_Object* pObjNode = rnd.m_pSC->GetDocument()->GetXFAObject(dwNameHash); | |
130 if (pObjNode) { | |
131 rnd.m_Nodes.Add(pObjNode); | |
132 } | |
133 } | |
134 if (rnd.m_Nodes.GetSize() > 0) { | |
135 XFA_ResolveNode_FilterCondition(rnd, wsCondition); | |
136 } | |
137 return rnd.m_Nodes.GetSize(); | |
138 } | |
139 int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_Excalmatory( | |
140 CXFA_ResolveNodesData& rnd) { | |
141 if (rnd.m_nLevel > 0) { | |
142 return 0; | |
143 } | |
144 CXFA_Node* datasets = | |
145 ToNode(rnd.m_pSC->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets)); | |
146 if (!datasets) { | |
147 return 0; | |
148 } | |
149 CXFA_ResolveNodesData rndFind; | |
150 rndFind.m_pSC = rnd.m_pSC; | |
151 rndFind.m_CurNode = datasets; | |
152 rndFind.m_wsName = rnd.m_wsName.Right(rnd.m_wsName.GetLength() - 1); | |
153 rndFind.m_uHashName = | |
154 FX_HashCode_String_GetW(rndFind.m_wsName, rndFind.m_wsName.GetLength()); | |
155 rndFind.m_nLevel = rnd.m_nLevel + 1; | |
156 rndFind.m_dwStyles = XFA_RESOLVENODE_Children; | |
157 rndFind.m_wsCondition = rnd.m_wsCondition; | |
158 XFA_ResolveNodes(rndFind); | |
159 if (rndFind.m_Nodes.GetSize() > 0) { | |
160 rnd.m_Nodes.Append(rndFind.m_Nodes); | |
161 rndFind.m_Nodes.RemoveAll(); | |
162 } | |
163 return rnd.m_Nodes.GetSize(); | |
164 } | |
165 int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_NumberSign( | |
166 CXFA_ResolveNodesData& rnd) { | |
167 CFX_WideString wsName = rnd.m_wsName.Right(rnd.m_wsName.GetLength() - 1); | |
168 CFX_WideString wsCondition = rnd.m_wsCondition; | |
169 CXFA_Node* curNode = ToNode(rnd.m_CurNode); | |
170 if (XFA_ResolveNodes_ForAttributeRs(curNode, rnd, wsName)) { | |
171 return 1; | |
172 } | |
173 CXFA_ResolveNodesData rndFind; | |
174 rndFind.m_pSC = rnd.m_pSC; | |
175 rndFind.m_nLevel = rnd.m_nLevel + 1; | |
176 rndFind.m_dwStyles = rnd.m_dwStyles; | |
177 rndFind.m_dwStyles |= XFA_RESOLVENODE_TagName; | |
178 rndFind.m_dwStyles &= ~XFA_RESOLVENODE_Attributes; | |
179 rndFind.m_wsName = wsName; | |
180 rndFind.m_uHashName = | |
181 FX_HashCode_String_GetW(rndFind.m_wsName, rndFind.m_wsName.GetLength()); | |
182 rndFind.m_wsCondition = wsCondition; | |
183 rndFind.m_CurNode = curNode; | |
184 XFA_ResolveNodes_Normal(rndFind); | |
185 if (rndFind.m_Nodes.GetSize() > 0) { | |
186 if (wsCondition.GetLength() == 0 && rndFind.m_Nodes.Find(curNode) >= 0) { | |
187 rnd.m_Nodes.Add(curNode); | |
188 } else { | |
189 rnd.m_Nodes.Append(rndFind.m_Nodes); | |
190 rndFind.m_Nodes.RemoveAll(); | |
191 } | |
192 } | |
193 return rnd.m_Nodes.GetSize(); | |
194 } | |
195 int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_ForAttributeRs( | |
196 CXFA_Object* curNode, | |
197 CXFA_ResolveNodesData& rnd, | |
198 const CFX_WideStringC& strAttr) { | |
199 const XFA_SCRIPTATTRIBUTEINFO* lpScriptAttribute = | |
200 XFA_GetScriptAttributeByName(curNode->GetClassID(), strAttr); | |
201 if (lpScriptAttribute) { | |
202 rnd.m_pScriptAttribute = lpScriptAttribute; | |
203 rnd.m_Nodes.Add(curNode); | |
204 rnd.m_dwFlag = XFA_RESOVENODE_RSTYPE_Attribute; | |
205 return 1; | |
206 } | |
207 return 0; | |
208 } | |
209 int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_Normal( | |
210 CXFA_ResolveNodesData& rnd) { | |
211 if (rnd.m_nLevel > 32) { | |
212 return 0; | |
213 } | |
214 if (!rnd.m_CurNode->IsNode()) { | |
215 return 0; | |
216 } | |
217 CXFA_Node* curNode = ToNode(rnd.m_CurNode); | |
218 CXFA_ObjArray& nodes = rnd.m_Nodes; | |
219 int32_t nNum = nodes.GetSize(); | |
220 FX_DWORD dwStyles = rnd.m_dwStyles; | |
221 CFX_WideString& wsName = rnd.m_wsName; | |
222 uint32_t uNameHash = rnd.m_uHashName; | |
223 CFX_WideString& wsCondition = rnd.m_wsCondition; | |
224 CXFA_ResolveNodesData rndFind; | |
225 rndFind.m_wsName = rnd.m_wsName; | |
226 rndFind.m_wsCondition = rnd.m_wsCondition; | |
227 rndFind.m_pSC = rnd.m_pSC; | |
228 rndFind.m_nLevel = rnd.m_nLevel + 1; | |
229 rndFind.m_uHashName = uNameHash; | |
230 CXFA_NodeArray children; | |
231 CXFA_NodeArray properties; | |
232 CXFA_Node* pVariablesNode = NULL; | |
233 CXFA_Node* pPageSetNode = NULL; | |
234 CXFA_Node* pChild = curNode->GetNodeItem(XFA_NODEITEM_FirstChild); | |
235 while (pChild) { | |
236 if (pChild->GetClassID() == XFA_ELEMENT_Variables) { | |
237 pVariablesNode = pChild; | |
238 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); | |
239 continue; | |
240 } else if (pChild->GetClassID() == XFA_ELEMENT_PageSet) { | |
241 pPageSetNode = pChild; | |
242 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); | |
243 continue; | |
244 } else { | |
245 const XFA_PROPERTY* pPropert = XFA_GetPropertyOfElement( | |
246 curNode->GetClassID(), pChild->GetClassID(), XFA_XDPPACKET_UNKNOWN); | |
247 if (pPropert) { | |
248 properties.Add(pChild); | |
249 } else { | |
250 children.Add(pChild); | |
251 } | |
252 } | |
253 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); | |
254 } | |
255 if ((dwStyles & XFA_RESOLVENODE_Properties) && pVariablesNode) { | |
256 uint32_t uPropHash = pVariablesNode->GetClassHashCode(); | |
257 if (uPropHash == uNameHash) { | |
258 nodes.Add(pVariablesNode); | |
259 } else { | |
260 rndFind.m_CurNode = pVariablesNode; | |
261 XFA_ResolveNodes_SetStylesForChild(dwStyles, rndFind); | |
262 CFX_WideString wsSaveCondition = rndFind.m_wsCondition; | |
263 rndFind.m_wsCondition.Empty(); | |
264 XFA_ResolveNodes_Normal(rndFind); | |
265 rndFind.m_wsCondition = wsSaveCondition; | |
266 if (rndFind.m_Nodes.GetSize() > 0) { | |
267 nodes.Append(rndFind.m_Nodes); | |
268 rndFind.m_Nodes.RemoveAll(); | |
269 } | |
270 } | |
271 if (nodes.GetSize() > nNum) { | |
272 XFA_ResolveNode_FilterCondition(rnd, wsCondition); | |
273 if (nodes.GetSize() > 0) { | |
274 return 1; | |
275 } | |
276 return 0; | |
277 } | |
278 } | |
279 if (dwStyles & XFA_RESOLVENODE_Children) { | |
280 FX_BOOL bSetFlag = FALSE; | |
281 if (pPageSetNode && (dwStyles & XFA_RESOLVENODE_Properties)) { | |
282 children.Add(pPageSetNode); | |
283 } | |
284 for (int32_t i = 0; i < children.GetSize(); i++) { | |
285 CXFA_Node* child = children[i]; | |
286 if (dwStyles & XFA_RESOLVENODE_TagName) { | |
287 if (child->GetClassHashCode() == uNameHash) { | |
288 nodes.Add(child); | |
289 } | |
290 } else if (child->GetNameHash() == uNameHash) { | |
291 nodes.Add(child); | |
292 } | |
293 if (m_pNodeHelper->XFA_NodeIsTransparent(child) && | |
294 child->GetClassID() != XFA_ELEMENT_PageSet) { | |
295 if (!bSetFlag) { | |
296 XFA_ResolveNodes_SetStylesForChild(dwStyles, rndFind); | |
297 bSetFlag = TRUE; | |
298 } | |
299 rndFind.m_CurNode = child; | |
300 CFX_WideString wsSaveCondition = rndFind.m_wsCondition; | |
301 rndFind.m_wsCondition.Empty(); | |
302 XFA_ResolveNodes_Normal(rndFind); | |
303 rndFind.m_wsCondition = wsSaveCondition; | |
304 if (rndFind.m_Nodes.GetSize() > 0) { | |
305 nodes.Append(rndFind.m_Nodes); | |
306 rndFind.m_Nodes.RemoveAll(); | |
307 } | |
308 } | |
309 } | |
310 if (nodes.GetSize() > nNum) { | |
311 if (!(dwStyles & XFA_RESOLVENODE_ALL)) { | |
312 CXFA_NodeArray upArrayNodes; | |
313 if (m_pNodeHelper->XFA_NodeIsTransparent(ToNode(curNode))) { | |
314 m_pNodeHelper->XFA_CountSiblings( | |
315 ToNode(nodes[0]), XFA_LOGIC_Transparent, &upArrayNodes, | |
316 !!(dwStyles & XFA_RESOLVENODE_TagName)); | |
317 } | |
318 if (upArrayNodes.GetSize() > nodes.GetSize()) { | |
319 upArrayNodes[0] = ToNode(nodes[0]); | |
320 nodes.RemoveAll(); | |
321 nodes.Append((CXFA_ObjArray&)upArrayNodes); | |
322 upArrayNodes.RemoveAll(); | |
323 } | |
324 } | |
325 XFA_ResolveNode_FilterCondition(rnd, wsCondition); | |
326 if (nodes.GetSize() > 0) { | |
327 return 1; | |
328 } | |
329 return 0; | |
330 } | |
331 } | |
332 if (dwStyles & XFA_RESOLVENODE_Attributes) { | |
333 if (XFA_ResolveNodes_ForAttributeRs(curNode, rnd, wsName)) { | |
334 return 1; | |
335 } | |
336 } | |
337 if (dwStyles & XFA_RESOLVENODE_Properties) { | |
338 for (int32_t i = 0; i < properties.GetSize(); i++) { | |
339 CXFA_Node* childProperty = properties[i]; | |
340 if (childProperty->IsUnnamed()) { | |
341 uint32_t uPropHash = childProperty->GetClassHashCode(); | |
342 if (uPropHash == uNameHash) { | |
343 nodes.Add(childProperty); | |
344 } | |
345 } else if (childProperty->GetNameHash() == uNameHash && | |
346 childProperty->GetClassID() != XFA_ELEMENT_Extras && | |
347 childProperty->GetClassID() != XFA_ELEMENT_Items) { | |
348 nodes.Add(childProperty); | |
349 } | |
350 } | |
351 if (nodes.GetSize() > nNum) { | |
352 XFA_ResolveNode_FilterCondition(rnd, wsCondition); | |
353 if (nodes.GetSize() > 0) { | |
354 return 1; | |
355 } | |
356 return 0; | |
357 } | |
358 CXFA_Node* pProp = NULL; | |
359 if (XFA_ELEMENT_Subform == curNode->GetClassID() && | |
360 XFA_HASHCODE_Occur == uNameHash) { | |
361 CXFA_Node* pInstanceManager = | |
362 curNode->AsNode()->GetInstanceMgrOfSubform(); | |
363 if (pInstanceManager) { | |
364 pProp = pInstanceManager->GetProperty(0, XFA_ELEMENT_Occur, TRUE); | |
365 } | |
366 } else { | |
367 const XFA_ELEMENTINFO* pElement = XFA_GetElementByName(wsName); | |
368 if (pElement) { | |
369 pProp = curNode->AsNode()->GetProperty( | |
370 0, pElement->eName, pElement->eName != XFA_ELEMENT_PageSet); | |
371 } | |
372 } | |
373 if (pProp) { | |
374 nodes.Add(pProp); | |
375 return nodes.GetSize(); | |
376 } | |
377 } | |
378 CXFA_Node* parentNode = m_pNodeHelper->XFA_ResolveNodes_GetParent( | |
379 curNode->AsNode(), XFA_LOGIC_NoTransparent); | |
380 uint32_t uCurClassHash = curNode->GetClassHashCode(); | |
381 if (!parentNode) { | |
382 if (uCurClassHash == uNameHash) { | |
383 nodes.Add(curNode->AsNode()); | |
384 XFA_ResolveNode_FilterCondition(rnd, wsCondition); | |
385 if (nodes.GetSize() > 0) { | |
386 return 1; | |
387 } | |
388 } | |
389 return 0; | |
390 } | |
391 if (dwStyles & XFA_RESOLVENODE_Siblings) { | |
392 CXFA_Node* child = parentNode->GetNodeItem(XFA_NODEITEM_FirstChild); | |
393 FX_DWORD dwSubStyles = | |
394 XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties; | |
395 if (dwStyles & XFA_RESOLVENODE_TagName) { | |
396 dwSubStyles |= XFA_RESOLVENODE_TagName; | |
397 } | |
398 if (dwStyles & XFA_RESOLVENODE_ALL) { | |
399 dwSubStyles |= XFA_RESOLVENODE_ALL; | |
400 } | |
401 rndFind.m_dwStyles = dwSubStyles; | |
402 while (child) { | |
403 if (child == curNode) { | |
404 if (dwStyles & XFA_RESOLVENODE_TagName) { | |
405 if (uCurClassHash == uNameHash) { | |
406 nodes.Add(curNode); | |
407 } | |
408 } else { | |
409 if (child->GetNameHash() == uNameHash) { | |
410 nodes.Add(curNode); | |
411 if (rnd.m_nLevel == 0 && wsCondition.GetLength() == 0) { | |
412 nodes.RemoveAll(); | |
413 nodes.Add(curNode); | |
414 return 1; | |
415 } | |
416 } | |
417 } | |
418 child = child->GetNodeItem(XFA_NODEITEM_NextSibling); | |
419 continue; | |
420 } | |
421 if (dwStyles & XFA_RESOLVENODE_TagName) { | |
422 if (child->GetClassHashCode() == uNameHash) { | |
423 nodes.Add(child); | |
424 } | |
425 } else if (child->GetNameHash() == uNameHash) { | |
426 nodes.Add(child); | |
427 } | |
428 const XFA_PROPERTY* pPropert = XFA_GetPropertyOfElement( | |
429 parentNode->GetClassID(), child->GetClassID(), XFA_XDPPACKET_UNKNOWN); | |
430 FX_BOOL bInnerSearch = FALSE; | |
431 if (pPropert) { | |
432 if ((child->GetClassID() == XFA_ELEMENT_Variables || | |
433 child->GetClassID() == XFA_ELEMENT_PageSet)) { | |
434 bInnerSearch = TRUE; | |
435 } | |
436 } else { | |
437 if (m_pNodeHelper->XFA_NodeIsTransparent(child)) { | |
438 bInnerSearch = TRUE; | |
439 } | |
440 } | |
441 if (bInnerSearch) { | |
442 rndFind.m_CurNode = child; | |
443 CFX_WideString wsOriginCondition = rndFind.m_wsCondition; | |
444 rndFind.m_wsCondition.Empty(); | |
445 FX_DWORD dwOriginStyle = rndFind.m_dwStyles; | |
446 rndFind.m_dwStyles = dwOriginStyle | XFA_RESOLVENODE_ALL; | |
447 XFA_ResolveNodes_Normal(rndFind); | |
448 rndFind.m_dwStyles = dwOriginStyle; | |
449 rndFind.m_wsCondition = wsOriginCondition; | |
450 if (rndFind.m_Nodes.GetSize() > 0) { | |
451 nodes.Append(rndFind.m_Nodes); | |
452 rndFind.m_Nodes.RemoveAll(); | |
453 } | |
454 } | |
455 child = child->GetNodeItem(XFA_NODEITEM_NextSibling); | |
456 } | |
457 if (nodes.GetSize() > nNum) { | |
458 if (m_pNodeHelper->XFA_NodeIsTransparent(parentNode)) { | |
459 CXFA_NodeArray upArrayNodes; | |
460 m_pNodeHelper->XFA_CountSiblings( | |
461 ToNode(nodes[0]), XFA_LOGIC_Transparent, &upArrayNodes, | |
462 !!(dwStyles & XFA_RESOLVENODE_TagName)); | |
463 if (upArrayNodes.GetSize() > nodes.GetSize()) { | |
464 upArrayNodes[0] = ToNode(nodes[0]); | |
465 nodes.RemoveAll(); | |
466 nodes.Append((CXFA_ObjArray&)upArrayNodes); | |
467 upArrayNodes.RemoveAll(); | |
468 } | |
469 } | |
470 XFA_ResolveNode_FilterCondition(rnd, wsCondition); | |
471 if (nodes.GetSize() > 0) { | |
472 return 1; | |
473 } | |
474 return 0; | |
475 } | |
476 } | |
477 if (dwStyles & XFA_RESOLVENODE_Parent) { | |
478 FX_DWORD dwSubStyles = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent | | |
479 XFA_RESOLVENODE_Properties; | |
480 if (dwStyles & XFA_RESOLVENODE_TagName) { | |
481 dwSubStyles |= XFA_RESOLVENODE_TagName; | |
482 } | |
483 if (dwStyles & XFA_RESOLVENODE_ALL) { | |
484 dwSubStyles |= XFA_RESOLVENODE_ALL; | |
485 } | |
486 rndFind.m_dwStyles = dwSubStyles; | |
487 rndFind.m_CurNode = parentNode; | |
488 CXFA_NodeArray& array = rnd.m_pSC->GetUpObjectArray(); | |
489 array.Add(parentNode); | |
490 XFA_ResolveNodes_Normal(rndFind); | |
491 if (rndFind.m_Nodes.GetSize() > 0) { | |
492 nodes.Append(rndFind.m_Nodes); | |
493 rndFind.m_Nodes.RemoveAll(); | |
494 } | |
495 if (nodes.GetSize() > nNum) { | |
496 return 1; | |
497 } | |
498 } | |
499 return 0; | |
500 } | |
501 int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_Asterisk( | |
502 CXFA_ResolveNodesData& rnd) { | |
503 CXFA_Node* curNode = ToNode(rnd.m_CurNode); | |
504 CXFA_ObjArray& nodes = rnd.m_Nodes; | |
505 CXFA_NodeArray array; | |
506 curNode->GetNodeList(array, | |
507 XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties); | |
508 nodes.Append((CXFA_ObjArray&)array); | |
509 return nodes.GetSize(); | |
510 } | |
511 int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_PopStack( | |
512 CFX_Int32Array& stack) { | |
513 int32_t nType = -1; | |
514 int32_t iSize = stack.GetSize() - 1; | |
515 if (iSize > -1) { | |
516 nType = stack[iSize]; | |
517 stack.RemoveAt(iSize, 1); | |
518 } | |
519 return nType; | |
520 } | |
521 int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_GetFilter( | |
522 const CFX_WideStringC& wsExpression, | |
523 int32_t nStart, | |
524 CXFA_ResolveNodesData& rnd) { | |
525 FXSYS_assert(nStart > -1); | |
526 int32_t iLength = wsExpression.GetLength(); | |
527 if (nStart >= iLength) { | |
528 return 0; | |
529 } | |
530 CFX_WideString& wsName = rnd.m_wsName; | |
531 CFX_WideString& wsCondition = rnd.m_wsCondition; | |
532 FX_WCHAR* pNameBuf = wsName.GetBuffer(iLength - nStart); | |
533 FX_WCHAR* pConditionBuf = wsCondition.GetBuffer(iLength - nStart); | |
534 int32_t nNameCount = 0; | |
535 int32_t nConditionCount = 0; | |
536 CFX_Int32Array stack; | |
537 int32_t nType = -1; | |
538 const FX_WCHAR* pSrc = wsExpression.GetPtr(); | |
539 FX_WCHAR wPrev = 0, wCur; | |
540 FX_BOOL bIsCondition = FALSE; | |
541 while (nStart < iLength) { | |
542 wCur = pSrc[nStart++]; | |
543 if (wCur == '.') { | |
544 if (wPrev == '\\') { | |
545 pNameBuf[nNameCount - 1] = wPrev = '.'; | |
546 continue; | |
547 } | |
548 if (nNameCount == 0) { | |
549 pNameBuf[nNameCount++] = wCur; | |
550 continue; | |
551 } | |
552 FX_WCHAR wLookahead = nStart < iLength ? pSrc[nStart] : 0; | |
553 if (wLookahead != '[' && wLookahead != '(') { | |
554 if (nType < 0) { | |
555 break; | |
556 } | |
557 } | |
558 } | |
559 if (wCur == '[' || wCur == '(') { | |
560 bIsCondition = TRUE; | |
561 } else if (wCur == '.' && nStart < iLength && | |
562 (pSrc[nStart] == '[' || pSrc[nStart] == '(')) { | |
563 bIsCondition = TRUE; | |
564 } | |
565 if (bIsCondition) { | |
566 pConditionBuf[nConditionCount++] = wCur; | |
567 } else { | |
568 pNameBuf[nNameCount++] = wCur; | |
569 } | |
570 FX_BOOL bRecursive = TRUE; | |
571 switch (nType) { | |
572 case 0: | |
573 if (wCur == ']') { | |
574 nType = XFA_ResolveNodes_PopStack(stack); | |
575 bRecursive = FALSE; | |
576 } | |
577 break; | |
578 case 1: | |
579 if (wCur == ')') { | |
580 nType = XFA_ResolveNodes_PopStack(stack); | |
581 bRecursive = FALSE; | |
582 } | |
583 break; | |
584 case 2: | |
585 if (wCur == '"') { | |
586 nType = XFA_ResolveNodes_PopStack(stack); | |
587 bRecursive = FALSE; | |
588 } | |
589 break; | |
590 } | |
591 if (bRecursive) { | |
592 switch (wCur) { | |
593 case '[': | |
594 stack.Add(nType); | |
595 nType = 0; | |
596 break; | |
597 case '(': | |
598 stack.Add(nType); | |
599 nType = 1; | |
600 break; | |
601 case '"': | |
602 stack.Add(nType); | |
603 nType = 2; | |
604 break; | |
605 } | |
606 } | |
607 wPrev = wCur; | |
608 } | |
609 if (stack.GetSize() > 0) { | |
610 return -1; | |
611 } | |
612 wsName.ReleaseBuffer(nNameCount); | |
613 wsName.TrimLeft(); | |
614 wsName.TrimRight(); | |
615 wsCondition.ReleaseBuffer(nConditionCount); | |
616 wsCondition.TrimLeft(); | |
617 wsCondition.TrimRight(); | |
618 rnd.m_uHashName = FX_HashCode_String_GetW(wsName, wsName.GetLength()); | |
619 return nStart; | |
620 } | |
621 void CXFA_ResolveProcessor::XFA_ResolveNode_ConditionArray( | |
622 int32_t iCurIndex, | |
623 CFX_WideString wsCondition, | |
624 int32_t iFoundCount, | |
625 CXFA_ResolveNodesData& rnd) { | |
626 CXFA_NodeArray& findNodes = (CXFA_NodeArray&)rnd.m_Nodes; | |
627 int32_t iLen = wsCondition.GetLength(); | |
628 FX_BOOL bRelative = FALSE; | |
629 FX_BOOL bAll = FALSE; | |
630 int32_t i = 1; | |
631 for (; i < iLen; ++i) { | |
632 FX_WCHAR ch = wsCondition[i]; | |
633 if (ch == ' ') { | |
634 continue; | |
635 } | |
636 if (ch == '+' || ch == '-') { | |
637 bRelative = TRUE; | |
638 break; | |
639 } else if (ch == '*') { | |
640 bAll = TRUE; | |
641 break; | |
642 } else { | |
643 break; | |
644 } | |
645 } | |
646 if (bAll) { | |
647 if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { | |
648 if (rnd.m_dwStyles & XFA_RESOLVENODE_Bind) { | |
649 m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurNode); | |
650 m_pNodeHelper->m_iCreateCount = 1; | |
651 findNodes.RemoveAll(); | |
652 m_pNodeHelper->m_iCurAllStart = -1; | |
653 m_pNodeHelper->m_pAllStartParent = NULL; | |
654 } else { | |
655 if (m_pNodeHelper->m_iCurAllStart == -1) { | |
656 m_pNodeHelper->m_iCurAllStart = m_iCurStart; | |
657 m_pNodeHelper->m_pAllStartParent = ToNode(rnd.m_CurNode); | |
658 } | |
659 } | |
660 } else if (rnd.m_dwStyles & XFA_RESOLVENODE_BindNew) { | |
661 if (m_pNodeHelper->m_iCurAllStart == -1) { | |
662 m_pNodeHelper->m_iCurAllStart = m_iCurStart; | |
663 } | |
664 } | |
665 return; | |
666 } | |
667 if (iFoundCount == 1 && !iLen) { | |
668 return; | |
669 } | |
670 CFX_WideString wsIndex; | |
671 wsIndex = wsCondition.Mid(i, iLen - 1 - i); | |
672 int32_t iIndex = wsIndex.GetInteger(); | |
673 if (bRelative) { | |
674 iIndex += iCurIndex; | |
675 } | |
676 if (iFoundCount <= iIndex || iIndex < 0) { | |
677 if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { | |
678 m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurNode); | |
679 m_pNodeHelper->m_iCreateCount = iIndex - iFoundCount + 1; | |
680 } | |
681 findNodes.RemoveAll(); | |
682 } else { | |
683 CXFA_Node* ret = findNodes[iIndex]; | |
684 findNodes.RemoveAll(); | |
685 findNodes.Add(ret); | |
686 } | |
687 } | |
688 void CXFA_ResolveProcessor::XFA_ResolveNode_DoPredicateFilter( | |
689 int32_t iCurIndex, | |
690 CFX_WideString wsCondition, | |
691 int32_t iFoundCount, | |
692 CXFA_ResolveNodesData& rnd) { | |
693 CXFA_NodeArray& findNodes = (CXFA_NodeArray&)rnd.m_Nodes; | |
694 FXSYS_assert(iFoundCount == findNodes.GetSize()); | |
695 CFX_WideString wsExpression; | |
696 IXFA_ScriptContext* pContext = NULL; | |
697 XFA_SCRIPTLANGTYPE eLangType = XFA_SCRIPTLANGTYPE_Unkown; | |
698 if (wsCondition.Left(2) == FX_WSTRC(L".[") && | |
699 wsCondition.Right(1) == FX_WSTRC(L"]")) { | |
700 eLangType = XFA_SCRIPTLANGTYPE_Formcalc; | |
701 } else if (wsCondition.Left(2) == FX_WSTRC(L".(") && | |
702 wsCondition.Right(1) == FX_WSTRC(L")")) { | |
703 eLangType = XFA_SCRIPTLANGTYPE_Javascript; | |
704 } else { | |
705 return; | |
706 } | |
707 pContext = rnd.m_pSC; | |
708 wsExpression = wsCondition.Mid(2, wsCondition.GetLength() - 3); | |
709 for (int32_t i = iFoundCount - 1; i >= 0; i--) { | |
710 CXFA_Object* node = findNodes[i]; | |
711 FX_BOOL bRet = FALSE; | |
712 FXJSE_HVALUE pRetValue = FXJSE_Value_Create(rnd.m_pSC->GetRuntime()); | |
713 bRet = pContext->RunScript(eLangType, wsExpression, pRetValue, node); | |
714 if (!bRet || !FXJSE_Value_ToBoolean(pRetValue)) { | |
715 findNodes.RemoveAt(i); | |
716 } | |
717 FXJSE_Value_Release(pRetValue); | |
718 } | |
719 } | |
720 | |
721 void CXFA_ResolveProcessor::XFA_ResolveNode_FilterCondition( | |
722 CXFA_ResolveNodesData& rnd, | |
723 CFX_WideString wsCondition) { | |
724 CXFA_NodeArray& findNodes = (CXFA_NodeArray&)rnd.m_Nodes; | |
725 int32_t iCurrIndex = 0; | |
726 const CXFA_NodeArray& array = rnd.m_pSC->GetUpObjectArray(); | |
727 int32_t iSize = array.GetSize(); | |
728 if (iSize) { | |
729 CXFA_Node* curNode = array[iSize - 1]; | |
730 FX_BOOL bIsProperty = m_pNodeHelper->XFA_NodeIsProperty(curNode); | |
731 if (curNode->IsUnnamed() || | |
732 (bIsProperty && curNode->GetClassID() != XFA_ELEMENT_PageSet)) { | |
733 iCurrIndex = m_pNodeHelper->XFA_GetIndex(curNode, XFA_LOGIC_Transparent, | |
734 bIsProperty, TRUE); | |
735 } else { | |
736 iCurrIndex = m_pNodeHelper->XFA_GetIndex(curNode, XFA_LOGIC_Transparent, | |
737 bIsProperty, FALSE); | |
738 } | |
739 } | |
740 int32_t iFoundCount = findNodes.GetSize(); | |
741 wsCondition.TrimLeft(); | |
742 wsCondition.TrimRight(); | |
743 int32_t iLen = wsCondition.GetLength(); | |
744 if (!iLen) { | |
745 if (rnd.m_dwStyles & XFA_RESOLVENODE_ALL) { | |
746 return; | |
747 } | |
748 if (iFoundCount == 1) { | |
749 return; | |
750 } | |
751 if (iFoundCount <= iCurrIndex) { | |
752 if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { | |
753 m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurNode); | |
754 m_pNodeHelper->m_iCreateCount = iCurrIndex - iFoundCount + 1; | |
755 } | |
756 findNodes.RemoveAll(); | |
757 return; | |
758 } else { | |
759 CXFA_Node* ret = findNodes[iCurrIndex]; | |
760 findNodes.RemoveAll(); | |
761 findNodes.Add(ret); | |
762 return; | |
763 } | |
764 } | |
765 FX_WCHAR wTypeChar = wsCondition[0]; | |
766 switch (wTypeChar) { | |
767 case '[': | |
768 XFA_ResolveNode_ConditionArray(iCurrIndex, wsCondition, iFoundCount, rnd); | |
769 return; | |
770 case '(': | |
771 return; | |
772 case '"': | |
773 return; | |
774 case '.': | |
775 if (iLen > 1 && (wsCondition[1] == '[' || wsCondition[1] == '(')) { | |
776 XFA_ResolveNode_DoPredicateFilter(iCurrIndex, wsCondition, iFoundCount, | |
777 rnd); | |
778 } | |
779 default: | |
780 return; | |
781 } | |
782 } | |
783 void CXFA_ResolveProcessor::XFA_ResolveNodes_SetStylesForChild( | |
784 FX_DWORD dwParentStyles, | |
785 CXFA_ResolveNodesData& rnd) { | |
786 FX_DWORD dwSubStyles = XFA_RESOLVENODE_Children; | |
787 if (dwParentStyles & XFA_RESOLVENODE_TagName) { | |
788 dwSubStyles |= XFA_RESOLVENODE_TagName; | |
789 } | |
790 dwSubStyles &= ~XFA_RESOLVENODE_Parent; | |
791 dwSubStyles &= ~XFA_RESOLVENODE_Siblings; | |
792 dwSubStyles &= ~XFA_RESOLVENODE_Properties; | |
793 dwSubStyles |= XFA_RESOLVENODE_ALL; | |
794 rnd.m_dwStyles = dwSubStyles; | |
795 } | |
796 int32_t CXFA_ResolveProcessor::XFA_ResolveNode_SetResultCreateNode( | |
797 XFA_RESOLVENODE_RS& resolveNodeRS, | |
798 CFX_WideString& wsLastCondition) { | |
799 if (m_pNodeHelper->m_pCreateParent) { | |
800 resolveNodeRS.nodes.Add(m_pNodeHelper->m_pCreateParent); | |
801 } else { | |
802 m_pNodeHelper->XFA_CreateNode_ForCondition(wsLastCondition); | |
803 } | |
804 resolveNodeRS.dwFlags = m_pNodeHelper->m_iCreateFlag; | |
805 if (resolveNodeRS.dwFlags == XFA_RESOLVENODE_RSTYPE_CreateNodeOne) { | |
806 if (m_pNodeHelper->m_iCurAllStart != -1) { | |
807 resolveNodeRS.dwFlags = XFA_RESOLVENODE_RSTYPE_CreateNodeMidAll; | |
808 } | |
809 } | |
810 return resolveNodeRS.nodes.GetSize(); | |
811 } | |
812 void CXFA_ResolveProcessor::XFA_ResolveNode_SetIndexDataBind( | |
813 CFX_WideString& wsNextCondition, | |
814 int32_t& iIndex, | |
815 int32_t iCount) { | |
816 if (m_pNodeHelper->XFA_CreateNode_ForCondition(wsNextCondition)) { | |
817 if (m_pNodeHelper->m_eLastCreateType == XFA_ELEMENT_DataGroup) { | |
818 iIndex = 0; | |
819 } else { | |
820 iIndex = iCount - 1; | |
821 } | |
822 } else { | |
823 iIndex = iCount - 1; | |
824 } | |
825 } | |
OLD | NEW |