Introduction
Active Server Page (ASP) allows you to write scripts that run on a server and provide standard HTML output. Although ASP is available only in Microsoft Internet Information Server or Microsoft Peer Web Services, any web browser can display the HTML output. Software requirements
To complete this tutorial, you need these software resources:
These sample applications were developed with Microsoft Visual InterDev 1.0. Although these sample applications were developed and tested with Microsoft Visual InterDev 1.0, you do not need it to run, build, or modify the source code.
In this chapter
In this chapter, you create ASP applications that use the ATK ActiveX server to retrieve tabular information from an ObjectStore database. This chapter contains these exercises:
Build an Application with ATK and ASP
Overview
This application uses ATK and ASP to query an ObjectStore database to retrieve ActiveX objects, build a table for display, and publish the output in HTML for display in any web browser. Process
To build an application with ATK and ASP, follow these steps:
Tip: In Inspector, instance format information is saved in grid templates. Instance format information is just one aspect of grid templates - grid templates include other information (fonts, formulas, and annotation, for example) that is not used by ATK.
3 Create the Active Server Page.
You can create an Active Server Page using Visual InterDev or a simple text editor. Procedures for using Visual InterDev are shown here. Using Visual InterDev
To create an Active Server Page using Visual InterDev:
Tip: If you are using a text editor to create an Active Server Page, create a file with an .asp extension that contains the text and format shown in the preceding window.
4 Create and access ATK ActiveX objects.
You can write VBScript or JavaScript code to create and access ATK ActiveX objects. In VBScript
This VBScript code is very similar to the Visual Basic example in Chapter 1, A Visual Basic Application with ATK ActiveX Server:
<%
On Error Resume Next
'Create the ATKKernel object
Set theKernel=Server.CreateObject("ATKKernel.Document")
'Try opening the database
Set theDatabase=theKernel.OpenDatabase("c:\odi\ATK6.0\Examples\demodbs\carsdemo.db")
If Err.Number = 0 Then 'If no errors occurred...
'Open "my_tut2_table1"
Set theDataView=theDatabase.GetDataView("my_tut2_table1")
If Err.Number = 0 Then 'If no errors occurred...
Set theTable= theDataView.GetATKTable 'Get the ATKTable object...
WriteTable(theTable) '...and print it
Else 'Error condition
Response.Write("Data view not found: " & Err.Description & "<BR>")
End If
Else 'Error condition
Response.Write("Error opening database: " & Err.Description & "<BR>")
End If
%>
The WriteTable procedure can display any ATKTable object in HTML:<SCRIPT LANGUAGE="VBScript" RUNAT=Server>
Sub WriteTable(theTable)
'Initialize the HTML table
Response.Write("<TABLE BORDER=1>" & CHR(13) & CHR(10))
'Fill the column headings
For Each colHeading in theTable.GetHeaders
Response.Write("<TH><B><PRE>" & colHeading & "</PRE></B></TH>")
Next
'Scan all the objects in the table
while not theTable.IsEOT
'Get the tabular representation of each object
For Each aRow in theTable.GetTabularRepresentation
'Each row in the representation is a row in the HTML table
Response.Write("<TR>")
'Scan all the cells in the row
For Each aCell in aRow
Response.Write("<TD>" & aCell & "</TD>")
Next
Response.Write("</TR>" & CHR(13) & CHR(10))
Next
'Jump to the next object in the table
theTable.MoveNext
wend
Response.Write("</TABLE>" & CHR(13) & CHR(10))
End Sub
</SCRIPT>
In JavaScript
You can also access an ATK ActiveX object through ASP using JavaScript. Refer to the odi\ATK6.0\Examples\Tutorial3\tut2_2.asp for an example of JavaScript code using the same data view.5 Test the application.
Use Inspector Instance Formats
Overview
Instead of defining new data views every time you want to display different data, you can use different instance formats for the same data view. Instance formats describe the columns of data to display, the column order, and the column heading text. Process
To display data using a new instance format, follow these steps:
2 Save the modified metaknowledge.
Select File | Save All to save the database. The metaknowledge for the database now associates the data view my_tut2_table1 with the my_tutorial2_2 grid template by default, which includes the new instance format.3 Modify the ASP code to refresh the metaknowledge.
Modify tut2_1.asp so it forces ATK to reload the metaknowledge for all of the databases it has opened. In the first lines of the ASP code, call ATKKernel::ReloadMetaKnowledge.
<%
On Error Resume Next
'Create the ATKKernel object
Set theKernel=Server.CreateObject("ATKKernel.Document")
'Force ATKKernel to reload its metaknowledge cache
theKernel.ReloadMetaknowledge
'Try opening the database
Set theDatabase=theKernel.OpenDatabase("c:\odi\ATK6.0\Examples\demodbs\carsdemo.db")
%>
4 Check the modified ASP code.
In a web browser, open the URL http://localhost/aspsamp/atk/tutorial2/tut2_1.asp to display the result, which uses the instance format saved in the my_tutorial2_2 grid template. Your browser window should display information similar to the following:
5 Change the ASP code to select the instance format.
You can modify the application to choose the instance format from among those you have saved with any grid template in the database. GetATKTable accepts an optional argument in which you can specify the name of the instance format you want to retrieve. Refer to ATKDataView::GetATKTable in the ObjectStore Active Toolkit Reference for details.
Set theTable = theDataView.GetATKTable("Part::my_tutorial2_1")
WriteTable(theTable)
This call forces ATK to format the selected data view using the Part::my_tutorial2_1 instance format saved with the my_tutorial2_1 grid format. (You can specify any valid Part instance format that you have saved with an Inspector grid template.)
Display Multimedia Object Managers
Overview
Although you can access multimedia data through the ObjectStore Active Toolkit OLE DB provider, you must do so through a standard OLE DB or ADO (Active Data Objects) interface. However, an ASP script that queries the ATK ActiveX server can directly access the multimedia Object Manager instances, retrieve the data, and display it in a web browser. Process
To display multimedia object managers, follow these steps:
2 Write the ASP code to display multimedia Object Managers.
The structure of an HTML page requires two Active Server Pages:
Using Microsoft Visual InterDev or any text editor:<%
On Error Resume Next
Set theKernel=Server.CreateObject("ATKKernel.Document")
'Open the extrademo.db database
Set theDatabase=theKernel.OpenDatabase("c:\odi\ATK6.0\Examples\demodbs\extrademo.db")
If Err.Number = 0 Then 'If no errors occurred...
'Retrieve the "exhibit_root" root
Set theRoot=theDatabase.GetRoot("IMAGES")
'Get the ATKReference of the object associated with the root
Set rootValue=theRoot.GetATKReference
'Get the ATKReferences representing the collection associated with the root
Set rootValues=rootValue.GetCollectionItems
'Initialize the HTML table
Response.Write("<TABLE BORDER=1>")
Response.Write("<TH><B>Images</B></TH>")
'Loop on all the Object Managers in the collection
For Each anOM in rootValues
Response.Write("<TR><TD>")
'Build an URL pointing to tut2_om2.asp, containing the code that dumps an OM
Response.Write("<IMG SRC=""tut2_om2.asp?dumpedReference=" & _
Server.URLEncode(anOM.GetReference) & """>")
Response.Write("</TD></TR>")
Next
Response.Write("</TABLE>" & CHR(13) & CHR(10))
Else
Response.Write("Error opening database: " & Err.Description & "<BR>")
End If
%>
<%@ LANGUAGE="VBSCRIPT" %>
<%
On Error Resume Next
Set theKernel=Server.CreateObject("ATKKernel.Document")
'Resolve the reference passed in the "dumpedReference" HTML variable
Set theObject=theKernel.ResolveReference( _
Request.QueryString("dumpedReference"))
If theObject.IsObjectManager Then 'If the object is an Object Manager...
'Get the ATKObjectManager object
Set theOM=theObject.GetATKObjectManager
'Store its mime type in the Response.ContentType field
Response.ContentType=theOM.GetOMMimeType
'Write the OM bits
Response.BinaryWrite(theOM.GetDataArray)
End If
%>
Display Tables of Tables
Overview
Typically, when you extract HTML tables from a database, you want to display the data at many levels of abstraction, and allow the user to navigate to additional data. The application you create in this section demonstrates how you can use ATK ActiveX server to create a table that displays all work orders in a database and, upon the user's request, detail all the service items for a particular work order. Process
To display tables of tables, follow these steps:
2 Check the data view format.
3 Build the ASP code to display a table of tables.
In the example Display Multimedia Object Managers, the Active Server Page simply displays a collection of images in a web browser. However, this example contains additional functionality that allows the user to click on an item in the first column of the table and navigate that item's relationship to more detailed data.
tut2_1.asp, change the WriteTable procedure so it contains this code:
For Each aRow in theTable.GetTabularRepresentation
Response.Write("<TR>")
isFirstColumn=true 'used to modify the first column
For Each aCell in aRow
If isFirstColumn Then 'is this the first column?
'if it is the first column, navigate the "items" relation
Set theRelatedItems=theTable.GetObject.GetSlotValue("items")
'then use the returned ATKReference to build the URL of the link;
'we send the dumped reference to the tut2_nav2 page
Response.Write("<TD><A HREF=""tut2_nav2.asp?dumpedReference=" _
& Server.URLEncode(theRelatedItems.GetReference) & """>" _
& aCell & "</A></TD>")
Else 'this isn't the first column
Response.Write("<TD>" & aCell & "</TD>")
End If
isFirstColumn=false 'no more the first column
Next
Response.Write("</TR>" & CHR(13) & CHR(10))
Next
<%
On Error Resume Next
Set theKernel=Server.CreateObject("ATKKernel.Document")
'Resolve the reference passed in the "dumpedReference" HTML variable
Set theObject=theKernel.ResolveReference( _
Request.QueryString("dumpedReference"))
'If the object is a collection
If theObject.IsCollection Then
'write the table gotten through an ATKReferences object
WriteTable(theObject.GetCollectionItems.GetATKTable("ServiceItem"))
End If
%>
The WriteTable procedure is the same one used in tut2_1.asp. Note that the GetATKTable call specifies the name of the class whose instances are contained in the ObjectStore collection that is being displayed. Thus, ATK formats the ATKTable object using the default ServiceItem instance format.
4 Test the application.
Summary
In this chapter, you built simple Active Server Page applications using data retrieved by the ATK ActiveX server. By using more of the classes and methods in the ATK object model, you can build much more sophisticated applications.
Updated: 05/11/99 11:58:34