Dim stack As New Stack()
Call stack.push("Domino")
Call stack.push("Notes")
Call stack.push("R7")
Print "Stack is: " & stack.toString()
Print "First: " & stack.pop()
Print "Second: " & stack.pop()
Print "Third: " & stack.pop()
' This will produce the output:
' R7
' Notes
' Domino
Thanks to Vitezsla Vit VLCEK and Chad ”Smiley” Schelfhout for pointing out bugs in the original class.
When executed on a Domino server, the result was a bit different, since the server is a bit old:
Public Sub serializeNode(node As NotesDOMNode_
, outStream As NotesStream)
On Error Goto catch
If node.IsNull Then Exit Sub
Dim currentNode As NotesDOMNode
Set currentNode = node
Do Until currentNode.isNull
Select Case currentNode.nodeType
Case DOMNODETYPE_DOCUMENT_NODE
Case DOMNODETYPE_XMLDECL_NODE
Dim xmlDecl As NotesDOMXMLDeclNode
Set xmlDecl = currentNode
Call outStream.WriteText("< ?xml version=""" _
+ xmlDecl.version + """ encoding=""" + xmldecl.encoding + """?>")
Case DOMNODETYPE_ELEMENT_NODE
Call outStream.writeText("< " + currentNode.nodeName + "")
Dim nodeMap As NotesDOMNamedNodeMap
Set nodeMap = currentNode.attributes
Dim attribute As NotesDOMNode
Dim i As Integer
For i = 1 To nodeMap.numberOfEntries
Set attribute = nodeMap.getItem(i)
Call outStream.WriteText(" " + attribute.nodeName + "=")
Call outStream.WriteText("""" + attribute.NodeValue + """")
Next i
Call outStream.writeText(">")
Case DOMNODETYPE_TEXT_NODE
Call outStream.writeText(currentNode.NodeValue)
Case DOMNODETYPE_COMMENT_NODE
Call outStream.writeText("")
Case Else
Error 2000, "Unhandled node type [" _
& currentNode.nodeType & "]"
End Select
Dim endWritten As Boolean
If currentNode.hasChildNodes Then
Call serializenode(currentNode.firstChild, outStream)
End If
If currentNode.NodeType = DOMNODETYPE_ELEMENT_NODE Then
Call outStream.writeText("")
endWritten = True
End If
Set currentNode = currentNode.nextSibling
Loop
If node.NodeType = DOMNODETYPE_ELEMENT_NODE _
And Not endWritten Then
Call outStream.writeText("")
End If
Exit Sub
catch:
Error Err, Err & Lsi_Info(2) & ":" & Erl & "|" & Error
End Sub
To further illustrate what I want, here is an example:
Public Sub testDOMParser()
Dim parser As NotesDOMParser
Dim inStream As NotesStream
Dim node As NotesDOMDocumentNode
Set inStream = session.createStream()
Call inStream.open("c:temptest.xml")
Set parser = session.createDOMParser(inStream)
Call parser.process()
Set node = parser.document
Call serializeDocument(node)
End Sub
Public Sub serializeDocument(node As NotesDOMDocumentNode)
' Here, I want to do something like this:
Dim outStream As NotesStream
Dim parser As NotesDOMParser
Set outStream = session.createStream()
Set parser = session.createDOMParser(node, outStream)
parser.exitOnFirstFatalError = True
Call parser.serialize()
Print "Serialized tree: " + outStream.readText()
End Sub
Anyone who have had any experience with this and are willing to share their thoughts? We are talking R6 here…
]]>
Dim xml As String
Dim rootElementNode As NotesDOMElementNode
xml = "YOUR XML HERE"
Set rootElementNode = parseXML(xml)._
getElementsByTagName("THE ROOTNODE").getItem(1)
Public Function parseXML(xml As String) _
As NotesDOMDocumentNode
' Parses the specified xml.
On Error Goto catch
Dim session As New NotesSession()
Dim stream As NotesStream
Set stream = session.createStream()
Call stream.writeText(xml)
Dim domparser As NotesDOMParser
Set domparser = session.createDOMParser(stream)
domParser.exitOnFirstFatalError = True
Call domParser.parse()
Set parseXML = domparser.Document
Exit Function
catch:
Error Err, _
Err & "|" & Error & "|" & Lsi_info(2) & ":" & Erl
End Function
]]>
Dim session as New NotesSession()
session.convertMIME = False ' Do not convert to rich text
Dim currentDb As NotesDatabase
Set currentDb = session.currentDatabase
Dim path As String
path = "c:temptest.html"
Dim message As NotesDocument
Set message = currentDb.createDocument()
Call message.replaceItemValue("Form", "memo")
Call message.replaceItemValue("From", "[email protected]")
Call message.replaceItemValue("Subject", _
"HTML email via MIME")
Call message.replaceItemValue("SendTo", "[email protected]")
Dim body As NotesMIMEEntity
Set body = message.CreateMIMEEntity
Dim mh As NotesMimeHeader
Set mh = body.CreateHeader({MIME-Version})
Call mh.SetHeaderVal("1.0")
Set mh = body.CreateHeader("Content-Type")
Call mh.SetHeaderValAndParams( _
{multipart/related;boundary="=NextPart_="})
Dim mc As NotesMIMEEntity
Set mc = body.createChildEntity()
Dim stream As NotesStream
Set stream = session.createStream()
If Not stream.open(path, "ISO-8859-1") Then
Error 2000, "Could not open file"
End If
Call mc.setContentFromText(stream, _
{text/html;charset="iso-8859-1"}, ENC_NONE)
Call stream.close()
Call addImage(body, "C:tempimage1.gif")
Call addImage(body, "C:tempimage2.gif")
Call message.send(False)
Public Sub addImage(body As NotesMimeEntity, _
imagePath As String)
Dim id As String
Dim stream As NotesStream
Dim mh As NotesMimeHeader
Dim mc As NotesMIMEEntity
id = Strrightback(imagePath, "")
Set stream = session.createStream()
Set mc = body.createChildEntity()
Set mh = mc.createHeader({Content-ID})
Call mh.setHeaderVal(id)
Call stream.open(imagePath)
Call mc.setContentFromBytes(stream, _
"image/gif;name=""" + id + """", ENC_IDENTITY_BINARY)
Call stream.close
End Sub
The HTML code must refer to the images via URL:s containing cid and the ”path” to the image, like this:
<img src="cid:imagename.gif" />
Found this great tip via LDD, posted by Raymond Neeves.
]]>
Dim http As Variant
Set http = CreateObject("WinHTTP.WinHTTPRequest.5.1")
http.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = 13056
' WinHTTPRequest options:
Const WinHttpRequestOption_UserAgentString = 0
Const WinHttpRequestOption_URL = 1
Const WinHttpRequestOption_URLCodePage = 2
Const WinHttpRequestOption_EscapePercentInURL = 3
Const WinHttpRequestOption_SslErrorIgnoreFlags = 4
Const WinHttpRequestOption_SelectCertificate = 5
Const WinHttpRequestOption_EnableRedirects = 6
Const WinHttpRequestOption_UrlEscapeDisable = 7
Const WinHttpRequestOption_UrlEscapeDisableQuery = 8
Const WinHttpRequestOption_SecureProtocols = 9
Const WinHttpRequestOption_EnableTracing = 10
Dim v As New Vector()
Call v.addElement("Domino")
Call v.addElement("Notes")
Call v.addElement("R5")
Print "Elements are: " & v.toString()
Results in the text ”Elements are: Domino, Notes, R5”
You may download and use the code at your own risk.
On request, I have changed the license from GPL to LGPL on these files.
I have updated the Vector class with a bug fix that Mikkel Heisterberg kindly supplied. The code is now also GPL:ed.
The definition of a class looks like this:
Public Class Car
End Class
The Public tells that this class will be seen outside the agent or scriptlibrary, where the class is created. You can also make a Private class, that only the agent or script library can see, where the class is defined:
Private Class Car
End Class
To create an instance of a class, you use the New keyword:
Dim myCar as New Car()
or:
Dim myCar as Car
Set myCar = New Car()
To add functionality to a class, you can create functions, subroutines, property getters and property getters. I will not explain the last ones, as they easily can be transformed into functions and subs. To add a function, that returns a value, you write like:
Public Class Car
Public Function getTopSpeed() as Integer
End Function
End Class
To add a subroutine, that does not return a value, you write:
Public Class Car
Public Sub start()
End Sub
End Class
There are two special subroutines, delete and new:
Public Class Car
Public Sub new()
End Sub
Public Sub delete()
End Sub
End Class
The new subroutine, also called constructor, is called whenever you use the New keyword to create a new instance of the class. The delete subroutine is called when there are no references to the object.
To add arguments that can be passed to subroutines and functions, just add them like you do to any ordinary function or subroutine:
Public Class Car
Public Sub new(topSpeed As Integer)
End Sub
End Class
To add instance member variables, declare them inside the class, without the usual Dim:
Public Class Car
topSpeed As Integer
End Class
To use instance member variables, you handle them like any other variable. A special case is show below, when a function has an argument variable, that has the same name as the instance variable. The keyword Me is used to denote the current object, and when saying Me.topSpeed, we mean the instance member variable topSpeed, and not the function argument variable :
Public Class Car
topSpeed As Integer
Public Sub new(topSpeed as Integer)
Me.topSpeed = topSpeed
End Sub
Public Function getTopSpeed() as Integer
getTopSpeed = topSpeed
' Can also be written as:
' Me.getTopSpeed = Me.topSpeed
End Function
End Class
To remove an object from memory, you use the Delete keyword. This removes the actual object from memory, and all references that are using the object can not use it any more.
Dim myCar as New Car(120)
Delete myCar
If you just want to relase a reference to an object, you use the Nothing keyword. This will only remove the specified reference, but the object is still in memory, until ALL references are removed.
Dim myCar as New Car(120)
Set myCar = Nothing
You can test if an object reference is still valid, by comparing the object reference to Nothing:
Dim myCar as New Car(120)
' Do some work...
If myCar Is Nothing _
Then Error 2000, "Object reference not valid"
To check what type an object reference is, you can use the IsA keyword. This is useful, when you don´t know at compile time what type of object you handle:
Dim myVehicle as Variant
If userName = "Donald" Then
Set myVehicle = New Helicopter()
Else
Set myVehicle = New Bicycle()
End If
If myVehicle IsA "Helicopter" _
Then Print "Fly away!"
The problem with the above is, that if you want to assign non-objects to the same variable, you must test if the variable is an object, before trying to use IsA or testing if it is Nothing:
Dim myVehicle as Variant
If userName = "Donald" Then
Set myVehicle = New Helicopter()
Else If userName = "Mickey" Then
Set myVehicle = New Bicycle()
Else
myVehicle = "Illegal user?"
End If
If IsObject(myVehicle) Then
If myVehicle IsA "Helicopter" _
Then Print "Fly away!"
Else
Print "No object, probably strange user..."
End If
To get the name of the class that was used to create an object instance, use the keyword Typename:
Dim myCar As New Car(120)
' Will print "Car":
Print "The type of object is: " & Typename(myCar)...
Ok, let´s do some useful with our new knowledge, let´s create a working Car class. The start sub must be called before the accelerate() method is called.
Public Class Car
topSpeed As Integer
currentSpeed As Integer
started As Intger
Public Sub new(topSpeed As Integer)
Me.topSpeed = topSpeed
End Sub
Public Sub start()
started = True
End Sub
Public Sub stop()
currentSpeed = 0
started = False
End Sub
Public Function accelerate() As Integer
If Not started _
Then Error 2000, "Start the before driving"
If currentSpeed => topSpeed _
Then Error 2000, "Top speed reached"
currentSpeed = currentSpeed + 10
accelerate = currentSpeed
End Function
Public Function getTopSpeed() As Integer
getTopSpeed = topSpeed
End Function
Public Function getCurrentSpeed() As Integer
getCurrentSpeed = currentSpeed
End Function
End Class
To use our class, we can write:
Dim car As New Car(120)
Call car.start()
Do While car.getCurrentSpeed() < car.getTopSpeed()
Print "Current speed is: " & car.accelerate()
Loop
Print "Top speed " & car.getTopSpeed() & " reached!"
Call car.stop()
Print "Car parked!"
Set car = Nothing
There is more to learn about classes in LotusScript, so stay tuned for the next article! Meanwhile, check the following links:
"Using the object-oriented features of LotusScript" on Lotus Developer Domain, great explanation of all (?) advantages!
"User-defined classes" in the Domino Designer Help 5.0.3
The Unfinished LotusScript Book by Julian Robichaux
Bill Buchan's Lotus Notes programming tips