tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r614981 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry/ main/java/org/apache/tapestry/internal/services/ main/java/org/apache/tapestry/services/ site/apt/ site/apt/guide/ test/java/org/apache/tapestry/integr...
Date Thu, 24 Jan 2008 20:29:28 GMT
Author: hlship
Date: Thu Jan 24 12:29:24 2008
New Revision: 614981

URL: http://svn.apache.org/viewvc?rev=614981&view=rev
Log:
TAPESTRY-2084: Add control over whether whitespace is stripped from templates by default

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryConstants.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/conf.apt
    tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/AppModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryConstants.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryConstants.java?rev=614981&r1=614980&r2=614981&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryConstants.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryConstants.java
Thu Jan 24 12:29:24 2008
@@ -66,8 +66,8 @@
     public static final String RESPONSE_ENCODING = "tapestry.response-encoding";
 
     /**
-     * Indicates whether Tapestry is running in production mode or developer mode.  The primary
difference is
-     * how exceptions are reported.
+     * Indicates whether Tapestry is running in production mode or developer mode.  The primary
difference is how
+     * exceptions are reported.
      */
     public static final String PRODUCTION_MODE_SYMBOL = "tapestry.production-mode";
 
@@ -98,6 +98,12 @@
      * one of these values.
      */
     public static final String SUPPORTED_LOCALES_SYMBOL = "tapestry.supported-locales";
+
+    /**
+     * Controls whether whitespace is compressed by default in templates, or left as is.
The factory default is to
+     * compress whitespace. This can be overridden using the xml:space attribute inside template
elements.
+     */
+    public static final String COMPRESS_WHITESPACE_SYMBOL = "tapestry.compress-whitespace";
 
     private TapestryConstants()
     {

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java?rev=614981&r1=614980&r2=614981&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java
Thu Jan 24 12:29:24 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -14,11 +14,13 @@
 
 package org.apache.tapestry.internal.services;
 
+import org.apache.tapestry.TapestryConstants;
 import org.apache.tapestry.internal.parser.*;
 import static org.apache.tapestry.ioc.IOCConstants.PERTHREAD_SCOPE;
 import org.apache.tapestry.ioc.Location;
 import org.apache.tapestry.ioc.Resource;
 import org.apache.tapestry.ioc.annotations.Scope;
+import org.apache.tapestry.ioc.annotations.Symbol;
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newSet;
 import org.apache.tapestry.ioc.internal.util.InternalUtils;
@@ -60,15 +62,15 @@
     private static final Pattern ID_PATTERN = Pattern.compile("^[a-z]\\w*$", Pattern.CASE_INSENSITIVE);
 
     /**
-     * Any amount of mixed simple whitespace (space, tab, form feed) mixed with at least
one carriage return or line feed,
-     * followed by any amount of whitespace.  Will be reduced to a single linefeed.
+     * Any amount of mixed simple whitespace (space, tab, form feed) mixed with at least
one carriage return or line
+     * feed, followed by any amount of whitespace.  Will be reduced to a single linefeed.
      */
     private static final Pattern REDUCE_LINEBREAKS_PATTERN = Pattern.compile("[ \\t\\f]*[\\r\\n]\\s*",
                                                                              Pattern.MULTILINE);
 
     /**
-     * Used when compressing whitespace, matches any sequence of simple whitespace (space,
tab, formfeed). Applied
-     * after REDUCE_LINEBREAKS_PATTERN.
+     * Used when compressing whitespace, matches any sequence of simple whitespace (space,
tab, formfeed). Applied after
+     * REDUCE_LINEBREAKS_PATTERN.
      */
     private static final Pattern REDUCE_WHITESPACE_PATTERN = Pattern.compile("[ \\t\\f]+",
Pattern.MULTILINE);
 
@@ -90,11 +92,13 @@
 
     private final List<TemplateToken> _tokens = newList();
 
+    private final boolean _compressWhitespaceDefault;
+
     /**
      * Because {@link org.xml.sax.ContentHandler#startPrefixMapping(String, String)} events
arrive before the
      * corresponding {@link org.xml.sax.ContentHandler#startElement(String, String, String,
org.xml.sax.Attributes)}
-     * events, we need to accumlate the {@link org.apache.tapestry.internal.parser.DefineNamespacePrefixToken}s
-     * ahead of time to get the correct ordering in the output tokens list.
+     * events, we need to accumlate the {@link org.apache.tapestry.internal.parser.DefineNamespacePrefixToken}s
ahead of
+     * time to get the correct ordering in the output tokens list.
      */
     private final List<DefineNamespacePrefixToken> _defineNamespaceTokens = newList();
 
@@ -149,10 +153,14 @@
     };
 
 
-    public TemplateParserImpl(Logger logger, Map<String, URL> configuration)
+    public TemplateParserImpl(Logger logger, Map<String, URL> configuration,
+
+                              @Symbol(TapestryConstants.COMPRESS_WHITESPACE_SYMBOL)
+                              boolean compressWhitespaceDefault)
     {
         _logger = logger;
         _configuration = configuration;
+        _compressWhitespaceDefault = compressWhitespaceDefault;
 
         reset();
     }
@@ -177,7 +185,7 @@
 
     public ComponentTemplate parseTemplate(Resource templateResource)
     {
-        _compressWhitespace = true;
+        _compressWhitespace = _compressWhitespaceDefault;
 
         if (_reader == null)
         {
@@ -250,8 +258,8 @@
 
 
     /**
-     * Adds tokens corresponding to the content in the text buffer. For a non-CDATA section,
we also
-     * search for expansions (thus we may add more than one token). Clears the text buffer.
+     * Adds tokens corresponding to the content in the text buffer. For a non-CDATA section,
we also search for
+     * expansions (thus we may add more than one token). Clears the text buffer.
      */
     private void processTextBuffer()
     {
@@ -287,11 +295,11 @@
     }
 
     /**
-     * Scans the text, using a regular expression pattern, for expansion patterns, and adds
-     * appropriate tokens for what it finds.
+     * Scans the text, using a regular expression pattern, for expansion patterns, and adds
appropriate tokens for what
+     * it finds.
      *
-     * @param text to add as {@link org.apache.tapestry.internal.parser.TextToken}s
-     *             and {@link org.apache.tapestry.internal.parser.ExpansionToken}s
+     * @param text to add as {@link org.apache.tapestry.internal.parser.TextToken}s and {@link
+     *             org.apache.tapestry.internal.parser.ExpansionToken}s
      */
     private void addTokensForText(String text)
     {
@@ -352,9 +360,8 @@
     }
 
     /**
-     * Checks to see if currently inside a t:body element (which should always be empty).
Content is
-     * ignored inside a body. If inside a body, then a warning is logged (but only one warning
per
-     * body element).
+     * Checks to see if currently inside a t:body element (which should always be empty).
Content is ignored inside a
+     * body. If inside a body, then a warning is logged (but only one warning per body element).
      *
      * @return true if inside t:body, false otherwise
      */
@@ -526,8 +533,8 @@
     /**
      * @param attributes     the attributes for the element
      * @param namespaceURI   the namespace URI for the element (or the empty string)
-     * @param elementName    the name of the element (to be assigned to the new token), may
be null for a
-     *                       component in the Tapestry namespace
+     * @param elementName    the name of the element (to be assigned to the new token), may
be null for a component in
+     *                       the Tapestry namespace
      * @param identifiedType the type of the element, usually null, but may be the component
type derived from
      */
     private void startPossibleComponent(Attributes attributes, String namespaceURI, String
elementName,

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java?rev=614981&r1=614980&r2=614981&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
Thu Jan 24 12:29:24 2008
@@ -1691,6 +1691,8 @@
 
         configuration.add(TapestryConstants.PRODUCTION_MODE_SYMBOL, "true");
 
+        configuration.add(TapestryConstants.COMPRESS_WHITESPACE_SYMBOL, "true");
+
         // This is designed to make it easy to keep synchronized with script.aculo.ous. As
we
         // support a new version, we create a new folder, and update the path entry. We can
then
         // delete the old version folder (or keep it around). This should be more manageable
than

Modified: tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/conf.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/conf.apt?rev=614981&r1=614980&r2=614981&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/conf.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/conf.apt Thu Jan 24 12:29:24
2008
@@ -82,7 +82,14 @@
   These symbols are always defined in terms of strings, that are coerced to the appropriate
type (a number,
   a boolean, etc.).  Of special note are <time intervals>, which are specified in a
   {{{../../apidocs/org/apache/tapestry/ioc/util/TimeInterval.html}particular format}}.
-  
+
+
+  [tapestry.compress-whitespace]
+
+    A flag (true or false).  When true (the default) whitespace in component templates is
compressed by default
+    (this can be fine-tuned using the standard xml:space attribute on an element in the template).
+    When this flag is false, then whitespace is retained by default (but can still be overridden).
+
   [tapestry.default-cookie-max-age]
     The default time interval that cookies created by Tapestry will be kept in the client
web browser.
     The dfault value is equal to one week. 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt?rev=614981&r1=614980&r2=614981&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt Thu Jan 24 12:29:24 2008
@@ -23,6 +23,8 @@
   * Page instances are now cached more efficiently, with Tapestry attempting to control how
many instances
     are created, and culling unused instances periodically.
 
+  * Component templates are stripped of unnecessary whitespace.
+
   * New Unless component (like an If component, but inverted).
 
   * Support for "password" and "longtext" data types (for use with the BeanEditor), and a
new

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?rev=614981&r1=614980&r2=614981&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
Thu Jan 24 12:29:24 2008
@@ -1449,8 +1449,12 @@
     {
         start("Override Validation Decorator");
 
+        // This is sub-optimal, as it doesn't esnure that the before/after field values really
do wrap around
+        // the field (they do, but that's hard to prove!).
+
         assertSourcePresent(
-                "[Before label for Value]<label for=\"value\" id=\"value:label\">Value</label>[After
label for Value][Before field Value]");
+                "[Before label for Value]<label for=\"value\" id=\"value:label\">Value</label>[After
label for Value]",
+                "[Before field Value]", "[After field Value]");
     }
 
     /**

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/AppModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/AppModule.java?rev=614981&r1=614980&r2=614981&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/AppModule.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/services/AppModule.java
Thu Jan 24 12:29:24 2008
@@ -104,7 +104,8 @@
     {
         configuration.add(TapestryConstants.SUPPORTED_LOCALES_SYMBOL, "en,fr");
         configuration.add(TapestryConstants.PRODUCTION_MODE_SYMBOL, "false");
-        
+        configuration.add(TapestryConstants.COMPRESS_WHITESPACE_SYMBOL, "false");
+
         configuration.add("app.injected-symbol", "Symbol contributed to ApplicationDefaults");
     }
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties?rev=614981&r1=614980&r2=614981&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties Thu Jan 24
12:29:24 2008
@@ -21,7 +21,7 @@
 log4j.appender.A1.layout=org.apache.log4j.PatternLayout
 log4j.appender.A1.layout.ConversionPattern= %d{HH:mm:ss,SSS} [%p] %c{1} %m%n
 
-log4j.category.org.apache.tapestry.corelib.pages=debug
+# log4j.category.org.apache.tapestry.corelib.pages=debug
 
 
 



Mime
View raw message