public class XmlCompressor extends Object implements Compressor
Modifier and Type | Field and Description |
---|---|
protected static Pattern |
cdataPattern
The Constant cdataPattern.
|
protected static Pattern |
commentPattern
The Constant commentPattern.
|
protected static Pattern |
intertagPattern
The Constant intertagPattern.
|
protected static Pattern |
multispacePattern
The Constant multispacePattern.
|
protected static Pattern |
tagEndSpacePattern
The Constant tagEndSpacePattern.
|
protected static Pattern |
tagPropertyPattern
The Constant tagPropertyPattern.
|
protected static String |
TEMP_CD_DATA_BLOCK
The Constant tempCdataBlock.
|
protected static Pattern |
tempCdataPattern
The Constant tempCdataPattern.
|
Constructor and Description |
---|
XmlCompressor() |
Modifier and Type | Method and Description |
---|---|
String |
compress(String xml)
The main method that compresses given XML source and returns compressed result.
|
boolean |
isEnabled()
Returns
true if compression is enabled. |
boolean |
isRemoveComments()
Returns
true if all XML comments will be removed. |
boolean |
isRemoveIntertagSpaces()
Returns
true 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 |
removeIntertagSpaces(String xml)
Removes the intertag spaces.
|
protected String |
removeSpacesInsideTags(String xml)
Removes the spaces inside tags.
|
protected String |
returnBlocks(String xml,
List<String> cdataBlocks)
Return blocks.
|
void |
setEnabled(boolean enabled)
If set to
false all compression will be bypassed. |
void |
setRemoveComments(boolean removeComments)
If set to
true all XML comments will be removed. |
void |
setRemoveIntertagSpaces(boolean removeIntertagSpaces)
If set to
true all inter-tag whitespace characters will be removed. |
protected static final String TEMP_CD_DATA_BLOCK
protected static final Pattern cdataPattern
protected static final Pattern commentPattern
protected static final Pattern intertagPattern
protected static final Pattern tagEndSpacePattern
protected static final Pattern multispacePattern
protected static final Pattern tagPropertyPattern
protected static final Pattern tempCdataPattern
public String compress(String xml)
compress
in interface Compressor
xml
- XML content to compressprotected String preserveBlocks(String xml, List<String> cdataBlocks)
xml
- the xmlcdataBlocks
- the cdata blocksprotected String returnBlocks(String xml, List<String> cdataBlocks)
xml
- the xmlcdataBlocks
- the cdata blocksprotected String processXml(String xml)
xml
- the xmlprotected String removeSpacesInsideTags(String xml)
xml
- the xmlprotected String removeIntertagSpaces(String xml)
xml
- the xmlprotected String removeComments(String xml)
xml
- the xmlpublic 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 XML comments will be removed.true
if all XML comments will be removedpublic void setRemoveComments(boolean removeComments)
true
all XML comments will be removed. Default is true
.removeComments
- set true
to remove all XML commentspublic 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 true
.removeIntertagSpaces
- set true
to remove all inter-tag whitespace charactersCopyright © 2009–2020 Jeremy Landis. All rights reserved.