Class EncoderManager

  • All Implemented Interfaces:
    IEncoder

    public class EncoderManager
    extends Object
    implements IEncoder
    Provides caching and lookup mechanism for the text encoders used when writing out text processed by a filter.
    • Constructor Detail

      • EncoderManager

        public EncoderManager()
        Creates a new encoder manager, with default pre-defined encoder loaded.
    • Method Detail

      • setAllKnownMappings

        public void setAllKnownMappings()
        Sets all mappings known by the core libraries.
      • reset

        public void reset()
        Description copied from interface: IEncoder
        Reset state in this encoder in preparation for processing new content.
        Specified by:
        reset in interface IEncoder
      • clearMap

        public void clearMap()
        Clears all encoders from the manager.
      • setMapping

        public void setMapping​(String mimeType,
                               String className)
        Sets a mapping in the manager. If a mapping for this MIME type exists already in the manager, it will be overridden by this new one.
        Parameters:
        mimeType - The MIME type identifier for this mapping.
        className - The class name of the encoder to use.
      • setMapping

        public void setMapping​(String mimeType,
                               IEncoder encoder)
      • removeMapping

        public void removeMapping​(String mimeType)
        Removes a given mapping from the manager.
        Parameters:
        mimeType - The MIME type identifier of the mapping to remove.
      • mergeMappings

        public void mergeMappings​(EncoderManager otherManager)
        Adds the mappings of a given encoder manager into this manager. If, for a given MIME type, both encoder manager have a different mapping, the original mapping of this manager remains unchanged and a warning is generated.
        Parameters:
        otherManager - the other encoder manager.
      • updateEncoder

        public void updateEncoder​(String newMimeType)
        Updates the current cached encoder for this manager. The method setDefaultOptions(IParameters, String, String) must have been called before calling this method.
        Parameters:
        newMimeType - The MIME type identifier for the encoder to use now. If there is no mapping for the given MIME type, the cache is cleared and no encoder is active.
      • encode

        public String encode​(String text,
                             EncoderContext context)
        Encodes a given text with the encoder currently cached. If no encoder is currently cached, the text is returned untouched.
        Specified by:
        encode in interface IEncoder
        Parameters:
        text - The text to encode.
        context - The context of the text: 0=text, 1=skeleton, 2=inline.
        Returns:
        The encoded text.
      • encode

        public String encode​(char value,
                             EncoderContext context)
        Encodes a given character with the encoder currently cached. If no encoder is currently cached, the character is returned as its string value.
        Specified by:
        encode in interface IEncoder
        Parameters:
        value - The character to encode.
        context - The context of the character: 0=text, 1=skeleton, 2=inline.
        Returns:
        The encoded character 9as a string since it can be now made up of more than one character).
      • encode

        public String encode​(int codePoint,
                             EncoderContext context)
        Encodes a given code-point with the encoder currently cached. If no encoder is currently cached, the character is returned as its string value.
        Specified by:
        encode in interface IEncoder
        Parameters:
        codePoint - The code-point to encode.
        context - The context of the character: 0=text, 1=skeleton, 2=inline.
        Returns:
        The encoded character 9as a string since it can be now made up of more than one character).
      • getEncoder

        public IEncoder getEncoder()
        Gets the encoder currently cached by this manager.
        Returns:
        The encoder currently cached by this manager, or null if there is none.
      • setOptions

        public void setOptions​(IParameters params,
                               String encoding,
                               String lineBreak)
        Sets the options for the encoder currently cached. If no encoder is currently cached, the method does nothing.
        Specified by:
        setOptions in interface IEncoder
        Parameters:
        params - The parameters object with all the configuration information specific to this encoder.
        encoding - The name of the charset encoding to use.
        lineBreak - Type of line-break to use in the output.
      • toNative

        public String toNative​(String propertyName,
                               String value)
        Description copied from interface: IEncoder
        Converts any property values from its standard representation to the native representation for this encoder.
        Specified by:
        toNative in interface IEncoder
        Parameters:
        propertyName - the name of the property.
        value - the standard value to convert.
        Returns:
        the native representation of the given value.
      • setDefaultOptions

        public void setDefaultOptions​(IParameters params,
                                      String encoding,
                                      String lineBreak)
        Sets the default options for this encoder manager. The values passed here are set as the values to use for each encoder as they are invoked.
        Parameters:
        params - The default parameter object.
        encoding - The default encoding.
        lineBreak - The string that the encoder will use as a line break.
      • getLineBreak

        public String getLineBreak()
        Description copied from interface: IEncoder
        Gets the line-break to use for this encoder.
        Specified by:
        getLineBreak in interface IEncoder
        Returns:
        the line-break used for this encoder.
      • getCharsetEncoder

        public CharsetEncoder getCharsetEncoder()
        Description copied from interface: IEncoder
        Gets the character set encoder used for this encoder.
        Specified by:
        getCharsetEncoder in interface IEncoder
        Returns:
        the character set encoder used for this encoder. This can be null.
      • getMimeType

        public final String getMimeType()
      • getEncoding

        public final String getEncoding()
        Description copied from interface: IEncoder
        Gets the name of the charset encoding to use.
        Specified by:
        getEncoding in interface IEncoder
        Returns:
        the charset encoding used for this encoder.
      • getDefLineBreak

        public final String getDefLineBreak()
      • getParameters

        public IParameters getParameters()
        Description copied from interface: IEncoder
        Gets the parameters object with all the configuration information specific to this encoder.
        Specified by:
        getParameters in interface IEncoder
        Returns:
        the parameters object used for this encoder. This can be null.
      • getDefEncoding

        protected String getDefEncoding()
      • setDefEncoding

        protected void setDefEncoding​(String defEncoding)
      • setDefParams

        protected void setDefParams​(IParameters defParams)
      • setMimeType

        protected void setMimeType​(String mimeType)
      • setEncoder

        protected void setEncoder​(IEncoder encoder)
      • setDefLineBreak

        protected void setDefLineBreak​(String defLineBreak)