kinman 2003/02/07 16:06:41 Modified: jasper2/src/share/org/apache/jasper Constants.java jasper2/src/share/org/apache/jasper/compiler Generator.java JspReader.java JspUtil.java Parser.java Validator.java jasper2/src/share/org/apache/jasper/resources messages.properties Log: - Implement \$ escape sequence in template text and attributes. - Rewrite template text parser. - Fix some minor bugs. Note: \$ escape sequence in JSP document (XML syntax) not implemented yet. Revision Changes Path 1.13 +7 -0 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/Constants.java Index: Constants.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/Constants.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- Constants.java 22 Jan 2003 21:13:50 -0000 1.12 +++ Constants.java 8 Feb 2003 00:06:40 -0000 1.13 @@ -224,5 +224,12 @@ */ public static final String TEMP_VARIABLE_NAME_PREFIX = "_jspx_temp"; + + /** + * A replacement char for "\$". + * XXX This is a hack to avoid changing EL interpreter to recognize "\$" + */ + public static final char ESC='\u001b'; + public static final String ESCStr="'\\u001b'"; } 1.161 +15 -4 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java Index: Generator.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java,v retrieving revision 1.160 retrieving revision 1.161 diff -u -r1.160 -r1.161 --- Generator.java 5 Feb 2003 23:39:20 -0000 1.160 +++ Generator.java 8 Feb 2003 00:06:40 -0000 1.161 @@ -786,9 +786,14 @@ if (attr.isExpression() || attr.isELInterpreterInput()) { if (attr.isELInterpreterInput()) { + boolean replaceESC = v.indexOf(Constants.ESC) > 0; v = JspUtil.interpreterCall(this.isTagFile, - attr.getValue(), expectedType, defaultPrefix, + v, expectedType, defaultPrefix, "_jspx_fnmap", false ); + // XXX ESC replacement hack + if (replaceESC) { + v = "(" + v + ").replace(" + Constants.ESCStr + ", '$')"; + } } if (encode) { return "java.net.URLEncoder.encode(\"\" + " + v + ")"; @@ -2507,8 +2512,14 @@ } } else if (attr.isELInterpreterInput()) { // run attrValue through the expression interpreter + boolean replaceESC = attrValue.indexOf(Constants.ESC) > 0; attrValue = JspUtil.interpreterCall(this.isTagFile, attrValue, c[0], n.getPrefix(), "_jspx_fnmap", false ); + // XXX hack: Replace ESC with '$' + if (replaceESC) { + attrValue = "(" + attrValue + ").replace(" + + Constants.ESCStr + ", '$')"; + } } else { attrValue = convertString( c[0], attrValue, localName, 1.16 +9 -35 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspReader.java Index: JspReader.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspReader.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- JspReader.java 3 Feb 2003 23:11:58 -0000 1.15 +++ JspReader.java 8 Feb 2003 00:06:40 -0000 1.16 @@ -172,41 +172,12 @@ } /** - * Gets Content until the next potential JSP element. Because all elements - * begin with a '<' we can just move until we see the next one. + * Back up the current cursor by one char, assumes current.cursor > 0, + * and that the char to be pushed back is not '\n'. */ - String nextContent() { - int cur_cursor = current.cursor; - int len = current.stream.length; - char ch; - - if (peekChar() == '\n') { - current.line++; - current.col = 0; - } - else current.col++; - - // pure obsfuscated genius! - while ((++current.cursor < len) && - ((ch = current.stream[current.cursor]) != '<')) { - - if (ch == '$') { - // XXX Make this backward compatible with JSP1.2. - if ((current.cursor+1 < len) && - current.stream[current.cursor+1] == '{') { - break; - } - } else if (ch == '\n') { - current.line++; - current.col = 0; - } else { - current.col++; - } - } - - len = current.cursor - cur_cursor; - - return new String(current.stream, cur_cursor, len); + void pushChar() { + current.cursor--; + current.col--; } String getText(Mark start, Mark stop) throws JasperException { @@ -378,7 +349,10 @@ skip: for (ret = mark(), ch = nextChar() ; ch != -1 ; ret = mark(), prev = ch, ch = nextChar()) { - if (ch == limit.charAt(0) && prev != '\\') { + if (ch == '\\' && prev == '\\') { + ch = 0; // Double \ is not an escape char anymore + } + else if (ch == limit.charAt(0) && prev != '\\') { for (int i = 1 ; i < limlen ; i++) { if (peekChar() == limit.charAt(i)) nextChar(); 1.31 +4 -4 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspUtil.java Index: JspUtil.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspUtil.java,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- JspUtil.java 4 Feb 2003 23:38:46 -0000 1.30 +++ JspUtil.java 8 Feb 2003 00:06:40 -0000 1.31 @@ -220,7 +220,7 @@ returnString = expression; } - return escapeXml(returnString); + return escapeXml(returnString.replace(Constants.ESC, '$')); } /** 1.60 +79 -46 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java Index: Parser.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java,v retrieving revision 1.59 retrieving revision 1.60 diff -u -r1.59 -r1.60 --- Parser.java 4 Feb 2003 00:04:53 -0000 1.59 +++ Parser.java 8 Feb 2003 00:06:40 -0000 1.60 @@ -296,6 +296,7 @@ * | '\"' * | "\'" * | '\>' + * | '\$' * | Char */ private String parseQuoted(String tx) { @@ -324,6 +325,10 @@ if (ch == '\\' || ch == '\"' || ch == '\'' || ch == '>') { buf.append(ch); i += 2; + } else if (ch == '$') { + // Replace "\$" with some special char. XXX hack! + buf.append(Constants.ESC); + i += 2; } else { buf.append('\\'); ++i; @@ -1378,16 +1383,48 @@ * */ private void parseTemplateText(Node parent) throws JasperException { - // Note except for the beginning of a page, the current char is '<'. - // Quoting in template text is handled here. - // JSP2.6 "A literal <% is quoted by <\%" - String templateText = null; - if (reader.matches("<\\%")) { - templateText = "<%"; - } - String content = reader.nextContent(); - templateText = (templateText == null) ? content : templateText+content; - new Node.TemplateText(templateText, start, parent); + + if (!reader.hasMoreInput()) + return; + + CharArrayWriter ttext = new CharArrayWriter(); + // Output the first character + int ch = reader.nextChar(); + ttext.write(ch); + + while (reader.hasMoreInput()) { + ch = reader.nextChar(); + if (ch == '<') { + reader.pushChar(); + break; + } + else if( ch == '$' ) { + if (!reader.hasMoreInput()) { + ttext.write('$'); + break; + } + ch = reader.nextChar(); + if (ch == '{') { + reader.pushChar(); + reader.pushChar(); + break; + } + ttext.write('$'); + } + else if (ch == '\\') { + if (!reader.hasMoreInput()) { + ttext.write('\\'); + break; + } + ch = reader.nextChar(); + // Looking for \% or \$ + if (ch != '%' && ch != '$') { + ttext.write('\\'); + } + } + ttext.write(ch); + } + new Node.TemplateText(ttext.toString(), start, parent); } /* @@ -1408,18 +1445,13 @@ "<jsp:text>" ); } CharArrayWriter ttext = new CharArrayWriter(); - int lastCh = 0; - do { - int ch = reader.nextChar(); - if( ch == -1 ) { - err.jspError(start, "jsp.error.unterminated", - "<jsp:text>" ); - break; - } + while (reader.hasMoreInput()) { + int ch = reader.nextChar(); if( ch == '<' ) { // Check for <![CDATA[ - if (!reader.matches("![CDATA[")) + if (!reader.matches("![CDATA[")) { break; + } start = reader.mark(); Mark stop = reader.skipUntil("]]>"); if (stop == null) { @@ -1428,7 +1460,28 @@ String text = reader.getText(start, stop); ttext.write(text, 0, text.length()); } - else if( (lastCh == '$') && (ch == '{') ) { + else if( ch == '\\') { + if (!reader.hasMoreInput()) { + ttext.write('\\'); + break; + } + ch = reader.nextChar(); + if (ch != '$' ) { + ttext.write('\\'); + } + ttext.write(ch); + } + else if( ch == '$' ) { + if (!reader.hasMoreInput()) { + ttext.write('$'); + break; + } + ch = reader.nextChar(); + if (ch != '{') { + ttext.write('$'); + ttext.write(ch); + continue; + } // Create a template text node new Node.TemplateText( ttext.toString(), start, parent); @@ -1436,35 +1489,15 @@ start = reader.mark(); parseELExpression(parent); - // Go back to parsing template text, unless next - // char is '<': - if( reader.peekChar() == '<' ) { - reader.nextChar(); - ttext = null; - break; - } start = reader.mark(); ttext = new CharArrayWriter(); } else { - if( (lastCh == '$') && (ch != '{') ) { - ttext.write( '$' ); - } - if( ch != '$' ) { - ttext.write( ch ); - } + ttext.write( ch ); } - lastCh = ch; - } while( true ); - - if( ttext != null ) { - if( lastCh == '$' ) { - ttext.write( '$' ); - } - // This could happen if we parsed an EL expression and then - // there was no more template text (see above). - new Node.TemplateText( ttext.toString(), start, parent ); } + + new Node.TemplateText( ttext.toString(), start, parent ); if( !reader.matchesETagWithoutLessThan( "jsp:text" ) ) { err.jspError( start, "jsp.error.unterminated", 1.73 +5 -3 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Validator.java Index: Validator.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Validator.java,v retrieving revision 1.72 retrieving revision 1.73 diff -u -r1.72 -r1.73 --- Validator.java 3 Feb 2003 20:33:35 -0000 1.72 +++ Validator.java 8 Feb 2003 00:06:40 -0000 1.73 @@ -71,6 +71,7 @@ import org.apache.jasper.JasperException; import org.apache.jasper.JspCompilationContext; +import org.apache.jasper.Constants; import org.xml.sax.Attributes; @@ -1039,6 +1040,7 @@ value, false, true, dynamic); } else { + value = value.replace(Constants.ESC, '$'); result = new Node.JspAttribute(qName, uri, localName, value, false, false, dynamic); 1.90 +2 -2 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties Index: messages.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties,v retrieving revision 1.89 retrieving revision 1.90 diff -u -r1.89 -r1.90 --- messages.properties 7 Feb 2003 20:16:18 -0000 1.89 +++ messages.properties 8 Feb 2003 00:06:41 -0000 1.90 @@ -309,7 +309,7 @@ jsp.error.config_pagedir_encoding_mismatch=Page-encoding specified in jsp-property-group ({0}) is different from that specified in page directive ({1}) jsp.error.prolog_pagedir_encoding_mismatch=Page-encoding specified in XML prolog ({0}) is different from that specified in page directive ({1}) jsp.error.prolog_config_encoding_mismatch=Page-encoding specified in XML prolog ({0}) is different from that specified in jsp-property-group ({1}) -jsp.error.attribute.custom.non_rt_with_expr=According to TLD, attribute {0} does not accept any expressions +jsp.error.attribute.custom.non_rt_with_expr=According to TLD or attribute directive in tag file, attribute {0} does not accept any expressions jsp.error.attribute.standard.non_rt_with_expr=The {0} attribute of the {1} standard action does not accept any expressions jsp.error.scripting.variable.missing_name=Unable to determine scripting variable name from attribute {0} jasper.error.emptybodycontent.nonempty=According to TLD, tag {0} must be empty, but is not
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]