4/28/2010

LS2J: Replace string by using regular expression

I introduced the sample code to use regular expression but some of guys still believe that this kind of code can be performed by using @contains or other LotusScript code.. I should have used more complicated matching to show the power of regular expressions.

As more practical sample, today I'd like to introduce another sample code to use regular expressions. (still not complicated)

Regular expression is very powerful when you want to replace the chunk of strings.
Please note that LS2J needs to load jvm when running the agent. so intensive use of this function might be slower than normal LotusScript application.




Uselsx "*javacon"
Sub Click(Source As Button) Dim b As Boolean teststr$ = "[09D4:000D-0D50] 2008/09/18 15:45:26 HTTP Server: Error - Memory allocation error" ' Regular expression to match Thread ID part ([09D4:000D-0D50]) regex$ = "\[[\p{Alnum}:-]*\]" ' regex$ = "\[[a-zA-Z0-9:-]*\]" replacedstr$ = "" result$ = ReplaceString(testStr$,regex$, replacedstr$) Msgbox "Input: " & teststr$ & Chr(13) & "Pattern: " & regex$ &; " -> " &; replacedstr$ &a; Chr(13) & result$ End Sub Function ReplaceString(InputStr As String , RegEx As String, ReplacedStr As String) As String ' RepleaceString: This function is to replace the string by using regular expression. ' See following reference site for Java regular expressions
' URL: http://java.sun.com/j2se/1.5.0/ja/docs/ja/api/java/util/regex/Pattern.html ' InputStr: Strings to be replaced
' RegEx: Regular expression to replace target string ' ReplacedStr: Strings To Replace ' Return Value: Replaced String ' Note: Do not forget declaring Uselsx "*javacon" Dim j As JavaSession Dim c As JavaClass Dim pattern As JavaObject Dim matcher As JavaObject Dim e As JavaError Set j = New JavaSession Set c = j.GetClass("java.util.regex.Pattern") Set pattern = c.compile(RegEx) Set matcher = pattern.matcher(InputStr) ReplaceString = matcher.replaceAll(ReplacedStr) End Function
Hope it helps!

4/26/2010

mandatory fix for Lotus iNotes 8.5.1 FP2 users

Supplemental DLL is released for Lotus iNotes 8.5.1 FP2 users.

Lotus iNotes supplemental DLL file (dwabho.dll) for Domino 8.5.1 Fix Pack 2 (851FP2)



This file (dwabho.dll) is used in iNotes browser cache management and this file should have been included in Lotus Domino 8.5.1 FP2. if you're not familiar with the browser cache management, please also refer to this technote.

the confusing point is file name. you may feel like the file extension "dll" does not fit non-Windows platform but this is for Internet explorer such as Windows XP or Windows 7.

4/10/2010

Great XPages sample application from OpenNTF

 Have you been already aware that a great XPages sample application is released from OpenNTF?
I'm so excited to see this sample application.

New Release of XPages Demo Application for 8.5.1 including Notes Client

You can test almost all kind of XPages control in one application on browser or Notes client (8.5.1 or higher). It's really good for starting point of your XPages experience.

Setup is very simple.
Just download the file and copy it to server and sign the design element from administrator client.

3/31/2010

LS2J: Match string with regular expression




Have you ever tries LS2J in your LotusScript?
This is the way to connect to Java class from LotusScript

Some of you may not have lots of time to learn new technology, but there're only 9 classes for LS2J.

As an example, I invoked java.util.regex.Pattern class and java.util.regex.Matcher class for use of regular expression and this sample code shows simple regular expression string match. some people may be missing regular expression of Java or perl.. With LS2J, you can use it!

See also following site to check what expressions can be used
Pattern class (Java SDK document)

' Module for LS2J Uselsx "*javacon" Sub Click(Source As Button) Dim b As Boolean teststr$ = "あああ" '"do not contain ASCII char = All of strings are DBCS" regex$ = "[^\p{ASCII}]*" replacedstr$ = "Test" b = MatchString(teststr$ ,regex$) Msgbox "Input: " & teststr$ & Chr(13) &; "Pattern string: " & regex$ & Chr(13) & "Result: " & Cstr(b) End Sub Function MatchString( InputStr As String, RegEx As String) As Boolean ' InputStr: Input string to test ' RegEx: Regular expression formula for match ' Return Value: True if matched Dim j As JavaSession Dim c As JavaClass Dim pattern As JavaObject Dim matcher As JavaObject Dim e As JavaError Set j = New JavaSession Set c = j.GetClass("java.util.regex.Pattern") Set pattern = c.compile(RegEx) Set matcher = pattern.matcher(InputStr) MatchString = matcher.matches() End Function

3/27/2010

Lotus Notes/Domino 8.5.1 FP2 is available!

 8.5.1 FP2 is now available

Notes/Domino 8.5.1 Fix Pack 2 is available (Notes From Lotus Support)



You can get it from FixCentral but download link information would help you access more quickly.


Download Options (Technote 4025721)


We strongly recommend customer to apply FP2 since it contains a multiple important fix to prevent a critical problem.
Fix list is available from Release Notice.


Personally, I am glad to know following fix is included in FP2


SPR# PALT5N5SE7 - If a view setting is changed via View-Customization, the changes will not stay if Shift-F9 is used to rebuild the view. With this fix, view customization will remain after rebuilding a view. If the view design is changed, the view customization will not be saved and must be re-applied by the user. (Technote #1112923)

Implement a typical loop routine to the previous diiop sample

The most typical sample of Notes API would be open view, get one document and change/get item value.

I previously posted a simple sample code for the beginner of DIIOP technology and some would want to know how to implement a typical Notes routine as follows.



NABLoop.java
import lotus.domino.* ;

public class NABLoop 
{
 static String host = "xxx.xxxx.com" ; // server address
 static String cName = "notes admin" ; //username
 static String dbname = "names.nsf"; // database (e.g. mail\\hnagashi.nsf)
 static String password = "password" ;  // internet password

  public static void main(String args[]){
     try{
   Session s = NotesFactory.createSession(host,cName,password) ;
   Database db = s.getDatabase("", dbname );

 if(!db.isOpen()){
  db.open();
 }
   View view = db.getView("People");
     Document doc = view.getFirstDocument();
   Document temp = null;
   String title = db.getTitle();
   String uname = s.getUserName();
   
   System.out.println("Session User Name: " + uname );
   System.out.println("ServerName: " + db.getServer());
   System.out.println("Title: " + title);

 while (doc != null)
 {
  System.out.println("User Name: " + doc.getItemValueString("FullName"));
  temp = view.getNextDocument(doc); 
  doc.recycle();   
  doc = null;
  doc = temp;
}

        }catch(NotesException ne){
   System.out.println(ne.id + ne.text);
   ne.printStackTrace() ;
 }catch (Exception e){e.printStackTrace() ;}
  }
}
Hope it helps!

3/22/2010

Collecting NSD file using VBScript

 Some of you may have experience to create batch file to kick NSD command.
I also created the batch file like that but I hated to edit the batch file every time it is copied to a different environment. this is why I created this command with VBScript.
By using VBScript, I can access registry value thus Notes program/data directory information can be retrieved from the registry.

You can run this VBS file just by copying it to any directory on your computer and double-click the file. so I think this sample is useful when you want to access Notes program/data directory automatically in the batch file.



RunNSD.vbs
Function GetProgramDir()
  GetProgramDir = ""
  Dim objWshShell
  Set objWshShell = WScript.CreateObject("WScript.Shell")
  strValue = objWshShell.RegRead("HKLM\SOFTWARE\Lotus\Notes\Path")
  if Right(strValue,1) <> "\" Then
    strValue = strValue & "\"
  End if
  GetProgramDir = strValue 
End Function

Function GetDataDir()
  GetDataDir = ""
  Dim objWshShell
  Set objWshShell = WScript.CreateObject("WScript.Shell")
  strValue = objWshShell.RegRead("HKLM\SOFTWARE\Lotus\Notes\DataPath")
  if Right(strValue,1) <> "\" Then
    strValue = strValue & "\"
  End if
  GetDataDir = strValue 
End Function

Function IsWin2k()
 IsWin2k = False
 strComputer = "." 
 Set objWMIService = GetObject("winmgmts:" _ 
     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
 Set colOperatingSystems = objWMIService.ExecQuery _ 
     ("Select * from Win32_OperatingSystem") 
 For Each objOperatingSystem in colOperatingSystems 
     If Instr (objOperatingSystem.Caption, "Windows 2000") > 0 Then
  IsWin2k = True
     End If
 Next 
End Function

Dim objWshShell
Dim strCmdLine
Set objWshShell = WScript.CreateObject("WScript.Shell")
NSDPath = GetProgramDir() & "nsd.exe"
objWshShell.CurrentDirectory = GetDataDir()

If Not isWin2k() Then
   strOption = " -detach"
End If

strCmdLine = NSDPath & strOption
objWshShell.Exec(strCmdLine)

If Err.Number <> 0 Then
  WScript.Echo "NSD Error " & Err.Description
End If


NOTE:
- This VBS file checks registry file regarding Notes client.
   If you want to run this file on the environment as follows, you need to change registry path.
   1) Multi user installation
   2) Old version (prior to Lotus Notes 6.5.x)
   3) Lotus Domino Server

- "-detach" option is not actually needed on the latest version like 8.5.x or 8.0.x 
   I added this option so that I just wanted to show OS check logic can be added

- If you want to clean up client after NSD execution, please change strOption as follows.
  strOption = " -DumpAndKill"

3/17/2010

Sendkeys method

When I set up an additional Domino server, I felt annoyed with typing server id password to console every time I launched domino server. Not to mention, you just need to reset server id password from administrator client to avoid this but I previously wrote following VBScript.
(This file needs to be located on Domino program directory)



StartServer.vbs
Dim WshShell
set WshShell = CreateObject("WScript.Shell")
WshShell.Run("nserver.exe")
WScript.Sleep(100)
WshShell.AppActivate("Lotus Domino Server")
WshShell.SendKeys("password")
WshShell.SendKeys("{Enter}")

See following page for the details about SendKeys method


Yes, you should not do this. This is VERY dangerous - Password information is directly written on plain text file. However, this is interesting...

I imagined that the VBS like following works like client automation testings tools!
See the following VBS code. This script is open notes client and open mail database, quit notes.


StartNotes.vbs
# Edit blue variable to fit your environment.
Dim WshShell
set WshShell = CreateObject("WScript.Shell")
WshShell.Run("notes.exe")
WScript.Sleep(8000)
WshShell.AppActivate("Lotus Notes")
WshShell.SendKeys("password")
WshShell.SendKeys("{Enter}")
WScript.Sleep(4000)
WshShell.SendKeys("^o")
WshShell.SendKeys("%i")
WshShell.SendKeys("mailserver")
WshShell.SendKeys("{Enter}")
WshShell.SendKeys("%f")
WshShell.SendKeys("mail/xxxx.nsf")
WshShell.SendKeys("%o")
WScript.Sleep(10000)
WshShell.SendKeys("%(fx)")


I tried this script, but I saw that this cannot be run for a long time. you know, This kind of script is very timing-dependent.

Anyway, it might be useless sample code, I just thought it was interesting.

3/16/2010

Installing and configuring IBM Lotus Domino 8.5 on AIX

I noticed that following article is posted on Lotus Notes And Domino Wiki.

Installing and configuring IBM Lotus Domino 8.5 on AIX


This article covers not only detailed procedure of installing Domino on AIX, but also various AIX commands and start script and important configuration information

3/15/2010

Some comments on my sample (in the previous post..)

On the previous post, I did not explain the code at all so I added some comments on my sample code.

Following line indicates that this code is a remote access application, thus this application uses NCSO.jar.

Session s = NotesFactory.createSession(host,cName,password) ;

As this is called a "remote" access application, you need to specify host name to connect server.
Local access application is used like this.

Session s = NotesFactory.createSession() ;

What confuses you is that "local" access application may access the server, too.
"local" just means that you use "local" notes client application dll to access Notes object and "remote" just means that application uses remote DIIOP-based procedure call (a.k.a ORB).


Also, some experienced developer saw my code and felt like this...

"Static variable for host name , user name and password in this code looks silly. I will handle this value as an argument value instead, which does not need compilation when I changed the value"

Believe me... I did it intentionally..
When investigating DIIOP issue/remote access application code issue in support scene, I always need to compile the code very frequently. so compilation is not the problem for my investigation. Rather, I wanted to avoid to forget the order of argument value or usage of aplication. That's why I preferred static value in sample code but feel free to change the same as you like.