Most used technotes for Lotus Domino –> IBM support.
Most used technotes for Lotus Notes –> IBM support.
Month: March 2005
Mylar
Super cool plugin for Eclipse that tracks which files you are using and presents these in special views for easy use. Mylar via eclipse powered.
Fallback JavaScript library
The solution is a combination of the two JavaScript libraries and the calling HTML page using exception handling and dynamic HTML generation.
“Primary JavaScript library
function one() {
return "1";
}
“Fallback” JavaScript library
function two() {
return "2";
}
HTML file
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>
<link rev="made" href="mailto:www-validator@w3.org" />
<link rev="start" href="./" title="Home Page" />
<style type="text/css" media="all">@import "./base.css";</style>
</head>
<!-- fail to load the primary library1.js JavaScript library -->
http://library.js
<body>
<!-- holder for dynamic HTML -->
<div id="script_holder" />
try {
// try and use the primary script library (will fail)
alert(one());
} catch (exception) {
// using the primary script library failed - fallback to secondary library
var e = document.createElement("script");
e.type = "text/javascript";
e.src = "library2.js";
document.getElementById("script_holder").appendChild(e);
// set timeout to test that the fallback library was loaded
setTimeout("doTest()", 100);
}
function doTest() {
alert(two());
}
</body>
</html>
ReplaceSubstring in LotusScript
Full code for the function is inserted below as well as an example.
Please note that the code may wrap…
Sub Initialize
'declarations
Dim s As New NotesSession
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim result As Variant
Dim look_for(1) As String
look_for(0) = TEST_OLD_URL_RESOURCE
look_for(1) = TEST_OLD_URL_SCANNET
Dim replace_with(1) As String
replace_with(0) = TEST_NEW_URL_RESOURCE
replace_with(1) = TEST_NEW_URL_SCANNET
Dim process_fields(5) As String
process_fields(0) = "txtLinksDisplayData_1"
process_fields(1) = "txtLinksDisplayData_2"
process_fields(2) = "txtLinksTargetData_1"
process_fields(3) = "txtLinksTargetData_2"
process_fields(4) = "txtLinks_1"
process_fields(5) = "txtLinks_2"
Set dc = s.CurrentDatabase.UnprocessedDocuments
Set doc = dc.GetFirstDocument
While Not (doc Is Nothing)
'loop fields and replace
Forall field In process_fields
result = ReplaceSubstring(doc.GetItemValue(field), look_for, replace_with)
Call doc.ReplaceItemValue(field, result)
End Forall
'save
Call doc.Save(True, False)
'get next
Set doc = dc.GetNextDocument(doc)
Wend
End Sub
Public Function ReplaceSubstring(look_in As Variant, look_for As Variant, replace_with As Variant) As Variant
'validate parameters
If Isarray(look_for) And Isarray(replace_with) Then
'both are arrays - make sure they are the same size
If Ubound(look_for) Ubound(replace_with) Then
'different size
Error 9999, "The look_for and replace_with arrays must be of the same size."
End If
Elseif (Isarray(look_for) Xor Isarray(replace_with)) Then
'either look_for is an array and replace_with isn't or nice versa
Error 9999, "If look_for is an array so must replace_with or vice versa."
End If
If Isarray(look_in) Then
'handle all entries in the array
Dim result_array() As Variant
Dim result As Variant
Redim result_array(Ubound(look_in))
Dim count As Integer
'loop
Forall v In look_in
'make sure we do not run on objects
If Not Isobject(v) Then
'do replace
result = pReplaceSubstring(v, look_for, replace_with)
'store result in array
result_array(count) = result
Else
'keep original value
Set result_array(count) = v
End If
'increment count
count = count + 1
End Forall
'return result
ReplaceSubstring = result_array
Else
'handle single value - make sure we do not run on objects
If Not Isobject(look_in) Then
'do replace
ReplaceSubstring = pReplaceSubstring(look_in, look_for, replace_with)
Else
'return original value
Set ReplaceSubstring = look_in
End If
End If
End Function
Private Function pReplaceSubstring(Byval look_in As Variant, look_for As Variant, replace_with As Variant) As Variant
'make sure the input is a string
If Typename(look_in) "STRING" Then
'return original value
If Isobject(look_in) Then
Set pReplaceSubstring = look_in
Else
pReplaceSubstring = look_in
End If
Exit Function
End If
'is there an array of things to look for ?
If Isarray(look_for) Then
'yes - handle all values
Dim i As Integer
'loop - arrays garanteed to be the same size be calling function
For i=0 To Ubound(look_for)
'do replacesubstring
look_in = pReplaceSingleValue(look_in,look_for(i), replace_with(i))
Next
'return
pReplaceSubstring = look_in
Else
'nope - single value
pReplaceSubstring = pReplaceSingleValue(look_in,look_for, replace_with)
End If
End Function
Private Function pReplaceSingleValue(look_in As Variant, look_for As Variant, replace_with As Variant) As String
'declarations
Dim index_start As Integer
Dim index_stop As Integer
Dim first_part As String
Dim last_part As String
Dim result As String
'look for the value
index_start = Instr(1, look_in, look_for)
If index_start > 0 Then
'we found the value - get the part before what we are
'looking for (if not at the beginning)
If index_start > 1 Then
first_part = Mid$(look_in, 1, index_start-1)
End If
'calcuate the stop index
index_stop = index_start + Len(look_for)
'get the last part (if not past the end of the string)
If index_stop < Len(look_in) Then
last_part = Mid$(look_in, index_stop)
End If
'concatenate the parts
result = first_part + replace_with + last_part
'return
pReplaceSingleValue = result
Else
'substring not found - return the original value
pReplaceSingleValue = look_in
End If
End Function