author | henryjen |
Mon, 22 Jan 2018 23:37:23 -0800 | |
changeset 48657 | 7e5fbd3a2254 |
parent 48577 | 8dff65f1d611 |
child 53593 | 1ceebbe2c1da |
permissions | -rw-r--r-- |
6 | 1 |
/* |
48577 | 2 |
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved. |
6 | 3 |
*/ |
4 |
/* |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
5 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
6 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
7 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
8 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
9 |
* (the "License"); you may not use this file except in compliance with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
10 |
* the License. You may obtain a copy of the License at |
6 | 11 |
* |
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
6 | 13 |
* |
14 |
* Unless required by applicable law or agreed to in writing, software |
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17 |
* See the License for the specific language governing permissions and |
|
18 |
* limitations under the License. |
|
19 |
*/ |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
20 |
|
6 | 21 |
package com.sun.org.apache.xpath.internal; |
22 |
||
23 |
import com.sun.org.apache.xalan.internal.extensions.ExpressionContext; |
|
24 |
import com.sun.org.apache.xalan.internal.res.XSLMessages; |
|
25 |
import com.sun.org.apache.xml.internal.dtm.Axis; |
|
26 |
import com.sun.org.apache.xml.internal.dtm.DTM; |
|
27 |
import com.sun.org.apache.xml.internal.dtm.DTMFilter; |
|
28 |
import com.sun.org.apache.xml.internal.dtm.DTMIterator; |
|
29 |
import com.sun.org.apache.xml.internal.dtm.DTMManager; |
|
30 |
import com.sun.org.apache.xml.internal.dtm.DTMWSFilter; |
|
31 |
import com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2RTFDTM; |
|
32 |
import com.sun.org.apache.xml.internal.utils.IntStack; |
|
33 |
import com.sun.org.apache.xml.internal.utils.NodeVector; |
|
34 |
import com.sun.org.apache.xml.internal.utils.ObjectStack; |
|
35 |
import com.sun.org.apache.xml.internal.utils.PrefixResolver; |
|
36 |
import com.sun.org.apache.xml.internal.utils.XMLString; |
|
37 |
import com.sun.org.apache.xpath.internal.axes.SubContextList; |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
38 |
import com.sun.org.apache.xpath.internal.objects.DTMXRTreeFrag; |
6 | 39 |
import com.sun.org.apache.xpath.internal.objects.XObject; |
40 |
import com.sun.org.apache.xpath.internal.objects.XString; |
|
41 |
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources; |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
42 |
import java.lang.reflect.Method; |
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
43 |
import java.util.ArrayList; |
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
44 |
import java.util.HashMap; |
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
45 |
import java.util.Iterator; |
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
46 |
import java.util.List; |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
47 |
import java.util.Map; |
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
48 |
import java.util.Stack; |
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
49 |
import javax.xml.transform.ErrorListener; |
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
50 |
import javax.xml.transform.SourceLocator; |
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
51 |
import javax.xml.transform.URIResolver; |
48577 | 52 |
import jdk.xml.internal.JdkXmlUtils; |
6 | 53 |
import org.xml.sax.XMLReader; |
54 |
||
55 |
/** |
|
56 |
* Default class for the runtime execution context for XPath. |
|
57 |
* |
|
58 |
* <p>This class extends DTMManager but does not directly implement it.</p> |
|
59 |
* @xsl.usage advanced |
|
48409 | 60 |
* @LastModified: Oct 2017 |
6 | 61 |
*/ |
62 |
public class XPathContext extends DTMManager // implements ExpressionContext |
|
63 |
{ |
|
64 |
IntStack m_last_pushed_rtfdtm=new IntStack(); |
|
65 |
/** |
|
66 |
* Stack of cached "reusable" DTMs for Result Tree Fragments. |
|
67 |
* This is a kluge to handle the problem of starting an RTF before |
|
68 |
* the old one is complete. |
|
69 |
* |
|
70 |
* %REVIEW% I'm using a Vector rather than Stack so we can reuse |
|
71 |
* the DTMs if the problem occurs multiple times. I'm not sure that's |
|
72 |
* really a net win versus discarding the DTM and starting a new one... |
|
73 |
* but the retained RTF DTM will have been tail-pruned so should be small. |
|
74 |
*/ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
75 |
private List<DTM> m_rtfdtm_stack=null; |
6 | 76 |
/** Index of currently active RTF DTM in m_rtfdtm_stack */ |
77 |
private int m_which_rtfdtm=-1; |
|
78 |
||
79 |
/** |
|
80 |
* Most recent "reusable" DTM for Global Result Tree Fragments. No stack is |
|
81 |
* required since we're never going to pop these. |
|
82 |
*/ |
|
83 |
private SAX2RTFDTM m_global_rtfdtm=null; |
|
84 |
||
85 |
/** |
|
86 |
* HashMap of cached the DTMXRTreeFrag objects, which are identified by DTM IDs. |
|
87 |
* The object are just wrappers for DTMs which are used in XRTreeFrag. |
|
88 |
*/ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
89 |
private Map<Integer, DTMXRTreeFrag> m_DTMXRTreeFrags = null; |
6 | 90 |
|
91 |
/** |
|
92 |
* state of the secure processing feature. |
|
93 |
*/ |
|
94 |
private boolean m_isSecureProcessing = false; |
|
95 |
||
48577 | 96 |
private boolean m_overrideDefaultParser; |
12458 | 97 |
|
6 | 98 |
/** |
99 |
* Though XPathContext context extends |
|
100 |
* the DTMManager, it really is a proxy for this object, which |
|
101 |
* is the real DTMManager. |
|
102 |
*/ |
|
20959
674f4eb04ac9
8008733: Psr:perf:osb performance regression (18%) in wss_bodyenc
aefimov
parents:
18352
diff
changeset
|
103 |
protected DTMManager m_dtmManager = null; |
6 | 104 |
|
105 |
/** |
|
106 |
* Return the DTMManager object. Though XPathContext context extends |
|
107 |
* the DTMManager, it really is a proxy for the real DTMManager. If a |
|
108 |
* caller needs to make a lot of calls to the DTMManager, it is faster |
|
109 |
* if it gets the real one from this function. |
|
110 |
*/ |
|
111 |
public DTMManager getDTMManager() |
|
112 |
{ |
|
113 |
return m_dtmManager; |
|
114 |
} |
|
115 |
||
116 |
/** |
|
117 |
* Set the state of the secure processing feature |
|
118 |
*/ |
|
119 |
public void setSecureProcessing(boolean flag) |
|
120 |
{ |
|
121 |
m_isSecureProcessing = flag; |
|
122 |
} |
|
123 |
||
124 |
/** |
|
125 |
* Return the state of the secure processing feature |
|
126 |
*/ |
|
127 |
public boolean isSecureProcessing() |
|
128 |
{ |
|
129 |
return m_isSecureProcessing; |
|
130 |
} |
|
131 |
||
132 |
/** |
|
133 |
* Get an instance of a DTM, loaded with the content from the |
|
134 |
* specified source. If the unique flag is true, a new instance will |
|
135 |
* always be returned. Otherwise it is up to the DTMManager to return a |
|
136 |
* new instance or an instance that it already created and may be being used |
|
137 |
* by someone else. |
|
138 |
* (I think more parameters will need to be added for error handling, and entity |
|
139 |
* resolution). |
|
140 |
* |
|
141 |
* @param source the specification of the source object, which may be null, |
|
142 |
* in which case it is assumed that node construction will take |
|
143 |
* by some other means. |
|
144 |
* @param unique true if the returned DTM must be unique, probably because it |
|
145 |
* is going to be mutated. |
|
146 |
* @param wsfilter Enables filtering of whitespace nodes, and may be null. |
|
147 |
* @param incremental true if the construction should try and be incremental. |
|
148 |
* @param doIndexing true if the caller considers it worth it to use |
|
149 |
* indexing schemes. |
|
150 |
* |
|
151 |
* @return a non-null DTM reference. |
|
152 |
*/ |
|
153 |
public DTM getDTM(javax.xml.transform.Source source, boolean unique, |
|
154 |
DTMWSFilter wsfilter, |
|
155 |
boolean incremental, |
|
156 |
boolean doIndexing) |
|
157 |
{ |
|
158 |
return m_dtmManager.getDTM(source, unique, wsfilter, |
|
159 |
incremental, doIndexing); |
|
160 |
} |
|
161 |
||
162 |
/** |
|
163 |
* Get an instance of a DTM that "owns" a node handle. |
|
164 |
* |
|
165 |
* @param nodeHandle the nodeHandle. |
|
166 |
* |
|
167 |
* @return a non-null DTM reference. |
|
168 |
*/ |
|
169 |
public DTM getDTM(int nodeHandle) |
|
170 |
{ |
|
171 |
return m_dtmManager.getDTM(nodeHandle); |
|
172 |
} |
|
173 |
||
174 |
/** |
|
175 |
* Given a W3C DOM node, try and return a DTM handle. |
|
176 |
* Note: calling this may be non-optimal. |
|
177 |
* |
|
178 |
* @param node Non-null reference to a DOM node. |
|
179 |
* |
|
180 |
* @return a valid DTM handle. |
|
181 |
*/ |
|
182 |
public int getDTMHandleFromNode(org.w3c.dom.Node node) |
|
183 |
{ |
|
184 |
return m_dtmManager.getDTMHandleFromNode(node); |
|
185 |
} |
|
186 |
// |
|
187 |
// |
|
188 |
/** |
|
189 |
* %TBD% Doc |
|
190 |
*/ |
|
191 |
public int getDTMIdentity(DTM dtm) |
|
192 |
{ |
|
193 |
return m_dtmManager.getDTMIdentity(dtm); |
|
194 |
} |
|
195 |
// |
|
196 |
/** |
|
197 |
* Creates an empty <code>DocumentFragment</code> object. |
|
198 |
* @return A new <code>DocumentFragment handle</code>. |
|
199 |
*/ |
|
200 |
public DTM createDocumentFragment() |
|
201 |
{ |
|
202 |
return m_dtmManager.createDocumentFragment(); |
|
203 |
} |
|
204 |
// |
|
205 |
/** |
|
206 |
* Release a DTM either to a lru pool, or completely remove reference. |
|
207 |
* DTMs without system IDs are always hard deleted. |
|
208 |
* State: experimental. |
|
209 |
* |
|
210 |
* @param dtm The DTM to be released. |
|
211 |
* @param shouldHardDelete True if the DTM should be removed no matter what. |
|
212 |
* @return true if the DTM was removed, false if it was put back in a lru pool. |
|
213 |
*/ |
|
214 |
public boolean release(DTM dtm, boolean shouldHardDelete) |
|
215 |
{ |
|
216 |
// %REVIEW% If it's a DTM which may contain multiple Result Tree |
|
217 |
// Fragments, we can't discard it unless we know not only that it |
|
218 |
// is empty, but that the XPathContext itself is going away. So do |
|
219 |
// _not_ accept the request. (May want to do it as part of |
|
220 |
// reset(), though.) |
|
221 |
if(m_rtfdtm_stack!=null && m_rtfdtm_stack.contains(dtm)) |
|
222 |
{ |
|
223 |
return false; |
|
224 |
} |
|
225 |
||
226 |
return m_dtmManager.release(dtm, shouldHardDelete); |
|
227 |
} |
|
228 |
||
229 |
/** |
|
230 |
* Create a new <code>DTMIterator</code> based on an XPath |
|
231 |
* <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath</a> or |
|
232 |
* a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>. |
|
233 |
* |
|
234 |
* @param xpathCompiler ??? Somehow we need to pass in a subpart of the |
|
235 |
* expression. I hate to do this with strings, since the larger expression |
|
236 |
* has already been parsed. |
|
237 |
* |
|
238 |
* @param pos The position in the expression. |
|
239 |
* @return The newly created <code>DTMIterator</code>. |
|
240 |
*/ |
|
241 |
public DTMIterator createDTMIterator(Object xpathCompiler, int pos) |
|
242 |
{ |
|
243 |
return m_dtmManager.createDTMIterator(xpathCompiler, pos); |
|
244 |
} |
|
245 |
// |
|
246 |
/** |
|
247 |
* Create a new <code>DTMIterator</code> based on an XPath |
|
248 |
* <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath</a> or |
|
249 |
* a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>. |
|
250 |
* |
|
251 |
* @param xpathString Must be a valid string expressing a |
|
252 |
* <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath</a> or |
|
253 |
* a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>. |
|
254 |
* |
|
255 |
* @param presolver An object that can resolve prefixes to namespace URLs. |
|
256 |
* |
|
257 |
* @return The newly created <code>DTMIterator</code>. |
|
258 |
*/ |
|
259 |
public DTMIterator createDTMIterator(String xpathString, |
|
260 |
PrefixResolver presolver) |
|
261 |
{ |
|
262 |
return m_dtmManager.createDTMIterator(xpathString, presolver); |
|
263 |
} |
|
264 |
// |
|
265 |
/** |
|
266 |
* Create a new <code>DTMIterator</code> based only on a whatToShow and |
|
267 |
* a DTMFilter. The traversal semantics are defined as the descendant |
|
268 |
* access. |
|
269 |
* |
|
270 |
* @param whatToShow This flag specifies which node types may appear in |
|
271 |
* the logical view of the tree presented by the iterator. See the |
|
272 |
* description of <code>NodeFilter</code> for the set of possible |
|
273 |
* <code>SHOW_</code> values.These flags can be combined using |
|
274 |
* <code>OR</code>. |
|
275 |
* @param filter The <code>NodeFilter</code> to be used with this |
|
276 |
* <code>TreeWalker</code>, or <code>null</code> to indicate no filter. |
|
277 |
* @param entityReferenceExpansion The value of this flag determines |
|
278 |
* whether entity reference nodes are expanded. |
|
279 |
* |
|
280 |
* @return The newly created <code>NodeIterator</code>. |
|
281 |
*/ |
|
282 |
public DTMIterator createDTMIterator(int whatToShow, |
|
283 |
DTMFilter filter, boolean entityReferenceExpansion) |
|
284 |
{ |
|
285 |
return m_dtmManager.createDTMIterator(whatToShow, filter, entityReferenceExpansion); |
|
286 |
} |
|
287 |
||
288 |
/** |
|
289 |
* Create a new <code>DTMIterator</code> that holds exactly one node. |
|
290 |
* |
|
291 |
* @param node The node handle that the DTMIterator will iterate to. |
|
292 |
* |
|
293 |
* @return The newly created <code>DTMIterator</code>. |
|
294 |
*/ |
|
295 |
public DTMIterator createDTMIterator(int node) |
|
296 |
{ |
|
297 |
// DescendantIterator iter = new DescendantIterator(); |
|
298 |
DTMIterator iter = new com.sun.org.apache.xpath.internal.axes.OneStepIteratorForward(Axis.SELF); |
|
299 |
iter.setRoot(node, this); |
|
300 |
return iter; |
|
301 |
// return m_dtmManager.createDTMIterator(node); |
|
302 |
} |
|
303 |
||
304 |
/** |
|
305 |
* Create an XPathContext instance. |
|
306 |
*/ |
|
307 |
public XPathContext() |
|
308 |
{ |
|
48577 | 309 |
this(false); |
6 | 310 |
} |
311 |
||
48577 | 312 |
public XPathContext(boolean overrideDefaultParser) { |
313 |
init(overrideDefaultParser); |
|
12458 | 314 |
} |
6 | 315 |
/** |
12458 | 316 |
**This constructor doesn't seem to be used anywhere -- huizhe wang** |
6 | 317 |
* Create an XPathContext instance. |
318 |
* @param owner Value that can be retrieved via the getOwnerObject() method. |
|
319 |
* @see #getOwnerObject |
|
320 |
*/ |
|
321 |
public XPathContext(Object owner) |
|
322 |
{ |
|
323 |
m_owner = owner; |
|
324 |
try { |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
325 |
m_ownerGetErrorListener = m_owner.getClass().getMethod("getErrorListener", new Class<?>[] {}); |
6 | 326 |
} |
327 |
catch (NoSuchMethodException nsme) {} |
|
48577 | 328 |
init(false); |
12458 | 329 |
} |
330 |
||
48577 | 331 |
private void init(boolean overrideDefaultParser) { |
6 | 332 |
m_prefixResolvers.push(null); |
333 |
m_currentNodes.push(DTM.NULL); |
|
334 |
m_currentExpressionNodes.push(DTM.NULL); |
|
335 |
m_saxLocations.push(null); |
|
48577 | 336 |
m_overrideDefaultParser = overrideDefaultParser; |
12458 | 337 |
m_dtmManager = DTMManager.newInstance( |
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
338 |
com.sun.org.apache.xpath.internal.objects.XMLStringFactoryImpl.getFactory() |
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
339 |
); |
6 | 340 |
} |
341 |
||
342 |
/** |
|
343 |
* Reset for new run. |
|
344 |
*/ |
|
345 |
public void reset() |
|
346 |
{ |
|
347 |
releaseDTMXRTreeFrags(); |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
348 |
// These couldn't be disposed of earlier (see comments in release()); zap them now. |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
349 |
if(m_rtfdtm_stack!=null) { |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
350 |
for (DTM dtm : m_rtfdtm_stack) { |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
351 |
m_dtmManager.release(dtm, true); |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
352 |
} |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
353 |
} |
6 | 354 |
|
355 |
m_rtfdtm_stack=null; // drop our references too |
|
356 |
m_which_rtfdtm=-1; |
|
357 |
||
358 |
if(m_global_rtfdtm!=null) |
|
359 |
m_dtmManager.release(m_global_rtfdtm,true); |
|
360 |
m_global_rtfdtm=null; |
|
361 |
||
362 |
||
363 |
m_dtmManager = DTMManager.newInstance( |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
364 |
com.sun.org.apache.xpath.internal.objects.XMLStringFactoryImpl.getFactory() |
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
365 |
); |
6 | 366 |
|
367 |
m_saxLocations.removeAllElements(); |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
368 |
m_axesIteratorStack.removeAllElements(); |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
369 |
m_contextNodeLists.removeAllElements(); |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
370 |
m_currentExpressionNodes.removeAllElements(); |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
371 |
m_currentNodes.removeAllElements(); |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
372 |
m_iteratorRoots.RemoveAllNoClear(); |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
373 |
m_predicatePos.removeAllElements(); |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
374 |
m_predicateRoots.RemoveAllNoClear(); |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
375 |
m_prefixResolvers.removeAllElements(); |
6 | 376 |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
377 |
m_prefixResolvers.push(null); |
6 | 378 |
m_currentNodes.push(DTM.NULL); |
379 |
m_currentExpressionNodes.push(DTM.NULL); |
|
380 |
m_saxLocations.push(null); |
|
381 |
} |
|
382 |
||
383 |
/** The current stylesheet locator. */ |
|
384 |
ObjectStack m_saxLocations = new ObjectStack(RECURSIONLIMIT); |
|
385 |
||
386 |
/** |
|
387 |
* Set the current locater in the stylesheet. |
|
388 |
* |
|
389 |
* @param location The location within the stylesheet. |
|
390 |
*/ |
|
391 |
public void setSAXLocator(SourceLocator location) |
|
392 |
{ |
|
393 |
m_saxLocations.setTop(location); |
|
394 |
} |
|
395 |
||
396 |
/** |
|
397 |
* Set the current locater in the stylesheet. |
|
398 |
* |
|
399 |
* @param location The location within the stylesheet. |
|
400 |
*/ |
|
401 |
public void pushSAXLocator(SourceLocator location) |
|
402 |
{ |
|
403 |
m_saxLocations.push(location); |
|
404 |
} |
|
405 |
||
406 |
/** |
|
407 |
* Push a slot on the locations stack so that setSAXLocator can be |
|
408 |
* repeatedly called. |
|
409 |
* |
|
410 |
*/ |
|
411 |
public void pushSAXLocatorNull() |
|
412 |
{ |
|
413 |
m_saxLocations.push(null); |
|
414 |
} |
|
415 |
||
416 |
||
417 |
/** |
|
418 |
* Pop the current locater. |
|
419 |
*/ |
|
420 |
public void popSAXLocator() |
|
421 |
{ |
|
422 |
m_saxLocations.pop(); |
|
423 |
} |
|
424 |
||
425 |
/** |
|
426 |
* Get the current locater in the stylesheet. |
|
427 |
* |
|
428 |
* @return The location within the stylesheet, or null if not known. |
|
429 |
*/ |
|
430 |
public SourceLocator getSAXLocator() |
|
431 |
{ |
|
432 |
return (SourceLocator) m_saxLocations.peek(); |
|
433 |
} |
|
434 |
||
435 |
/** The owner context of this XPathContext. In the case of XSLT, this will be a |
|
436 |
* Transformer object. |
|
437 |
*/ |
|
438 |
private Object m_owner; |
|
439 |
||
440 |
/** The owner context of this XPathContext. In the case of XSLT, this will be a |
|
441 |
* Transformer object. |
|
442 |
*/ |
|
443 |
private Method m_ownerGetErrorListener; |
|
444 |
||
445 |
/** |
|
446 |
* Get the "owner" context of this context, which should be, |
|
447 |
* in the case of XSLT, the Transformer object. This is needed |
|
448 |
* so that XSLT functions can get the Transformer. |
|
449 |
* @return The owner object passed into the constructor, or null. |
|
450 |
*/ |
|
451 |
public Object getOwnerObject() |
|
452 |
{ |
|
453 |
return m_owner; |
|
454 |
} |
|
455 |
||
456 |
// ================ VarStack =================== |
|
457 |
||
458 |
/** |
|
459 |
* The stack of Variable stacks. A VariableStack will be |
|
460 |
* pushed onto this stack for each template invocation. |
|
461 |
*/ |
|
462 |
private VariableStack m_variableStacks = new VariableStack(); |
|
463 |
||
464 |
/** |
|
465 |
* Get the variable stack, which is in charge of variables and |
|
466 |
* parameters. |
|
467 |
* |
|
468 |
* @return the variable stack, which should not be null. |
|
469 |
*/ |
|
470 |
public final VariableStack getVarStack() |
|
471 |
{ |
|
472 |
return m_variableStacks; |
|
473 |
} |
|
474 |
||
475 |
/** |
|
476 |
* Get the variable stack, which is in charge of variables and |
|
477 |
* parameters. |
|
478 |
* |
|
479 |
* @param varStack non-null reference to the variable stack. |
|
480 |
*/ |
|
481 |
public final void setVarStack(VariableStack varStack) |
|
482 |
{ |
|
483 |
m_variableStacks = varStack; |
|
484 |
} |
|
485 |
||
486 |
// ================ SourceTreeManager =================== |
|
487 |
||
488 |
/** The source tree manager, which associates Source objects to source |
|
489 |
* tree nodes. */ |
|
490 |
private SourceTreeManager m_sourceTreeManager = new SourceTreeManager(); |
|
491 |
||
492 |
/** |
|
493 |
* Get the SourceTreeManager associated with this execution context. |
|
494 |
* |
|
495 |
* @return the SourceTreeManager associated with this execution context. |
|
496 |
*/ |
|
497 |
public final SourceTreeManager getSourceTreeManager() |
|
498 |
{ |
|
499 |
return m_sourceTreeManager; |
|
500 |
} |
|
501 |
||
502 |
/** |
|
503 |
* Set the SourceTreeManager associated with this execution context. |
|
504 |
* |
|
505 |
* @param mgr the SourceTreeManager to be associated with this |
|
506 |
* execution context. |
|
507 |
*/ |
|
508 |
public void setSourceTreeManager(SourceTreeManager mgr) |
|
509 |
{ |
|
510 |
m_sourceTreeManager = mgr; |
|
511 |
} |
|
512 |
||
513 |
// ================================================= |
|
514 |
||
515 |
/** The ErrorListener where errors and warnings are to be reported. */ |
|
516 |
private ErrorListener m_errorListener; |
|
517 |
||
518 |
/** A default ErrorListener in case our m_errorListener was not specified and our |
|
519 |
* owner either does not have an ErrorListener or has a null one. |
|
520 |
*/ |
|
521 |
private ErrorListener m_defaultErrorListener; |
|
522 |
||
523 |
/** |
|
524 |
* Get the ErrorListener where errors and warnings are to be reported. |
|
525 |
* |
|
526 |
* @return A non-null ErrorListener reference. |
|
527 |
*/ |
|
528 |
public final ErrorListener getErrorListener() |
|
529 |
{ |
|
530 |
||
531 |
if (null != m_errorListener) |
|
532 |
return m_errorListener; |
|
533 |
||
534 |
ErrorListener retval = null; |
|
535 |
||
536 |
try { |
|
537 |
if (null != m_ownerGetErrorListener) |
|
538 |
retval = (ErrorListener) m_ownerGetErrorListener.invoke(m_owner, new Object[] {}); |
|
539 |
} |
|
540 |
catch (Exception e) {} |
|
541 |
||
542 |
if (null == retval) |
|
543 |
{ |
|
544 |
if (null == m_defaultErrorListener) |
|
545 |
m_defaultErrorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler(); |
|
546 |
retval = m_defaultErrorListener; |
|
547 |
} |
|
548 |
||
549 |
return retval; |
|
550 |
} |
|
551 |
||
552 |
/** |
|
553 |
* Set the ErrorListener where errors and warnings are to be reported. |
|
554 |
* |
|
555 |
* @param listener A non-null ErrorListener reference. |
|
556 |
*/ |
|
557 |
public void setErrorListener(ErrorListener listener) throws IllegalArgumentException |
|
558 |
{ |
|
559 |
if (listener == null) |
|
560 |
throw new IllegalArgumentException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, null)); //"Null error handler"); |
|
561 |
m_errorListener = listener; |
|
562 |
} |
|
563 |
||
564 |
||
565 |
// ================================================= |
|
566 |
||
567 |
/** The TrAX URI Resolver for resolving URIs from the document(...) |
|
568 |
* function to source tree nodes. */ |
|
569 |
private URIResolver m_uriResolver; |
|
570 |
||
571 |
/** |
|
572 |
* Get the URIResolver associated with this execution context. |
|
573 |
* |
|
574 |
* @return a URI resolver, which may be null. |
|
575 |
*/ |
|
576 |
public final URIResolver getURIResolver() |
|
577 |
{ |
|
578 |
return m_uriResolver; |
|
579 |
} |
|
580 |
||
581 |
/** |
|
582 |
* Set the URIResolver associated with this execution context. |
|
583 |
* |
|
584 |
* @param resolver the URIResolver to be associated with this |
|
585 |
* execution context, may be null to clear an already set resolver. |
|
586 |
*/ |
|
587 |
public void setURIResolver(URIResolver resolver) |
|
588 |
{ |
|
589 |
m_uriResolver = resolver; |
|
590 |
} |
|
591 |
||
592 |
// ================================================= |
|
593 |
||
594 |
/** The reader of the primary source tree. */ |
|
595 |
public XMLReader m_primaryReader; |
|
596 |
||
597 |
/** |
|
598 |
* Get primary XMLReader associated with this execution context. |
|
599 |
* |
|
600 |
* @return The reader of the primary source tree. |
|
601 |
*/ |
|
602 |
public final XMLReader getPrimaryReader() |
|
603 |
{ |
|
604 |
return m_primaryReader; |
|
605 |
} |
|
606 |
||
607 |
/** |
|
608 |
* Set primary XMLReader associated with this execution context. |
|
609 |
* |
|
610 |
* @param reader The reader of the primary source tree. |
|
611 |
*/ |
|
612 |
public void setPrimaryReader(XMLReader reader) |
|
613 |
{ |
|
614 |
m_primaryReader = reader; |
|
615 |
} |
|
616 |
||
617 |
// ================================================= |
|
618 |
||
619 |
||
620 |
/** Misnamed string manager for XPath messages. */ |
|
621 |
// private static XSLMessages m_XSLMessages = new XSLMessages(); |
|
622 |
||
623 |
//========================================================== |
|
624 |
// SECTION: Execution context state tracking |
|
625 |
//========================================================== |
|
626 |
||
627 |
/** |
|
628 |
* The current context node list. |
|
629 |
*/ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
630 |
private Stack<DTMIterator> m_contextNodeLists = new Stack<>(); |
6 | 631 |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
632 |
public Stack<DTMIterator> getContextNodeListsStack() { return m_contextNodeLists; } |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
633 |
public void setContextNodeListsStack(Stack<DTMIterator> s) { m_contextNodeLists = s; } |
6 | 634 |
|
635 |
/** |
|
636 |
* Get the current context node list. |
|
637 |
* |
|
638 |
* @return the <a href="http://www.w3.org/TR/xslt#dt-current-node-list">current node list</a>, |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
639 |
* also referred to here as a <term>context node list</term>. |
6 | 640 |
*/ |
641 |
public final DTMIterator getContextNodeList() |
|
642 |
{ |
|
643 |
||
644 |
if (m_contextNodeLists.size() > 0) |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
645 |
return m_contextNodeLists.peek(); |
6 | 646 |
else |
647 |
return null; |
|
648 |
} |
|
649 |
||
650 |
/** |
|
651 |
* Set the current context node list. |
|
652 |
* |
|
653 |
* @param nl the <a href="http://www.w3.org/TR/xslt#dt-current-node-list">current node list</a>, |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
654 |
* also referred to here as a <term>context node list</term>. |
6 | 655 |
* @xsl.usage internal |
656 |
*/ |
|
657 |
public final void pushContextNodeList(DTMIterator nl) |
|
658 |
{ |
|
659 |
m_contextNodeLists.push(nl); |
|
660 |
} |
|
661 |
||
662 |
/** |
|
663 |
* Pop the current context node list. |
|
664 |
* @xsl.usage internal |
|
665 |
*/ |
|
666 |
public final void popContextNodeList() |
|
667 |
{ |
|
668 |
if(m_contextNodeLists.isEmpty()) |
|
669 |
System.err.println("Warning: popContextNodeList when stack is empty!"); |
|
670 |
else |
|
671 |
m_contextNodeLists.pop(); |
|
672 |
} |
|
673 |
||
674 |
/** |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
12458
diff
changeset
|
675 |
* The amount to use for stacks that record information during the |
6 | 676 |
* recursive execution. |
677 |
*/ |
|
678 |
public static final int RECURSIONLIMIT = (1024*4); |
|
679 |
||
680 |
/** The stack of <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a> objects. |
|
681 |
* Not to be confused with the current node list. %REVIEW% Note that there |
|
682 |
* are no bounds check and resize for this stack, so if it is blown, it's all |
|
683 |
* over. */ |
|
684 |
private IntStack m_currentNodes = new IntStack(RECURSIONLIMIT); |
|
685 |
||
686 |
// private NodeVector m_currentNodes = new NodeVector(); |
|
687 |
||
688 |
public IntStack getCurrentNodeStack() {return m_currentNodes; } |
|
689 |
public void setCurrentNodeStack(IntStack nv) { m_currentNodes = nv; } |
|
690 |
||
691 |
/** |
|
692 |
* Get the current context node. |
|
693 |
* |
|
694 |
* @return the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>. |
|
695 |
*/ |
|
696 |
public final int getCurrentNode() |
|
697 |
{ |
|
698 |
return m_currentNodes.peek(); |
|
699 |
} |
|
700 |
||
701 |
/** |
|
702 |
* Set the current context node and expression node. |
|
703 |
* |
|
704 |
* @param cn the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>. |
|
705 |
* @param en the sub-expression context node. |
|
706 |
*/ |
|
707 |
public final void pushCurrentNodeAndExpression(int cn, int en) |
|
708 |
{ |
|
709 |
m_currentNodes.push(cn); |
|
710 |
m_currentExpressionNodes.push(cn); |
|
711 |
} |
|
712 |
||
713 |
/** |
|
714 |
* Set the current context node. |
|
715 |
*/ |
|
716 |
public final void popCurrentNodeAndExpression() |
|
717 |
{ |
|
718 |
m_currentNodes.quickPop(1); |
|
719 |
m_currentExpressionNodes.quickPop(1); |
|
720 |
} |
|
721 |
||
722 |
/** |
|
723 |
* Push the current context node, expression node, and prefix resolver. |
|
724 |
* |
|
725 |
* @param cn the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>. |
|
726 |
* @param en the sub-expression context node. |
|
727 |
* @param nc the namespace context (prefix resolver. |
|
728 |
*/ |
|
729 |
public final void pushExpressionState(int cn, int en, PrefixResolver nc) |
|
730 |
{ |
|
731 |
m_currentNodes.push(cn); |
|
732 |
m_currentExpressionNodes.push(cn); |
|
733 |
m_prefixResolvers.push(nc); |
|
734 |
} |
|
735 |
||
736 |
/** |
|
737 |
* Pop the current context node, expression node, and prefix resolver. |
|
738 |
*/ |
|
739 |
public final void popExpressionState() |
|
740 |
{ |
|
741 |
m_currentNodes.quickPop(1); |
|
742 |
m_currentExpressionNodes.quickPop(1); |
|
743 |
m_prefixResolvers.pop(); |
|
744 |
} |
|
745 |
||
746 |
||
747 |
||
748 |
/** |
|
749 |
* Set the current context node. |
|
750 |
* |
|
751 |
* @param n the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>. |
|
752 |
*/ |
|
753 |
public final void pushCurrentNode(int n) |
|
754 |
{ |
|
755 |
m_currentNodes.push(n); |
|
756 |
} |
|
757 |
||
758 |
/** |
|
759 |
* Pop the current context node. |
|
760 |
*/ |
|
761 |
public final void popCurrentNode() |
|
762 |
{ |
|
763 |
m_currentNodes.quickPop(1); |
|
764 |
} |
|
765 |
||
766 |
/** |
|
767 |
* Set the current predicate root. |
|
768 |
*/ |
|
769 |
public final void pushPredicateRoot(int n) |
|
770 |
{ |
|
771 |
m_predicateRoots.push(n); |
|
772 |
} |
|
773 |
||
774 |
/** |
|
775 |
* Pop the current predicate root. |
|
776 |
*/ |
|
777 |
public final void popPredicateRoot() |
|
778 |
{ |
|
779 |
m_predicateRoots.popQuick(); |
|
780 |
} |
|
781 |
||
782 |
/** |
|
783 |
* Get the current predicate root. |
|
784 |
*/ |
|
785 |
public final int getPredicateRoot() |
|
786 |
{ |
|
787 |
return m_predicateRoots.peepOrNull(); |
|
788 |
} |
|
789 |
||
790 |
/** |
|
791 |
* Set the current location path iterator root. |
|
792 |
*/ |
|
793 |
public final void pushIteratorRoot(int n) |
|
794 |
{ |
|
795 |
m_iteratorRoots.push(n); |
|
796 |
} |
|
797 |
||
798 |
/** |
|
799 |
* Pop the current location path iterator root. |
|
800 |
*/ |
|
801 |
public final void popIteratorRoot() |
|
802 |
{ |
|
803 |
m_iteratorRoots.popQuick(); |
|
804 |
} |
|
805 |
||
806 |
/** |
|
807 |
* Get the current location path iterator root. |
|
808 |
*/ |
|
809 |
public final int getIteratorRoot() |
|
810 |
{ |
|
811 |
return m_iteratorRoots.peepOrNull(); |
|
812 |
} |
|
813 |
||
814 |
/** A stack of the current sub-expression nodes. */ |
|
815 |
private NodeVector m_iteratorRoots = new NodeVector(); |
|
816 |
||
817 |
/** A stack of the current sub-expression nodes. */ |
|
818 |
private NodeVector m_predicateRoots = new NodeVector(); |
|
819 |
||
820 |
/** A stack of the current sub-expression nodes. */ |
|
821 |
private IntStack m_currentExpressionNodes = new IntStack(RECURSIONLIMIT); |
|
822 |
||
823 |
||
824 |
public IntStack getCurrentExpressionNodeStack() { return m_currentExpressionNodes; } |
|
825 |
public void setCurrentExpressionNodeStack(IntStack nv) { m_currentExpressionNodes = nv; } |
|
826 |
||
827 |
private IntStack m_predicatePos = new IntStack(); |
|
828 |
||
829 |
public final int getPredicatePos() |
|
830 |
{ |
|
831 |
return m_predicatePos.peek(); |
|
832 |
} |
|
833 |
||
834 |
public final void pushPredicatePos(int n) |
|
835 |
{ |
|
836 |
m_predicatePos.push(n); |
|
837 |
} |
|
838 |
||
839 |
public final void popPredicatePos() |
|
840 |
{ |
|
841 |
m_predicatePos.pop(); |
|
842 |
} |
|
843 |
||
844 |
/** |
|
845 |
* Get the current node that is the expression's context (i.e. for current() support). |
|
846 |
* |
|
847 |
* @return The current sub-expression node. |
|
848 |
*/ |
|
849 |
public final int getCurrentExpressionNode() |
|
850 |
{ |
|
851 |
return m_currentExpressionNodes.peek(); |
|
852 |
} |
|
853 |
||
854 |
/** |
|
855 |
* Set the current node that is the expression's context (i.e. for current() support). |
|
856 |
* |
|
857 |
* @param n The sub-expression node to be current. |
|
858 |
*/ |
|
859 |
public final void pushCurrentExpressionNode(int n) |
|
860 |
{ |
|
861 |
m_currentExpressionNodes.push(n); |
|
862 |
} |
|
863 |
||
864 |
/** |
|
865 |
* Pop the current node that is the expression's context |
|
866 |
* (i.e. for current() support). |
|
867 |
*/ |
|
868 |
public final void popCurrentExpressionNode() |
|
869 |
{ |
|
870 |
m_currentExpressionNodes.quickPop(1); |
|
871 |
} |
|
872 |
||
873 |
private ObjectStack m_prefixResolvers |
|
874 |
= new ObjectStack(RECURSIONLIMIT); |
|
875 |
||
876 |
/** |
|
877 |
* Get the current namespace context for the xpath. |
|
878 |
* |
|
879 |
* @return the current prefix resolver for resolving prefixes to |
|
880 |
* namespace URLs. |
|
881 |
*/ |
|
882 |
public final PrefixResolver getNamespaceContext() |
|
883 |
{ |
|
884 |
return (PrefixResolver) m_prefixResolvers.peek(); |
|
885 |
} |
|
886 |
||
887 |
/** |
|
888 |
* Get the current namespace context for the xpath. |
|
889 |
* |
|
890 |
* @param pr the prefix resolver to be used for resolving prefixes to |
|
891 |
* namespace URLs. |
|
892 |
*/ |
|
893 |
public final void setNamespaceContext(PrefixResolver pr) |
|
894 |
{ |
|
895 |
m_prefixResolvers.setTop(pr); |
|
896 |
} |
|
897 |
||
898 |
/** |
|
899 |
* Push a current namespace context for the xpath. |
|
900 |
* |
|
901 |
* @param pr the prefix resolver to be used for resolving prefixes to |
|
902 |
* namespace URLs. |
|
903 |
*/ |
|
904 |
public final void pushNamespaceContext(PrefixResolver pr) |
|
905 |
{ |
|
906 |
m_prefixResolvers.push(pr); |
|
907 |
} |
|
908 |
||
909 |
/** |
|
910 |
* Just increment the namespace contest stack, so that setNamespaceContext |
|
911 |
* can be used on the slot. |
|
912 |
*/ |
|
913 |
public final void pushNamespaceContextNull() |
|
914 |
{ |
|
915 |
m_prefixResolvers.push(null); |
|
916 |
} |
|
917 |
||
918 |
/** |
|
919 |
* Pop the current namespace context for the xpath. |
|
920 |
*/ |
|
921 |
public final void popNamespaceContext() |
|
922 |
{ |
|
923 |
m_prefixResolvers.pop(); |
|
924 |
} |
|
925 |
||
926 |
//========================================================== |
|
927 |
// SECTION: Current TreeWalker contexts (for internal use) |
|
928 |
//========================================================== |
|
929 |
||
930 |
/** |
|
931 |
* Stack of AxesIterators. |
|
932 |
*/ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
933 |
private Stack<SubContextList> m_axesIteratorStack = new Stack<>(); |
6 | 934 |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
935 |
public Stack<SubContextList> getAxesIteratorStackStacks() { return m_axesIteratorStack; } |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
936 |
public void setAxesIteratorStackStacks(Stack<SubContextList> s) { m_axesIteratorStack = s; } |
6 | 937 |
|
938 |
/** |
|
939 |
* Push a TreeWalker on the stack. |
|
940 |
* |
|
941 |
* @param iter A sub-context AxesWalker. |
|
942 |
* @xsl.usage internal |
|
943 |
*/ |
|
944 |
public final void pushSubContextList(SubContextList iter) |
|
945 |
{ |
|
946 |
m_axesIteratorStack.push(iter); |
|
947 |
} |
|
948 |
||
949 |
/** |
|
950 |
* Pop the last pushed axes iterator. |
|
951 |
* @xsl.usage internal |
|
952 |
*/ |
|
953 |
public final void popSubContextList() |
|
954 |
{ |
|
955 |
m_axesIteratorStack.pop(); |
|
956 |
} |
|
957 |
||
958 |
/** |
|
959 |
* Get the current axes iterator, or return null if none. |
|
960 |
* |
|
961 |
* @return the sub-context node list. |
|
962 |
* @xsl.usage internal |
|
963 |
*/ |
|
964 |
public SubContextList getSubContextList() |
|
965 |
{ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
966 |
return m_axesIteratorStack.isEmpty() ? null : m_axesIteratorStack.peek(); |
6 | 967 |
} |
968 |
||
969 |
/** |
|
970 |
* Get the <a href="http://www.w3.org/TR/xslt#dt-current-node-list">current node list</a> |
|
971 |
* as defined by the XSLT spec. |
|
972 |
* |
|
973 |
* @return the <a href="http://www.w3.org/TR/xslt#dt-current-node-list">current node list</a>. |
|
974 |
* @xsl.usage internal |
|
975 |
*/ |
|
976 |
||
977 |
public com.sun.org.apache.xpath.internal.axes.SubContextList getCurrentNodeList() |
|
978 |
{ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
979 |
return m_axesIteratorStack.isEmpty() ? null : m_axesIteratorStack.get(0); |
6 | 980 |
} |
981 |
//========================================================== |
|
982 |
// SECTION: Implementation of ExpressionContext interface |
|
983 |
//========================================================== |
|
984 |
||
985 |
/** |
|
986 |
* Get the current context node. |
|
987 |
* @return The current context node. |
|
988 |
*/ |
|
989 |
public final int getContextNode() |
|
990 |
{ |
|
991 |
return this.getCurrentNode(); |
|
992 |
} |
|
993 |
||
994 |
/** |
|
995 |
* Get the current context node list. |
|
996 |
* @return An iterator for the current context list, as |
|
997 |
* defined in XSLT. |
|
998 |
*/ |
|
999 |
public final DTMIterator getContextNodes() |
|
1000 |
{ |
|
1001 |
||
1002 |
try |
|
1003 |
{ |
|
1004 |
DTMIterator cnl = getContextNodeList(); |
|
1005 |
||
1006 |
if (null != cnl) |
|
1007 |
return cnl.cloneWithReset(); |
|
1008 |
else |
|
1009 |
return null; // for now... this might ought to be an empty iterator. |
|
1010 |
} |
|
1011 |
catch (CloneNotSupportedException cnse) |
|
1012 |
{ |
|
1013 |
return null; // error reporting? |
|
1014 |
} |
|
1015 |
} |
|
1016 |
||
1017 |
XPathExpressionContext expressionContext = new XPathExpressionContext(); |
|
1018 |
||
1019 |
/** |
|
1020 |
* The the expression context for extensions for this context. |
|
1021 |
* |
|
1022 |
* @return An object that implements the ExpressionContext. |
|
1023 |
*/ |
|
1024 |
public ExpressionContext getExpressionContext() |
|
1025 |
{ |
|
1026 |
return expressionContext; |
|
1027 |
} |
|
1028 |
||
1029 |
public class XPathExpressionContext implements ExpressionContext |
|
1030 |
{ |
|
1031 |
/** |
|
1032 |
* Return the XPathContext associated with this XPathExpressionContext. |
|
1033 |
* Extensions should use this judiciously and only when special processing |
|
1034 |
* requirements cannot be met another way. Consider requesting an enhancement |
|
1035 |
* to the ExpressionContext interface to avoid having to call this method. |
|
1036 |
* @return the XPathContext associated with this XPathExpressionContext. |
|
1037 |
*/ |
|
1038 |
public XPathContext getXPathContext() |
|
1039 |
{ |
|
1040 |
return XPathContext.this; |
|
1041 |
} |
|
1042 |
||
1043 |
/** |
|
1044 |
* Return the DTMManager object. Though XPathContext context extends |
|
1045 |
* the DTMManager, it really is a proxy for the real DTMManager. If a |
|
1046 |
* caller needs to make a lot of calls to the DTMManager, it is faster |
|
1047 |
* if it gets the real one from this function. |
|
1048 |
*/ |
|
1049 |
public DTMManager getDTMManager() |
|
1050 |
{ |
|
1051 |
return m_dtmManager; |
|
1052 |
} |
|
1053 |
||
1054 |
/** |
|
1055 |
* Get the current context node. |
|
1056 |
* @return The current context node. |
|
1057 |
*/ |
|
1058 |
public org.w3c.dom.Node getContextNode() |
|
1059 |
{ |
|
1060 |
int context = getCurrentNode(); |
|
1061 |
||
1062 |
return getDTM(context).getNode(context); |
|
1063 |
} |
|
1064 |
||
1065 |
/** |
|
1066 |
* Get the current context node list. |
|
1067 |
* @return An iterator for the current context list, as |
|
1068 |
* defined in XSLT. |
|
1069 |
*/ |
|
1070 |
public org.w3c.dom.traversal.NodeIterator getContextNodes() |
|
1071 |
{ |
|
1072 |
return new com.sun.org.apache.xml.internal.dtm.ref.DTMNodeIterator(getContextNodeList()); |
|
1073 |
} |
|
1074 |
||
1075 |
/** |
|
1076 |
* Get the error listener. |
|
1077 |
* @return The registered error listener. |
|
1078 |
*/ |
|
1079 |
public ErrorListener getErrorListener() |
|
1080 |
{ |
|
1081 |
return XPathContext.this.getErrorListener(); |
|
1082 |
} |
|
12458 | 1083 |
/** |
1084 |
* Return the state of the services mechanism feature. |
|
1085 |
*/ |
|
48577 | 1086 |
public boolean overrideDefaultParser() { |
1087 |
return m_overrideDefaultParser; |
|
12458 | 1088 |
} |
1089 |
||
1090 |
/** |
|
1091 |
* Set the state of the services mechanism feature. |
|
1092 |
*/ |
|
48577 | 1093 |
public void setOverrideDefaultParser(boolean flag) { |
1094 |
m_overrideDefaultParser = flag; |
|
12458 | 1095 |
} |
6 | 1096 |
|
1097 |
/** |
|
1098 |
* Get the value of a node as a number. |
|
1099 |
* @param n Node to be converted to a number. May be null. |
|
1100 |
* @return value of n as a number. |
|
1101 |
*/ |
|
1102 |
public double toNumber(org.w3c.dom.Node n) |
|
1103 |
{ |
|
1104 |
// %REVIEW% You can't get much uglier than this... |
|
1105 |
int nodeHandle = getDTMHandleFromNode(n); |
|
1106 |
DTM dtm = getDTM(nodeHandle); |
|
1107 |
XString xobj = (XString)dtm.getStringValue(nodeHandle); |
|
1108 |
return xobj.num(); |
|
1109 |
} |
|
1110 |
||
1111 |
/** |
|
1112 |
* Get the value of a node as a string. |
|
1113 |
* @param n Node to be converted to a string. May be null. |
|
1114 |
* @return value of n as a string, or an empty string if n is null. |
|
1115 |
*/ |
|
1116 |
public String toString(org.w3c.dom.Node n) |
|
1117 |
{ |
|
1118 |
// %REVIEW% You can't get much uglier than this... |
|
1119 |
int nodeHandle = getDTMHandleFromNode(n); |
|
1120 |
DTM dtm = getDTM(nodeHandle); |
|
1121 |
XMLString strVal = dtm.getStringValue(nodeHandle); |
|
1122 |
return strVal.toString(); |
|
1123 |
} |
|
1124 |
||
1125 |
/** |
|
1126 |
* Get a variable based on it's qualified name. |
|
1127 |
* @param qname The qualified name of the variable. |
|
1128 |
* @return The evaluated value of the variable. |
|
1129 |
* @throws javax.xml.transform.TransformerException |
|
1130 |
*/ |
|
1131 |
||
1132 |
public final XObject getVariableOrParam(com.sun.org.apache.xml.internal.utils.QName qname) |
|
1133 |
throws javax.xml.transform.TransformerException |
|
1134 |
{ |
|
1135 |
return m_variableStacks.getVariableOrParam(XPathContext.this, qname); |
|
1136 |
} |
|
1137 |
||
1138 |
} |
|
1139 |
||
1140 |
/** |
|
1141 |
* Get a DTM to be used as a container for a global Result Tree |
|
1142 |
* Fragment. This will always be an instance of (derived from? equivalent to?) |
|
1143 |
* SAX2DTM, since each RTF is constructed by temporarily redirecting our SAX |
|
1144 |
* output to it. It may be a single DTM containing for multiple fragments, |
|
1145 |
* if the implementation supports that. |
|
1146 |
* |
|
1147 |
* Note: The distinction between this method and getRTFDTM() is that the latter |
|
1148 |
* allocates space from the dynamic variable stack (m_rtfdtm_stack), which may |
|
1149 |
* be pruned away again as the templates which defined those variables are exited. |
|
1150 |
* Global variables may be bound late (see XUnresolvedVariable), and never want to |
|
1151 |
* be discarded, hence we need to allocate them separately and don't actually need |
|
1152 |
* a stack to track them. |
|
1153 |
* |
|
1154 |
* @return a non-null DTM reference. |
|
1155 |
*/ |
|
1156 |
public DTM getGlobalRTFDTM() |
|
1157 |
{ |
|
1158 |
// We probably should _NOT_ be applying whitespace filtering at this stage! |
|
1159 |
// |
|
1160 |
// Some magic has been applied in DTMManagerDefault to recognize this set of options |
|
1161 |
// and generate an instance of DTM which can contain multiple documents |
|
1162 |
// (SAX2RTFDTM). Perhaps not the optimal way of achieving that result, but |
|
1163 |
// I didn't want to change the manager API at this time, or expose |
|
1164 |
// too many dependencies on its internals. (Ideally, I'd like to move |
|
1165 |
// isTreeIncomplete all the way up to DTM, so we wouldn't need to explicitly |
|
1166 |
// specify the subclass here.) |
|
1167 |
||
1168 |
// If it doesn't exist, or if the one already existing is in the middle of |
|
1169 |
// being constructed, we need to obtain a new DTM to write into. I'm not sure |
|
1170 |
// the latter will ever arise, but I'd rather be just a bit paranoid.. |
|
1171 |
if( m_global_rtfdtm==null || m_global_rtfdtm.isTreeIncomplete() ) |
|
1172 |
{ |
|
1173 |
m_global_rtfdtm=(SAX2RTFDTM)m_dtmManager.getDTM(null,true,null,false,false); |
|
1174 |
} |
|
1175 |
return m_global_rtfdtm; |
|
1176 |
} |
|
1177 |
||
1178 |
||
1179 |
||
1180 |
||
1181 |
/** |
|
1182 |
* Get a DTM to be used as a container for a dynamic Result Tree |
|
1183 |
* Fragment. This will always be an instance of (derived from? equivalent to?) |
|
1184 |
* SAX2DTM, since each RTF is constructed by temporarily redirecting our SAX |
|
1185 |
* output to it. It may be a single DTM containing for multiple fragments, |
|
1186 |
* if the implementation supports that. |
|
1187 |
* |
|
1188 |
* @return a non-null DTM reference. |
|
1189 |
*/ |
|
1190 |
public DTM getRTFDTM() |
|
1191 |
{ |
|
1192 |
SAX2RTFDTM rtfdtm; |
|
1193 |
||
1194 |
// We probably should _NOT_ be applying whitespace filtering at this stage! |
|
1195 |
// |
|
1196 |
// Some magic has been applied in DTMManagerDefault to recognize this set of options |
|
1197 |
// and generate an instance of DTM which can contain multiple documents |
|
1198 |
// (SAX2RTFDTM). Perhaps not the optimal way of achieving that result, but |
|
1199 |
// I didn't want to change the manager API at this time, or expose |
|
1200 |
// too many dependencies on its internals. (Ideally, I'd like to move |
|
1201 |
// isTreeIncomplete all the way up to DTM, so we wouldn't need to explicitly |
|
1202 |
// specify the subclass here.) |
|
1203 |
||
1204 |
if(m_rtfdtm_stack==null) |
|
1205 |
{ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1206 |
m_rtfdtm_stack=new ArrayList<>(); |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1207 |
rtfdtm=(SAX2RTFDTM)m_dtmManager.getDTM(null,true,null,false,false); |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1208 |
m_rtfdtm_stack.add(rtfdtm); |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1209 |
++m_which_rtfdtm; |
6 | 1210 |
} |
1211 |
else if(m_which_rtfdtm<0) |
|
1212 |
{ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1213 |
rtfdtm=(SAX2RTFDTM)m_rtfdtm_stack.get(++m_which_rtfdtm); |
6 | 1214 |
} |
1215 |
else |
|
1216 |
{ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1217 |
rtfdtm=(SAX2RTFDTM)m_rtfdtm_stack.get(m_which_rtfdtm); |
6 | 1218 |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1219 |
// It might already be under construction -- the classic example would be |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1220 |
// an xsl:variable which uses xsl:call-template as part of its value. To |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1221 |
// handle this recursion, we have to start a new RTF DTM, pushing the old |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1222 |
// one onto a stack so we can return to it. This is not as uncommon a case |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1223 |
// as we might wish, unfortunately, as some folks insist on coding XSLT |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1224 |
// as if it were a procedural language... |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1225 |
if(rtfdtm.isTreeIncomplete()) |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1226 |
{ |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1227 |
if(++m_which_rtfdtm < m_rtfdtm_stack.size()) |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1228 |
rtfdtm=(SAX2RTFDTM)m_rtfdtm_stack.get(m_which_rtfdtm); |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1229 |
else |
6 | 1230 |
{ |
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1231 |
rtfdtm=(SAX2RTFDTM)m_dtmManager.getDTM(null,true,null,false,false); |
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1232 |
m_rtfdtm_stack.add(rtfdtm); |
6 | 1233 |
} |
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1234 |
} |
6 | 1235 |
} |
1236 |
||
1237 |
return rtfdtm; |
|
1238 |
} |
|
1239 |
||
1240 |
/** Push the RTFDTM's context mark, to allows discarding RTFs added after this |
|
1241 |
* point. (If it doesn't exist we don't push, since we might still be able to |
|
1242 |
* get away with not creating it. That requires that excessive pops be harmless.) |
|
1243 |
* */ |
|
1244 |
public void pushRTFContext() |
|
1245 |
{ |
|
1246 |
m_last_pushed_rtfdtm.push(m_which_rtfdtm); |
|
1247 |
if(null!=m_rtfdtm_stack) |
|
1248 |
((SAX2RTFDTM)(getRTFDTM())).pushRewindMark(); |
|
1249 |
} |
|
1250 |
||
1251 |
/** Pop the RTFDTM's context mark. This discards any RTFs added after the last |
|
1252 |
* mark was set. |
|
1253 |
* |
|
1254 |
* If there is no RTF DTM, there's nothing to pop so this |
|
1255 |
* becomes a no-op. If pushes were issued before this was called, we count on |
|
1256 |
* the fact that popRewindMark is defined such that overpopping just resets |
|
1257 |
* to empty. |
|
1258 |
* |
|
1259 |
* Complicating factor: We need to handle the case of popping back to a previous |
|
1260 |
* RTF DTM, if one of the weird produce-an-RTF-to-build-an-RTF cases arose. |
|
1261 |
* Basically: If pop says this DTM is now empty, then return to the previous |
|
1262 |
* if one exists, in whatever state we left it in. UGLY, but hopefully the |
|
1263 |
* situation which forces us to consider this will arise exceedingly rarely. |
|
1264 |
* */ |
|
1265 |
public void popRTFContext() |
|
1266 |
{ |
|
1267 |
int previous=m_last_pushed_rtfdtm.pop(); |
|
1268 |
if(null==m_rtfdtm_stack) |
|
1269 |
return; |
|
1270 |
||
1271 |
if(m_which_rtfdtm==previous) |
|
1272 |
{ |
|
1273 |
if(previous>=0) // guard against none-active |
|
1274 |
{ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1275 |
boolean isEmpty=((SAX2RTFDTM)(m_rtfdtm_stack.get(previous))).popRewindMark(); |
6 | 1276 |
} |
1277 |
} |
|
1278 |
else while(m_which_rtfdtm!=previous) |
|
1279 |
{ |
|
1280 |
// Empty each DTM before popping, so it's ready for reuse |
|
1281 |
// _DON'T_ pop the previous, since it's still open (which is why we |
|
1282 |
// stacked up more of these) and did not receive a mark. |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1283 |
boolean isEmpty=((SAX2RTFDTM)(m_rtfdtm_stack.get(m_which_rtfdtm))).popRewindMark(); |
6 | 1284 |
--m_which_rtfdtm; |
1285 |
} |
|
1286 |
} |
|
1287 |
||
1288 |
/** |
|
1289 |
* Gets DTMXRTreeFrag object if one has already been created. |
|
1290 |
* Creates new DTMXRTreeFrag object and adds to m_DTMXRTreeFrags HashMap, |
|
1291 |
* otherwise. |
|
1292 |
* @param dtmIdentity |
|
1293 |
* @return DTMXRTreeFrag |
|
1294 |
*/ |
|
1295 |
public DTMXRTreeFrag getDTMXRTreeFrag(int dtmIdentity){ |
|
1296 |
if(m_DTMXRTreeFrags == null){ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1297 |
m_DTMXRTreeFrags = new HashMap<>(); |
6 | 1298 |
} |
1299 |
||
45853
bfa06be36a17
8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents:
44797
diff
changeset
|
1300 |
if(m_DTMXRTreeFrags.containsKey(dtmIdentity)){ |
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1301 |
return m_DTMXRTreeFrags.get(dtmIdentity); |
6 | 1302 |
}else{ |
1303 |
final DTMXRTreeFrag frag = new DTMXRTreeFrag(dtmIdentity,this); |
|
45853
bfa06be36a17
8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents:
44797
diff
changeset
|
1304 |
m_DTMXRTreeFrags.put(dtmIdentity,frag); |
6 | 1305 |
return frag ; |
1306 |
} |
|
1307 |
} |
|
1308 |
||
1309 |
/** |
|
1310 |
* Cleans DTMXRTreeFrag objects by removing references |
|
1311 |
* to DTM and XPathContext objects. |
|
1312 |
*/ |
|
1313 |
private final void releaseDTMXRTreeFrags(){ |
|
1314 |
if(m_DTMXRTreeFrags == null){ |
|
1315 |
return; |
|
1316 |
} |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1317 |
final Iterator<DTMXRTreeFrag> iter = (m_DTMXRTreeFrags.values()).iterator(); |
6 | 1318 |
while(iter.hasNext()){ |
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
1319 |
DTMXRTreeFrag frag = iter.next(); |
6 | 1320 |
frag.destruct(); |
1321 |
iter.remove(); |
|
1322 |
} |
|
1323 |
m_DTMXRTreeFrags = null; |
|
1324 |
} |
|
1325 |
} |