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

📄 xpath.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  public XObject execute(          XPathContext xctxt, int contextNode, PrefixResolver namespaceContext)            throws javax.xml.transform.TransformerException  {    xctxt.pushNamespaceContext(namespaceContext);    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);    XObject xobj = null;    try    {      xobj = m_mainExp.execute(xctxt);    }    catch (TransformerException te)    {      te.setLocator(this.getLocator());      ErrorListener el = xctxt.getErrorListener();      if(null != el) // defensive, should never happen.      {        el.error(te);      }      else        throw te;    }    catch (Exception e)    {      while (e instanceof com.sun.org.apache.xml.internal.utils.WrappedRuntimeException)      {        e = ((com.sun.org.apache.xml.internal.utils.WrappedRuntimeException) e).getException();      }      // e.printStackTrace();      String msg = e.getMessage();            if (msg == null || msg.length() == 0) {           msg = XSLMessages.createXPATHMessage(               XPATHErrorResources.ER_XPATH_ERROR, null);           }        TransformerException te = new TransformerException(msg,              getLocator(), e);      ErrorListener el = xctxt.getErrorListener();      // te.printStackTrace();      if(null != el) // defensive, should never happen.      {        el.fatalError(te);      }      else        throw te;    }    finally    {      xctxt.popNamespaceContext();      xctxt.popCurrentNodeAndExpression();    }    return xobj;  }    /**   * Given an expression and a context, evaluate the XPath   * and return the result.   *    * @param xctxt The execution context.   * @param contextNode The node that "." expresses.   * @param namespaceContext The context in which namespaces in the   * XPath are supposed to be expanded.   *    * @throws TransformerException thrown if the active ProblemListener decides   * the error condition is severe enough to halt processing.   *   * @throws javax.xml.transform.TransformerException   * @xsl.usage experimental   */  public boolean bool(          XPathContext xctxt, int contextNode, PrefixResolver namespaceContext)            throws javax.xml.transform.TransformerException  {    xctxt.pushNamespaceContext(namespaceContext);    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);    try    {      return m_mainExp.bool(xctxt);    }    catch (TransformerException te)    {      te.setLocator(this.getLocator());      ErrorListener el = xctxt.getErrorListener();      if(null != el) // defensive, should never happen.      {        el.error(te);      }      else        throw te;    }    catch (Exception e)    {      while (e instanceof com.sun.org.apache.xml.internal.utils.WrappedRuntimeException)      {        e = ((com.sun.org.apache.xml.internal.utils.WrappedRuntimeException) e).getException();      }      // e.printStackTrace();      String msg = e.getMessage();            if (msg == null || msg.length() == 0) {           msg = XSLMessages.createXPATHMessage(               XPATHErrorResources.ER_XPATH_ERROR, null);           }                    TransformerException te = new TransformerException(msg,              getLocator(), e);      ErrorListener el = xctxt.getErrorListener();      // te.printStackTrace();      if(null != el) // defensive, should never happen.      {        el.fatalError(te);      }      else        throw te;    }    finally    {      xctxt.popNamespaceContext();      xctxt.popCurrentNodeAndExpression();    }    return false;  }  /** Set to true to get diagnostic messages about the result of    *  match pattern testing.  */  private static final boolean DEBUG_MATCHES = false;  /**   * Get the match score of the given node.   *   * @param xctxt XPath runtime context.   * @param context The current source tree context node.   *    * @return score, one of {@link #MATCH_SCORE_NODETEST},   * {@link #MATCH_SCORE_NONE}, {@link #MATCH_SCORE_OTHER},    * or {@link #MATCH_SCORE_QNAME}.   *   * @throws javax.xml.transform.TransformerException   */  public double getMatchScore(XPathContext xctxt, int context)          throws javax.xml.transform.TransformerException  {    xctxt.pushCurrentNode(context);    xctxt.pushCurrentExpressionNode(context);    try    {      XObject score = m_mainExp.execute(xctxt);      if (DEBUG_MATCHES)      {        DTM dtm = xctxt.getDTM(context);        System.out.println("score: " + score.num() + " for "                           + dtm.getNodeName(context) + " for xpath "                           + this.getPatternString());      }      return score.num();    }    finally    {      xctxt.popCurrentNode();      xctxt.popCurrentExpressionNode();    }    // return XPath.MATCH_SCORE_NONE;  }  /**   * Warn the user of an problem.   *   * @param xctxt The XPath runtime context.   * @param sourceNode Not used.   * @param msg An error msgkey that corresponds to one of the constants found    *            in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is    *            a key for a format string.   * @param args An array of arguments represented in the format string, which    *             may be null.   *   * @throws TransformerException if the current ErrorListoner determines to    *                              throw an exception.   */  public void warn(          XPathContext xctxt, int sourceNode, String msg, Object[] args)            throws javax.xml.transform.TransformerException  {    String fmsg = XSLMessages.createXPATHWarning(msg, args);    ErrorListener ehandler = xctxt.getErrorListener();    if (null != ehandler)    {      // TO DO: Need to get stylesheet Locator from here.      ehandler.warning(new TransformerException(fmsg, (SAXSourceLocator)xctxt.getSAXLocator()));    }  }  /**   * Tell the user of an assertion error, and probably throw an   * exception.   *   * @param b  If false, a runtime exception will be thrown.   * @param msg The assertion message, which should be informative.   *    * @throws RuntimeException if the b argument is false.   */  public void assertion(boolean b, String msg)  {    if (!b)    {      String fMsg = XSLMessages.createXPATHMessage(        XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,        new Object[]{ msg });      throw new RuntimeException(fMsg);    }  }  /**   * Tell the user of an error, and probably throw an   * exception.   *   * @param xctxt The XPath runtime context.   * @param sourceNode Not used.   * @param msg An error msgkey that corresponds to one of the constants found    *            in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is    *            a key for a format string.   * @param args An array of arguments represented in the format string, which    *             may be null.   *   * @throws TransformerException if the current ErrorListoner determines to    *                              throw an exception.   */  public void error(          XPathContext xctxt, int sourceNode, String msg, Object[] args)            throws javax.xml.transform.TransformerException  {    String fmsg = XSLMessages.createXPATHMessage(msg, args);    ErrorListener ehandler = xctxt.getErrorListener();    if (null != ehandler)    {      ehandler.fatalError(new TransformerException(fmsg,                              (SAXSourceLocator)xctxt.getSAXLocator()));    }    else    {      SourceLocator slocator = xctxt.getSAXLocator();      System.out.println(fmsg + "; file " + slocator.getSystemId()                         + "; line " + slocator.getLineNumber() + "; column "                         + slocator.getColumnNumber());    }  }    /**   * This will traverse the heararchy, calling the visitor for    * each member.  If the called visitor method returns    * false, the subtree should not be called.   *    * @param owner The owner of the visitor, where that path may be    *              rewritten if needed.   * @param visitor The visitor whose appropriate method will be called.   */  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)  {  	m_mainExp.callVisitors(this, visitor);  }  /**   * The match score if no match is made.   * @xsl.usage advanced   */  public static final double MATCH_SCORE_NONE = Double.NEGATIVE_INFINITY;  /**   * The match score if the pattern has the form   * of a QName optionally preceded by an @ character.   * @xsl.usage advanced   */  public static final double MATCH_SCORE_QNAME = 0.0;  /**   * The match score if the pattern pattern has the form NCName:*.   * @xsl.usage advanced   */  public static final double MATCH_SCORE_NSWILD = -0.25;  /**   * The match score if the pattern consists of just a NodeTest.   * @xsl.usage advanced   */  public static final double MATCH_SCORE_NODETEST = -0.5;  /**   * The match score if the pattern consists of something   * other than just a NodeTest or just a qname.   * @xsl.usage advanced   */  public static final double MATCH_SCORE_OTHER = 0.5;}

⌨️ 快捷键说明

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