Java Code Examples for org.apache.xpath.XPathContext#popNamespaceContext()

The following examples show how to use org.apache.xpath.XPathContext#popNamespaceContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TemplateList.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Given a target element, find the template that best
 * matches in the given XSL document, according
 * to the rules specified in the xsl draft.
 *
 * @param xctxt
 * @param targetNode
 * @param mode A string indicating the display mode.
 * @param quietConflictWarnings
 * @return Rule that best matches targetElem.
 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
 * the error condition is severe enough to halt processing.
 *
 * @throws TransformerException
 */
public ElemTemplate getTemplate(XPathContext xctxt,
                              int targetNode,
                              QName mode,
                              boolean quietConflictWarnings,
                              DTM dtm)
          throws TransformerException
{

  TemplateSubPatternAssociation head = getHead(xctxt, targetNode, dtm);

  if (null != head)
  {
    // XSLT functions, such as xsl:key, need to be able to get to 
    // current ElemTemplateElement via a cast to the prefix resolver.
    // Setting this fixes bug idkey03.
    xctxt.pushNamespaceContextNull();
    xctxt.pushCurrentNodeAndExpression(targetNode, targetNode);
    try
    {
      do
      {
        ElemTemplate template = head.getTemplate();        
        xctxt.setNamespaceContext(template);
        
        if ((head.m_stepPattern.execute(xctxt, targetNode) != NodeTest.SCORE_NONE)
                && head.matchMode(mode))
        {
          if (quietConflictWarnings)
            checkConflicts(head, xctxt, targetNode, mode);

          return template;
        }
      }
      while (null != (head = head.getNext()));
    }
    finally
    {
      xctxt.popCurrentNodeAndExpression();
      xctxt.popNamespaceContext();
    }
  }

  return null;
}
 
Example 2
Source File: TemplateList.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Given a target element, find the template that best
 * matches in the given XSL document, according
 * to the rules specified in the xsl draft.
 *
 * @param xctxt
 * @param targetNode
 * @param mode A string indicating the display mode.
 * @param maxImportLevel The maximum importCountComposed that we should consider or -1
 *        if we should consider all import levels.  This is used by apply-imports to
 *        access templates that have been overridden.
 * @param endImportLevel The count of composed imports
 * @param quietConflictWarnings
 * @return Rule that best matches targetElem.
 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
 * the error condition is severe enough to halt processing.
 *
 * @throws TransformerException
 */
public ElemTemplate getTemplate(XPathContext xctxt,
                              int targetNode,
                              QName mode,
                              int maxImportLevel, int endImportLevel,
                              boolean quietConflictWarnings,
                              DTM dtm)
          throws TransformerException
{

  TemplateSubPatternAssociation head = getHead(xctxt, targetNode, dtm);

  if (null != head)
  {
    // XSLT functions, such as xsl:key, need to be able to get to 
    // current ElemTemplateElement via a cast to the prefix resolver.
    // Setting this fixes bug idkey03.
    xctxt.pushNamespaceContextNull();
    xctxt.pushCurrentNodeAndExpression(targetNode, targetNode);
    try
    {
      do
      {
        if ( (maxImportLevel > -1) && (head.getImportLevel() > maxImportLevel))
        {
          continue;
        }
        if (head.getImportLevel()<= maxImportLevel - endImportLevel)
          return null;
        ElemTemplate template = head.getTemplate();        
        xctxt.setNamespaceContext(template);
        
        if ((head.m_stepPattern.execute(xctxt, targetNode) != NodeTest.SCORE_NONE)
                && head.matchMode(mode))
        {
          if (quietConflictWarnings)
            checkConflicts(head, xctxt, targetNode, mode);

          return template;
        }
      }
      while (null != (head = head.getNext()));
    }
    finally
    {
      xctxt.popCurrentNodeAndExpression();
      xctxt.popNamespaceContext();
    }
  }

  return null;
}
 
Example 3
Source File: ElemValueOf.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Execute the string expression and copy the text to the
 * result tree.
 * The required select attribute is an expression; this expression
 * is evaluated and the resulting object is converted to a string
 * as if by a call to the string function. The string specifies
 * the string-value of the created text node. If the string is
 * empty, no text node will be created. The created text node will
 * be merged with any adjacent text nodes.
 * @see <a href="http://www.w3.org/TR/xslt#value-of">value-of in XSLT Specification</a>
 *
 * @param transformer non-null reference to the the current transform-time state.
 *
 * @throws TransformerException
 */
public void execute(TransformerImpl transformer) throws TransformerException
{

  XPathContext xctxt = transformer.getXPathContext();
  SerializationHandler rth = transformer.getResultTreeHandler();

  try
  {
    // Optimize for "."
      xctxt.pushNamespaceContext(this);

      int current = xctxt.getCurrentNode();

      xctxt.pushCurrentNodeAndExpression(current, current);

      if (m_disableOutputEscaping)
        rth.processingInstruction(
          javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");

      try
      {
        Expression expr = m_selectExpression.getExpression();

          expr.executeCharsToContentHandler(xctxt, rth);
      }
      finally
      {
        if (m_disableOutputEscaping)
          rth.processingInstruction(
            javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");

        xctxt.popNamespaceContext();
        xctxt.popCurrentNodeAndExpression();
      }
  }
  catch (SAXException se)
  {
    throw new TransformerException(se);
  }
  catch (RuntimeException re) {
  	TransformerException te = new TransformerException(re);
  	te.setLocator(this);
  	throw te;
  }
}
 
Example 4
Source File: PredicatedNodeTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Process the predicates.
 *
 * @param context The current context node.
 * @param xctxt The XPath runtime context.
 *
 * @return the result of executing the predicate expressions.
 *
 * @throws javax.xml.transform.TransformerException
 */
boolean executePredicates(int context, XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{
  
  int nPredicates = getPredicateCount();
  // System.out.println("nPredicates: "+nPredicates);
  if (nPredicates == 0)
    return true;

  PrefixResolver savedResolver = xctxt.getNamespaceContext();

  try
  {
    m_predicateIndex = 0;
    xctxt.pushSubContextList(this);
    xctxt.pushNamespaceContext(m_lpi.getPrefixResolver());
    xctxt.pushCurrentNode(context);

    for (int i = 0; i < nPredicates; i++)
    {
      // System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      XObject pred = m_predicates[i].execute(xctxt);
      // System.out.println("\nBack from executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
      // System.out.println("pred.getType(): "+pred.getType());
      if (XObject.CLASS_NUMBER == pred.getType())
      {
        if (DEBUG_PREDICATECOUNTING)
        {
          System.out.flush();
          System.out.println("\n===== start predicate count ========");
          System.out.println("m_predicateIndex: " + m_predicateIndex);
          // System.out.println("getProximityPosition(m_predicateIndex): "
          //                   + getProximityPosition(m_predicateIndex));
          System.out.println("pred.num(): " + pred.num());
        }

        int proxPos = this.getProximityPosition(m_predicateIndex);
        int predIndex = (int) pred.num();
        if (proxPos != predIndex)
        {
          if (DEBUG_PREDICATECOUNTING)
          {
            System.out.println("\nnode context: "+nodeToString(context));
            System.out.println("index predicate is false: "+proxPos);
            System.out.println("\n===== end predicate count ========");
          }
          return false;
        }
        else if (DEBUG_PREDICATECOUNTING)
        {
          System.out.println("\nnode context: "+nodeToString(context));
          System.out.println("index predicate is true: "+proxPos);
          System.out.println("\n===== end predicate count ========");
        }
        
        // If there is a proximity index that will not change during the 
        // course of itteration, then we know there can be no more true 
        // occurances of this predicate, so flag that we're done after 
        // this.
        //
        // bugzilla 14365
        // We can't set m_foundLast = true unless we're sure that -all-
        // remaining parameters are stable, or else last() fails. Fixed so
        // only sets m_foundLast if on the last predicate
        if(m_predicates[i].isStableNumber() && i == nPredicates - 1)
        {
          m_foundLast = true;
        }
      }
      else if (!pred.bool())
        return false;

      countProximityPosition(++m_predicateIndex);
    }
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popNamespaceContext();
    xctxt.popSubContextList();
    m_predicateIndex = -1;
  }

  return true;
}