2.1
String strFileName = tools.getParamValue("OutputFilePath");
PRFile objFile = new PRFile(strFileName); //some error checking
if(objFile.exists())
objFile.delete();
2.2
call pxGenerateExcelFile
Params - Param.FileName, WEBWB!APPRSVS!XLSX
2.3
String strFileName = tools.getParamValue("OutputFilePath");
PRFile objFile = new PRFile(strFileName); //some error checking
if (!objFile.exists())
{
attach = false;
} if(!objFile.isFile())
{
attach = false;
}
tools.putParamValue("OutputLocation",objFile.getName()); if (!objFile.canRead())
{
attach = false;
throw new PRRuntimeException("Can't continue with file upload. File \"" + strFileName + "\" is unreadable.");
} //read the file into a buffer.
java.io.DataInputStream dis = null;
byte buffer [] = null;
try
{
// dis = new java.io.DataInputStream(new java.io.FileInputStream(objFile));
dis = new java.io.DataInputStream(new PRInputStream(objFile));
buffer= new byte[dis.available()];
dis.readFully(buffer);
dis.close();
}
catch (Exception e)
{
attach = false;
throw new PRRuntimeException("Can't continue with file upload. Can't read File \"" + strFileName + "\"");
} //encode the file to Base64 so that we can store it on the database
strFileData = Base64Util.encodeToString(buffer);
if (strFileData == null)
{
attach = false;
throw new PRRuntimeException("Can't continue with file upload. Couldn't encode the file to Base64 so that we can store it on the database");
}
2.5
Page-new att (Embed-EmailAttachment)
2.6
Property-set att
.pyDecode=true
.pyData=local.strFileData
.pyName=Param.FileName
2.7 atts (Data-EmailAttachments)
Page-copy
from: att
to: atts.pyAttachments(<APPEND>)
Param.AttachmentPage=atts
===================================
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
java.util.zip.ZipOutputStream logical_zip = null;
class ParamHelper {
Boolean getBooleanValue(String param){
String value = tools.getParameterPage().getString(param);
if("true".equalsIgnoreCase(value)){
return true;
}else if("false".equalsIgnoreCase(value)){
return false;
}else{
return null;
}
}
}
ParamHelper params = new ParamHelper();
try {
// Create a ZIP archive output stream with no compression
logical_zip = new java.util.zip.ZipOutputStream(baos);
} catch (Exception e) {
throw new PRRuntimeException("Cannot initialize archive: " + e.getMessage());
}
ClipboardProperty cpResults = tools.findPage("pyWorkPage").getProperty("SendFiles");
try {
for (Iterator instPgList = cpResults.iterator(); instPgList.hasNext();) {
ClipboardProperty objOneRow = (ClipboardProperty) instPgList.next();
ClipboardPage objOneRowPage = objOneRow.getPageValue();
String strOutputPRFileName = objOneRowPage.getProperty("AttachStream").getStringValue();
byte[] data = Base64Util.decodeToByteArray(strOutputPRFileName);
String strOutputFileName = objOneRowPage.getProperty("AttachName").getStringValue();
boolean isSubFolderExist = Boolean.parseBoolean(objOneRowPage.getProperty("IsSubFolderExist").getStringValue());
// Determine the folder path based on the isSubFolderExist flag
String folderPath;
if (isSubFolderExist) {
folderPath = "SubFolder/";
} else {
folderPath = "";
}
// Add each file to the appropriate folder in the ZIP archive
String fileFolderPath = folderPath + strOutputFileName;
try {
logical_zip.putNextEntry(new java.util.zip.ZipEntry(fileFolderPath));
logical_zip.write(data);
logical_zip.closeEntry();
} catch (java.io.IOException e) {
throw new PRRuntimeException("Cannot add file to archive: " + e.getMessage());
}
}
// Send the entire ZIP archive to the client
String zipFileName = tools.getParameterPage().getString("ZipFileName");
zipFileName = zipFileName + ".zip";
try {
logical_zip.close();
baos.close();
tools.sendFile(baos.toByteArray(), zipFileName, false, null, true);
} catch (java.io.IOException e) {
throw new PRRuntimeException("Error while sending: " + e.getMessage());
}
} catch (Exception ex) {
throw new PRRuntimeException("Error: " + ex.getMessage());
}
============================================================
No comments:
Post a Comment