| By Andrew Cripps | Article Rating: |
|
| February 5, 2002 12:00 AM EST | Reads: |
8,211 |
Microsoft invented a technology called Smart Tags. Smart Tags allow text to be marked up with actions, such as hyperlinks, when the text is displayed.
They planned to introduce the technology with Windows XP. However, since public opinion was strongly against it, Microsoft decided to de-emphasize it. You can still create and use Smart Tags, but they're not prominent in Windows XP.
This article provides an overview of the technology and then shows how you can use ColdFusion to implement a simple version of Smart Tags. You can download the custom tag, cf_smarttag, from the CFDJ Web site (www.sys-con.com/coldfusion/sourcec.cfm).
Overview of Microsoft Smart Tags
A typical Web page has text that includes hyperlinks to other Web sites or resources on the World Wide Web. The author usually creates the hyperlinks when the document is written, and those hyperlinks are part of the authored Web page. However, Microsoft thought it would be interesting to take the hyperlink concept one step further: the author of the document creates some text, then someone (possibly the author, but perhaps not) can create a set of keywords that are associated with shortcuts in Windows that could provide a hyperlink to another Web site, open another application, or perform some custom action.
For example, if an author writes "The most interesting news last month was...," Smart Tags technology allows you to associate the word "news" with a hyperlink to msn.com, or some other Web site. When a user goes to a site that's Smart - Tags enabled and opens a Web page, the user sees squiggly purple lines under the keywords (like the lines in Microsoft Office documents if you've made a spelling mistake). When the user hovers over a keyword with a squiggly underline, a Smart Tags icon appears with a dropdown selection defined for the particular Smart Tag associated with the keyword. Most typically, the action is to hyperlink to one or more (Microsoft) Web sites. Note that the author of the document may not have intended this hyperlink when writing the document; the hyperlinks and other actions are added when the page is displayed, depending on the definitions of the Smart Tags on the computer the page has been requested from.
To use Smart Tags, define the Smart Tag and what it does, then create a list that relates the Smart Tag to a keyword. When a page is rendered that contains those keywords, the user can click on an item in the Smart Tag dropdown menu to take one of the actions defined by the Smart Tag.
For more information, visit www.microsoft.com/officedev/xp_06_2001/odc_stwebpages.htm.
Why Smart Tags Stalled
Smart Tags received a rough reception from the public. Although many people thought the technology was interesting, they believed Microsoft would use it to increase traffic to their own Web sites and servers. For example, keywords such as "news," "sports," and "servers," would all link to Microsoft's Web servers.
Many critics thought Smart Tags would primarily allow Microsoft to re-edit a Web site without the author's knowledge or permission.
There are, in fact, some legitimate uses for Smart Tags technology. Imagine a large company with offices worldwide, and each office has a local intranet. With Smart Tags technology, whenever the word "intranet" appears in documents posted on any of the company Web sites, Smart Tags technology would allow each office to associate a hyperlink with that keyword so that it pointed to their local intranet. This is clearly an improvement for each office. The head office sends documents that can be hosted on several corporate intranet sites, and the hyperlinks are now separately maintained and consistent across all documents. Wherever the word "intranet" occurs, the same hyperlink would be in place.
A Simple Smart Tags Implementation
After that summary of Microsoft Smart Tags technology, I will now show you how to build a simple version using ColdFusion. In my implementation we will define keywords and just one action: a hyperlink. When a page is displayed that contains one of the defined keywords, a hyperlink is added to the keyword. In this section I describe the basic implementation; later I'll provide some ideas about how you might extend it.
The solution breaks down into the following parts:
- Wrapping text: paired custom tags
- Storing keywords and their associated hyperlinks
- Generating content
- Exiting gracefully
<cfsmarttags>The Smart Tag custom tag could be written at the start and end of each page, or perhaps into header and footer files that are included on each CFML template on a site.
text to change goes here.
This could be a ColdFusion #variable#
</cfsmarttags>
The second part of the solution is to design a way to store the keywords and their associated Smart Tag action - a hyperlink. One convenient way to store this association is in an XML file. The format I chose is shown in Listing 1.
The XML document has a single root element, "<smarttags>" in this case, and that element has any number of "<smarttag>" elements that relate keywords (the field elements) to Smart Tag actions (the URL element). I'll show ways to extend this XML definition later in the article.
The Smart Tag custom tag uses a default XML file, smarttags.xml, but you can also pass in the location of the XML file through the "smarttagsfile" attribute. For example, you could call the Smart Tag custom tag like this:
<cfsmarttags smarttagsfile=and the sport_smarttags.xml file containing the keyword/hyperlink pairs would be used to mark up the text. (You could even use the smarttagsfile attribute in combination with a ColdFusion variable - perhaps the location of the smarttagsfile to use in a particular section of a large Web site is retrieved from a database.)
"c:/inetpub/wwwroot/news/sport_smarttags.xml">
text to change goes here.
This could be a ColdFusion #variable#
</cfsmarttags>
The third part of the solution is generating the modified content. The Smart Tag tag has to be a paired tag - with a begin tag and a matching end tag, just like <cfquery> or <cfhttp> - since it will be used to wrap text that will be changed by the Smart Tags. The custom tag has to:
Macromedia has built into CFML the ability to create paired custom tags and to manipulate whatever it generates (most often HTML) for display in the browser. In CFML you can make some final changes to the output before the Cold-Fusion server sends it off to the browser to be displayed. You can access the content the ColdFusion server sends to the browser through the variable "thistag.- generatedcontent".
Once a copy of the thistag.generatedcontent variable has been taken:
<cfset mytext = thistag.generatedcontent>the tag looks for keywords defined in the XML Smart Tags file, and replaces each keyword it finds with the associated URL. Lines 60-69 of smarttag.cfm use the midstring function that's user-defined and declared in the file functionlibrary.cfm. (A valuable resource for user-defined functions that you can download and use can be found at www.cflib.org.)
You may think that it would be easier to define the midstring function in the Smart Tag custom tag. Unfortunately, this won't work because a paired custom tag executes twice: once in start mode and once in end mode. To ColdFusion it appears as though the user-defined function midstring has been declared twice, and you get this error:
The routine midstring has been declared twice in different templates.
To avoid this problem, use cfinclude to include a CFML template that contains your user-defined function definition. In the smarttags.cfm custom tag, nothing is required in start mode (lines 43-44); however, if you wanted to do something the first time the tag runs, this is where your code would go. All the processing occurs when the closing "</cfsmarttag>" is encountered on the CFML template. The custom tag is executed in end mode, and lines 45-71 copy the generated content, make changes, and write out the modified content.
The last thing to note in this solution is the use of <CFEXIT method="ExitTag">. The CFEXIT tag allows a custom tag to pass control back to the caller of the custom tag. It's used in the Smart Tag custom tag if any errors are caught while trying to read the XML settings file. If the XML settings file is not readable, the tag will exit cleanly without making any changes to the generated content.
Ideas for Extensions
The ColdFusion implementation is very simple right now. All it does is gain access to the generated content and, before that content is sent back to the browser, it makes some substitutions in the generated content variable.
Microsoft's implementation is much more complex. They've allowed for the fact that you might want to use several sets of Smart Tag definitions that might contain the same keyword. They use namespaces to avoid confusion about what to do when that keyword is encountered. Microsoft's implementation also shows a squiggly line under each keyword when the page is displayed in Internet Explorer: no action is taken automatically - you have the option to take an action such as hyperlinking to another location when you hover over the keyword. How might you extend and improve on this CFML implementation?
You could extend the XML file with additional actions. In my simple example the action is a hyperlink to the provided URL. But you could create an XML definition that associates keywords with CFML templates that are executed when one of the keywords is encountered. Another example might be to create an XML definition that associates keywords with CFML templates that take actions such as sending e-mail when one of the keywords is encountered.
You could extend the Smart Tag to work through a set of definition files instead of one. Rather than have the XML definition file stored locally on the ColdFusion server that returns the page for display, the definitions could live anywhere on the Web. You could use an attribute similar to the smarttagsfile attribute to find the location of the settings file on the Web and perhaps retrieve the file using CFHTTP (although this may raise performance issues).
You could also extend the XML definition to replace keywords, not with a hyperlink but with almost any HTML or dynamic HTML you like. You might use this to create a simple menu scheme, replacing some keywords specifically chosen to identify menu choices, and then allowing the Smart Tag custom tag to substitute your keywords with HTML or JavaScript. You could almost create an XML definitions file that would act as a set of macros for a Web site, consistently changing text and HTML. To make this work, you would also need to extend the basic midstring user-defined function.
To create something similar in appearance to Microsoft Smart Tags, you need to embed objects using the HTML element <object classid="">. You'd want to access the same object that Microsoft uses in Smart Tags so that when you hover over a link, you get the icon and the options dropdown box appears.
The Code
The files included in the ColdFusion implementation on the CFDJ Web site are:
Published February 5, 2002 Reads 8,211
Copyright © 2002 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Andrew Cripps
Andrew Cripps has over thirteen years of experience in the computing
industry. His computing career has taken him from delivering large
enterprise systems in Europe and in Canada to his current position as a development manager at Macromedia in Boston where he works on ColdFusion
and Flash technologies. He holds a Masters degree in Computing Science and a Masters degree in Philosophy from Canadian universities.
![]() |
Chinta Srinivas 02/20/02 05:06:00 AM EST | |||
thanks |
||||
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Adobe Cans Another 9% of its Workforce
- Moyea DVD4Web Converter V2.0 Converts DVD to FLV Fast and Synchronously with Watermarks
- Adobe & Salesforce Cut Cloud Deal
- Adobe Fiddles with its Web Apps
- Hosting.com Launches ColdFusion 9 in the Cloud
- The Real Time Infrastructure Ultimatum
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- The Planet Named “Bronze Sponsor” of Cloud Computing Expo
- Microsoft Expression Web Has Got Game
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Bruce Chizen Joins Voyager Capital as Venture Partner
- My Top Seven Wishes From Adobe MAX 2009
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- Constructing an Application with Flash Forms from the Ground Up
- AJAX World RIA Conference & Expo Kicks Off in New York City
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Personal Branding Checklist
- Adobe Flex 2: Advanced DataGrid
- Has the Technology Bounceback Begun?
- Building a Zip Code Proximity Search with ColdFusion
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- The Asynchronous CFML Gateway
- Web Services Using ColdFusion and Apache CXF
























