A LotusScript class to handle Query_String key/values
This comes in handy when you want to manipulate key/value pairs in your URLs, e.g. to show part of a view:
myView?open&page=1&count=20&hidedetails
How to use
You need to add the CGI field Query_String_Decoded on your form. The DwQuery class requires one other class: StringBuffer.
- Create an instance with:
Dim myQuery as New DwQuery - Get a value:
myQuery.getValue(theKey) - Set a value:
myQuery.setValue(theKey, theValue) - Check if a key is present, even not having a value:
myQuery.hasKey(theKey) - Remove a key/value pair:
myQuery.remove(theKey) - Getting the complete query again:
myQuery.toString
The code
Class DwQuery
Private qList List As String
Sub New
Dim s As New notessession
Dim v As Variant, i As Integer, vv As Variant
v=Split(Replace(s.DocumentContext.query_string_decoded(0), "&", "&"), "&")
For i=1 To Ubound(v)
vv=Split(v(i), "=")
If Ubound(vv)>0 Then
qList(vv(0))=vv(1)
Else
qList(vv(0))=""
End If
Next
End Sub
Function getValue(Byval sKey As String)As String
If Iselement(qList(sKey)) Then
getValue=qList(sKey)
Else
getValue=""
End If
End Function
Sub setValue(Byval sKey As String, Byval sValue As String)
qList(sKey)=sValue
End Sub
Function hasKey(Byval sKey As String)As String
hasKey=Iselement(qList(sKey))
End Function
Function remove(Byval sKey As String)
If Iselement(qList(sKey)) Then
Erase qList(sKey)
End If
End Function
Function toString As String
Dim tmp As New stringbuffer(10),sTmp As String
Forall q In qList
tmp.add Listtag(q) & "=" & q
End Forall
sTmp=tmp.collapse("&")
If sTmp="" Then
toString="?open"
Else
toString="?open&" & sTmp
End If
End Function
End Class
Comments
01/16/2008 08:28:16 PM, Tom ONeil
Is it fair to assume that stringbuffer is a class you created for something else?
01/16/2008 09:26:00 PM, Tom ONeil
My only other note is that your code doesn't like non-encoded "equals" (=) in the URL.
01/17/2008 07:46:27 AM, Michel Van der Meiren
Equals can in this case only be used to separate key/values. And the StringBuffer class is here:
01/17/2008 07:47:46 AM, Michel Van der Meiren
blog.lotusnotes.be/domino/archive/2007-11-19-stringbuffer.html
01/18/2008 08:03:10 PM, Tom ONeil
You can tell I have the memory of a flea. I was the first comment on that post.
To add a comment, log in or register as new user. It's free and safe.