cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple Download Issue

Former Member
0 Kudos

<pre>Hi...

Following the link bellow, I was developed the next code:


IWDMessageManager msg_manager = wdComponentAPI.getMessageManager();
	try
		{
		//zip all PDFs data into zip file and allows user to save
		String pONo = "";
		String pONoNext = "";
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ZipOutputStream zos = new ZipOutputStream(baos);
		
		int intTotalNF	= wdContext.nodeRetornoXML().size();
		int count 		= wdContext.nodeRetornoXML().size();
		int destPos 	= 0;
		
		//msg_manager.reportSuccess("Tamanho -> " + count);
		
		byte[] out = new byte[2048 * count];
		byte[] Content = new byte[2048 * count];
		
		wdContext.nodeRetornoXML().moveFirst();
		wdContext.nodeRetornoXML().clearSelection();
		wdContext.nodeRetornoXML().moveTo(0);
		
		ZipEntry entry		= null;
		//navega entre os registros do contexto, para salvar dentro do ZIP file.
		for(int x = 0; x < intTotalNF; x++){
			wdContext.nodeRetornoXML().moveTo(x);
			
			//destPos = destPos + wdContext.currentRetornoXMLElement().getStringXML().getBytes().length;
			/*try{
				System.arraycopy(wdContext.currentRetornoXMLElement().getStringXML(), 0,
				Content, destPos,wdContext.currentRetornoXMLElement().getStringXML().getBytes().length);
			}catch(Exception e){
				msg_manager.reportWarning("Erro -> " + e);
			}*/
			
			destPos = destPos + wdContext.currentRetornoXMLElement().getStringXML().getBytes().length;
			
			
			String strChave		= wdContext.currentRetornoXMLElement().getChaveXML();
			String strContent	= wdContext.currentRetornoXMLElement().getStringXML();
			
			msg_manager.reportSuccess("Size -> " + destPos);
			msg_manager.reportSuccess("Nome -> " + strChave);
			msg_manager.reportSuccess("Nome -> " + strContent);
			msg_manager.reportSuccess("Size -> " + strContent.getBytes().length);
			
			//try{
				entry = new ZipEntry(strChave + ".xml");
				entry.setSize(strContent.getBytes().length);
				
				zos.putNextEntry(entry);
				zos.write(strContent.getBytes());
				zos.flush();
				zos.finish();
				zos.closeEntry();
				
				msg_manager.reportSuccess("NF " + strChave + ".xml adicionada com sucesso!");
				count = wdContext.nodeRetornoXML().size();
				
				destPos = 0;
				Content = new byte[2048 * count];
				entry = null;
				
			//}catch(Exception e){
			//	msg_manager.reportWarning("Erro -> " + e);
			//}

		}
	//	  Close the zipoutputstream
		zos.close();
	//	  Get the byte array for PO
		out = baos.toByteArray();
	//	  Set the Resource for zip file
		IWDResource resource = WDResourceFactory.createResource(out, "download.zip", WDWebResourceType.UNKNOWN);
	//	  Get the url form resource created
		String url = resource.getUrl(WDFileDownloadBehaviour.AUTO.ordinal());
	//	  Call external window passing the above url
		IWDWindow window = wdComponentAPI.getWindowManager().createNonModalExternalWindow(url,resource.getResourceName());
		//window.setWindowSize(0,0);
		window.show();
		
		} catch (Exception e) {
			msg_manager.reportWarning("-> " + e);
		}

But, when I call this action, just one file was put into my zip file.

What's wrong?!

Thanks in advance.<pre>

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

The problem is solved.

Thanks...