file2xliff4j
Class MifImporter

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by file2xliff4j.MifImporter
All Implemented Interfaces:
Converter, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class MifImporter
extends org.xml.sax.helpers.DefaultHandler
implements Converter

The MifImporter is used to normalize "outside" XLIFF to a smaller subset of XLIFF. This importer assumes that the "owner" of the XLIFF file used as input is responsible for its associated skeleton and other files. This converter creates skeleton and format files, but only for the purpose of exporting the reduced XLIFF file to the original format. (Upon export, the XLIFF file will have additional translation unit targets, and existing targets might be modified.)

This importer replaces bpt, ept, sub, it and ph elements (which "mask off codes left inline") with x, bx and ex elements (which "remove codes"). The codes removed from the bpt, ept, sub, it and ph elements are placed in a format file. At export time, the information from the format file is used to restore the original bpt, ept, sub, it and ph elements.

This importer also replaces opening g tags with bx elements and closing g tags with ex elements.

Author:
Weldon Whipple <weldon@whipple.org>

Nested Class Summary
 class MifImporter.NonFrameRomanUnescaper
          This class reads from a non-FrameRoman-encoded (likely) input stream and echos the input to an output stream, unescaping MIF characters of the format "\xab " (where a and b represent hex digits).
 
Field Summary
 
Fields inherited from interface file2xliff4j.Converter
BLKSIZE, formatSuffix, skeletonSuffix, startXliff, stylesTSkeletonSuffix, tSkeletonSuffix, xliffSuffix, xmlDeclaration
 
Constructor Summary
MifImporter()
          Constructor for the MIF importer.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Called whenever characters are encountered
 ConversionStatus convert(ConversionMode mode, java.util.Locale language, java.lang.String phaseName, int maxPhase, java.nio.charset.Charset nativeEncoding, FileType nativeFileType, java.lang.String inputMifFileName, java.lang.String baseDir, Notifier notifier)
          Deprecated. 
 ConversionStatus convert(ConversionMode mode, java.util.Locale language, java.lang.String phaseName, int maxPhase, java.nio.charset.Charset nativeEncoding, FileType nativeFileType, java.lang.String inputMifFileName, java.lang.String baseDir, Notifier notifier, SegmentBoundary boundary, java.io.StringWriter generatedFileName)
          Convert a Maker Interchange Format file (MIF) to XLIFF.
 ConversionStatus convert(ConversionMode mode, java.util.Locale language, java.lang.String phaseName, int maxPhase, java.nio.charset.Charset nativeEncoding, FileType nativeFileType, java.lang.String inputMifFileName, java.lang.String baseDir, Notifier notifier, SegmentBoundary boundary, java.io.StringWriter generatedFileName, java.util.Set<f2xutils.XMLTuXPath> skipList)
          Convert a Maker Interchange Format file (MIF) to XLIFF.
 void endDocument()
          When the end-of-document is encountered, write what follows tqhe final translation unit.
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qualifiedName)
          Method called whenever an end element is encountered
 java.lang.Object getConversionProperty(java.lang.String property)
          Return an object representing a format-specific (and converter-specific) property.
 FileType getFileType()
          Return the file type that this converter handles.
 void setConversionProperty(java.lang.String property, java.lang.Object value)
          Set a format-specific property that might affect the way that the conversion occurs.
 void startDocument()
          Method called by the SAX parser at the beginning of document parsing.
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qualifiedName, org.xml.sax.Attributes atts)
          Method called whenever a start element is encountered
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MifImporter

public MifImporter()
Constructor for the MIF importer.

Method Detail

convert

public ConversionStatus convert(ConversionMode mode,
                                java.util.Locale language,
                                java.lang.String phaseName,
                                int maxPhase,
                                java.nio.charset.Charset nativeEncoding,
                                FileType nativeFileType,
                                java.lang.String inputMifFileName,
                                java.lang.String baseDir,
                                Notifier notifier,
                                SegmentBoundary boundary,
                                java.io.StringWriter generatedFileName)
                         throws ConversionException
Convert a Maker Interchange Format file (MIF) to XLIFF. Additionally create skeleton and format files. (The skeleton and format files are used on export to generate localized MIF files from seleced XLIFF targets.)

Specified by:
convert in interface Converter
Parameters:
mode - The mode of conversion (to or from XLIFF). The value must be TO_XLIFF.
language - The primary language of the MIF file to be imported.
phaseName - The target phase-name. This value is ignored.
maxPhase - The maximum phase number. This value is ignored.
nativeEncoding - The encoding of the input MIF. (MIF files are FrameMaker documents encoded in ASCII format. On Unix, ISO Latin-1 is used. MIF can also use Shift-JIS or EUC (Japanese), Big5, CNS or GB2312-80.EUC (Chinese), or KSC5601-1992 for Korean.)
nativeFileType - The type of the input file. This value is ignored. (The value "mif" is an official XLIFF attribute value and is used unconditionally by this importer.)
inputMifFileName - The name of the input MIF file.
baseDir - The directory that contains the input MIF file--from which we will read the input file. This is also the directory in which the output xliff, skeleton and format files will be written. The output files will be named as follows:
  • <original_file_name>.xliff
  • <original_file_name>.skeleton
  • <original_file_name>.format
notifier - Instance of a class that implements the Notifier interface (to send notifications in case of conversion error).
boundary - The boundary on which to segment translation units (e.g., on paragraph or sentence boundaries)
generatedFileName - If non-null, the converter will write the name of the file (without parent directories) to which the generated XLIFF file was written.
Returns:
Indicator of the status of the conversion.
Throws:
ConversionException - If a conversion exception is encountered.

convert

public ConversionStatus convert(ConversionMode mode,
                                java.util.Locale language,
                                java.lang.String phaseName,
                                int maxPhase,
                                java.nio.charset.Charset nativeEncoding,
                                FileType nativeFileType,
                                java.lang.String inputMifFileName,
                                java.lang.String baseDir,
                                Notifier notifier,
                                SegmentBoundary boundary,
                                java.io.StringWriter generatedFileName,
                                java.util.Set<f2xutils.XMLTuXPath> skipList)
                         throws ConversionException
Convert a Maker Interchange Format file (MIF) to XLIFF. Additionally create skeleton and format files. (The skeleton and format files are used on export to generate localized MIF files from seleced XLIFF targets.)

Specified by:
convert in interface Converter
Parameters:
mode - The mode of conversion (to or from XLIFF). The value must be TO_XLIFF.
language - The primary language of the MIF file to be imported.
phaseName - The target phase-name. This value is ignored.
maxPhase - The maximum phase number. This value is ignored.
nativeEncoding - The encoding of the input MIF. (MIF files are FrameMaker documents encoded in ASCII format. On Unix, ISO Latin-1 is used. MIF can also use Shift-JIS or EUC (Japanese), Big5, CNS or GB2312-80.EUC (Chinese), or KSC5601-1992 for Korean.)
nativeFileType - The type of the input file. This value is ignored. (The value "mif" is an official XLIFF attribute value and is used unconditionally by this importer.)
inputMifFileName - The name of the input MIF file.
baseDir - The directory that contains the input MIF file--from which we will read the input file. This is also the directory in which the output xliff, skeleton and format files will be written. The output files will be named as follows:
  • <original_file_name>.xliff
  • <original_file_name>.skeleton
  • <original_file_name>.format
notifier - Instance of a class that implements the Notifier interface (to send notifications in case of conversion error).
boundary - The boundary on which to segment translation units (e.g., on paragraph or sentence boundaries)
generatedFileName - If non-null, the converter will write the name of the file (without parent directories) to which the generated XLIFF file was written.
skipList - (Not used by this converter.)
Returns:
Indicator of the status of the conversion.
Throws:
ConversionException - If a conversion exception is encountered.

convert

@Deprecated
public ConversionStatus convert(ConversionMode mode,
                                           java.util.Locale language,
                                           java.lang.String phaseName,
                                           int maxPhase,
                                           java.nio.charset.Charset nativeEncoding,
                                           FileType nativeFileType,
                                           java.lang.String inputMifFileName,
                                           java.lang.String baseDir,
                                           Notifier notifier)
                         throws ConversionException
Deprecated. 

Convert a Maker Interchange Format file (MIF) to XLIFF. Additionally create skeleton and format files. (The skeleton and format files are used on export to generate localized MIF files from seleced XLIFF targets.)

Specified by:
convert in interface Converter
Parameters:
mode - The mode of conversion (to or from XLIFF). The value must be TO_XLIFF.
language - The primary language of the MIF file to be imported.
phaseName - The target phase-name. This value is ignored.
maxPhase - The maximum phase number. This value is ignored.
nativeEncoding - The encoding of the input MIF. (MIF files are FrameMaker documents encoded in ASCII format. On Unix, ISO Latin-1 is used. MIF can also use Shift-JIS or EUC (Japanese), Big5, CNS or GB2312-80.EUC (Chinese), or KSC5601-1992 for Korean.)
nativeFileType - The type of the input file. This value is ignored. (The value "mif" is an official XLIFF attribute value and is used unconditionally by this importer.)
inputMifFileName - The name of the input MIF file.
baseDir - The directory that contains the input MIF file--from which we will read the input file. This is also the directory in which the output xliff, skeleton and format files will be written. The output files will be named as follows:
  • <original_file_name>.xliff
  • <original_file_name>.skeleton
  • <original_file_name>.format
notifier - Instance of a class that implements the Notifier interface (to send notifications in case of conversion error).
Returns:
Indicator of the status of the conversion.
Throws:
ConversionException - If a conversion exception is encountered.

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Method called by the SAX parser at the beginning of document parsing.

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException - I if any problems are found.

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qualifiedName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Method called whenever a start element is encountered

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
namespaceURI - The URI of the namespace
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qualifiedName - The qualified name (with prefix), or the empty string if qualified names are not available
atts - The specified or defaulted attributes.
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qualifiedName)
                throws org.xml.sax.SAXException
Method called whenever an end element is encountered

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
namespaceURI - The URI of the namespace
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qualifiedName - The qualified name (with prefix), or the empty string if qualified names are not available
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Called whenever characters are encountered

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Parameters:
ch - Array containing characters encountered
start - Position in array of first applicable character
length - How many characters are of interest?
Throws:
org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
When the end-of-document is encountered, write what follows tqhe final translation unit.

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

getConversionProperty

public java.lang.Object getConversionProperty(java.lang.String property)
Return an object representing a format-specific (and converter-specific) property.

Specified by:
getConversionProperty in interface Converter
Parameters:
property - The name of the property to return.
Returns:
An Object that represents the property's value.

getFileType

public FileType getFileType()
Return the file type that this converter handles. (For importers, this means the file type that it imports to XLIFF; for exporters, it is the file type that ie exports to (from XLIFF).

Specified by:
getFileType in interface Converter
Returns:
the MIF file type.

setConversionProperty

public void setConversionProperty(java.lang.String property,
                                  java.lang.Object value)
                           throws ConversionException
Set a format-specific property that might affect the way that the conversion occurs.

Note: This converter needs no format-specific properties. If any are passed, they will be silently ignored.

Specified by:
setConversionProperty in interface Converter
Parameters:
property - The name of the property
value - The value of the property
Throws:
ConversionException - If the property isn't recognized (and if it matters).