• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java XPathContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



XPathContext类属于org.apache.xpath包,在下文中一共展示了XPathContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getAttributeBooleanValue

import org.apache.xpath.XPathContext; //导入依赖的package包/类
private static final boolean getAttributeBooleanValue(XSLProcessorContext ctx, ElemExtensionCall call, String attr, boolean defaultValue) throws TransformerException {
	Node node = ctx.getContextNode();
	String expr = call.getAttribute(attr);
	if (expr == null || expr.isEmpty())
		return defaultValue;
	XPathContext xpctx = ctx.getTransformer().getXPathContext();
	XPath xp = new XPath(expr, call, xpctx.getNamespaceContext(), XPath.SELECT);
	XObject xobj = xp.execute(xpctx, node, call);
	String value = xobj.str();
	if (value == null)
		return defaultValue;
	if (value.equals("yes"))
		return true;
	if (value.equals("true"))
		return true;
	if (value.equals("no"))
		return false;
	if (value.equals("false"))
		return false;
	return defaultValue;
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:22,代码来源:XMLReader.java


示例2: execute

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
  double sum = 0.0;
  int pos;

  while (DTM.NULL != (pos = nodes.nextNode()))
  {
    DTM dtm = nodes.getDTM(pos);
    XMLString s = dtm.getStringValue(pos);

    if (null != s)
      sum += s.toDouble();
  }
  nodes.detach();

  return new XNumber(sum);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:28,代码来源:FuncSum.java


示例3: setRoot

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Initialize the context values for this expression
 * after it is cloned.
 *
 * @param context The XPath runtime context for this
 * transformation.
 */
public void setRoot(int context, Object environment)
{

  m_context = context;
  
  XPathContext xctxt = (XPathContext)environment;
  m_execContext = xctxt;
  m_cdtm = xctxt.getDTM(context);
  
  m_currentContextNode = context; // only if top level?
  
  // Yech, shouldn't have to do this.  -sb
  if(null == m_prefixResolver)
  	m_prefixResolver = xctxt.getNamespaceContext();
      
  m_lastFetched = DTM.NULL;
  m_foundLast = false;
  m_pos = 0;
  m_length = -1;

  if (m_isTopLevel)
    this.m_stackFrame = xctxt.getVarStack().getStackFrame();
    
  // reset();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:33,代码来源:LocPathIterator.java


示例4: getCountOfContextNodeList

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Get the position in the current context node list.
 *
 * @param xctxt non-null reference to XPath runtime context.
 *
 * @return The number of nodes in the list.
 *
 * @throws javax.xml.transform.TransformerException
 */
public int getCountOfContextNodeList(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  // assert(null != m_contextNodeList, "m_contextNodeList must be non-null");
  // If we're in a predicate, then this will return non-null.
  SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList();

  // System.out.println("iter: "+iter);
  if (null != iter)
    return iter.getLastPos(xctxt);

  DTMIterator cnl = xctxt.getContextNodeList();
  int count;
  if(null != cnl)
  {
    count = cnl.getLength();
    // System.out.println("count: "+count); 
  }
  else
    count = 0;   
  return count;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:33,代码来源:FuncLast.java


示例5: setRoot

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * @see DTMIterator#setRoot(int, Object)
 */
public void setRoot(int nodeHandle, Object environment)
{
	if(null != m_iter)
	{
		XPathContext xctxt = (XPathContext)environment;
		m_dtmMgr = xctxt.getDTMManager();
		m_iter.setRoot(nodeHandle, environment);
		if(!m_iter.isDocOrdered())
		{
			if(!hasCache())
				setShouldCacheNodes(true);
			runTo(-1);
			m_next=0;
		}
	}
	else
		assertion(false, "Can not setRoot on a non-iterated NodeSequence!");
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:22,代码来源:NodeSequence.java


示例6: sortNodes

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Sort given nodes
 *
 *
 * @param xctxt The XPath runtime state for the sort.
 * @param keys Vector of sort keyx
 * @param sourceNodes Iterator of nodes to sort
 *
 * @return iterator of sorted nodes
 *
 * @throws TransformerException
 */
public DTMIterator sortNodes(
        XPathContext xctxt, Vector keys, DTMIterator sourceNodes)
          throws TransformerException
{

  NodeSorter sorter = new NodeSorter(xctxt);
  sourceNodes.setShouldCacheNodes(true);
  sourceNodes.runTo(-1);
  xctxt.pushContextNodeList(sourceNodes);

  try
  {
    sorter.sort(sourceNodes, keys, xctxt);
    sourceNodes.setCurrentPos(0);
  }
  finally
  {
    xctxt.popContextNodeList();
  }

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


示例7: getAttribute

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Return the value of the attribute interpreted as an Attribute
 * Value Template (in other words, you can use curly expressions
 * such as href="http://{website}".
 *
 * @param rawName Raw name of the attribute to get
 * @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
 * @param transformer non-null reference to the the current transform-time state.
 *
 * @return the value of the attribute
 *
 * @throws TransformerException
 */
public String getAttribute(
        String rawName, org.w3c.dom.Node sourceNode, TransformerImpl transformer)
          throws TransformerException
{

  AVT avt = getLiteralResultAttribute(rawName);

  if ((null != avt) && avt.getRawName().equals(rawName))
  {
    XPathContext xctxt = transformer.getXPathContext();

    return avt.evaluate(xctxt, 
          xctxt.getDTMHandleFromNode(sourceNode), 
          this);
  }

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


示例8: execute

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Generate the EXSLT function return value, and assign it to the variable
 * index slot assigned for it in ElemExsltFunction compose().
 * 
 */
public void execute(TransformerImpl transformer) throws TransformerException
{    
  XPathContext context = transformer.getXPathContext();

  // Verify that result has not already been set by another result
  // element. Recursion is allowed: intermediate results are cleared 
  // in the owner ElemExsltFunction execute().
  if (transformer.currentFuncResultSeen()) {
      throw new TransformerException("An EXSLT function cannot set more than one result!");
  }

  int sourceNode = context.getCurrentNode();

  // Set the return value;
  XObject var = getValue(transformer, sourceNode);
  transformer.popCurrentFuncResult();
  transformer.pushCurrentFuncResult(var);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:24,代码来源:ElemExsltFuncResult.java


示例9: execute

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  StringBuffer sb = new StringBuffer();

  // Compiler says we must have at least two arguments.
  sb.append(m_arg0.execute(xctxt).str());
  sb.append(m_arg1.execute(xctxt).str());

  if (null != m_arg2)
    sb.append(m_arg2.execute(xctxt).str());

  if (null != m_args)
  {
    for (int i = 0; i < m_args.length; i++)
    {
      sb.append(m_args[i].execute(xctxt).str());
    }
  }

  return new XString(sb.toString());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:31,代码来源:FuncConcat.java


示例10: TransformerHandlerImpl

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Construct a TransformerHandlerImpl.
 *
 * @param transformer Non-null reference to the Xalan transformer impl.
 * @param doFragment True if the result should be a document fragement.
 * @param baseSystemID  The system ID to use as the base for relative URLs.
 */
public TransformerHandlerImpl(TransformerImpl transformer,
                              boolean doFragment, String baseSystemID)
{

  super();

  m_transformer = transformer;
  m_baseSystemID = baseSystemID;

  XPathContext xctxt = transformer.getXPathContext();
  DTM dtm = xctxt.getDTM(null, true, transformer, true, true);
  
  m_dtm = dtm;
  dtm.setDocumentBaseURI(baseSystemID);

  m_contentHandler = dtm.getContentHandler();
  m_dtdHandler = dtm.getDTDHandler();
  m_entityResolver = dtm.getEntityResolver();
  m_errorHandler = dtm.getErrorHandler();
  m_lexicalHandler = dtm.getLexicalHandler();
  m_incremental = transformer.getIncremental();
  m_optimizer = transformer.getOptimize();
  m_source_location = transformer.getSource_location();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:32,代码来源:TransformerHandlerImpl.java


示例11: execute

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int context = getArg0AsNode(xctxt);
  XObject val;

  if (DTM.NULL != context)
  {
    DTM dtm = xctxt.getDTM(context);
    String qname = dtm.getNodeNameX(context);
    val = (null == qname) ? XString.EMPTYSTRING : new XString(qname);
  }
  else
  {
    val = XString.EMPTYSTRING;
  }

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


示例12: setRoot

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Set the root node of the TreeWalker.
 * (Not part of the DOM2 TreeWalker interface).
 *
 * @param root The context node of this step.
 */
public void setRoot(int root)
{
  // %OPT% Get this directly from the lpi.
  XPathContext xctxt = wi().getXPathContext();
  m_dtm = xctxt.getDTM(root);
  m_traverser = m_dtm.getAxisTraverser(m_axis);
  m_isFresh = true;
  m_foundLast = false;
  m_root = root;
  m_currentNode = root;

  if (DTM.NULL == root)
  {
    throw new RuntimeException(
      XSLMessages.createXPATHMessage(XPATHErrorResources.ER_SETTING_WALKER_ROOT_TO_NULL, null)); //"\n !!!! Error! Setting the root of a walker to null!!!");
  }

  resetProximityPositions();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:26,代码来源:AxesWalker.java


示例13: getArg0AsNumber

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Execute the first argument expression that is expected to return a
 * number.  If the argument is null, then get the number value from the
 * current context node.
 *
 * @param xctxt Runtime XPath context.
 *
 * @return The number value of the first argument, or the number value of the
 *         current context node if the first argument is null.
 *
 * @throws javax.xml.transform.TransformerException if an error occurs while
 *                                   executing the argument expression.
 */
protected double getArg0AsNumber(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  if(null == m_arg0)
  {
    int currentNode = xctxt.getCurrentNode();
    if(DTM.NULL == currentNode)
      return 0;
    else
    {
      DTM dtm = xctxt.getDTM(currentNode);
      XMLString str = dtm.getStringValue(currentNode);
      return str.toDouble();
    }
    
  }
  else
    return m_arg0.execute(xctxt).num();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:34,代码来源:FunctionDef1Arg.java


示例14: getMatchScore

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Get the match score of the given node.
 *
 * @param xctxt The XPath runtime context.
 * @param context The node to be tested.
 *
 * @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
 *         {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
 *         {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
 *         {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
 *
 * @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 = execute(xctxt);

    return score.num();
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popCurrentExpressionNode();
  }

  // return XPath.MATCH_SCORE_NONE;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:36,代码来源:StepPattern.java


示例15: execute

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
 
  SubContextList subContextList = xctxt.getCurrentNodeList();
  int currentNode = DTM.NULL;

  if (null != subContextList) {
      if (subContextList instanceof PredicatedNodeTest) {
          LocPathIterator iter = ((PredicatedNodeTest)subContextList)
                                                        .getLocPathIterator();
          currentNode = iter.getCurrentContextNode();
       } else if(subContextList instanceof StepPattern) {
         throw new RuntimeException(XSLMessages.createMessage(
            XSLTErrorResources.ER_PROCESSOR_ERROR,null));
       }
  } else {
      // not predicate => ContextNode == CurrentNode
      currentNode = xctxt.getContextNode();
  }
  return new XNodeSet(currentNode, xctxt.getDTMManager());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:30,代码来源:FuncCurrent.java


示例16: execute

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int which = getArg0AsNode(xctxt);

  if (DTM.NULL != which)
  {
    // Note that this is a different value than in previous releases
    // of Xalan. It's sensitive to the exact encoding of the node
    // handle anyway, so fighting to maintain backward compatability
    // really didn't make sense; it may change again as we continue
    // to experiment with balancing document and node numbers within
    // that value.
    return new XString("N" + Integer.toHexString(which).toUpperCase());
  }
  else
    return XString.EMPTYSTRING;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:27,代码来源:FuncGenerateId.java


示例17: rtf

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Cast result object to a result tree fragment.
 *
 * @param support XPath context to use for the conversion
 *
 * @return the objec as a result tree fragment.
 */
public int rtf(XPathContext support)
{

  int result = rtf();

  if (DTM.NULL == result)
  {
    DTM frag = support.createDocumentFragment();

    // %OPT%
    frag.appendTextChild(str());

    result = frag.getDocument();
  }

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


示例18: executeCharsToContentHandler

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Execute an expression in the XPath runtime context, and return the 
 * result of the expression.
 *
 *
 * @param xctxt The XPath runtime context.
 *
 * @return The result of the expression in the form of a <code>XObject</code>.
 *
 * @throws javax.xml.transform.TransformerException if a runtime exception 
 *         occurs.
 */
public void executeCharsToContentHandler(XPathContext xctxt, 
                                            ContentHandler handler)
  throws javax.xml.transform.TransformerException,
         org.xml.sax.SAXException
{
  if(Arg0IsNodesetExpr())
  {
    int node = getArg0AsNode(xctxt);
    if(DTM.NULL != node)
    {
      DTM dtm = xctxt.getDTM(node);
      dtm.dispatchCharactersEvents(node, handler, true);
    }
  }
  else
  {
    XObject obj = execute(xctxt);
    obj.dispatchCharactersEvents(handler);
  }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:33,代码来源:FuncNormalizeSpace.java


示例19: executeCharsToContentHandler

import org.apache.xpath.XPathContext; //导入依赖的package包/类
/**
 * Execute an expression in the XPath runtime context, and return the
 * result of the expression.
 *
 *
 * @param xctxt The XPath runtime context.
 * @param handler The target content handler.
 *
 * @return The result of the expression in the form of a <code>XObject</code>.
 *
 * @throws javax.xml.transform.TransformerException if a runtime exception
 *         occurs.
 * @throws org.xml.sax.SAXException
 */
public void executeCharsToContentHandler(
        XPathContext xctxt, org.xml.sax.ContentHandler handler)
          throws javax.xml.transform.TransformerException,
                 org.xml.sax.SAXException
{
  LocPathIterator clone = (LocPathIterator)m_clones.getInstance();

  int current = xctxt.getCurrentNode();
  clone.setRoot(current, xctxt);
  
  int node = clone.nextNode();
  DTM dtm = clone.getDTM(node);
  clone.detach();
	
  if(node != DTM.NULL)
  {
    dtm.dispatchCharactersEvents(node, handler, false);
  }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:34,代码来源:LocPathIterator.java


示例20: getAttributeStringValue

import org.apache.xpath.XPathContext; //导入依赖的package包/类
private static final String getAttributeStringValue(XSLProcessorContext ctx, ElemExtensionCall call, String exprAttr, String valueAttr) throws TransformerException {
	Node node = ctx.getContextNode();
	String expr = call.getAttribute(exprAttr);
	if (expr == null || expr.isEmpty()) {
		return call.getAttribute(valueAttr);
	}
	XPathContext xpctx = ctx.getTransformer().getXPathContext();
	XPath xp = new XPath(expr, call, xpctx.getNamespaceContext(), XPath.SELECT);
	XObject xobj = xp.execute(xpctx, node, call);
	return xobj.str();
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:12,代码来源:XMLReader.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java JerseyClient类代码示例发布时间:2022-05-21
下一篇:
Java DoubleAccumulator类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap