16
16
17
17
package stroom .xml .event .np ;
18
18
19
- import java .util .HashMap ;
20
- import java .util .Map ;
21
-
22
19
import net .sf .saxon .event .PipelineConfiguration ;
23
20
import net .sf .saxon .event .Receiver ;
24
21
import net .sf .saxon .event .ReceiverOptions ;
22
+ import net .sf .saxon .expr .parser .Location ;
25
23
import net .sf .saxon .om .CodedName ;
26
24
import net .sf .saxon .om .NamePool ;
27
25
import net .sf .saxon .trans .XPathException ;
28
26
import net .sf .saxon .tree .tiny .CharSlice ;
29
27
import net .sf .saxon .type .BuiltInAtomicType ;
30
28
import net .sf .saxon .type .Untyped ;
31
29
30
+ import java .util .HashMap ;
31
+ import java .util .Map ;
32
+
32
33
public class EventListConsumer {
34
+ private static final Location NULL_LOCATION = new NullLocation ();
35
+
33
36
private static final String EMPTY = "" ;
34
37
private final Receiver receiver ;
35
38
private final PipelineConfiguration pipe ;
@@ -72,43 +75,43 @@ public void consume(final NPEventList eventList) throws XPathException {
72
75
for (eventTypeIndex = 0 ; eventTypeIndex < eventList .eventTypeArr .length ; eventTypeIndex ++) {
73
76
{
74
77
switch (eventList .eventTypeArr [eventTypeIndex ]) {
75
- case NPEventList .START_ELEMENT :
76
- nameCode = eventList .nameCodeArr [nameCodeIndex ++];
77
- startElement (namePool , nameCode );
78
- receiver .startContent ();
79
- break ;
80
- case NPEventList .START_ELEMENT_WITH_ATTS :
81
- nameCode = eventList .nameCodeArr [nameCodeIndex ++];
82
- startElement (namePool , nameCode );
83
- atts = eventList .attsArr [attsIndex ++];
84
- attributes (namePool , atts );
85
- receiver .startContent ();
86
- break ;
87
- case NPEventList .END_ELEMENT :
88
- receiver .endElement ();
89
- break ;
90
- case NPEventList .CHARACTERS :
91
- final int pos = eventList .charPosArr [charPosIndex ++];
92
- final CharSlice slice = new CharSlice (eventList .charArr , lastPos , pos - lastPos );
93
- receiver .characters (slice , 0 , ReceiverOptions .WHOLE_TEXT_NODE );
94
- lastPos = pos ;
95
- break ;
78
+ case NPEventList .START_ELEMENT :
79
+ nameCode = eventList .nameCodeArr [nameCodeIndex ++];
80
+ startElement (namePool , nameCode );
81
+ receiver .startContent ();
82
+ break ;
83
+ case NPEventList .START_ELEMENT_WITH_ATTS :
84
+ nameCode = eventList .nameCodeArr [nameCodeIndex ++];
85
+ startElement (namePool , nameCode );
86
+ atts = eventList .attsArr [attsIndex ++];
87
+ attributes (namePool , atts );
88
+ receiver .startContent ();
89
+ break ;
90
+ case NPEventList .END_ELEMENT :
91
+ receiver .endElement ();
92
+ break ;
93
+ case NPEventList .CHARACTERS :
94
+ final int pos = eventList .charPosArr [charPosIndex ++];
95
+ final CharSlice slice = new CharSlice (eventList .charArr , lastPos , pos - lastPos );
96
+ receiver .characters (slice , NULL_LOCATION , ReceiverOptions .WHOLE_TEXT_NODE );
97
+ lastPos = pos ;
98
+ break ;
96
99
}
97
100
}
98
101
}
99
102
}
100
103
101
104
private void startElement (final NPEventListNamePool namePool , final int nameCode ) throws XPathException {
102
105
final int code = mapCode (namePool , nameCode );
103
- receiver .startElement (new CodedName (code , pool ), Untyped .getInstance (), 0 , ReceiverOptions .NAMESPACE_OK );
106
+ receiver .startElement (new CodedName (code , pool ), Untyped .getInstance (), NULL_LOCATION , ReceiverOptions .NAMESPACE_OK );
104
107
}
105
108
106
109
private void attributes (final NPEventListNamePool namePool , final NPAttributes atts ) throws XPathException {
107
110
int code = 0 ;
108
111
for (int a = 0 ; a < atts .length ; a ++) {
109
112
code = atts .nameCode [a ];
110
113
code = mapCode (namePool , code );
111
- receiver .attribute (new CodedName (code , pool ), BuiltInAtomicType .UNTYPED_ATOMIC , atts .value [a ], 0 ,
114
+ receiver .attribute (new CodedName (code , pool ), BuiltInAtomicType .UNTYPED_ATOMIC , atts .value [a ], NULL_LOCATION ,
112
115
ReceiverOptions .NAMESPACE_OK );
113
116
}
114
117
}
@@ -129,4 +132,31 @@ private int mapCode(final NPEventListNamePool namePool, final int nameCode) {
129
132
130
133
return code ;
131
134
}
135
+
136
+ private static class NullLocation implements Location {
137
+ @ Override
138
+ public String getSystemId () {
139
+ return null ;
140
+ }
141
+
142
+ @ Override
143
+ public String getPublicId () {
144
+ return null ;
145
+ }
146
+
147
+ @ Override
148
+ public int getLineNumber () {
149
+ return 0 ;
150
+ }
151
+
152
+ @ Override
153
+ public int getColumnNumber () {
154
+ return 0 ;
155
+ }
156
+
157
+ @ Override
158
+ public Location saveLocation () {
159
+ return this ;
160
+ }
161
+ }
132
162
}
0 commit comments