本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentReader.setMimetype方法的典型用法代码示例。如果您正苦于以下问题:Java ContentReader.setMimetype方法的具体用法?Java ContentReader.setMimetype怎么用?Java ContentReader.setMimetype使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.service.cmr.repository.ContentReader
的用法示例。
在下文中一共展示了ContentReader.setMimetype方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHtmlSpecialCharsToText
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的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));
}
示例2: testNonAsciiRFC822ToText
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* 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));
}
示例3: openAndCheck
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
private Map<String, Serializable> openAndCheck(String fileBase, String expMimeType) throws Throwable {
// Get the mimetype via the MimeTypeMap
// (Uses Tika internally for the detection)
File file = open(fileBase);
ContentReader detectReader = new FileContentReader(file);
String mimetype = mimetypeMap.guessMimetype(fileBase, detectReader);
assertEquals("Wrong mimetype for " + fileBase, mimetype, expMimeType);
// Ensure the Tika Auto parser actually handles this
assertTrue("Mimetype should be supported but isn't: " + mimetype, extracter.isSupported(mimetype));
// Now create our proper reader
ContentReader sourceReader = new FileContentReader(file);
sourceReader.setMimetype(mimetype);
// And finally do the properties extraction
return extracter.extractRaw(sourceReader);
}
示例4: testFootnotesLimitParameterUsingDefault
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Test for MNT-577: Alfresco is running 100% CPU for over 10 minutes while extracting metadata for Word office document
*
* @throws Exception
*/
public void testFootnotesLimitParameterUsingDefault() throws Exception
{
PoiMetadataExtracter extractor = (PoiMetadataExtracter) getExtracter();
File sourceFile = AbstractContentTransformerTest.loadNamedQuickTestFile(PROBLEM_FOOTNOTES_DOCUMENT_NAME);
ContentReader sourceReader = new FileContentReader(sourceFile);
sourceReader.setMimetype(MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING);
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
long startTime = System.currentTimeMillis();
extractor.extract(sourceReader, properties);
extractionTimeWithDefaultFootnotesLimit = System.currentTimeMillis() - startTime;
assertExtractedProperties(properties);
if (extractionTimeWithLargeFootnotesLimit != null)
{
assertTrue("The second metadata extraction operation must be longer!", extractionTimeWithLargeFootnotesLimit > extractionTimeWithDefaultFootnotesLimit);
}
}
示例5: buildContentReader
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Writes the supplied text out to a temporary file, and opens
* a content reader onto it.
*/
protected static ContentReader buildContentReader(String text, Charset encoding)
throws IOException
{
File tmpFile = TempFileProvider.createTempFile("AlfrescoTest_", ".txt");
FileOutputStream out = new FileOutputStream(tmpFile);
OutputStreamWriter wout = new OutputStreamWriter(out, encoding);
wout.write(text);
wout.close();
out.close();
ContentReader reader = new FileContentReader(tmpFile);
reader.setEncoding(encoding.displayName());
reader.setMimetype("text/plain");
return reader;
}
示例6: testCsvOutput
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public void testCsvOutput() throws Exception
{
File sourceFile = AbstractContentTransformerTest.loadQuickTestFile("xls");
ContentReader sourceReader = new FileContentReader(sourceFile);
File targetFile = TempFileProvider.createTempFile(
getClass().getSimpleName() + "_" + getName() + "_xls_",
".csv");
ContentWriter targetWriter = new FileContentWriter(targetFile);
sourceReader.setMimetype(MimetypeMap.MIMETYPE_EXCEL);
targetWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_CSV);
transformer.transform(sourceReader, targetWriter);
ContentReader targetReader = targetWriter.getReader();
String checkContent = targetReader.getContentString();
additionalContentCheck(
MimetypeMap.MIMETYPE_EXCEL,
MimetypeMap.MIMETYPE_TEXT_CSV,
checkContent
);
}
示例7: testHtmlToPdf
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的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);
}
示例8: testEmptyHtmlToEmptyPdf
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的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);
}
示例9: testFootnotesLimitParameterUsingLarge
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Test for MNT-577: Alfresco is running 100% CPU for over 10 minutes while extracting metadata for Word office document
*
* @throws Exception
*/
public void testFootnotesLimitParameterUsingLarge() throws Exception
{
PoiMetadataExtracter extractor = (PoiMetadataExtracter) getExtracter();
File sourceFile = AbstractContentTransformerTest.loadNamedQuickTestFile(PROBLEM_FOOTNOTES_DOCUMENT_NAME);
ContentReader sourceReader = new FileContentReader(sourceFile);
sourceReader.setMimetype(MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING);
// Just let the extractor do the job...
extractor.setPoiFootnotesLimit(LARGE_FOOTNOTES_LIMIT);
extractor.afterPropertiesSet();
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
long startTime = System.currentTimeMillis();
extractor.extract(sourceReader, properties);
extractionTimeWithLargeFootnotesLimit = System.currentTimeMillis() - startTime;
assertExtractedProperties(properties);
if (extractionTimeWithDefaultFootnotesLimit != null)
{
assertTrue("The second metadata extraction operation must be longer!", extractionTimeWithLargeFootnotesLimit > extractionTimeWithDefaultFootnotesLimit);
}
}
示例10: testUnicodeMsgToText
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Test transforming a valid unicode msg file to text
*/
public void testUnicodeMsgToText() throws Exception
{
File msgSourceFile = loadQuickTestFile("unicode.msg");
File txtTargetFile = TempFileProvider.createTempFile(getName() + "-target-2", ".txt");
ContentReader reader = new FileContentReader(msgSourceFile);
reader.setMimetype(MimetypeMap.MIMETYPE_OUTLOOK_MSG);
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_CONTENT));
}
示例11: testNonUnicodeChineseMsgToText
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Test transforming a chinese non-unicode msg file to
* text
*/
public void testNonUnicodeChineseMsgToText() throws Exception
{
File msgSourceFile = loadQuickTestFile("chinese.msg");
File txtTargetFile = TempFileProvider.createTempFile(getName() + "-target-2", ".txt");
ContentReader reader = new FileContentReader(msgSourceFile);
reader.setMimetype(MimetypeMap.MIMETYPE_OUTLOOK_MSG);
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);
// Check the quick text
String text = reader2.getContentString();
assertTrue(text.contains(QUICK_CONTENT));
// Now check the non quick parts came out ok
assertTrue(text.contains("(\u5f35\u6bd3\u502b)"));
assertTrue(text.contains("\u683c\u5f0f\u6e2c\u8a66 )"));
}
示例12: testRFC822ToText
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* 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));
}
示例13: getReader
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Performs checks and copies required reader attributes
*/
public final ContentReader getReader() throws ContentIOException
{
String contentUrl = getContentUrl();
if (!isClosed())
{
return new EmptyContentReader(contentUrl);
}
ContentReader reader = createReader();
if (reader == null)
{
throw new AlfrescoRuntimeException("ContentReader failed to create new reader: \n" +
" writer: " + this);
}
else if (reader.getContentUrl() == null || !reader.getContentUrl().equals(contentUrl))
{
throw new AlfrescoRuntimeException("ContentReader has different URL: \n" +
" writer: " + this + "\n" +
" new reader: " + reader);
}
// copy across common attributes
reader.setMimetype(this.getMimetype());
reader.setEncoding(this.getEncoding());
reader.setLocale(this.getLocale());
// done
if (logger.isDebugEnabled())
{
logger.debug("Writer spawned new reader: \n" +
" writer: " + this + "\n" +
" new reader: " + reader);
}
return reader;
}
示例14: extractFromFile
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
protected Map<QName, Serializable> extractFromFile(File sourceFile, String mimetype) throws Exception
{
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
// construct a reader onto the source file
ContentReader sourceReader = new FileContentReader(sourceFile);
sourceReader.setMimetype(mimetype);
getExtracter().extract(sourceReader, properties);
return properties;
}
示例15: testExcelToPdfConversion
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public void testExcelToPdfConversion() throws Exception
{
String[] quickFiles = getQuickFilenames(sourceMimeType);
for (String quickFile : quickFiles)
{
String sourceExtension = quickFile.substring(quickFile.lastIndexOf('.') + 1);
// 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 + "_", ".pdf");
ContentWriter targetWriter = new FileContentWriter(targetFile);
// do the transformation
sourceReader.setMimetype(sourceMimeType);
targetWriter.setMimetype(targetMimeType);
try
{
transformer.transform(sourceReader.getReader(), targetWriter);
}
catch (ContentIOException e)
{
// all transformers expected to fail for password protected MS office document
}
if (transformer.getTriggered().getValue())
{
org.junit.Assert.fail("final AbstractContentTransformer2.transform was called for html2pdf");
}
}
}