pierred 00/10/27 20:20:23
Modified: jasper/src/share/org/apache/jasper/compiler
JspParseEventListener.java Parser.java
ParserController.java
jasper/src/share/org/apache/jasper/resources
messages.properties
Log:
Support for new JSP1.2 feature (new in PFD)
"Added pageEncoding attribute to page directive"
ParserController
- Inspects the document for 'pageEncoding' and 'contentType' page
attributes to set the proper encoding of the page
JspParseEventListener
- Supports new 'pageEncoding' attribute in 'page' directive
Parser
- Added 'pageEncoding' as valid attribute for the page directive
messages.properties
- New error messages for page encoding
Revision Changes Path
1.9 +26 -6
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java
Index: JspParseEventListener.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- JspParseEventListener.java 2000/10/27 21:23:33 1.8
+++ JspParseEventListener.java 2000/10/28 03:20:19 1.9
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v
1.8 2000/10/27 21:23:33 pierred Exp $
- * $Revision: 1.8 $
- * $Date: 2000/10/27 21:23:33 $
+ * $Header:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v
1.9 2000/10/28 03:20:19 pierred Exp $
+ * $Revision: 1.9 $
+ * $Date: 2000/10/28 03:20:19 $
*
* ====================================================================
*
@@ -417,6 +417,7 @@
static final String errorPageStr = "errorPage";
static final String isErrorPageStr = "isErrorPage";
static final String contentTypeStr = "contentType";
+ static final String pageEncodingStr = "pageEncoding";
PageDirectiveHandlerInfo[] pdhis = new PageDirectiveHandlerInfo[] {
@@ -430,6 +431,7 @@
new PageDirectiveHandlerInfo(infoStr, new InfoHandler()),
new PageDirectiveHandlerInfo(isErrorPageStr, new IsErrorPageHandler()),
new PageDirectiveHandlerInfo(contentTypeStr, new ContentTypeHandler()),
+ new PageDirectiveHandlerInfo(pageEncodingStr, new PageEncodingHandler()),
new PageDirectiveHandlerInfo(errorPageStr, new ErrorPageHandler())
};
@@ -453,6 +455,25 @@
}
}
+ static final class PageEncodingHandler implements PageDirectiveHandler {
+ public void handlePageDirectiveAttribute(JspParseEventListener listener,
+ String pageEncoding,
+ Mark start, Mark stop)
+ throws JasperException
+ {
+ if (pageEncoding == null)
+ throw new CompileException(start,
+
Constants.getString("jsp.error.page.invalid.pageencoding"));
+ // We do nothing with pageEncoding.
+ // This is handled by the parser
+ // to set the encoding type on the reader before we even
+ // start parsing the page.
+ // No restriction on one such attribute per translation unit.
+ // We can have one per page.
+ // FIXME: we do not track multiple occurrences per page
+ }
+ }
+
static final class SessionHandler implements PageDirectiveHandler {
public void handlePageDirectiveAttribute(JspParseEventListener listener,
String session,
@@ -744,9 +765,8 @@
Constants.getString("jsp.error.file.not.found",
new Object[]{file}));
} catch (Exception ex) {
- throw new CompileException(
- start,
-
Constants.getString("jsp.error.include.bad.file"));
+ throw new CompileException(start,
+ ex.getMessage());
}
}
xo.append("jsp:directive." + directive, attrs);
1.5 +2 -1
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/Parser.java
Index: Parser.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/Parser.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Parser.java 2000/10/11 19:35:16 1.4
+++ Parser.java 2000/10/28 03:20:21 1.5
@@ -174,7 +174,8 @@
new JspUtil.ValidAttribute ("info"),
new JspUtil.ValidAttribute ("errorPage"),
new JspUtil.ValidAttribute ("isErrorPage"),
- new JspUtil.ValidAttribute ("contentType")
+ new JspUtil.ValidAttribute ("contentType"),
+ new JspUtil.ValidAttribute ("pageEncoding")
};
private static final JspUtil.ValidAttribute[] includeDvalidAttrs = {
1.7 +41 -4
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/ParserController.java
Index: ParserController.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/ParserController.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ParserController.java 2000/10/13 19:57:16 1.6
+++ ParserController.java 2000/10/28 03:20:22 1.7
@@ -60,6 +60,7 @@
import javax.servlet.jsp.tagext.*;
import org.xml.sax.InputSource;
+import org.xml.sax.Attributes;
import org.apache.jasper.*;
@@ -114,6 +115,11 @@
private static final String JSP_ROOT_TAG = "<jsp:root";
/*
+ * The 'new' encoding required to read a page.
+ */
+ private String newEncoding;
+
+ /*
* Information to allow us to dynamically generate the
* DTD to be used to validate the XML document.
* @@@[This has been pulled out for the time being.
@@ -195,11 +201,13 @@
reader = getReader(file, encoding, absFileName);
figureOutJspDocument(file, encoding, reader);
//p("isXml = " + isXml + " hasTaglib = " + hasTaglib);
-
- // dispatch to the proper parser
+ encoding = (newEncoding!=null) ? newEncoding : encoding;
try {
reader.close();
} catch (IOException ex) {}
+
+ // dispatch to the proper parser
+
reader = getReader(file, encoding, absFileName);
if (isXml) {
(new ParserXJspSax(filePath, reader, jspHandler)).parse();
@@ -245,10 +253,37 @@
isXml = true;
} else {
isXml = false;
- return;
}
}
+ // Figure out the encoding of the page
+ // FIXME: We assume xml parser will take care of
+ // encoding for page in XML syntax. Correct?
+ newEncoding = null;
+ jspReader.reset(startMark);
+ while (jspReader.skipUntil("<%@") != null) {
+ jspReader.skipSpaces();
+ if (jspReader.matches("page")) {
+ jspReader.advance(4);
+ jspReader.skipSpaces();
+ Attributes attrs = jspReader.parseTagAttributes();
+ String attribute = "pageEncoding";
+ newEncoding = attrs.getValue("pageEncoding");
+ if (newEncoding == null) {
+ String contentType = attrs.getValue("contentType");
+ if (contentType != null) {
+ int loc = contentType.indexOf("charset=");
+ if (loc != -1) {
+ newEncoding = contentType.substring(loc+8);
+ return;
+ }
+ }
+ } else {
+ return;
+ }
+ }
+ }
+
/* NOT COMPILED
// This is an XML document. Let's see if it uses tag libraries.
jspReader.reset(startMark);
@@ -412,7 +447,9 @@
}
return reader;
} catch (UnsupportedEncodingException ex) {
- throw new JasperException(ex);
+ throw new JasperException(
+ Constants.getString("jsp.error.unsupported.encoding",
+ new Object[]{encoding}));
}
}
1.6 +4 -1
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/resources/messages.properties
Index: messages.properties
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/resources/messages.properties,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- messages.properties 2000/10/11 04:32:23 1.5
+++ messages.properties 2000/10/28 03:20:23 1.6
@@ -1,4 +1,4 @@
-# $Id: messages.properties,v 1.5 2000/10/11 04:32:23 pierred Exp $
+# $Id: messages.properties,v 1.6 2000/10/28 03:20:23 pierred Exp $
#
# Default localized string information
# Localized this the Default Locale as is en_US
@@ -35,6 +35,7 @@
jsp.warning.bad.type=Warning: bad type in .class file
jsp.error.data.file.write=Error while writing data file
jsp.error.page.multiple.contenttypes=Page directive: can't have multiple
occurrences of contentType
+#Page directive: invalid value for pageEncoding
jsp.error.page.invalid.contenttype=Page directive: invalid value for contentType
jsp.error.page.multiple.session=Page directive: can't have multiple occurrences of
session
jsp.error.page.invalid.session=Page directive: invalid value for session
@@ -223,3 +224,5 @@
jsp.error.internal.filenotfound=Internal Error: File {0} not found
jsp.error.parse.xml.invalidPublicId=Invalid PUBLIC ID: {0}
jsp.error.include.flush.invalid.value=Invalid value for the flush attribute: {0}
+jsp.error.page.invalid.pageencoding=Page directive: invalid value for pageEncoding
+jsp.error.unsupported.encoding=Unsupported encoding: {0}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]