Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: More Macintosh Toolbox /
Chapter 7 - Translation Manager / Writing a Translation Extension


Identifying Files

Once Macintosh Easy Open knows the types of files from and to which your extension can translate, it might call your extension to determine whether your extension can translate a particular file. This further check is necessary because some documents might have file types that are not specific enough for translation purposes. For example, a document imported from a different operating system might have a file type of 'TEXT'. Your translation extension might be able to determine, however, that the file actually contains SurfWriterPC data and hence deserves special format conversion treatment.

When your translation extension is called with the kTranslateIdentifyFile request code, your extension should identify the particular document. The TranslateEntry extension (shown in Listing 7-5 on page 7-25) dispatches to its DoIdentifyFile function when it receives this request code. Listing 7-7 shows the skeleton of a DoIdentifyFile function.

Listing 7-7 Identifying file types

FUNCTION DoIdentifyFile (self: ComponentInstance; theDoc: FSSpec; 
                         VAR docKind: FileType): ComponentResult;
VAR
   isKnown: Boolean; {indicates whether this extension can identify the file}
BEGIN
   {call an extension-defined routine to do the real work}
   isKnown := MyIdentifyDocument(theDoc, docKind);
   IF isKnown THEN
      DoIdentifyFile := noErr
   ELSE
      DoIdentifyFile := noTypeErr;
END;
Some documents can be identified simply by inspecting their file type and creator. Other documents (in particular, those of type 'TEXT') might require opening the files and examining their contents to determine whether they can be translated by your extension. If your extension cannot recognize the document type, DoIdentifyFile should return noTypeErr. Otherwise, DoIdentifyFile should return noErr, and the docKind parameter should be set to the recognized file type.

Note
Your DoIdentifyFile function should not return 'TEXT' as a file type unless it's certain that the document consists of plain, unformatted ASCII text.
You should be aware that even if your extension identifies a particular document as one that it can translate, Macintosh Easy Open might not in fact call your extension to do the translation.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996