tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu...@apache.org
Subject cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler ParserController.java
Date Fri, 25 Apr 2003 00:20:57 GMT
luehe       2003/04/24 17:20:57

  Modified:    jasper2/src/share/org/apache/jasper/compiler
                        ParserController.java
  Log:
  When determining page encoding of JSP page in standard syntax,
  consider page directive of form <jsp:directive.page>, in addition to
  <%@ page %>.
  
  Revision  Changes    Path
  1.39      +48 -16    jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java
  
  Index: ParserController.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- ParserController.java	9 Apr 2003 22:34:42 -0000	1.38
  +++ ParserController.java	25 Apr 2003 00:20:57 -0000	1.39
  @@ -419,7 +419,7 @@
   	 */
   	sourceEnc = jspConfigPageEnc;
   	if (sourceEnc == null) {
  -	    sourceEnc = getSourceEncodingForJspSyntax(jspReader, startMark);
  +	    sourceEnc = getPageEncodingForJspSyntax(jspReader, startMark);
   	}
   
   	return;
  @@ -428,38 +428,70 @@
       /*
        * Determines page source encoding for JSP page or tag file in JSP syntax
        */
  -    private String getSourceEncodingForJspSyntax(JspReader jspReader,
  +    private String getPageEncodingForJspSyntax(JspReader jspReader,
   						 Mark startMark)
   	        throws JasperException {
   
   	String encoding = null;
   
  +	/*
  +	 * Determine page encoding from directive of the form <%@ page %> or
  +	 * <%@ tag %>
  +	 */
   	jspReader.reset(startMark);
   	while (jspReader.skipUntil("<%@") != null) {
   	    jspReader.skipSpaces();
   	    // compare for "tag ", so we don't match "taglib"
   	    if (jspReader.matches("tag ") || jspReader.matches("page")) {
   		jspReader.skipSpaces();
  -		Attributes attrs = Parser.parseAttributes(this, jspReader);
  -		encoding = attrs.getValue("pageEncoding");
  -		if (encoding != null) {
  -		    break;
  -		}
  -		String contentType = attrs.getValue("contentType");
  -		if (contentType != null) {
  -		    int loc = contentType.indexOf(CHARSET);
  -		    if (loc != -1) {
  -			encoding = contentType.substring(loc
  -							 + CHARSET.length());
  -			break;
  -		    }
  -		}
  +		encoding = getPageEncodingFromDirective(
  +                        Parser.parseAttributes(this, jspReader));
  +		if (encoding != null) break;
  +	    }
  +	}
  +
  +	if (encoding == null) {
  +	    /*
  +	     * Determine page encoding from page directive of the form
  +	     * <jsp:directive.page>
  +	     */
  +	    jspReader.reset(startMark);
  +	    while (jspReader.skipUntil("<jsp:directive.page") != null) {
  +		jspReader.skipSpaces();
  +		encoding = getPageEncodingFromDirective(
  +                        Parser.parseAttributes(this, jspReader));
  +		if (encoding != null) break;
   	    }
   	}
   
   	if (encoding == null) {
   	    // Default to "ISO-8859-1" per JSP spec
   	    encoding = "ISO-8859-1";
  +	}
  +
  +	return encoding;
  +    }
  +
  +    /*
  +     * Scans the given attributes for the 'pageEncoding' attribute, if present,
  +     * or the 'contentType' attribute, and gets the page encoding from them.
  +     *
  +     * In the case of the 'contentType' attribute, the page encoding is taken
  +     * from its 'charset' component.
  +     *
  +     * @param attrs The attributes from which to determine the page encoding
  +     * @return The page encoding
  +     */
  +    private String getPageEncodingFromDirective(Attributes attrs) {
  +	String encoding = attrs.getValue("pageEncoding");
  +	if (encoding == null) {
  +	    String contentType = attrs.getValue("contentType");
  +	    if (contentType != null) {
  +		int loc = contentType.indexOf(CHARSET);
  +		if (loc != -1) {
  +		    encoding = contentType.substring(loc + CHARSET.length());
  +		}
  +	    }
   	}
   
   	return encoding;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message