Class XmlCompressor
java.lang.Object
com.googlecode.htmlcompressor.compressor.XmlCompressor
- All Implemented Interfaces:
Compressor
Class that compresses given XML source by removing comments, extra spaces and line breaks while preserving content
within CDATA blocks.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final PatternThe Constant cdataPattern.protected static final PatternThe Constant commentPattern.protected static final PatternThe Constant intertagPattern.protected static final PatternThe Constant multispacePattern.protected static final PatternThe Constant tagEndSpacePattern.protected static final PatternThe Constant tagPropertyPattern.protected static final StringThe Constant tempCdataBlock.protected static final PatternThe Constant tempCdataPattern. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe main method that compresses given XML source and returns compressed result.booleanReturnstrueif compression is enabled.booleanReturnstrueif all XML comments will be removed.booleanReturnstrueif all inter-tag whitespace characters will be removed.protected StringpreserveBlocks(String xml, List<String> cdataBlocks) Preserve blocks.protected StringprocessXml(String xml) Process xml.protected StringremoveComments(String xml) Removes the comments.protected StringRemoves the intertag spaces.protected StringRemoves the spaces inside tags.protected StringreturnBlocks(String xml, List<String> cdataBlocks) Return blocks.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 Details
-
TEMP_CD_DATA_BLOCK
-
cdataPattern
The Constant cdataPattern. -
commentPattern
The Constant commentPattern. -
intertagPattern
The Constant intertagPattern. -
tagEndSpacePattern
The Constant tagEndSpacePattern. -
multispacePattern
The Constant multispacePattern. -
tagPropertyPattern
The Constant tagPropertyPattern. -
tempCdataPattern
The Constant tempCdataPattern.
-
-
Constructor Details
-
XmlCompressor
public XmlCompressor()
-
-
Method Details
-
compress
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
-
returnBlocks
-
processXml
-
removeSpacesInsideTags
-
removeIntertagSpaces
-
removeComments
-
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
-