Class XMLEncode

java.lang.Object
org.apache.maven.shared.utils.xml.XMLEncode

final class XMLEncode extends Object
Collection of XML encoding/decoding helpers.
This is all about the special characters & and <, and for attributes " and '. These must be encoded/decoded from/to XML.
  • Field Details

    • CDATA_BLOCK_THRESHOLD_LENGTH

      private static final int CDATA_BLOCK_THRESHOLD_LENGTH
      See Also:
    • DEFAULT_QUOTE_CHAR

      private static final char DEFAULT_QUOTE_CHAR
      See Also:
  • Constructor Details

    • XMLEncode

      XMLEncode()
  • Method Details

    • isWhiteSpace

      public static boolean isWhiteSpace(String text)
      Checks if this text purely consists of the white space characters ' ', TAB, NEWLINE.
    • xmlEncodeTextForAttribute

      public static String xmlEncodeTextForAttribute(String text, char quoteChar)
      Makes any text fit into XML attributes.
    • xmlEncodeText

      public static String xmlEncodeText(String text)
      Encodes text as XML in the most suitable way, either CDATA block or PCDATA.
    • xmlEncodeText

      public static void xmlEncodeText(String text, Writer writer)
    • xmlEncodeTextAsPCDATA

      public static String xmlEncodeTextAsPCDATA(String text)
      Encodes any text as PCDATA.
    • xmlEncodeTextAsPCDATA

      public static String xmlEncodeTextAsPCDATA(String text, boolean forAttribute)
      Encodes any text as PCDATA.
      Parameters:
      forAttribute - if you want quotes and apostrophes specially treated for attributes
    • xmlEncodeTextAsPCDATA

      public static String xmlEncodeTextAsPCDATA(String text, boolean forAttribute, char quoteChar)
      Encodes any text as PCDATA.
      Parameters:
      forAttribute - if you want quotes and apostrophes specially treated for attributes
      quoteChar - if this is for attributes this char is used to quote the attribute value
    • xmlEncodeTextAsPCDATA

      public static void xmlEncodeTextAsPCDATA(String text, boolean forAttribute, char quoteChar, Writer n)
    • xmlEncodeTextAsCDATABlock

      public static String xmlEncodeTextAsCDATABlock(String text)
      Returns string as CDATA block if possible, otherwise null.
    • needsEncoding

      public static boolean needsEncoding(String text)
      Checks if this text needs encoding in order to be represented in XML.
    • needsEncoding

      public static boolean needsEncoding(String data, boolean checkForAttr)
      Checks if this text needs encoding in order to be represented in XML.

      Set checkForAttr if you want to check for storability in an attribute.

    • isCompatibleWithCDATABlock

      public static boolean isCompatibleWithCDATABlock(String text)
      Can this text be stored into a CDATA block?
    • xmlDecodeTextToCDATA

      public static String xmlDecodeTextToCDATA(String pcdata)
      Make CDATA out of possibly encoded PCDATA.
      E.g. make '&' out of '&amp;'
    • lookAhead

      private static char lookAhead(int la, int offset, String data)