net.sf.okapi.common.encoder
Class EncoderManager

java.lang.Object
  extended by 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
EncoderManager()
          Creates a new encoder manager, with default pre-defined encoder loaded.
 
Method Summary
 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.
 IEncoder getEncoder()
          Gets the encoder currently cached by this manager.
 java.lang.String getLineBreak()
          Gets the line-break to use for 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 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.
 void setMapping(java.lang.String mimeType, IEncoder encoder)
           
 void setMapping(java.lang.String mimeType, java.lang.String className)
          Sets a mapping in the manager.
 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.


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.

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 to use 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 the character set encoder used for this encoder. This can be null.