Tuesday, June 27, 2006

Notes, Domino, WebService, Service

Sample WebService in ND7:

Dim s As notesSession
Dim db As notesDatabase
Class arTitles
Public ar() As String
End Class

Class docInfo

Sub NEW ()
Set s = New notesSession
Set db = s.CurrentDatabase
End Sub

Public Function getAllDocs () As arTitles
Dim n As Integer, vw As notesView, doc As notesDocument, sTitle As String
Set getAllDocs = New arTitles()
Set vw = db.GetView("vwMain")
Set doc = vw.GetFirstDocument()
n = -1
While Not (doc Is Nothing)
n = n + 1
sTitle = doc.docTitle(0)
Redim Preserve getAllDocs.ar(0 To n)
getAllDocs.ar(n) = sTitle
Set doc = vw.GetNextDocument(doc)
Wend
End Function

Public Function getSingleDocAbstractByTitle (sTitle As String) As String
Dim docIn As notesDocument
Set docIn = s.DocumentContext
sLang = getLangFromHeader (docIn, "English")
Dim vw As notesView, doc As notesDocument, sAbstract As String
Set vw = db.GetView("vwMain")
Set doc = vw.GetDocumentByKey (sTitle, True)
If (doc Is Nothing) Then
Msgbox "Nothing found. (" + sTitle + ")"
getSingleDocAbstractByTitle = "Document could not be found."
Else
Msgbox "Something found. (" + sTitle + ")"
Select Case sLang
Case "English"
getSingleDocAbstractByTitle = doc.docAbstract(0)
Case "Spanish"
getSingleDocAbstractByTitle = doc.docAbstract_es(0)
Case Else
getSingleDocAbstractByTitle = doc.docAbstract(0)
End Select
End If
Msgbox "Web service Returning: " + getSingleDocAbstractByTitle
End Function

Private Function getLangFromHeader (doc As notesDocument, sDefault As String) As String
Dim sXML As String
On Error Goto getLangFromHeader_err
If (doc Is Nothing) Then
getLangFromHeader = sDefault
Exit Function
End If
sXML = doc.Request_Content(0)
If (sXML = "") Then
getLangFromHeader = sDefault
Exit Function
End If

Dim s As New notesSession, dp As notesDOMParser, root As notesDOMDocumentNode, nodeList As NotesDOMNodeList, n As Integer
Dim nodeLang As notesDOMNode, nodeLangText As notesDOMNode
Set dp = s.CreateDOMParser (sXML)
Call dp.Parse
Set root = dp.Document
Set nodeList = root.GetElementsByTagName("sLang")
n = nodeList.NumberOfEntries
If (n <= 0) Then
getLangFromHeader = sDefault
Exit Function
End If
Set nodeLang = nodeList.GetItem(1)
Set nodeLangText = nodeLang.FirstChild
If (nodeLangText.IsNull) Then
getLangFromHeader = sDefault
Exit Function
End If
getLangFromHeader = nodeLangText.NodeValue
Exit Function
getLangFromHeader_err:
getLangFromHeader = "Error: (" + Cstr(nLine) + ") " + Error$
Exit Function

End Function
End Class

Thursday, June 22, 2006

Javascript, Listbox, Select

Add an entry to a list

function addToLB (lb, s) {
var optionObject = new Option(s);
var optionRank = lb.options.length;
lb.options[optionRank]=optionObject;
}
Javascript, ListBox

Add a day and month to select (listbox)

function addMonthYear (lb, nMonth, nYear) {
var optionObject = new Option(monthName(nMonth) + ", " + nYear, nYear*100+nMonth);
var optionRank = lb.options.length;
lb.options[optionRank]=optionObject;
}

Tuesday, April 11, 2006

HTML, Targets

The _new attribute is treated as textual identifier for a window instance -- the window created is thereafter referred to as "_new". This can be a very useful behavior, allowing you to target links to various windows by name, but it is an important difference from the "_blank" reserved word. Using a target value of "_blank" will always create a brand new window.

Wednesday, March 22, 2006

Java, Portlet

Code to change edit mode:

PortletRequest request = (PortletRequest) facesContext.getExternalContext().getRequest();
try {
request.setModeModifier(Portlet.ModeModifier.PREVIOUS);
} catch (AccessDeniedException e) {
// Your exception handling code here
}

Thursday, March 16, 2006

JavaScript, Show/Hide Fields

#script language="javascript"#
function hideField(bHide, textFld) {
if (bHide){
textFld.style.display = 'none';
}
else {
textFld.style.display = 'block';
}
}
#/script#

Tuesday, February 28, 2006

Notes, Dialog Boxes

When hiding the OK and Cancel buttons, and replacing with simulator buttons, on an @DialogBox form, you must use @Command([RefreshParentNote]) or uiDoc.RefreshParentNote( ) to move field values back to the source document, before doing an CloseWindow. The following code can be used in a button which simulates the OK button:

@Command([RefreshParentNote]);
@Command([FileCloseWindow]);
Notes, ACL, Roles

If a user is in two groups both listed in the ACL, and one has a higher access level than the other, then the user gets the entire acl entry for the higher level. Even if this means they do not get the roles associated with the lower entry (if not also associated with the higher entry).

Friday, February 24, 2006

Notes, LotusScript

Encode a URL - similar to @URLEncode

Function urlEncode(s As String) As String
If Len(s) = 0 Then Exit Function

Dim tmp As String
Dim c As String
Dim i As Integer

For i = 1 To Len(s)
c = Mid(s, i, 1)
If (Asc(c) >= 65 And Asc(c) <= 90) _
Or (Asc(c) >= 97 And Asc(c) <= 122) _
Or (Asc(c) >= 48 And Asc(c) <= 58) _
Or Asc(c) = 38 _
Or (Asc(c) >= 45 And Asc(c) <= 47) _
Or Asc(c) = 58 Or Asc(c) = 61 _
Or Asc(c) = 63 Or Asc(c) = 126 Then
tmp = tmp + c
Else
tmp = tmp + "%" + Hex(Asc(c))
End If
Next i
urlEncode = tmp
End Function