beautypg.com

Server behavior techniques, Finding server behaviors – Adobe Extending Dreamweaver CS4 User Manual

Page 289

background image

283

EXTENDING DREAMWEAVER CS4

Server behaviors

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

You can find server behaviors by:

Writing search patterns

Using optional search patterns

Writing search patterns
To update or delete server behaviors, provide a way for Dreamweaver to find each instance in a document. It requires
a

quickSearch

tag and at least one

searchPattern

tag, which is contained within the

searchPatterns

tag.

The

quickSearch

tag must be a string, not a regular expression, that indicates that the server behavior exists on the

page. It is not case-sensitive. It must be short and unique, and it must avoid spaces and other sections that the user can
change. The following example shows a participant that consists of the simple ASP JavaScript tag:

<% if (Recordset1.EOF) Response.Redirect("some_url_here") %>

In the following example, the

quickSearch

string checks for that tag:

Response.Redirect

For performance reasons, the

quickSearch

pattern is the beginning of the process of finding server behavior

instances. If this string is found in the document and the participant identifies a server behavior (in the group file,

partType="identifier"

for this participant), the related server behavior files are loaded and the

findServerBehaviors()

function is called. If your participant has no reliable strings for which to search (or for

debugging purposes), you can leave the

quickSearch

string empty, as shown in the following example:

In this example, the server behavior is always loaded and can search the document.

Next, the

searchPattern

tag searches the document more precisely than the

quickSearch

tag and extracts

parameter values from the participant code. The search patterns specify where to search (the

whereToSearch

attribute) with a series of

searchPattern

tags that contain specific patterns. These patterns can use simple strings or

regular expressions. The previous example code is an ASP directive. So the

whereToSearch="directive"

specification and a regular expression identify the directive and extract the parameters, as shown in the following
example:

Response.Write

/if\s*\((\w+)\.EOF\)\s*Response\.Redirect\("([^\r\n]*)"\)/i

The search string is defined as a regular expression by starting and ending with a slash (/). An

i

follows the slash, 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). In this example,

(\w+)

and

([^\r\n]*)

indicate the parameters. These values correspond to the regular expression values that

$1

and

$2

normally returns.

This manual is related to the following products: