Package net.sf.okapi.common.encoder
Class EncoderManager
- java.lang.Object
-
- net.sf.okapi.common.encoder.EncoderManager
-
-
Constructor Summary
Constructors Constructor Description EncoderManager()Creates a new encoder manager, with default pre-defined encoder loaded.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearMap()Clears all encoders from the manager.Stringencode(char value, EncoderContext context)Encodes a given character with the encoder currently cached.Stringencode(int codePoint, EncoderContext context)Encodes a given code-point with the encoder currently cached.Stringencode(String text, EncoderContext context)Encodes a given text with the encoder currently cached.CharsetEncodergetCharsetEncoder()Gets the character set encoder used for this encoder.protected StringgetDefEncoding()StringgetDefLineBreak()protected IParametersgetDefParams()IEncodergetEncoder()Gets the encoder currently cached by this manager.Hashtable<String,IEncoder>getEncoders()StringgetEncoding()Gets the name of the charset encoding to use.StringgetLineBreak()Gets the line-break to use for this encoder.Hashtable<String,String>getMimeMap()StringgetMimeType()IParametersgetParameters()Gets the parameters object with all the configuration information specific to this encoder.voidmergeMappings(EncoderManager otherManager)Adds the mappings of a given encoder manager into this manager.voidremoveMapping(String mimeType)Removes a given mapping from the manager.voidreset()Reset state in this encoder in preparation for processing new content.voidsetAllKnownMappings()Sets all mappings known by the core libraries.voidsetDefaultOptions(IParameters params, String encoding, String lineBreak)Sets the default options for this encoder manager.protected voidsetDefEncoding(String defEncoding)protected voidsetDefLineBreak(String defLineBreak)protected voidsetDefParams(IParameters defParams)protected voidsetEncoder(IEncoder encoder)protected voidsetEncoders(Hashtable<String,IEncoder> encoders)voidsetMapping(String mimeType, String className)Sets a mapping in the manager.voidsetMapping(String mimeType, IEncoder encoder)protected voidsetMimeMap(Hashtable<String,String> mimeMap)protected voidsetMimeType(String mimeType)voidsetOptions(IParameters params, String encoding, String lineBreak)Sets the options for the encoder currently cached.StringtoNative(String propertyName, String value)Converts any property values from its standard representation to the native representation for this encoder.voidupdateEncoder(String newMimeType)Updates the current cached encoder for this manager.
-
-
-
Method Detail
-
setAllKnownMappings
public void setAllKnownMappings()
Sets all mappings known by the core libraries.
-
reset
public void reset()
Description copied from interface:IEncoderReset state in this encoder in preparation for processing new content.
-
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.
-
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 methodsetDefaultOptions(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.
-
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.
-
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.
-
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:
setOptionsin interfaceIEncoder- 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:IEncoderConverts any property values from its standard representation to the native representation for this encoder.
-
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:IEncoderGets the line-break to use for this encoder.- Specified by:
getLineBreakin interfaceIEncoder- Returns:
- the line-break used for this encoder.
-
getCharsetEncoder
public CharsetEncoder getCharsetEncoder()
Description copied from interface:IEncoderGets the character set encoder used for this encoder.- Specified by:
getCharsetEncoderin interfaceIEncoder- 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:IEncoderGets the name of the charset encoding to use.- Specified by:
getEncodingin interfaceIEncoder- Returns:
- the charset encoding used for this encoder.
-
getDefLineBreak
public final String getDefLineBreak()
-
getParameters
public IParameters getParameters()
Description copied from interface:IEncoderGets the parameters object with all the configuration information specific to this encoder.- Specified by:
getParametersin interfaceIEncoder- Returns:
- the parameters object used for this encoder. This can be null.
-
getDefEncoding
protected String getDefEncoding()
-
setDefEncoding
protected void setDefEncoding(String defEncoding)
-
getDefParams
protected IParameters getDefParams()
-
setDefParams
protected void setDefParams(IParameters defParams)
-
setMimeType
protected void setMimeType(String mimeType)
-
setEncoder
protected void setEncoder(IEncoder encoder)
-
setDefLineBreak
protected void setDefLineBreak(String defLineBreak)
-
-