Anonymous
Domino 2.0 Rich Internet Applications with IBM Lotus Notes/Domino
You are here: Today » A LotusScript class to handle Query_String key/values
« Web standards: the tools
In search for the fastest string concatenation method in LotusScript »

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.

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

Star rating

0%

Comments

  1. 01/16/2008 08:28:16 PM, Tom ONeil

    Is it fair to assume that stringbuffer is a class you created for something else?

  2. 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.

  3. 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:

  4. 01/17/2008 07:47:46 AM, Michel Van der Meiren

    blog.lotusnotes.be/domino/archive/2007-11-19-stringbuffer.html

  5. 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.