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.

A sample code for testing DIIOP feature

Today I want to introduce a testing code for users who have not had an enough experience of DIIOP or Notes Java class and want to learn DIIOP feature.

Preparation
1. Start HTTP & DIIOP task
 To use DIIOP feature, you need to start HTTP task and DIIOP task beforehand.
You can manually start these task like "load DIIOP" command or you can add these tasks to "ServerTasks" entry in your server Notes.ini file.

2. Install JDK
 You also need to install JDK environment to compile DIIOP program.
You can get JDK environment from here.

IBM JDK Download
Sun JDK Download

On the sample in this article, you need to take so much care of Java version, but basically you need to use the same Java version as your Lotus Notes/Domino JRE environment.
 To check your JRE version, use \jvm\bin\java -fullversion command.

Example:
C:\lotus\notes\jvm\bin>java -fullversion
java full version "J2RE 1.5.0 IBM Windows 32 build pwi32devifx-20071025 (SR6b)"


3. Copy NCSO.jar
 On using remote access application ( I mean the Java program which uses NCSO.jar, not Notes.jar) , you don't need to install Lotus Notes client on client environment.
You just copy NCSO.jar file to your client machine.
NCSO.jar file is located on \domino\java

Sample Code
 On this article, you don't need to prepare sample database to run the sample.
This sample code just accesses the specified server and opens names.nsf on the Domino server and get some database information.

NABTest.java  (Change the variable in blue to fit your environment)
import lotus.domino.* ;

public class NABTest 
{
 static String host = "xxxx.xxx.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();
 }
   String title = db.getTitle();
   String uname = s.getUserName();
   
   System.out.println("UserName: " + uname );
   System.out.println("ServerName: " + db.getServer());
   System.out.println("Title: " + title);

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

Compile and Execution
When you start to run DIIOP program, I think compiling DIIOP program would be the most difficult step for unfamiliar users. To compile program, you just add the path to NCSO.jar file to CLASSPATH but to avoid confusion, I usually create the batch file like this.
(I used "C:\MyJava" directory as working directory)

Compile.bat (Change the variable in blue)
set Java_HOME=C:\SUN\Java\jdk1.6.0_06\bin
set PATH=%Java_HOME%;%PATH%
set CLASSPATH=C:\lotus\notes\data\domino\java\NCSO.jar;C:\myjava
javac -target 1.5 NABTest.java


JAVA_HOME:  Full path to your JDK bin folder
CLASSPATH: Add work directory(C:\MyJava in the above sample) and full path to NCSO.jar


Note: On the above sample. I used "-target 1.5" because Notes Domino 8.x uses Java 1.5.
so you need to specify "-target 1.4" when you uses Lotus Notes Domino 7.x


run.bat
java -cp c:\MyJava;c:\lotus\notes\data\domino\java\NCSO.jar NABTest


Result
 You will get the result like this.


C:\MyJava>run
C:\MyJava>java -cp c:\MyJava;D:\lotus\notes\data\domino\java\NCSO.jar NABTest
UserName: CN=notes admin/O=LTS
ServerName: CN=xxxx/O=LTS
Title: LTS's Directory





This is very cheap and simple code like "Hello World" code and when I set up DIIOP test environment, I am using this kind of code to test my environment is working correctly.


Hope it helps!

Lotus Domino 8.5.1 FP1 IF1 for DAOS is released!

Now you can see Lotus Domino 8.5.1 FP1 IF1 is available. See below link for details.

Domino 8.5.1 Fix Pack 1 Interim Fix 1 (8.5.1 FP1 IF1) - DAOS Fixes

Although all of fix in this interim fix will be included in 8.5.1 FP2, it is recommended that customer who uses DAOS feature applies this fix immediately.

Just started my blog

I just launched my blog today
I've been posting Japanese version blog, but I also wanted to have an English version.

Stay tuned!