本文整理汇总了Java中org.alfresco.util.TempFileProvider类的典型用法代码示例。如果您正苦于以下问题:Java TempFileProvider类的具体用法?Java TempFileProvider怎么用?Java TempFileProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TempFileProvider类属于org.alfresco.util包,在下文中一共展示了TempFileProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformTextAndCheck
import org.alfresco.util.TempFileProvider; //导入依赖的package包/类
private void transformTextAndCheck(String text, String encoding, String checkText)
throws IOException
{
// Get a reader for the text
ContentReader reader = buildContentReader(text, Charset.forName(encoding));
// And a temp writer
File out = TempFileProvider.createTempFile("AlfrescoTest_", ".pdf");
ContentWriter writer = new FileContentWriter(out);
writer.setMimetype("application/pdf");
// Transform to PDF
transformer.transform(reader, writer);
// Read back in the PDF and check it
PDDocument doc = PDDocument.load(out);
PDFTextStripper textStripper = new PDFTextStripper();
StringWriter textWriter = new StringWriter();
textStripper.writeText(doc, textWriter);
doc.close();
String roundTrip = clean(textWriter.toString());
assertEquals(
"Incorrect text in PDF when starting from text in " + encoding,
checkText, roundTrip
);
}
示例2: testHtmlSpecialCharsToText
import org.alfresco.util.TempFileProvider; //导入依赖的package包/类
/**
* Test transforming a valid eml with a html part containing html special characters to text
*/
public void testHtmlSpecialCharsToText() throws Exception
{
File emlSourceFile = loadQuickTestFile("htmlChars.eml");
File txtTargetFile = TempFileProvider.createTempFile("test6", ".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(HTML_SPACE_SPECIAL_CHAR));
}
示例3: LinkNodeFileExtensionHelper
import org.alfresco.util.TempFileProvider; //导入依赖的package包/类
private LinkNodeFileExtensionHelper() throws IOException
{
// Open a log file
File tempDir = TempFileProvider.getLongLifeTempDir("patches");
logFile = new File(tempDir, "LinkNodeExtensionPatch.log");
RandomAccessFile outputFile = new RandomAccessFile(logFile, "rw");
channel = outputFile.getChannel();
// Append to the end of the file
channel.position(channel.size());
writeLine("").writeLine("");
writeLine("LinkNodeExtensionPatch executing on " + new Date());
}
示例4: exportSystem
import org.alfresco.util.TempFileProvider; //导入依赖的package包/类
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;
}
示例5: createDownload
import org.alfresco.util.TempFileProvider; //导入依赖的package包/类
private void createDownload(final NodeRef actionedUponNodeRef, ExporterCrawlerParameters crawlerParameters, SizeEstimator estimator)
{
// perform the actual export
final File tempFile = TempFileProvider.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX);
final ZipDownloadExporter handler = new ZipDownloadExporter(tempFile, checkOutCheckInService, nodeService, transactionHelper, updateService, downloadStorage, actionedUponNodeRef, estimator.getSize(), estimator.getFileCount());
try {
exporterService.exportView(handler, crawlerParameters, null);
archiveCreationComplete(actionedUponNodeRef, tempFile, handler);
}
catch (DownloadCancelledException ex)
{
downloadCancelled(actionedUponNodeRef, handler);
}
finally
{
tempFile.delete();
}
}
示例6: transformInternal
import org.alfresco.util.TempFileProvider; //导入依赖的package包/类
public void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options)
throws Exception
{
// We can only work from a file
File htmlFile = TempFileProvider.createTempFile("HtmlParserContentTransformer_", ".html");
reader.getContent(htmlFile);
// Fetch the encoding of the HTML, as set in the ContentReader
// This will default to 'UTF-8' if not specifically set
String encoding = reader.getEncoding();
// Create the extractor
EncodingAwareStringBean extractor = new EncodingAwareStringBean();
extractor.setCollapse(false);
extractor.setLinks(false);
extractor.setReplaceNonBreakingSpaces(false);
extractor.setURL(htmlFile, encoding);
// get the text
String text = extractor.getStrings();
// write it to the writer
writer.putContent(text);
// Tidy up
htmlFile.delete();
}
示例7: extractRaw
import org.alfresco.util.TempFileProvider; //导入依赖的package包/类
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();
}
示例8: init
import org.alfresco.util.TempFileProvider; //导入依赖的package包/类
/**
* Service initialise
*/
public void init()
{
// Set up a temporary store
this.tempStore = new FileContentStore(this.applicationContext, TempFileProvider.getTempDir().getAbsolutePath());
// Bind on update properties behaviour
this.policyComponent.bindClassBehaviour(
NodeServicePolicies.OnUpdatePropertiesPolicy.QNAME,
this,
new JavaBehaviour(this, "onUpdateProperties"));
// Register on content update policy
this.onContentUpdateDelegate = this.policyComponent.registerClassPolicy(OnContentUpdatePolicy.class);
this.onContentPropertyUpdateDelegate = this.policyComponent.registerClassPolicy(OnContentPropertyUpdatePolicy.class);
this.onContentReadDelegate = this.policyComponent.registerClassPolicy(OnContentReadPolicy.class);
}
示例9: dumpSchema
import org.alfresco.util.TempFileProvider; //导入依赖的package包/类
/**
* Dumps the DB schema to temporary file(s), named similarly to:
* <pre>
* Alfresco-schema-DialectName-whenDumped-dbPrefix-23498732.xml
* </pre>
* Where the digits serve to create a unique temp file name. If whenDumped is empty or null,
* then the output is similar to:
* <pre>
* Alfresco-schema-DialectName-dbPrefix-23498732.xml
* </pre>
* If dbPrefixes is null, then the default list is used (see {@link MultiFileDumper#DEFAULT_PREFIXES})
* The dump files' paths are logged at info level.
*
* @param whenDumped String
* @param dbPrefixes Array of database object prefixes to filter by, e.g. "alf_"
* @return List of output files.
*/
private List<File> dumpSchema(String whenDumped, String[] dbPrefixes)
{
// Build a string to use as the file name template,
// e.g. "Alfresco-schema-MySQLDialect-pre-upgrade-{0}-"
StringBuilder sb = new StringBuilder(64);
sb.append("Alfresco-schema-").
append(dialect.getClass().getSimpleName());
if (whenDumped != null && whenDumped.length() > 0)
{
sb.append("-");
sb.append(whenDumped);
}
sb.append("-{0}-");
File outputDir = TempFileProvider.getTempDir();
String fileNameTemplate = sb.toString();
return dumpSchema(outputDir, fileNameTemplate, dbPrefixes);
}
示例10: dumpFiles
import org.alfresco.util.TempFileProvider; //导入依赖的package包/类
public List<File> dumpFiles()
{
List<File> files = new ArrayList<File>(dbPrefixes.length);
for (String dbPrefix : dbPrefixes)
{
String fileNamePrefix = getFileNamePrefix(dbPrefix);
File outputFile = TempFileProvider.createTempFile(fileNamePrefix, fileNameSuffix, directory);
files.add(outputFile);
DbToXML dbToXML = dbToXMLFactory.create(outputFile, dbPrefix);
dbToXML.setDbSchemaName(defaultSchemaName);
dbToXML.execute();
}
return files;
}
示例11: copyToTempFile
import org.alfresco.util.TempFileProvider; //导入依赖的package包/类
private File copyToTempFile(ContentStream contentStream)
{
if (contentStream == null)
{
return null;
}
File result = null;
try
{
result = TempFileProvider.createTempFile(contentStream.getStream(), "cmis", "content");
}
catch (Exception e)
{
throw new CmisStorageException("Unable to store content: " + e.getMessage(), e);
}
if ((contentStream.getLength() > -1) && (result == null || contentStream.getLength() != result.length()))
{
removeTempFile(result);
throw new CmisStorageException("Expected " + contentStream.getLength() + " bytes but retrieved " +
(result == null ? -1 :result.length()) + " bytes!");
}
return result;
}
示例12: createTextFile
import org.alfresco.util.TempFileProvider; //导入依赖的package包/类
protected Document createTextFile(String parentId, String fileName, String textContent, String encoding, Map<String, String> props, int expectedStatus) throws IOException, Exception
{
if (props == null)
{
props = Collections.EMPTY_MAP;
}
ByteArrayInputStream inputStream = new ByteArrayInputStream(textContent.getBytes());
File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt");
MultiPartBuilder.MultiPartRequest reqBody = MultiPartBuilder.create()
.setFileData(new MultiPartBuilder.FileData(fileName, txtFile))
.setProperties(props)
.build();
HttpResponse response = post(getNodeChildrenUrl(parentId), reqBody.getBody(), null, reqBody.getContentType(), expectedStatus);
if (response.getJsonResponse().get("error") != null)
{
return null;
}
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
}
示例13: extractToDir
import org.alfresco.util.TempFileProvider; //导入依赖的package包/类
private String extractToDir(String extension, String location)
{
File tmpDir = TempFileProvider.getTempDir();
try {
TFile zipFile = new TFile(this.getClass().getClassLoader().getResource(location).getPath());
TFile outDir = new TFile(tmpDir.getAbsolutePath()+"/moduleManagementToolTestDir"+System.currentTimeMillis());
outDir.mkdir();
zipFile.cp_rp(outDir);
TVFS.umount(zipFile);
return outDir.getPath();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例14: getFile
import org.alfresco.util.TempFileProvider; //导入依赖的package包/类
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);
}
示例15: 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;
}