/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: NodeTest.java,v 1.2.4.2 2005/09/15 00:21:14 jeffsuttor Exp $
*/
/**
* This is the basic node test class for both match patterns and location path
* steps.
* @xsl.usage advanced
*/
{
/**
* The namespace or local name for node tests with a wildcard.
* @see <a href="http://www.w3.org/TR/xpath#NT-NameTest">the XPath NameTest production.</a>
*/
/**
* The URL to pass to the Node#supports method, to see if the
* DOM has already been stripped of whitespace nodes.
*/
/**
* This attribute determines which node types are accepted.
* @serial
*/
protected int m_whatToShow;
/**
* Special bitmap for match patterns starting with a function.
* Make sure this does not conflict with {@link org.w3c.dom.traversal.NodeFilter}.
*/
/**
* This attribute determines which node types are accepted.
* These constants are defined in the {@link org.w3c.dom.traversal.NodeFilter}
* interface.
*
* @return bitset mainly defined in {@link org.w3c.dom.traversal.NodeFilter}.
*/
public int getWhatToShow()
{
return m_whatToShow;
}
/**
* This attribute determines which node types are accepted.
* These constants are defined in the {@link org.w3c.dom.traversal.NodeFilter}
* interface.
*
* @param what bitset mainly defined in {@link org.w3c.dom.traversal.NodeFilter}.
*/
{
m_whatToShow = what;
}
/**
* The namespace to be tested for, which may be null.
* @serial
*/
/**
* Return the namespace to be tested.
*
* @return The namespace to be tested for, or {@link #WILD}, or null.
*/
{
return m_namespace;
}
/**
* Set the namespace to be tested.
*
* @param ns The namespace to be tested for, or {@link #WILD}, or null.
*/
{
m_namespace = ns;
}
/**
* The local name to be tested for.
* @serial
*/
/**
* Return the local name to be tested.
*
* @return the local name to be tested, or {@link #WILD}, or an empty string.
*/
{
}
/**
* Set the local name to be tested.
*
* @param name the local name to be tested, or {@link #WILD}, or an empty string.
*/
{
}
/**
* Statically calculated score for this test. One of
* {@link #SCORE_NODETEST},
* {@link #SCORE_NONE},
* {@link #SCORE_NSWILD},
* {@link #SCORE_QNAME}, or
* {@link #SCORE_OTHER}.
* @serial
*/
/**
* The match score if the pattern consists of just a NodeTest.
* @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a>
*/
/**
* The match score if the pattern pattern has the form NCName:*.
* @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a>
*/
/**
* The match score if the pattern has the form
* of a QName optionally preceded by an @ character.
* @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a>
*/
/**
* The match score if the pattern consists of something
* other than just a NodeTest or just a qname.
* @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a>
*/
/**
* The match score if no match is made.
* @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a>
*/
/**
* Construct an NodeTest that tests for namespaces and node names.
*
*
* @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
* @param namespace The namespace to be tested.
* @param name The local name to be tested.
*/
{
}
/**
* Construct an NodeTest that doesn't test for node names.
*
*
* @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
*/
{
}
/**
* @see Expression#deepEquals(Expression)
*/
{
if(!isSameClass(expr))
return false;
{
return false;
return false;
}
return false;
{
if(null == m_namespace)
return false;
return false;
}
else if(null != m_namespace)
return false;
return false;
return false;
return true;
}
/**
* Null argument constructor.
*/
public NodeTest(){}
/**
* Initialize this node test by setting the whatToShow property, and
* calculating the score that this test will return if a test succeeds.
*
*
* @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
*/
{
calcScore();
}
/**
* 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.
*
*
* @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
* @param namespace The namespace to be tested.
* @param name The local name to be tested.
*/
{
calcScore();
}
/**
* True if this test has a null namespace and a local name of {@link #WILD}.
* @serial
*/
private boolean m_isTotallyWild;
/**
* Get the static score for this node test.
* @return Should be one of the SCORE_XXX constants.
*/
{
return m_score;
}
/**
* Set the static score for this node test.
* @param score Should be one of the SCORE_XXX constants.
*/
{
}
/**
* Static calc of match score.
*/
protected void calcScore()
{
else
}
/**
* Get the score that this test will return if a test succeeds.
*
*
* @return the score that this test will return if a test succeeds.
*/
public double getDefaultScore()
{
}
/**
* Tell what node type to test, if not DTMFilter.SHOW_ALL.
*
* @param whatToShow Bit set defined mainly by
* {@link com.sun.org.apache.xml.internal.dtm.DTMFilter}.
* @return the node type for the whatToShow. Since whatToShow can specify
* multiple types, it will return the first bit tested that is on,
* so the caller of this function should take care that this is
* the function they really want to call. If none of the known bits
* are set, this function will return zero.
*/
{
// %REVIEW% Is there a better way?
return DTM.ELEMENT_NODE;
return DTM.ATTRIBUTE_NODE;
return DTM.DOCUMENT_NODE;
return DTM.DOCUMENT_FRAGMENT_NODE;
return DTM.NAMESPACE_NODE;
return DTM.COMMENT_NODE;
return DTM.PROCESSING_INSTRUCTION_NODE;
return DTM.DOCUMENT_TYPE_NODE;
return DTM.ENTITY_NODE;
return DTM.ENTITY_REFERENCE_NODE;
return DTM.NOTATION_NODE;
return DTM.CDATA_SECTION_NODE;
return 0;
}
/**
* Do a diagnostics dump of a whatToShow bit set.
*
*
* @param whatToShow Bit set defined mainly by
* {@link com.sun.org.apache.xml.internal.dtm.DTMFilter}.
*/
{
v.addElement("SHOW_ATTRIBUTE");
v.addElement("SHOW_NAMESPACE");
v.addElement("SHOW_CDATA_SECTION");
v.addElement("SHOW_COMMENT");
v.addElement("SHOW_DOCUMENT");
v.addElement("SHOW_DOCUMENT_FRAGMENT");
v.addElement("SHOW_DOCUMENT_TYPE");
v.addElement("SHOW_ELEMENT");
v.addElement("SHOW_ENTITY");
v.addElement("SHOW_ENTITY_REFERENCE");
v.addElement("SHOW_NOTATION");
v.addElement("SHOW_PROCESSING_INSTRUCTION");
v.addElement("SHOW_TEXT");
int n = v.size();
for (int i = 0; i < n; i++)
{
if (i > 0)
}
if (0 == n)
}
/**
* 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.
*
* @param p part string from the node.
* @param t target string, which may be {@link #WILD}.
*
* @return true if the strings match according to the rules of this method.
*/
{
// boolean b = (p == t) || ((null != p) && ((t == WILD) || p.equals(t)));
// System.out.println("subPartMatch - p: "+p+", t: "+t+", result: "+b);
}
/**
* This is temporary to patch over Xerces issue with representing DOM
* namespaces as "".
*
* @param p part string from the node, which may represent the null namespace
* as null or as "".
* @param t target string, which may be {@link #WILD}.
*
* @return true if the strings match according to the rules of this method.
*/
{
return (p == t)
|| ((null != p)
&& ((p.length() > 0)
}
/**
* Tell what the test score is for the given node.
*
*
* @param xctxt XPath runtime context.
* @param context The node being tested.
*
* @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
{
return m_score;
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 :
// was:
// return (!xctxt.getDOMHelper().shouldStripSourceNode(context))
// ? m_score : SCORE_NONE;
return m_score;
? 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 :
{
}
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)
}
/**
* Tell what the test score is for the given node.
*
*
* @param xctxt XPath runtime context.
* @param context The node being tested.
*
* @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
{
return m_score;
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 :
// was:
// return (!xctxt.getDOMHelper().shouldStripSourceNode(context))
// ? m_score : SCORE_NONE;
return m_score;
? 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 :
{
}
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)
}
/**
* Test the current node to see if it matches the given node test.
*
* @param xctxt XPath runtime context.
*
* @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
{
}
/**
* Node tests by themselves do not need to fix up variables.
*/
{
// no-op
}
/**
* @see com.sun.org.apache.xpath.internal.XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
*/
{
assertion(false, "callVisitors should not be called for this object!!!");
}
}