Xpages是否从ViewPanel下载了多个附件?

时间:2018-08-01 12:46:43

标签: download xpages attachment viewpanel

在Xpage上,我试图从Viewpanel下载选定的文档。我尝试使用Knut Herrmann's modified script中的Naveen Maurya's XSnippet

我收到以下错误:

[16A4:000A-0BF8] 08/01/2018 09:18:14 AM  HTTP JVM: TEST 01  
[16A4:000A-0BF8] 08/01/2018 09:18:14 AM  HTTP JVM: A42  
[16A4:000A-0BF8] 08/01/2018 09:18:14 AM  HTTP JVM: TEST 02  
[16A4:000A-0BF8] 08/01/2018 09:18:14 AM  HTTP JVM: TEST 03  
[16A4:000A-0BF8] 08/01/2018 09:18:14 AM  HTTP JVM: com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript action expression  
[16A4:000A-0BF8] 08/01/2018 09:18:14 AM  HTTP JVM: com.ibm.xsp.webapp.FacesServlet$ExtendedServletException: java.lang.IllegalStateException: Can't get a Writer while an OutputStream is already in use  
[16A4:000A-0BF8] 08/01/2018 09:18:14 AM  HTTP JVM: CLFAD0134E: Exception processing XPage request. For more detailed information, please consult error-log-0.xml located in e:/IBM/Domino/data/domino/workspace/logs

代码:

var selectedIds = sessionScope.selectedIds;
print("TEST 01");

for(i=0; i < selectedIds.length; i++) {
print(selectedIds[i]);
    var doc:NotesDocument = database.getDocumentByID(selectedIds[i]);
    print("TEST 02");    
    var attachments:java.util.Vector = session.evaluate("@AttachmentNames", doc);
    print("TEST 03");
///////////new arrangement
// If there are no attachments then STOP!
if (attachments == null || (attachments.size() == 1 && attachments.get(0).toString().trim().equals(""))) {
  print("TEST 04");
  this.setRendered(true); // Show the XPage
  return;
}

var externalContext:javax.faces.context.ExternalContext = facesContext.getExternalContext();
var response:javax.servlet.http.HttpServletResponse = externalContext.getResponse();


// Get the name of the zip file to be shown in download dialog box
var zipFileName = context.getUrl().getParameter("zipFileName");

if (zipFileName == null || zipFileName.equals("")) {
  zipFileName = "AllAttachments.zip";
} else if (!zipFileName.toLowerCase().endsWith(".zip")) {
  zipFileName = zipFileName + ".zip";
}

response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", -1);
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename=" + zipFileName);

var outStream:java.io.OutputStream = response.getOutputStream();
var zipOutStream:java.util.zip.ZipOutputStream = new java.util.zip.ZipOutputStream(outStream);
var embeddedObj:NotesEmbeddedObject = null;
var bufferInStream:java.io.BufferedInputStream = null;

 //////////end new arrangement
// Loop through all the attachments
for (var i = 0; i < attachments.size(); i++) {
  embeddedObj = downloadDocument.getAttachment(attachments.get(i).toString());
  if (embeddedObj != null) {
    bufferInStream = new java.io.BufferedInputStream(embeddedObj.getInputStream());
    var bufferLength = bufferInStream.available();
    var data = new byte[bufferLength];
    bufferInStream.read(data, 0, bufferLength); // Read the attachment data
    var entry:java.util.zip.ZipEntry = new java.util.zip.ZipEntry(embeddedObj.getName());
    zipOutStream.putNextEntry(entry);
    zipOutStream.write(data); // Write attachment into Zip
    bufferInStream.close();
    embeddedObj.recycle();
  }
}
} 
downloadDocument.recycle();
zipOutStream.flush();
zipOutStream.close();
outStream.flush();
outStream.close();
facesContext.responseComplete();

0 个答案:

没有答案