|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.googlecode.htmlcompressor.compressor.HtmlCompressor
public class HtmlCompressor
Class that compresses given HTML source by removing comments, extra spaces and line breaks while preserving content within <pre>, <textarea>, <script> and <style> tags. Can optionally compress content inside <script> or <style> tags using Yahoo YUI Compressor library.
Constructor Summary | |
---|---|
HtmlCompressor()
|
Method Summary | |
---|---|
java.lang.String |
compress(java.lang.String html)
The main method that compresses given HTML source and returns compressed result. |
java.util.List<java.util.regex.Pattern> |
getPreservePatterns()
Returns a list of Patterns defining custom preserving block rules |
int |
getYuiCssLineBreak()
Returns number of symbols per line Yahoo YUI Compressor will use during CSS compression. |
org.mozilla.javascript.ErrorReporter |
getYuiErrorReporter()
Returns ErrorReporter used by YUI Compressor to log error messages
during JavasSript compression |
int |
getYuiJsLineBreak()
Returns number of symbols per line Yahoo YUI Compressor will use during JavaScript compression. |
boolean |
isCompressCss()
Returns true if CSS compression is enabled. |
boolean |
isCompressJavaScript()
Returns true if JavaScript compression is enabled. |
boolean |
isEnabled()
Returns true if compression is enabled. |
boolean |
isRemoveComments()
Returns true if all HTML comments will be removed. |
boolean |
isRemoveIntertagSpaces()
Returns true if all inter-tag whitespace characters will be removed. |
boolean |
isRemoveMultiSpaces()
Returns true if all multiple whitespace characters will be replaced with single spaces. |
boolean |
isRemoveQuotes()
Returns true if all unnecessary quotes will be removed
from tag attributes. |
boolean |
isYuiJsDisableOptimizations()
Returns true if Yahoo YUI Compressor
will disable all the built-in micro optimizations during JavaScript compression. |
boolean |
isYuiJsNoMunge()
Returns true if Yahoo YUI Compressor
will only minify javascript without obfuscating local symbols. |
boolean |
isYuiJsPreserveAllSemiColons()
Returns true if Yahoo YUI Compressor
will preserve unnecessary semicolons during JavaScript compression. |
void |
setCompressCss(boolean compressCss)
Enables CSS compression within <style> tags using Yahoo YUI Compressor if set to true . |
void |
setCompressJavaScript(boolean compressJavaScript)
Enables JavaScript compression within <script> tags using Yahoo YUI Compressor if set to true . |
void |
setEnabled(boolean enabled)
If set to false all compression will be bypassed. |
void |
setPreservePatterns(java.util.List<java.util.regex.Pattern> preservePatterns)
This method allows setting custom block preservation rules defined by regular expression patterns. |
void |
setRemoveComments(boolean removeComments)
If set to true all HTML comments will be removed. |
void |
setRemoveIntertagSpaces(boolean removeIntertagSpaces)
If set to true all inter-tag whitespace characters will be removed. |
void |
setRemoveMultiSpaces(boolean removeMultiSpaces)
If set to true all multiple whitespace characters will be replaced with single spaces. |
void |
setRemoveQuotes(boolean removeQuotes)
If set to true all unnecessary quotes will be removed
from tag attributes. |
void |
setYuiCssLineBreak(int yuiCssLineBreak)
Tells Yahoo YUI Compressor to break lines after the specified number of symbols during CSS compression. |
void |
setYuiErrorReporter(org.mozilla.javascript.ErrorReporter yuiErrorReporter)
Sets ErrorReporter that YUI Compressor will use for reporting errors during
JavaScript compression. |
void |
setYuiJsDisableOptimizations(boolean yuiJsDisableOptimizations)
Tells Yahoo YUI Compressor to disable all the built-in micro optimizations during JavaScript compression. |
void |
setYuiJsLineBreak(int yuiJsLineBreak)
Tells Yahoo YUI Compressor to break lines after the specified number of symbols during JavaScript compression. |
void |
setYuiJsNoMunge(boolean yuiJsNoMunge)
Tells Yahoo YUI Compressor to only minify javascript without obfuscating local symbols. |
void |
setYuiJsPreserveAllSemiColons(boolean yuiJsPreserveAllSemiColons)
Tells Yahoo YUI Compressor to preserve unnecessary semicolons during JavaScript compression. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HtmlCompressor()
Method Detail |
---|
public java.lang.String compress(java.lang.String html) throws java.lang.Exception
compress
in interface Compressor
html
- HTML content to compress
java.lang.Exception
public boolean isCompressJavaScript()
true
if JavaScript compression is enabled.
public void setCompressJavaScript(boolean compressJavaScript)
true
. Default is false
for performance reasons.
Note: Compressing JavaScript is not recommended if pages are compressed dynamically on-the-fly because of performance impact. You should consider putting JavaScript into a separate file and compressing it using standalone YUICompressor for example.
compressJavaScript
- set true
to enable JavaScript compression.
Default is false
public boolean isCompressCss()
true
if CSS compression is enabled.
public void setCompressCss(boolean compressCss)
true
. Default is false
for performance reasons.
Note: Compressing CSS is not recommended if pages are compressed dynamically on-the-fly because of performance impact. You should consider putting CSS into a separate file and compressing it using standalone YUICompressor for example.
compressCss
- set true
to enable CSS compression.
Default is false
public boolean isYuiJsNoMunge()
true
if Yahoo YUI Compressor
will only minify javascript without obfuscating local symbols.
This corresponds to --nomunge
command line option.
nomunge
parameter value used for JavaScript compression.public void setYuiJsNoMunge(boolean yuiJsNoMunge)
--nomunge
command line option.
This option has effect only if JavaScript compression is enabled.
Default is false
.
yuiJsNoMunge
- set true to enable nomunge
mode- See Also:
- Yahoo YUI Compressor
public boolean isYuiJsPreserveAllSemiColons()
true
if Yahoo YUI Compressor
will preserve unnecessary semicolons during JavaScript compression.
This corresponds to --preserve-semi
command line option.
preserve-semi
parameter value used for JavaScript compression.public void setYuiJsPreserveAllSemiColons(boolean yuiJsPreserveAllSemiColons)
--preserve-semi
command line option.
This option has effect only if JavaScript compression is enabled.
Default is false
.
yuiJsPreserveAllSemiColons
- set true to enable preserve-semi
mode- See Also:
- Yahoo YUI Compressor
public boolean isYuiJsDisableOptimizations()
true
if Yahoo YUI Compressor
will disable all the built-in micro optimizations during JavaScript compression.
This corresponds to --disable-optimizations
command line option.
disable-optimizations
parameter value used for JavaScript compression.public void setYuiJsDisableOptimizations(boolean yuiJsDisableOptimizations)
--disable-optimizations
command line option.
This option has effect only if JavaScript compression is enabled.
Default is false
.
yuiJsDisableOptimizations
- set true to enable
disable-optimizations
mode- See Also:
- Yahoo YUI Compressor
public int getYuiJsLineBreak()
--line-break
command line option.
line-break
parameter value used for JavaScript compression.public void setYuiJsLineBreak(int yuiJsLineBreak)
--line-break
command line option.
This option has effect only if JavaScript compression is enabled.
Default is -1
to disable line breaks.
yuiJsLineBreak
- set number of symbols per linepublic int getYuiCssLineBreak()
--line-break
command line option.
line-break
parameter value used for CSS compression.public void setYuiCssLineBreak(int yuiCssLineBreak)
--line-break
command line option.
This option has effect only if CSS compression is enabled.
Default is -1
to disable line breaks.
yuiCssLineBreak
- set number of symbols per linepublic boolean isRemoveQuotes()
true
if all unnecessary quotes will be removed
from tag attributes.
public void setRemoveQuotes(boolean removeQuotes)
true
all unnecessary quotes will be removed
from tag attributes. Default is false
.
Note: Even though quotes are removed only when it is safe to do so, it still might break strict HTML validation. Turn this option on only if a page validation is not very important or to squeeze the most out of the compression. This option has no performance impact.
removeQuotes
- set true
to remove unnecessary quotes from tag attributespublic boolean isEnabled()
true
if compression is enabled.
true
if compression is enabled.public void setEnabled(boolean enabled)
false
all compression will be bypassed. Might be useful for testing purposes.
Default is true
.
enabled
- set false
to bypass all compressionpublic boolean isRemoveComments()
true
if all HTML comments will be removed.
true
if all HTML comments will be removedpublic void setRemoveComments(boolean removeComments)
true
all HTML comments will be removed.
Default is true
.
removeComments
- set true
to remove all HTML commentspublic boolean isRemoveMultiSpaces()
true
if all multiple whitespace characters will be replaced with single spaces.
true
if all multiple whitespace characters will be replaced with single spaces.public void setRemoveMultiSpaces(boolean removeMultiSpaces)
true
all multiple whitespace characters will be replaced with single spaces.
Default is true
.
removeMultiSpaces
- set true
to replace all multiple whitespace characters
will single spaces.public boolean isRemoveIntertagSpaces()
true
if all inter-tag whitespace characters will be removed.
true
if all inter-tag whitespace characters will be removed.public void setRemoveIntertagSpaces(boolean removeIntertagSpaces)
true
all inter-tag whitespace characters will be removed.
Default is false
.
Note: It is fairly safe to turn this option on unless you
rely on spaces for page formatting. Even if you do, you can always preserve
required spaces with
. This option has no performance impact.
removeIntertagSpaces
- set true
to remove all inter-tag whitespace characterspublic java.util.List<java.util.regex.Pattern> getPreservePatterns()
Pattern
objects defining rules for preserving block rulespublic void setPreservePatterns(java.util.List<java.util.regex.Pattern> preservePatterns)
Custom preservation rules have higher priority than default rules. Priority between custom rules are defined by their position in a list (beginning of a list has higher priority).
preservePatterns
- List of Pattern
objects that will be
used to skip matched blocks during compressionpublic org.mozilla.javascript.ErrorReporter getYuiErrorReporter()
ErrorReporter
used by YUI Compressor to log error messages
during JavasSript compression
ErrorReporter
used by YUI Compressor to log error messages
during JavasSript compressionpublic void setYuiErrorReporter(org.mozilla.javascript.ErrorReporter yuiErrorReporter)
ErrorReporter
that YUI Compressor will use for reporting errors during
JavaScript compression. If no ErrorReporter
was provided a NullPointerException
will be throuwn in case of an error during the compression.
For simple error reporting that uses System.err
stream
DefaultErrorReporter
can be used.
yuiErrorReporter
- ErrorReporter that will be used by YUI Compressor- See Also:
DefaultErrorReporter
,
Yahoo YUI Compressor,
ErrorReporter Interface
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |