1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xpath.patterns;
  58. import java.util.Vector;
  59. import javax.xml.transform.TransformerException;
  60. import org.apache.xml.dtm.DTM;
  61. import org.apache.xml.dtm.DTMFilter;
  62. import org.apache.xml.dtm.ref.ExpandedNameTable;
  63. import org.apache.xpath.Expression;
  64. import org.apache.xpath.ExpressionOwner;
  65. import org.apache.xpath.XPath;
  66. import org.apache.xpath.XPathContext;
  67. import org.apache.xpath.XPathVisitor;
  68. import org.apache.xpath.objects.XNumber;
  69. import org.apache.xpath.objects.XObject;
  70. /**
  71. * <meta name="usage" content="advanced"/>
  72. * This is the basic node test class for both match patterns and location path
  73. * steps.
  74. */
  75. public class NodeTest extends Expression
  76. {
  77. /**
  78. * The namespace or local name for node tests with a wildcard.
  79. * @see <a href="http://www.w3.org/TR/xpath#NT-NameTest">the XPath NameTest production.</a>
  80. */
  81. public static final String WILD = "*";
  82. /**
  83. * The URL to pass to the Node#supports method, to see if the
  84. * DOM has already been stripped of whitespace nodes.
  85. */
  86. public static final String SUPPORTS_PRE_STRIPPING =
  87. "http://xml.apache.org/xpath/features/whitespace-pre-stripping";
  88. /**
  89. * This attribute determines which node types are accepted.
  90. * @serial
  91. */
  92. protected int m_whatToShow;
  93. /**
  94. * Special bitmap for match patterns starting with a function.
  95. * Make sure this does not conflict with {@link org.w3c.dom.traversal.NodeFilter}.
  96. */
  97. public static final int SHOW_BYFUNCTION = 0x00010000;
  98. /**
  99. * This attribute determines which node types are accepted.
  100. * These constants are defined in the {@link org.w3c.dom.traversal.NodeFilter}
  101. * interface.
  102. *
  103. * @return bitset mainly defined in {@link org.w3c.dom.traversal.NodeFilter}.
  104. */
  105. public int getWhatToShow()
  106. {
  107. return m_whatToShow;
  108. }
  109. /**
  110. * This attribute determines which node types are accepted.
  111. * These constants are defined in the {@link org.w3c.dom.traversal.NodeFilter}
  112. * interface.
  113. *
  114. * @param what bitset mainly defined in {@link org.w3c.dom.traversal.NodeFilter}.
  115. */
  116. public void setWhatToShow(int what)
  117. {
  118. m_whatToShow = what;
  119. }
  120. /**
  121. * The namespace to be tested for, which may be null.
  122. * @serial
  123. */
  124. String m_namespace;
  125. /**
  126. * Return the namespace to be tested.
  127. *
  128. * @return The namespace to be tested for, or {@link #WILD}, or null.
  129. */
  130. public String getNamespace()
  131. {
  132. return m_namespace;
  133. }
  134. /**
  135. * Set the namespace to be tested.
  136. *
  137. * @param ns The namespace to be tested for, or {@link #WILD}, or null.
  138. */
  139. public void setNamespace(String ns)
  140. {
  141. m_namespace = ns;
  142. }
  143. /**
  144. * The local name to be tested for.
  145. * @serial
  146. */
  147. protected String m_name;
  148. /**
  149. * Return the local name to be tested.
  150. *
  151. * @return the local name to be tested, or {@link #WILD}, or an empty string.
  152. */
  153. public String getLocalName()
  154. {
  155. return (null == m_name) ? "" : m_name;
  156. }
  157. /**
  158. * Set the local name to be tested.
  159. *
  160. * @param name the local name to be tested, or {@link #WILD}, or an empty string.
  161. */
  162. public void setLocalName(String name)
  163. {
  164. m_name = name;
  165. }
  166. /**
  167. * Statically calculated score for this test. One of
  168. * {@link #SCORE_NODETEST},
  169. * {@link #SCORE_NONE},
  170. * {@link #SCORE_NSWILD},
  171. * {@link #SCORE_QNAME}, or
  172. * {@link #SCORE_OTHER}.
  173. * @serial
  174. */
  175. XNumber m_score;
  176. /**
  177. * The match score if the pattern consists of just a NodeTest.
  178. * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a>
  179. */
  180. public static final XNumber SCORE_NODETEST =
  181. new XNumber(XPath.MATCH_SCORE_NODETEST);
  182. /**
  183. * The match score if the pattern pattern has the form NCName:*.
  184. * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a>
  185. */
  186. public static final XNumber SCORE_NSWILD =
  187. new XNumber(XPath.MATCH_SCORE_NSWILD);
  188. /**
  189. * The match score if the pattern has the form
  190. * of a QName optionally preceded by an @ character.
  191. * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a>
  192. */
  193. public static final XNumber SCORE_QNAME =
  194. new XNumber(XPath.MATCH_SCORE_QNAME);
  195. /**
  196. * The match score if the pattern consists of something
  197. * other than just a NodeTest or just a qname.
  198. * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a>
  199. */
  200. public static final XNumber SCORE_OTHER =
  201. new XNumber(XPath.MATCH_SCORE_OTHER);
  202. /**
  203. * The match score if no match is made.
  204. * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a>
  205. */
  206. public static final XNumber SCORE_NONE =
  207. new XNumber(XPath.MATCH_SCORE_NONE);
  208. /**
  209. * Construct an NodeTest that tests for namespaces and node names.
  210. *
  211. *
  212. * @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
  213. * @param namespace The namespace to be tested.
  214. * @param name The local name to be tested.
  215. */
  216. public NodeTest(int whatToShow, String namespace, String name)
  217. {
  218. initNodeTest(whatToShow, namespace, name);
  219. }
  220. /**
  221. * Construct an NodeTest that doesn't test for node names.
  222. *
  223. *
  224. * @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
  225. */
  226. public NodeTest(int whatToShow)
  227. {
  228. initNodeTest(whatToShow);
  229. }
  230. /**
  231. * @see Expression#deepEquals(Expression)
  232. */
  233. public boolean deepEquals(Expression expr)
  234. {
  235. if(!isSameClass(expr))
  236. return false;
  237. NodeTest nt = (NodeTest)expr;
  238. if(null != nt.m_name)
  239. {
  240. if(null == m_name)
  241. return false;
  242. else if(!nt.m_name.equals(m_name))
  243. return false;
  244. }
  245. else if(null != m_name)
  246. return false;
  247. if(null != nt.m_namespace)
  248. {
  249. if(null == m_namespace)
  250. return false;
  251. else if(!nt.m_namespace.equals(m_namespace))
  252. return false;
  253. }
  254. else if(null != m_namespace)
  255. return false;
  256. if(m_whatToShow != nt.m_whatToShow)
  257. return false;
  258. if(m_isTotallyWild != nt.m_isTotallyWild)
  259. return false;
  260. return true;
  261. }
  262. /**
  263. * Null argument constructor.
  264. */
  265. public NodeTest(){}
  266. /**
  267. * Initialize this node test by setting the whatToShow property, and
  268. * calculating the score that this test will return if a test succeeds.
  269. *
  270. *
  271. * @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
  272. */
  273. public void initNodeTest(int whatToShow)
  274. {
  275. m_whatToShow = whatToShow;
  276. calcScore();
  277. }
  278. /**
  279. * Initialize this node test by setting the whatToShow property and the
  280. * namespace and local name, and
  281. * calculating the score that this test will return if a test succeeds.
  282. *
  283. *
  284. * @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
  285. * @param namespace The namespace to be tested.
  286. * @param name The local name to be tested.
  287. */
  288. public void initNodeTest(int whatToShow, String namespace, String name)
  289. {
  290. m_whatToShow = whatToShow;
  291. m_namespace = namespace;
  292. m_name = name;
  293. calcScore();
  294. }
  295. /**
  296. * True if this test has a null namespace and a local name of {@link #WILD}.
  297. * @serial
  298. */
  299. private boolean m_isTotallyWild;
  300. /**
  301. * Get the static score for this node test.
  302. * @return Should be one of the SCORE_XXX constants.
  303. */
  304. public XNumber getStaticScore()
  305. {
  306. return m_score;
  307. }
  308. /**
  309. * Set the static score for this node test.
  310. * @param score Should be one of the SCORE_XXX constants.
  311. */
  312. public void setStaticScore(XNumber score)
  313. {
  314. m_score = score;
  315. }
  316. /**
  317. * Static calc of match score.
  318. */
  319. protected void calcScore()
  320. {
  321. if ((m_namespace == null) && (m_name == null))
  322. m_score = SCORE_NODETEST;
  323. else if (((m_namespace == WILD) || (m_namespace == null))
  324. && (m_name == WILD))
  325. m_score = SCORE_NODETEST;
  326. else if ((m_namespace != WILD) && (m_name == WILD))
  327. m_score = SCORE_NSWILD;
  328. else
  329. m_score = SCORE_QNAME;
  330. m_isTotallyWild = (m_namespace == null && m_name == WILD);
  331. }
  332. /**
  333. * Get the score that this test will return if a test succeeds.
  334. *
  335. *
  336. * @return the score that this test will return if a test succeeds.
  337. */
  338. public double getDefaultScore()
  339. {
  340. return m_score.num();
  341. }
  342. /**
  343. * Tell what node type to test, if not DTMFilter.SHOW_ALL.
  344. *
  345. * @param whatToShow Bit set defined mainly by
  346. * {@link org.apache.xml.dtm.DTMFilter}.
  347. * @return the node type for the whatToShow. Since whatToShow can specify
  348. * multiple types, it will return the first bit tested that is on,
  349. * so the caller of this function should take care that this is
  350. * the function they really want to call. If none of the known bits
  351. * are set, this function will return zero.
  352. */
  353. public static int getNodeTypeTest(int whatToShow)
  354. {
  355. // %REVIEW% Is there a better way?
  356. if (0 != (whatToShow & DTMFilter.SHOW_ELEMENT))
  357. return DTM.ELEMENT_NODE;
  358. if (0 != (whatToShow & DTMFilter.SHOW_ATTRIBUTE))
  359. return DTM.ATTRIBUTE_NODE;
  360. if (0 != (whatToShow & DTMFilter.SHOW_TEXT))
  361. return DTM.TEXT_NODE;
  362. if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT))
  363. return DTM.DOCUMENT_NODE;
  364. if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT_FRAGMENT))
  365. return DTM.DOCUMENT_FRAGMENT_NODE;
  366. if (0 != (whatToShow & DTMFilter.SHOW_NAMESPACE))
  367. return DTM.NAMESPACE_NODE;
  368. if (0 != (whatToShow & DTMFilter.SHOW_COMMENT))
  369. return DTM.COMMENT_NODE;
  370. if (0 != (whatToShow & DTMFilter.SHOW_PROCESSING_INSTRUCTION))
  371. return DTM.PROCESSING_INSTRUCTION_NODE;
  372. if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT_TYPE))
  373. return DTM.DOCUMENT_TYPE_NODE;
  374. if (0 != (whatToShow & DTMFilter.SHOW_ENTITY))
  375. return DTM.ENTITY_NODE;
  376. if (0 != (whatToShow & DTMFilter.SHOW_ENTITY_REFERENCE))
  377. return DTM.ENTITY_REFERENCE_NODE;
  378. if (0 != (whatToShow & DTMFilter.SHOW_NOTATION))
  379. return DTM.NOTATION_NODE;
  380. if (0 != (whatToShow & DTMFilter.SHOW_CDATA_SECTION))
  381. return DTM.CDATA_SECTION_NODE;
  382. return 0;
  383. }
  384. /**
  385. * Do a diagnostics dump of a whatToShow bit set.
  386. *
  387. *
  388. * @param whatToShow Bit set defined mainly by
  389. * {@link org.apache.xml.dtm.DTMFilter}.
  390. */
  391. public static void debugWhatToShow(int whatToShow)
  392. {
  393. java.util.Vector v = new java.util.Vector();
  394. if (0 != (whatToShow & DTMFilter.SHOW_ATTRIBUTE))
  395. v.addElement("SHOW_ATTRIBUTE");
  396. if (0 != (whatToShow & DTMFilter.SHOW_NAMESPACE))
  397. v.addElement("SHOW_NAMESPACE");
  398. if (0 != (whatToShow & DTMFilter.SHOW_CDATA_SECTION))
  399. v.addElement("SHOW_CDATA_SECTION");
  400. if (0 != (whatToShow & DTMFilter.SHOW_COMMENT))
  401. v.addElement("SHOW_COMMENT");
  402. if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT))
  403. v.addElement("SHOW_DOCUMENT");
  404. if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT_FRAGMENT))
  405. v.addElement("SHOW_DOCUMENT_FRAGMENT");
  406. if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT_TYPE))
  407. v.addElement("SHOW_DOCUMENT_TYPE");
  408. if (0 != (whatToShow & DTMFilter.SHOW_ELEMENT))
  409. v.addElement("SHOW_ELEMENT");
  410. if (0 != (whatToShow & DTMFilter.SHOW_ENTITY))
  411. v.addElement("SHOW_ENTITY");
  412. if (0 != (whatToShow & DTMFilter.SHOW_ENTITY_REFERENCE))
  413. v.addElement("SHOW_ENTITY_REFERENCE");
  414. if (0 != (whatToShow & DTMFilter.SHOW_NOTATION))
  415. v.addElement("SHOW_NOTATION");
  416. if (0 != (whatToShow & DTMFilter.SHOW_PROCESSING_INSTRUCTION))
  417. v.addElement("SHOW_PROCESSING_INSTRUCTION");
  418. if (0 != (whatToShow & DTMFilter.SHOW_TEXT))
  419. v.addElement("SHOW_TEXT");
  420. int n = v.size();
  421. for (int i = 0; i < n; i++)
  422. {
  423. if (i > 0)
  424. System.out.print(" | ");
  425. System.out.print(v.elementAt(i));
  426. }
  427. if (0 == n)
  428. System.out.print("empty whatToShow: " + whatToShow);
  429. System.out.println();
  430. }
  431. /**
  432. * Two names are equal if they and either both are null or
  433. * the name t is wild and the name p is non-null, or the two
  434. * strings are equal.
  435. *
  436. * @param p part string from the node.
  437. * @param t target string, which may be {@link #WILD}.
  438. *
  439. * @return true if the strings match according to the rules of this method.
  440. */
  441. private static final boolean subPartMatch(String p, String t)
  442. {
  443. // boolean b = (p == t) || ((null != p) && ((t == WILD) || p.equals(t)));
  444. // System.out.println("subPartMatch - p: "+p+", t: "+t+", result: "+b);
  445. return (p == t) || ((null != p) && ((t == WILD) || p.equals(t)));
  446. }
  447. /**
  448. * This is temporary to patch over Xerces issue with representing DOM
  449. * namespaces as "".
  450. *
  451. * @param p part string from the node, which may represent the null namespace
  452. * as null or as "".
  453. * @param t target string, which may be {@link #WILD}.
  454. *
  455. * @return true if the strings match according to the rules of this method.
  456. */
  457. private static final boolean subPartMatchNS(String p, String t)
  458. {
  459. return (p == t)
  460. || ((null != p)
  461. && ((p.length() > 0)
  462. ? ((t == WILD) || p.equals(t)) : null == t));
  463. }
  464. /**
  465. * Tell what the test score is for the given node.
  466. *
  467. *
  468. * @param xctxt XPath runtime context.
  469. * @param context The node being tested.
  470. *
  471. * @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
  472. * {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
  473. * {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
  474. * {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
  475. * {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
  476. *
  477. * @throws javax.xml.transform.TransformerException
  478. */
  479. public XObject execute(XPathContext xctxt, int context)
  480. throws javax.xml.transform.TransformerException
  481. {
  482. DTM dtm = xctxt.getDTM(context);
  483. short nodeType = dtm.getNodeType(context);
  484. if (m_whatToShow == DTMFilter.SHOW_ALL)
  485. return m_score;
  486. int nodeBit = (m_whatToShow & (0x00000001 << (nodeType - 1)));
  487. switch (nodeBit)
  488. {
  489. case DTMFilter.SHOW_DOCUMENT_FRAGMENT :
  490. case DTMFilter.SHOW_DOCUMENT :
  491. return SCORE_OTHER;
  492. case DTMFilter.SHOW_COMMENT :
  493. return m_score;
  494. case DTMFilter.SHOW_CDATA_SECTION :
  495. case DTMFilter.SHOW_TEXT :
  496. // was:
  497. // return (!xctxt.getDOMHelper().shouldStripSourceNode(context))
  498. // ? m_score : SCORE_NONE;
  499. return m_score;
  500. case DTMFilter.SHOW_PROCESSING_INSTRUCTION :
  501. return subPartMatch(dtm.getNodeName(context), m_name)
  502. ? m_score : SCORE_NONE;
  503. // From the draft: "Two expanded names are equal if they
  504. // have the same local part, and either both have no URI or
  505. // both have the same URI."
  506. // "A node test * is true for any node of the principal node type.
  507. // For example, child::* will select all element children of the
  508. // context node, and attribute::* will select all attributes of
  509. // the context node."
  510. // "A node test can have the form NCName:*. In this case, the prefix
  511. // is expanded in the same way as with a QName using the context
  512. // namespace declarations. The node test will be true for any node
  513. // of the principal type whose expanded name has the URI to which
  514. // the prefix expands, regardless of the local part of the name."
  515. case DTMFilter.SHOW_NAMESPACE :
  516. {
  517. String ns = dtm.getNodeValue(context);
  518. return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
  519. }
  520. case DTMFilter.SHOW_ATTRIBUTE :
  521. case DTMFilter.SHOW_ELEMENT :
  522. {
  523. return (m_isTotallyWild || (subPartMatchNS(dtm.getNamespaceURI(context), m_namespace) && subPartMatch(dtm.getLocalName(context), m_name)))
  524. ? m_score : SCORE_NONE;
  525. }
  526. default :
  527. return SCORE_NONE;
  528. } // end switch(testType)
  529. }
  530. /**
  531. * Tell what the test score is for the given node.
  532. *
  533. *
  534. * @param xctxt XPath runtime context.
  535. * @param context The node being tested.
  536. *
  537. * @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
  538. * {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
  539. * {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
  540. * {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
  541. * {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
  542. *
  543. * @throws javax.xml.transform.TransformerException
  544. */
  545. public XObject execute(XPathContext xctxt, int context,
  546. DTM dtm, int expType)
  547. throws javax.xml.transform.TransformerException
  548. {
  549. if (m_whatToShow == DTMFilter.SHOW_ALL)
  550. return m_score;
  551. int nodeBit = (m_whatToShow & (0x00000001
  552. << ((dtm.getNodeType(context)) - 1)));
  553. switch (nodeBit)
  554. {
  555. case DTMFilter.SHOW_DOCUMENT_FRAGMENT :
  556. case DTMFilter.SHOW_DOCUMENT :
  557. return SCORE_OTHER;
  558. case DTMFilter.SHOW_COMMENT :
  559. return m_score;
  560. case DTMFilter.SHOW_CDATA_SECTION :
  561. case DTMFilter.SHOW_TEXT :
  562. // was:
  563. // return (!xctxt.getDOMHelper().shouldStripSourceNode(context))
  564. // ? m_score : SCORE_NONE;
  565. return m_score;
  566. case DTMFilter.SHOW_PROCESSING_INSTRUCTION :
  567. return subPartMatch(dtm.getNodeName(context), m_name)
  568. ? m_score : SCORE_NONE;
  569. // From the draft: "Two expanded names are equal if they
  570. // have the same local part, and either both have no URI or
  571. // both have the same URI."
  572. // "A node test * is true for any node of the principal node type.
  573. // For example, child::* will select all element children of the
  574. // context node, and attribute::* will select all attributes of
  575. // the context node."
  576. // "A node test can have the form NCName:*. In this case, the prefix
  577. // is expanded in the same way as with a QName using the context
  578. // namespace declarations. The node test will be true for any node
  579. // of the principal type whose expanded name has the URI to which
  580. // the prefix expands, regardless of the local part of the name."
  581. case DTMFilter.SHOW_NAMESPACE :
  582. {
  583. String ns = dtm.getNodeValue(context);
  584. return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
  585. }
  586. case DTMFilter.SHOW_ATTRIBUTE :
  587. case DTMFilter.SHOW_ELEMENT :
  588. {
  589. return (m_isTotallyWild || (subPartMatchNS(dtm.getNamespaceURI(context), m_namespace) && subPartMatch(dtm.getLocalName(context), m_name)))
  590. ? m_score : SCORE_NONE;
  591. }
  592. default :
  593. return SCORE_NONE;
  594. } // end switch(testType)
  595. }
  596. /**
  597. * Test the current node to see if it matches the given node test.
  598. *
  599. * @param xctxt XPath runtime context.
  600. *
  601. * @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
  602. * {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
  603. * {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
  604. * {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
  605. * {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
  606. *
  607. * @throws javax.xml.transform.TransformerException
  608. */
  609. public XObject execute(XPathContext xctxt)
  610. throws javax.xml.transform.TransformerException
  611. {
  612. return execute(xctxt, xctxt.getCurrentNode());
  613. }
  614. /**
  615. * Node tests by themselves do not need to fix up variables.
  616. */
  617. public void fixupVariables(java.util.Vector vars, int globalsSize)
  618. {
  619. // no-op
  620. }
  621. /**
  622. * @see XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
  623. */
  624. public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
  625. {
  626. assertion(false, "callVisitors should not be called for this object!!!");
  627. }
  628. }