@Test public void shouldExportDocumentAsXML() throws OperationException { DocumentModel doc = session.createDocumentModel("/", "file", "File"); doc = session.createDocument(doc); ctx.setInput(doc); Blob result = (Blob) as.run(ctx, ExportDocument.ID); assertNotNull(result); assertEquals("document.xml", result.getFilename()); }
@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; }