Package jodd.net

Class HtmlEncoder


  • public class HtmlEncoder
    extends java.lang.Object
    Encodes text and URL strings in various ways resulting HTML-safe text. All methods are null safe. Invalid HTML chars are not checked with these methods, they are just passed as they are.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static char[] AMP  
      private static char[] APOS  
      private static char[][] ATTR_DQ  
      private static char[][] ATTR_SQ  
      private static char[] GT  
      private static int LEN  
      private static int LEN_XML  
      private static char[] LT  
      private static char[] NBSP  
      private static char[] QUOT  
      private static char[][] TEXT  
      private static char[][] TEXT_XML  
    • Constructor Summary

      Constructors 
      Constructor Description
      HtmlEncoder()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String attributeDoubleQuoted​(java.lang.CharSequence value)
      Encodes attribute value that will be double quoted.
      static java.lang.String attributeSingleQuoted​(java.lang.CharSequence value)
      Encodes attribute value that will be single quoted.
      private static java.lang.String encode​(java.lang.CharSequence text, char[][] buff, int bufflen)  
      static java.lang.String text​(java.lang.CharSequence text)
      Encodes a string to HTML-safe text.
      static java.lang.String xml​(java.lang.CharSequence text)
      Encodes XML string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • TEXT

        private static final char[][] TEXT
      • ATTR_SQ

        private static final char[][] ATTR_SQ
      • ATTR_DQ

        private static final char[][] ATTR_DQ
      • TEXT_XML

        private static final char[][] TEXT_XML
      • AMP

        private static final char[] AMP
      • QUOT

        private static final char[] QUOT
      • APOS

        private static final char[] APOS
      • LT

        private static final char[] LT
      • GT

        private static final char[] GT
      • NBSP

        private static final char[] NBSP
    • Constructor Detail

      • HtmlEncoder

        public HtmlEncoder()
    • Method Detail

      • attributeDoubleQuoted

        public static java.lang.String attributeDoubleQuoted​(java.lang.CharSequence value)
        Encodes attribute value that will be double quoted. In this case, only these entities are encoded:
        • & with &
        • " with "
      • attributeSingleQuoted

        public static java.lang.String attributeSingleQuoted​(java.lang.CharSequence value)
        Encodes attribute value that will be single quoted. In this case, only two entities are encoded:
        • & with &
        • ' with '
      • text

        public static java.lang.String text​(java.lang.CharSequence text)
        Encodes a string to HTML-safe text. The following characters are replaced:
        • & with &
        • < with &lt;
        • > with &gt;
        •   with  
      • xml

        public static java.lang.String xml​(java.lang.CharSequence text)
        Encodes XML string. In XML there are only 5 predefined character entities.
      • encode

        private static java.lang.String encode​(java.lang.CharSequence text,
                                               char[][] buff,
                                               int bufflen)