Fields Summary |
---|
static final long | serialVersionUID |
public static final String | WILDThe namespace or local name for node tests with a wildcard. |
public static final String | SUPPORTS_PRE_STRIPPINGThe URL to pass to the Node#supports method, to see if the
DOM has already been stripped of whitespace nodes. |
protected int | m_whatToShowThis attribute determines which node types are accepted. |
public static final int | SHOW_BYFUNCTIONSpecial bitmap for match patterns starting with a function.
Make sure this does not conflict with {@link org.w3c.dom.traversal.NodeFilter}. |
String | m_namespaceThe namespace to be tested for, which may be null. |
protected String | m_nameThe local name to be tested for. |
XNumber | m_scoreStatically calculated score for this test. One of
{@link #SCORE_NODETEST},
{@link #SCORE_NONE},
{@link #SCORE_NSWILD},
{@link #SCORE_QNAME}, or
{@link #SCORE_OTHER}. |
public static final XNumber | SCORE_NODETESTThe match score if the pattern consists of just a NodeTest. |
public static final XNumber | SCORE_NSWILDThe match score if the pattern pattern has the form NCName:*. |
public static final XNumber | SCORE_QNAMEThe match score if the pattern has the form
of a QName optionally preceded by an @ character. |
public static final XNumber | SCORE_OTHERThe match score if the pattern consists of something
other than just a NodeTest or just a qname. |
public static final XNumber | SCORE_NONEThe match score if no match is made. |
private boolean | m_isTotallyWildTrue if this test has a null namespace and a local name of {@link #WILD}. |
Methods Summary |
---|
protected void | calcScore()Static calc of match score.
if ((m_namespace == null) && (m_name == null))
m_score = SCORE_NODETEST;
else if (((m_namespace == WILD) || (m_namespace == null))
&& (m_name == WILD))
m_score = SCORE_NODETEST;
else if ((m_namespace != WILD) && (m_name == WILD))
m_score = SCORE_NSWILD;
else
m_score = SCORE_QNAME;
m_isTotallyWild = (m_namespace == null && m_name == WILD);
|
public void | callVisitors(com.sun.org.apache.xpath.internal.ExpressionOwner owner, com.sun.org.apache.xpath.internal.XPathVisitor visitor)
assertion(false, "callVisitors should not be called for this object!!!");
|
public static void | debugWhatToShow(int whatToShow)Do a diagnostics dump of a whatToShow bit set.
java.util.Vector v = new java.util.Vector();
if (0 != (whatToShow & DTMFilter.SHOW_ATTRIBUTE))
v.addElement("SHOW_ATTRIBUTE");
if (0 != (whatToShow & DTMFilter.SHOW_NAMESPACE))
v.addElement("SHOW_NAMESPACE");
if (0 != (whatToShow & DTMFilter.SHOW_CDATA_SECTION))
v.addElement("SHOW_CDATA_SECTION");
if (0 != (whatToShow & DTMFilter.SHOW_COMMENT))
v.addElement("SHOW_COMMENT");
if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT))
v.addElement("SHOW_DOCUMENT");
if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT_FRAGMENT))
v.addElement("SHOW_DOCUMENT_FRAGMENT");
if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT_TYPE))
v.addElement("SHOW_DOCUMENT_TYPE");
if (0 != (whatToShow & DTMFilter.SHOW_ELEMENT))
v.addElement("SHOW_ELEMENT");
if (0 != (whatToShow & DTMFilter.SHOW_ENTITY))
v.addElement("SHOW_ENTITY");
if (0 != (whatToShow & DTMFilter.SHOW_ENTITY_REFERENCE))
v.addElement("SHOW_ENTITY_REFERENCE");
if (0 != (whatToShow & DTMFilter.SHOW_NOTATION))
v.addElement("SHOW_NOTATION");
if (0 != (whatToShow & DTMFilter.SHOW_PROCESSING_INSTRUCTION))
v.addElement("SHOW_PROCESSING_INSTRUCTION");
if (0 != (whatToShow & DTMFilter.SHOW_TEXT))
v.addElement("SHOW_TEXT");
int n = v.size();
for (int i = 0; i < n; i++)
{
if (i > 0)
System.out.print(" | ");
System.out.print(v.elementAt(i));
}
if (0 == n)
System.out.print("empty whatToShow: " + whatToShow);
System.out.println();
|
public boolean | deepEquals(com.sun.org.apache.xpath.internal.Expression expr)
if(!isSameClass(expr))
return false;
NodeTest nt = (NodeTest)expr;
if(null != nt.m_name)
{
if(null == m_name)
return false;
else if(!nt.m_name.equals(m_name))
return false;
}
else if(null != m_name)
return false;
if(null != nt.m_namespace)
{
if(null == m_namespace)
return false;
else if(!nt.m_namespace.equals(m_namespace))
return false;
}
else if(null != m_namespace)
return false;
if(m_whatToShow != nt.m_whatToShow)
return false;
if(m_isTotallyWild != nt.m_isTotallyWild)
return false;
return true;
|
public com.sun.org.apache.xpath.internal.objects.XObject | execute(com.sun.org.apache.xpath.internal.XPathContext xctxt, int context)Tell what the test score is for the given node.
DTM dtm = xctxt.getDTM(context);
short nodeType = dtm.getNodeType(context);
if (m_whatToShow == DTMFilter.SHOW_ALL)
return m_score;
int nodeBit = (m_whatToShow & (0x00000001 << (nodeType - 1)));
switch (nodeBit)
{
case DTMFilter.SHOW_DOCUMENT_FRAGMENT :
case DTMFilter.SHOW_DOCUMENT :
return SCORE_OTHER;
case DTMFilter.SHOW_COMMENT :
return m_score;
case DTMFilter.SHOW_CDATA_SECTION :
case DTMFilter.SHOW_TEXT :
// was:
// return (!xctxt.getDOMHelper().shouldStripSourceNode(context))
// ? m_score : SCORE_NONE;
return m_score;
case DTMFilter.SHOW_PROCESSING_INSTRUCTION :
return subPartMatch(dtm.getNodeName(context), m_name)
? m_score : SCORE_NONE;
// From the draft: "Two expanded names are equal if they
// have the same local part, and either both have no URI or
// both have the same URI."
// "A node test * is true for any node of the principal node type.
// For example, child::* will select all element children of the
// context node, and attribute::* will select all attributes of
// the context node."
// "A node test can have the form NCName:*. In this case, the prefix
// is expanded in the same way as with a QName using the context
// namespace declarations. The node test will be true for any node
// of the principal type whose expanded name has the URI to which
// the prefix expands, regardless of the local part of the name."
case DTMFilter.SHOW_NAMESPACE :
{
String ns = dtm.getLocalName(context);
return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
}
case DTMFilter.SHOW_ATTRIBUTE :
case DTMFilter.SHOW_ELEMENT :
{
return (m_isTotallyWild || (subPartMatchNS(dtm.getNamespaceURI(context), m_namespace) && subPartMatch(dtm.getLocalName(context), m_name)))
? m_score : SCORE_NONE;
}
default :
return SCORE_NONE;
} // end switch(testType)
|
public com.sun.org.apache.xpath.internal.objects.XObject | execute(com.sun.org.apache.xpath.internal.XPathContext xctxt, int context, com.sun.org.apache.xml.internal.dtm.DTM dtm, int expType)Tell what the test score is for the given node.
if (m_whatToShow == DTMFilter.SHOW_ALL)
return m_score;
int nodeBit = (m_whatToShow & (0x00000001
<< ((dtm.getNodeType(context)) - 1)));
switch (nodeBit)
{
case DTMFilter.SHOW_DOCUMENT_FRAGMENT :
case DTMFilter.SHOW_DOCUMENT :
return SCORE_OTHER;
case DTMFilter.SHOW_COMMENT :
return m_score;
case DTMFilter.SHOW_CDATA_SECTION :
case DTMFilter.SHOW_TEXT :
// was:
// return (!xctxt.getDOMHelper().shouldStripSourceNode(context))
// ? m_score : SCORE_NONE;
return m_score;
case DTMFilter.SHOW_PROCESSING_INSTRUCTION :
return subPartMatch(dtm.getNodeName(context), m_name)
? m_score : SCORE_NONE;
// From the draft: "Two expanded names are equal if they
// have the same local part, and either both have no URI or
// both have the same URI."
// "A node test * is true for any node of the principal node type.
// For example, child::* will select all element children of the
// context node, and attribute::* will select all attributes of
// the context node."
// "A node test can have the form NCName:*. In this case, the prefix
// is expanded in the same way as with a QName using the context
// namespace declarations. The node test will be true for any node
// of the principal type whose expanded name has the URI to which
// the prefix expands, regardless of the local part of the name."
case DTMFilter.SHOW_NAMESPACE :
{
String ns = dtm.getLocalName(context);
return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
}
case DTMFilter.SHOW_ATTRIBUTE :
case DTMFilter.SHOW_ELEMENT :
{
return (m_isTotallyWild || (subPartMatchNS(dtm.getNamespaceURI(context), m_namespace) && subPartMatch(dtm.getLocalName(context), m_name)))
? m_score : SCORE_NONE;
}
default :
return SCORE_NONE;
} // end switch(testType)
|
public com.sun.org.apache.xpath.internal.objects.XObject | execute(com.sun.org.apache.xpath.internal.XPathContext xctxt)Test the current node to see if it matches the given node test.
return execute(xctxt, xctxt.getCurrentNode());
|
public void | fixupVariables(java.util.Vector vars, int globalsSize)Node tests by themselves do not need to fix up variables.
// no-op
|
public double | getDefaultScore()Get the score that this test will return if a test succeeds.
return m_score.num();
|
public java.lang.String | getLocalName()Return the local name to be tested.
return (null == m_name) ? "" : m_name;
|
public java.lang.String | getNamespace()Return the namespace to be tested.
return m_namespace;
|
public static int | getNodeTypeTest(int whatToShow)Tell what node type to test, if not DTMFilter.SHOW_ALL.
// %REVIEW% Is there a better way?
if (0 != (whatToShow & DTMFilter.SHOW_ELEMENT))
return DTM.ELEMENT_NODE;
if (0 != (whatToShow & DTMFilter.SHOW_ATTRIBUTE))
return DTM.ATTRIBUTE_NODE;
if (0 != (whatToShow & DTMFilter.SHOW_TEXT))
return DTM.TEXT_NODE;
if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT))
return DTM.DOCUMENT_NODE;
if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT_FRAGMENT))
return DTM.DOCUMENT_FRAGMENT_NODE;
if (0 != (whatToShow & DTMFilter.SHOW_NAMESPACE))
return DTM.NAMESPACE_NODE;
if (0 != (whatToShow & DTMFilter.SHOW_COMMENT))
return DTM.COMMENT_NODE;
if (0 != (whatToShow & DTMFilter.SHOW_PROCESSING_INSTRUCTION))
return DTM.PROCESSING_INSTRUCTION_NODE;
if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT_TYPE))
return DTM.DOCUMENT_TYPE_NODE;
if (0 != (whatToShow & DTMFilter.SHOW_ENTITY))
return DTM.ENTITY_NODE;
if (0 != (whatToShow & DTMFilter.SHOW_ENTITY_REFERENCE))
return DTM.ENTITY_REFERENCE_NODE;
if (0 != (whatToShow & DTMFilter.SHOW_NOTATION))
return DTM.NOTATION_NODE;
if (0 != (whatToShow & DTMFilter.SHOW_CDATA_SECTION))
return DTM.CDATA_SECTION_NODE;
return 0;
|
public com.sun.org.apache.xpath.internal.objects.XNumber | getStaticScore()Get the static score for this node test.
return m_score;
|
public int | getWhatToShow()This attribute determines which node types are accepted.
These constants are defined in the {@link org.w3c.dom.traversal.NodeFilter}
interface.
return m_whatToShow;
|
public void | initNodeTest(int whatToShow)Initialize this node test by setting the whatToShow property, and
calculating the score that this test will return if a test succeeds.
m_whatToShow = whatToShow;
calcScore();
|
public void | initNodeTest(int whatToShow, java.lang.String namespace, java.lang.String name)Initialize this node test by setting the whatToShow property and the
namespace and local name, and
calculating the score that this test will return if a test succeeds.
m_whatToShow = whatToShow;
m_namespace = namespace;
m_name = name;
calcScore();
|
public void | setLocalName(java.lang.String name)Set the local name to be tested.
m_name = name;
|
public void | setNamespace(java.lang.String ns)Set the namespace to be tested.
m_namespace = ns;
|
public void | setStaticScore(com.sun.org.apache.xpath.internal.objects.XNumber score)Set the static score for this node test.
m_score = score;
|
public void | setWhatToShow(int what)This attribute determines which node types are accepted.
These constants are defined in the {@link org.w3c.dom.traversal.NodeFilter}
interface.
m_whatToShow = what;
|
private static final boolean | subPartMatch(java.lang.String p, java.lang.String t)Two names are equal if they and either both are null or
the name t is wild and the name p is non-null, or the two
strings are equal.
// boolean b = (p == t) || ((null != p) && ((t == WILD) || p.equals(t)));
// System.out.println("subPartMatch - p: "+p+", t: "+t+", result: "+b);
return (p == t) || ((null != p) && ((t == WILD) || p.equals(t)));
|
private static final boolean | subPartMatchNS(java.lang.String p, java.lang.String t)This is temporary to patch over Xerces issue with representing DOM
namespaces as "".
return (p == t)
|| ((null != p)
&& ((p.length() > 0)
? ((t == WILD) || p.equals(t)) : null == t));
|