The Content Linking Component

The Content Linking component lets you organize the pages of your Web site like the pages of a book. It constructs a table of contents and maintains previous and next page links in your Web pages. This allows you to change the order of pages, insert pages, or delete pages without having to do much maintenance work on the pages themselves. Content linking has two parts: a Content Linking List and a NextLink object.

The Content Linking List

The Content Linking component needs to know which pages are to be included in the table of contents. This information is maintained in the Content Linking List, which is a text file. Each URL is listed on one line in the file—along with a description and a comment—in the order that it will appear in a table of contents. This syntax, shown below, is described in Table 17-10.

 URL [Description] [Comment] 

A tab character separates the URL from the description and the comment. The description and comment are optional. The comment is for your use only; the component does not use it.

Table 17-10. The format of the Content Linking List file.

Item Description
URL The URL for the page. It must be a virtual or relative URL. The Content Linking component will not use an absolute URL (one that begins with http).
Description A textual description of the URL.
Comment A textual comment, which the component will not process.P

The NextLink Object

The NextLink object is implemented in the NextLink.dll file. It contains several methods for managing a list of URLs. For IIS, the file is located by default in the C:\WINNT\system32\inetsrv folder.

The syntax to instantiate the NextLink object is as follows, where objNextLink refers to the new NextLink object.

 <OBJECT RUNAT=server PROGID=MSWC.NextLink id=objNextLink> </OBJECT> 

The methods within the NextLink object all require the Content Linking List file as a parameter, as shown in Table 17-11. The NextLink object has no properties.

Table 17-11. Methods in the NextLink object.

Method Description
GetNextURL(ContentLinkFile)
GetPreviousURL(ContentLinkFile)
GetNextDescription(ContentLinkFile)
GetPreviousDescription(ContentLinkFile)
Returns a string that is the next or previous URL or description. These calls are valid only from a page that is in the Content Linking List file.
GetListCount(ContentLinkFile) Returns the number of pages in the Content Linking List file.
GetListIndex(ContentLinkFile) Returns the index number of the current URL in the Content Linking List file.
GetNthDescription (ContentLinkFile, index)GetNthURL (ContentLinkFile, index) Returns the page's URL or description, as specified by the index in the Content Linking List file.

A Sample Table of Contents

The Content Linking List file is fairly easy to use because it has only one purpose—to provide the list of URLs and their descriptions. You must create a Content Linking List file and some Active Server Script code to build the table of contents and the links to other pages. The following example is a table of contents for an online book and is included on the CD-ROM in the Components Web project. The code below shows the Content Linking List file, toc.txt:

 ch1.asp     Chapter 1 - Introduction ch2.asp     Chapter 2 - Active Server Pages ch3.asp     Chapter 3 - Database Access ch4.asp     Chapter 4 - N-Tier Architectures 

In this file, tabs are used to separate the URL from the descriptions.

To keep your table of contents easy to maintain, you can store all your files in the same virtual directory on your Web server. This includes the Content Linking List file (toc.txt), the Table of Contents page (ContentLinking.asp), and the pages of the book (ch1.asp etc.).

One of the Content Linking component's most useful features is its ability to automatically create the table of contents. The Active Server script used in the ContentLinking.asp page, shown below, is generic enough for you to use in any of your tables of contents.

 <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> <TITLE>Content Linking Sample</TITLE> </HEAD> <BODY> <H2>Content Linking Sample</H2> <HR> <OBJECT RUNAT=server PROGID=MSWC.NextLink id=objNextLink> </OBJECT> <B>Table of Contents</B> <%   count = NextLink.GetListCount("toc.txt") Response.Write "<UL><ul> For i = 1 to count     Response.Write "<LI><A HREF=" + _         objNextLink.GetNthURL("toc.txt", i) + _         ">" + objNextLink.GetNthDescription("toc.txt", i) + "</A>" Next %>   </UL> </BODY> </HTML> 

Figure 17-12 shows the output from this script. This script uses GetListCount to find the number of pages. It then uses GetNthURL and GetNthDescription in a For…Next loop to build a bulleted list of the table of contents.

click to view at full size.

Figure 17-12. The table of contents is generated automatically from the contents in the text file that defines the pages.

Each page in the book needs links to the previous and next pages. Using the Content Linking component, you can include the same standard boilerplate code in each page. In this way, you don't have to make any changes if you rearrange the order or the number of pages.

You include parts of the following script at the end of each page of the report. You can, of course, place the relevant sections of this file in an Include file and use the server-side include to pull this file into each page. This makes code maintenance much easier.

 <%@ Language=VBScript %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <BODY> <H2>Content Linking Sample - Chapter 2</H2> <HR> <OBJECT RUNAT=server PROGID=MSWC.NextLink id=objNextLink> </OBJECT> <B>Chapter 2</B> <P> <% last = objNextLink.GetListCount("toc.txt") current = objNextLink.GetListIndex("toc.txt") If current > 1 Then     Response.Write "<A HREF=" + _         objNextLink.GetPreviousURL("toc.txt") + _         ">Previous Page</A>" End If %> &nbsp; <% If current < last Then     Response.Write "<A HREF=" + _         objNextLink.GetNextURL("toc.txt") + _         ">Next Page</A>" End If %> <P> <A HREF="ContentLinking.asp">Table of Contents</A> </BODY> </HTML> 

This code automatically generates the links in the bottom part of the page, as shown in Figure 17-13 below. The Next Page and Previous Page links move users forward and backward in the pages listed in the Content Linking List file.

Since you will use this same code for each page in your situation report, you need to check which page you're on and include next and previous links only when necessary. The script's first job is to create a NextLink object and get the number of pages and the current page.

click to view at full size.

Figure 17-13. An ASP Web page showing the Previous Page and Next Page hyperlinks created using the Content Linking component.

Two If…Then statements make comparisons on the current page. The first statement determines whether the current page is greater than one; if it is, you need to include a link back to the previous page. The second checks whether the current page is the last page; if it is not, you need a next-page link.

Each page of your online book will have the correct links, both backward and forward. All you have to do is edit the toc.txt file to change the order of the pages.



Programming Microsoft Visual InterDev 6. 0
Programming Microsoft Visual InterDev 6.0
ISBN: 1572318147
EAN: 2147483647
Year: 2005
Pages: 143

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net