Package com.day.text

Class AutoFormatter

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class AutoFormatter
    extends java.text.Format
    The AutoFormatter class implements the automatic conversion of line endings to <br> HTML lists. This is the formatting subset of the UBM feature of the former Communiqué 2 system.

    This implementation only supports automatically converting bulleted and numbered lists as well as line breaking. Therefore these formatting options are not implemented here : FORMAT_NOISODEC, FORMAT_ISOENC, FORMAT_AUTOLINK, and FORMAT_URLENC. For replacements, use the CodeISO and/or java.net.URLEncoder classes.

    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.text.Format

        java.text.Format.Field
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static AutoFormatter DEFAULT_FORMATTER
      The system default formatter.
      static int FORMAT_AUTOBR
      Combination of line break handling and automatic lists.
      static int FORMAT_AUTOLINK
      Deprecated.
      this is not implemented and has no effects
      static int FORMAT_AUTOLISTS
      Automatically create ordered and unordered lists.
      static int FORMAT_BR
      Automatically convert line breaks to <br> tags
      static int FORMAT_ISOENC
      Deprecated.
      not implemented here, use CodeISO instead.
      static int FORMAT_NOISODEC
      Deprecated.
      not implemented here, use CodeISO instead.
      static int FORMAT_URLENC
      Deprecated.
      not implemented here, use CodeISO or java.net.URLEncoder#encode(String) instead.
    • Constructor Summary

      Constructors 
      Constructor Description
      AutoFormatter()
      Deprecated.
      as of echidna.
      AutoFormatter​(java.util.Properties config)
      Creates a new AutoFormatter object with the given configuration.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.StringBuffer format​(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
      Formats the object according to the standard modifiers, which are automatic line breaks and list formatting.
      java.lang.String format​(java.lang.String str, int mods)
      Formats the string according to the modifier set.
      java.lang.StringBuffer format​(java.lang.String str, java.lang.StringBuffer toAppendTo, int mods)
      Formats the string according to the modifier set.
      java.lang.Object parseObject​(java.lang.String source, java.text.ParsePosition status)
      The AutoFormatter class does not support parsing, so an UnsupportedOperationException is thrown when trying to parse.
      • Methods inherited from class java.text.Format

        clone, format, formatToCharacterIterator, parseObject
      • Methods inherited from class java.lang.Object

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

      • FORMAT_NOISODEC

        public static final int FORMAT_NOISODEC
        Deprecated.
        not implemented here, use CodeISO instead.
        ISO encodes the <, " and & characters.
        See Also:
        Constant Field Values
      • FORMAT_ISOENC

        public static final int FORMAT_ISOENC
        Deprecated.
        not implemented here, use CodeISO instead.
        ISO encode characters according to HTTP standard.
        See Also:
        Constant Field Values
      • FORMAT_AUTOLISTS

        public static final int FORMAT_AUTOLISTS
        Automatically create ordered and unordered lists.
        See Also:
        Constant Field Values
      • FORMAT_AUTOLINK

        public static final int FORMAT_AUTOLINK
        Deprecated.
        this is not implemented and has no effects
        Autmatic link formatting (?).
        See Also:
        Constant Field Values
      • FORMAT_BR

        public static final int FORMAT_BR
        Automatically convert line breaks to <br> tags
        See Also:
        Constant Field Values
      • FORMAT_URLENC

        public static final int FORMAT_URLENC
        Deprecated.
        not implemented here, use CodeISO or java.net.URLEncoder#encode(String) instead.
        Encodes characters illegal in URLs.
        See Also:
        Constant Field Values
      • FORMAT_AUTOBR

        public static final int FORMAT_AUTOBR
        Combination of line break handling and automatic lists.
        See Also:
        Constant Field Values
      • DEFAULT_FORMATTER

        public static final AutoFormatter DEFAULT_FORMATTER
        The system default formatter. Use this instance when formatting with no special configuration is needed.
    • Constructor Detail

      • AutoFormatter

        public AutoFormatter()
        Deprecated.
        as of echidna. To get an instance with default settings use the DEFAULT_FORMATTER.
        Creates a new AutoFormatter object with the default configuration.
      • AutoFormatter

        public AutoFormatter​(java.util.Properties config)
        Creates a new AutoFormatter object with the given configuration.

        The configuration contained in the config parameter is assumed to have the following structure, where config.getName() would return auto or config.getChild("auto") is used as the configuration (this is the same structure as was used in Communiqué 2 to configure automatic formatting.

                 
                    
          " end="
        " >

      All values are replaced as-is except for the ol.start attribute which gets the string %s replaced with the number which is used in the input to defined the ordered list. If the %s string is missing that number is of course not inserted.

Parameters:
config - The configuration for the automatic formatting replacement. If this is null, the defualt configuration is used.
  • Method Detail

    • format

      public java.lang.StringBuffer format​(java.lang.Object obj,
                                           java.lang.StringBuffer toAppendTo,
                                           java.text.FieldPosition pos)
      Formats the object according to the standard modifiers, which are automatic line breaks and list formatting. This implementation only supports strings and completely ignores the pos parameter.
      Specified by:
      format in class java.text.Format
      Parameters:
      obj - The object to format, which must be a String or a ClassCastException will be thrown.
      toAppendTo - Where to append the formatted data. If null, a new string buffer is allocated.
      pos - Formatting position information. Not used or obeyed.
      Returns:
      a StringBuffer containing the formatted string. This is either the same as toAppendTo or a newly allocated StringBuffer if the parameter is null.
      Throws:
      java.lang.ClassCastException - if the object is not a String.
    • parseObject

      public java.lang.Object parseObject​(java.lang.String source,
                                          java.text.ParsePosition status)
      The AutoFormatter class does not support parsing, so an UnsupportedOperationException is thrown when trying to parse.
      Specified by:
      parseObject in class java.text.Format
      Parameters:
      source - The source string to parse. Ignored.
      status - The position to define parsing. Ignored.
      Throws:
      java.lang.UnsupportedOperationException - as it is not yet implemented.
    • format

      public java.lang.String format​(java.lang.String str,
                                     int mods)
      Formats the string according to the modifier set. The modifier set may be any combination of the FORMAT constants defined.
      Parameters:
      str - The string to be formatted.
      mods - The modifier set controlling the format operation.
      Returns:
      the formatted string.
    • format

      public java.lang.StringBuffer format​(java.lang.String str,
                                           java.lang.StringBuffer toAppendTo,
                                           int mods)
      Formats the string according to the modifier set. The modifier set may be any combination of the FORMAT constants defined.

      Implementation Note: Only line break processing and automatic lists are currently supported.

      Parameters:
      str - The string to be formatted.
      toAppendTo - The string buffer to append the result to. If this null a new string buffer is created and returned, else the result of the method will be this string buffer.
      mods - The modifier set controlling the format operation.
      Returns:
      the string buffer to which the formatted result has been appended. This is either the input string buffer or a newly created string buffer, if null has been supplied.