0
|
1 |
"{ Package: 'stx:goodies/xmlsuite/xpath' }"
|
|
2 |
|
|
3 |
"{ NameSpace: XMLv2 }"
|
|
4 |
|
|
5 |
Object subclass:#XPathProcessor
|
|
6 |
instanceVariableNames:'expressionParser documentAdaptor'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'XML Suite-XPath'
|
|
10 |
!
|
|
11 |
|
|
12 |
|
|
13 |
!XPathProcessor class methodsFor:'instance creation'!
|
|
14 |
|
|
15 |
new
|
|
16 |
^ self basicNew initialize.
|
|
17 |
! !
|
|
18 |
|
|
19 |
!XPathProcessor methodsFor:'initialization'!
|
|
20 |
|
|
21 |
documentAdaptor:anXPathDocumentAdaptor
|
|
22 |
|
|
23 |
<resource: #obsolete>
|
|
24 |
self obsoleteMethodWarning.
|
|
25 |
|
|
26 |
documentAdaptor := anXPathDocumentAdaptor.
|
|
27 |
|
|
28 |
"Created: / 13-10-2006 / 17:23:33 / janfrog"
|
|
29 |
"Modified: / 25-10-2006 / 17:14:36 / janfrog"
|
|
30 |
!
|
|
31 |
|
|
32 |
initialize
|
|
33 |
super initialize.
|
|
34 |
expressionParser := XPathExpressionParser new.
|
|
35 |
!
|
|
36 |
|
|
37 |
setDocumentAdaptor:anXPathDocumentAdaptor
|
|
38 |
|
|
39 |
documentAdaptor := anXPathDocumentAdaptor.
|
|
40 |
|
|
41 |
"Created: / 25-10-2006 / 17:14:07 / janfrog"
|
|
42 |
!
|
|
43 |
|
|
44 |
setDocumentProvider:aDocumentProvider
|
|
45 |
|
|
46 |
"Nothing to do here"
|
|
47 |
|
|
48 |
"Created: / 25-10-2006 / 17:15:40 / janfrog"
|
|
49 |
! !
|
|
50 |
|
|
51 |
!XPathProcessor methodsFor:'private'!
|
|
52 |
|
|
53 |
evaluateTree:anExpressionTreeRootNode inContext:aContext
|
|
54 |
|location_path nodeSet context|
|
|
55 |
|
|
56 |
XPathExprTreeNode loadRules.
|
|
57 |
location_path := anExpressionTreeRootNode
|
|
58 |
evaluateWithDerivedValue:(XPathExpression new).
|
|
59 |
context := aContext.
|
|
60 |
location_path absolute ifTrue:[
|
|
61 |
context := documentAdaptor xpathRootContext
|
|
62 |
].
|
|
63 |
nodeSet := aContext newNodeSetWith:(context node).
|
|
64 |
location_path steps do:[:step |
|
|
65 |
|newNodeSet|
|
|
66 |
|
|
67 |
newNodeSet := aContext newNodeSet.
|
|
68 |
nodeSet do:[:node |
|
|
69 |
"get elements by axis"
|
|
70 |
newNodeSet addAll:(step axis
|
|
71 |
createNodeSetFromContext:(documentAdaptor xpathContextOf:node)).
|
|
72 |
"filter the set using node test"
|
|
73 |
newNodeSet := step nodeTest filterNodeSet:newNodeSet.
|
|
74 |
"filter the set using predicates"
|
|
75 |
].
|
|
76 |
nodeSet := newNodeSet.
|
|
77 |
].
|
|
78 |
nodeSet documentAdaptor:documentAdaptor.
|
|
79 |
^ nodeSet.
|
|
80 |
|
|
81 |
"Created: / 25-10-2006 / 17:27:44 / janfrog"
|
|
82 |
"Modified: / 15-11-2007 / 22:10:42 / janfrog"
|
|
83 |
!
|
|
84 |
|
|
85 |
sortByDocumentOrder:aNodeSet
|
|
86 |
^aNodeSet
|
|
87 |
ifNil:[#()]
|
|
88 |
ifNotNil:[
|
|
89 |
aNodeSet
|
|
90 |
asSortedCollection:documentAdaptor xpathNodePositionComparator]
|
|
91 |
|
|
92 |
"[:right :left |
|
|
93 |
|result leftPos rightPos pos|
|
|
94 |
|
|
95 |
leftPos := documentAdaptor xpathPositionVectorOf:left.
|
|
96 |
rightPos := documentAdaptor xpathPositionVectorOf:right.
|
|
97 |
pos := 1.
|
|
98 |
|
|
99 |
[
|
|
100 |
((pos <= leftPos elementPosition size)
|
|
101 |
and:[ pos <= rightPos elementPosition size ]) and:[ result isNil ]
|
|
102 |
] whileTrue:[
|
|
103 |
((leftPos elementPosition at:pos) > (rightPos elementPosition at:pos)) ifTrue:[
|
|
104 |
result := true.
|
|
105 |
].
|
|
106 |
((leftPos elementPosition at:pos) < (rightPos elementPosition at:pos)) ifTrue:[
|
|
107 |
result := false.
|
|
108 |
].
|
|
109 |
pos := pos + 1.
|
|
110 |
].
|
|
111 |
(leftPos elementPosition size = (rightPos elementPosition size)) ifTrue:[
|
|
112 |
pos := 1.
|
|
113 |
[
|
|
114 |
((pos <= leftPos attributePosition size)
|
|
115 |
and:[ pos <= rightPos attributePosition size ]) and:[ result isNil ]
|
|
116 |
] whileTrue:[
|
|
117 |
((leftPos attributePosition at:pos) > (rightPos attributePosition at:pos)) ifTrue:[
|
|
118 |
result := true.
|
|
119 |
].
|
|
120 |
((leftPos attributePosition at:pos) < (rightPos attributePosition at:pos)) ifTrue:[
|
|
121 |
result := false.
|
|
122 |
].
|
|
123 |
pos := pos + 1.
|
|
124 |
].
|
|
125 |
].
|
|
126 |
result isNil ifTrue:[
|
|
127 |
result := true
|
|
128 |
].
|
|
129 |
result.
|
|
130 |
]
|
|
131 |
]."
|
|
132 |
|
|
133 |
"Modified: / 13-10-2006 / 20:06:46 / janfrog"
|
|
134 |
! !
|
|
135 |
|
|
136 |
!XPathProcessor methodsFor:'processing'!
|
|
137 |
|
|
138 |
evaluate: aString
|
|
139 |
|
|
140 |
^self evaluate: aString inContext: documentAdaptor xpathRootContext
|
|
141 |
|
|
142 |
"Created: / 25-10-2006 / 17:25:55 / janfrog"
|
|
143 |
!
|
|
144 |
|
|
145 |
evaluate:aString inContext:aContext
|
|
146 |
^ self evaluateTree:(expressionParser parse:aString) inContext:aContext.
|
|
147 |
|
|
148 |
"Created: / 25-10-2006 / 17:28:13 / janfrog"
|
|
149 |
!
|
|
150 |
|
|
151 |
processExpression:aString
|
|
152 |
|
|
153 |
<resource: #obsolete>
|
|
154 |
self obsoleteMethodWarning: 'User #evaluate: instead'.
|
|
155 |
^self evaluate:aString inContext: documentAdaptor xpathRootContext.
|
|
156 |
|
|
157 |
"Modified: / 25-10-2006 / 17:29:25 / janfrog"
|
|
158 |
! !
|
|
159 |
|
|
160 |
!XPathProcessor class methodsFor:'documentation'!
|
|
161 |
|
|
162 |
version
|
|
163 |
^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/xpath/XMLv2__XPathProcessor.st,v 1.4 2007-11-16 09:20:57 vranyj1 Exp $'
|
|
164 |
! !
|