Domino Workspace: the WebSession class
Inspired Jake Howlett's Notes Butter, I've made my own WebSession class to make it easier to work with the basic elements one often needs in a WebQueryOpen agent:
- Easy access to the current database and document
- Easy access to a profile or config document
- Stringbuffer classes to collect HTML blocks
Here's the class so far:
Class WebSession
Public db As NotesDatabase
Public doc As NotesDocument
Public config As NotesDocument
Public path As String
Public user As String
Public pagetype As String
Public debugStack As StringBuffer
Public headStack As StringBuffer
Public bodyStack As StringBuffer
Sub New
start=Getthreadinfo(6)
Dim ns As New NotesSession
Dim prDoc As NotesDocument
Dim setupId As String, tmp As String
Set debugStack=New StringBuffer(100)
Set headStack=New StringBuffer(10)
Set bodyStack=New StringBuffer(100)
Set db=ns.CurrentDatabase
Set doc=ns.DocumentContext
user=doc.getitemvalue("UserName")(0)
pagetype=doc.getitemvalue("PageType")(0)
Set prDoc=db.GetProfileDocument("Domino")
setupID=prDoc.GetItemValue("dbprofile")(0)
Set config=db.GetDocumentByUNID(setupId)
path="/" & doc.GetItemValue("WebDbName")(0) & "/"
End Sub
Sub debug(Byval txt As String)
debugStack.add txt
End Sub
Sub head(Byval txt As String)
headStack.add txt
End Sub
Sub body(Byval txt As String)
bodyStack.add txt
End Sub
End Class
This class sits in a LotusScript library "WebProcessing" and it initiated when the library is included:
' Script library: WebProcessing
Dim ws As WebSession
Sub Initialize
Set ws=New WebSession
End Sub
After that, I have a global object with handles to the current database and document, global settings from a config document or stored as computed for display fields and a few stringbuffers to collect the HTML fragments.
Displaying the list of places
As an example, here's the code I use to display the list of places on the second tab of the Workspace. I use ws.db.GetView("index") to get the view. With ws.body I can add HTML to the page.
Sub displayPlaces
On Error Goto catch
Dim view As notesView
Dim vc As NotesViewEntryCollection
Dim entry As NotesViewEntry
Dim out As New StringBuffer(100)
Dim i As Long
Dim href As String,desc As String
Set view=ws.db.GetView("index")
Set vc=view.GetAllEntriesByKey("places", True)
ws.body |<ul class="view">|
For i=1 To vc.count
Set entry=vc.GetNthEntry(i)
href=ws.path & "pub/" & entry.ColumnValues(2)
ws.body |<li>|
ws.body |<a href="| & href & |">| & entry.ColumnValues(3) & |</a>|
desc=entry.ColumnValues(4)
If Not desc="" Then
ws.body |<p>| & desc & |</p>|
End If
ws.body |<i>Owner: | & entry.ColumnValues(5) & |</i>|
ws.body |</li>|
Next
ws.body |</ul>|
Goto finally
catch:
Error Err, Error & " in " & Getthreadinfo(1) & ", line " & Erl
Resume finally
finally:
End Sub
Comments
To add a comment, log in or register as new user. It's free and safe.