0
|
1 |
"{ Package: 'stx:goodies/xmlsuite/xpath' }"
|
|
2 |
|
|
3 |
"{ NameSpace: XMLv2 }"
|
|
4 |
|
|
5 |
Object subclass:#XPathExpressionOptimizer
|
|
6 |
instanceVariableNames:'xpathExpression'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'XML Suite-XPath'
|
|
10 |
!
|
|
11 |
|
|
12 |
|
|
13 |
!XPathExpressionOptimizer class methodsFor:'optimizer'!
|
|
14 |
|
|
15 |
optimize: xpathExpression
|
|
16 |
|
|
17 |
^self new
|
|
18 |
xpathExpression: xpathExpression;
|
|
19 |
optimize;
|
|
20 |
xpathExpression
|
|
21 |
|
|
22 |
"Created: / 21-11-2007 / 10:43:43 / janfrog"
|
|
23 |
! !
|
|
24 |
|
|
25 |
!XPathExpressionOptimizer methodsFor:'accessing'!
|
|
26 |
|
|
27 |
xpathExpression
|
|
28 |
^ xpathExpression
|
|
29 |
|
|
30 |
"Created: / 21-11-2007 / 10:43:48 / janfrog"
|
|
31 |
!
|
|
32 |
|
|
33 |
xpathExpression:something
|
|
34 |
xpathExpression := something.
|
|
35 |
|
|
36 |
"Created: / 21-11-2007 / 10:43:48 / janfrog"
|
|
37 |
! !
|
|
38 |
|
|
39 |
!XPathExpressionOptimizer methodsFor:'optimizing'!
|
|
40 |
|
|
41 |
optimize
|
|
42 |
|
|
43 |
self optimizeDescendantOrSelf
|
|
44 |
|
|
45 |
"Created: / 21-11-2007 / 10:45:04 / janfrog"
|
|
46 |
!
|
|
47 |
|
|
48 |
optimizeDescendantOrSelf
|
|
49 |
|
|
50 |
| newXPathExpression locationStepIndex |
|
|
51 |
xpathExpression size < 1 ifTrue:[^self].
|
|
52 |
newXPathExpression := XPathExpression new absolute: xpathExpression absolute.
|
|
53 |
locationStepIndex := 1.
|
|
54 |
|
|
55 |
[locationStepIndex < xpathExpression size] whileTrue:
|
|
56 |
[| currentLocationStep nextLocationStep |
|
|
57 |
currentLocationStep := xpathExpression at:locationStepIndex.
|
|
58 |
nextLocationStep := xpathExpression at:locationStepIndex + 1.
|
|
59 |
(currentLocationStep isDescendantOrSelfWithAnyKindTestStepAndWithoutPredicates
|
|
60 |
and:[nextLocationStep isChildWithNameTestStep])
|
|
61 |
ifTrue:
|
|
62 |
[newXPathExpression add:
|
|
63 |
(XPathLocationStep new
|
|
64 |
axis: XPathAxisDescendantOrSelf new;
|
|
65 |
nodeTest: nextLocationStep nodeTest;
|
|
66 |
predicates: nextLocationStep predicates).
|
|
67 |
locationStepIndex := locationStepIndex + 1]
|
|
68 |
ifFalse:
|
|
69 |
[newXPathExpression
|
|
70 |
add: currentLocationStep].
|
|
71 |
locationStepIndex := locationStepIndex + 1].
|
|
72 |
locationStepIndex = xpathExpression size ifTrue:
|
|
73 |
[newXPathExpression add:xpathExpression last].
|
|
74 |
xpathExpression := newXPathExpression
|
|
75 |
|
|
76 |
"Created: / 21-11-2007 / 11:02:49 / janfrog"
|
|
77 |
! !
|
|
78 |
|
|
79 |
!XPathExpressionOptimizer class methodsFor:'documentation'!
|
|
80 |
|
|
81 |
version
|
|
82 |
^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/xpath/XMLv2__XPathExpressionOptimizer.st,v 1.1 2007-11-22 21:47:19 vranyj1 Exp $'
|
|
83 |
! !
|