From b88981ad61aebc6336e4cdb21f89017475d092d5 Mon Sep 17 00:00:00 2001 From: markt Date: Tue, 22 Dec 2009 15:44:54 +0000 Subject: [PATCH] JSP 2.2 implementation (partial) - JSP 3.3.9 - Default content type - JSP 3.3.10 - Default buffer size - JSP 3.3.11 - Error on undeclared namespace git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@893209 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/jasper/compiler/Compiler.java | 12 ++++ java/org/apache/jasper/compiler/JspConfig.java | 79 ++++++++++++++++++++-- java/org/apache/jasper/compiler/PageInfo.java | 26 ++++++- java/org/apache/jasper/compiler/Parser.java | 12 ++-- .../jasper/resources/LocalStrings.properties | 1 + 5 files changed, 118 insertions(+), 12 deletions(-) diff --git a/java/org/apache/jasper/compiler/Compiler.java b/java/org/apache/jasper/compiler/Compiler.java index 77a172e64..1bee5973a 100644 --- a/java/org/apache/jasper/compiler/Compiler.java +++ b/java/org/apache/jasper/compiler/Compiler.java @@ -140,6 +140,18 @@ public abstract class Compiler { pageInfo.setTrimDirectiveWhitespaces(JspUtil.booleanValue(jspProperty .isTrimDirectiveWhitespaces())); } + if (jspProperty.getDefaultContentType() != null) { + pageInfo.setContentType(jspProperty.getDefaultContentType()); + } + if (jspProperty.getBuffer() != null) { + pageInfo.setBufferValue(jspProperty.getBuffer(), null, + errDispatcher); + } + if (jspProperty.isErrorOnUndeclaredNamespace() != null) { + pageInfo.setErrorOnUndeclaredNamespace( + JspUtil.booleanValue( + jspProperty.isErrorOnUndeclaredNamespace())); + } ctxt.checkOutputDir(); String javaFileName = ctxt.getServletJavaFileName(); diff --git a/java/org/apache/jasper/compiler/JspConfig.java b/java/org/apache/jasper/compiler/JspConfig.java index e16148d2b..ac9fd6f91 100644 --- a/java/org/apache/jasper/compiler/JspConfig.java +++ b/java/org/apache/jasper/compiler/JspConfig.java @@ -55,6 +55,9 @@ public class JspConfig { private String defaultIsScriptingInvalid = null; private String defaultDeferedSyntaxAllowedAsLiteral = null; private String defaultTrimDirectiveWhitespaces = null; + private String defaultDefaultContentType = null; + private String defaultBuffer = null; + private String defaultErrorOnUndeclaredNamespace = "false"; private JspProperty defaultJspProperty; public JspConfig(ServletContext ctxt) { @@ -117,6 +120,9 @@ public class JspConfig { Vector includeCoda = new Vector(); String deferredSyntaxAllowedAsLiteral = null; String trimDirectiveWhitespaces = null; + String defaultContentType = null; + String buffer = null; + String errorOnUndeclaredNamespace = null; while (list.hasNext()) { @@ -141,6 +147,12 @@ public class JspConfig { deferredSyntaxAllowedAsLiteral = element.getBody(); else if ("trim-directive-whitespaces".equals(tname)) trimDirectiveWhitespaces = element.getBody(); + else if ("default-content-type".equals(tname)) + defaultContentType = element.getBody(); + else if ("buffer".equals(tname)) + buffer = element.getBody(); + else if ("error-on-undeclared-namespace".equals(tname)) + errorOnUndeclaredNamespace = element.getBody(); } if (urlPatterns.size() == 0) { @@ -197,7 +209,10 @@ public class JspConfig { includePrelude, includeCoda, deferredSyntaxAllowedAsLiteral, - trimDirectiveWhitespaces); + trimDirectiveWhitespaces, + defaultContentType, + buffer, + errorOnUndeclaredNamespace); JspPropertyGroup propertyGroup = new JspPropertyGroup(path, extension, property); @@ -225,7 +240,10 @@ public class JspConfig { defaultIsELIgnored, defaultIsScriptingInvalid, null, null, null, defaultDeferedSyntaxAllowedAsLiteral, - defaultTrimDirectiveWhitespaces); + defaultTrimDirectiveWhitespaces, + defaultDefaultContentType, + defaultBuffer, + defaultErrorOnUndeclaredNamespace); initialized = true; } } @@ -303,6 +321,9 @@ public class JspConfig { JspPropertyGroup pageEncodingMatch = null; JspPropertyGroup deferedSyntaxAllowedAsLiteralMatch = null; JspPropertyGroup trimDirectiveWhitespacesMatch = null; + JspPropertyGroup defaultContentTypeMatch = null; + JspPropertyGroup bufferMatch = null; + JspPropertyGroup errorOnUndeclaredNamespaceMatch = null; Iterator iter = jspProperties.iterator(); while (iter.hasNext()) { @@ -365,6 +386,17 @@ public class JspConfig { trimDirectiveWhitespacesMatch = selectProperty(trimDirectiveWhitespacesMatch, jpg); } + if (jp.getDefaultContentType() != null) { + defaultContentTypeMatch = + selectProperty(defaultContentTypeMatch, jpg); + } + if (jp.getBuffer() != null) { + bufferMatch = selectProperty(bufferMatch, jpg); + } + if (jp.isErrorOnUndeclaredNamespace() != null) { + errorOnUndeclaredNamespaceMatch = + selectProperty(errorOnUndeclaredNamespaceMatch, jpg); + } } @@ -372,8 +404,12 @@ public class JspConfig { String isELIgnored = defaultIsELIgnored; String isScriptingInvalid = defaultIsScriptingInvalid; String pageEncoding = null; - String isDeferedSyntaxAllowedAsLiteral = defaultDeferedSyntaxAllowedAsLiteral; + String isDeferedSyntaxAllowedAsLiteral = + defaultDeferedSyntaxAllowedAsLiteral; String isTrimDirectiveWhitespaces = defaultTrimDirectiveWhitespaces; + String defaultContentType = defaultDefaultContentType; + String buffer = defaultBuffer; + String errorOnUndelcaredNamespace = defaultErrorOnUndeclaredNamespace; if (isXmlMatch != null) { isXml = isXmlMatch.getJspProperty().isXml(); @@ -396,10 +432,22 @@ public class JspConfig { isTrimDirectiveWhitespaces = trimDirectiveWhitespacesMatch.getJspProperty().isTrimDirectiveWhitespaces(); } + if (defaultContentTypeMatch != null) { + defaultContentType = + defaultContentTypeMatch.getJspProperty().getDefaultContentType(); + } + if (bufferMatch != null) { + buffer = bufferMatch.getJspProperty().getBuffer(); + } + if (errorOnUndeclaredNamespaceMatch != null) { + errorOnUndelcaredNamespace = + errorOnUndeclaredNamespaceMatch.getJspProperty().isErrorOnUndeclaredNamespace(); + } return new JspProperty(isXml, isELIgnored, isScriptingInvalid, pageEncoding, includePreludes, includeCodas, - isDeferedSyntaxAllowedAsLiteral, isTrimDirectiveWhitespaces); + isDeferedSyntaxAllowedAsLiteral, isTrimDirectiveWhitespaces, + defaultContentType, buffer, errorOnUndelcaredNamespace); } /** @@ -483,12 +531,18 @@ public class JspConfig { private Vector includeCoda; private String deferedSyntaxAllowedAsLiteral; private String trimDirectiveWhitespaces; + private String defaultContentType; + private String buffer; + private String errorOnUndeclaredNamespace; public JspProperty(String isXml, String elIgnored, String scriptingInvalid, String pageEncoding, Vector includePrelude, Vector includeCoda, String deferedSyntaxAllowedAsLiteral, - String trimDirectiveWhitespaces) { + String trimDirectiveWhitespaces, + String defaultContentType, + String buffer, + String errorOnUndeclaredNamespace) { this.isXml = isXml; this.elIgnored = elIgnored; @@ -498,6 +552,9 @@ public class JspConfig { this.includeCoda = includeCoda; this.deferedSyntaxAllowedAsLiteral = deferedSyntaxAllowedAsLiteral; this.trimDirectiveWhitespaces = trimDirectiveWhitespaces; + this.defaultContentType = defaultContentType; + this.buffer = buffer; + this.errorOnUndeclaredNamespace = errorOnUndeclaredNamespace; } public String isXml() { @@ -531,5 +588,17 @@ public class JspConfig { public String isTrimDirectiveWhitespaces() { return trimDirectiveWhitespaces; } + + public String getDefaultContentType() { + return defaultContentType; + } + + public String getBuffer() { + return buffer; + } + + public String isErrorOnUndeclaredNamespace() { + return errorOnUndeclaredNamespace; + } } } diff --git a/java/org/apache/jasper/compiler/PageInfo.java b/java/org/apache/jasper/compiler/PageInfo.java index 04a04df61..051012256 100644 --- a/java/org/apache/jasper/compiler/PageInfo.java +++ b/java/org/apache/jasper/compiler/PageInfo.java @@ -95,6 +95,8 @@ class PageInfo { private Vector includeCoda; private Vector pluginDcls; // Id's for tagplugin declarations + // JSP 2.2 + private boolean errorOnUndeclaredNamepsace = false; PageInfo(BeanRepository beanRepository, String jspFile) { @@ -454,13 +456,22 @@ class PageInfo { if ("none".equalsIgnoreCase(value)) buffer = 0; else { - if (value == null || !value.endsWith("kb")) - err.jspError(n, "jsp.error.page.invalid.buffer"); + if (value == null || !value.endsWith("kb")) { + if (n == null) { + err.jspError("jsp.error.page.invalid.buffer"); + } else { + err.jspError(n, "jsp.error.page.invalid.buffer"); + } + } try { Integer k = new Integer(value.substring(0, value.length()-2)); buffer = k.intValue() * 1024; } catch (NumberFormatException e) { - err.jspError(n, "jsp.error.page.invalid.buffer"); + if (n == null) { + err.jspError("jsp.error.page.invalid.buffer"); + } else { + err.jspError(n, "jsp.error.page.invalid.buffer"); + } } } @@ -714,4 +725,13 @@ class PageInfo { public Set getVarInfoNames() { return varInfoNames; } + + public boolean isErrorOnUndeclaredNamespace() { + return errorOnUndeclaredNamepsace; + } + + public void setErrorOnUndeclaredNamespace( + boolean errorOnUndeclaredNamespace) { + this.errorOnUndeclaredNamepsace = errorOnUndeclaredNamespace; + } } diff --git a/java/org/apache/jasper/compiler/Parser.java b/java/org/apache/jasper/compiler/Parser.java index dcc6b4f0f..6a6d83da4 100644 --- a/java/org/apache/jasper/compiler/Parser.java +++ b/java/org/apache/jasper/compiler/Parser.java @@ -1217,10 +1217,14 @@ class Parser implements TagConstants { // Check if this is a user-defined tag. String uri = pageInfo.getURI(prefix); if (uri == null) { - reader.reset(start); - // Remember the prefix for later error checking - pageInfo.putNonCustomTagPrefix(prefix, reader.mark()); - return false; + if (pageInfo.isErrorOnUndeclaredNamespace()) { + err.jspError(start, "jsp.error.undeclared_namespace", prefix); + } else { + reader.reset(start); + // Remember the prefix for later error checking + pageInfo.putNonCustomTagPrefix(prefix, reader.mark()); + return false; + } } TagLibraryInfo tagLibInfo = pageInfo.getTaglib(uri); diff --git a/java/org/apache/jasper/resources/LocalStrings.properties b/java/org/apache/jasper/resources/LocalStrings.properties index 0336dc1a9..168c4eece 100644 --- a/java/org/apache/jasper/resources/LocalStrings.properties +++ b/java/org/apache/jasper/resources/LocalStrings.properties @@ -159,6 +159,7 @@ jsp.error.setproperty.invalidSyntax=setProperty: can't have non-null value when jsp.error.setproperty.beanInfoNotFound=setproperty: beanInfo for bean {0} not found jsp.error.setproperty.paramOrValue=setProperty: either param or value can be present jsp.error.setproperty.arrayVal=setProperty: can't set array property {0} through a string constant value +jsp.error.undeclared_namespace=A custom tag was encountered with an undeclared namespace [{0}] jsp.warning.keepgen=Warning: Invalid value for the initParam keepgenerated. Will use the default value of \"false\" jsp.warning.xpoweredBy=Warning: Invalid value for the initParam xpoweredBy. Will use the default value of \"false\" jsp.warning.enablePooling=Warning: Invalid value for the initParam enablePooling. Will use the default value of \"true\" -- 2.11.0