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.
- Author:
- Sergiy Kovalchuk
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Pattern
The Constant cdataPattern.protected static final Pattern
The Constant commentPattern.protected static final Pattern
The Constant intertagPattern.protected static final Pattern
The Constant multispacePattern.protected static final Pattern
The Constant tagEndSpacePattern.protected static final Pattern
The Constant tagPropertyPattern.protected static final String
The Constant tempCdataBlock.protected static final Pattern
The Constant tempCdataPattern. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe main method that compresses given XML source and returns compressed result.boolean
Returnstrue
if compression is enabled.boolean
Returnstrue
if all XML comments will be removed.boolean
Returnstrue
if all inter-tag whitespace characters will be removed.protected String
preserveBlocks
(String xml, List<String> cdataBlocks) Preserve blocks.protected String
processXml
(String xml) Process xml.protected String
removeComments
(String xml) Removes the comments.protected String
Removes the intertag spaces.protected String
Removes the spaces inside tags.protected String
returnBlocks
(String xml, List<String> cdataBlocks) Return blocks.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 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:
compress
in interfaceCompressor
- Parameters:
xml
- XML content to compress- Returns:
- compressed content.
-
preserveBlocks
-
returnBlocks
-
processXml
-
removeSpacesInsideTags
-
removeIntertagSpaces
-
removeComments
-
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
-