⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nodetest.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   * 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.   */  public static int getNodeTypeTest(int whatToShow)  {    // %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;  }  /**   * 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}.   */  public static void debugWhatToShow(int whatToShow)  {    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();  }  /**   * 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.   */  private static final boolean subPartMatch(String p, String t)  {    // 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)));  }  /**   * 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.   */  private static final boolean subPartMatchNS(String p, String t)  {    return (p == t)           || ((null != p)               && ((p.length() > 0)                   ? ((t == WILD) || p.equals(t)) : null == t));  }  /**   * 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   */  public XObject execute(XPathContext xctxt, int context)          throws javax.xml.transform.TransformerException  {    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)  }    /**   * 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   */  public XObject execute(XPathContext xctxt, int context,                          DTM dtm, int expType)          throws javax.xml.transform.TransformerException  {    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)  }  /**   * 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   */  public XObject execute(XPathContext xctxt)          throws javax.xml.transform.TransformerException  {    return execute(xctxt, xctxt.getCurrentNode());  }    /**   * Node tests by themselves do not need to fix up variables.   */  public void fixupVariables(java.util.Vector vars, int globalsSize)  {    // no-op  }  /**   * @see com.sun.org.apache.xpath.internal.XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)   */  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)  {  	assertion(false, "callVisitors should not be called for this object!!!");  	  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -