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.Pattern
cdataPattern
protected static java.util.regex.Pattern
commentPattern
protected static java.util.regex.Pattern
intertagPattern
protected static java.util.regex.Pattern
multispacePattern
protected static java.util.regex.Pattern
tagEndSpacePattern
protected static java.util.regex.Pattern
tagPropertyPattern
protected static java.lang.String
tempCdataBlock
protected static java.util.regex.Pattern
tempCdataPattern
Constructor Summary
Constructors Constructor Description XmlCompressor()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
compress(java.lang.String xml)
The main method that compresses given XML source and returns compressed result.boolean
isEnabled()
Returnstrue
if compression is enabled.boolean
isRemoveComments()
Returnstrue
if all XML comments will be removed.boolean
isRemoveIntertagSpaces()
Returnstrue
if all inter-tag whitespace characters will be removed.protected java.lang.String
preserveBlocks(java.lang.String xml, java.util.List<java.lang.String> cdataBlocks)
protected java.lang.String
processXml(java.lang.String xml)
protected java.lang.String
removeComments(java.lang.String xml)
protected java.lang.String
removeIntertagSpaces(java.lang.String xml)
protected java.lang.String
removeSpacesInsideTags(java.lang.String xml)
protected java.lang.String
returnBlocks(java.lang.String xml, java.util.List<java.lang.String> cdataBlocks)
void
setEnabled(boolean enabled)
If set tofalse
all compression will be bypassed.void
setRemoveComments(boolean removeComments)
If set totrue
all XML comments will be removed.void
setRemoveIntertagSpaces(boolean removeIntertagSpaces)
If set totrue
all 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:
compress
in 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()
Returnstrue
if compression is enabled.- Returns:
true
if compression is enabled.
setEnabled
public void setEnabled(boolean enabled)
If set tofalse
all compression will be bypassed. Might be useful for testing purposes. Default istrue
.- Parameters:
enabled
- setfalse
to bypass all compression
isRemoveComments
public boolean isRemoveComments()
Returnstrue
if all XML comments will be removed.- Returns:
true
if all XML comments will be removed
setRemoveComments
public void setRemoveComments(boolean removeComments)
If set totrue
all XML comments will be removed. Default istrue
.- Parameters:
removeComments
- settrue
to remove all XML comments
isRemoveIntertagSpaces
public boolean isRemoveIntertagSpaces()
Returnstrue
if all inter-tag whitespace characters will be removed.- Returns:
true
if all inter-tag whitespace characters will be removed.
setRemoveIntertagSpaces
public void setRemoveIntertagSpaces(boolean removeIntertagSpaces)
If set totrue
all inter-tag whitespace characters will be removed. Default istrue
.- Parameters:
removeIntertagSpaces
- settrue
to remove all inter-tag whitespace characters