tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r450897 - in /tomcat/tc6.0.x/trunk/java/org/apache/jasper: EmbeddedServletOptions.java JspC.java Options.java resources/LocalStrings.properties servlet/JspServletWrapper.java
Date Thu, 28 Sep 2006 15:28:06 GMT
Author: remm
Date: Thu Sep 28 08:28:05 2006
New Revision: 450897

URL: http://svn.apache.org/viewvc?view=rev&rev=450897
Log:
- Add a new init param for controlling display of source fragments.

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java
    tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java
    tomcat/tc6.0.x/trunk/java/org/apache/jasper/Options.java
    tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties
    tomcat/tc6.0.x/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java?view=diff&rev=450897&r1=450896&r2=450897
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java Thu Sep 28 08:28:05
2006
@@ -179,6 +179,13 @@
      */
     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 @@
     }
 
     /**
+     * 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. 
      */
@@ -649,6 +664,19 @@
             } else {
                 if (log.isWarnEnabled()) {
                     log.warn(Localizer.getMessage("jsp.warning.xpoweredBy"));
+                }
+            }
+        }
+        
+        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"));
                 }
             }
         }

Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java?view=diff&rev=450897&r1=450896&r2=450897
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java Thu Sep 28 08:28:05 2006
@@ -385,6 +385,10 @@
         this.xpoweredBy = xpoweredBy;
     }
 
+    public boolean getDisplaySourceFragment() {
+        return true;
+    }
+    
     public boolean getErrorOnUseBeanInvalidClassAttribute() {
         return errorOnUseBeanInvalidClassAttribute;
     }

Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/Options.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/Options.java?view=diff&rev=450897&r1=450896&r2=450897
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/Options.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/Options.java Thu Sep 28 08:28:05 2006
@@ -75,6 +75,12 @@
     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();

Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties?view=diff&rev=450897&r1=450896&r2=450897
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties Thu Sep
28 08:28:05 2006
@@ -155,6 +155,7 @@
 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
@@ -412,6 +413,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

Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java?view=diff&rev=450897&r1=450896&r2=450897
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java Thu Sep 28
08:28:05 2006
@@ -515,43 +515,49 @@
                     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<jspLines.length; i++) {
-                        if (jspLines[i].indexOf(javaLine) != -1) {
-                            jspLineNumber = i+1;
-                            break;
+                        for (int i=jspLineNumber-1; i<jspLines.length; i++) {
+                            if (jspLines[i].indexOf(javaLine) != -1) {
+                                jspLineNumber = i+1;
+                                break;
+                            }
                         }
                     }
-                }
 
-                // copy out a fragment of JSP to display to the user
-                StringBuffer buffer = new StringBuffer(1024);
-                int startIndex = Math.max(0, jspLineNumber-1-3);
-                int endIndex = Math.min(jspLines.length-1, jspLineNumber-1+3);
-
-                for (int i=startIndex;i<=endIndex; ++i) {
-                    buffer.append(i+1);
-                    buffer.append(": ");
-                    buffer.append(jspLines[i]);
-                    buffer.append("\n");
-                }
+                    // copy out a fragment of JSP to display to the user
+                    StringBuffer buffer = new StringBuffer(1024);
+                    int startIndex = Math.max(0, jspLineNumber-1-3);
+                    int endIndex = Math.min(jspLines.length-1, jspLineNumber-1+3);
+
+                    for (int i=startIndex;i<=endIndex; ++i) {
+                        buffer.append(i+1);
+                        buffer.append(": ");
+                        buffer.append(jspLines[i]);
+                        buffer.append("\n");
+                    }
 
-                return new JasperException(
-                                           "Exception in JSP: " + detail.getJspFileName()
+ ":" +
-                                           jspLineNumber + "\n\n" + buffer + "\n\nStacktrace:",
ex);
+                    return new JasperException(Localizer.getMessage
+                            ("jsp.exception", detail.getJspFileName(), "" + jspLineNumber)
+ "\n" + buffer, ex);
+                    
+                } else {
+                    return new JasperException(Localizer.getMessage
+                            ("jsp.exception", detail.getJspFileName(), "" + jspLineNumber),
ex);
+                }
             }
         } catch (Exception je) {
             // If anything goes wrong, just revert to the original behaviour



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message