Figure 3 Initialization Public Sub Class_Initialize()
If Not (LoadProductNumbersDataFromXML()) Then
Stop
End If
End Sub
Public Function LoadProductNumbersDataFromXML()
Dim xmlDoc As New MSXML2.DOMDocument40
Dim objNodeList As IXMLDOMNodeList
On Error GoTo errXMLLoadError
xmlDoc.async = False
xmlDoc.Load ("http://localhost/productlist.xml")
On Error GoTo 0
Set objNodeList = xmlDoc.getElementsByTagName("PartNumber")
For i = 0 To (objNodeList.length - 1)
ReDim Preserve strPartNumbers(i + 1)
strPartNumbers(i + 1) = objNodeList.Item(i).Text
Next
numParts = i - 1
LoadProductNumbersDataFromXML = True
Exit Function
errXMLLoadError:
'Stop processing if the list of terms cannot be created
MsgBox "Problem loading XML"
LoadProductNumbersDataFromXML = False
Exit Function
End Function
Figure 4 Recognizer Class Public Sub ISmartTagRecognizer_Recognize(ByVal Text As String, _
ByVal DataType As SmartTagLib.IF_TYPE, ByVal LocaleID As Long, _
ByVal RecognizerSite As SmartTagLib.ISmartTagRecognizerSite)
Dim propbag As SmartTagLib.ISmartTagProperties
Dim termIndex
For i = 1 To numParts
termIndex = InStr(Text, strPartNumbers(i))
If termIndex > 0 Then
termLength = Len(strPartNumbers(i))
Set propbag = RecognizerSite.GetNewPropertyBag
RecognizerSite.CommitSmartTag _
"schemas/msdn-mag#productnumber", termIndex, _
termLength, propbag
End If
Next
End Sub
Figure 5 Action Provider Properties Private Property Get ISmartTagAction_ProgId() As String
ISmartTagAction_ProgId = "ProgIDTest.SmartTagAction"
End Property
Private Property Get ISmartTagAction_Name(ByVal LocaleID As Long) _
As String
ISmartTagAction_Name = "Order Validation Options"
End Property
Private Property Get ISmartTagAction_Desc(ByVal LocaleID As Long) _
As String
ISmartTagAction_Desc = "Provides actions order validation"
End Property
Private Property Get ISmartTagAction_SmartTagCount() As Long
ISmartTagAction_SmartTagCount = SMART_TAG_TYPE_COUNT
End Property
Private Property Get ISmartTagAction_SmartTagName(ByVal SmartTagID _
As Long) As String
If (SmartTagID = 1) Then
ISmartTagAction_SmartTagName = "schemas/msdn-mag#productnumber"
End If
End Property
Figure 6 VerbCaptionFromID Property Private Property Get ISmartTagAction_VerbCaptionFromID(ByVal VerbID _
As Long, ByVal ApplicationName As String, ByVal LocaleID As Long) _
As String
'Populate the Smart Tag action menu
'Use the VerbID
If (VerbID = 1) Then
ISmartTagAction_VerbCaptionFromID = "Get product name"
End If
If (VerbID = 2) Then
ISmartTagAction_VerbCaptionFromID = "Get product price"
End If
If (VerbID = 3) Then
ISmartTagAction_VerbCaptionFromID = "Get product availability"
End If
End Property
Figure 7 InvokeVerb Public Sub ISmartTagAction_InvokeVerb(ByVal VerbID As Long, _
ByVal ApplicationName As String, ByVal Target As Object, _
ByVal Properties As SmartTagLib.ISmartTagProperties, ByVal Text _
As String, ByVal XML As String)
Dim ie, theURL
Set ie = CreateObject("InternetExplorer.Application")
Select Case VerbID
Case 1
theURL = URLStub & _
"?operation=GetProductName&ProductNumber=" & Text
Case 2
theURL = URLStub & _
"?operation=GetProductPrice&ProductNumber=" & Text
Case 3
theURL = URLStub & _
"?operation=GetProductAvail&ProductNumber=" & Text
End Select
ie.Navigate2 (theURL)
ie.Visible = True
End Sub
|