com.google.clearsilver.jsilver.template
Class HtmlWhiteSpaceStripper

java.lang.Object
  extended by com.google.clearsilver.jsilver.template.HtmlWhiteSpaceStripper
All Implemented Interfaces:
Appendable

public class HtmlWhiteSpaceStripper
extends Object
implements Appendable

HTML whitespace stripper to be used by JSilver. It removes leading and trailing whitespace, it reduces contiguous whitespace characters with just the first character, and removes lines of nothing but whitespace. It does not strip whitespace inside the following elements:

It also strips out empty lines and leading whitespace inside HTML tags (i.e. between '<' and '>') and inside SCRIPT elements. It leaves trailing whitespace since that is more costly to remove and tends to not be common based on how templates are created (they don't have trailing whitespace).

Loadtests indicate that this class can strip whitespace almost as quickly as just reading every character from a string (20% slower).

While not strictly compatible with the JNI Clearsilver whitestripping function, we are not aware of any differences that yield functionally different HTML output. However, we encourage users to verify for themselves and report any differences.


Constructor Summary
HtmlWhiteSpaceStripper(Appendable out)
          Intermediate Appendable object that strips whitespace as it passes through characters to another Appendable object.
HtmlWhiteSpaceStripper(Appendable out, int level)
          Intermediate Appendable object that strips whitespace as it passes through characters to another Appendable object.
 
Method Summary
 Appendable append(char c)
           
 Appendable append(CharSequence csq)
           
 Appendable append(CharSequence csq, int start, int end)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HtmlWhiteSpaceStripper

public HtmlWhiteSpaceStripper(Appendable out)
Intermediate Appendable object that strips whitespace as it passes through characters to another Appendable object.

Parameters:
out - The Appendable object to dump the stripped output to.

HtmlWhiteSpaceStripper

public HtmlWhiteSpaceStripper(Appendable out,
                              int level)
Intermediate Appendable object that strips whitespace as it passes through characters to another Appendable object.

Parameters:
out - The Appendable object to dump the stripped output to.
level - Ignored for now.
Method Detail

toString

public String toString()
Overrides:
toString in class Object

append

public Appendable append(CharSequence csq)
                  throws IOException
Specified by:
append in interface Appendable
Throws:
IOException

append

public Appendable append(CharSequence csq,
                         int start,
                         int end)
                  throws IOException
Specified by:
append in interface Appendable
Throws:
IOException

append

public Appendable append(char c)
                  throws IOException
Specified by:
append in interface Appendable
Throws:
IOException


Copyright © 2010-2012 Google. All Rights Reserved.