Package com.iizix.js.build.compressors
Class XmlCompressor
- java.lang.Object
- com.iizix.js.build.compressors.XmlCompressor
- All Implemented Interfaces:
Compressor
public class XmlCompressor extends java.lang.Object implements Compressor
Class that compresses given XML source by removing comments, extra spaces and line breaks while preserving content within CDATA blocks.- Author:
- Sergiy Kovalchuk
Field Summary
Fields Modifier and Type Field Description protected static java.util.regex.PatterncdataPatternprotected static java.util.regex.PatterncommentPatternprotected static java.util.regex.PatternintertagPatternprotected static java.util.regex.PatternmultispacePatternprotected static java.util.regex.PatterntagEndSpacePatternprotected static java.util.regex.PatterntagPropertyPatternprotected static java.lang.StringtempCdataBlockprotected static java.util.regex.PatterntempCdataPattern
Constructor Summary
Constructors Constructor Description XmlCompressor()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringcompress(java.lang.String xml)The main method that compresses given XML source and returns compressed result.booleanisEnabled()Returnstrueif compression is enabled.booleanisRemoveComments()Returnstrueif all XML comments will be removed.booleanisRemoveIntertagSpaces()Returnstrueif all inter-tag whitespace characters will be removed.protected java.lang.StringpreserveBlocks(java.lang.String xml, java.util.List<java.lang.String> cdataBlocks)protected java.lang.StringprocessXml(java.lang.String xml)protected java.lang.StringremoveComments(java.lang.String xml)protected java.lang.StringremoveIntertagSpaces(java.lang.String xml)protected java.lang.StringremoveSpacesInsideTags(java.lang.String xml)protected java.lang.StringreturnBlocks(java.lang.String xml, java.util.List<java.lang.String> cdataBlocks)voidsetEnabled(boolean enabled)If set tofalseall compression will be bypassed.voidsetRemoveComments(boolean removeComments)If set totrueall XML comments will be removed.voidsetRemoveIntertagSpaces(boolean removeIntertagSpaces)If set totrueall inter-tag whitespace characters will be removed.
Field Detail
tempCdataBlock
protected static final java.lang.String tempCdataBlock
- See Also:
- Constant Field Values
cdataPattern
protected static final java.util.regex.Pattern cdataPattern
commentPattern
protected static final java.util.regex.Pattern commentPattern
intertagPattern
protected static final java.util.regex.Pattern intertagPattern
tagEndSpacePattern
protected static final java.util.regex.Pattern tagEndSpacePattern
multispacePattern
protected static final java.util.regex.Pattern multispacePattern
tagPropertyPattern
protected static final java.util.regex.Pattern tagPropertyPattern
tempCdataPattern
protected static final java.util.regex.Pattern tempCdataPattern
Method Detail
compress
public java.lang.String compress(java.lang.String xml)
The main method that compresses given XML source and returns compressed result.- Specified by:
compressin interfaceCompressor- Parameters:
xml- XML content to compress- Returns:
- compressed content.
preserveBlocks
protected java.lang.String preserveBlocks(java.lang.String xml, java.util.List<java.lang.String> cdataBlocks)
returnBlocks
protected java.lang.String returnBlocks(java.lang.String xml, java.util.List<java.lang.String> cdataBlocks)
processXml
protected java.lang.String processXml(java.lang.String xml)
removeSpacesInsideTags
protected java.lang.String removeSpacesInsideTags(java.lang.String xml)
removeIntertagSpaces
protected java.lang.String removeIntertagSpaces(java.lang.String xml)
removeComments
protected java.lang.String removeComments(java.lang.String xml)
isEnabled
public boolean isEnabled()
Returnstrueif compression is enabled.- Returns:
trueif compression is enabled.
setEnabled
public void setEnabled(boolean enabled)
If set tofalseall compression will be bypassed. Might be useful for testing purposes. Default istrue.- Parameters:
enabled- setfalseto bypass all compression
isRemoveComments
public boolean isRemoveComments()
Returnstrueif all XML comments will be removed.- Returns:
trueif all XML comments will be removed
setRemoveComments
public void setRemoveComments(boolean removeComments)
If set totrueall XML comments will be removed. Default istrue.- Parameters:
removeComments- settrueto remove all XML comments
isRemoveIntertagSpaces
public boolean isRemoveIntertagSpaces()
Returnstrueif all inter-tag whitespace characters will be removed.- Returns:
trueif all inter-tag whitespace characters will be removed.
setRemoveIntertagSpaces
public void setRemoveIntertagSpaces(boolean removeIntertagSpaces)
If set totrueall inter-tag whitespace characters will be removed. Default istrue.- Parameters:
removeIntertagSpaces- settrueto remove all inter-tag whitespace characters