You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@apache.org on 2001/01/07 07:24:41 UTC

cvs commit: xml-xalan/java/src/org/apache/xpath/res XPATHErrorResources.java

sboag       01/01/06 22:24:41

  Modified:    java/src/org/apache/xalan/processor ProcessorLRE.java
                        ProcessorStylesheetElement.java
                        StylesheetHandler.java XSLTAttributeDef.java
               java/src/org/apache/xalan/templates AVTPartXPath.java
                        ElemNumber.java StylesheetRoot.java
               java/src/org/apache/xpath XPath.java XPathAPI.java
               java/src/org/apache/xpath/compiler Compiler.java
                        XPathParser.java
               java/src/org/apache/xpath/res XPATHErrorResources.java
  Log:
  Make sure both the source locator and the error listener are set in
  the XPath Compiler and XPath parser, and the XPath object itself.
  This required passing the error listener to the XPath object, which
  had a ripple effect on several functions, including the constructor
  for StylesheetRoot.
  
  This was sparked by BugId 4402417 which Krishna.Meduri@eng.sun.com
  submitted to me privately, but may not be the same thing, since
  he was getting a NoSuchMethodError, and I don't
  have the stylesheet to replicate the bug.
  
  This fixes an error where a null pointer
  exception was being thrown if an unknown
  function was found.
  
  Revision  Changes    Path
  1.16      +3 -2      xml-xalan/java/src/org/apache/xalan/processor/ProcessorLRE.java
  
  Index: ProcessorLRE.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorLRE.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ProcessorLRE.java	2000/11/28 17:25:50	1.15
  +++ ProcessorLRE.java	2001/01/07 06:24:39	1.16
  @@ -121,7 +121,7 @@
           Stylesheet stylesheet;
           try
           {
  -          stylesheet = new StylesheetRoot(handler.getSchema());
  +          stylesheet = new StylesheetRoot(handler.getSchema(), handler.getStylesheetProcessor().getErrorListener());
           }
           catch(TransformerConfigurationException tfe)
           {
  @@ -189,7 +189,8 @@
   
           appendAndPush(handler, template);
   
  -        XPath rootMatch = new XPath("/", stylesheet, stylesheet, XPath.MATCH);
  +        XPath rootMatch = new XPath("/", stylesheet, stylesheet, XPath.MATCH, 
  +             handler.getStylesheetProcessor().getErrorListener());
   
           template.setMatch(rootMatch);
   
  
  
  
  1.8       +1 -1      xml-xalan/java/src/org/apache/xalan/processor/ProcessorStylesheetElement.java
  
  Index: ProcessorStylesheetElement.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorStylesheetElement.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ProcessorStylesheetElement.java	2000/11/28 17:25:50	1.7
  +++ ProcessorStylesheetElement.java	2001/01/07 06:24:39	1.8
  @@ -103,7 +103,7 @@
         {
           try
           {
  -          stylesheet = new StylesheetRoot(handler.getSchema());
  +          stylesheet = new StylesheetRoot(handler.getSchema(), handler.getStylesheetProcessor().getErrorListener());
           }
           catch(TransformerConfigurationException tfe)
           {
  
  
  
  1.30      +4 -7      xml-xalan/java/src/org/apache/xalan/processor/StylesheetHandler.java
  
  Index: StylesheetHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/StylesheetHandler.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- StylesheetHandler.java	2000/12/13 19:25:53	1.29
  +++ StylesheetHandler.java	2001/01/07 06:24:39	1.30
  @@ -188,7 +188,8 @@
     public XPath createXPath(String str)
             throws javax.xml.transform.TransformerException
     {
  -    return new XPath(str, getLocator(), this, XPath.SELECT);
  +    ErrorListener handler = m_stylesheetProcessor.getErrorListener();
  +    return new XPath(str, getLocator(), this, XPath.SELECT, handler);
     }
   
     /**
  @@ -204,7 +205,8 @@
     XPath createMatchPatternXPath(String str)
             throws javax.xml.transform.TransformerException
     {
  -    return new XPath(str, getLocator(), this, XPath.MATCH);
  +    ErrorListener handler = m_stylesheetProcessor.getErrorListener();
  +    return new XPath(str, getLocator(), this, XPath.MATCH, handler);
     }
   
     /**
  @@ -1433,11 +1435,6 @@
      * older XSLT namespace URL.
      */
     private boolean warnedAboutOldXSLTNamespace = false;
  -
  -  /**
  -   * The query/pattern-matcher object.
  -   */
  -  private XPathParser m_xpathProcessor = new XPathParser();
   
     /** Stack of {@link org.xml.sax.helpers.NamespaceSupport} objects. */
     Stack m_nsSupportStack = new Stack();
  
  
  
  1.18      +1 -0      xml-xalan/java/src/org/apache/xalan/processor/XSLTAttributeDef.java
  
  Index: XSLTAttributeDef.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/XSLTAttributeDef.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- XSLTAttributeDef.java	2001/01/03 09:59:43	1.17
  +++ XSLTAttributeDef.java	2001/01/07 06:24:39	1.18
  @@ -576,6 +576,7 @@
       }
       catch (TransformerException te)
       {
  +      org.xml.sax.SAXException se = new org.xml.sax.SAXException(te);
         throw new org.xml.sax.SAXException(te);
       }
     }
  
  
  
  1.12      +1 -1      xml-xalan/java/src/org/apache/xalan/templates/AVTPartXPath.java
  
  Index: AVTPartXPath.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/AVTPartXPath.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AVTPartXPath.java	2001/01/02 03:36:45	1.11
  +++ AVTPartXPath.java	2001/01/07 06:24:40	1.12
  @@ -122,7 +122,7 @@
             XPathContext liaison)
               throws javax.xml.transform.TransformerException
     {
  -    m_xpath = new XPath(val, null, nsNode, XPath.SELECT);
  +    m_xpath = new XPath(val, null, nsNode, XPath.SELECT, liaison.getErrorListener());
     }
   
     /**
  
  
  
  1.16      +6 -6      xml-xalan/java/src/org/apache/xalan/templates/ElemNumber.java
  
  Index: ElemNumber.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemNumber.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ElemNumber.java	2001/01/02 03:36:46	1.15
  +++ ElemNumber.java	2001/01/07 06:24:40	1.16
  @@ -684,35 +684,35 @@
   
           // countMatchPattern = m_stylesheet.createMatchPattern(contextNode.getNodeName(), this);
           countMatchPattern = new XPath(contextNode.getNodeName(), this, this,
  -                                      XPath.MATCH);
  +                                      XPath.MATCH, support.getErrorListener());
           break;
         case Node.ATTRIBUTE_NODE :
   
           // countMatchPattern = m_stylesheet.createMatchPattern("@"+contextNode.getNodeName(), this);
           countMatchPattern = new XPath("@" + contextNode.getNodeName(), this,
  -                                      this, XPath.MATCH);
  +                                      this, XPath.MATCH, support.getErrorListener());
           break;
         case Node.CDATA_SECTION_NODE :
         case Node.TEXT_NODE :
   
           // countMatchPattern = m_stylesheet.createMatchPattern("text()", this);
  -        countMatchPattern = new XPath("text()", this, this, XPath.MATCH);
  +        countMatchPattern = new XPath("text()", this, this, XPath.MATCH, support.getErrorListener());
           break;
         case Node.COMMENT_NODE :
   
           // countMatchPattern = m_stylesheet.createMatchPattern("comment()", this);
  -        countMatchPattern = new XPath("comment()", this, this, XPath.MATCH);
  +        countMatchPattern = new XPath("comment()", this, this, XPath.MATCH, support.getErrorListener());
           break;
         case Node.DOCUMENT_NODE :
   
           // countMatchPattern = m_stylesheet.createMatchPattern("/", this);
  -        countMatchPattern = new XPath("/", this, this, XPath.MATCH);
  +        countMatchPattern = new XPath("/", this, this, XPath.MATCH, support.getErrorListener());
           break;
         case Node.PROCESSING_INSTRUCTION_NODE :
   
           // countMatchPattern = m_stylesheet.createMatchPattern("pi("+contextNode.getNodeName()+")", this);
           countMatchPattern = new XPath("pi(" + contextNode.getNodeName()
  -                                      + ")", this, this, XPath.MATCH);
  +                                      + ")", this, this, XPath.MATCH, support.getErrorListener());
           break;
         default :
           countMatchPattern = null;
  
  
  
  1.38      +11 -10    xml-xalan/java/src/org/apache/xalan/templates/StylesheetRoot.java
  
  Index: StylesheetRoot.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/StylesheetRoot.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- StylesheetRoot.java	2001/01/04 08:06:23	1.37
  +++ StylesheetRoot.java	2001/01/07 06:24:40	1.38
  @@ -85,6 +85,7 @@
   import javax.xml.transform.TransformerConfigurationException;
   import javax.xml.transform.Templates;
   import javax.xml.transform.OutputKeys;
  +import javax.xml.transform.ErrorListener;
   
   /**
    * <meta name="usage" content="general"/>
  @@ -98,7 +99,7 @@
      * Uses an XSL stylesheet document.
      * @throws TransformerConfigurationException if the baseIdentifier can not be resolved to a URL.
      */
  -  public StylesheetRoot() throws TransformerConfigurationException
  +  public StylesheetRoot(ErrorListener errorListener) throws TransformerConfigurationException
     {
   
       super(null);
  @@ -107,9 +108,9 @@
   
       try
       {
  -      m_selectDefault = new XPath("node()", this, this, XPath.SELECT);
  +      m_selectDefault = new XPath("node()", this, this, XPath.SELECT, errorListener);
   
  -      initDefaultRule();
  +      initDefaultRule(errorListener);
       }
       catch (TransformerException se)
       {
  @@ -130,10 +131,10 @@
      * @param schema The schema used to create this stylesheet
      * @throws TransformerConfigurationException if the baseIdentifier can not be resolved to a URL.
      */
  -  public StylesheetRoot(XSLTSchema schema) throws TransformerConfigurationException
  +  public StylesheetRoot(XSLTSchema schema, ErrorListener listener) throws TransformerConfigurationException
     {
   
  -    this();
  +    this(listener);
       m_availElems = schema.getElemsAvailable();
   
     }
  @@ -948,7 +949,7 @@
      *
      * @throws TransformerException
      */
  -  private void initDefaultRule() throws TransformerException
  +  private void initDefaultRule(ErrorListener errorListener) throws TransformerException
     {
   
       // Then manufacture a default
  @@ -956,7 +957,7 @@
   
       m_defaultRule.setStylesheet(this);
   
  -    XPath defMatch = new XPath("*", this, this, XPath.MATCH);
  +    XPath defMatch = new XPath("*", this, this, XPath.MATCH, errorListener);
   
       m_defaultRule.setMatch(defMatch);
   
  @@ -970,7 +971,7 @@
   
       m_defaultTextRule.setStylesheet(this);
   
  -    defMatch = new XPath("text() | @*", this, this, XPath.MATCH);
  +    defMatch = new XPath("text() | @*", this, this, XPath.MATCH, errorListener);
   
       m_defaultTextRule.setMatch(defMatch);
   
  @@ -978,7 +979,7 @@
   
       m_defaultTextRule.appendChild(elemValueOf);
   
  -    XPath selectPattern = new XPath(".", this, this, XPath.SELECT);
  +    XPath selectPattern = new XPath(".", this, this, XPath.SELECT, errorListener);
   
       elemValueOf.setSelect(selectPattern);
   
  @@ -987,7 +988,7 @@
   
       m_defaultRootRule.setStylesheet(this);
   
  -    defMatch = new XPath("/", this, this, XPath.MATCH);
  +    defMatch = new XPath("/", this, this, XPath.MATCH, errorListener);
   
       m_defaultRootRule.setMatch(defMatch);
   
  
  
  
  1.15      +27 -3     xml-xalan/java/src/org/apache/xpath/XPath.java
  
  Index: XPath.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/XPath.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- XPath.java	2001/01/02 03:47:13	1.14
  +++ XPath.java	2001/01/07 06:24:40	1.15
  @@ -177,17 +177,22 @@
      * @param prefixResolver A prefix resolver to use to resolve prefixes to 
      *                       namespace URIs.
      * @param type one of {@link #SELECT} or {@link #MATCH}.
  +   * @param errorListener The error listener, or null if default should be used.
      *
      * @throws javax.xml.transform.TransformerException if syntax or other error.
      */
     public XPath(
  -          String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type)
  +          String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type,
  +          ErrorListener errorListener)
               throws javax.xml.transform.TransformerException
     {      
  +    if(null == errorListener)
  +      errorListener = new org.apache.xml.utils.DefaultErrorHandler();
  +    
       m_patternString = exprString;
   
  -    XPathParser parser = new XPathParser();
  -    Compiler compiler = new Compiler(null, locator);
  +    XPathParser parser = new XPathParser(errorListener, locator);
  +    Compiler compiler = new Compiler(errorListener, locator);
   
       if (SELECT == type)
         parser.initXPath(compiler, exprString, prefixResolver);
  @@ -202,6 +207,25 @@
       // System.out.println("expr: "+expr);
       this.setExpression(expr);
   
  +  }
  +  
  +  /**
  +   * Construct an XPath object.  The object must be initialized by the
  +   * XPathParser.initXPath method.
  +   *
  +   * @param exprString The XPath expression.
  +   * @param locator The location of the expression, may be null.
  +   * @param prefixResolver A prefix resolver to use to resolve prefixes to 
  +   *                       namespace URIs.
  +   * @param type one of {@link #SELECT} or {@link #MATCH}.
  +   *
  +   * @throws javax.xml.transform.TransformerException if syntax or other error.
  +   */
  +  public XPath(
  +          String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type)
  +            throws javax.xml.transform.TransformerException
  +  {  
  +    this(exprString, locator, prefixResolver, type, null);    
     }
   
     /**
  
  
  
  1.8       +2 -2      xml-xalan/java/src/org/apache/xpath/XPathAPI.java
  
  Index: XPathAPI.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/XPathAPI.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XPathAPI.java	2000/12/18 00:04:53	1.7
  +++ XPathAPI.java	2001/01/07 06:24:40	1.8
  @@ -262,7 +262,7 @@
         ? ((Document) namespaceNode).getDocumentElement() : namespaceNode);
   
       // Create the XPath object.
  -    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT);
  +    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
   
       // Execute the XPath, and have it return the result
       return xpath.execute(xpathSupport, contextNode, prefixResolver);
  @@ -301,7 +301,7 @@
       //    because XPathContext is weak in a number of areas... perhaps
       //    XPathContext should be done away with.)
       // Create the XPath object.
  -    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT);
  +    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
   
       // Execute the XPath, and have it return the result
       return xpath.execute(new XPathContext(), contextNode, prefixResolver);
  
  
  
  1.18      +2 -2      xml-xalan/java/src/org/apache/xpath/compiler/Compiler.java
  
  Index: Compiler.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/Compiler.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Compiler.java	2000/12/17 05:20:08	1.17
  +++ Compiler.java	2001/01/07 06:24:40	1.18
  @@ -72,7 +72,6 @@
   import org.apache.xpath.operations.Operation;
   import org.apache.xpath.operations.Or;
   import org.apache.xpath.operations.Plus;
  -import org.apache.xpath.operations.Quo;
   import org.apache.xpath.operations.UnaryOperation;
   import org.apache.xpath.operations.Variable;
   import org.apache.xpath.objects.*;
  @@ -1002,7 +1001,7 @@
       }
       else
       {
  -      warn(XPATHErrorResources.WG_FUNCTION_TOKEN_NOT_FOUND, null);  //"function token not found.");
  +      error(XPATHErrorResources.ER_FUNCTION_TOKEN_NOT_FOUND, null);  //"function token not found.");
   
         return null;
       }
  @@ -1131,6 +1130,7 @@
     {
   
       java.lang.String fmsg = XSLMessages.createXPATHMessage(msg, args);
  +    
   
       if (null != m_errorHandler)
       {
  
  
  
  1.11      +13 -4     xml-xalan/java/src/org/apache/xpath/compiler/XPathParser.java
  
  Index: XPathParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/XPathParser.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- XPathParser.java	2001/01/02 03:47:16	1.10
  +++ XPathParser.java	2001/01/07 06:24:40	1.11
  @@ -110,7 +110,11 @@
     /**
      * The parser constructor.
      */
  -  public XPathParser(){}
  +  public XPathParser(ErrorListener errorListener, javax.xml.transform.SourceLocator sourceLocator)
  +  {
  +    m_errorListener = errorListener;
  +    m_sourceLocator = sourceLocator;
  +  }
   
     /**
      * The prefix resolver to map prefixes to namespaces in the OpMap.
  @@ -226,6 +230,9 @@
     /** The error listener where syntax errors are to be sent.
      *  @serial  */
     private ErrorListener m_errorListener;
  +  
  +  /** The source location of the XPath. */
  +  javax.xml.transform.SourceLocator m_sourceLocator;
   
     /**
      * Allow an application to register an error event handler, where syntax 
  @@ -546,7 +553,7 @@
       if (null != ehandler)
       {
         // TO DO: Need to get stylesheet Locator from here.
  -      ehandler.warning(new TransformerException(fmsg));
  +      ehandler.warning(new TransformerException(fmsg, m_sourceLocator));
       }
       else
       {
  @@ -596,14 +603,16 @@
       String fmsg = XSLMessages.createXPATHMessage(msg, args);
       ErrorListener ehandler = this.getErrorListener();
   
  +    TransformerException te = new TransformerException(fmsg, m_sourceLocator);
       if (null != ehandler)
       {
         // TO DO: Need to get stylesheet Locator from here.
  -      ehandler.fatalError(new TransformerException(fmsg));
  +      ehandler.fatalError(te);
       }
       else
       {
  -      System.err.println(fmsg);
  +      // System.err.println(fmsg);
  +      throw te;
       }
     }
   
  
  
  
  1.7       +11 -1     xml-xalan/java/src/org/apache/xpath/res/XPATHErrorResources.java
  
  Index: XPATHErrorResources.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/res/XPATHErrorResources.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XPATHErrorResources.java	2000/12/17 05:21:54	1.6
  +++ XPATHErrorResources.java	2001/01/07 06:24:41	1.7
  @@ -84,7 +84,7 @@
     public static final String WARNING_SUFFIX = "WR";
   
     /** Field MAX_CODE          */
  -  public static final int MAX_CODE = 68;  // this is needed to keep track of the number of messages          
  +  public static final int MAX_CODE = 69;  // this is needed to keep track of the number of messages          
   
     /** Field MAX_WARNING          */
     public static final int MAX_WARNING = 11;  // this is needed to keep track of the number of warnings
  @@ -732,6 +732,16 @@
     {
       contents[ER_XPATH_READOBJECT][1] = "In XPath.readObject: {0}";
     }
  +  
  +  /** Field ER_XPATH_READOBJECT         */
  +  public static final int ER_FUNCTION_TOKEN_NOT_FOUND = 69;
  +
  +  static
  +  {
  +    contents[ER_FUNCTION_TOKEN_NOT_FOUND][1] =
  +      "function token not found.";
  +  }
  +
   
     // Warnings...