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


Java XPathContext类代码示例

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


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


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