ecarmich    2003/09/01 16:22:56

  Modified:    jasper2/src/share/org/apache/jasper/compiler
                        JspDocumentParser.java
  Log:
  Set Node.startMark correctly in JSP document nodes created from character data.
  This fixes incorrect SMAPping of template text nodes containing line feeds, and 
incorrect
  error reporting for unparseable EL expression nodes.
  
  Revision  Changes    Path
  1.70      +50 -18    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java
  
  Index: JspDocumentParser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java,v
  retrieving revision 1.69
  retrieving revision 1.70
  diff -u -r1.69 -r1.70
  --- JspDocumentParser.java    1 Sep 2003 00:17:35 -0000       1.69
  +++ JspDocumentParser.java    1 Sep 2003 23:22:56 -0000       1.70
  @@ -115,6 +115,18 @@
   
       private Locator locator;
   
  +    //Mark representing the start of the current element.  Note
  +    //that locator.getLineNumber() and locator.getColumnNumber()
  +    //return the line and column numbers for the character
  +    //immediately _following_ the current element.  The underlying
  +    //XMl parser eats white space that is not part of character
  +    //data, so for Nodes that are not created from character data,
  +    //this is the best we can do.  But when we parse character data,
  +    //we get an accurate starting location by starting with startMark
  +    //as set by the previous element, and updating it as we advance
  +    //through the characters.
  +    private Mark startMark;
  +
       // Flag indicating whether we are inside DTD declarations
       private boolean inDTD;
   
  @@ -287,7 +299,7 @@
                   locator);
           }
   
  -        Mark start =
  +        startMark =
               new Mark(path, locator.getLineNumber(), locator.getColumnNumber());
   
           if (attrs != null) {
  @@ -353,7 +365,7 @@
                       nonTaglibAttrs,
                       nonTaglibXmlnsAttrs,
                       taglibAttrs,
  -                    start,
  +                    startMark,
                       current);
           } else {
               node =
  @@ -364,7 +376,7 @@
                       nonTaglibAttrs,
                       nonTaglibXmlnsAttrs,
                       taglibAttrs,
  -                    start,
  +                    startMark,
                       current);
               if (node == null) {
                   node =
  @@ -374,7 +386,7 @@
                           nonTaglibAttrs,
                           nonTaglibXmlnsAttrs,
                           taglibAttrs,
  -                        start,
  +                        startMark,
                           current);
               }
           }
  @@ -417,21 +429,31 @@
           if ((current instanceof Node.JspText)
               || (current instanceof Node.NamedAttribute)
               || !isAllSpace) {
  -            Mark start =
  -                new Mark(
  -                    path,
  -                    locator.getLineNumber(),
  -                    locator.getColumnNumber());
  +
  +            int line = startMark.getLineNumber();
  +            int column = startMark.getColumnNumber();
   
               CharArrayWriter ttext = new CharArrayWriter();
               int limit = offset + len;
               int lastCh = 0;
               for (int i = offset; i < limit; i++) {
                   int ch = buf[i];
  +                if (ch == '\n') {
  +                    column = 1;
  +                    line++;
  +                } else {
  +                    column++;
  +                }
                   if (lastCh == '$' && ch == '{') {
                       if (ttext.size() > 0) {
  -                        new Node.TemplateText(ttext.toString(), start, current);
  +                        new Node.TemplateText(
  +                            ttext.toString(),
  +                            startMark,
  +                            current);
                           ttext = new CharArrayWriter();
  +                        //We subtract two from the column number to
  +                        //account for the '${' that we've already parsed
  +                        startMark = new Mark(path, line, column - 2);
                       }
                       // following "${" to first unquoted "}"
                       i++;
  @@ -448,6 +470,12 @@
   
                           }
                           ch = buf[i];
  +                        if (ch == '\n') {
  +                            column = 1;
  +                            line++;
  +                        } else {
  +                            column++;
  +                        }
                           if (lastCh == '\\' && (singleQ || doubleQ)) {
                               ttext.write(ch);
                               lastCh = 0;
  @@ -456,9 +484,10 @@
                           if (ch == '}') {
                               new Node.ELExpression(
                                   ttext.toString(),
  -                                start,
  +                                startMark,
                                   current);
                               ttext = new CharArrayWriter();
  +                            startMark = new Mark(path, line, column);
                               break;
                           }
                           if (ch == '"')
  @@ -483,9 +512,11 @@
                   ttext.write('$');
               }
               if (ttext.size() > 0) {
  -                new Node.TemplateText(ttext.toString(), start, current);
  +                new Node.TemplateText(ttext.toString(), startMark, current);
               }
           }
  +        startMark =
  +            new Mark(path, locator.getLineNumber(), locator.getColumnNumber());
       }
   
       /*
  @@ -553,12 +584,12 @@
       public void comment(char[] buf, int offset, int len) throws SAXException {
           // ignore comments in the DTD
           if (!inDTD) {
  -            Mark start =
  +            startMark =
                   new Mark(
                       path,
                       locator.getLineNumber(),
                       locator.getColumnNumber());
  -            new Node.Comment(new String(buf, offset, len), start, current);
  +            new Node.Comment(new String(buf, offset, len), startMark, current);
           }
       }
   
  @@ -566,7 +597,8 @@
        * See org.xml.sax.ext.LexicalHandler.
        */
       public void startCDATA() throws SAXException {
  -        // do nothing
  +        startMark =
  +            new Mark(path, locator.getLineNumber(), locator.getColumnNumber());
       }
   
       /*
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to