From 212b1c0333c653dd357e2e46f49330e7aacec2fb Mon Sep 17 00:00:00 2001 From: remm Date: Thu, 28 Sep 2006 15:28:05 +0000 Subject: [PATCH] - Add a new init param for controlling display of source fragments. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@450897 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/jasper/EmbeddedServletOptions.java | 28 +++++++++++ java/org/apache/jasper/JspC.java | 4 ++ java/org/apache/jasper/Options.java | 6 +++ .../jasper/resources/LocalStrings.properties | 3 ++ .../apache/jasper/servlet/JspServletWrapper.java | 58 ++++++++++++---------- 5 files changed, 73 insertions(+), 26 deletions(-) diff --git a/java/org/apache/jasper/EmbeddedServletOptions.java b/java/org/apache/jasper/EmbeddedServletOptions.java index 6c3a32043..9904d4876 100644 --- a/java/org/apache/jasper/EmbeddedServletOptions.java +++ b/java/org/apache/jasper/EmbeddedServletOptions.java @@ -179,6 +179,13 @@ public final class EmbeddedServletOptions implements Options { */ private boolean xpoweredBy; + /** + * Should we include a source fragment in exception messages, which could be displayed + * to the developer ? + */ + private boolean displaySourceFragment = true; + + public String getProperty(String name ) { return settings.getProperty( name ); } @@ -368,6 +375,14 @@ public final class EmbeddedServletOptions implements Options { } /** + * Should we include a source fragment in exception messages, which could be displayed + * to the developer ? + */ + public boolean getDisplaySourceFragment() { + return displaySourceFragment; + } + + /** * Create an EmbeddedServletOptions object using data available from * ServletConfig and ServletContext. */ @@ -653,6 +668,19 @@ public final class EmbeddedServletOptions implements Options { } } + String displaySourceFragment = config.getInitParameter("displaySourceFragment"); + if (displaySourceFragment != null) { + if (displaySourceFragment.equalsIgnoreCase("true")) { + this.displaySourceFragment = true; + } else if (displaySourceFragment.equalsIgnoreCase("false")) { + this.displaySourceFragment = false; + } else { + if (log.isWarnEnabled()) { + log.warn(Localizer.getMessage("jsp.warning.displaySourceFragment")); + } + } + } + // Setup the global Tag Libraries location cache for this // web-application. tldLocationsCache = new TldLocationsCache(context); diff --git a/java/org/apache/jasper/JspC.java b/java/org/apache/jasper/JspC.java index 158a5d62a..5f667bf48 100644 --- a/java/org/apache/jasper/JspC.java +++ b/java/org/apache/jasper/JspC.java @@ -385,6 +385,10 @@ public class JspC implements Options { this.xpoweredBy = xpoweredBy; } + public boolean getDisplaySourceFragment() { + return true; + } + public boolean getErrorOnUseBeanInvalidClassAttribute() { return errorOnUseBeanInvalidClassAttribute; } diff --git a/java/org/apache/jasper/Options.java b/java/org/apache/jasper/Options.java index 62130ff1c..30437685e 100644 --- a/java/org/apache/jasper/Options.java +++ b/java/org/apache/jasper/Options.java @@ -75,6 +75,12 @@ public interface Options { public boolean getDevelopment(); /** + * Should we include a source fragment in exception messages, which could be displayed + * to the developer ? + */ + public boolean getDisplaySourceFragment(); + + /** * Is the generation of SMAP info for JSR45 debugging suppressed? */ public boolean isSmapSuppressed(); diff --git a/java/org/apache/jasper/resources/LocalStrings.properties b/java/org/apache/jasper/resources/LocalStrings.properties index 3c5ef3856..c68e02fcf 100644 --- a/java/org/apache/jasper/resources/LocalStrings.properties +++ b/java/org/apache/jasper/resources/LocalStrings.properties @@ -155,6 +155,7 @@ jsp.warning.reloading=Warning: Invalid value for the initParam reloading. Will u jsp.warning.dumpSmap=Warning: Invalid value for the initParam dumpSmap. Will use the default value of \"false\" jsp.warning.genchararray=Warning: Invalid value for the initParam genStrAsCharArray. Will use the default value of \"false\" jsp.warning.suppressSmap=Warning: Invalid value for the initParam suppressSmap. Will use the default value of \"false\" +jsp.warning.displaySourceFragment=Warning: Invalid value for the initParam displaySourceFragment. Will use the default value of \"true\" jsp.error.badtaglib=Unable to open taglibrary {0} : {1} jsp.error.badGetReader=Cannot create a reader when the stream is not buffered jsp.warning.unknown.element.in.taglib=Unknown element ({0}) in taglib @@ -413,6 +414,8 @@ jsp.error.unbalanced.endtag=The end tag \"</{0}\" is unbalanced jsp.error.invalid.bean=The value for the useBean class attribute {0} is invalid. jsp.error.prefix.use_before_dcl=The prefix {0} specified in this tag directive has been previously used by an action in file {1} line {2}. +jsp.exception=An exception occurred processing JSP page {0} at line {1} + # JSP 2.1 jsp.error.el.template.deferred=#{..} is not allowed in template text jsp.error.el.parse={0} : {1} diff --git a/java/org/apache/jasper/servlet/JspServletWrapper.java b/java/org/apache/jasper/servlet/JspServletWrapper.java index 2d67bb157..8e9ac2219 100644 --- a/java/org/apache/jasper/servlet/JspServletWrapper.java +++ b/java/org/apache/jasper/servlet/JspServletWrapper.java @@ -515,43 +515,49 @@ public class JspServletWrapper { throw new JasperException(ex); } - // Read both files in, so we can inspect them - String[] jspLines = readFile + if (options.getDisplaySourceFragment()) { + + // Read both files in, so we can inspect them + String[] jspLines = readFile (this.ctxt.getResourceAsStream(this.ctxt.getJspFile())); - String[] javaLines = readFile + String[] javaLines = readFile (new FileInputStream(this.ctxt.getServletJavaFileName())); - // If the line contains the opening of a multi-line scriptlet - // block, then the JSP line number we got back is probably - // faulty. Scan forward to match the java line... - if (jspLines[jspLineNumber-1].lastIndexOf("<%") > + // If the line contains the opening of a multi-line scriptlet + // block, then the JSP line number we got back is probably + // faulty. Scan forward to match the java line... + if (jspLines[jspLineNumber-1].lastIndexOf("<%") > jspLines[jspLineNumber-1].lastIndexOf("%>")) { - String javaLine = javaLines[javaLineNumber-1].trim(); + String javaLine = javaLines[javaLineNumber-1].trim(); - for (int i=jspLineNumber-1; i