当前位置: 首页>>代码示例>>Java>>正文


Java XPath.getMatchScore方法代码示例

本文整理汇总了Java中org.apache.xpath.XPath.getMatchScore方法的典型用法代码示例。如果您正苦于以下问题:Java XPath.getMatchScore方法的具体用法?Java XPath.getMatchScore怎么用?Java XPath.getMatchScore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.xpath.XPath的用法示例。


在下文中一共展示了XPath.getMatchScore方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findAncestor

import org.apache.xpath.XPath; //导入方法依赖的package包/类
/**
 * Given a 'from' pattern (ala xsl:number), a match pattern
 * and a context, find the first ancestor that matches the
 * pattern (including the context handed in).
 *
 * @param xctxt The XPath runtime state for this.
 * @param fromMatchPattern The ancestor must match this pattern.
 * @param countMatchPattern The ancestor must also match this pattern.
 * @param context The node that "." expresses.
 * @param namespaceContext The context in which namespaces in the
 * queries are supposed to be expanded.
 *
 * @return the first ancestor that matches the given pattern
 *
 * @throws javax.xml.transform.TransformerException
 */
int findAncestor(
        XPathContext xctxt, XPath fromMatchPattern, XPath countMatchPattern, 
        int context, ElemNumber namespaceContext)
          throws javax.xml.transform.TransformerException
{
  DTM dtm = xctxt.getDTM(context);
  while (DTM.NULL != context)
  {
    if (null != fromMatchPattern)
    {
      if (fromMatchPattern.getMatchScore(xctxt, context)
              != XPath.MATCH_SCORE_NONE)
      {

        //context = null;
        break;
      }
    }

    if (null != countMatchPattern)
    {
      if (countMatchPattern.getMatchScore(xctxt, context)
              != XPath.MATCH_SCORE_NONE)
      {
        break;
      }
    }

    context = dtm.getParent(context);
  }

  return context;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:50,代码来源:ElemNumber.java

示例2: findPrecedingOrAncestorOrSelf

import org.apache.xpath.XPath; //导入方法依赖的package包/类
/**
 * Given a 'from' pattern (ala xsl:number), a match pattern
 * and a context, find the first ancestor that matches the
 * pattern (including the context handed in).
 * @param xctxt The XPath runtime state for this.
 * @param fromMatchPattern The ancestor must match this pattern.
 * @param countMatchPattern The ancestor must also match this pattern.
 * @param context The node that "." expresses.
 * @param namespaceContext The context in which namespaces in the
 * queries are supposed to be expanded.
 *
 * @return the first preceding, ancestor or self node that 
 * matches the given pattern
 *
 * @throws javax.xml.transform.TransformerException
 */
private int findPrecedingOrAncestorOrSelf(
        XPathContext xctxt, XPath fromMatchPattern, XPath countMatchPattern, 
        int context, ElemNumber namespaceContext)
          throws javax.xml.transform.TransformerException
{
  DTM dtm = xctxt.getDTM(context);
  while (DTM.NULL != context)
  {
    if (null != fromMatchPattern)
    {
      if (fromMatchPattern.getMatchScore(xctxt, context)
              != XPath.MATCH_SCORE_NONE)
      {
        context = DTM.NULL;

        break;
      }
    }

    if (null != countMatchPattern)
    {
      if (countMatchPattern.getMatchScore(xctxt, context)
              != XPath.MATCH_SCORE_NONE)
      {
        break;
      }
    }

    int prevSibling = dtm.getPreviousSibling(context);

    if (DTM.NULL == prevSibling)
    {
      context = dtm.getParent(context);
    }
    else
    {

      // Now go down the chain of children of this sibling 
      context = dtm.getLastChild(prevSibling);

      if (context == DTM.NULL)
        context = prevSibling;
    }
  }

  return context;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:64,代码来源:ElemNumber.java

示例3: getMatchingAncestors

import org.apache.xpath.XPath; //导入方法依赖的package包/类
/**
 * Get the ancestors, up to the root, that match the
 * pattern.
 * 
 * @param xctxt The XPath runtime state for this.
 * @param node Count this node and it's ancestors.
 * @param stopAtFirstFound Flag indicating to stop after the
 * first node is found (difference between level = single
 * or multiple)
 * @return The number of ancestors that match the pattern.
 *
 * @throws javax.xml.transform.TransformerException
 */
NodeVector getMatchingAncestors(
        XPathContext xctxt, int node, boolean stopAtFirstFound)
          throws javax.xml.transform.TransformerException
{

  NodeSetDTM ancestors = new NodeSetDTM(xctxt.getDTMManager());
  XPath countMatchPattern = getCountMatchPattern(xctxt, node);
  DTM dtm = xctxt.getDTM(node);

  while (DTM.NULL != node)
  {
    if ((null != m_fromMatchPattern)
            && (m_fromMatchPattern.getMatchScore(xctxt, node)
                != XPath.MATCH_SCORE_NONE))
    {

      // The following if statement gives level="single" different 
      // behavior from level="multiple", which seems incorrect according 
      // to the XSLT spec.  For now we are leaving this in to replicate 
      // the same behavior in XT, but, for all intents and purposes we 
      // think this is a bug, or there is something about level="single" 
      // that we still don't understand.
      if (!stopAtFirstFound)
        break;
    }

    if (null == countMatchPattern)
      System.out.println(
        "Programmers error! countMatchPattern should never be null!");

    if (countMatchPattern.getMatchScore(xctxt, node)
            != XPath.MATCH_SCORE_NONE)
    {
      ancestors.addElement(node);

      if (stopAtFirstFound)
        break;
    }

    node = dtm.getParent(node);
  }

  return ancestors;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:58,代码来源:ElemNumber.java

示例4: acceptNode

import org.apache.xpath.XPath; //导入方法依赖的package包/类
/**
 *  Test whether a specified node is visible in the logical view of a
 * TreeWalker or NodeIterator. This function will be called by the
 * implementation of TreeWalker and NodeIterator; it is not intended to
 * be called directly from user code.
 * 
 * @param testNode  The node to check to see if it passes the filter or not.
 *
 * @return  a constant to determine whether the node is accepted,
 *   rejected, or skipped, as defined  above .
 */
public short acceptNode(int testNode)
{
  boolean foundKey = false;
  KeyIterator ki = (KeyIterator) m_lpi;
  org.apache.xpath.XPathContext xctxt = ki.getXPathContext();
  Vector keys = ki.getKeyDeclarations();

  QName name = ki.getName();
  try
  {
    // System.out.println("lookupKey: "+lookupKey);
    int nDeclarations = keys.size();

    // Walk through each of the declarations made with xsl:key
    for (int i = 0; i < nDeclarations; i++)
    {
      KeyDeclaration kd = (KeyDeclaration) keys.elementAt(i);

      // Only continue if the name on this key declaration
      // matches the name on the iterator for this walker. 
      if (!kd.getName().equals(name))
        continue;

      foundKey = true;
      // xctxt.setNamespaceContext(ki.getPrefixResolver());

      // See if our node matches the given key declaration according to 
      // the match attribute on xsl:key.
      XPath matchExpr = kd.getMatch();
      double score = matchExpr.getMatchScore(xctxt, testNode);

      if (score == kd.getMatch().MATCH_SCORE_NONE)
        continue;

      return DTMIterator.FILTER_ACCEPT;

    } // end for(int i = 0; i < nDeclarations; i++)
  }
  catch (TransformerException se)
  {

    // TODO: What to do?
  }

  if (!foundKey)
    throw new RuntimeException(
      XSLMessages.createMessage(
        XSLTErrorResources.ER_NO_XSLKEY_DECLARATION,
        new Object[] { name.getLocalName()}));
        
  return DTMIterator.FILTER_REJECT;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:64,代码来源:KeyIterator.java


注:本文中的org.apache.xpath.XPath.getMatchScore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。