Author: markt Date: Tue Jun 6 12:10:04 2017 New Revision: 1797782 URL: http://svn.apache.org/viewvc?rev=1797782&view=rev Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=45931 Extend Jasper's timeSpaces option to add support for single which replaces template text that consists entirely of whitespace with a single space character. Based on a patch by Meetesh Karia.
Added: tomcat/trunk/java/org/apache/jasper/TrimSpacesOption.java (with props) Modified: tomcat/trunk/conf/web.xml tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java tomcat/trunk/java/org/apache/jasper/JspC.java tomcat/trunk/java/org/apache/jasper/Options.java tomcat/trunk/java/org/apache/jasper/compiler/TextOptimizer.java tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_es.properties tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_fr.properties tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_ja.properties tomcat/trunk/webapps/docs/changelog.xml tomcat/trunk/webapps/docs/jasper-howto.xml Modified: tomcat/trunk/conf/web.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/conf/web.xml?rev=1797782&r1=1797781&r2=1797782&view=diff ============================================================================== --- tomcat/trunk/conf/web.xml (original) +++ tomcat/trunk/conf/web.xml Tue Jun 6 12:10:04 2017 @@ -233,7 +233,13 @@ <!-- debugging be suppressed? [false] --> <!-- --> <!-- trimSpaces Should template text that consists entirely of --> - <!-- whitespace be removed from the output? [false] --> + <!-- whitespace be removed from the output (true), --> + <!-- replaced with a single space (single) or left --> + <!-- unchanged (false)? Note that if a JSP page or --> + <!-- tag file specifies a trimDirectiveWhitespaces --> + <!-- value of true, that will take precedence over --> + <!-- this configuration setting for that page/tag. --> + <!-- [false] --> <!-- --> <!-- xpoweredBy Determines whether X-Powered-By response --> <!-- header is added by generated servlet. [false] --> Modified: tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java?rev=1797782&r1=1797781&r2=1797782&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java (original) +++ tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java Tue Jun 6 12:10:04 2017 @@ -63,9 +63,9 @@ public final class EmbeddedServletOption private boolean keepGenerated = true; /** - * Should template text that consists entirely of whitespace be removed? + * How should template text that consists entirely of whitespace be handled? */ - private boolean trimSpaces = false; + private TrimSpacesOption trimSpaces = TrimSpacesOption.FALSE; /** * Determines whether tag handler pooling is enabled. @@ -238,11 +238,8 @@ public final class EmbeddedServletOption return keepGenerated; } - /** - * Should template text that consists entirely of whitespace be removed? - */ @Override - public boolean getTrimSpaces() { + public TrimSpacesOption getTrimSpaces() { return trimSpaces; } @@ -499,13 +496,11 @@ public final class EmbeddedServletOption String trimsp = config.getInitParameter("trimSpaces"); if (trimsp != null) { - if (trimsp.equalsIgnoreCase("true")) { - trimSpaces = true; - } else if (trimsp.equalsIgnoreCase("false")) { - trimSpaces = false; - } else { + try { + trimSpaces = TrimSpacesOption.valueOf(trimsp.toUpperCase()); + } catch (IllegalArgumentException iae) { if (log.isWarnEnabled()) { - log.warn(Localizer.getMessage("jsp.warning.trimspaces")); + log.warn(Localizer.getMessage("jsp.warning.trimspaces"), iae); } } } Modified: tomcat/trunk/java/org/apache/jasper/JspC.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/JspC.java?rev=1797782&r1=1797781&r2=1797782&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/JspC.java (original) +++ tomcat/trunk/java/org/apache/jasper/JspC.java Tue Jun 6 12:10:04 2017 @@ -167,7 +167,7 @@ public class JspC extends Task implement protected String classPath = null; protected ClassLoader loader = null; - protected boolean trimSpaces = false; + protected TrimSpacesOption trimSpaces = TrimSpacesOption.FALSE; protected boolean genStringAsCharArray = false; protected boolean validateTld; protected boolean validateXml; @@ -348,7 +348,13 @@ public class JspC extends Task implement } else if (tok.equals(SWITCH_XPOWERED_BY)) { xpoweredBy = true; } else if (tok.equals(SWITCH_TRIM_SPACES)) { - setTrimSpaces(true); + tok = nextArg(); + if (TrimSpacesOption.SINGLE.toString().equalsIgnoreCase(tok)) { + setTrimSpaces(TrimSpacesOption.SINGLE); + } else { + setTrimSpaces(TrimSpacesOption.TRUE); + argPos--; + } } else if (tok.equals(SWITCH_CACHE)) { tok = nextArg(); if ("false".equals(tok)) { @@ -429,22 +435,23 @@ public class JspC extends Task implement return true; } - /** - * {@inheritDoc} - */ @Override - public boolean getTrimSpaces() { + public TrimSpacesOption getTrimSpaces() { return trimSpaces; } + public void setTrimSpaces(TrimSpacesOption trimSpaces) { + this.trimSpaces = trimSpaces; + } + /** - * Sets the option to remove template text that consists entirely of - * whitespace. + * Sets the option to control handling of template text that consists + * entirely of whitespace. * * @param ts New value */ - public void setTrimSpaces(boolean ts) { - this.trimSpaces = ts; + public void setTrimSpaces(String ts) { + this.trimSpaces = TrimSpacesOption.valueOf(ts); } /** Modified: tomcat/trunk/java/org/apache/jasper/Options.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/Options.java?rev=1797782&r1=1797781&r2=1797782&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/Options.java (original) +++ tomcat/trunk/java/org/apache/jasper/Options.java Tue Jun 6 12:10:04 2017 @@ -98,10 +98,13 @@ public interface Options { public boolean isSmapDumped(); /** - * @return <code>true</code> to remove template text that consists entirely - * of whitespace + * @return {@link TrimSpacesOption#TRUE} to remove template text that + * consists only of whitespace from the output completely, + * {@link TrimSpacesOption#SINGLE} to replace such template text + * with a single space or {@link TrimSpacesOption#FALSE} to leave + * such template text unchanged */ - public boolean getTrimSpaces(); + public TrimSpacesOption getTrimSpaces(); /** * Gets the class-id value that is sent to Internet Explorer when using Added: tomcat/trunk/java/org/apache/jasper/TrimSpacesOption.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/TrimSpacesOption.java?rev=1797782&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/jasper/TrimSpacesOption.java (added) +++ tomcat/trunk/java/org/apache/jasper/TrimSpacesOption.java Tue Jun 6 12:10:04 2017 @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jasper; + +public enum TrimSpacesOption { + FALSE, + TRUE, + SINGLE +} Propchange: tomcat/trunk/java/org/apache/jasper/TrimSpacesOption.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/java/org/apache/jasper/compiler/TextOptimizer.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/TextOptimizer.java?rev=1797782&r1=1797781&r2=1797782&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/TextOptimizer.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/TextOptimizer.java Tue Jun 6 12:10:04 2017 @@ -18,6 +18,7 @@ package org.apache.jasper.compiler; import org.apache.jasper.JasperException; import org.apache.jasper.Options; +import org.apache.jasper.TrimSpacesOption; /** */ @@ -29,6 +30,7 @@ public class TextOptimizer { private static class TextCatVisitor extends Node.Visitor { private static final String EMPTY_TEXT = ""; + private static final String SINGLE_SPACE = " "; private final Options options; private final PageInfo pageInfo; @@ -81,10 +83,15 @@ public class TextOptimizer { @Override public void visit(Node.TemplateText n) throws JasperException { - if ((options.getTrimSpaces() || pageInfo.isTrimDirectiveWhitespaces()) - && n.isAllSpace()) { - n.setText(EMPTY_TEXT); - return; + if (n.isAllSpace()) { + if ((options.getTrimSpaces() == TrimSpacesOption.TRUE || + pageInfo.isTrimDirectiveWhitespaces())) { + n.setText(EMPTY_TEXT); + return; + } else if (options.getTrimSpaces() == TrimSpacesOption.SINGLE) { + n.setText(SINGLE_SPACE); + return; + } } if (textNodeCount++ == 0) { Modified: tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties?rev=1797782&r1=1797781&r2=1797782&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties Tue Jun 6 12:10:04 2017 @@ -185,7 +185,8 @@ where options include:\n\ \ -ieplugin <clsid> Java Plugin classid for Internet Explorer\n\ \ -classpath <path> Overrides java.class.path system property\n\ \ -xpoweredBy Add X-Powered-By response header\n\ -\ -trimSpaces Remove template text that consists entirely of whitespace\n\ +\ -trimSpaces [single] Remove template text that consists entirely of whitespace\n\ +\ (if "single", replace such template text with a single space)\n \ -javaEncoding <enc> Set the encoding charset for Java classes (default UTF-8)\n\ \ -source <version> Set the -source argument to the compiler (default 1.8)\n\ \ -target <version> Set the -target argument to the compiler (default 1.8)\n\ Modified: tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_es.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_es.properties?rev=1797782&r1=1797781&r2=1797782&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_es.properties (original) +++ tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_es.properties Tue Jun 6 12:10:04 2017 @@ -181,7 +181,8 @@ y donde <opciones> incluyen:\n\ \ -ieplugin <clsid> Java Plugin classid para Internet Explorer\n\ \ -classpath <path> Pasa por alto la propiedad de sistema java.class.path\n\ \ -xpoweredBy A\u00F1ade cabecera de respuesta X-Powered-By\n\ -\ -trimSpaces Remove template text that consists entirely of whitespace\n\ +\ -trimSpaces [single] Remove template text that consists entirely of whitespace\n\ +\ (if "single", replace such template text with a single space)\n \ -javaEncoding <enc> Set the encoding charset for Java classes (default UTF-8)\n\ \ -source <version> Set the -source argument to the compiler (default 1.8)\n\ \ -target <version> Set the -target argument to the compiler (default 1.8)\n\ Modified: tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_fr.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_fr.properties?rev=1797782&r1=1797781&r2=1797782&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_fr.properties (original) +++ tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_fr.properties Tue Jun 6 12:10:04 2017 @@ -117,7 +117,8 @@ o\u00f9 les options comprennet:\n\ \ -ieplugin <clsid> Le classid du Plugin Java Plugin pour Internet Explorer\n\ \ -classpath <path> Overrides java.class.path system property\n\ \ -xpoweredBy Add X-Powered-By response header\n\ -\ -trimSpaces Remove template text that consists entirely of whitespace\n\ +\ -trimSpaces [single] Remove template text that consists entirely of whitespace\n\ +\ (if "single", replace such template text with a single space)\n \ -javaEncoding <enc> Set the encoding charset for Java classes (default UTF-8)\n\ \ -source <version> Set the -source argument to the compiler (default 1.8)\n\ \ -target <version> Set the -target argument to the compiler (default 1.8)\n\ Modified: tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_ja.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_ja.properties?rev=1797782&r1=1797781&r2=1797782&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_ja.properties (original) +++ tomcat/trunk/java/org/apache/jasper/resources/LocalStrings_ja.properties Tue Jun 6 12:10:04 2017 @@ -157,7 +157,8 @@ JSP\u30d5\u30a1\u30a4\u30eb\u306e\u5834\ \ -ieplugin <clsid> Internet Explorer\u306eJava Plugin\u306eclassid\n\ \ -classpath <path> java.class.path\u30b7\u30b9\u30c6\u30e0\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u4e0a\u66f8\u304d\n\ \ -xpoweredBy X-Powered-By\u30ec\u30b9\u30dd\u30f3\u30b9\u30d8\u30c3\u30c0\u306e\u8ffd\u52a0\n\ -\ -trimSpaces Remove template text that consists entirely of whitespace\n\ +\ -trimSpaces [single] Remove template text that consists entirely of whitespace\n\ +\ (if "single", replace such template text with a single space)\n \ -javaEncoding <enc> Set the encoding charset for Java classes (default UTF-8)\n\ \ -source <version> Set the -source argument to the compiler (default 1.8)\n\ \ -target <version> Set the -target argument to the compiler (default 1.8)\n\ Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1797782&r1=1797781&r2=1797782&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Tue Jun 6 12:10:04 2017 @@ -101,6 +101,12 @@ <bug>44787</bug>: Improve error message when JSP compiler configuration options are not valid. (markt) </fix> + <add> + <bug>45931</bug>: Extend Jasper's <code>timeSpaces</code> option to add + support for <code>single</code> which replaces template text that + consists entirely of whitespace with a single space character. Based on + a patch by Meetesh Karia. (markt) + </add> <fix> <bug>53011</bug>: When pre-compiling with JspC, report all compilation errors rather than stopping after the first error. A new option Modified: tomcat/trunk/webapps/docs/jasper-howto.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/jasper-howto.xml?rev=1797782&r1=1797781&r2=1797782&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/jasper-howto.xml (original) +++ tomcat/trunk/webapps/docs/jasper-howto.xml Tue Jun 6 12:10:04 2017 @@ -192,8 +192,11 @@ debugging be suppressed? <code>true</cod <code>false</code>.</li> <li><strong>trimSpaces</strong> - Should template text that consists entirely of -whitespace be removed? <code>true</code> or <code>false</code>, default -<code>false</code>.</li> +whitespace be removed from the output (<code>true</code>), replaced with a +single space (<code>single</code>) or left unchanged (<code>false</code>)? Note +that if a JSP page or tag file specifies a <code>trimDirectiveWhitespaces</code> +value of <code>true</code>, that will take precedence over this configuration +setting for that page/tag. Default <code>false</code>.</li> <li><strong>xpoweredBy</strong> - Determines whether X-Powered-By response header is added by generated servlet. <code>true</code> or <code>false</code>, --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org