@Test public void shouldExportDocumentAsZip() throws OperationException, IOException { DocumentModel doc = session.createDocumentModel("/", "file", "File"); doc = session.createDocument(doc); ctx.setInput(doc); Map<String, Object> params = new HashMap<>(); params.put("exportAsZip", true); Blob result = (Blob) as.run(ctx, ExportDocument.ID, params); assertNotNull(result); assertEquals("export.zip", result.getFilename()); ZipInputStream zin = new ZipInputStream(result.getStream()); ZipEntry entry = zin.getNextEntry(); int nbDocs = 0; while (entry != null) { if (entry.getName().endsWith(ExportConstants.DOCUMENT_FILE)) { nbDocs++; } entry = zin.getNextEntry(); } assertEquals(1, nbDocs); }
@OperationMethod public Blob run(DocumentModel doc) throws IOException { if (exportAsTree) { exportAsZip = true; } File tempFile = Framework.createTempFilePath(null, null).toFile(); Framework.trackFile(tempFile, tempFile); DocumentReader documentReader = null; DocumentWriter documentWriter = null; try { documentReader = makeDocumentReader(session, doc, exportAsTree, exportAsZip); @SuppressWarnings("resource") FileOutputStream out = new FileOutputStream(tempFile); documentWriter = makeDocumentWriter(out, exportAsTree, exportAsZip); DocumentPipe pipe = makePipe(exportAsTree); pipe.setReader(documentReader); pipe.setWriter(documentWriter); pipe.run(); } finally { if (documentReader != null) { documentReader.close(); } if (documentWriter != null) { documentWriter.close(); } } String filename = exportAsZip ? "export.zip" : "document.xml"; String mimeType = exportAsZip ? "application/zip" : "text/xml"; return Blobs.createBlob(tempFile, mimeType, null, filename); }
ExportDocument { @OperationMethod public Blob run(DocumentModel doc) throws IOException { if (exportAsTree) { exportAsZip = true; } File tempFile = Framework.createTempFilePath(null, null).toFile(); Framework.trackFile(tempFile, tempFile); DocumentReader documentReader = null; DocumentWriter documentWriter = null; try { documentReader = makeDocumentReader(session, doc, exportAsTree, exportAsZip); @SuppressWarnings("resource") FileOutputStream out = new FileOutputStream(tempFile); documentWriter = makeDocumentWriter(out, exportAsTree, exportAsZip); DocumentPipe pipe = makePipe(exportAsTree); pipe.setReader(documentReader); pipe.setWriter(documentWriter); pipe.run(); } finally { if (documentReader != null) { documentReader.close(); } if (documentWriter != null) { documentWriter.close(); } } String filename = exportAsZip ? "export.zip" : "document.xml"; String mimeType = exportAsZip ? "application/zip" : "text/xml"; return Blobs.createBlob(tempFile, mimeType, null, filename); } }
ExportDocument { @OperationMethod public Blob run(DocumentModel doc) throws IOException { if (exportAsTree) { exportAsZip = true; } File tempFile = Framework.createTempFilePath(null, null).toFile(); Framework.trackFile(tempFile, tempFile); DocumentReader documentReader = null; DocumentWriter documentWriter = null; try { documentReader = makeDocumentReader(session, doc, exportAsTree, exportAsZip); @SuppressWarnings("resource") FileOutputStream out = new FileOutputStream(tempFile); documentWriter = makeDocumentWriter(out, exportAsTree, exportAsZip); DocumentPipe pipe = makePipe(exportAsTree); pipe.setReader(documentReader); pipe.setWriter(documentWriter); pipe.run(); } finally { if (documentReader != null) { documentReader.close(); } if (documentWriter != null) { documentWriter.close(); } } String filename = exportAsZip ? "export.zip" : "document.xml"; String mimeType = exportAsZip ? "application/zip" : "text/xml"; return Blobs.createBlob(tempFile, mimeType, null, filename); }  }
ExportDocument { @OperationMethod public Blob run(DocumentModel doc) throws IOException { if (exportAsTree) { exportAsZip = true; } File tempFile = Framework.createTempFilePath(null, null).toFile(); Framework.trackFile(tempFile, tempFile); DocumentReader documentReader = null; DocumentWriter documentWriter = null; try { documentReader = makeDocumentReader(session, doc, exportAsTree, exportAsZip); @SuppressWarnings("resource") FileOutputStream out = new FileOutputStream(tempFile); documentWriter = makeDocumentWriter(out, exportAsTree, exportAsZip); DocumentPipe pipe = makePipe(exportAsTree); pipe.setReader(documentReader); pipe.setWriter(documentWriter); pipe.run(); } finally { if (documentReader != null) { documentReader.close(); } if (documentWriter != null) { documentWriter.close(); } } String filename = exportAsZip ? "export.zip" : "document.xml"; String mimeType = exportAsZip ? "application/zip" : "text/xml"; return Blobs.createBlob(tempFile, mimeType, null, filename); }  @OperationMethod Blob run(DocumentModel doc); }
ExportDocument { @OperationMethod public Blob run(DocumentModel doc) throws IOException { if (exportAsTree) { exportAsZip = true; } File tempFile = Framework.createTempFilePath(null, null).toFile(); Framework.trackFile(tempFile, tempFile); DocumentReader documentReader = null; DocumentWriter documentWriter = null; try { documentReader = makeDocumentReader(session, doc, exportAsTree, exportAsZip); @SuppressWarnings("resource") FileOutputStream out = new FileOutputStream(tempFile); documentWriter = makeDocumentWriter(out, exportAsTree, exportAsZip); DocumentPipe pipe = makePipe(exportAsTree); pipe.setReader(documentReader); pipe.setWriter(documentWriter); pipe.run(); } finally { if (documentReader != null) { documentReader.close(); } if (documentWriter != null) { documentWriter.close(); } } String filename = exportAsZip ? "export.zip" : "document.xml"; String mimeType = exportAsZip ? "application/zip" : "text/xml"; return Blobs.createBlob(tempFile, mimeType, null, filename); }  @OperationMethod Blob run(DocumentModel doc); static final String ID; }