net.sf.okapi.common.encoder

## Class EncoderManager

- java.lang.Object
- - net.sf.okapi.common.encoder.EncoderManager

- All Implemented Interfaces:
    IEncoder

      public class EncoderManager
      extends java.lang.Object
      implements IEncoder

  Provides caching and lookup mechanism for the text encoders used when writing out text processed by a filter.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `EncoderManager()` Creates a new encoder manager, with default pre-defined encoder loaded.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clearMap()` Clears all encoders from the manager.
    `java.lang.String` | `encode(char value, EncoderContext context)` Encodes a given character with the encoder currently cached.
    `java.lang.String` | `encode(int codePoint, EncoderContext context)` Encodes a given code-point with the encoder currently cached.
    `java.lang.String` | `encode(java.lang.String text, EncoderContext context)` Encodes a given text with the encoder currently cached.
    `java.nio.charset.CharsetEncoder` | `getCharsetEncoder()` Gets the character set encoder used for this encoder.
    `protected java.lang.String` | `getDefEncoding()`
    `java.lang.String` | `getDefLineBreak()`
    `protected IParameters` | `getDefParams()`
    `IEncoder` | `getEncoder()` Gets the encoder currently cached by this manager.
    `java.util.Hashtable<java.lang.String,IEncoder>` | `getEncoders()`
    `java.lang.String` | `getEncoding()` Gets the name of the charset encoding to use.
    `java.lang.String` | `getLineBreak()` Gets the line-break to use for this encoder.
    `java.util.Hashtable<java.lang.String,java.lang.String>` | `getMimeMap()`
    `java.lang.String` | `getMimeType()`
    `IParameters` | `getParameters()` Gets the parameters object with all the configuration information specific to this encoder.
    `void` | `mergeMappings(EncoderManager otherManager)` Adds the mappings of a given encoder manager into this manager.
    `void` | `removeMapping(java.lang.String mimeType)` Removes a given mapping from the manager.
    `void` | `reset()` Reset state in this encoder in preparation for processing new content.
    `void` | `setAllKnownMappings()` Sets all mappings known by the core libraries.
    `void` | `setDefaultOptions(IParameters params, java.lang.String encoding, java.lang.String lineBreak)` Sets the default options for this encoder manager.
    `protected void` | `setDefEncoding(java.lang.String defEncoding)`
    `protected void` | `setDefLineBreak(java.lang.String defLineBreak)`
    `protected void` | `setDefParams(IParameters defParams)`
    `protected void` | `setEncoder(IEncoder encoder)`
    `protected void` | `setEncoders(java.util.Hashtable<java.lang.String,IEncoder> encoders)`
    `void` | `setMapping(java.lang.String mimeType, IEncoder encoder)`
    `void` | `setMapping(java.lang.String mimeType, java.lang.String className)` Sets a mapping in the manager.
    `protected void` | `setMimeMap(java.util.Hashtable<java.lang.String,java.lang.String> mimeMap)`
    `protected void` | `setMimeType(java.lang.String mimeType)`
    `void` | `setOptions(IParameters params, java.lang.String encoding, java.lang.String lineBreak)` Sets the options for the encoder currently cached.
    `java.lang.String` | `toNative(java.lang.String propertyName, java.lang.String value)` Converts any property values from its standard representation to the native representation for this encoder.
    `void` | `updateEncoder(java.lang.String newMimeType)` Updates the current cached encoder for this manager.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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(java.lang.String mimeType,
                        java.lang.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(java.lang.String mimeType,
                        IEncoder encoder)

    - #### removeMapping

          public void removeMapping(java.lang.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(java.lang.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 java.lang.String encode(java.lang.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 java.lang.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 java.lang.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,
                        java.lang.String encoding,
                        java.lang.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 java.lang.String toNative(java.lang.String propertyName,
                                  java.lang.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,
                               java.lang.String encoding,
                               java.lang.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 java.lang.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 java.nio.charset.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.

    - #### getMimeMap

          public final java.util.Hashtable<java.lang.String,java.lang.String> getMimeMap()

    - #### getEncoders

          public final java.util.Hashtable<java.lang.String,IEncoder> getEncoders()

    - #### getMimeType

          public final java.lang.String getMimeType()

    - #### getEncoding

          public final java.lang.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 java.lang.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 java.lang.String getDefEncoding()

    - #### setDefEncoding

          protected void setDefEncoding(java.lang.String defEncoding)

    - #### getDefParams

          protected IParameters getDefParams()

    - #### setDefParams

          protected void setDefParams(IParameters defParams)

    - #### setMimeMap

          protected void setMimeMap(java.util.Hashtable<java.lang.String,java.lang.String> mimeMap)

    - #### setEncoders

          protected void setEncoders(java.util.Hashtable<java.lang.String,IEncoder> encoders)

    - #### setMimeType

          protected void setMimeType(java.lang.String mimeType)

    - #### setEncoder

          protected void setEncoder(IEncoder encoder)

    - #### setDefLineBreak

          protected void setDefLineBreak(java.lang.String defLineBreak)