|
Using Logical Names |
|
|
One last concept remains and it is something unique to the Web Toolkit - logical names.
As you will see, logical names provide an easy and flexible way to make global changes
to your site in a non-destructive manner.
|
||||
|
In this lesson, we will use logical names to demonstrate the maintenance capabilities
of the Web Toolkit.
|
||||
|
The Toyz Inc. brass have decided to change their logo. Naturally, they want the new
logo on all web pages for the TEACH system. Of course, since top-level management
personnel are not very technical (nor do they care for techno babble), they don't
care how hard or easy it is make this change, they just want it done.
If you recall, the HTML code that displays the logo is found in an include file. Given the nature of include files, you would initially say that this "change the logo" modification would be easy - all you have to do is edit one file. While this is true, you still have to identify "how" you are going to make the change. Below is the line of HTML that displays the logo:
<img src=images/toyzinc.gif>
You now have two choices for the change.
For the first method, the advantage is that nothing is lost - you still would have access to the old logo in case there was a problem with the new logo and you had to revert back to the old one. The disadvantage is that you would have to edit this file each time they wanted to change the logo. For the second method, the advantage is that you did not have to edit the include file - all you had to do was replace (overwrite) the old logo with the new logo. The disadvantage was that the old logo is now gone (and gone forever if there wasn't a backup copy somewhere on your network). These issues may seem trite but for the sake of example, let's raise the scope of this situation to something a bit more "real world". It's not just one logo (one graphic) file the big brass wants to change - it's every single graphic on the entire site. At this point you would have to say that the second method looks the best because once you take a good backup of the "old" graphic files, you could then replace them all with the new ones. This solution has a huge solution over the first method because it would save you from having to edit a (potentially) large number of files (not just 1 include file) that make references to graphics. The Web Toolkit can solve this with the use of logical names. The concept is quite simple. Use a logical name (or alias) for the directory where you graphics are kept. For example, in addition to an images directory, create a directory called newlook and copy all graphic files from the images directory to the newlook directory. Make your modifications to the graphics in the newlook directory and use a logical name to point to one directory or the other. The line of HTML code for this would look something like this:
<img src=where_the_images_are/toyzinc.gif>
Then create an entry in the site-specific INI file as below:
[logical-names]
# where_the_images_are = images where_the_images_are = newlook The pound or hash symbol (#) in the INI file is the "comment out" character. Note here we are commenting out the line that would point to the previous images directory and using the logical name of where_the_images_are to point to the newlook directory. Should we wish to revert back to the previous images directory, we would use the logical name of where_the_images_are to point to the images directory and comment out the line that pointed to the newlook directory. Using this methodolgy, you can see that once we start using logical names, making a switch like this means that you would never have to edit tens, hundreds or potentially thousands of SSP files in our web application in order to accomodate site-wide changes. This would apply not just for graphics but for anything in your web application. To witness how this works, proceed with the following steps. |
||||
|
1.
If VisualWorks is not already running, please start running it now. File in the latest
Smalltalk code from your last lesson, whether it was from the ASP model or J2EE model
lessons.
2. Create another directory called artwork under the teach directory (in other words, at the same level where you have already a directory called images that contains the toyzinc.gif file). 3. Copy the file toyzinc2.gif to the artwork directory and rename it to toyzinc.gif. You should then have a file structure like the one pictured below: Figure 3. The new toyzinc.gif file in the artwork directory 4. Using your favorite text editor, edit the teach-site.ini file in the web directory and add the following in the [logical-names] section:
[logical-names]
# where_the_images_are = images where_the_images_are = artwork There is no need to specify the complete path to this folder. The Web Toolkit already knows what the root directory is for this site so all you have to specify is the directory name. 5. Edit the include file that contains the line to display the Toyz Inc logo. Change the line to:
<img src=where_the_images_are/toyzinc.gif>
6. If you have already loaded the Web Toolkit parcel and have already started a TinyHTTPServer, (before you edited the INI file), then perform the following steps:
|
||||
|
Congratulations!
It is now easy to perform maintenance to a configuration file without having to make changes to individual files, thereby providing an easy and flexible way to make global changes to your site in a non-destructive manner. You should now be able to:
|
||||
|
This concludes the introductory tutorial on the Web Toolkit. We hoped you enjoyed this
tutorial and learned a little something about how to create web applications using the
Web Toolkit in the process. If you would like to see another Web Toolkit application,
it is recommended that you look closely at the ToyzInc Demo application that accompanies
this release of VisualWorks. You will find a link to the ToyzInc Demo application on the
Web Toolkit main configuration page.
As always, we welcome your comments and would like to know if this tutorial was of benefit to you. We also would like to know what other topics you think would make good tutorials. This will help us plan and give us a good sense of producing material that you, the customer, want. Please send you comments to: Jim Fuldner Instructional Design Engineer Cincom Systems, Inc. 1-800-888-0115 (ext. 2067) jfuldner@cincom.com |