Пример #1
0
  /**
   * Given an expression and a context, evaluate the XPath and return the result.
   *
   * @param xctxt The execution context.
   * @param contextNode The node that "." expresses.
   * @param namespaceContext The context in which namespaces in the XPath are supposed to be
   *     expanded.
   * @throws TransformerException thrown if the active ProblemListener decides the error condition
   *     is severe enough to halt processing.
   * @throws javax.xml.transform.TransformerException
   * @xsl.usage experimental
   */
  public XObject execute(XPathContext xctxt, int contextNode, PrefixResolver namespaceContext)
      throws javax.xml.transform.TransformerException {

    xctxt.pushNamespaceContext(namespaceContext);

    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    XObject xobj = null;

    try {
      xobj = m_mainExp.execute(xctxt);
    } catch (TransformerException te) {
      te.setLocator(this.getLocator());
      ErrorListener el = xctxt.getErrorListener();
      if (null != el) // defensive, should never happen.
      {
        el.error(te);
      } else throw te;
    } catch (Exception e) {
      while (e instanceof com.sun.org.apache.xml.internal.utils.WrappedRuntimeException) {
        e = ((com.sun.org.apache.xml.internal.utils.WrappedRuntimeException) e).getException();
      }
      // e.printStackTrace();

      String msg = e.getMessage();

      if (msg == null || msg.length() == 0) {
        msg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_XPATH_ERROR, null);
      }
      TransformerException te = new TransformerException(msg, getLocator(), e);
      ErrorListener el = xctxt.getErrorListener();
      // te.printStackTrace();
      if (null != el) // defensive, should never happen.
      {
        el.fatalError(te);
      } else throw te;
    } finally {
      xctxt.popNamespaceContext();

      xctxt.popCurrentNodeAndExpression();
    }

    return xobj;
  }
Пример #2
0
  /**
   * Warn the user of an problem.
   *
   * @param xctxt The XPath runtime context.
   * @param sourceNode Not used.
   * @param msg An error msgkey that corresponds to one of the constants found in {@link
   *     com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is a key for a format
   *     string.
   * @param args An array of arguments represented in the format string, which may be null.
   * @throws TransformerException if the current ErrorListoner determines to throw an exception.
   */
  public void warn(XPathContext xctxt, int sourceNode, String msg, Object[] args)
      throws javax.xml.transform.TransformerException {

    String fmsg = XSLMessages.createXPATHWarning(msg, args);
    ErrorListener ehandler = xctxt.getErrorListener();

    if (null != ehandler) {

      // TO DO: Need to get stylesheet Locator from here.
      ehandler.warning(new TransformerException(fmsg, (SAXSourceLocator) xctxt.getSAXLocator()));
    }
  }
Пример #3
0
  /**
   * Tell the user of an error, and probably throw an exception.
   *
   * @param xctxt The XPath runtime context.
   * @param sourceNode Not used.
   * @param msg An error msgkey that corresponds to one of the constants found in {@link
   *     com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is a key for a format
   *     string.
   * @param args An array of arguments represented in the format string, which may be null.
   * @throws TransformerException if the current ErrorListoner determines to throw an exception.
   */
  public void error(XPathContext xctxt, int sourceNode, String msg, Object[] args)
      throws javax.xml.transform.TransformerException {

    String fmsg = XSLMessages.createXPATHMessage(msg, args);
    ErrorListener ehandler = xctxt.getErrorListener();

    if (null != ehandler) {
      ehandler.fatalError(new TransformerException(fmsg, (SAXSourceLocator) xctxt.getSAXLocator()));
    } else {
      SourceLocator slocator = xctxt.getSAXLocator();
      System.out.println(
          fmsg
              + "; file "
              + slocator.getSystemId()
              + "; line "
              + slocator.getLineNumber()
              + "; column "
              + slocator.getColumnNumber());
    }
  }