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 Wed, 09 Apr 2003 22:34:43 GMT
luehe       2003/04/09 15:34:42

  Modified:    jasper2/src/share/org/apache/jasper/compiler
                        ParserController.java
  Log:
  Relaxed requirement that <root> element in JSP document must have
  "jsp" prefix. It may have any index and will still be considered a JSP
  document, as long as its index is bound to the JSP namespace
  ("http://java.sun.com/JSP/Page")
  
  This is in line with the latest JSP 2.0 spec clarification.
  
  Revision  Changes    Path
  1.38      +66 -3     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.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- ParserController.java	2 Apr 2003 03:45:08 -0000	1.37
  +++ ParserController.java	9 Apr 2003 22:34:42 -0000	1.38
  @@ -75,7 +75,7 @@
    * @author Pierre Delisle
    * @author Jan Luehe
    */
  -class ParserController {
  +class ParserController implements TagConstants {
   
       private static final String CHARSET = "charset=";
   
  @@ -402,8 +402,7 @@
           Mark startMark = jspReader.mark();
   	if (!isExternal) {
   	    jspReader.reset(startMark);
  -	    Mark mark = jspReader.skipUntil(JSP_ROOT_TAG);
  -	    if (mark != null) {
  +	    if (hasJspRoot(jspReader)) {
   	        isXml = true;
   		if (revert) sourceEnc = "UTF-8";
   		return;
  @@ -483,4 +482,68 @@
   	return fileName;
       }
   
  +    /*
  +     * Checks to see if the given page contains, as its first element, a <root>
  +     * element whose prefix is bound to the JSP namespace, as in:
  +     *
  +     * <wombat:root xmlns:wombat="http://java.sun.com/JSP/Page" version="1.2">
  +     *   ...
  +     * </wombat:root>
  +     *
  +     * @param reader The reader for this page
  +     *
  +     * @return true if this page contains a root element whose prefix is bound
  +     * to the JSP namespace, and false otherwise
  +     */
  +    private boolean hasJspRoot(JspReader reader) throws JasperException {
  +
  +	// <prefix>:root must be the first element
  +	Mark start = null;
  +	while ((start = reader.skipUntil("<")) != null) {
  +	    int c = reader.nextChar();
  +	    if (c != '!' && c != '?') break;
  +	}
  +	if (start == null) {
  +	    return false;
  +	}
  +	Mark stop = reader.skipUntil(":root");
  +	if (stop == null) {
  +	    return false;
  +	}
  +	// call substring to get rid of leading '<'
  +	String prefix = reader.getText(start, stop).substring(1);
  +
  +	start = stop;
  +	stop = reader.skipUntil(">");
  +	if (stop == null) {
  +	    return false;
  +	}
  +
  +	// Determine namespace associated with <root> element's prefix
  +	String root = reader.getText(start, stop);
  +	String xmlnsDecl = "xmlns:" + prefix;
  +	int index = root.indexOf(xmlnsDecl);
  +	if (index == -1) {
  +	    return false;
  +	}
  +	index += xmlnsDecl.length();
  +	while (index < root.length()
  +	           && Character.isSpace(root.charAt(index))) {
  +	    index++;
  +	}
  +	if (index < root.length() && root.charAt(index) == '=') {
  +	    index++;
  +	    while (index < root.length()
  +		       && Character.isSpace(root.charAt(index))) {
  +		index++;
  +	    }
  +	    if (index < root.length() && root.charAt(index++) == '"'
  +		    && root.regionMatches(index, JSP_URI, 0,
  +					  JSP_URI.length())) {
  +		return true;
  +	    }
  +	}
  +
  +	return false;
  +    }
   }
  
  
  

---------------------------------------------------------------------
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