The Data Translator API

 < Day Day Up > 

This section describes the functions used to define translators for Dreamweaver.

getTranslatorInfo()

Description

This function provides information about the translator and the files it can affect.

Arguments

None.

Returns

An array of strings. The elements of the array must appear in the following order:

1.

The translatorClass string uniquely identifies the translator. This string must begin with a letter and can contain only alphanumeric characters, hyphens (-), and underscores (_).

2.

The title string describes the translator in no more than 40 characters.

3.

The nExtensions string specifies the number of file extensions to follow. If nExtensions is zero, the translator can run on any file. If nExtensions is zero, nRegExps is the next element in the array.

4.

The extension string specifies a file extension (for example, "htm" or "SHTML") that works with this translator. This string is not case-sensitive and should not contain a leading period. The array should contain the same number of extension elements that are specified in nExtensions.

5.

The nRegExps string specifies the number of regular expressions that follow. If nRegExps is zero, runDefault is the next element in the array.

6.

The regExps string specifies a regular expression that you can check. The array should contain the same number of regExps elements as are specified in nRegExps, and at least one of the regExps elements must match a piece of the document's source code before the translator can act on a file.

7.

The runDefault string specifies when this translator executes. The following list gives the possible string values:

String

Definition

"allFiles"

Sets the translator to always execute.

"noFiles"

Sets the translator to never execute.

"byExtension"

Sets the translator to execute for files that have one of the file extensions that are specified in the extension.

"byExpression"

Sets the translator to execute if the document contains a match for one of the specified regular expressions.

"bystring"

Sets the translator to execute if the document contains a match for one of the specified strings.


NOTE

If you set runDefault to "byExtension" but do not specify any extensions (see step 4.), the effect is the same as setting "allFiles". If you set runDefault to "byExpression" but do not specify any expressions (see step 6.), the effect is the same as setting "noFiles".

8.

The priority string specifies the default priority for running this translator. The priority is a number between 0 and 100. If you do not specify a priority, the default priority is 100. The highest priority is 0, and 100 is the lowest. When multiple translators apply to a document, this setting controls the order in which the translators are applied. The highest priority is applied first. When multiple translators have the same priority, they are applied in alphabetical order by translatorClass.

Example

The following instance of the gettranslatorInfo() function gives information about a translator for server-side includes:

 function getTranslatorInfo(){   var transArray = new Array(11);   transArray[0] = "SSI";   transArray[1] = "Server-Side Includes";   transArray[2] = "4";   transArray[3] = "htm";   transArray[4] = "stm";   transArray[5] = "html";   transArray[6] = "shtml";   transArray[7] = "2";   transArray[8] = "<!--#include file";   transArray[9] = "<!--#include virtual";   transArray[10] = "byExtension";   transArray[11] = "50";   return transArray; } 

translateMarkup()

Description

This function performs the translation.

Arguments

 docName, siteRoot, docContent 

  • The docName argument is a string that contains the file:// URL for the document to be translated.

  • The siteRoot argument is a string that contains the file:// URL for the root of the site that contains the document to be translated. If the document is outside a site, this string might be empty.

  • The docContent argument is a string that contains the contents of the document.

Returns

A string that contains the translated document or an empty string if nothing is translated.

Example

The following instance of the TRanslateMarkup() function calls the C function translateASP(), which is contained in a dynamic link library (DLL) (Windows) or a code library (Macintosh) called ASPTrans:

 function translateMarkup(docName, siteRoot, docContent){   var translatedString = "";   if (docContent.length > 0){   translatedString = ASPTrans.translateASP(docName, siteRoot, docContent);   }   return translatedString; } 

For an all-JavaScript example, see "A simple attribute translator example" on page 443 or "A simple block/tag translator example" on page 447.

liveDataTranslateMarkup()

Availability

Dreamweaver UltraDev 1.

Description

This function translates documents when users are using the Live Data window. When the user selects the View > Live Data command or clicks the Refresh button, Dreamweaver calls the liveDataTranslateMarkup() function instead of the TRanslateMarkup() function.

Arguments

 docName, siteRoot, docContent 

  • The docName argument is a string that contains the file:// URL for the document to be translated.

  • The siteRoot argument is a string that contains the file:// URL for the root of the site that contains the document to be translated. If the document is outside a site, this string might be empty.

  • The docContent argument is a string that contains the contents of the document.

Returns

A string that contains the translated document or an empty string if nothing is translated.

Example

The following instance of the liveDataTranslateMarkup() function calls the C function translateASP(), which is contained in a DLL (Windows) or a code library (Macintosh) called ASPTrans:

 function liveDataTranslateMarkup(docName, siteRoot, docContent){   var translatedString = "";   if (docContent.length > 0){   translatedString = ASPTrans.translateASP(docName, siteRoot, docContent);   }   return translatedString; } 

     < Day Day Up > 


    Developing Extensions for Macromedia Dreamweaver 8
    Developing Extensions for Macromedia Dreamweaver 8
    ISBN: 0321395409
    EAN: 2147483647
    Year: 2005
    Pages: 282

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net