Java Code Examples for org.alfresco.util.TempFileProvider#createTempFile()
The following examples show how to use
org.alfresco.util.TempFileProvider#createTempFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RepositoryExporterComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public FileExportHandle exportSystem(String packageName) { // create a temporary file to hold the system info export File systemTempDir = TempFileProvider.getSystemTempDir(); File tempFile = TempFileProvider.createTempFile("repoExpSystemInfo", ".xml", systemTempDir); try { OutputStream outputStream = new FileOutputStream(tempFile); systemExporterImporter.exportSystem(outputStream); } catch(FileNotFoundException e) { tempFile.delete(); throw new ExporterException("Failed to create temporary file for holding export of system info"); } // return handle onto temp file FileExportHandle handle = new FileExportHandle(); handle.storeRef = null; handle.packageName = packageName; handle.mimeType = MimetypeMap.MIMETYPE_XML; handle.exportFile = tempFile; return handle; }
Example 2
Source File: JodConverterMetadataExtracterWorker.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable { String sourceMimetype = reader.getMimetype(); if (logger.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("Extracting metadata content from ") .append(sourceMimetype); logger.debug(msg.toString()); } // create temporary files to convert from and to File tempFile = TempFileProvider.createTempFile(this.getClass() .getSimpleName() + "-", "." + mimetypeService.getExtension(sourceMimetype)); // download the content from the source reader reader.getContent(tempFile); ResultsCallback callback = new ResultsCallback(); jodc.getOfficeManager().execute(new ExtractMetadataOfficeTask(tempFile, callback)); return callback.getResults(); }
Example 3
Source File: EMLTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a valid eml file to text */ public void testRFC822ToText() throws Exception { File emlSourceFile = loadQuickTestFile("eml"); File txtTargetFile = TempFileProvider.createTempFile("test", ".txt"); ContentReader reader = new FileContentReader(emlSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_RFC822); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); assertTrue(reader2.getContentString().contains(QUICK_EML_CONTENT)); }
Example 4
Source File: OpenOfficeContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * ALF-219. Transforamtion from .html to .pdf for empty file. * @throws Exception */ // The test was never run and fails on remote transformer public void ignoreTestEmptyHtmlToEmptyPdf() throws Exception { if (!isOpenOfficeWorkerAvailable()) { // no connection System.err.println("ooWorker not available - skipping testEmptyHtmlToEmptyPdf !!"); return; } URL url = this.getClass().getClassLoader().getResource("misc/empty.html"); assertNotNull("URL was unexpectedly null", url); File htmlSourceFile = new File(url.getFile()); assertTrue("Test file does not exist.", htmlSourceFile.exists()); File pdfTargetFile = TempFileProvider.createTempFile(getName() + "-target-", ".pdf"); ContentReader reader = new FileContentReader(htmlSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_HTML); ContentWriter writer = new FileContentWriter(pdfTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_PDF); transformer.transform(reader, writer); }
Example 5
Source File: EMLTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a non-ascii eml file to text */ public void testNonAsciiRFC822ToText() throws Exception { File emlSourceFile = loadQuickTestFile("spanish.eml"); File txtTargetFile = TempFileProvider.createTempFile("test2", ".txt"); ContentReader reader = new FileContentReader(emlSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_RFC822); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); String contentStr = reader2.getContentString(); assertTrue(contentStr.contains(QUICK_EML_CONTENT_SPANISH_UNICODE)); }
Example 6
Source File: OpenOfficeContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test what is up with HTML to PDF */ public void testHtmlToPdf() throws Exception { if (!isOpenOfficeWorkerAvailable()) { // no connection System.err.println("ooWorker not available - skipping testHtmlToPdf !!"); return; } File htmlSourceFile = loadQuickTestFile("html"); File pdfTargetFile = TempFileProvider.createTempFile(getName() + "-target-", ".pdf"); ContentReader reader = new FileContentReader(htmlSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_HTML); ContentWriter writer = new FileContentWriter(pdfTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_PDF); transformer.transform(reader, writer); }
Example 7
Source File: EMLTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a valid eml with nested mimetype multipart/alternative to text */ public void testRFC822NestedAlternativeToText() throws Exception { File emlSourceFile = loadQuickTestFile("nested.alternative.eml"); File txtTargetFile = TempFileProvider.createTempFile("test5", ".txt"); ContentReader reader = new FileContentReader(emlSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_RFC822); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); String contentStr = reader2.getContentString(); assertTrue(contentStr.contains(QUICK_EML_NESTED_ALTERNATIVE_CONTENT)); }
Example 8
Source File: MediaWikiContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public void testMediaWikiToHTML() throws Exception { File input = TempFileProvider.createTempFile("mediaWikiTest", ".mw"); FileOutputStream fos = new FileOutputStream(input); fos.write(WIKI_TEXT.getBytes()); fos.close(); File output = TempFileProvider.createTempFile("mediaWikiTest", ".htm"); ContentReader contentReader = new FileContentReader(input); contentReader.setMimetype(MimetypeMap.MIMETYPE_TEXT_MEDIAWIKI); contentReader.setEncoding("UTF-8"); ContentWriter contentWriter = new FileContentWriter(output); contentWriter.setMimetype(MimetypeMap.MIMETYPE_HTML); contentWriter.setEncoding("UTF-8"); transformer.transform(contentReader, contentWriter); String line = null; BufferedReader reader = new BufferedReader(new FileReader(output)); while ((line = reader.readLine()) != null) { System.out.println(line); } }
Example 9
Source File: WarHelperImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private TFile getFile(String extension, String location) { File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension); InputStream is = this.getClass().getClassLoader().getResourceAsStream(location); assertNotNull(is); OutputStream os; try { os = new FileOutputStream(file); FileCopyUtils.copy(is, os); } catch (IOException error) { error.printStackTrace(); } return new TFile(file); }
Example 10
Source File: CustomModelUploadPost.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
protected File createTempFile(InputStream inputStream) { try { File tempFile = TempFileProvider.createTempFile(inputStream, TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX); return tempFile; } catch (Exception ex) { throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "cmm.rest_api.model.import_process_zip_file_failure", ex); } }
Example 11
Source File: RepositoryExporterComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public FileExportHandle exportStore(ExporterCrawlerParameters exportParameters, String packageName, Exporter progress) { // create a temporary file to hold the acp export File systemTempDir = TempFileProvider.getSystemTempDir(); File tempFile = TempFileProvider.createTempFile("repoExp" + packageName, "." + ACPExportPackageHandler.ACP_EXTENSION, systemTempDir); // create acp export handler around the temp file File dataFile = new File(packageName); File contentDir = new File(packageName); try { OutputStream outputStream = new FileOutputStream(tempFile); ACPExportPackageHandler acpHandler = new ACPExportPackageHandler(outputStream, dataFile, contentDir, mimetypeService); // export the store exporterService.exportView(acpHandler, exportParameters, progress); } catch(FileNotFoundException e) { tempFile.delete(); throw new ExporterException("Failed to create temporary file for holding export of store " + exportParameters.getExportFrom().getStoreRef()); } // return handle onto temp file FileExportHandle handle = new FileExportHandle(); handle.storeRef = exportParameters.getExportFrom().getStoreRef(); handle.packageName = packageName; handle.mimeType = MimetypeMap.MIMETYPE_ACP; handle.exportFile = tempFile; return handle; }
Example 12
Source File: WorkflowInstanceDiagramGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { Map<String, String> params = req.getServiceMatch().getTemplateVars(); // getting workflow instance id from request parameters String workflowInstanceId = params.get("workflow_instance_id"); WorkflowInstance workflowInstance = workflowService.getWorkflowById(workflowInstanceId); // workflow instance was not found -> return 404 if (workflowInstance == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find workflow instance with id: " + workflowInstanceId); } // check whether there is a diagram available if (!workflowService.hasWorkflowImage(workflowInstanceId)) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find diagram for workflow instance with id: " + workflowInstanceId); } // copy image data into temporary file File file = TempFileProvider.createTempFile("workflow-diagram-", ".png"); InputStream imageData = workflowService.getWorkflowImage(workflowInstanceId); OutputStream os = new FileOutputStream(file); FileCopyUtils.copy(imageData, os); // stream temporary file back to client streamContent(req, res, file); }
Example 13
Source File: AbstractContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Helper method to load one of the "The quick brown fox" files from the * classpath. * * @param quickname file required, eg <b>quick.txt</b> * @return Returns a test resource loaded from the classpath or <tt>null</tt> if * no resource could be found. * @throws IOException */ public static File loadNamedQuickTestFile(String quickname) throws IOException { String quickNameAndPath = "quick/" + quickname; URL url = AbstractContentTransformerTest.class.getClassLoader().getResource(quickNameAndPath); if (url == null) { return null; } if (ResourceUtils.isJarURL(url)) { if (logger.isDebugEnabled()) { logger.debug("Using a temp file for quick resource that's in a jar." + quickNameAndPath); } try { InputStream is = AbstractContentTransformerTest.class.getClassLoader().getResourceAsStream(quickNameAndPath); File tempFile = TempFileProvider.createTempFile(is, quickname, ".tmp"); return tempFile; } catch (Exception error) { logger.error("Failed to load a quick file from a jar. "+error); return null; } } return ResourceUtils.getFile(url); }
Example 14
Source File: SchemaBootstrap.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private void executeScriptUrl(Connection connection, String scriptUrl) throws Exception { Dialect dialect = this.dialect; String dialectStr = dialect.getClass().getSimpleName(); InputStream scriptInputStream = getScriptInputStream(dialect.getClass(), scriptUrl); // check that it exists if (scriptInputStream == null) { throw AlfrescoRuntimeException.create(ERR_SCRIPT_NOT_FOUND, scriptUrl); } // write the script to a temp location for future and failure reference File tempFile = null; try { tempFile = TempFileProvider.createTempFile("AlfrescoSchema-" + dialectStr + "-Update-", ".sql"); ContentWriter writer = new FileContentWriter(tempFile); writer.putContent(scriptInputStream); } finally { try { scriptInputStream.close(); } catch (Throwable e) {} // usually a duplicate close } // now execute it String dialectScriptUrl = scriptUrl.replaceAll(DialectUtil.PLACEHOLDER_DIALECT, dialect.getClass().getName()); // Replace the script placeholders executeScriptFile(connection, tempFile, dialectScriptUrl); }
Example 15
Source File: CustomModelImportTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private File createZip(ZipEntryContext... zipEntryContexts) { File zipFile = TempFileProvider.createTempFile(getClass().getSimpleName(), ".zip"); tempFiles.add(zipFile); byte[] buffer = new byte[BUFFER_SIZE]; try { OutputStream out = new BufferedOutputStream(new FileOutputStream(zipFile), BUFFER_SIZE); ZipOutputStream zos = new ZipOutputStream(out); for (ZipEntryContext context : zipEntryContexts) { ZipEntry zipEntry = new ZipEntry(context.getZipEntryName()); zos.putNextEntry(zipEntry); InputStream input = context.getEntryContent(); int len; while ((len = input.read(buffer)) > 0) { zos.write(buffer, 0, len); } input.close(); } zos.closeEntry(); zos.close(); } catch (IOException ex) { fail("couldn't create zip file."); } return zipFile; }
Example 16
Source File: ImageMagickContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
protected long transform(String sourceMimetype, String targetMimetype, TransformationOptions options) throws IOException { long size = -1; String[] quickFiles = getQuickFilenames(sourceMimetype); for (String quickFile : quickFiles) { String sourceExtension = quickFile.substring(quickFile.lastIndexOf('.')+1); String targetExtension = mimetypeService.getExtension(targetMimetype); // is there a test file for this conversion? File sourceFile = AbstractContentTransformerTest.loadNamedQuickTestFile(quickFile); if (sourceFile == null) { continue; // no test file available for that extension } ContentReader sourceReader = new FileContentReader(sourceFile); // make a writer for the target file File targetFile = TempFileProvider.createTempFile( getClass().getSimpleName() + "_" + getName() + "_" + sourceExtension + "_", "." + targetExtension); ContentWriter targetWriter = new FileContentWriter(targetFile); // do the transformation sourceReader.setMimetype(sourceMimetype); targetWriter.setMimetype(targetMimetype); transformer.transform(sourceReader.getReader(), targetWriter, options); ContentReader targetReader = targetWriter.getReader(); size = targetReader.getSize(); assertTrue(size > 0); } return size; }
Example 17
Source File: ThumbnailServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private void outputThumbnailTempContentLocation(NodeRef thumbnail, String ext, String message) throws IOException { File tempFile = TempFileProvider.createTempFile("thumbnailServiceImplTest", "." + ext); ContentReader reader = this.contentService.getReader(thumbnail, ContentModel.PROP_CONTENT); reader.getContent(tempFile); System.out.println(message + ": " + tempFile.getPath()); }
Example 18
Source File: StringExtractingContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Generate a large file and then transform it using the text extractor. * We are not creating super-large file (1GB) in order to test the transform * as it takes too long to create the file in the first place. Rather, * this test can be used during profiling to ensure that memory is not * being consumed. */ public void testLargeFileStreaming() throws Exception { File sourceFile = TempFileProvider.createTempFile(getName(), ".txt"); int chars = 1000000; // a million characters should do the trick Random random = new Random(); Writer charWriter = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(sourceFile))); for (int i = 0; i < chars; i++) { char next = (char)(random.nextDouble() * 93D + 32D); charWriter.write(next); } charWriter.close(); // get a reader and a writer ContentReader reader = new FileContentReader(sourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); File outputFile = TempFileProvider.createTempFile(getName(), ".txt"); ContentWriter writer = new FileContentWriter(outputFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); // transform transformer.transform(reader, writer); // delete files sourceFile.delete(); outputFile.delete(); }
Example 19
Source File: ProcessesImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@Override public BinaryResource getProcessImage(String processId) { validateIfUserAllowedToWorkWithProcess(processId); ProcessInstance processInstance = activitiProcessEngine.getRuntimeService() .createProcessInstanceQuery() .processInstanceId(processId) .singleResult(); if (processInstance == null) { throw new EntityNotFoundException(processId); } try { BpmnModel model = activitiProcessEngine.getRepositoryService().getBpmnModel(processInstance.getProcessDefinitionId()); if(model != null && model.getLocationMap().size() > 0) { List<String> activeActivities = activitiProcessEngine.getRuntimeService().getActiveActivityIds(processId); ProcessDiagramGenerator generator = new DefaultProcessDiagramGenerator(); InputStream generateDiagram = generator.generateDiagram(model, "png", activeActivities); File file = TempFileProvider.createTempFile(processId + UUID.randomUUID(), ".png"); FileOutputStream fos = new FileOutputStream(file); IOUtils.copy(generateDiagram, fos); fos.close(); return new FileBinaryResource(file); } else { throw new EntityNotFoundException(processId + "/image"); } } catch (IOException error) { throw new ApiException("Error while getting process image."); } }
Example 20
Source File: StringExtractingContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * @return Returns a new temp file */ private File getTempFile() { return TempFileProvider.createTempFile(getName(), ".txt"); }