kinman      2003/11/10 14:26:21

  Modified:    jasper2/src/share/org/apache/jasper
                        EmbeddedServletOptions.java JspC.java Options.java
               jasper2/src/share/org/apache/jasper/compiler Compiler.java
                        TextOptimizer.java
  Log:
  - Provide an option to trim white spaces that appear in a template text
    between two actions/directives.  This also fixes 24506.  Since this is
    NOT spec conformant, the default is don't do.
  
  Revision  Changes    Path
  1.7       +15 -18    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/EmbeddedServletOptions.java
  
  Index: EmbeddedServletOptions.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/EmbeddedServletOptions.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- EmbeddedServletOptions.java       9 Sep 2003 21:46:22 -0000       1.6
  +++ EmbeddedServletOptions.java       10 Nov 2003 22:26:20 -0000      1.7
  @@ -105,12 +105,9 @@
       private boolean keepGenerated = true;
   
       /**
  -     * Do you want support for "large" files? What this essentially
  -     * means is that we generated code so that the HTML data in a JSP
  -     * file is stored separately as opposed to those constant string
  -     * data being used literally in the generated servlet. 
  +     * Should white spaces between directives or actions be trimmed?
        */
  -    private boolean largeFile = false;
  +    private boolean trimSpaces = false;
   
       /**
        * Determines whether tag handler pooling is enabled.
  @@ -228,10 +225,10 @@
       }
       
       /**
  -     * Are we supporting large files?
  +     * Should white spaces between directives or actions be trimmed?
        */
  -    public boolean getLargeFile() {
  -        return largeFile;
  +    public boolean getTrimSpaces() {
  +        return trimSpaces;
       }
       
       public boolean isPoolingEnabled() {
  @@ -394,15 +391,15 @@
           }
               
   
  -        String largeFile = config.getInitParameter("largefile"); 
  -        if (largeFile != null) {
  -            if (largeFile.equalsIgnoreCase("true")) {
  -                this.largeFile = true;
  -            } else if (largeFile.equalsIgnoreCase("false")) {
  -                this.largeFile = false;
  +        String trimsp = config.getInitParameter("trimSpaces"); 
  +        if (trimsp != null) {
  +            if (trimsp.equalsIgnoreCase("true")) {
  +                trimSpaces = true;
  +            } else if (trimsp.equalsIgnoreCase("false")) {
  +                trimSpaces = false;
               } else {
                if (log.isWarnEnabled()) {
  -                 log.warn(Localizer.getMessage("jsp.warning.largeFile"));
  +                 log.warn(Localizer.getMessage("jsp.warning.trimspaces"));
                }
            }
           }
  
  
  
  1.61      +10 -6     
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java
  
  Index: JspC.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- JspC.java 9 Sep 2003 21:46:22 -0000       1.60
  +++ JspC.java 10 Nov 2003 22:26:20 -0000      1.61
  @@ -172,7 +172,7 @@
       private static int die; 
       private String classPath = null;
       private URLClassLoader loader = null;
  -    private boolean largeFile = false;
  +    private boolean trimSpaces = false;
       private boolean xpoweredBy;
       private boolean mappedFile = false;
       private File scratchDir;
  @@ -331,8 +331,12 @@
           return true;
       }
   
  -    public boolean getLargeFile() {
  -        return largeFile;
  +    public boolean getTrimSpaces() {
  +        return trimSpaces;
  +    }
  +
  +    public void setTrimSpaces(boolean ts) {
  +        this.trimSpaces = ts;
       }
   
       public boolean isPoolingEnabled() {
  
  
  
  1.19      +8 -8      
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/Options.java
  
  Index: Options.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/Options.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Options.java      9 Sep 2003 21:46:22 -0000       1.18
  +++ Options.java      10 Nov 2003 22:26:20 -0000      1.19
  @@ -82,11 +82,6 @@
       public boolean getKeepGenerated();
   
       /**
  -     * Are we supporting large files?
  -     */
  -    public boolean getLargeFile();
  -
  -    /**
        * Returns true if tag handler pooling is enabled, false otherwise.
        */
       public boolean isPoolingEnabled();
  @@ -131,6 +126,11 @@
        * Ignored is suppressSmap() is true
        */
       public boolean isSmapDumped();
  +
  +    /**
  +     * Should white spaces between directives or actions be trimmed?
  +     */
  +    public boolean getTrimSpaces();
   
       /**
        * Class ID for use in the plugin tag when the browser is IE. 
  
  
  
  1.74      +1 -1      
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java
  
  Index: Compiler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v
  retrieving revision 1.73
  retrieving revision 1.74
  diff -u -r1.73 -r1.74
  --- Compiler.java     28 Oct 2003 23:04:11 -0000      1.73
  +++ Compiler.java     10 Nov 2003 22:26:20 -0000      1.74
  @@ -268,7 +268,7 @@
        tagPluginManager.apply(pageNodes, errDispatcher, pageInfo);
   
           // Optimization: concatenate contiguous template texts.
  -        TextOptimizer.concatenate(pageNodes);
  +        TextOptimizer.concatenate(this, pageNodes);
   
        // Generate static function mapper codes.
        ELFunctionMapper.map(this, pageNodes);
  
  
  
  1.2       +17 -5     
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TextOptimizer.java
  
  Index: TextOptimizer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TextOptimizer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TextOptimizer.java        28 Oct 2003 23:04:11 -0000      1.1
  +++ TextOptimizer.java        10 Nov 2003 22:26:20 -0000      1.2
  @@ -61,6 +61,7 @@
   package org.apache.jasper.compiler;
   
   import org.apache.jasper.JasperException;
  +import org.apache.jasper.Options;
   
   /**
    */
  @@ -71,11 +72,16 @@
        */
       static class TextCatVisitor extends Node.Visitor {
   
  +        private Options options;
           private int textNodeCount = 0;
           private Node.TemplateText firstTextNode = null;
           private StringBuffer textBuffer;
           private final String emptyText = new String("");
   
  +        public TextCatVisitor(Compiler compiler) {
  +            options = compiler.getCompilationContext().getOptions();
  +        }
  +
           public void doVisit(Node n) throws JasperException {
               collectText();
           }
  @@ -112,6 +118,11 @@
   
           public void visit(Node.TemplateText n) throws JasperException {
   
  +            if (options.getTrimSpaces() && n.isAllSpace()) {
  +                n.setText(emptyText);
  +                return;
  +            }
  +
               if (textNodeCount++ == 0) {
                   firstTextNode = n;
                   textBuffer = new StringBuffer(n.getText());
  @@ -137,9 +148,10 @@
   
       }
   
  -    public static void concatenate(Node.Nodes page) throws JasperException {
  +    public static void concatenate(Compiler compiler, Node.Nodes page)
  +            throws JasperException {
   
  -        TextCatVisitor v = new TextCatVisitor();
  +        TextCatVisitor v = new TextCatVisitor(compiler);
           page.visit(v);
   
        // Cleanup, in case the page ends with a template text
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to