org.apache.xpath.XPathContext Java Examples

The following examples show how to use org.apache.xpath.XPathContext. 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: ElemTemplate.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
   * Copy the template contents into the result tree.
   * The content of the xsl:template element is the template
   * that is instantiated when the template rule is applied.
   *
   * @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();
    
    xctxt.pushRTFContext();

      // %REVIEW% commenting out of the code below.
//    if (null != sourceNode)
//    {
      transformer.executeChildTemplates(this, true);
//    }
//    else  // if(null == sourceNode)
//    {
//      transformer.getMsgMgr().error(this,
//        this, sourceNode,
//        XSLTErrorResources.ER_NULL_SOURCENODE_HANDLEAPPLYTEMPLATES);
//
//      //"sourceNode is null in handleApplyTemplatesInstruction!");
//    }

    xctxt.popRTFContext();
    }
 
Example #2
Source File: XObject.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: StepPattern.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
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: FuncNormalizeSpace.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.
 *
 * @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);
  }
}
 
Example #6
Source File: StepPattern.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Execute this pattern step, including predicates.
 *
 *
 * @param xctxt XPath runtime context.
 * @param currentNode The current node 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, int currentNode)
        throws javax.xml.transform.TransformerException
{

  DTM dtm = xctxt.getDTM(currentNode);

  if (dtm != null)
  {
    int expType = dtm.getExpandedTypeID(currentNode);

    return execute(xctxt, currentNode, dtm, expType);
  }

  return NodeTest.SCORE_NONE;
}
 
Example #7
Source File: FuncGenerateId.java    From j2objc with Apache License 2.0 6 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
{

  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;
}
 
Example #8
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 #9
Source File: TransformerHandlerImpl.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #10
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 #11
Source File: ElemForEach.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: ElemExtensionCall.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #13
Source File: TransformerImpl.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a TransformerImpl.
 *
 * @param stylesheet The root of the stylesheet tree.
 */
public TransformerImpl(StylesheetRoot stylesheet)
 // throws javax.xml.transform.TransformerException    
{
  m_optimizer = stylesheet.getOptimizer();
  m_incremental = stylesheet.getIncremental();
  m_source_location = stylesheet.getSource_location();  	
  setStylesheet(stylesheet);
  XPathContext xPath = new XPathContext(this);
  xPath.setIncremental(m_incremental);
  xPath.getDTMManager().setIncremental(m_incremental);
  xPath.setSource_location(m_source_location);
  xPath.getDTMManager().setSource_location(m_source_location);
  
  if (stylesheet.isSecureProcessing())
    xPath.setSecureProcessing(true);
  
  setXPathContext(xPath);
  getXPathContext().setNamespaceContext(stylesheet);
}
 
Example #14
Source File: ElemNumber.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Get the target node that will be counted..
 *
 * @param xctxt The XPath runtime state for this.
 * @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
 *
 * @return the target node that will be counted
 *
 * @throws TransformerException
 */
public int getTargetNode(XPathContext xctxt, int sourceNode)
        throws TransformerException
{

  int target = DTM.NULL;
  XPath countMatchPattern = getCountMatchPattern(xctxt, sourceNode);

  if (Constants.NUMBERLEVEL_ANY == m_level)
  {
    target = findPrecedingOrAncestorOrSelf(xctxt, m_fromMatchPattern,
                                           countMatchPattern, sourceNode,
                                           this);
  }
  else
  {
    target = findAncestor(xctxt, m_fromMatchPattern, countMatchPattern,
                          sourceNode, this);
  }

  return target;
}
 
Example #15
Source File: StepPattern.java    From j2objc with Apache License 2.0 5 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 currentNode The currentNode.
 * @param dtm The DTM of the current node.
 * @param expType The expanded type ID of the current node.
 *
 * @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 XObject execute(
        XPathContext xctxt, int currentNode, DTM dtm, int expType)
          throws javax.xml.transform.TransformerException
{

  if (m_whatToShow == NodeTest.SHOW_BYFUNCTION)
  {
    if (null != m_relativePathPattern)
    {
      return m_relativePathPattern.execute(xctxt);
    }
    else
      return NodeTest.SCORE_NONE;
  }

  XObject score;

  score = super.execute(xctxt, currentNode, dtm, expType);

  if (score == NodeTest.SCORE_NONE)
    return NodeTest.SCORE_NONE;

  if (getPredicateCount() != 0)
  {
    if (!executePredicates(xctxt, dtm, currentNode))
      return NodeTest.SCORE_NONE;
  }

  if (null != m_relativePathPattern)
    return m_relativePathPattern.executeRelativePathPattern(xctxt, dtm,
            currentNode);

  return score;
}
 
Example #16
Source File: Or.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * OR two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link org.apache.xpath.objects.XBoolean#S_TRUE} or 
 * {@link org.apache.xpath.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (!expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_TRUE;
}
 
Example #17
Source File: Operation.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Execute a binary operation by calling execute on each of the operands,
 * and then calling the operate method on the derived class.
 *
 *
 * @param xctxt The runtime execution context.
 *
 * @return The XObject result of the operation.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  XObject left = m_left.execute(xctxt, true);
  XObject right = m_right.execute(xctxt, true);

  XObject result = operate(left, right);
  left.detach();
  right.detach();
  return result;
}
 
Example #18
Source File: XRTreeFrag.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Create an XRTreeFrag Object.
 *
 */
public XRTreeFrag(int root, XPathContext xctxt, ExpressionNode parent)
{
  super(null);
  exprSetParent(parent);
  initDTM(root, xctxt);    
}
 
Example #19
Source File: SerializerUtils.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Given a result tree fragment, walk the tree and
 * output it to the SerializationHandler.
 *
 * @param obj Result tree fragment object
 * @param support XPath context for the result tree fragment
 *
 * @throws org.xml.sax.SAXException
 */
public static void outputResultTreeFragment(
    SerializationHandler handler,
    XObject obj,
    XPathContext support)
    throws org.xml.sax.SAXException
{

    int doc = obj.rtf();
    DTM dtm = support.getDTM(doc);

    if (null != dtm)
    {
        for (int n = dtm.getFirstChild(doc);
            DTM.NULL != n;
            n = dtm.getNextSibling(n))
        {
            handler.flushPending();

            // I think. . . . This used to have a (true) arg
            // to flush prefixes, will that cause problems ???
            if (dtm.getNodeType(n) == DTM.ELEMENT_NODE
                    && dtm.getNamespaceURI(n) == null)
                handler.startPrefixMapping("", "");
            dtm.dispatchToEvents(n, handler);
        }
    }
}
 
Example #20
Source File: Equals.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
  * Execute a binary operation by calling execute on each of the operands,
  * and then calling the operate method on the derived class.
  *
  *
  * @param xctxt The runtime execution context.
  *
  * @return The XObject result of the operation.
  *
  * @throws javax.xml.transform.TransformerException
  */
 public boolean bool(XPathContext xctxt)
         throws javax.xml.transform.TransformerException
 {
   XObject left = m_left.execute(xctxt, true);
   XObject right = m_right.execute(xctxt, true);

   boolean result = left.equals(right) ? true : false;
left.detach();
right.detach();
   return result;
 }
 
Example #21
Source File: ElemNumber.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #22
Source File: FuncLocalPart.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
{

  int context = getArg0AsNode(xctxt);
  if(DTM.NULL == context)
    return XString.EMPTYSTRING;
  DTM dtm = xctxt.getDTM(context);
  String s = (context != DTM.NULL) ? dtm.getLocalName(context) : "";
  if(s.startsWith("#") || s.equals("xmlns"))
    return XString.EMPTYSTRING;

  return new XString(s);
}
 
Example #23
Source File: Counter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Try and find a node that was previously counted. If found,
 * return a positive integer that corresponds to the count.
 *
 * @param support The XPath context to use
 * @param node The node to be counted.
 * 
 * @return The count of the node, or -1 if not found.
 */
int getPreviouslyCounted(XPathContext support, int node)
{

  int n = m_countNodes.size();

  m_countResult = 0;

  for (int i = n - 1; i >= 0; i--)
  {
    int countedNode = m_countNodes.elementAt(i);

    if (node == countedNode)
    {

      // Since the list is in backwards order, the count is 
      // how many are in the rest of the list.
      m_countResult = i + 1 + m_countNodesStartCount;

      break;
    }
    
    DTM dtm = support.getDTM(countedNode);

    // Try to see if the given node falls after the counted node...
    // if it does, don't keep searching backwards.
    if (dtm.isNodeAfter(countedNode, node))
      break;
  }

  return m_countResult;
}
 
Example #24
Source File: UnionPattern.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Test a node to see if it matches any of the patterns in the union.
 *
 * @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
{

  XObject bestScore = null;
  int n = m_patterns.length;

  for (int i = 0; i < n; i++)
  {
    XObject score = m_patterns[i].execute(xctxt);

    if (score != NodeTest.SCORE_NONE)
    {
      if (null == bestScore)
        bestScore = score;
      else if (score.num() > bestScore.num())
        bestScore = score;
    }
  }

  if (null == bestScore)
  {
    bestScore = NodeTest.SCORE_NONE;
  }

  return bestScore;
}
 
Example #25
Source File: FuncDocument.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Tell the user of an error, and probably throw an
 * exception.
 *
 * @param xctxt The XPath runtime state.
 * @param msg The error message key
 * @param args Arguments to be used in the error message
 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 */
public void error(XPathContext xctxt, String msg, Object args[])
        throws javax.xml.transform.TransformerException
{

  String formattedMsg = XSLMessages.createMessage(msg, args);
  ErrorListener errHandler = xctxt.getErrorListener();
  TransformerException spe = new TransformerException(formattedMsg,
                            (SourceLocator)xctxt.getSAXLocator());

  if (null != errHandler)
    errHandler.error(spe);
  else
    System.out.println(formattedMsg);
}
 
Example #26
Source File: FuncDocument.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Warn the user of a problem.
 *
 * @param xctxt The XPath runtime state.
 * @param msg Warning message key
 * @param args Arguments to be used in the warning message
 * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 */
public void warn(XPathContext xctxt, String msg, Object args[])
        throws javax.xml.transform.TransformerException
{

  String formattedMsg = XSLMessages.createWarning(msg, args);
  ErrorListener errHandler = xctxt.getErrorListener();
  TransformerException spe = new TransformerException(formattedMsg,
                            (SourceLocator)xctxt.getSAXLocator());

  if (null != errHandler)
    errHandler.warning(spe);
  else
    System.out.println(formattedMsg);
}
 
Example #27
Source File: XNodeSetForDOM.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public XNodeSetForDOM(NodeIterator nodeIter, XPathContext xctxt)
{
  m_dtmMgr = xctxt.getDTMManager();
  m_origObj = nodeIter;

  // JKESS 20020514: Longer-term solution is to force
  // folks to request length through an accessor, so we can defer this
  // retrieval... but that requires an API change.
  // m_obj = new org.apache.xpath.NodeSetDTM(nodeIter, xctxt);
  org.apache.xpath.NodeSetDTM nsdtm=new org.apache.xpath.NodeSetDTM(nodeIter, xctxt);
  m_last=nsdtm.getLength();
  setObject(nsdtm);   
}
 
Example #28
Source File: XObject.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Cast object to type t.
 *
 * @param t Type of object to cast this to
 * @param support XPath context to use for the conversion
 *
 * @return This object as the given type t
 *
 * @throws javax.xml.transform.TransformerException
 */
public Object castToType(int t, XPathContext support)
        throws javax.xml.transform.TransformerException
{

  Object result;

  switch (t)
  {
  case CLASS_STRING :
    result = str();
    break;
  case CLASS_NUMBER :
    result = new Double(num());
    break;
  case CLASS_NODESET :
    result = iter();
    break;
  case CLASS_BOOLEAN :
    result = new Boolean(bool());
    break;
  case CLASS_UNKNOWN :
    result = m_obj;
    break;

  // %TBD%  What to do here?
  //    case CLASS_RTREEFRAG :
  //      result = rtree(support);
  //      break;
  default :
    error(XPATHErrorResources.ER_CANT_CONVERT_TO_TYPE,
          new Object[]{ getTypeString(),
                        Integer.toString(t) });  //"Can not convert "+getTypeString()+" to a type#"+t);

    result = null;
  }

  return result;
}
 
Example #29
Source File: XNodeSetForDOM.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public XNodeSetForDOM(NodeList nodeList, XPathContext xctxt)
{
  m_dtmMgr = xctxt.getDTMManager();
  m_origObj = nodeList;

  // JKESS 20020514: Longer-term solution is to force
  // folks to request length through an accessor, so we can defer this
  // retrieval... but that requires an API change.
  // m_obj=new org.apache.xpath.NodeSetDTM(nodeList, xctxt);
  org.apache.xpath.NodeSetDTM nsdtm=new org.apache.xpath.NodeSetDTM(nodeList, xctxt);
  m_last=nsdtm.getLength();
  setObject(nsdtm);   
}
 
Example #30
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);
    }

}