本文整理汇总了Java中org.alfresco.util.TempFileProvider.createTempFile方法的典型用法代码示例。如果您正苦于以下问题:Java TempFileProvider.createTempFile方法的具体用法?Java TempFileProvider.createTempFile怎么用?Java TempFileProvider.createTempFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.util.TempFileProvider
的用法示例。
在下文中一共展示了TempFileProvider.createTempFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exportContent
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
/**
* @param nodeRef nodeRef
* @return File
* @throws FileNotFoundException
* @throws IOException
*/
private File exportContent(NodeRef nodeRef)
throws FileNotFoundException, IOException
{
TestProgress testProgress = new TestProgress();
Location location = new Location(nodeRef);
ExporterCrawlerParameters parameters = new ExporterCrawlerParameters();
parameters.setExportFrom(location);
File acpFile = TempFileProvider.createTempFile("category-export-test", ACPExportPackageHandler.ACP_EXTENSION);
System.out.println("Exporting to file: " + acpFile.getAbsolutePath());
File dataFile = new File("test-data-file");
File contentDir = new File("test-content-dir");
OutputStream fos = new FileOutputStream(acpFile);
ACPExportPackageHandler acpHandler = new ACPExportPackageHandler(fos, dataFile, contentDir, null);
acpHandler.setNodeService(nodeService);
acpHandler.setExportAsFolders(true);
exporterService.exportView(acpHandler, parameters, testProgress);
fos.close();
return acpFile;
}
示例2: testHtmlToPdf
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
/**
* 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);
}
示例3: transform
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
@Override
public void transform(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception {
String sourceMimetype = getMimetype(reader);
String targetMimetype = getMimetype(writer);
String sourceExtension = getMimetypeService().getExtension(sourceMimetype);
String targetExtension = getMimetypeService().getExtension(targetMimetype);
if (sourceExtension == null || targetExtension == null)
{
throw new AlfrescoRuntimeException("Unknown extensions for mimetypes: \n" +
" source mimetype: " + sourceMimetype + "\n" +
" source extension: " + sourceExtension + "\n" +
" target mimetype: " + targetMimetype + "\n" +
" target extension: " + targetExtension);
}
File sourceFile = TempFileProvider.createTempFile(getClass().getSimpleName() + "_source_", "." + sourceExtension);
File targetFile = TempFileProvider.createTempFile(getClass().getSimpleName() + "_target_", "." + targetExtension);
reader.getContent(sourceFile);
convertToPDF(sourceFile, targetFile);
writer.putContent(targetFile);
}
示例4: testEmptyHtmlToEmptyPdf
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
/**
* ALF-219. Transforamtion from .html to .pdf for empty file.
* @throws Exception
*/
public void testEmptyHtmlToEmptyPdf() 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);
}
示例5: testMissingContent
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
/**
* Checks what happens when the physical content disappears
*/
public void testMissingContent() throws Exception
{
File tempFile = TempFileProvider.createTempFile(getName(), ".txt");
ContentWriter writer = new FileContentWriter(tempFile);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent("What about the others? Buckwheats!");
// check
assertTrue("File does not exist", tempFile.exists());
assertTrue("File not written to", tempFile.length() > 0);
// update the node with this new info
ContentData contentData = writer.getContentData();
nodeService.setProperty(contentNodeRef, ContentModel.PROP_CONTENT, contentData);
// delete the content
tempFile.delete();
assertFalse("File not deleted", tempFile.exists());
// now attempt to get the reader for the node
ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT);
assertFalse("Reader should indicate that content is missing", reader.exists());
// check the indexing doesn't spank everthing
txn.commit();
txn = null;
// cleanup
txn = getUserTransaction();
txn.begin();
nodeService.deleteNode(contentNodeRef);
txn.commit();
txn = null;
}
示例6: readProperty
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
@WebApiDescription(title = "Download content", description = "Download content")
@BinaryProperties({"content"})
public BinaryResource readProperty(String herdId, String entityResourceId, Parameters parameters) throws EntityNotFoundException
{
File file = TempFileProvider.createTempFile("Its a goat", ".txt");
return new FileBinaryResource(file);
}
示例7: processPart
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
/**
* Finds text on a given mail part. Accepted parts types are text/html and text/plain.
* Attachments are ignored
*
* @param part
* @param sb
* @throws IOException
* @throws MessagingException
*/
private void processPart(Part part, StringBuilder sb) throws IOException, MessagingException
{
boolean isAttachment = Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition());
if (isAttachment)
{
return;
}
if (part.getContentType().contains(MimetypeMap.MIMETYPE_TEXT_PLAIN))
{
sb.append(part.getContent().toString());
}
else if (part.getContentType().contains(MimetypeMap.MIMETYPE_HTML))
{
String mailPartContent = part.getContent().toString();
//create a temporary html file with same mail part content and encoding
File tempHtmlFile = TempFileProvider.createTempFile("EMLTransformer_", ".html");
ContentWriter contentWriter = new FileContentWriter(tempHtmlFile);
contentWriter.setEncoding(getMailPartContentEncoding(part));
contentWriter.setMimetype(MimetypeMap.MIMETYPE_HTML);
contentWriter.putContent(mailPartContent);
//transform html file's content to plain text
EncodingAwareStringBean extractor = new EncodingAwareStringBean();
extractor.setCollapse(false);
extractor.setLinks(false);
extractor.setReplaceNonBreakingSpaces(false);
extractor.setURL(tempHtmlFile, contentWriter.getEncoding());
sb.append(extractor.getStrings());
tempHtmlFile.delete();
}
}
示例8: createZip
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
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;
}
示例9: loadNamedQuickTestFile
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
/**
* 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);
}
示例10: testReadAndWriteFile
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
@Test
public void testReadAndWriteFile() throws Exception
{
ContentWriter writer = getWriter();
File sourceFile = TempFileProvider.createTempFile("testReadAndWriteFile", ".txt");
sourceFile.deleteOnExit();
// dump some content into the temp file
String content = "ABC";
FileOutputStream os = new FileOutputStream(sourceFile);
os.write(content.getBytes());
os.flush();
os.close();
// put our temp file's content
writer.putContent(sourceFile);
assertTrue("Stream close not detected", writer.isClosed());
// create a sink temp file
File sinkFile = TempFileProvider.createTempFile("testReadAndWriteFile", ".txt");
sinkFile.deleteOnExit();
// get the content into our temp file
ContentReader reader = writer.getReader();
reader.getContent(sinkFile);
// read the sink file manually
FileInputStream is = new FileInputStream(sinkFile);
byte[] buffer = new byte[100];
int count = is.read(buffer);
assertEquals("No content read", 3, count);
is.close();
String check = new String(buffer, 0, count);
assertEquals("Write out of and read into files failed", content, check);
}
示例11: executeScriptUrl
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
private void executeScriptUrl(Configuration cfg, Connection connection, String scriptUrl) throws Exception
{
Dialect dialect = Dialect.getDialect(cfg.getProperties());
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(PLACEHOLDER_DIALECT, dialect.getClass().getName());
// Replace the script placeholders
executeScriptFile(cfg, connection, tempFile, dialectScriptUrl);
}
示例12: testNotZipFileUpload
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
public void testNotZipFileUpload() throws Exception
{
File file = getResourceFile("validModel.zip");
ZipFile zipFile = new ZipFile(file);
ZipEntry zipEntry = zipFile.entries().nextElement();
File unzippedModelFile = TempFileProvider.createTempFile(zipFile.getInputStream(zipEntry), "validModel", ".xml");
tempFiles.add(unzippedModelFile);
zipFile.close();
PostRequest postRequest = buildMultipartPostRequest(unzippedModelFile);
sendRequest(postRequest, 400); // CMM upload supports only zip file.
}
示例13: testMNT12504
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
public void testMNT12504() throws Exception
{
String testUser = "testUserMnt12504";
StoreRef storeRef = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
NodeRef rootNode = nodeService.getRootNode(storeRef);
// Create folder and two documents
NodeRef folder = fileFolderService.create(rootNode, getClass().getName() + "testMNT12504" + GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
NodeRef docA = nodeService.createNode(folder, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_CONTENT,
Collections.singletonMap(ContentModel.PROP_NAME, (Serializable) "docA.txt")).getChildRef();
NodeRef docB = nodeService.createNode(folder, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_CONTENT,
Collections.singletonMap(ContentModel.PROP_NAME, (Serializable) "docB.txt")).getChildRef();
// Add association between docA and docB
nodeService.createAssociation(docA, docB, ContentModel.ASSOC_REFERENCES);
// Set read permissions for user1 on folder and docA. docB should be set to false
permissionService.setPermission(folder, testUser, PermissionService.READ, true);
permissionService.setInheritParentPermissions(folder, false);
permissionService.setPermission(docA, testUser, PermissionService.READ, true);
permissionService.setPermission(docB, testUser, PermissionService.READ, false);
if (!authenticationService.authenticationExists(testUser))
{
this.authenticationService.createAuthentication(testUser, testUser.toCharArray());
}
this.authenticationComponent.authenticate(testUser, testUser.toCharArray());
// Check that test goes as expect
assertTrue(this.authenticationComponent.getCurrentUserName().equals(testUser));
assertTrue(permissionService.hasPermission(folder, PermissionService.READ).equals(AccessStatus.ALLOWED));
assertTrue(permissionService.hasPermission(docA, PermissionService.READ).equals(AccessStatus.ALLOWED));
assertTrue(permissionService.hasPermission(docB, PermissionService.READ).equals(AccessStatus.DENIED));
ExporterCrawlerParameters crawlerParameters = new ExporterCrawlerParameters();
crawlerParameters.setExportFrom(new Location(folder));
crawlerParameters.setCrawlSelf(true);
crawlerParameters.setExcludeAspects(new QName[] { ContentModel.ASPECT_WORKING_COPY });
File acpFile = TempFileProvider.createTempFile("alf", ACPExportPackageHandler.ACP_EXTENSION);
ACPExportPackageHandler acpHandler = new ACPExportPackageHandler(new FileOutputStream(acpFile), new File("test"), new File("test"), null);
acpHandler.setNodeService(nodeService);
acpHandler.setExportAsFolders(true);
// Check that fix works as expect
boolean isFixed = true;
try
{
exporterService.exportView(acpHandler, crawlerParameters, null);
}
catch (AccessDeniedException e)
{
isFixed = false;
}
finally
{
this.authenticationComponent.setSystemUserAsCurrentUser();
nodeService.deleteNode(folder);
}
assertTrue("The MNT12504 is reproduced.", isFixed);
}
示例14: tempfile
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
private File tempfile(String name, String suffix)
{
File file = TempFileProvider.createTempFile(name, suffix);
file.deleteOnExit();
return file;
}
示例15: createRequisiteFile
import org.alfresco.util.TempFileProvider; //导入方法依赖的package包/类
private File createRequisiteFile()
{
File tempDir = TempFileProvider.getLongLifeTempDir(FILE_DIRECTORY);
File reqFile = TempFileProvider.createTempFile("TRX-REQ", FILE_SUFFIX, tempDir);
return reqFile;
}