LotusScript non ha alcuna classe al suo
interno per comprimere le informazioni utilizzando lo ZIP.
Ma per realizzare questa funzionalità basta utilizzare una caratteristica
di LS capace di richimaare una classe scritta in JAVA.
Tutto ciò è possibile utilizzando LS2J descritto nell'help del designer.
Ottengo un agente con il seguente codice:
*****************************************************
Sub Initialize
Dim js As JAVASESSION
Dim zipClass As JAVACLASS
Dim zipFileObject As JavaObject
Dim varFileToZip As String, varOutFilePath As String, returnCode As String
Set js = New JAVASESSION
Set zipClass = js.GetClass("ZipFile")
Set zipFileObject = zipClass.CreateObject
varFileToZip = "c:tempdocument.doc"
varOutFilePath = "c:tempthezipfile.zip"
returnCode = zipFileObject.zipMyFile(varFileToZip, varOutFilePath) 'Calling
the zip function
If Not returnCode = "OK" Then
Print "An Error occurred"
Else
Print "Zip went OK"
End If
End Sub
*****************************************************
Nelle option dell'agente dichiaro:
*****************************************************
Uselsx "*javacon" 'Which lets you use Java from LotusScript
Use "ZipFile" 'A Java library that holds a function to do zipping
*****************************************************
Qui di seguito vien messa una libreria Java che deve essere utilizzata
per ZIPPARE un file. Bisogna creare una JAVA Library con Designer nello
Shared Code--> Script Library--> Click Add New Java Library ed inserire
il codice seguente:
*****************************************************
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ZipFile {
public String zipMyFile(String fileToZip, String zipFilePath) {
String result = "";
byte[] buffer = new byte[18024];
// Specify zip file name
String zipFileName = zipFilePath;
try {
ZipOutputStream out =
new ZipOutputStream(new FileOutputStream(zipFileName));
// Set the compression ratio
out.setLevel(Deflater.BEST_COMPRESSION);
System.out.println(fileToZip);
// Associate a file input stream for the current
file
FileInputStream in = new FileInputStream(fileToZip);
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(fileToZip));
// Transfer bytes from the current file to
the ZIP file
//out.write(buffer, 0, in.read(buffer));
int len;
while ((len = in.read(buffer)) > 0)
{
out.write(buffer, 0, len);
}
// Close the current entry
out.closeEntry();
// Close the current file input stream
in.close();
// Close the ZipOutPutStream
out.close();
}
catch (IllegalArgumentException iae) {
iae.printStackTrace();
return "ERROR_ILLEGALARGUMENTSEXCEPTION";
}
catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
return "ERROR_FILENOTFOUND";
}
catch (IOException ioe)
{
ioe.printStackTrace();
return "ERROR_IOEXCEPTION";
}
return "OK";
}
}
*****************************************************
ZIP da LotusScript con Domino 6.x e successivi
- 04/24/2005
- 0 commenti
0 Commenti:
Nessun Commento Trovato