<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
		<meta name="generator" content="Adobe GoLive 7"/>
		<title>Translate SSI Sample Extension</title>
	</head>

	<body>
		<hr/>
		<p>ADOBE SYSTEMS INCORPORATED</p>
		<p>Copyright 2001-2003 Adobe Systems Incorporated<br/>
			All Rights Reserved</p>
		<p>NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms of the Adobe license agreement accompanying it. If you have received this file from a source other than Adobe, then your use, modification, or distribution of it requires the prior written permission of Adobe.</p>
		<hr/>
		<p><b>Extension Name:</b> Translate SSI</p>
		<p><b>Folder name:</b> Translate SSI</p>
		<hr/>
		<p><b>Description:</b></p>
		<p>This sample demonstrates how to use the JSXTranslator object and how to implement a markup translator. See the documentation for more information on JSXTranslator. A markup translator is called before the GoLive parser parses the file. The translator is able to modify the document markup before it is sent to the GoLive parser.</p>
		<p>This sample translates the SSI directive <tt>include</tt> with the <tt>virtual</tt> or <tt>file</tt> attribute. The translator is activated on file extensions htm, html, shtm and shtml. These are specified in the &lt;jsxtranslator&gt; tag (see below).</p>
		<p>The <tt>include</tt> directive is replaced by the contents of the included file. See the translate() function in the &lt;script&gt; tag (see below).</p>
		<p>According to the implementation, the <tt>include</tt> directive is specified as follows:</p>
		<blockquote>
			<pre>&lt;!--#include virtual=&quot;file.htm&quot; --&gt;</pre>
		</blockquote>
		<p>The <tt>virtual</tt> attribute specifies the absolute URL for the HTML snippet to include. The translator translates the contents of the src attribute and displays the contents of the file at the location of the <tt>include</tt> directive.</p>
		<hr/>
		<p><b>How to use</b></p>
		<ol>
			<li>Create an HTML snippet and save it as a file (such as snippet.htm). An HTML?snippet might be file with contents:
				<pre>&lt;p&gt;This is an included paragraph.&lt;/p&gt;</pre>
			</li>
			<li>Create a new document.</li>
			<li>From the Translator Tags Objects Palette, drag the <tt>SSI?#include</tt> object onto the page. This inserts an <tt>include</tt> directive onto the page.</li>
			<li>Highlight the <tt>include</tt> directive. The Inspector shows the current setting for the <tt>virtual</tt> attribute.</li>
			<li>In the Inspector, set <tt>virtual</tt> to point to snippet.htm. In document view you will see the contents of snippet.htm displayed in the <tt>include</tt> directive.</li>
			<li>In source view, you can see the <tt>include</tt>?directive.</li>
			<li>In Split View (select &quot;Toggle Split View&quot; at the bottom of the Layout window), you can see the &lt;agl:translated&gt; tag contents that this translator extension updates. &lt;agl:translated&gt;?is the translation of the <tt>include</tt> directive.</li>
			<li>Save the document, and view the document in a text editor. See the <tt>include</tt> directive.</li>
			<li>Open the document in GoLive. The <tt>include</tt> directives are translated, and display the contents of the included files.</li>
		</ol>
		<p><b>Note: </b>The virtual attribute for #include is supposed to be an absolute path. To ensure that GoLive writes out an absolute path, turn on <tt>Make new links absolute</tt> in the Edit &gt;?Preferences, General &gt;?URL?Handling dialog.</p>
		<hr/>
		<p><b>Removing the blue color</b></p>
		<p>To display SSI include without blue color, add the attribute &quot;blend&quot; set to &quot;no&quot; on to the jsxtranslator object below.</p>
		<hr/>
		<p><b>Editing this sample</b></p>
		<p>It is necessary to turn off this extension before editing this file. If the extension is not turned off, <tt>include</tt> directives that occur in this document will be translated to &lt;agl:translated&gt; tags.</p>
		<hr/>
		<p><b>Module Definition:</b></p>
		<jsxmodule debug="debug" info="This extension displays Server Side Includes." name="Translate SSI" version="1.0"/> 
		<p><b>Scripts:</b></p>
		<script><![CDATA[
//--------------------------------------------------------------------
// CALLBACK FUNCTIONS
//--------------------------------------------------------------------


//---------------------------------------------------------
// inspectTranslation -  inspect the translated tag
//
// Description:
//   Use it to fill in the controls of the inspector with
//   current values.

function inspectTranslation (inspector, source) {
	// urlgetters are handled automatically
	// they must have a name "linkX" where X is the
	// zero based index of the reported link

	// Set the inspector title
	var linkLabel = inspector.controls['TypeAttrLabel'];
	if (linkLabel)
	{
		var pattern		= new RegExp(' (virtual)="(.*)"', 'i');
		linkLabel.value = (source.match(pattern) ? 'Virtual:' : 'File:');
	}
}

//---------------------------------------------------------
// translationLinkChanged - called when a link changes
//
// Parameters:
//   source - original markup of translation
//   index - 
//   newURL - the new value the URL 
//
// Description: Use it to update references to the link.

function translationLinkChanged (source, index, newURL) {
	var pattern		= new RegExp(' (virtual|file)="(.*)"', 'i');
	var newSource	= source.replace(pattern, ' $1="' + newURL +'"');

	app.translator.rewriteSnippet (newSource, module.localize("Include Link Change"));
}


//---------------------------------------------------------
// translate -  implement the document translation
//
// Description:
//   Called when the translator detects a match
//   with its defined file types and one of its regular
//   expressions.

function translate (documentURL, siteURL, source) {
	var reSSI = new RegExp('<!'+'--#include[^-]*--'+'>','gi');
	var reFilePath = / (virtual|file)="(.*)"/i;
	var resultSSI;
	var foundFilePath;
	var src;
	var	translation	= '';

	var fileObj;
	var rtnString = 'SSI include file not found';

	var success = false;
			
	var curFileDir = JSXFile( documentURL );
	var oldCurFolder = app.currentFolder; // Save current folder to restore at end
	app.currentFolder = curFileDir.parent;

	// Find all SSI #includes in the source	
	while ((resultSSI = reSSI.exec (source)) != null)
	{
		// Get the included file path
		foundFilePath = resultSSI[0].match(reFilePath);

		// Convert the found path to an absolute file URL that JSXFile can open.
		if (foundFilePath && foundFilePath[2]) {
			src = foundFilePath[2];
			
			fileObj = JSXFile( src );		
			
			success = fileObj.open("r");
			if (!success) {
				if (foundFilePath[1].toLowerCase() == 'virtual' ) // If virtual use site root
				{
					if (src.indexOf('/') == 0) {
						fileObj = JSXFile( siteURL + src.substring(1) );			
					} else {
						fileObj = JSXFile( siteURL + src );			
					}
				} else {
					fileObj = JSXFile( absoluteURL(src, documentURL) );
				}
				success = fileObj.open("r");
			}
			if (success) {
				translation = fileObj.read(fileObj.size);
				fileObj.close();
			} else { // File not found create error message to display as translation
				translation = '[' + module.localize(rtnString) + ' : ' + src + ']';
			}
			// Perform translation for found entry.
			app.translator.translateSnippet (resultSSI.index, resultSSI[0].length, translation, src);
		}
	}
	app.currentFolder = oldCurFolder; // Restore previous current folder
}


]]>
		</script>
		<hr/>
		<p><b>User Interface Tags:</b></p>
		<p><b>Image</b> Define images here. These are referenced by the picture attribute of the jsxpaletteentry and jsxpalettegroup tags.</p>
		<p>The little icon displayed in the Objects palette tab:</p>
		<img src="Images/groupicon.gif" name="paletteGroupIcon">
		<p>The icon to be displayed in the Objects palette:</p>
		<img src="Images/include.gif" name="paletteIcon"/> 
		<img src="Images/include_over.gif" name="paletteIconOver"/> 
		<p><b>Translator</b> Define a translator that imitates server side replacements.</p>
		<jsxtranslator classid="SSIinclude" direction="twoway" haslinks="yes">
			<param name="extension" value="html"/>
			<param name="extension" value="htm"/>
			<param name="extension" value="shtml"/>
			<param name="extension" value="shtm"/>
			<param name="expression" value="#include"/>
		</jsxtranslator>
		<p><b>Inspectors</b> Define Inspectors for custom tags</p>
		<jsxinspector classid="SSIinclude" height="164" name="SSIinspector" title="SSI Include" width="226">
			<table width="226" border="0" cellspacing="0" cellpadding="0" cool="cool" gridx="5" gridy="5" height="164" showgridx="yes" showgridy="yes" usegridx="yes" usegridy="yes">
				<tr height="10">
					<td rowspan="3" width="10" height="163"></td>
					<td rowspan="2" width="35" height="15"></td>
					<td width="180" height="10"></td>
					<td width="1" height="10"><spacer height="10" type="block" width="1"/></td>
				</tr>
				<tr height="5">
					<td rowspan="2" align="left" valign="top" width="180" height="153" xpos="45">
						<jsxcontrol halign="scale" height="21" name="link0" posx="45" posy="10" type="urlGetter" width="170"></jsxcontrol>
					</td>
					<td width="1" height="5"><spacer height="5" type="block" width="1"/></td>
				</tr>
				<tr height="148">
					<td align="left" valign="top" width="35" height="148" xpos="10">
						<jsxcontrol height="16" name="TypeAttrLabel" posx="10" posy="15" type="static" value="Virtual:" width="35"></jsxcontrol>
					</td>
					<td width="1" height="148"><spacer height="148" type="block" width="1"/></td>
				</tr>
				<tr cntrlrow="cntrlrow" height="1">
					<td width="10" height="1"><spacer height="1" type="block" width="10"/></td>
					<td width="35" height="1"><spacer height="1" type="block" width="35"/></td>
					<td width="180" height="1"><spacer height="1" type="block" width="180"/></td>
					<td width="1" height="1"></td>
				</tr>
			</table>
		</jsxinspector>
		<p><b>Palette Group</b> Define a new tab for the Object Palette, or add to an existing tab.</p>
		<jsxpalettegroup name="TRANS" display="Dynamic Script Tags" taborder="3000" picture="paletteGroupIcon" order="3000">
			<jsxpaletteentry classid="SSIinclude" display="SSI #include" picture="paletteIcon" hilitepicture="paletteIconOver">
				<!--#include virtual="(EmptyReference!)" -->
			</jsxpaletteentry>
		</jsxpalettegroup>
		<p><b>JSXLocale</b> Specify localized versions of strings used in menu items, dialogs, alerts, etc.</p>
		<jsxlocale file="locale.html"></jsxlocale>
		<p></p>
	</body>

</html>