8-2-SP1 DSP and Output Template Developers Guide
8-2-SP1 DSP and Output Template Developers Guide
Version 8.2
April 2011
Copyright
& Docu-
ment ID
This document applies to webMethods Integration Server Version 8.2 and webMethods Developer Version 8.2 and to all subsequent releases.
Specifications contained herein are subject to change and these changes will be reported in subsequent release notes or new editions.
Copyright © 1998–2011 Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, United States of America, and/or
their licensors.
Detailed information on trademarks and patents owned by Software AG and/or its subsidiaries is located at
http://documentation.softwareag.com/legal/.
Use of this software is subject to adherence to Software AG’s licensing conditions and terms. These terms are part of the product
documentation, located at http://documentation.softwareag.com/legal/ and/or in the root installation directory of the licensed product(s).
This software may include portions of third-party products. For third-party copyright notices and license terms, please refer to "License
Texts, Copyright Notices and Disclaimers of Third Party Products." This document is part of the product documentation, located at
http://documentation.softwareag.com/legal/ and/or in the root installation directory of the licensed product(s).
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 3
Table of Contents
A. Tag Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
%comment% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
%ifvar% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
%include% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
%invoke% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
%loop% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
%loopsep% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
%nl% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
%rename% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
%scope% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
%switch% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
%sysvar% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
%validConst% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
%value% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
4 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
Table of Contents
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 5
Table of Contents
6 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
About This Guide
This guide is for those developers who want to build browser-based clients using
Dynamic Server Pages (DSPs) and who want to build output templates to format the
results of services executed on the webMethods Integration Server.
Note: This guide describes features and functionality that may or may not be available
with your licensed version of webMethods Integration Server. For information about the
licensed components for your installation, see the Settings > License page in the
webMethods Integration Server Administrator.
Document Conventions
Convention Description
Bold Identifies elements on a user interface.
Narrow font Identifies storage locations for services on webMethods Integration
Server, using the convention folder.subfolder:service.
UPPERCASE Identifies keyboard keys. Keys you must press simultaneously are
joined with a plus sign (+).
Italic Identifies variables for which you must supply values specific to your
own situation or environment. Identifies new terms the first time they
occur in the text.
Monospace Identifies text you must type or messages displayed by the system.
font
{} Indicates a set of choices from which you must choose one. Type only
the information inside the curly braces. Do not type the { } symbols.
| Separates two mutually exclusive choices in a syntax line. Type one of
these choices. Do not type the | symbol.
[] Indicates one or more options. Type only the information inside the
square brackets. Do not type the [ ] symbols.
... Indicates that you can type multiple options of the same type. Type
only the information. Do not type the ellipsis (...).
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 7
About This Guide
Documentation Installation
You can download the product documentation using the Software AG Installer.
Depending on the release of the webMethods product suite, the location of the
downloaded documentation will be as shown in the table below.
Online Information
You can find additional information about Software AG products at the locations listed
below.
Note: The Empower Product Support Web site and the Software AG Documentation
Web site replace Software AG ServLine24 and webMethods Advantage.
8 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
About This Guide
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 9
About This Guide
10 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
1 Using Dynamic Server Pages (DSPs)
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 11
1 Using Dynamic Server Pages (DSPs)
Important! When the Integration Server returns a DSP, it always sets the value of the
HTTP content-type header field to text/html. Therefore, a DSP should only contain
HTML content and should only be used by clients that recognize and accept this
content type.
Note: A DSP tag is never sent to the client; the client receives only the result of the tag.
The following is an example of a very basic DSP (tags are underscored). In this example,
the DSP invokes a service and then loops over the list of documents (called orders) that
the service returns.
<HTML>
<HEAD>
<title>Order Tracking System</title>
</HEAD>
<BODY>
The %invoke% tag <h1>Current Orders</h1>
invokes a service... %invoke orders:showOrders%
%loop orders%
...and the %loop% <p>Date: %value orderDate% PO Number: %value orderNum%</p>
...%endloop% block %endloop%
inserts the results into %endinvoke%
the HTML document. </BODY>
12 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
1 Using Dynamic Server Pages (DSPs)
Creating DSPs
To create a DSP, you must compose it with a text editor and then save it on the
Integration Server (see “Publishing DSPs” on page 14). Unlike output templates, you do
not create DSPs with webMethods Developer.
When you build a DSP, do the following:
Type literal text exactly as you want it to appear in the document that you want the
Integration Server to return to the client.
Insert DSP tags at the points where you want their results to appear. For a summary
of valid DSP tags and how to use them, see “Using the DSP Tags” on page 18.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 13
1 Using Dynamic Server Pages (DSPs)
Make sure that your HTML file contains the proper encoding or META tag for the
encoding you use, as this may affect the browser or parser performance outside the
Integration Server.
Important! Make sure the document that you create resolves into a valid HTML
document.
Note: While building your DSP, keep in mind that at run time the Integration Server
will process it once, from top to bottom.
Publishing DSPs
To run a DSP, you must publish it on a Integration Server. To do this, take the following
general steps.
1 Save the DSP document in a text file that has a “.dsp” extension.
Example: showorders.dsp
2 Place the DSP file in the pub directory of the package in which you want the dsp to reside.
Examples:
To publish a DSP in the orders package, you would copy it to:
IntegrationServer_directory\packages\orders\pub
To publish a DSP in the status subdirectory within the orders package, you would copy
it to:
IntegrationServer_directory\packages\orders\pub\status
For details about publishing DSPs in other languages, see Appendix B, “DSPs and
Output Templates in Different Languages”.
14 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
1 Using Dynamic Server Pages (DSPs)
Securing DSPs
The following sections describe how you can secure DSPs against unauthorized access,
secure against cross site scripting (XSS) attacks, and limit the external URLs to which a
page can be redirected.
Access to services invoked by the DSP. When a user requests a DSP, the services invoked
by the DSP are subject to a port-level check (against the port on which the DSP was
requested) and an ACL check (against the user that requested the DSP). To ensure
that the services in your DSP execute successfully, you must do the following:
Make sure that the services it invokes are allowed to execute on the port(s) where
the DSP will be requested.
Make sure that users who are authorized to use the DSP are also authorized to
execute the services that the DSP invokes. (For convenience, you might want to
assign the same ACL to the DSP and to the services it invokes.)
For information about configuring port-level security and assigning ACLs to services,
see Administering webMethods Integration Server.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 15
1 Using Dynamic Server Pages (DSPs)
Important! If you use encode(none) so that the output from a %value Variable% tag is not
HTML encoded, that value is vulnerable to cross site scripting attacks. If you set the
watt.core.template.enableFilterHTML parameter to false, all DSPs that use the
%value Variable% tag are vulnerable to cross site scripting attacks.
For more information about the encode(none) option, see “%value%” on page 78. For more
information about the watt.core.template.enableFilterHTML parameter, see
Administering webMethods Integration Server.
16 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
1 Using Dynamic Server Pages (DSPs)
Requesting DSPs
To process a DSP, you request it from a browser using the following URL format:
http://hostName:portNum/packageName/fileName.dsp
where:
hostName Is the host name or IP address of the Integration Server on which the
DSP resides.
portNum Is the port number on which the Integration Server listens for HTTP
requests.
packageName Is the name of the package to which the DSP belongs. packageName
must match the package directory in which the DSP resides within
IntegrationServer_directory\packages on the server. If you do not
specify a package name, the server looks for the named DSP in the
Default package.
fileName.dsp Is the name of the file containing the DSP. This file name must have a
“.dsp” extension, and it must reside within the pub directory (or a
subdirectory beneath pub) under the package directory named in
packageName. If the DSP resides in a subdirectory, include the name of
that subdirectory in the file name (see example below).
Examples
The following URL retrieves showorders.dsp from a package named ORDER_TRAK on a
server named rubicon:
http://rubicon:5555/ORDER_TRAK/showorders.dsp
The following URL retrieves showorders.dsp from the STATUS subdirectory in a package
named ORDER_TRAK on a server named rubicon:
http://rubicon:5555/ORDER_TRAK/STATUS/showorders.dsp
The following URL retrieves showorders.dsp from the Default package on a server
named rubicon:
http://rubicon:5555/showorders.dsp
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 17
1 Using Dynamic Server Pages (DSPs)
Hyperlinks to DSPs
Typing the DSP’s URL on the address line in your browser is one way to run a DSP.
However, when you use DSPs to build a user interface, you will often invoke DSPs from
HTML forms and links as shown in the following example.
<HTML>
<HEAD>
<title>Order Tracking System</title>
</HEAD>
<BODY>
<A HREF=/ORDER_TRAK/showorders.dsp>Show Orders</A>
</BODY>
</HTML>
Important! DSP tags are case sensitive. In your DSP, you must type them exactly as
shown below (e.g., type %loop%, not %LOOP%).
18 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
1 Using Dynamic Server Pages (DSPs)
Note: Tags are automatically resolved by Integration Server when a client requests
that DSP via an HTTP or HTTPS request. If you want to resolve tags within a
document at some arbitrary point in a service, you can explicitly run the DSP
Processor against the document using the services in the pub.report folder. For
information about using these services, see “Arbitrarily Processing DSP Tags” on
page 35.
Begin…End Constructs
Many DSP tags have both beginning and ending elements. When you use the %loop% tag,
for example, you enclose the code over which you want the DSP Processor to iterate,
within a %loop%…%end% construct.
To make your DSP easier to read, you can append a suffix to the %end% element of any
construct to visually associate it with its beginning element. For example, in the following
DSP, the %end% element of the %loop% construct is named %endloop% and the %end%
element for the %ifvar% construct is named %endifvar%.
.
.
.
%ifvar orders%
%loop orders%
<p>Date: %value orderDate% PO Number: %value orderNum%</p>
%endloop%
%endifvar%
.
.
Be aware that only the first three characters of an %end% element are significant. The DSP
Processor ignores any suffixes that you add and simply associates an %end% element with
the most recent beginning element (in other words, the %end% element always ends the
current construct). This means that you can nest one construct within another (as shown
above), but you cannot overlap them.
For example, you cannot use the %comment%…%endcomment% construct to “remark out” an
%endloop% element as shown in the following sample.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 19
1 Using Dynamic Server Pages (DSPs)
.
.
.
Because the DSP %ifvar orders%
Processor ignores %loop orders%
suffixes, this <p>Date: %value orderDate% PO Number: %value orderNum%</
%endloop% tag %comment%
would end the
<p>Buyer: %value orderDate% PO Number: %value orderNum%<
comment block
%endloop%
%endcomment%
...and the
%endcomment <p><b>Shipping Details:</b></p>
% tag would <p>Date Shipped: %value shipDate%<br>
end the loop. Carrier: %value carrier% %value serviceLevel%<br>
=============================================</p>
%endloop%
%endifvar%
.
%invoke serviceName%
Block of Code
[%onerror%
Block of Code]
%end%
Example
.
.
.
%invoke orders:getShipInfo%
<p>
Date Shipped: %value shipDate%<br>
Carrier: %value carrier% %value serviceLevel%
</p>
%onerror%
%include standarderror.txt%
%endinvoke%
.
.
.
20 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
1 Using Dynamic Server Pages (DSPs)
What Is Scope?
When you invoke a service in a DSP, notice that you do not specifically state which
parameters you want to pass to it. Instead, the service automatically receives an IData
object containing all the variables that are in the DSP’s current scope.
Scope refers to the set of variables upon which a DSP can operate directly. When a DSP is
initially invoked, its scope encompasses the set of name=value pairs it receives (via GET or
POST) from the requestor. For example, if you were to request a DSP with the following
URL:
http://rubicon:5555/ORDER_TRAK/getorderinfo.dsp?action=shipinfo&oNum=0001152
0
action shipinfo
oNum 00011520A
After you execute a service with the %invoke% tag, the scope automatically switches to
encompass the set of variables returned by that service. For example, if the DSP in the
preceding example invokes a service that returns shipping information, that DSP’s
collection of variables would look like this after the service executes. Note that just the
variables returned by the service are within scope.
action shipinfo
oNum 00011520A
Conceptually, you can think of a DSP as maintaining its run-time variables in a set of
nested containers. It starts with a container that holds the variables submitted by the
requestor. When a service is invoked, it puts the results from the service in a new
container inside the initial container—the new container comprises the current scope. If
another service is invoked while that container is open, the variables returned by the
from the service are put into another container, which is placed inside the previous
container, and so forth.
Important! Besides the %invoke% tag, certain other tags (e.g., %loop%) implicitly switch
scope. This behavior is noted in the tag descriptions in Appendix A, “Tag
Descriptions”.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 21
1 Using Dynamic Server Pages (DSPs)
<HTML>
<HEAD>
<title>Order Tracking System</title>
</HEAD>
<!--User passes in order number in param named <oNum> -->
<!--The initial scope contains only <oNum> -->
%invoke orders:getShipInfo%
<!--Scope switches to results of getShipInfo -->
<!--You can reference variables in the initial scope -->
<!--with a relative addressing qualifier -->
<p>
Order: %value /oNum%<br>
Date Shipped: %value shipDate%<br>
Carrier: %value carrier% %value serviceLevel%
</p>
%endinvoke%
22 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
1 Using Dynamic Server Pages (DSPs)
%invoke orders:getCustInfo%
<!--Scope switches to results of getCustInfo -->
<!--You can reference variables in the initial scope -->
<!--with a relative addressing qualifier -->
<table>
<tr><td>Company:</td> <td>%value companyName%</td></tr>
<tr><td>Phone:</td> <td>%value phoneNum%</td></tr>
<tr><td>Address:</td> <td>%value StreetAddr1%<br>
%value StreetAddr2%</td></tr>
<tr><td></td > <td>%value city%, %value state%</td></tr>
<tr><td></td > <td>%value postalCode%</td></tr>
</table>
%endinvoke%
The following example shows a DSP that invokes two services. In this example, the
second service is invoked within the scope of the first service, so it receives the output
from the first service as input.
<HTML>
<HEAD>
<title>Order Tracking System</title>
</HEAD>
<!--User passes in order number in param named <oNum> -->
<!--The initial scope contains only <oNum> -->
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 23
1 Using Dynamic Server Pages (DSPs)
%invoke orders:getShipInfo%
<!--Scope switches to results of getShipInfo -->
<!--You can reference variables in the initial scope -->
<!--with a relative addressing qualifier -->
<p>
Order: %value /oNum%<br>
Date Shipped: %value shipDate%<br>
Carrier: %value carrier% %value serviceLevel%
</p>
%invoke orders:getCustInfo%
<!--Scope switches to results of getCustInfo -->
<!--You can reference variables in the initial scope -->
<!—and prior scope with relative addressing qualifiers -->
<table>
<tr><td>Company:</td> <td>%value companyName%</td></tr>
<tr><td>Phone:</td> <td>%value phoneNum%</td></tr>
<tr><td>Address:</td> <td>%value StreetAddr1%<br>
%value StreetAddr2%</td></tr>
<tr><td></td > <td>%value city%, %value
state%</td></tr>
<tr><td></td > <td>%value postalCode%</td></tr>
</table>
%endinvoke%
<!--Scope reverts back to results of getShipInfo -->
<!--Results from getCustInfo have been discarded -->
<!--and cannot be accessed beyond this point -->
%endinvoke%
</BODY>
</HTML>
24 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
1 Using Dynamic Server Pages (DSPs)
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 25
1 Using Dynamic Server Pages (DSPs)
<HTML>
<HEAD>
<TITLE>Order Tracking System</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFCC">
<H1>Shipping Information</H1>
Use an HTML form to <HR>
invoke a DSP...
<FORM ACTION="/ORDER_TRAK/getorderinfo.dsp" METHOD="GET">
<P>Enter Order Number <INPUT TYPE="TEXT" NAME="oNum"> <
<INPUT TYPE="HIDDEN" NAME="action" VALUE="shipinfo"> <
<INPUT TYPE="SUBMIT" VALUE="Submit">
...and pass input
parameters to it. </FORM>
<HR>
</BODY>
When the DSP is invoked, its initial scope encompasses two parameters: oNum and action.
Services that you invoke within this scope receive an IData object containing these two
elements.
The following code shows the contents of the DSP (getorderinfo.dsp) invoked by the
previous example. It uses the value in action to conditionally execute a section of the DSP
that invokes the service. (For more information about using the %switch% tag to
conditionally execute a section of code, see “Building Conditional Blocks with the
%switch% Tag” on page 32.)
<HTML>
<HEAD>
<title>Order Tracking System</title>
</HEAD>
<BODY BGCOLOR="#FFFFCC">
26 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
1 Using Dynamic Server Pages (DSPs)
<HTML>
<HEAD>
<title>Order Tracking System</title>
</HEAD>
<BODY BGCOLOR="#FFFFCC">
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 27
1 Using Dynamic Server Pages (DSPs)
Catching Errors
If you want your DSP to react in a specified way when the invoked service fails, include
an %onerror% tag within your %invoke%…%end% construct. The code in the %onerror% block
executes only if an exception occurs while the service executes or the service returns an
error.
When the %onerror% block executes, the scope contains the following values:
Key… Description
error A String containing the Java class name of the exception that was
thrown (e.g., com.wm.app.b2b.server.AccessException).
errorMessage A String containing the exception message in English, regardless
of the locale of the server or client.
localizedMessage A String containing the exception message, translated into the
language used by the client that invoked the DSP.
errorInput The IData object that was passed to the invoked service.
errorOutput The IData object returned by the invoked service. If the service
returned an error, errorOutput will contain $error and any other
variables that were in the pipeline when the service ended.
28 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
1 Using Dynamic Server Pages (DSPs)
The following example shows how you might use an %onerror% clause to return an error
message to the user.
.
.
.
%invoke orders:getShipInfo%
<H2>Shipping Details for Order %value /oNum%</H2>
<P>Date Shipped: %value shipDate%<BR>
.
.
.
%onerror%
<HR>
<P><FONT COLOR="#FF0000">The Server could not process your request
because the following error occurred. Contact your server
administrator.</FONT></P>
<TABLE WIDTH="50%" BORDER="1">
<TR><TD><B>Service</B></TD><TD>%value errorService%</TD></TR>
<TR><TD><B>Error</B></TD><TD>%value error%
%value errorMessage%</TD></TR>
</TABLE>
<HR>
%endinvoke%
.
.
.
%invoke orders:getOrderInfo%
<P>This shipment contains the following items</P>
<TABLE WIDTH="90%" BORDER="1">
<TR><TD>Number</TD><TD>Qty</TD><TD>Description</TD><TD>Status</TD></TR>
%loop items%
<TR>
<TD>%value stockNum%</TD>
<TD>%value qty%</TD>
<TD>%value description%</TD>
<TD>%value status%</TD>
</TR>
%endloop%
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 29
1 Using Dynamic Server Pages (DSPs)
</TABLE>
%endinvoke%
.
.
.
For additional information about the %loop% tag, see the %loop% tag description on
page 61.
%invoke orders:getOrderInfo%
<P>Buyer:</P><P>
%loop –struct buyerInfo%
%value%<BR>
%endloop%
</TABLE>
.
.
.
.
.
.
<P>
%loop –struct%
%value $key% %value%<BR>
%endloop%
</P>
.
.
.
30 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
1 Using Dynamic Server Pages (DSPs)
%ifvar variableName%
Block of Code
[%else%
Block of Code]
%end%
Example
.
.
.
<!--Check for presence of backordered items in the order -->
<!—and display if they exist -->
%ifvar backItems%
<p>Backordered Items
%loop backItems%
%value%<BR>
%endloop%
%endifvar%
.
.
.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 31
1 Using Dynamic Server Pages (DSPs)
.
.
.
%invoke orders:getShipInfo%
<H2>Shipping Details for Order %value /oNum%</H2>
<P>Date Shipped: %value shipDate%<BR>
.
.
.
%ifvar clubMember equals('Y')%
%include membershipterms.txt%
%else%
%include nonmembershipterms.txt%
%endifvar%
%endinvoke%
.
.
.
For additional information about the %ifvar% tag, see the %ifvar% description on page 55.
32 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
1 Using Dynamic Server Pages (DSPs)
The basic format of the %switch % tag is as follows, where variableName specifies the name
of the variable you want to evaluate at run time and switchValue is the value that will
cause a case to execute:
%switch variableName%
%case 'switchValue'%
Block of Code
%case 'switchValue'%
Block of Code
.
.
.
[%case%
Default Block of Code]
%end%
At run time, the DSP Processor evaluates each %case% block in order, and executes the
first block whose switchValue matches the value in variableName. After processing the code
within that block, the DSP Processor skips the remaining cases in the %switch% construct.
The following example shows an %switch% construct that executes one of two cases,
depending on the contents of a variable named action.
.
.
.
%switch action%
%case 'shipinfo'%
%invoke orders:getShipInfo%
.
.
.
%endinvoke%
%case 'vieworder'%
%invoke orders:getOrderInfo%
.
.
.
%endinvoke%
%endswitch%
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 33
1 Using Dynamic Server Pages (DSPs)
.
.
.
%switch acctType%
%case 'Platinum'%
To create a default case, %include platorderform.html%
omit switchValue and put
%case 'Gold'%
this case at the end of
the %switch% construct. %include goldform.html%
%case%
%include regorderform.html%
If you include a default case, you must put it at the end of the switch construct. For
additional information about using the %switch% tag, see the %switch% tag description on
page 73.
Example
.
.
.
%switch acctType%
%case 'Platinum'%
%include forms\platorderform.txt%
%case 'Gold'%
%include forms\goldform.txt%
%case%
%include forms\regorderform.txt%
%endswitch%
When you insert a file, it inherits the scope that is current at the point where you call it.
For additional information about the %include% tag, see the %include% tag description on
page 57.
34 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
1 Using Dynamic Server Pages (DSPs)
.
.
.
%validConst url(http://example.com)%
%endvalidConst%
.
.
.
If you want to allow more than one URL for redirection, you can specify a
comma-separated list of URLs. The following example shows how to use the %validConst%
tag to specify the URLs “http://example.com”, “http://example.org”, and
“http://example.net” are valid for redirection.
Example
.
.
.
%validConst url(http://example.com,http://example.org,http://example.net)%
%endvalidConst%
.
.
.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 35
1 Using Dynamic Server Pages (DSPs)
36 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
2 Creating Output Templates
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 37
2 Creating Output Templates
Note: Create output templates using Developer. You cannot create output templates in
Designer. You can assign output templates to a service using either Developer or
Designer.
You might create a template that looks as follows to return the values in an HTML
document to a browser-based client. The strings in bold are template tags instructing the
server to insert specified values from the pipeline at run time.
38 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
2 Creating Output Templates
Output templates are not limited to HTML. You could create an output template that
looks like this to return values in an XML document:
Or an output template that looks like this to return values as a comma-separated record:
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 39
2 Creating Output Templates
If you assign an existing output template to a service, the output template must reside
in the IntegrationServer_directory\packages\packageName\templates directory where
packageName is the package in which the service is located.
Note: If you assign an output template to a service and later copy that service to a
different package, you must copy the output template file to the
IntegrationServer_directory\packages\packageName\templates directory of the
new package. (If you copy an entire package, any output templates will be
included automatically.)
The server treats the case of the file name differently depending on which operating
system you are using. For example, on a case-insensitive system such as Windows,
the server would see the names template and TEMPLATE as the same name. However,
on a case-sensitive system such as UNIX, the server would see these as two different
names. If you are trying to assign an existing output template and you enter a file
name in the wrong case on a UNIX system, you could end up with the wrong file
name being assigned as the output template for your service.
You can reference one output template from within another.
You can specify the encoding in which to save the template (for example, SJIS, a type
of Japanese encoding). The Integration Server is optimized for the UTF-8 encoding.
You should not change this setting unless you are sure that you want to use another
encoding.
1 Start Developer and connect to the server on which the service resides.
2 In the Navigation panel, select the service to which you want to assign an output
template.
3 In the Properties panel for the service, find the Output Template category. Select the
Name field and do one of the following:
If you want to assign a new output template to the service, type the name of the
new output template. By default, Developer assigns the service an output
template with the name FolderName_ServiceName.
If you want to assign an existing output template to the service, type the file name
of the existing output template. You do not need to include the path information
or the file name extension.
Important! In order to assign an existing output template to the service, the output
template must reside in the
IntegrationServer_directory\packages\packageName\templates directory where
packageName is the same package in which the service is located.
40 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
2 Creating Output Templates
4 In the Type field, select one of the following to specify the format for the output
template:
Select… To…
Note: The Type you select determines the extension for the output template file
(*.html, *.xml, *.wml, or *.hdml). In cases where the output is returned to a Web
browser, the Type also determines the value of the HTTP “Content-Type” header
field (e.g., “text/html,” “text/xml,” “text/vnd.wap.wml,” or “text/x-hdml“).
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 41
2 Creating Output Templates
If you assigned an existing output template to the service and you want to edit the
template, click Edit.
Note: If you created the template file outside of Developer, the Select Encoding
dialog box appears instead of the template dialog box.
Select the encoding used to create the template file and click OK. (By default,
Developer uses UTF-8 to create output template files.)
6 In the template dialog box, create or edit the output template by typing HTML, XML,
WML, or HDML content, and/or by inserting template tags. For more information
about creating an output template, see “Creating an Output Template” on page 46.
For more information about template tags, see Appendix A, “Tag Descriptions”.
7 In the File Encoding list, select the encoding in which you want the template file saved.
The encoding is used by the Integration Server to send the template to the browser
and to interpret data posted in the resulting page in the browser The default encoding
is Unicode (UTF8).
You should not change this setting unless you are sure that you wish to use another
encoding. The Integration Server is optimized for the UTF-8 encoding. The encoding
you choose also applies to any localized (translated) versions of the template that you
may create, so you should choose a character encoding that supports all of the
languages for which you will create localized templates. For details, see Appendix B,
“DSPs and Output Templates in Different Languages”.
42 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
2 Creating Output Templates
If you do change this setting, make sure that your XML or HTML file contains the
proper encoding or META tag for the encoding you use, as this may affect the
browser or parser performance outside the Integration Server.
Note: The File Encoding you select limits the characters that you can use in your
template (including the data inserted into your template using %VALUE%
statements) to those in the character set of the encoding you choose. It also limits
any translated versions of the templates to the same character set. Generally it is a
good idea to use the UTF-8 (Unicode) encoding, since Unicode supports nearly all
of the characters in all of the world's languages. You will not lose any data if you
choose to save your template in UTF-8; any data entered into a form will be
properly interpreted by the Integration Server.
8 Click Save.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 43
2 Creating Output Templates
44 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
2 Creating Output Templates
The browser on the wireless device needs to support WML 1.1 or higher to receive a
WML output template from the Integration Server.
Different types of Web browsers on wireless devices may display WML pages
differently.
Some Web browsers for wireless devices place a limitation on the length of a URL:
name in WML pages. Make sure that you create WML pages that are compliant with
the browser requirements.
For more information about WML, see http://www.oasis-open.org/cover/.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 45
Creating an Output Template
An output template is an arbitrary string of text that you create and save in a file. You can
use Developer to create an output template file or you can create it with an ordinary text
editor.
When you create an output template, keep the following points in mind:
The template file must reside in the template directory of the package where the
service resides
(i.e., IntegrationServer_directory\packages\packageName\templates).
Note: If you assign an output template to a service and later copy that service to a
different package, you must copy the output template file to the
IntegrationServer_directory\packages\packageName\templates directory of the
new package. (If you are copying an entire package, any output templates will be
included automatically.)
You must give an output template file a name that is unique within the package.
If you want to work with (i.e., edit or assign) an output template using Developer,
you must give the file an HTML, XML, WML, or HDML extension.
If you selected a File Encoding other than UTF-8, the characters that you use in your
template (including the data inserted into your template using %VALUE%
statements) are limited to those in the character set of the encoding you chose.
To create the contents of an output template file, type all literal text exactly as you want it
to appear in the result and then embed any of the following tags where you want the
server to execute them at run time. For a complete description of each tag, see
Appendix A, “Tag Descriptions”.
Important! These tags are case sensitive and must be typed exactly as shown in this
document. Additionally, all text between %…% symbols in a tag must appear on one
line (i.e., a tag cannot contain line breaks).
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 46
2 Creating Output Templates
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 47
2 Creating Output Templates
Important! If you use encode(none) so that the output from a %value Variable% tag is not
HTML encoded, that value is vulnerable to cross site scripting attacks. If you set the
watt.core.template.enableFilterHTML parameter to false, all documents and pages
resulting from output templates that use the %value Variable% tag are vulnerable to
cross site scripting attacks.
For more information about the encode(none) option, see “%value%” on page 78. For
more information about the watt.core.template.enableFilterHTML parameter, see
Administering webMethods Integration Server.
48 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
2 Creating Output Templates
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 49
2 Creating Output Templates
50 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
%comment% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
%ifvar% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
%include% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
%invoke% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
%loop% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
%loopsep% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
%nl% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
%rename% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
%scope% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
%switch% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
%sysvar% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
%validConst% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
%value% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 51
A Tag Descriptions
Overview
This appendix describes the tags you use to construct Dynamic Server Pages (DSPs) and
output templates.
Important! Tags are case sensitive and must be typed into a template or DSP exactly as
shown in this appendix (e.g., %loop%, not %LOOP% or %Loop%).
Important! All text between %…% symbols in a tag must appear on one line (i.e., no
line breaks).
The examples shown in this appendix assume a pipeline that looks as follows:
52 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 53
A Tag Descriptions
%comment%
You use the %comment% tag to include remarks in your code. At run time, the server
ignores all text (and tags) between the %comment% and %end% tag.
Syntax
%comment%
Block of Code
%end%
Effect on Scope
None
Examples
The following example contains a section of explanatory information.
%comment%
Use this template to generate an order list from any document containing a
purchased item number, quantity, description, and PO number
%end%
<tr>
<td>%value stockNum%</td>
<td>%value qty%</td>
<td>%value description%</td>
<td>%value orderNum%</td>
</tr>
54 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
%ifvar%
You use the %ifvar% tag to conditionally include or exclude a block of code based on the
existence or value of a specified variable.
Syntax
%ifvar Variable [option option option…]%
Block of Code
[%else%
Block of Code]
%end%
Arguments
Variable specifies the name of the variable that determines whether or not the enclosed
block of code is processed.
Options
You can use any of the following options with this tag. To specify multiple options,
separate them with spaces.
Options Description
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 55
A Tag Descriptions
Effect on Scope
None
Notes
For readability, you can optionally use %endif% or %endifvar% instead of %end% to denote
the end of the %ifvar% block.
Examples
The following example inserts a paragraph if a variable named AuthCode exists.
.
.
.
%ifvar AuthCode%
<p>Authorization Code Received %value $date%: %value AuthCode%</p>
%endif%
.
.
.
The following example generates a line for each element in the backItems String list only if
backItems exists; otherwise, it prints a standard message.
.
.
.
%ifvar backitems%
<p>The following items are backordered</p>
<p>
%loop backItems%
%value%<BR>
%endloop%
</p>
%else%
<p>There are no backordered items pending for your account</p>
%end%
.
.
.
56 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
%include%
You use the %include% tag to reference a text file. When you %include% a text file, the server
inserts the contents of the specified file (processing any tags it contains) at run time. If
you use template and/or DSPs extensively, you may want to build a library of standard
“code fragments” that you reference using %include% tags as needed.
Syntax
%include FileName%
Arguments
FileName specifies the name of the text file that you want to insert. If the text file is not in
the same directory as the template or DSP that references it, FileName must specify its
path relative to the template or DSP file.
Effect on Scope
None. If the inserted file contains tags, they inherit the scope that is in effect at the point
where the %include% tag appears.
Examples
The following example inserts a file called “TMPL_ShipToBlock.html” into the code.
Because path information is not provided, the server expects to find this file in the same
directory as the file containing the template or DSP.
.
.
.
%scope buyerInfo%
<p>Shipped To:<br>
%include TMPL_ShipToBlock.html%</p>
%end%
.
.
.
The following example inserts a file called “TMPL_ShipToBlock.html” into the code. At
run time, the server expects to find this file in a subdirectory called “StandardDSPs” in
the directory where the template or DSP resides.
.
.
.
%scope buyerInfo%
<p>Shipped To:<br>
%include StandardDSPs/TMPL_ShipToBlock.html%</p>
%end%
.
.
.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 57
A Tag Descriptions
The following example inserts a file called “TMPL_ShipToBlock.html” into the code. At
run time, the server expects to find this file in the template or DSPs parent directory.
.
.
.
%scope buyerInfo%
<p>Shipped To:<br>
%include ../TMPL_ShipToBlock.html%</p>
%end%
.
.
.
58 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
%invoke%
You use the %invoke% tag to execute a service from a DSP. When you use this tag, the
server executes the specified service at run time and returns the results of the service to
the DSP. You may optionally include the %onerror% tag within the %invoke% block to define
a block of code that executes if an exception occurs while the service executes or the
service returns an error.
This tag can only be used in DSPs. It cannot be used in an output template.
Syntax
%invoke serviceName%
Block of Code
[%onerror%
Block of Code]
%end%
Arguments
serviceName specifies the fully qualified name of the service that you want to invoke.
Effect on Scope
Within an %invoke% block, the scope switches to the results of the service. If the service
fails, the scope within the %onerror% block contains the following:
Key Description
error A String containing the Java class name of the exception that was
thrown (e.g., com.wm.app.b2b.server.AccessException).
errorMessage A String containing the exception message.
errorInput The IData object that was passed to the invoked service.
errorOutput The IData object containing the output returned by the invoked
service. If the service returned an error, errorOutput will contain
$error. If the service experienced an exception, errorOutput will not
exist.
errorService The name of the invoked service.
Examples
The following example invokes a service that returns shipping information and a form
allowing the user to optionally edit or cancel an order. This example also includes a
%onerror% block that displays error information if the service fails.
%invoke orders:getShipInfo%
<H2>Shipping Details for Order %value /oNum%</H2>
<P>Date Shipped: %value shipDate%<BR>
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 59
A Tag Descriptions
60 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
%loop%
You use the %loop% tag to repeat a block of code once for each element in a specified array
(String list or document list) or for each key in a document.
Syntax
%loop [Variable] [option option option…] %
Block of Code
%end%
Arguments
Variable specifies the name of the array variable over which you want the enclosed section
of code to iterate.
You may optionally omit Variable and specify the –struct option to loop over each
element in the current scope.
When looping against a set of complex elements (e.g., documents, document lists,
String lists) in a document, you can optionally use the #$key keyword to specify
Variable instead of explicitly specifying a key name. When you use #$key in place of
an explicit key name, it indicates that you want to apply the body of the loop to (i.e.,
switch the scope to) the current key. This allows you to process the contents of a
document whose key names are not known. It is most often used with the –struct
option to process a set of documents contained within another document. For an
example of how this option is used, see the Examples section, below.
Options
You can use any of the following options with this tag. To specify multiple options,
separate the options with spaces.
Option Description
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 61
A Tag Descriptions
Option Description
-eol Ends the body of the loop at the next end-of-line (EOL) character
in the code. When you use –eol, you can omit the %end% tag.
-$index Returns the current index number in an array. You can use it
within a loop to obtain the index number upon which the loop is
acting during each iteration.
Effect on Scope
If Variable is a document list, scope switches to the document on which the loop is
executing.
Notes
Omit the variable name from the %value% tag if it is used in the body of a loop for a String
table or a document. When variable name is omitted, the server inserts the value of the
current element at run time.
For readability, you can optionally use %endloop% instead of %end% to denote the end of a
%loop% block.
Examples
The following example generates a paragraph for each document in the items document
list.
.
.
.
<p>This shipment contains the following items:</p>
%loop items%
<p>%value qty% %value stockNum% %value description% %value status%</p>
%end%
.
.
.
62 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
The following example generates a line for each element in the backItems String list.
.
.
.
<p>The following items are backordered</p>
<p>
%loop backItems%
%value%<BR>
%end%
</p>
.
.
.
The following example shows how you can nest %loop% tags to process the individual
document elements in a document list.
.
.
.
<This shipment contains the following items:</p>
<table>
%loop items%
<tr>
%loop –struct%
<td>%value%</td>
%end%
</tr>
%end%
.
.
.
The following example shows how you can use the %loop% tag to dump the contents (key
names and values) of the current scope.
.
.
.
%loop -struct%
%value $key% %value%<BR>
%end%
.
.
.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 63
A Tag Descriptions
The following example shows how you use the #$key option to loop over the individual
elements in a collection of documents contained within another document.
This example assumes that the service returns a document named
MatchingAddresses that holds a set of documents (of unknown name and
quantity) containing address information.
.
.
.
<p>The following addresses were returned:</p>
%loop -struct MatchingAddresses%
%loop –struct #$key%
<p>
%value streetAddr1%
%value streetAddr2%
%value city%, %value state% %value postalCode%
</p>
%end%
%end%
.
.
.
The following example shows how to obtain the iteration number of the loop execution
and insert it into the output:
indices = {%loop arrayA%%value $index%%loopsep ','%%endloop%}
64 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
%loopsep%
You use the %loopsep% tag to insert a specified character sequence between the results
from a %loop% block.
Syntax
%loopsep 'sepString'%
Arguments
sepString is a string that you want to insert between each result.
Effect on Scope
None
Notes
%loopsep% does not insert sepString after the result produced by the last iteration of the
loop.
Examples
The following example inserts a comma between each value produced by the loop.
.
.
.
%loop items%
%loop -struct%
%value%
%loopsep ','%
%endloop%
%endloop%
.
.
.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 65
A Tag Descriptions
%nl%
You use the %nl% tag to generate a new line character in the code. The tag is useful when
you want to preserve the ending of a line that ends in a tag. If you do not explicitly insert
a %nl% tag on such lines, the server drops the new line character following that tag. (Note
that this tag does not insert the HTML line break <BR>code. It merely inserts a line break
character, which is treated as white space.) The main reason you use this tag is to
preserve the format of the underlying code in a DSP, which can make it easier to read
during debugging.
Syntax
%nl%
ArgEffect on Scope
None
Examples
The following example shows how the %nl% tag is used to preserve the line endings on
lines occupied by the three %value% tags. If the %nl% tag did not appear in this code, the
three lines would be concatenated in the HTML document generated by the server.
.
.
.
<hr>
<p>Shipping Info:
%value carrier%%nl%
%value serviceLevel%%nl%
%value arrivalDate%%nl%</p>
<hr>
.
.
.
66 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
%rename%
You use the %rename% tag to move or copy a variable in the pipeline.
Syntax
%rename SourceVar TargetVar [option option option…]%
Arguments
SourceVar is the name of the variable that you want to move or copy. SourceVar can reside
in any existing scope or document.
TargetVar specifies the name of the variable to which you want SourceVar moved or
copied. TargetVar must be in the current scope. If TargetVar does not exist, it will be
created. If TargetVar already exists, it will be overwritten.
Options
You can use the following option with this tag.
Option Description
Effect on Scope
Does not cause scope to switch to a different level, but, depending on how you use this
tag, it may alter the contents of the current scope.
Examples
The following example renames the state variable in the current scope.
.
.
.
%scope buyerInfo%
%rename state ST%
%invoke TMPL_ShipToBlock.html%</p>
%end%
.
.
.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 67
A Tag Descriptions
The following example copies the variable named oNum from the previous scope into the
current scope.
.
.
.
%invoke orders:getCustInfo%</p>
%rename ../oNum oNum -copy%
%invoke orders:getOrderDetails%</p>
.
.
.
68 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
%scope%
You use the %scope% tag to restrict a specified block of code to a particular document in
the pipeline. You can also use the %scope% tag to define a completely new document and
switch the scope to that document.
Syntax
%scope [DocumentName] [option option option…]%
Block of Code
%end%
Arguments
DocumentName specifies the name of a document within the current scope. If you do not
specify DocumentName, the param and rparam options will extend the current scope. If
you specify a new DocumentName, the scope switches to that document.
Options
You can use any of the following options to add elements to the scope specified by
DocumentName. When you specify multiple options, separate them with spaces.
Important! If you set the value of an existing variable with these options, the value you
specify will replace the variable’s current value.
Note: For space reasons, the %scope% tag is shown on multiple lines in some of the
examples below. Be aware that when you use the %scope% tag in a template or DSP, the
entire tag must appear on one line.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 69
A Tag Descriptions
Option Description
param(Name='Value') Defines a new String or String array with the name you
specify in Name and assigns to it the string you specify in
Value.
If Name is a String, specify one Value and enclose it in
single quotes.
Example %scope param(buyerClass='Gold')%
If Name is a String array:
Include a set of empty brackets at the end of the name
to indicate that you are defining an array.
Enclose each element Value in single quotes.
Separate elements with commas.
Example %scope param(shipPoints[]='BWI','LAX',
'ORD','MSP','DFW')%
70 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
Effect on Scope
Switches scope to the specified document.
Notes
The specified scope remains in effect until the next %scope% tag is encountered (which
declares a new scope) or the next, non-nested %end% tag is encountered (which reverts to
the prior scope).
For readability, you may use %endscope% instead of %end% to denote the end of the
%scope% structure.
Examples
The following example sets the scope to the document named buyerInfo.
.
.
.
%scope buyerInfo%
<p>Shipped To:<br>
%value companyName%<br>
%value streetAddr1%<br>
%value streetAddr2%<br>
%value city%, %value state% %value postalCode%
%end%
.
.
.
The following example sets the scope to document buyerInfo and then uses the param
option to add variables called buyerClass and shipPoint to that document.
.
.
.
%scope buyerInfo param(buyerClass='Gold') param(shipPoint='BWI Hub')%
<p>Shipped To:<br>
%value companyName%<br>
%value streetAddr1%<br>
%value streetAddr2%<br>
%value city%, %value state% %value postalCode%</p>
<hr>
<p>Point of Departure: %value shipPoint%<br>
Customer Class: %value buyerClass%</p>
%end%
.
.
.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 71
A Tag Descriptions
The following example sets the scope to document buyerInfo and then uses the rparam
option to add a String variable named req to that scope before invoking a service.
.
.
.
<p>Open Orders:</p>
%scope buyerInfo rparam(req=openorders)%
%invoke orders:getOrderInfo%<br>
%loop orders%
Date: %value oDate%
Number: <A HREF="showOrder.dsp&oNum=%value oNum%">%value oNum%</A>
<br>
%endloop%
<p>Click Order Number to View Details:</p>
%endscope%
.
.
.
72 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
%switch%
You use the %switch% tag to process one block from a series of predefined alternatives
based on the value of a specified variable at run time.
Syntax
%switch Variable%
%case 'SwitchValue'%
Block of Code
%case 'SwitchValue'%
Block of Code
.
.
.
[%case%
Default Block of Code]
%end%
Arguments
Variable specifies the name of the variable whose value will determine which case is
processed at run time.
SwitchValue is a string that specifies the value that will cause the associated case to be
processed at run time.
Effect on Scope
None
Notes
To select a case, SwitchValue must match the value of Variable exactly. SwitchValue is case
sensitive—”FedEx” does not match “Fedex” or “FEDEX”.
The server evaluates %case% tags in the order that they appear in your code. When it
finds a “true” case, it processes the associated block of code and then exits the
%switch%…%end% structure.
You can specify a default case using the %case% tag without a SwitchValue. This case will
be processed if Variable does not exist or if none of the other cases are true. The default
case must appear as the last %case% in the %switch%…%end% structure.
For readability, you can optionally use %endswitch% instead of %end% to denote the end of
the %switch% structure.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 73
A Tag Descriptions
Examples
The following example inserts a specified paragraph, depending on the value in carrier.
.
.
.
%switch carrier%
%case 'FedEx'%
<p>Shipped via Federal Express %value serviceLevel% %value trackNum%
%case 'UPS'%
<p>Shipped via UPS %value serviceLevel%
%case 'Freight'%
<p>Shipped via %transCompany%<br>
FOB: %value buyerInfo/streetAddr1%<br>
%value buyerInfo/streetAddr2%<br>
%value city%, %value state% %postalCode%
%end%
</p>
.
.
.
The following example invokes different services based on the value of a variable named
action.
<HTML>
<HEAD>
<title>Order Tracking System</title>
</HEAD>
<BODY BGCOLOR="#FFFFCC">
<H1>Order Tracking System</H1>
<HR>
%switch action%
%case 'shipinfo'%
%invoke orders:getShipInfo%
.
.
%case 'showorder'%
%invoke orders:getOrderInfo%
.
.
%case 'showinvoice'%
%invoke orders:getInvoices%
.
.
%end%
<HR>
%include stdFooter.txt%
</BODY>
</HTML>
74 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
%sysvar%
You use the %sysvar% tag to insert the value of a special variable or server property into
the document.
Syntax
%sysvar SystemVariable%
Arguments
SystemVariable is one of the following values, indicating which system variable or
property you want to insert.
Value Description
host Inserts the name of the server that processed the DSP or
template.
date Inserts the current date. The date will appear in
“Weekday Month Day HH:MM:SS Locale Year” format—
e.g., Fri Aug 12 04:15:30 Pacific 2007.
lastmod Inserts the date and time that this file was last modified.
The date will appear in “Weekday Month Day HH:MM:SS
Locale Year” format—e.g., Fri Aug 12 04:15:30 Pacific
2007.
Effect on Scope
None
Examples
The following example inserts the name of the server processing the DSP or template and
the date on which it was processed:
.
.
.
Response generated on %sysvar date% by host %sysvar host%
.
.
.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 75
A Tag Descriptions
The following example includes the value of the “watt.server.port” property, which
identifies the server’s main HTTP listening port:
.
.
.
<p>
%sysvar host% was listening on %sysvar property(watt.server.port)%
<p>
.
.
.
76 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
%validConst%
You use the %validConst% tag to specify a list of external URLs that will be permitted for
redirection from the page.
Syntax
%validConst url(url1,url2,...,urln)%
%endvalidConst%
Arguments
url(url1,url2,...,urln)%
is one or more URLs to which the page can be redirected. Use a
comma-separated list to specify more than one URL.
Effect on Scope
None
Examples
The following example shows how to allow the page to redirect to the URLs
http://example.com, http://example.org, and http://example.net:
.
.
.
%validConst url(http://example.com,http://example.org,http://example.net)
%endvalidConst
.
.
.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 77
A Tag Descriptions
%value%
You use the %value% tag to insert the value of a specified variable in a document.
Syntax
%value [Variable] [option option option…]%
Arguments
Variable specifies the name of the variable whose value you want to insert into the code.
You may specify the name of a variable that exists in the pipeline or the following
keyword/reserved words.
Variable Description
$key Inserts the name of the current key. You can use this keyword
when looping over a document (i.e., using the %loop –struct%
tag) to retrieve the name of each key in the current scope or a
specified document.
url url Instructs Integration Server to redirect to the specified URL.
returnurl url Software AG recommends that you only use the reserved words
url or returnurl when you want to redirect a DSP page to a
location internal to Integration Server, by using a relative path
(e.g., %value url ../redirectedurl.dsp%), or to redirect to an external URL
that you have allowed using the %validConst% tag.
If you attempt to use the reserved words url or returnurl to
redirect to an external URL (e.g., http://example.com) that you
have not allowed using the %validConst% tag, the setting of the
watt.core.template.enableSecureUrlRedirection server
configuration parameter governs the server’s behavior. When the
watt.core.template.enableSecureUrlRedirection parameter is:
true, Integration Server uses secure URL redirection and
prepends the value “error.dsp?data=” to the output of the
%value% tag (e.g., error.dsp?data=http://example.com). This is
the default setting for the
watt.core.template.enableSecureUrlRedirection parameter.
false, Integration Server does not use secure URL redirection.
That is, Integration Server does not prepend “error.dsp?data=”
to the external URL and, as a result, redirection to the external
URL is possible, which might put your application at risk.
When you specify Variable, the server retrieves the variable from the current scope. To
select a variable outside the current scope, you use the following symbols to address it.
78 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
If you don’t specify Variable, the current element within the current scope is assumed. (See
example of this usage, below.)
Options
You can use any of the following options with this tag. To specify multiple options,
separate the options with spaces.
Option Description
null='AnyString' Specifies the string that you want the server to insert when
Variable is null. You specify the string in AnyString.
Example %value carrier null='No Carrier Assigned'%
empty='AnyString' Specifies the string that you want the server to insert when
Variable contains an empty string. You specify the string in
AnyString.
Example %value description empty='Description Not Found'%
index=IndexNum Specifies the index of an element that you want to insert. You
can use this option to extract an element from an array variable.
Specify an integer that represents the element’s position in the
array. (Arrays are zero based.)
Example %value backItems index=1%
$index Returns the current index number in an array. This option is
usually used with the %loop% tag to print the loop’s iteration.
See “%loop%” on page 61 for more information and an
example.
encode(Code) Encodes the contents of Variable prior to inserting it, where Code
specifies the encoding system you want the server to apply to
the string.
Set Code to... To encode the value using...
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 79
A Tag Descriptions
Option Description
decode(Code) Decodes the contents of Variable prior to inserting it, where Code
specifies the way in which Variable is currently encoded.
Set Code to... To encode the value using...
Effect on Scope
None
Examples
The following example invokes a service and then uses the %value% tag to insert the
results of the service into the DSP.
.
.
.
%invoke orders:getOrderInfo%<br>
<p>%value buyerInfo/companyName%<br>
%value buyerInfo/acctNum%
<P>This shipment contains the following items</P>
80 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
A Tag Descriptions
The following example inserts the contents of carrier. If carrier is null, the string “UPS” is
inserted. If carrier is empty, the string “UPS” is also inserted.
%value carrier null=UPS empty=UPS%
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 81
A Tag Descriptions
82 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
B DSPs and Output Templates in Different Languages
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Creating DSPs and Templates in Other Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Using Localized DSPs and Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
The localeID Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 83
B DSPs and Output Templates in Different Languages
Overview
This appendix contains procedures and guidelines for using DSPs and output templates
in different languages (or for translating into other languages) with the webMethods
Integration Server.
84 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
B DSPs and Output Templates in Different Languages
You can create the default file in any language. Exercise care when selecting the language
for the file, since the default file will be displayed to all users for who you did not supply
a specific file for their locale (or to those users who did not set their browser to request a
language).
The default file is located at the root directory of published DSPs and templates in a
package. For details on creating DSPs or templates, see “Using Dynamic Server Pages
(DSPs)” on page 11 or “Creating Output Templates” on page 37. For details on
publishing the default DSP or template to the server, see the next section.
Points to Remember
You must create the default DSP or output template file with the same filename and
encoding as its corresponding localized files on the server.
You should create the default file with UTF-8 encoding to reduce difficulty in
localizing later into other languages.
Keep the contents of the default file generic.
Note: If you already created or imported an output template in Developer for a service
in a package, then you already have a default template for that package.
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 85
B DSPs and Output Templates in Different Languages
Netscape. Click EditPreferences. On the Languages screen, make sure that the
language in which you want to display the DSP or template is at the top of the list.
If not, use the Add and arrow buttons to adjust the language setting.
Netscape—Languages Screen
2 Click OK. The Integration Server stores this setting as your user locale.
86 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
B DSPs and Output Templates in Different Languages
1 Save the DSP document in a text file that has a “.dsp” extension. Make sure that the
default DSP file has the same name and encoding as the localized DSP file.
Example showorders.dsp
2 Place the default DSP file in the pub directory of the package in which you want the
DSP to reside.
Example
To publish a default DSP in the orders package, you would copy it to:
IntegrationServer_directory\packages\orders\pub
3 Place the localized DSP file in the pub\localeID directory of the package in which you
want the DSP to reside. You may have to create this directory. The localeID
corresponds to a language code as defined in RFC 3066 by the W3C. For details on
localeID values, see “The localeID Value” on page 90.
Examples
To publish a Japanese DSP in the orders package, you would copy it to:
IntegrationServer_directory\packages\orders\pub\ja\
To publish an English DSP in the orders package, you would copy it to:
IntegrationServer_directory\packages\orders\pub\en\
To publish a United Kingdom English DSP in the orders package, you would copy it
to:
IntegrationServer_directory\packages\orders\pub\en-GB\
To publish a United Kingdom English DSP in the status subdirectory within the orders
package, you would copy it to:
IntegrationServer_directory\packages\orders\pub\en-GB\status\
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 87
B DSPs and Output Templates in Different Languages
1 Save the template document to a file. If you want to edit or assign the template in
Developer, make sure that the file has a HTML, XML, WML, or HDML extension.
Make sure that the default template file has the same name and encoding as the
localized template file.
Example showorders.html
2 Place the default template file in the templates directory of the package in which you
want the template to reside.
Example
To publish a default template in the orders package, you would copy it to:
IntegrationServer_directory\packages\orders\templates\
3 Place the localized template file in the templates\localeID directory of the package in
which you want the template to reside. You may have to create this directory. The
localeID corresponds to a language and country code as defined in RFC 3066 by the
W3C. For details on localeID values, see “The localeID Value” on page 90.
Examples
To publish a Japanese template in the orders package, you would copy it to:
IntegrationServer_directory\packages\orders\templates\ja\
To publish an English template in the orders package, you would copy it to:
IntegrationServer_directory\packages\orders\templates\en\
To publish a United Kingdom English template in the orders package, you would copy
it to:
IntegrationServer_directory\packages\orders\templates\en-GB\
To publish a United Kingdom English template in the status subdirectory within the
orders package, you would copy it to:
IntegrationServer_directory\packages\orders\templates\en-GB\status\
Note: If you have references to other files within your DSP or template (for example,
CSS and GIF files), the same localization rules apply. Make sure to publish those files
in the appropriate directory for locale.
88 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
B DSPs and Output Templates in Different Languages
For details on the values in the URL, see “Requesting DSPs” on page 17.
Examples
The following URL retrieves showorders.dsp from a package named ORDER_TRAK on a
server named rubicon:
http://rubicon:5555/ORDER_TRAK/showorders.dsp
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 89
B DSPs and Output Templates in Different Languages
You can also have a localeID that is less specific by using the language code only. For
examples, see the following table.
90 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
Index
Symbols C
#$key variable 61, 64 case tag 32, 73
%case% tag 32, 73 catching errors 28
%comment% tag 18, 47, 54 closing the scope 22
%else% tag 31, 55 comment tag 18, 47, 54
%ifvar% tag 18, 47, 55 conditionally executing blocks of code 31
usage and examples 31 Content-Type header
%include% tag 18, 47, 57 for DSPs 12
usage and examples 34 text/html 43
%invoke% tag 18, 38, 59 text/vnd.wap.wml 44
usage and examples 20 text/x-hdml 45
%loop% tag 18, 30, 47, 61 text/xml 44
struct option 30 conventions used in this document 7
usage and examples 29 copying a service with an assigned output template
%loopsep% tag 65 40
%nl% tag 47, 66 creating
%onerror% tag 28, 59 DSPs 13
%rename% tag 18, 28, 47, 67 HDML-based output templates 45
%scope% tag 18, 28, 46, 69 HTML-based output templates 43
%switch% tag 18, 47, 73 output templates 46
default case specification 34 WML-based output templates 44
usage and examples 32 XML-based output templates 44
%sysvar% tag 75 current scope, dumping 30
%validConst% tag 77
%value% tag 18, 46, 78 D
$key variable 61, 63, 78 directory location
of DSPs 14
A of output templates 40
ACLs and DSPs 15 document elements, looping over 30
advantages of using DSPs 13 documentation
applying output templates arbitrarily 45 conventions used 7
arbitrarily processing DSP tags 35 DSPs
array values, looping over 29 #$key variable 61
assigning a template to a service 39 $key variable 63, 78
ACL settings 15
B advantages of using 13
begin…end constructs 19 begin…end constructs 19
building conditional blocks catching errors 28
with the %ifvar% tag 31 comment tag 18, 54
with the %switch% tag 32 conditional code 31
creating 13
definition of 12
dumping the current scope 30
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 91
Index
92 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2
Index
O R
onerror tag 28, 59 referencing variables in and out of scope 24
output templates 38 rename tag 18, 28, 47, 67
applying arbitrarily 45 report services 35
assigning to a service 39 requesting a DSP 17
comment tag 47, 54 requesting a localized DSP 89
copying or moving with a service 40
creating 46 S
definition of 38 scope
for browser-based clients 43 closing 22
for e-mail clients 44 definition of 21
for FTP clients 44 effect on pipeline 22
for HTTP clients 43 examining current values of 30
for non-browser clients 44 referencing variables outside of 24
for wireless devices 44 scope tag 18, 28, 46, 69
guidelines for HDML templates 45 securing a DSP 15
guidelines for HTML templates 43 server property value, inserting 75
guidelines for WML templates 44 services
guidelines for XML templates 44 invoking in a DSP 20, 38
ifvar tag 47, 55 keeping the output template when copying or
include tag 47, 57 moving 40
location of 40 passing input to 25, 28
loop tag 47, 61 security issues 15
loopsep tag 65 Settings tab, See Properties panel
nl tag 47, 66 SMTP clients and output templates 43, 44
rename tag 47, 67 specifying a default case 34
scope tag 46, 69 struct option 30, 61
summary of tags 46 summary of tags
switch tag 47, 73 for DSPs 18
sysvar tag 75 for output templates 46
Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2 93
Index
T
tags
begin…end constructs 19
for DSPs 18
for output templates 46
syntax 52, 84
templates. See output templates
templates directory 40
testing for a particular value 31
timestamp, inserting 75
typographical conventions in this document 7
U
URL format for a DSP 17, 89
urls, limiting those for redirection 77
using output templates
to return output to HTTP clients 43
to return output to SMTP and FTP clients 44
to return output to wireless devices 44
using the %loop% tag to examine the current scope
30
using the DSP tags 18
V
validConst tag 77
value tag 18, 46, 78
variables, referencing 24
W
wireless devices and output templates 44
Wireless Markup Language 44
WML 44
WML-based templates 44
X
XML-based templates 44
94 Dynamic Server Pages and Output Templates Developer’s Guide Version 8.2