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

The following examples show how to use org.apache.xpath.XPathContext#getCurrentNode() . 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: FunctionDef1Arg.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example 2
Source File: FunctionDef1Arg.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Execute the first argument expression that is expected to return a
 * string.  If the argument is null, then get the string value from the
 * current context node.
 *
 * @param xctxt Runtime XPath context.
 *
 * @return The string value of the first argument, or the string 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 XMLString getArg0AsString(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{
  if(null == m_arg0)
  {
    int currentNode = xctxt.getCurrentNode();
    if(DTM.NULL == currentNode)
      return XString.EMPTYSTRING;
    else
    {
      DTM dtm = xctxt.getDTM(currentNode);
      return dtm.getStringValue(currentNode);
    }
    
  }
  else
    return m_arg0.execute(xctxt).xstr();   
}
 
Example 3
Source File: ElemExsltFuncResult.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 4
Source File: LocPathIterator.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 5
Source File: ElemIf.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Conditionally execute a sub-template.
 * The expression is evaluated and the resulting object is converted
 * to a boolean as if by a call to the boolean function. If the result
 * is true, then the content template is instantiated; otherwise, nothing
 * is created.
 *
 * @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();
  int sourceNode = xctxt.getCurrentNode();

    if (m_test.bool(xctxt, sourceNode, this)) {
        transformer.executeChildTemplates(this, true);
    }

}
 
Example 6
Source File: FuncUnparsedEntityURI.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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
{

  String name = m_arg0.execute(xctxt).str();
  int context = xctxt.getCurrentNode();
  DTM dtm = xctxt.getDTM(context);
  int doc = dtm.getDocument();
  
  String uri = dtm.getUnparsedEntityURI(name);

  return new XString(uri);
}
 
Example 7
Source File: DescendantIterator.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Return the first node out of the nodeset, if this expression is 
 * a nodeset expression.  This is the default implementation for 
 * nodesets.
 * <p>WARNING: Do not mutate this class from this function!</p>
 * @param xctxt The XPath runtime context.
 * @return the first node out of the nodeset, or DTM.NULL.
 */
public int asNode(XPathContext xctxt)
  throws javax.xml.transform.TransformerException
{
  if(getPredicateCount() > 0)
    return super.asNode(xctxt);

  int current = xctxt.getCurrentNode();
  
  DTM dtm = xctxt.getDTM(current);
  DTMAxisTraverser traverser = dtm.getAxisTraverser(m_axis);
  
  String localName = getLocalName();
  String namespace = getNamespace();
  int what = m_whatToShow;
  
  // System.out.print(" (DescendantIterator) ");
  
  // System.out.println("what: ");
  // NodeTest.debugWhatToShow(what);
  if(DTMFilter.SHOW_ALL == what
     || localName == NodeTest.WILD
     || namespace == NodeTest.WILD)
  {
    return traverser.first(current);
  }
  else
  {
    int type = getNodeTypeTest(what);
    int extendedType = dtm.getExpandedTypeID(namespace, localName, type);
    return traverser.first(current, extendedType);
  }
}
 
Example 8
Source File: FuncLang.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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
{

  String lang = m_arg0.execute(xctxt).str();
  int parent = xctxt.getCurrentNode();
  boolean isLang = false;
  DTM dtm = xctxt.getDTM(parent);

  while (DTM.NULL != parent)
  {
    if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
    {
      int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");

      if (DTM.NULL != langAttr)
      {
        String langVal = dtm.getNodeValue(langAttr);
        // %OPT%
        if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
        {
          int valLen = lang.length();

          if ((langVal.length() == valLen)
                  || (langVal.charAt(valLen) == '-'))
          {
            isLang = true;
          }
        }

        break;
      }
    }

    parent = dtm.getParent(parent);
  }

  return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example 9
Source File: ChildIterator.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Return the first node out of the nodeset, if this expression is 
 * a nodeset expression.  This is the default implementation for 
 * nodesets.
 * <p>WARNING: Do not mutate this class from this function!</p>
 * @param xctxt The XPath runtime context.
 * @return the first node out of the nodeset, or DTM.NULL.
 */
public int asNode(XPathContext xctxt)
  throws javax.xml.transform.TransformerException
{
  int current = xctxt.getCurrentNode();
  
  DTM dtm = xctxt.getDTM(current);
  
  return dtm.getFirstChild(current);
}
 
Example 10
Source File: FunctionPattern.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Test a node to see if it matches the given node test.
 *
 * @param xctxt XPath runtime context.
 *
 * @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 XObject execute(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  int context = xctxt.getCurrentNode();
  DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
  XNumber score = SCORE_NONE;

  if (null != nl)
  {
    int n;

    while (DTM.NULL != (n = nl.nextNode()))
    {
      score = (n == context) ? SCORE_OTHER : SCORE_NONE;

      if (score == SCORE_OTHER)
      {
        context = n;

        break;
      }
    }

    nl.detach();
  }

  return score;
}
 
Example 11
Source File: LocPathIterator.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Return the first node out of the nodeset, if this expression is 
 * a nodeset expression.  This is the default implementation for 
 * nodesets.  Derived classes should try and override this and return a 
 * value without having to do a clone operation.
 * @param xctxt The XPath runtime context.
 * @return the first node out of the nodeset, or DTM.NULL.
 */
public int asNode(XPathContext xctxt)
  throws javax.xml.transform.TransformerException
{
  DTMIterator iter = (DTMIterator)m_clones.getInstance();
  
  int current = xctxt.getCurrentNode();
  
  iter.setRoot(current, xctxt);

  int next = iter.nextNode();
  // m_clones.freeInstance(iter);
  iter.detach();
  return next;
}
 
Example 12
Source File: ElemChoose.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Execute the xsl:choose transformation.
 *
 *
 * @param transformer non-null reference to the the current transform-time state.
 *
 * @throws TransformerException
 */
public void execute(TransformerImpl transformer) throws TransformerException
{

  boolean found = false;

  for (ElemTemplateElement childElem = getFirstChildElem();
          childElem != null; childElem = childElem.getNextSiblingElem())
  {
    int type = childElem.getXSLToken();

    if (Constants.ELEMNAME_WHEN == type)
    {
      found = true;

      ElemWhen when = (ElemWhen) childElem;

      // must be xsl:when
      XPathContext xctxt = transformer.getXPathContext();
      int sourceNode = xctxt.getCurrentNode();
      
      // System.err.println("\""+when.getTest().getPatternString()+"\"");
      
      // if(when.getTest().getPatternString().equals("COLLECTION/icuser/ictimezone/LITERAL='GMT +13:00 Pacific/Tongatapu'"))
      // 	System.err.println("Found COLLECTION/icuser/ictimezone/LITERAL");

        if (when.getTest().bool(xctxt, sourceNode, when)) {
            transformer.executeChildTemplates(when, true);

            return;
        }
    }
    else if (Constants.ELEMNAME_OTHERWISE == type)
    {
      found = true;

      // xsl:otherwise
      transformer.executeChildTemplates(childElem, true);

      return;
    }
  }

  if (!found)
    transformer.getMsgMgr().error(
      this, XSLTErrorResources.ER_CHOOSE_REQUIRES_WHEN);
}
 
Example 13
Source File: ElemCallTemplate.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Invoke a named template.
 * @see <a href="http://www.w3.org/TR/xslt#named-templates">named-templates 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
{

  if (null != m_template)
  {
    XPathContext xctxt = transformer.getXPathContext();
    VariableStack vars = xctxt.getVarStack();

    int thisframe = vars.getStackFrame();
    int nextFrame = vars.link(m_template.m_frameSize);
    
    // We have to clear the section of the stack frame that has params 
    // so that the default param evaluation will work correctly.
    if(m_template.m_inArgsSize > 0)
    {
      vars.clearLocalSlots(0, m_template.m_inArgsSize);
    
      if(null != m_paramElems)
      {
        int currentNode = xctxt.getCurrentNode();
        vars.setStackFrame(thisframe);
        int size = m_paramElems.length;
        
        for (int i = 0; i < size; i++) 
        {
          ElemWithParam ewp = m_paramElems[i];
          if(ewp.m_index >= 0)
          {
            XObject obj = ewp.getValue(transformer, currentNode);

            // Note here that the index for ElemWithParam must have been
            // statically made relative to the xsl:template being called, 
            // NOT this xsl:template.
            vars.setLocalVariable(ewp.m_index, obj, nextFrame);
          }
        }
        vars.setStackFrame(nextFrame);
      }
    }
    
    SourceLocator savedLocator = xctxt.getSAXLocator();

    try
    {
      xctxt.setSAXLocator(m_template);

      // template.executeChildTemplates(transformer, sourceNode, mode, true);
      transformer.pushElemTemplateElement(m_template);
      m_template.execute(transformer);
    }
    finally
    {
      transformer.popElemTemplateElement();
      xctxt.setSAXLocator(savedLocator);
      // When we entered this function, the current 
      // frame buffer (cfb) index in the variable stack may 
      // have been manually set.  If we just call 
      // unlink(), however, it will restore the cfb to the 
      // previous link index from the link stack, rather than 
      // the manually set cfb.  So, 
      // the only safe solution is to restore it back 
      // to the same position it was on entry, since we're 
      // really not working in a stack context here. (Bug4218)
      vars.unlink(thisframe);
    }
  }
  else
  {
    transformer.getMsgMgr().error(this, XSLTErrorResources.ER_TEMPLATE_NOT_FOUND,
                                  new Object[]{ m_templateName });  //"Could not find template named: '"+templateName+"'");
  }
  
}
 
Example 14
Source File: ElemPI.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Create a processing instruction in the result tree.
 * The content of the xsl:processing-instruction element is a
 * template for the string-value of the processing instruction node.
 * @see <a href="http://www.w3.org/TR/xslt#section-Creating-Processing-Instructions">section-Creating-Processing-Instructions 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();
  int sourceNode = xctxt.getCurrentNode();
  
  String piName = m_name_atv == null ? null : m_name_atv.evaluate(xctxt, sourceNode, this);
  
  // Ignore processing instruction if name is null
  if (piName == null) return;

  if (piName.equalsIgnoreCase("xml"))
  {
   	transformer.getMsgMgr().warn(
      this, XSLTErrorResources.WG_PROCESSINGINSTRUCTION_NAME_CANT_BE_XML,
            new Object[]{ Constants.ATTRNAME_NAME, piName });
return;
  }
  
  // Only check if an avt was used (ie. this wasn't checked at compose time.)
  // Ignore processing instruction, if invalid
  else if ((!m_name_atv.isSimple()) && (!XML11Char.isXML11ValidNCName(piName)))
  {
   	transformer.getMsgMgr().warn(
      this, XSLTErrorResources.WG_PROCESSINGINSTRUCTION_NOTVALID_NCNAME,
            new Object[]{ Constants.ATTRNAME_NAME, piName });
return;    	
  }

  // Note the content model is:
  // <!ENTITY % instructions "
  // %char-instructions;
  // | xsl:processing-instruction
  // | xsl:comment
  // | xsl:element
  // | xsl:attribute
  // ">
  String data = transformer.transformToString(this);

  try
  {
    transformer.getResultTreeHandler().processingInstruction(piName, data);
  }
  catch(org.xml.sax.SAXException se)
  {
    throw new TransformerException(se);
  }
}
 
Example 15
Source File: ElemCopyOf.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * The xsl:copy-of element can be used to insert a result tree
 * fragment into the result tree, without first converting it to
 * a string as xsl:value-of does (see [7.6.1 Generating Text with
 * xsl:value-of]).
 *
 * @param transformer non-null reference to the the current transform-time state.
 *
 * @throws TransformerException
 */
public void execute(
        TransformerImpl transformer)
          throws TransformerException
{
  try
  {
    XPathContext xctxt = transformer.getXPathContext();
    int sourceNode = xctxt.getCurrentNode();
    XObject value = m_selectExpression.execute(xctxt, sourceNode, this);

    SerializationHandler handler = transformer.getSerializationHandler();

    if (null != value)
                      {
      int type = value.getType();
      String s;

      switch (type)
      {
      case XObject.CLASS_BOOLEAN :
      case XObject.CLASS_NUMBER :
      case XObject.CLASS_STRING :
        s = value.str();

        handler.characters(s.toCharArray(), 0, s.length());
        break;
      case XObject.CLASS_NODESET :

        // System.out.println(value);
        DTMIterator nl = value.iter();

        // Copy the tree.
        DTMTreeWalker tw = new TreeWalker2Result(transformer, handler);
        int pos;

        while (DTM.NULL != (pos = nl.nextNode()))
        {
          DTM dtm = xctxt.getDTMManager().getDTM(pos);
          short t = dtm.getNodeType(pos);

          // If we just copy the whole document, a startDoc and endDoc get 
          // generated, so we need to only walk the child nodes.
          if (t == DTM.DOCUMENT_NODE)
          {
            for (int child = dtm.getFirstChild(pos); child != DTM.NULL;
                 child = dtm.getNextSibling(child))
            {
              tw.traverse(child);
            }
          }
          else if (t == DTM.ATTRIBUTE_NODE)
          {
            SerializerUtils.addAttribute(handler, pos);
          }
          else
          {
            tw.traverse(pos);
          }
        }
        // nl.detach();
        break;
      case XObject.CLASS_RTREEFRAG :
        SerializerUtils.outputResultTreeFragment(
          handler, value, transformer.getXPathContext());
        break;
      default :
        
        s = value.str();

        handler.characters(s.toCharArray(), 0, s.length());
        break;
      }
    }
                      
    // I don't think we want this.  -sb
    //  if (transformer.getDebug())
    //  transformer.getTraceManager().fireSelectedEvent(sourceNode, this,
    //  "endSelect", m_selectExpression, value);

  }
  catch(org.xml.sax.SAXException se)
  {
    throw new TransformerException(se);
  }

}
 
Example 16
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 17
Source File: ElemElement.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Create an element in the result tree.
 * The xsl:element element allows an element to be created with a
 * computed name. The expanded-name of the element to be created
 * is specified by a required name attribute and an optional namespace
 * attribute. The content of the xsl:element element is a template
 * for the attributes and children of the created element.
 *
 * @param transformer non-null reference to the the current transform-time state.
 *
 * @throws TransformerException
 */
public void execute(
        TransformerImpl transformer)
          throws TransformerException
{

SerializationHandler rhandler = transformer.getSerializationHandler();
  XPathContext xctxt = transformer.getXPathContext();
  int sourceNode = xctxt.getCurrentNode();
  
  
  String nodeName = m_name_avt == null ? null : m_name_avt.evaluate(xctxt, sourceNode, this);

  String prefix = null;
  String nodeNamespace = "";

  // Only validate if an AVT was used.
  if ((nodeName != null) && (!m_name_avt.isSimple()) && (!XML11Char.isXML11ValidQName(nodeName)))
  {
    transformer.getMsgMgr().warn(
      this, XSLTErrorResources.WG_ILLEGAL_ATTRIBUTE_VALUE,
      new Object[]{ Constants.ATTRNAME_NAME, nodeName });

    nodeName = null;
  }

  else if (nodeName != null)
  {
    prefix = QName.getPrefixPart(nodeName);

    if (null != m_namespace_avt)
    {
      nodeNamespace = m_namespace_avt.evaluate(xctxt, sourceNode, this);
      if (null == nodeNamespace || 
          (prefix != null && prefix.length()>0 && nodeNamespace.length()== 0) )
        transformer.getMsgMgr().error(
            this, XSLTErrorResources.ER_NULL_URI_NAMESPACE);
      else
      {
      // Determine the actual prefix that we will use for this nodeNamespace

      prefix = resolvePrefix(rhandler, prefix, nodeNamespace);
      if (null == prefix)
        prefix = "";

      if (prefix.length() > 0)
        nodeName = (prefix + ":" + QName.getLocalPart(nodeName));
      else
        nodeName = QName.getLocalPart(nodeName);
      }
    }

    // No namespace attribute was supplied. Use the namespace declarations
    // currently in effect for the xsl:element element.
    else    
    {
      try
      {
        // Maybe temporary, until I get this worked out.  test: axes59
        nodeNamespace = getNamespaceForPrefix(prefix);

        // If we get back a null nodeNamespace, that means that this prefix could
        // not be found in the table.  This is okay only for a default namespace
        // that has never been declared.

        if ( (null == nodeNamespace) && (prefix.length() == 0) )
          nodeNamespace = "";
        else if (null == nodeNamespace)
        {
          transformer.getMsgMgr().warn(
            this, XSLTErrorResources.WG_COULD_NOT_RESOLVE_PREFIX,
            new Object[]{ prefix });

          nodeName = null;
        }

      }
      catch (Exception ex)
      {
        transformer.getMsgMgr().warn(
          this, XSLTErrorResources.WG_COULD_NOT_RESOLVE_PREFIX,
          new Object[]{ prefix });

        nodeName = null;
      }
    }
  }

  constructNode(nodeName, prefix, nodeNamespace, transformer);
}
 
Example 18
Source File: ElemCopy.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * The xsl:copy element provides an easy way of copying the current node.
 * Executing this function creates a copy of the current node into the
 * result tree.
 * <p>The namespace nodes of the current node are automatically
 * copied as well, but the attributes and children of the node are not
 * automatically copied. The content of the xsl:copy element is a
 * template for the attributes and children of the created node;
 * the content is instantiated only for nodes of types that can have
 * attributes or children (i.e. root nodes and element nodes).</p>
 * <p>The root node is treated specially because the root node of the
 * result tree is created implicitly. When the current node is the
 * root node, xsl:copy will not create a root node, but will just use
 * the content template.</p>
 *
 * @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();
    
  try
  {
    int sourceNode = xctxt.getCurrentNode();
    xctxt.pushCurrentNode(sourceNode);
    DTM dtm = xctxt.getDTM(sourceNode);
    short nodeType = dtm.getNodeType(sourceNode);

    if ((DTM.DOCUMENT_NODE != nodeType) && (DTM.DOCUMENT_FRAGMENT_NODE != nodeType))
    {
      SerializationHandler rthandler = transformer.getSerializationHandler();

      // TODO: Process the use-attribute-sets stuff
      ClonerToResultTree.cloneToResultTree(sourceNode, nodeType, dtm, 
                                           rthandler, false);

      if (DTM.ELEMENT_NODE == nodeType)
      {
        super.execute(transformer);
        SerializerUtils.processNSDecls(rthandler, sourceNode, nodeType, dtm);
        transformer.executeChildTemplates(this, true);
        
        String ns = dtm.getNamespaceURI(sourceNode);
        String localName = dtm.getLocalName(sourceNode);
        transformer.getResultTreeHandler().endElement(ns, localName,
                                                      dtm.getNodeName(sourceNode));
      }
    }
    else
    {
      super.execute(transformer);
      transformer.executeChildTemplates(this, true);
    }
  }
  catch(org.xml.sax.SAXException se)
  {
    throw new TransformerException(se);
  }
  finally
  {
    xctxt.popCurrentNode();
  }
}
 
Example 19
Source File: ContextMatchStepPattern.java    From j2objc with Apache License 2.0 3 votes vote down vote up
/**
 * Execute this pattern step, including predicates.
 *
 *
 * @param xctxt XPath runtime context.
 *
 * @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 XObject execute(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  if (xctxt.getIteratorRoot() == xctxt.getCurrentNode())
    return getStaticScore();
  else
    return this.SCORE_NONE;
}
 
Example 20
Source File: FunctionDef1Arg.java    From j2objc with Apache License 2.0 3 votes vote down vote up
/**
 * Execute the first argument expression that is expected to return a
 * nodeset.  If the argument is null, then return the current context node.
 *
 * @param xctxt Runtime XPath context.
 *
 * @return The first node of the executed nodeset, or 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 int getArg0AsNode(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  return (null == m_arg0)
         ? xctxt.getCurrentNode() : m_arg0.asNode(xctxt);
}