Class XmlCompressor

java.lang.Object
com.iizix.js.build.compressors.XmlCompressor
All Implemented Interfaces:
Compressor

public class XmlCompressor extends 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 Details Link icon

    • tempCdataBlock Link icon

      protected static final String tempCdataBlock
      See Also:
    • cdataPattern Link icon

      protected static final Pattern cdataPattern
    • commentPattern Link icon

      protected static final Pattern commentPattern
    • intertagPattern Link icon

      protected static final Pattern intertagPattern
    • tagEndSpacePattern Link icon

      protected static final Pattern tagEndSpacePattern
    • multispacePattern Link icon

      protected static final Pattern multispacePattern
    • tagPropertyPattern Link icon

      protected static final Pattern tagPropertyPattern
    • tempCdataPattern Link icon

      protected static final Pattern tempCdataPattern
  • Constructor Details Link icon

    • XmlCompressor Link icon

      public XmlCompressor()
  • Method Details Link icon

    • compress Link icon

      public String compress(String xml)
      The main method that compresses given XML source and returns compressed result.
      Specified by:
      compress in interface Compressor
      Parameters:
      xml - XML content to compress
      Returns:
      compressed content.
    • preserveBlocks Link icon

      protected String preserveBlocks(String xml, List<String> cdataBlocks)
    • returnBlocks Link icon

      protected String returnBlocks(String xml, List<String> cdataBlocks)
    • processXml Link icon

      protected String processXml(String xml)
    • removeSpacesInsideTags Link icon

      protected String removeSpacesInsideTags(String xml)
    • removeIntertagSpaces Link icon

      protected String removeIntertagSpaces(String xml)
    • removeComments Link icon

      protected String removeComments(String xml)
    • isEnabled Link icon

      public boolean isEnabled()
      Returns true if compression is enabled.
      Returns:
      true if compression is enabled.
    • setEnabled Link icon

      public void setEnabled(boolean enabled)
      If set to false all compression will be bypassed. Might be useful for testing purposes. Default is true.
      Parameters:
      enabled - set false to bypass all compression
    • isRemoveComments Link icon

      public boolean isRemoveComments()
      Returns true if all XML comments will be removed.
      Returns:
      true if all XML comments will be removed
    • setRemoveComments Link icon

      public void setRemoveComments(boolean removeComments)
      If set to true all XML comments will be removed. Default is true.
      Parameters:
      removeComments - set true to remove all XML comments
    • isRemoveIntertagSpaces Link icon

      public boolean isRemoveIntertagSpaces()
      Returns true if all inter-tag whitespace characters will be removed.
      Returns:
      true if all inter-tag whitespace characters will be removed.
    • setRemoveIntertagSpaces Link icon

      public void setRemoveIntertagSpaces(boolean removeIntertagSpaces)
      If set to true all inter-tag whitespace characters will be removed. Default is true.
      Parameters:
      removeIntertagSpaces - set true to remove all inter-tag whitespace characters