Click or drag to resize
The File Parser

When writing filters that use the Native API (for monolingual file formats) you must derive your parser class from the interfaces INativeFileTypeComponent and INativeFileParser. These interfaces provide a way of connecting to the SDL File Type Support Framework and allow the class to initialize the parser with the necessary objects it requires to interact with the SDL File Type Support Framework. A parser will also normally derive from the INativeContentCycleAware interface, which provides the parser with additional information such as the original file path name, source language and encoding. These interface class methods are called during key phases of the parsing process to enable your filter to manage its initialization, flow-control and clean-up.

However, the simplest way to implement a native parser is to merely it derive from the AbstractNativeFileParser class and the INativeContentCycleAware interface and then use the helper functions of the AbstractNativeFileParser class.

C#
public class SimpleTextParser : AbstractNativeFileParser, INativeContentCycleAware, ISettingsAware
{
     ...
}

Deriving from the AbstractNativeFileParser base class provides an implementation of the INativeFilterComponent and INativeFileParser interfaces, leaving only the INativeContentCycleAware and ISettingsAware interfaces to be implemented by the derived class. If this class is used as a base class, then in its implementation of INativeFileParser it provides some overridable methods than can be used to simplify the implementation of a native parser class. These overridable methods are as follows:

You may have noticed that we have not yet explained how you access essential information such as the actual name of the file to be processed. For this, we refer you back to the INativeContentCycleAware interface. This interface contains the method SetFileProperties(). Its standard implementation is to save its parameter (IFileProperties properties) to a class variable. Probably the most commonly used member is FileConversionProperties, which in turn implements the following:

The INativeContentCycleAware interface contains two further methods that need to be implemented in any parser class, which are outlined below. However, if you are using the flow control methods of the AbstractNativeFileParser base class, your implementation methods may not require any code content.

The ISettingsAware interface contains one method that needs to be implemented in any parser class, which requires access to any settings the parser may need. This is shown below:

Community
Edit
Be the first to Edit the community content of this topic.
Comments