Author: remm
Date: Tue Sep 19 02:41:41 2006
New Revision: 447792
URL: http://svn.apache.org/viewvc?view=rev&rev=447792
Log:
- Add parsing of the two new elements for property groups.
Modified:
tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java
Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java?view=diff&rev=447792&r1=447791&r2=447792
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java Tue Sep
19 02:41:41 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@
* for specifying the JSP configuration information on a JSP page
*
* @author Kin-man Chung
+ * @author Remy Maucherat
*/
public class JspConfig {
@@ -50,13 +51,15 @@
private String defaultIsXml = null; // unspecified
private String defaultIsELIgnored = null; // unspecified
- private String defaultIsScriptingInvalid = "false";
+ private String defaultIsScriptingInvalid = null;
+ private String defaultDefferedSyntaxAllowedAsLitteral = null;
+ private String defaultTrimDirectiveWhitespaces = null;
private JspProperty defaultJspProperty;
public JspConfig(ServletContext ctxt) {
- this.ctxt = ctxt;
+ this.ctxt = ctxt;
}
-
+
private double getVersion(TreeNode webApp) {
if (webApp == null) {
String v = webApp.findAttribute("version");
@@ -76,26 +79,26 @@
try {
URL uri = ctxt.getResource(WEB_XML);
if (uri == null) {
- // no web.xml
+ // no web.xml
return;
- }
+ }
is = uri.openStream();
InputSource ip = new InputSource(is);
ip.setSystemId(uri.toExternalForm());
ParserUtils pu = new ParserUtils();
- TreeNode webApp = pu.parseXMLDocument(WEB_XML, ip);
+ TreeNode webApp = pu.parseXMLDocument(WEB_XML, ip);
- if (webApp == null
+ if (webApp == null
|| getVersion(webApp) < 2.4) {
- defaultIsELIgnored = "true";
- return;
- }
- TreeNode jspConfig = webApp.findChild("jsp-config");
- if (jspConfig == null) {
- return;
- }
+ defaultIsELIgnored = "true";
+ return;
+ }
+ TreeNode jspConfig = webApp.findChild("jsp-config");
+ if (jspConfig == null) {
+ return;
+ }
jspProperties = new Vector();
Iterator jspPropertyList =
jspConfig.findChildren("jsp-property-group");
@@ -111,6 +114,8 @@
String isXml = null;
Vector includePrelude = new Vector();
Vector includeCoda = new Vector();
+ String defferedSyntaxAllowedAsLitteral = null;
+ String trimDirectiveWhitespaces = null;
while (list.hasNext()) {
@@ -131,19 +136,23 @@
includePrelude.addElement(element.getBody());
else if ("include-coda".equals(tname))
includeCoda.addElement(element.getBody());
+ else if
("deferred-syntax-allowed-as-literal".equals(tname))
+ defferedSyntaxAllowedAsLitteral = element.getBody();
+ else if ("trim-directive-whitespaces".equals(tname))
+ trimDirectiveWhitespaces = element.getBody();
}
if (urlPatterns.size() == 0) {
continue;
}
-
+
// Add one JspPropertyGroup for each URL Pattern. This makes
// the matching logic easier.
for( int p = 0; p < urlPatterns.size(); p++ ) {
String urlPattern = (String)urlPatterns.elementAt( p );
String path = null;
String extension = null;
-
+
if (urlPattern.indexOf('*') < 0) {
// Exact match
path = urlPattern;
@@ -156,7 +165,7 @@
} else {
file = urlPattern;
}
-
+
// pattern must be "*", or of the form "*.jsp"
if (file.equals("*")) {
extension = "*";
@@ -172,20 +181,22 @@
if ((path == null && (extension == null || isStar))
|| (path != null && !isStar)) {
if (log.isWarnEnabled()) {
- log.warn(Localizer.getMessage(
- "jsp.warning.bad.urlpattern.propertygroup",
- urlPattern));
+ log.warn(Localizer.getMessage(
+
"jsp.warning.bad.urlpattern.propertygroup",
+ urlPattern));
}
continue;
}
}
JspProperty property = new JspProperty(isXml,
- elIgnored,
- scriptingInvalid,
- pageEncoding,
- includePrelude,
- includeCoda);
+ elIgnored,
+ scriptingInvalid,
+ pageEncoding,
+ includePrelude,
+ includeCoda,
+ defferedSyntaxAllowedAsLitteral,
+ trimDirectiveWhitespaces);
JspPropertyGroup propertyGroup =
new JspPropertyGroup(path, extension, property);
@@ -205,14 +216,15 @@
private void init() throws JasperException {
- if (!initialized) {
- processWebDotXml(ctxt);
- defaultJspProperty = new JspProperty(defaultIsXml,
- defaultIsELIgnored,
- defaultIsScriptingInvalid,
- null, null, null);
- initialized = true;
- }
+ if (!initialized) {
+ processWebDotXml(ctxt);
+ defaultJspProperty = new JspProperty(defaultIsXml,
+ defaultIsELIgnored,
+ defaultIsScriptingInvalid,
+ null, null, null, defaultDefferedSyntaxAllowedAsLitteral,
+ defaultTrimDirectiveWhitespaces);
+ initialized = true;
+ }
}
/**
@@ -220,7 +232,7 @@
* In case of tie, select the first.
*/
private JspPropertyGroup selectProperty(JspPropertyGroup prev,
- JspPropertyGroup curr) {
+ JspPropertyGroup curr) {
if (prev == null) {
return curr;
}
@@ -249,7 +261,7 @@
}
return curr;
}
-
+
/**
* Find a property that best matches the supplied resource.
@@ -258,110 +270,131 @@
*/
public JspProperty findJspProperty(String uri) throws JasperException {
- init();
+ init();
- // JSP Configuration settings do not apply to tag files
- if (jspProperties == null || uri.endsWith(".tag")
- || uri.endsWith(".tagx")) {
- return defaultJspProperty;
- }
-
- String uriPath = null;
- int index = uri.lastIndexOf('/');
- if (index >=0 ) {
- uriPath = uri.substring(0, index+1);
- }
- String uriExtension = null;
- index = uri.lastIndexOf('.');
- if (index >=0) {
- uriExtension = uri.substring(index+1);
- }
-
- Vector includePreludes = new Vector();
- Vector includeCodas = new Vector();
-
- JspPropertyGroup isXmlMatch = null;
- JspPropertyGroup elIgnoredMatch = null;
- JspPropertyGroup scriptingInvalidMatch = null;
- JspPropertyGroup pageEncodingMatch = null;
-
- Iterator iter = jspProperties.iterator();
- while (iter.hasNext()) {
-
- JspPropertyGroup jpg = (JspPropertyGroup) iter.next();
- JspProperty jp = jpg.getJspProperty();
-
- // (arrays will be the same length)
- String extension = jpg.getExtension();
- String path = jpg.getPath();
-
- if (extension == null) {
- // exact match pattern: /a/foo.jsp
- if (!uri.equals(path)) {
- // not matched;
- continue;
- }
- } else {
- // Matching patterns *.ext or /p/*
- if (path != null && uriPath != null &&
- ! uriPath.startsWith(path)) {
- // not matched
- continue;
- }
- if (!extension.equals("*") &&
- !extension.equals(uriExtension)) {
- // not matched
- continue;
- }
- }
- // We have a match
- // Add include-preludes and include-codas
- if (jp.getIncludePrelude() != null) {
- includePreludes.addAll(jp.getIncludePrelude());
- }
- if (jp.getIncludeCoda() != null) {
- includeCodas.addAll(jp.getIncludeCoda());
- }
-
- // If there is a previous match for the same property, remember
- // the one that is more restrictive.
- if (jp.isXml() != null) {
- isXmlMatch = selectProperty(isXmlMatch, jpg);
- }
- if (jp.isELIgnored() != null) {
- elIgnoredMatch = selectProperty(elIgnoredMatch, jpg);
- }
- if (jp.isScriptingInvalid() != null) {
- scriptingInvalidMatch =
- selectProperty(scriptingInvalidMatch, jpg);
- }
- if (jp.getPageEncoding() != null) {
- pageEncodingMatch = selectProperty(pageEncodingMatch, jpg);
- }
- }
-
-
- String isXml = defaultIsXml;
- String isELIgnored = defaultIsELIgnored;
- String isScriptingInvalid = defaultIsScriptingInvalid;
- String pageEncoding = null;
-
- if (isXmlMatch != null) {
- isXml = isXmlMatch.getJspProperty().isXml();
- }
- if (elIgnoredMatch != null) {
- isELIgnored = elIgnoredMatch.getJspProperty().isELIgnored();
- }
- if (scriptingInvalidMatch != null) {
- isScriptingInvalid =
- scriptingInvalidMatch.getJspProperty().isScriptingInvalid();
- }
- if (pageEncodingMatch != null) {
- pageEncoding = pageEncodingMatch.getJspProperty().getPageEncoding();
- }
+ // JSP Configuration settings do not apply to tag files
+ if (jspProperties == null || uri.endsWith(".tag")
+ || uri.endsWith(".tagx")) {
+ return defaultJspProperty;
+ }
- return new JspProperty(isXml, isELIgnored, isScriptingInvalid,
- pageEncoding, includePreludes, includeCodas);
+ String uriPath = null;
+ int index = uri.lastIndexOf('/');
+ if (index >=0 ) {
+ uriPath = uri.substring(0, index+1);
+ }
+ String uriExtension = null;
+ index = uri.lastIndexOf('.');
+ if (index >=0) {
+ uriExtension = uri.substring(index+1);
+ }
+
+ Vector includePreludes = new Vector();
+ Vector includeCodas = new Vector();
+
+ JspPropertyGroup isXmlMatch = null;
+ JspPropertyGroup elIgnoredMatch = null;
+ JspPropertyGroup scriptingInvalidMatch = null;
+ JspPropertyGroup pageEncodingMatch = null;
+ JspPropertyGroup defferedSyntaxAllowedAsLitteralMatch = null;
+ JspPropertyGroup trimDirectiveWhitespacesMatch = null;
+
+ Iterator iter = jspProperties.iterator();
+ while (iter.hasNext()) {
+
+ JspPropertyGroup jpg = (JspPropertyGroup) iter.next();
+ JspProperty jp = jpg.getJspProperty();
+
+ // (arrays will be the same length)
+ String extension = jpg.getExtension();
+ String path = jpg.getPath();
+
+ if (extension == null) {
+ // exact match pattern: /a/foo.jsp
+ if (!uri.equals(path)) {
+ // not matched;
+ continue;
+ }
+ } else {
+ // Matching patterns *.ext or /p/*
+ if (path != null && uriPath != null &&
+ ! uriPath.startsWith(path)) {
+ // not matched
+ continue;
+ }
+ if (!extension.equals("*") &&
+ !extension.equals(uriExtension)) {
+ // not matched
+ continue;
+ }
+ }
+ // We have a match
+ // Add include-preludes and include-codas
+ if (jp.getIncludePrelude() != null) {
+ includePreludes.addAll(jp.getIncludePrelude());
+ }
+ if (jp.getIncludeCoda() != null) {
+ includeCodas.addAll(jp.getIncludeCoda());
+ }
+
+ // If there is a previous match for the same property, remember
+ // the one that is more restrictive.
+ if (jp.isXml() != null) {
+ isXmlMatch = selectProperty(isXmlMatch, jpg);
+ }
+ if (jp.isELIgnored() != null) {
+ elIgnoredMatch = selectProperty(elIgnoredMatch, jpg);
+ }
+ if (jp.isScriptingInvalid() != null) {
+ scriptingInvalidMatch =
+ selectProperty(scriptingInvalidMatch, jpg);
+ }
+ if (jp.getPageEncoding() != null) {
+ pageEncodingMatch = selectProperty(pageEncodingMatch, jpg);
+ }
+ if (jp.isDefferedSyntaxAllowedAsLitteral() != null) {
+ defferedSyntaxAllowedAsLitteralMatch =
+ selectProperty(defferedSyntaxAllowedAsLitteralMatch, jpg);
+ }
+ if (jp.isTrimDirectiveWhitespaces() != null) {
+ trimDirectiveWhitespacesMatch =
+ selectProperty(trimDirectiveWhitespacesMatch, jpg);
+ }
+ }
+
+
+ String isXml = defaultIsXml;
+ String isELIgnored = defaultIsELIgnored;
+ String isScriptingInvalid = defaultIsScriptingInvalid;
+ String pageEncoding = null;
+ String isDefferedSyntaxAllowedAsLitteral =
defaultDefferedSyntaxAllowedAsLitteral;
+ String isTrimDirectiveWhitespaces = defaultTrimDirectiveWhitespaces;
+
+ if (isXmlMatch != null) {
+ isXml = isXmlMatch.getJspProperty().isXml();
+ }
+ if (elIgnoredMatch != null) {
+ isELIgnored = elIgnoredMatch.getJspProperty().isELIgnored();
+ }
+ if (scriptingInvalidMatch != null) {
+ isScriptingInvalid =
+ scriptingInvalidMatch.getJspProperty().isScriptingInvalid();
+ }
+ if (pageEncodingMatch != null) {
+ pageEncoding =
pageEncodingMatch.getJspProperty().getPageEncoding();
+ }
+ if (defferedSyntaxAllowedAsLitteralMatch != null) {
+ isDefferedSyntaxAllowedAsLitteral =
+
defferedSyntaxAllowedAsLitteralMatch.getJspProperty().isDefferedSyntaxAllowedAsLitteral();
+ }
+ if (trimDirectiveWhitespacesMatch != null) {
+ isTrimDirectiveWhitespaces =
+
trimDirectiveWhitespacesMatch.getJspProperty().isTrimDirectiveWhitespaces();
+ }
+
+ return new JspProperty(isXml, isELIgnored, isScriptingInvalid,
+ pageEncoding, includePreludes, includeCodas,
+ isDefferedSyntaxAllowedAsLitteral, isTrimDirectiveWhitespaces);
}
/**
@@ -402,7 +435,7 @@
}
} else {
if ((path == null || path.equals(uriPath)) &&
- (extension.equals("*") || extension.equals(uriExtension)))
{
+ (extension.equals("*") ||
extension.equals(uriExtension))) {
// Matches *, *.ext, /p/*, or /p/*.ext
return true;
}
@@ -412,73 +445,87 @@
}
static class JspPropertyGroup {
- private String path;
- private String extension;
- private JspProperty jspProperty;
-
- JspPropertyGroup(String path, String extension,
- JspProperty jspProperty) {
- this.path = path;
- this.extension = extension;
- this.jspProperty = jspProperty;
- }
-
- public String getPath() {
- return path;
- }
-
- public String getExtension() {
- return extension;
- }
-
- public JspProperty getJspProperty() {
- return jspProperty;
- }
+ private String path;
+ private String extension;
+ private JspProperty jspProperty;
+
+ JspPropertyGroup(String path, String extension,
+ JspProperty jspProperty) {
+ this.path = path;
+ this.extension = extension;
+ this.jspProperty = jspProperty;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public String getExtension() {
+ return extension;
+ }
+
+ public JspProperty getJspProperty() {
+ return jspProperty;
+ }
}
static public class JspProperty {
- private String isXml;
- private String elIgnored;
- private String scriptingInvalid;
- private String pageEncoding;
- private Vector includePrelude;
- private Vector includeCoda;
-
- public JspProperty(String isXml, String elIgnored,
- String scriptingInvalid, String pageEncoding,
- Vector includePrelude, Vector includeCoda) {
-
- this.isXml = isXml;
- this.elIgnored = elIgnored;
- this.scriptingInvalid = scriptingInvalid;
- this.pageEncoding = pageEncoding;
- this.includePrelude = includePrelude;
- this.includeCoda = includeCoda;
- }
-
- public String isXml() {
- return isXml;
- }
-
- public String isELIgnored() {
- return elIgnored;
- }
-
- public String isScriptingInvalid() {
- return scriptingInvalid;
- }
-
- public String getPageEncoding() {
- return pageEncoding;
- }
-
- public Vector getIncludePrelude() {
- return includePrelude;
- }
-
- public Vector getIncludeCoda() {
- return includeCoda;
- }
+ private String isXml;
+ private String elIgnored;
+ private String scriptingInvalid;
+ private String pageEncoding;
+ private Vector includePrelude;
+ private Vector includeCoda;
+ private String defferedSyntaxAllowedAsLitteral;
+ private String trimDirectiveWhitespaces;
+
+ public JspProperty(String isXml, String elIgnored,
+ String scriptingInvalid, String pageEncoding,
+ Vector includePrelude, Vector includeCoda,
+ String defferedSyntaxAllowedAsLitteral,
+ String trimDirectiveWhitespaces) {
+
+ this.isXml = isXml;
+ this.elIgnored = elIgnored;
+ this.scriptingInvalid = scriptingInvalid;
+ this.pageEncoding = pageEncoding;
+ this.includePrelude = includePrelude;
+ this.includeCoda = includeCoda;
+ this.defferedSyntaxAllowedAsLitteral =
defferedSyntaxAllowedAsLitteral;
+ this.trimDirectiveWhitespaces = trimDirectiveWhitespaces;
+ }
+
+ public String isXml() {
+ return isXml;
+ }
+
+ public String isELIgnored() {
+ return elIgnored;
+ }
+
+ public String isScriptingInvalid() {
+ return scriptingInvalid;
+ }
+
+ public String getPageEncoding() {
+ return pageEncoding;
+ }
+
+ public Vector getIncludePrelude() {
+ return includePrelude;
+ }
+
+ public Vector getIncludeCoda() {
+ return includeCoda;
+ }
+
+ public String isDefferedSyntaxAllowedAsLitteral() {
+ return defferedSyntaxAllowedAsLitteral;
+ }
+
+ public String isTrimDirectiveWhitespaces() {
+ return trimDirectiveWhitespaces;
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]