I created the following java script library using the java class from the site above and made minor tweaks for my situation:
package com.clr.zip;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class ZipExtractor {
public String extractZip(String folderName, String fileName) {
try {
byte[] buf = new byte[1024];
ZipInputStream zipinputstream = null;
ZipEntry zipentry;
zipinputstream = new ZipInputStream(new FileInputStream(folderName + fileName));
zipentry = zipinputstream.getNextEntry();
while (zipentry != null) {
// for each entry to be extracted
String entryName = zipentry.getName();
int n;
FileOutputStream fileoutputstream;
File newFile = new File(entryName);
String directory = newFile.getParent();
if (directory == null) {
if (newFile.isDirectory()) {
break;
}
}
fileoutputstream = new FileOutputStream(folderName + entryName);
while ((n = zipinputstream.read(buf, 0, 1024)) > -1) {
fileoutputstream.write(buf, 0, n);
}
fileoutputstream.close();
zipinputstream.closeEntry();
zipentry = zipinputstream.getNextEntry();
}// while
zipinputstream.close();
return(“SUCCESS”);
} catch (Exception ex) {
ex.printStackTrace();
return (“ERROR”);
}
}
}
Then I modified my lotusscript agent to use this class to decompress the zip files.
To be able to use LS2J we have to add these to the Options section of our code
Uselsx “*javacon”
Use “ZipExtractor”
Then declare the following variables to work with the java class:
Dim js As JAVASESSION
Dim zipExtractorClass As JAVACLASS
Dim zipExtractorObject As JavaObject
Now all we have to do is use the following lines to actually decompress a zip file to a certain folder:
Set js = New JAVASESSION
‘Here we get a reference to the ZipExtractor class
Set zipExtractorClass = js.GetClass(“com.clr.zip.ZipExtractor”)
‘Here we get an actual instance of the ZipExtractor class
Set zipExtractorObject = zipExtractorClass.CreateObject
‘This is were the actual java class method is called and parameters are sent
result = zipExtractorObject.ExtractZip(folderName, attachName)
As we can see LS2J can be very handy to provide functionality in lotusscript that normally wouldn’t be possible. Hope others will find this helpful.
Here is a link to a demo db with the java class and the agent so you can mess around with it.
Link to the example database has been fixed.
Thanks thats quite helpful…
also is there any way i can create the java resource/library without domino desiner..if i only have a lotus notes client installed?..thanks
I haven't tested but I think you might be able to use Domiclipse to do that. Check here to install –> https://criverapr.com/2009/04/better-java-development-with-domiclipse.html