User Guide

1 2 3 4 5 6 7 8 9 10
Extending Dreamweaver

Summary of content (504 pages)

2. Verify that the tag editor is working by performing the following steps: ■ Launch Dreamweaver. ■ Type cfweather in Code view. ■ Right click on the tag. ■ Select Edit Tag cfweather from the Context menu.

  • PAGE 275

    ■ The cfweather tag appears in the list box on the right. ■ Select cfweather, and click the Insert button. The tag editor should appear. Tag editor APIs In order to create a new tag editor, you must provide an implementation for the inspectTag(), validateTag(), and applyTag() functions. For an example of an implementation, see “Creating a tag editor UI” on page 272. inspectTag() Availability Dreamweaver MX. Description The function is called when the tag editor first appears.

  • PAGE 276

    validateTag() Availability Dreamweaver MX. Description When a user clicks on a node in the tree control or clicks OK, the function performs input validation on the currently displayed HTML form elements. Arguments None. Returns Dreamweaver expects a Boolean value: true if the input for HTML form elements is valid; false if input values are not valid. Example When the user creates a table, a negative integer is entered for the number of table rows.

  • PAGE 277

    Example Continuing the cfweather example, in the following code, if the user changes the ZIP code from 94065 to 53402, in order to update the user’s document to use the new ZIP code, the dom object must be updated: function applyTag(tag) { tag.zip = document.forms[0].zip.

  • PAGE 278

    Tag Libraries and Editors

  • PAGE 279

    12 CHAPTER 12 Property Inspectors The Property inspector is perhaps the most familiar floating panel in the Macromedia Dreamweaver 8 interface. It is indispensable for defining, reviewing, and changing the name, size, appearance, and other attributes of the selection as well as for launching internal and external editors for the selected element. Dreamweaver has several built-in interfaces for the Property inspector that let you set properties for many standard HTML tags.

  • PAGE 280

    This comment has the following elements: ■ The serverModel element specifies that Dreamweaver should load this Property inspector only when the server model specified is active. ■ The tagNameOrKeyword element is the tag to be inspected or one of the following keywords: *COMMENT* (for comments), *LOCKED* (for locked regions), or *ASP* (for ASP tags).

  • PAGE 281

    How Property inspector files work At start up, Dreamweaver reads the first line of each HTM and HTML file in the Configuration/Inspectors folder, searching for the comment string that defines the type, priority, and selection type of a Property inspector. Files that do not have this comment as their first line are ignored. When the user makes a selection in Dreamweaver or moves the insertion point to a different location, the following events occur: 1.

  • PAGE 282

    A simple Property inspector example The following Property inspector inspects the MARQUEE tag, which is available only in Microsoft Internet Explorer. The example lets you set the value of the direction attribute in the Property inspector. To set the value of the MARQUEE tag’s other attributes, use this example as a model.

  • PAGE 283

    z-index:16; left: 44px; top: 5px">Marquee . ■ The text value searches only within raw text sections, as shown in the following example: XYZ This example finds a text node that contains the text XYZ.

  • PAGE 355

    ■ The value is used if no pattern is given. It is always considered a match, and the entire value is assigned to the first parameter. In the following example, to identify the participant text <%= RS1.Field.Items("author_id") %>, you can define a simple pattern, followed by a precise pattern that also extracts the two parameter values: Field.Items

  • PAGE 356

    The parameter names should match the ones that are specified in the insertion text and the update parameters. Parent searchPattern Type Attribute. Required Yes. Values paramName1, paramName2, ... Each parameter name should be the exact name of a parameter that is used in the insertion text.

  • PAGE 357

    Required No. Values all, attribute+attribName, tagOnly, innerOnly ■ The all value (default) searches the entire tag that is specified in the whereToSearch attribute.

  • PAGE 358

    Values true, false ■ The value is true if the searchPattern is not necessary to identify the participant. ■ The value is false (default) if the searchPattern tag is required. For example, consider the following simple recordset string: <% var Recordset1 = Server.CreateObject("ADODB.Recordset"); Recordset1.ActiveConnection = "dsn=andescoffee;"; Recordset1.Source = "SELECT * FROM PressReleases"; Recordset1.CursorType = 3; Recordset1.

  • PAGE 359

    Type Block tag. Required No. Description This tag is a specific type of regular expression that lets you update participant text precisely. There should be at least one update pattern definition for every unique parameter that is declared in the insertion text (of the form @@paramName@@). Parent updatePatterns Type Block tag. Required Yes (at least one, if you declare the updatePatterns tag).

  • PAGE 360

    The literal parentheses, as well as other special regular expression characters, are escaped by preceding them with a backslash (\). The middle expression, defined as \w+, is updated with the latest value that passed in for parameters "rs" and "col", respectively. The values "RS1" and "author_id" can be precisely updated with new values. Multiple occurrences of the same pattern can be updated simultaneously by using the regular expression global flag "g" after the closing slash (such as /pattern/g).

  • PAGE 361

    Type Attribute. Required Yes. Values The value is the exact name of a parameter that is used in the insertion text. In the following example, if the insertion text contains an @@rs@@ value, you should have a parameter with that name: pattern Description This tag is an optional advanced feature lets you control how to delete a participant.

  • PAGE 362

    Parent delete Type Attribute. Required No. Values all, none, tagOnly, innerOnly, attribute+attribName, attribute+* ■ The all value (default) deletes the entire directive or tag. For attributes, it deletes the entire definition. ■ The none value is never automatically deleted. ■ The tagOnly value removes only the outer tag but leaves the contents of the innerHTML tag intact. For attributes, it also removes the outer tag if it is a block tag. It is meaningless for directives.

  • PAGE 363

    Type Block tag. Required No. Description This tag lets Dreamweaver find each specified instance in a document. If multiple search patterns are defined, they must all be found within the text being searched (the search patterns have a logical AND relationship), unless they are marked as optional using the isOptional flag. Parent translator Type Block tag. Required Yes.

  • PAGE 364

    Description This tag contains a single translation instruction that includes the location for the participant, what type of translation to perform, and the content that should replace the participant text. Parent translations Type Block tag. Required No. attributes The following items are valid attributes of the translation tag.

  • PAGE 365

    Type Attribute. Required No. translationType Description This attribute indicates the type of translation to perform. These types are preset and give the translation specific functionality. For example, if you specify "dynamic data", any data that is translated should behave the same as Dreamweaver dynamic data; that is, it should have the dynamic data placeholder look in the Design view (curly braces ({}) notation with dynamic background color) and appear in the Server Behaviors panel.

  • PAGE 366

    ■ The tabbed region start value indicates that the translated tags define the beginning of a tabbed outline, as shown in the following example: ■ The tabbed region end value indicates that the translated tags define the end of a tabbed outline, as shown in the following example: ■ The custom value is the default case in which no internal

  • PAGE 367

    Description This tag contains a list of attributes to add to the translated tag that is specified by the openTag tag. Alternatively, if the openTag tag is not defined and the searchPattern tag specifies tag, this tag contains a list of translated attributes to add to the tag that is found. Parent translation Type Block tag. Required No. Description This tag specifies a single attribute (or translated attribute) to add to the translated tag. Parent attributes Type Block tag.

  • PAGE 368

    Description This tag is an optional display string that should be inserted in the translation. Parent translation Type Block tag. Required No. Values The displayString value is any string comprising text and HTML. It can include parameter references that are extracted by the parameter patterns. For example, {@@rs@@.@@col@@} causes the translation to render as {myRecordset.myCol}.

  • PAGE 369

    Server behavior techniques This section covers the common and advanced techniques that create and edit server behaviors. Most of the suggestions involve specific settings in the EDML files. Finding server behaviors Writing search patterns In order to update or delete server behaviors, you must provide a way for Dreamweaver to find each instance in a document. This requires a quickSearch tag and at least one searchPattern tag, which is contained within the searchPatterns tag.

  • PAGE 370

    The search string is defined as a regular expression by starting and ending with a slash (/) and is followed by i, which means that it is not case-sensitive. Within the regular expression, special characters such as parentheses () and periods (.) are escaped by preceding them with a backslash (\). The two parameters rs and new__url are extracted from the string by using parenthetical subexpressions (the parameters must be enclosed in parentheses).

  • PAGE 371

    How participants are matched If a server behavior has more than one participant, the participants must be identified in the user’s document and matched. If the user applies multiple instances of the server behavior to a document, each group of participants must be matched accordingly. To ensure participants are matched correctly, you might need to change or add parameters and construct participants so they can be uniquely identified. Matching requires some rules.

  • PAGE 372

    There are two instances of Test listed in the Server Behaviors panel. If the user tries to add a third instance to the page and names it "aaa", nothing is added because it already exists. Within the html tag, matching can also use position information.

  • PAGE 373

    This server behavior no longer works correctly because only one parameter is named total. To solve this problem, make sure that there is a parameter with a unique value and can be used to match the participants. In the following example, you could make the total variable name unique using the column name: <% itemPrice_total Value * 1.0825 %> <% salePrice_total Value * 1.0825 %> The total (with Sale price (with = Recordset1.Fields.Item("itemPrice").¬ = Recordset1.Fields.

  • PAGE 374

    3. Look for the limitSearch attribute within the searchPattern tag. 4. If the attribute value starts with attribute+, the remaining string is assumed to be the attribute name (no spaces are allowed in the attribute name). If these four steps are successful, Dreamweaver assumes a tag/attribute combination. Otherwise, Dreamweaver starts looking for searchPattern tags with a paramName attribute that has a _url suffix and a regular expression that is defined.

  • PAGE 375

    This example might use the following search patterns: Response.Write /if\s*\((\w+)\.EOF\)\s*Response\.Redirect\("([^\r\n]*)"\)/i The user might add another test to a particular instance of this code, as shown in the following example: <% if (Recordset1.EOF || x > 2) Response.

  • PAGE 376

    Deleting server behaviors Default deletion and dependency counts The user can delete an instance that is selected in the Server Behaviors panel by clicking the Minus (-) button or pressing Delete. All the participants are removed except for the ones that are shared by other server behaviors. Specifically, if more than one server behavior has a participant pointer to the same node, the node is not deleted. By default, participants are deleted by removing an entire tag.

  • PAGE 377

    If a JavaScript file has the SHARE-IN-MEMORY directive and an HTML file references it (by using the SCRIPT tag with the SRC attribute), Dreamweaver loads the JavaScript into a memory location where the code is implicitly included in all HTML files thereafter. NO TE Because JavaScript files that are loaded into this central location share memory, the files cannot duplicate any declarations.

  • PAGE 378

    Server Behaviors

  • PAGE 379

    16 CHAPTER 16 Data Sources The Macromedia Dreamweaver 8 Data Sources API functions let you add data sources, which appear in the Plus (+) menu in the Bindings panel (for related information, see the function dreamweaver.dbi.getDataSources() in the Dreamweaver API Reference). Data source files are stored in the Configuration/DataSources/ServerModelName folder. Dreamweaver currently supports the following server models: ASP.Net/C#, ASP.

  • PAGE 380

    How data sources work Dreamweaver users can add dynamic data by using the Bindings panel. The dynamic data objects that are shown on the Plus (+) menu are based on the server model that is specified for the page. For example, users can insert recordsets, commands, request variables, session variables, and application variables for ASP applications. The following steps describe the process that is involved in adding dynamic data: 1.

  • PAGE 381

    Request NameOfRequestVariable NameOfAnotherRequestVariable Session NameOfSessionVariable 4. If the user double-clicks on a data source name in the Bindings panel to edit the data source, Dreamweaver calls the editDynamicSource() function to handle the user edits within the tree. 5.

  • PAGE 382

    8. Every time the user changes the selection, Dreamweaver calls the inspectDynamicDataRef() function to determine whether the new selection is dynamic text or a tag with a dynamic attribute. If it is dynamic text, Dreamweaver displays the bindings for the current selection in the Bindings panel. 9.

  • PAGE 383

    When a user clicks on the Bindings Plus (+) menu, Dreamweaver searches the DataSources folder for the current server model to gather all available data sources defined in the folder’s HTML (HTM) files. So, to make a new data source available to the user, you need to create a data source definition file that simply provides the name of the data source using the TITLE tag and the location of all supporting JavaScript files using the SCRIPT tag.

  • PAGE 384

    To create the EDML file: 1. Create a new blank file. 2. Enter the following: #MyDatasource.@@bindin gName@@#]]> 3. Save the file as MyDatasource_DataRef.

  • PAGE 385

    { var theResponse = MM.MyDatasourceContents; if (theResponse.length) { var siteURL = dw.getSiteRoot(); if (siteURL.length) { dwscripts.addListValueToNote(siteURL, "MyDatasource", theResponse); } else { alert(MM.MSG_DefineSite); } } else { alert(MM.MSG_DefineMyDatasource); } } } function findDynamicSources() { var retList = new Array(); var siteURL = dw.getSiteRoot() if (siteURL.length) { var bindingsArray = dwscripts.getListValuesFromNote(siteURL, "MyDatasource"); if (bindingsArray.

  • PAGE 386

    { var retVal = new Array(); var siteURL = dw.getSiteRoot(); // For localized object name... if (sourceName != "MyDatasource") { sourceName = "MyDatasource"; } if (siteURL.length) { var bindingsArray = dwscripts.getListValuesFromNote(siteURL, sourceName); retVal = getDataSourceBindingList(bindingsArray, DATASOURCELEAF_FILENAME, true, "MyDatasource.htm"); } return retVal; } function generateDynamicDataRef(sourceName, bindingName, dropObject) { var paramObj = new Object(); paramObj.

  • PAGE 387

    var params = extPart.findInString("MyDatasource_DataRef", expression); if (params) { retArray[0] = params.sourceName; retArray[1] = params.bindingName; } } return retArray; } function deleteDynamicSource(sourceName, bindingName) { var siteURL = dw.getSiteRoot(); if (siteURL.length) { //For localized object name if (sourceName != "MyDatasource") { sourceName = "MyDatasource"; } dwscripts.deleteListValueFromNote(siteURL, sourceName, bindingName); } } 3. Save this file MyDatasource.

  • PAGE 388

    To create the command definition file: 1. Create a new blank file. 2. Enter the following: MyDatasource Variable PAGE 389

    function okClicked(){ var nameObj = document.forms[0].theName; if (nameObj.value) { if (IsValidVarName(nameObj.value)) { MM.MyDatasourceContents = nameObj.value; MM.retVal = "OK"; window.close(); } else { alert(nameObj.value + " " + MM.MSG_InvalidParamName); } } else { alert(MM.MSG_NoName); } } 3. Save the file as MyDatasource_Variable.js in the Configuration/Commands folder.

  • PAGE 390

    2. Click the MyDatasource data source option, and the MyDatasource Variable dialog box you created appears: 3. Enter a value in the dialog box and click OK. The Bindings panel displays the data source in a tree with the variable from the dialog box under the data source name: 4.

  • PAGE 391

    The Data Sources API The functions in the Data Sources API let you find, add, edit, and delete data sources and also generate and inspect dynamic data objects. addDynamicSource() Availability Dreamweaver UltraDev 1. Description This function adds a dynamic data source. Because there is one implementation of this function in each data source file, Dreamweaver calls the appropriate implementation of the addDynamicSource() function when you select a data source from the Plus (+) menu.

  • PAGE 392

    For example, in Dreamweaver, if the selection is a recordset or command, the deleteDynamicSource() function calls the dw.serverBehaviorInspector.deleteServerBehavior() function. If the selection is a request, session, or application variable, the function remembers that the variable was deleted and does not continue to display it.

  • PAGE 393

    editDynamicSource() Availability Dreamweaver MX. Description This function is called when the user double-clicks a data source name in the Bindings panel to edit the data source. You can implement this function to handle user edits in the tree. Otherwise, the server behavior that matches the data source is automatically invoked. The extension developer can use this function to override the default implementation of server behaviors and provide a custom handler.

  • PAGE 394

    Returns Dreamweaver expects an array of JavaScript objects where each object can have as many as five properties, which are described in the following list: ■ The title property is the label string that appears to the right of the icon for each parent node. The title property is always required. ■ The imageFile property is the path of a file that contains the icon (a GIF image), which represents the parent node in the tree control in the Dynamic Data or Dynamic Text dialog box or in the Bindings panel.

  • PAGE 395

    Arguments sourceName, bindingName ■ The sourceName argument is the name of the top-level node that is associated with the child node. ■ The bindingName argument is the name of the child node from which you want to generate a dynamic data object. Returns Dreamweaver expects a string, which can be passed to the formatDynamicDataRef() function to format it before inserting it in a user’s document. generateDynamicSourceBindings() Availability Dreamweaver UltraDev 1.

  • PAGE 396

    ■ The dataSource property is the simple name of the file in which the findDynamicSources() function is defined. For example, the findDynamicSources() function in the Session.htm file, which is located in the Configuration/DataSources/ ASP_Js folder, sets the dataSource property to session.htm. This property is required. ■ The name property is the name of the server behavior that is associated with the data source, if one exists. It is a required property.

  • PAGE 397

    Arguments string ■ The string argument is the dynamic data object. Returns Dreamweaver expects an array of two elements (parent name and child name) for the matched node; it returns a null value if no matches are found.

  • PAGE 398

    Data Sources

  • PAGE 399

    17 CHAPTER 17 Server Formats Chapter 16, “Data Sources,” on page 379, discusses how Macromedia Dreamweaver 8 inserts dynamic data into a user’s document by adding a server expression at the appropriate location. When a visitor requests the document from the web server, that server expression is converted to a value from a database, the contents of a request variable, or some other dynamic value. The Dreamweaver server formats let you format how this dynamic value is presented to the visitor.

  • PAGE 400

    One example might be to create a new currency format. Essentially, all currency formatting consists of converting a number to a string, inserting commas and decimal points, and inserting a currency symbol, such as a dollar ($) sign. The Currency format data type collects all the common parameters and prompts you for the required values. How data formatting works All format files reside in the Configuration/ServerFormats/currentServerModel folder.

  • PAGE 401

    The following example shows the format tag for the "Currency - default" string: The format type for this format is Currency. The "Currency - default" string appears on the Format menu. The expression <%\s*=\s*FormatCurrency\(.

  • PAGE 402

    When the data formatting functions are called The data formatting functions are called in the following scenarios: ■ In the Dynamic Data or the Dynamic Text dialog box, the user selects a node from the data source tree and a format from the Format menu. When the user selects the format, Dreamweaver calls the generateDynamicDataRef() function and passes the return value from the generateDynamicDataRef() function to the formatDynamicDataRef() function.

  • PAGE 403

    The Server Formats API The server formats API consists of the following data formatting functions. applyFormat() Availability Dreamweaver UltraDev 1. Description This function can edit a user’s document by adding a format function declaration to it.

  • PAGE 404

    Description Commits the changes to a format that was created using the Edit Format dialog box. Users can create, edit, or delete formats with the Edit Format List dialog box. This function is called to commit any modifications that are made to a format. It can also set other, arbitrarily named properties on the object. Each property is stored as an attribute of the format tag in the Formats.xml file. Arguments format ■ The format argument corresponds to the JavaScript format object.

  • PAGE 405

    Returns Dreamweaver expects nothing. formatDynamicDataRef() Availability Dreamweaver UltraDev 1. Description Adds the format function call to the dynamic data object.

  • PAGE 406

    inspectFormatDefinition() Availability Dreamweaver UltraDev 1. Description Initializes form controls when a user edits a format in the Edit Format List dialog box. Arguments format ■ The format argument is a JavaScript object that describes the format to apply. The JavaScript object is the node that corresponds to the format tag in the Formats.xml file. The object has a JavaScript property for each attribute of the corresponding format tag. Returns Dreamweaver expects nothing.

  • PAGE 407

    18 CHAPTER 18 Components Macromedia Dreamweaver supports the creation of many of the most popular types of components. In addition, Dreamweaver lets you extend the types of components that appear in the Components panel. Component basics Programmers use various strategies to encapsulate their work. You can think of encapsulation as creating an entity that exists in a virtual black box.

  • PAGE 408

    Extending the Components panel If you have invented (or simply use) a component strategy that is not represented in Dreamweaver’s current Components panel, you can extend the Components panel’s logic so the panel can handle new kinds of components. To add a new kind of component to the Dreamweaver Components panel, you need to locate the available components (in the user’s environment) and request descriptions from each component (or parse them if they are written using ASCII files).

  • PAGE 409

    Extensibility lets you add new component types to the panel. There are several general steps that you need to follow when adding a new component type to the Components panel: 1. Add the component to the list of available component types for the appropriate server model(s). 2. Add instructions, known as setup steps, which appear as interactive numbered steps, for setting up the component in the Components panel or in a dialog box (depending on the extension for which the steps are implemented).

  • PAGE 410

    classlocation="d:\music\music.jar"> JavaBeans should contain the logic for saving themselves in the multiuser configuration folder, so the next time the user launches an application, the component loads itself again from the saved data file. Adding a service component To add a new lightweight directory access protocol (LDAP) service using Dreamweaver MX: 1.

  • PAGE 411

    2. Write the JavaScript code to implement the new server component. The extension file (HTM) defines the locations of the JavaScript code in the SCRIPT tag. These JavaScript files can reside in the Shared folder, in the same folder as the extension file, or in the Common folder for code that applies to multiple server models. For example, the Configuration/Components/Common/WebServices/WebServices.htm file contains the line: .

  • PAGE 412

    For example, the following WebServicesClass node has web methods as its children: this.name = "TrafficLocatorWebService"; this.image = "Components/Common/WebServices/WebServices.gif"; this.hasChildren = true; this.toolTipText = "TrafficLocatorWebService"; this.isCodeViewDraggable = true; // the following allows of enabling/disabling of the button that appears // above the Component Tree this.allowDelete = true; this.

  • PAGE 413

    getContextMenuId() Availability Dreamweaver MX. Description Returns the Context Menu ID for the component type. Every component type can have a context menu associated with it. The Context Menu pop-up menus are defined in the ComponentNameMenus.xml file, and they work the same way as the menu.xml file. The menu string can be static or dynamic. Shortcut keys (accelerator keys) are supported. Arguments None. Returns A string defining the Context Menu ID.

  • PAGE 414

    getCodeViewDropCode() Availability Dreamweaver MX. Description This function gets the code that is dragged and dropped in Code view from the Components panel or the code that is cut, copied, or pasted from the Components panel. Arguments componentRec ■ The componentRec argument is an object. Returns The string that contains the code for the component.

  • PAGE 415

    getSetupSteps() Availability Dreamweaver MX. Description Dreamweaver calls this function if the setupStepsCompleted() function returns zero or a positive integer. This function controls the server-side setup instructions, which can be implemented using extensions that use a modal dialog box and extensions that use server components. This function returns an array of the strings for Dreamweaver to display in either the Setup Steps dialog box or the Components panel, depending on the extension type.

  • PAGE 416

    Example The following example sets four steps for ColdFusion components, and provides a hypertext link in the fourth step so the user can enter the RDS user name and password: function getSetupSteps() { var doSDK = false; dom = dw.getDocumentDOM(); if (dom && dom.serverModel) { var aServerModelName = dom.serverModel.getDisplayName(); } else { var aServerModelName = site.getServerDisplayNameForSite(); } if (aServerModelName.

  • PAGE 417

    Description Dreamweaver calls this function before the Components tab appears. Dreamweaver then calls the getSetupSteps() function if the setupStepsCompleted() function returns zero or a positive integer. Arguments None. Returns An integer that represents the number of setup steps the user has completed, as described in the following list: ■ A value of either zero or a positive integer indicates the number of completed steps.

  • PAGE 418

    Returns A Boolean value that indicates whether the drop operation was successful: true if successful; false otherwise. Example The following example determines if the component is a table or view, and then returns the appropriate bHandled value: function handleDesignViewDrop(componentRec) { var bHandled = false; if (componentRec) { if ((componentRec.objectType == "Table")|| (componentRec.

  • PAGE 419

    Arguments componentRec ■ The componentRec argument is an object that contains the following properties: ■ ■ ■ ■ ■ ■ The name property is the name of the tree node item. The image property is an optional icon for the tree node item. If this icon is omitted, Dreamweaver uses a default icon.

  • PAGE 420

    toolbarControls() Availability Dreamweaver MX. Description Every component type returns a list of toolBarButtonRec objects, which represents the toolbar icons, in left-to-right order.

  • PAGE 421

    Example The following example assigns properties to the toolbar buttons: function toolbarControls() { var toolBarBtnArray = new Array(); dom = dw.getDocumentDOM(); var plusButton = new ToolbarControlRec(); var aServerModelName = null; if (dom && dom.serverModel) { aServerModelName = dom.serverModel.getDisplayName(); } else { //look in the site for potential server model aServerModelName = site.getServerDisplayNameForSite(); } if (aServerModelName.length) { if(aServerModelName == "ColdFusion") { plusButton.

  • PAGE 422

    minusButton.command = "clickedDelete()"; minusButton.enabled = "(dw.serverComponentsPalette.getSelectedNode() != null && dw.serverComponentsPalette.getSelectedNode() && ((dw.serverComponentsPalette.getSelectedNode().objectType=='Root') || (dw.serverComponentsPalette.getSelectedNode().objectType == 'Error') || (dw.serverComponentsPalette.getSelectedNode().objectType == 'MissingProxyGen')))"; toolBarBtnArray.push(minusButton); if(aServerModelName != null && aServerModelName.indexOf(".

  • PAGE 423

    19 CHAPTER 19 Server Models Server models are the technologies that run scripts on a server. When users define a new site, they can identify the server model that they want to use at the site level and at the individual document level. This server model handles any dynamic elements that the user adds to the document. Server model configuration files are stored in the Configuration/ServerModels folder.

  • PAGE 424

    The Server Model API functions This section describes the functions that configure server models for Dreamweaver. canRecognizeDocument() Availability Dreamweaver MX. Description When opening a document (and when more than one server model claims a file extension), Dreamweaver calls this function for each of the extension-associated server models to see whether any of the functions can identify whether the document is its file.

  • PAGE 425

    getFileExtensions() Availability Dreamweaver UltraDev 1, deprecated in Dreamweaver MX. Description Returns the document file extensions with which a server model can work. For example, the ASP server model supports .asp and .htm file extensions. This function returns an array of strings, and Dreamweaver uses these strings to populate the Default Page Extension list that is found in the App Server category in the Site Definition dialog box.

  • PAGE 426

    The getLanguageSignatures() function returns a map of these signature declarations. Extension developers can use this map to generate language-specific code blocks that Dreamweaver drops on the page (based on the appropriate server model for the page) when the user drags and drops a Web Services method, for example. For examples of how to write this function, see the HTML implementation files for the JSP and the ASP.Net server models.

  • PAGE 427

    Description This function returns a JavaScript object that can be accessed from within the JavaScript code. You can retrieve this object by calling the dom.serverModel.getServerInfo() JavaScript function. Furthermore, serverName, serverLanguage, and serverVersion are special properties, which you can access through the following JavaScript functions: dom.serverModel.getServerName() dom.serverModel.getServerLanguage() dom.serverModel.getServerVersion() Arguments None.

  • PAGE 428

    If you want a file in the ServerFormats folder to apply only to a specific scripting language, add the following statement so it is the first line in the HTML file: In this example, XXX represents the scripting language. This statement causes the server behavior to appear in the Plus (+) menu of the Server Behaviors panel only when the currently selected scripting language is XXX. Arguments None.

  • PAGE 429

    Arguments None. Returns Dreamweaver expects an array of objects where each object contains the following three properties: ■ The startPattern property is a regular expression that matches the opening script delimiter (such as "<%"). ■ The endPattern property is a regular expression that matches the closing script delimiter (such as "%>").

  • PAGE 430

    Description This function returns the folder name to use for this server model within the Configuration folder. You can access this value from JavaScript by calling the dom.serverModel.getFolderName() function. Arguments None. Returns Dreamweaver expects a string, such as "ASP_JS". getServerSupportsCharset() Availability Dreamweaver MX. Description This function returns a true value if the current server supports the specified character set.

  • PAGE 431

    Arguments None. Returns Dreamweaver expects an array of version objects, each with a version name and version value, as listed in the following examples: ■ ASP version 2.0 ■ ADODB version 2.

  • PAGE 432

    Server Models

  • PAGE 433

    20 CHAPTER 20 Data Translators Data translators translate specialized markup—server-side includes, conditional JavaScript statements, or other code such as PHP3, JSP, CFML, or ASP—into code that Macromedia Dreamweaver 8 can read and display. In Dreamweaver, you can translate attributes within tags as well as entire tags or blocks of code. All data translators—block/tag or attribute—are HTML files. Translated tags or blocks of code must be enclosed in locked regions to preserve the original markup.

  • PAGE 434

    How data translators work Dreamweaver handles all translator files the same way, regardless of whether they translate entire tags or only attributes. At startup, Dreamweaver reads all the files in the Configuration/ Translators folder and calls the getTranslatorInfo() function to obtain information about the translator. Dreamweaver ignores any file in which the getTranslatorInfo() function does not exist or contains an error that causes it to be undefined.

  • PAGE 435

    Determining what kind of translator to use All translators must contain the getTranslatorInfo() and translateMarkup() functions, and they must reside in the Configuration/Translators folder.

  • PAGE 436

    The mmTranslatedValue attribute must be unique within the tag. If it is likely that your translator needs to translate more than one attribute in a single tag, you must add a routine in the translator that appends numbers to the mmTranslatedValue attribute (for example, mmTranslatedValue1, mmTranslatedValue2, and so on). The value of the mmTranslatedValue attribute must be a URL-encoded string that contains at least one valid attribute/value pair. This means that mmTranslatedValue="src=%22open.

  • PAGE 437

    Inspecting translated attributes When server markup specifies a single attribute and the attribute is represented in a Property inspector, Dreamweaver displays the server markup in the Property inspector, as shown in the following figure: The markup appears whether or not a translator is associated with it. The translator runs whenever the user edits the server markup that appears in the Property inspector.

  • PAGE 438

    The syntax of the XML tags is shown in the following example: Translated content The italicized values in this example have the following significance: ■ The translatorClass value is the unique identifier for the translator; it is the first string in the array that the getTranslatorInfo() function returns.

  • PAGE 439

    [support] [about us] [help] Creating Property inspectors for locked content After you create a translator, you need to create a Property inspector for the content so the user can change its properties (for example, the file to be included or one of the conditions in a conditional statement).

  • PAGE 440

    Another problem is inherent in inspecting translated content. When you call the dom.getSelection() function, the values that return by default are offsets into the untranslated source. To expand the selection properly so that the locked region (and only the locked region) is selected, use the following technique: var currentDOM = dw.getDocumentDOM(); var offsets = currentDOM.getSelection(); var theSelection = currentDOM.

  • PAGE 441

    document.layers['timelayer'].document.timeForm.timefield.¬ value = timeValue; } After you parse the orig attribute to populate the boxes in the Property inspector for the translated tag, the next step is probably to set the value of the orig attribute if the user changes the value in any of the text boxes. You might find restrictions against making changes in a locked region. You can avoid this problem by changing the original markup and retranslating.

  • PAGE 442

    Finding bugs in your translator If the translateMarkup() function contains certain types of errors, the translator loads properly, but it fails without an error message when you invoke it. Although failing silently prevents Dreamweaver from becoming unstable, it can hinder development, especially when you need to find one small syntax error in multiple lines of code. If your translator fails, one effective debugging method is to turn the translator into a command, as described in the following steps: 1.

  • PAGE 443

    6. Add alert() statements in strategic spots throughout the translateMarkup() function so you can make sure you’re getting the proper branches and so you can check the values of variables and properties at different points: for (var i=0; i< foo.length; i++){ alert("we're at the top of foo.length array, and the value ¬ of i is " + i); /* rest of loop */ } 7. After adding the alert() statements, select your command from the Commands menu, click Cancel, and select it again.

  • PAGE 444

    Creating the icon Next, you create the icon for Poco tags. To create the icon: 1. Create an image file that is 18 x 18 pixels for the Poco tags icon. 2. Save the file as poco.gif in the Configuration/ThirdPartyTags folder. Creating the attribute translator You create an HTML file that contains the functions necessary for the attribute translator. To create the HTML file: 1. Create a new blank file. 2.

  • PAGE 445

    // the conditional statement var trueStart; // The beginning of the true case var falseStart; // The beginning of the false case var trueValue; // The HTML that would render in the true case var attName; // The name of the attribute that is being' // set conditionally.

  • PAGE 446

    transValue = attName + '="' + trueValue + '"'; transAtt = ' mmTranslatedValue' + count + '="' + ¬ escape(transValue) + '"'; outStr = outStr.substring(0,end+4) + transAtt + ¬ outStr.substring(end+4); // If attAndValue is true, and tokens is greater than // 1, then trueValue is a series of attribute/value // pairs, not just one. In that case, each attribute/value // pair must be encoded separately and then added back // together to make the translated value. }else if (tokens.

  • PAGE 447

    returnArray[0] returnArray[1] returnArray[2] returnArray[3] returnArray[4] returnArray[5] returnArray[6] returnArray[7] returnArray[8] = = = = = = = = = "Pound_Conditional"; // The translatorClass "Pound Conditional Translator"; // The title "2"; // The number of extensions "html"; // The first extension "htm"; // The second extension "1"; // The number of expressions "<#"; // The first expression "byString"; // "50"; // return returnArray } 3.

  • PAGE 448

    * markup to be translated, the regular expressions that * * a document containing the markup to be translated * * would match (whether the translator should run on all * * files, no files, in files with the specified * * extensions, or in files matching the specified * * expressions).

  • PAGE 449

    return ""; } // As long as start, which is equal to the location in inStr of the // KENT tag, is not equal to -1 (that is, as long as there is another // KENT tag in the document) while (start != -1){ // Copy everything up to the start of the KENT tag. // This is very important, as translators should never change // anything other than the markup that is to be translated. outStr = inStr.substring(0, start); // Replace the KENT tag with the translated HTML, wrapped in special // locking tags.

  • PAGE 450

    //Assemble the lock tags and the replacement HTML. var replCode = start + ' depFiles="' + depFiles + '"'; replCode = replCode + ' orig="%3Ckent%3E">\n'; replCode = replCode + imgTag; replCode = replCode + end; return replCode; } /****************************************************************** * The getImage() function determines which image to display * * based on the day of the week, the time of day and the * * user's platform.

  • PAGE 451

    // Now determine which photo to show based on whether it's a workday or a // weekend; what time it is; and, if it's a time and day when Kent is // working, what platform the user is on. //If it's not Sunday if (day != 0){ //And it's between 10am and noon, inclusive if (SFhour >= 10 && SFhour <= 12){ imageRef = "images/kent_tiredAndIrritated.jpg"; //Or else it's between 1pm and 3pm, inclusive }else if (SFhour >= 13 && SFhour <= 15){ imageRef = "images/kent_hungry.

  • PAGE 452

    3. Save the file as kent.htm in the Configuration/Translators folder. The Data Translator API 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.

  • PAGE 453

    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.

  • PAGE 454

    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.

  • PAGE 455

    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.

  • PAGE 456

    Data Translators

  • PAGE 457

    21 CHAPTER 21 C-Level Extensibility The C-level extensibility mechanism lets you implement Macromedia Dreamweaver 8 extensibility files using a combination of JavaScript and custom C code. You define functions using C, bundle them in a dynamic linked library (DLL) or a shared library, save the library in the Configuration/JSExtensions folder within the Dreamweaver application folder, and then call the functions from JavaScript using the Dreamweaver JavaScript interpreter.

  • PAGE 458

    The readContentsOfFile() function accepts a list of arguments from the user, retrieves the filename argument, reads the contents of the file, and returns the contents of the file. For more information about the JavaScript data structures and functions that appear in the readContentsOfFile() function, see “C-level extensibility and the JavaScript interpreter” on page 459.

  • PAGE 459

    The following example shows how the MM_Init() function for the library myLibrary might look: void MM_Init() { JS_DefineFunction("readContentsOfFile", readContentsOfFile, 1); } Your library must include exactly one instance of the following macro: /* MM_STATE is a macro that expands to some definitions that are * needed to interact with Dreamweaver. This macro must * be defined exactly once in your library.

  • PAGE 460

    Data types The JavaScript interpreter defines the following data types. typedef struct JSContext JSContext A pointer to this opaque data type passes to the C-level function. Some functions in the API accept this pointer as one of their arguments. typedef struct JSObject JSObject A pointer to this opaque data type passes to the C-level function. This data type represents an object, which might be an array object or some other object type.

  • PAGE 461

    The C-level API The C-level extensibility API consists of the following functions: typedef JSBool (*JSNative)(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval) Description This function signature describes C-level implementations of JavaScript functions in the following situations: ■ The cx pointer is a pointer to an opaque JSContext structure, which must be passed to some of the functions in the JavaScript API. This variable holds the interpreter’s execution context.

  • PAGE 462

    Arguments char *name, JSNative call, unsigned int nargs ■ The name argument is the name of the function as it is exposed to JavaScript. ■ The call argument is a pointer to a C-level function. The function must accept the same arguments as readContentsOfFile, and it must return a JSBool, which indicates success or failure. ■ The nargs argument is the number of arguments that the function expects to receive. Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure.

  • PAGE 463

    Arguments JSContext *cx, jsval v, long *lp ■ The cx argument is the opaque JSContext pointer that passes to the JavaScript function. ■ The v argument is the jsval structure from which the integer is to be extracted. ■ The lp argument is a pointer to a 4-byte integer. This function stores the converted value in *lp. Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure.

  • PAGE 464

    ■ The bp argument is a pointer to a JSBool Boolean value. This function stores the converted value in *bp. Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. JSBool JS_ValueToObject() Description This function extracts a function argument from a jsval structure, converts it to an object (if possible), and passes the converted value back to the caller. If the object is an array, use JS_GetArrayLength() and JS_GetElement() to read its contents.

  • PAGE 465

    ■ The vp argument is a pointer to the jsval structure into which the contents of the string should be copied. Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. JSBool JS_DoubleToValue() Description This function stores a floating-point number return value in a jsval structure. Arguments JSContext *cx, double dv, jsval *vp ■ The cx argument is the opaque JSContext pointer that passes to the JavaScript function. ■ The dv argument is an 8-byte floating-point number.

  • PAGE 466

    JSVal JS_IntegerToValue() Description This function converts a long integer value to JSVal structure. Arguments lv ■ The lv argument is the long integer value that you want to convert to a jsval structure. Returns A JSVal structure that contains the integer that was passed to the function as an argument. JSVal JS_ObjectToValue() Description This function stores an object return value in a JSVal. Use JS_ NewArrayObject() to create an array object; use JS_SetElement() to define its contents.

  • PAGE 467

    ■ Typically, this argument is passed in and converted using the JS_ValueToObject() function. Returns A pointer to a null-terminated string. The caller should not free this string when it finishes. JSObject *JS_NewArrayObject() Description This function creates a new object that contains an array of JSVals. Arguments JSContext *cx, unsigned int length, jsval *v ■ The cx argument is the opaque JSContext pointer that passes to the JavaScript function.

  • PAGE 468

    JSBool JS_GetElement() Description This function reads a single element of an array object. Arguments JSContext *cx, JSObject *obj, unsigned int index, jsval *v ■ The cx argument is the opaque JSContext pointer that passes to the JavaScript function. ■ The obj argument is a pointer to an array object. ■ The index argument is an integer index into the array. The first element is index 0, and the last element is index (length - 1).

  • PAGE 469

    JSBool JS_ExecuteScript() Description This function compiles and executes a JavaScript string. If the script generates a return value, it returns in *rval. Arguments JSContext *cx, JSObject *obj, char *script, unsigned int sz, jsval *rval ■ The cx argument is the opaque JSContext pointer that passes to the JavaScript function. ■ The obj argument is a pointer to the object in whose context the script executes. While the script is running, the this keyword is equal to this object.

  • PAGE 470

    Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. File Access and Multiuser Configuration API Macromedia recommends that you always use the File Access and Multiuser Configuration API to access the file system through C-level extensions. For files other than configuration files, the functions access the specified file or folder. Dreamweaver supports multiple-user configurations for the Windows XP, Windows 2000, and Mac OS X operating systems.

  • PAGE 471

    There are many cases where JavaScript extensions open files and write to the Configuration folder. JavaScript extensions can access the file system by using DWFile, MMNotes, or passing a URL to the dreamweaver.getDocumentDOM() function. When an extension accesses the file system in a Configuration folder, it generally uses the dw.getConfigurationPath() function and adds the filename, or it gets the path by accessing the dom.URL property of an open document and adding the filename.

  • PAGE 472

    For example, if you use the trash can icon in the Snippets panel to delete a Snippets folder called javascript and a file called onepixelborder.csn, Dreamweaver writes a file in the user Configuration folder called mm_deleted_files.xml, which looks like the following example: PAGE 473

    ■ The char *contstraints argument can be "files" or "directories" or a null value. If you specify null, the MM_GetConfigFolderList() function returns files and folders. Returns is an array that contains the list of files or folders in either the user Configuration folder or the Dreamweaver Configuration folder, subject to filtering by the mm_deleted_files.xml file.

  • PAGE 474

    int MM_OpenConfigFile() Availability Dreamweaver MX. Description This function opens the file and returns an operating system file handle. You can use the operating system file handle in calls to system file functions. You must close the file handle with a call to the system _close function. If the file is a configuration file, it finds the file in either the user Configuration folder or the Dreamweaver Configuration folder.

  • PAGE 475

    Example char *dwConfig = "file:///c|/Program Files/Macromedia/Dreamweaver/ Configuration/Extensions.txt"; int = fileno; if(MM_ConfigFileExists(dwConfig)) { fileno = MM_OpenConfigFile(dwConfig, "read"); } JSBool MM_GetConfigFileAttributes() Availability Dreamweaver MX. Description This function finds the file and returns the attributes of the file. You can set any of the arguments except fileURL to null if you do not need the value.

  • PAGE 476

    Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. Returns JS_FALSE if the file does not exist or an error occurs while getting the attributes. Example char dwConfig = "file:///c|/Program Files/Macromedia/Dreamweaver/ Configuration/Extensions.

  • PAGE 477

    Example char *dwConfig = "file:///c|/Program Files/Macromedia/Dreamweaver/ Configuration/Extensions.txt"; unsigned long attrs; attrs = (MM_FILEATTR_NORMAL | MM_FILEATTR_RDONLY); int fileno = 0; if(MM_SetConfigFileAttrs(dwConfig, attrs)) { fileno = MM_OpenConfigFile(dwConfig); } JSBool MM_CreateConfigFolder() Availability Dreamweaver MX. Description This function creates a folder in the specified location.

  • PAGE 478

    JSBool MM_RemoveConfigFolder() Availability Dreamweaver MX. Description This function removes the folder and its files and subfolders. If the folder is in the Dreamweaver Configuration folder, it marks the folder for deletion in the mm_deleted_files.xml file. Arguments char *fileURL ■ The char *fileURL argument is a pointer to a string that names the folder to remove, which is provided as a file:// URL. Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure.

  • PAGE 479

    Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. Example char dwConfig = "file:///c:|Program Files\Macromedia\Dreamweaver \Configuration\Objects\insertbar.xml"; MM_DeleteConfigFile(dwConfig); Calling a C function from JavaScript After you understand how C-level extensibility works in Dreamweaver and its dependency on certain data types and functions, it’s useful to know how to build a library and call a function.

  • PAGE 480

    To build the shared library on the Macintosh using Metrowerks CodeWarrior 9 or greater: 1. Open Sample.mcp. 2. Build the project (Project > Make) to generate a Mach-O Bundle. When the build operation finishes, the Sample.bundle file appears in the folder that contains Sample.mcp. N OT E The Mach-O Bundle that is generated can only be used in Macromedia Dreamweaver 8. Earlier versions of Dreamweaver do not recognize it. To build the shared library on the Macintosh using Apple Xcode 1.5 or greater: 1.

  • PAGE 481

    4 PART 4 Appendix Find information about supporting files and reference resources that can aid in developing Macromedia Dreamweaver 8 extensions. Appendix: The Shared Folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

  • PAGE 482

  • PAGE 483

    APPENDIX The Shared Folder The Shared folder is the central repository for utility functions, classes, and images that are commonly used by all extensions. Any extension can reference the files in the Shared folder’s subfolders, and you can add custom common utilities to the ones already provided by Macromedia Dreamweaver 8. The multiple user Configuration folders installed for users on Windows XP, Windows 2000, and Macintosh OS X also contain a Shared folder for individual customizations.

  • PAGE 484

    The Common folder The Common folder has shared scripts and classes for use in third-party extensions. CodeBehindMgr.js Contains functions for creating a code-behind document. A code-behind document lets you create distinct pages that separate the code for user interface (UI) logic from the code for a UI design. The methods of JSCodeBehindMgr defined in this file can create new code-behind documents and manage the link to design documents, ColumnValueNodeClass.

  • PAGE 485

    GridControlClass.js Use this class to create and manipulate an editable grid. You add a special select list in your HTML, and attach this class to it in JavaScript to manipulate the grid. ImageButtonClass.js This class makes it easy to control the Pressed/Mouse-overwhile-pressed/Mouse-over/Disabled-while-pressed look of a button. ListControlClass.js Contains functions that manage a