本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentReader.getContent方法的典型用法代码示例。如果您正苦于以下问题:Java ContentReader.getContent方法的具体用法?Java ContentReader.getContent怎么用?Java ContentReader.getContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.service.cmr.repository.ContentReader
的用法示例。
在下文中一共展示了ContentReader.getContent方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformInternal
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的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();
}
示例2: put
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
@Override
public boolean put(String contentUrl, ContentReader source)
{
File tempFile = createCacheFile();
// Copy the content from the source into a cache file
if (source.getSize() > 0L)
{
source.getContent(tempFile);
File cacheFile = renameTempToActive(tempFile);
// Add a record of the cached file to the in-memory cache.
recordCacheEntries(contentUrl, cacheFile);
return true;
}
return false;
}
示例3: extractRaw
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的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();
}
示例4: testReadAndWriteStreamByPull
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
@Test
public void testReadAndWriteStreamByPull() throws Exception
{
ContentWriter writer = getWriter();
String content = "ABC";
// put the content using a stream
InputStream is = new ByteArrayInputStream(content.getBytes());
writer.putContent(is);
assertTrue("Stream close not detected", writer.isClosed());
// get the content using a stream
ByteArrayOutputStream os = new ByteArrayOutputStream(100);
ContentReader reader = writer.getReader();
reader.getContent(os);
byte[] bytes = os.toByteArray();
String check = new String(bytes);
assertEquals("Write out and read in using streams failed", content, check);
}
示例5: transform
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的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);
}
示例6: saveContentInFile
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Populates a file with the content in the reader.
*/
public void saveContentInFile(String sourceMimetype, ContentReader reader, File file) throws ContentIOException
{
String encoding = reader.getEncoding();
if (encodeAsUtf8(sourceMimetype, encoding))
{
saveContentInUtf8File(reader, file);
}
else
{
reader.getContent(file);
}
}
示例7: testCreateRenditionThumbnailFromPdfPage2
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public void testCreateRenditionThumbnailFromPdfPage2() throws Exception
{
ImageTransformationOptions options = new ImageTransformationOptions();
PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
pagedSourceOptions.setStartPageNumber(new Integer(2));
pagedSourceOptions.setEndPageNumber(new Integer(2));
options.addSourceOptions(pagedSourceOptions);
ThumbnailDefinition thumbnailDefinition = new ThumbnailDefinition(MimetypeMap.MIMETYPE_PDF, options, "doclib_2");
thumbnailService.getThumbnailRegistry().addThumbnailDefinition(thumbnailDefinition);
checkTransformer();
NodeRef pdfOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_PDF);
NodeRef thumbnail0 = this.thumbnailService.createThumbnail(pdfOrig, ContentModel.PROP_CONTENT,
MimetypeMap.MIMETYPE_IMAGE_JPEG, thumbnailDefinition.getTransformationOptions(), "doclib_2");
assertNotNull(thumbnail0);
checkRenditioned(pdfOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "doclib_2", 1)));
checkRendition("doclib_2", thumbnail0);
// Check the length
File tempFile = TempFileProvider.createTempFile("thumbnailServiceImplTest", ".jpg");
ContentReader reader = this.contentService.getReader(thumbnail0, ContentModel.PROP_CONTENT);
long size = reader.getSize();
System.out.println("size=" + size);
assertTrue("Page 2 should be blank and less than 4500 bytes", size < 4500);
reader.getContent(tempFile);
System.out.println("doclib_2 test: " + tempFile.getPath());
}
示例8: outputThumbnailTempContentLocation
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
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());
}
示例9: testReadAndWriteFile
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的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);
}
示例10: attemptReadContent
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
protected void attemptReadContent(FileInfo realNodeInfo, ContentReader reader) throws IOException
{
if (byteRanges != null && byteRanges.startsWith(RANGE_HEADER_UNIT_SPECIFIER))
{
HttpRangeProcessor rangeProcessor = new HttpRangeProcessor(getContentService());
String userAgent = m_request.getHeader(WebDAV.HEADER_USER_AGENT);
if (m_returnContent)
{
m_davHelper.publishReadEvent(realNodeInfo, reader.getMimetype(), reader.getSize(), byteRanges.substring(6), reader.getEncoding());
rangeProcessor.processRange(
m_response,
reader,
byteRanges.substring(6),
realNodeInfo.getNodeRef(),
ContentModel.PROP_CONTENT,
reader.getMimetype(),
userAgent);
}
}
else
{
if (m_returnContent)
{
// there is content associated with the node
m_response.setHeader(WebDAV.HEADER_CONTENT_LENGTH, Long.toString(reader.getSize()));
m_response.setHeader(WebDAV.HEADER_CONTENT_TYPE, reader.getMimetype());
m_davHelper.publishReadEvent(realNodeInfo, reader.getMimetype(), reader.getSize(), null, reader.getEncoding());
// copy the content to the response output stream
reader.getContent(m_response.getOutputStream());
}
}
}
示例11: transform
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* @see #transformInternal(File, String, File, String, TransformationOptions)
*/
public final void transform(
ContentReader reader,
ContentWriter writer,
TransformationOptions options) throws Exception
{
// get mimetypes
String sourceMimetype = getMimetype(reader);
String targetMimetype = getMimetype(writer);
// get the extensions to use
MimetypeService mimetypeService = getMimetypeService();
String sourceExtension = mimetypeService.getExtension(sourceMimetype);
String targetExtension = mimetypeService.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);
}
// create required temp files
File sourceFile = TempFileProvider.createTempFile(
getClass().getSimpleName() + "_source_",
"." + sourceExtension);
File targetFile = TempFileProvider.createTempFile(
getClass().getSimpleName() + "_target_",
"." + targetExtension);
// pull reader file into source temp file
reader.getContent(sourceFile);
// For most target mimetypes, it only makes sense to read the first page of the
// source, as the target is a single page, so set the pageLimit automatically.
// However for others, such as PDF (see ALF-7278) all pages should be read.
// transform the source temp file to the target temp file
transformInternal(sourceFile, sourceMimetype, targetFile, targetMimetype, options);
// check that the file was created
if (!targetFile.exists() || targetFile.length() == 0)
{
throw new ContentIOException("JMagick transformation failed to write output file");
}
// upload the output image
writer.putContent(targetFile);
// done
if (logger.isDebugEnabled())
{
logger.debug("Transformation completed: \n" +
" source: " + reader + "\n" +
" target: " + writer + "\n" +
" options: " + options);
}
}
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:59,代码来源:AbstractImageMagickContentTransformerWorker.java
示例12: transformInternal
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
@Override
protected void transformInternal(ContentReader reader,
ContentWriter writer,
TransformationOptions options) throws Exception
{
final String sourceMimetype = reader.getMimetype();
final String sourceExtension = getMimetypeService().getExtension(sourceMimetype);
final String targetMimetype = writer.getMimetype();
if (log.isDebugEnabled())
{
StringBuilder msg = new StringBuilder();
msg.append("Transforming from ").append(sourceMimetype)
.append(" to ").append(targetMimetype);
log.debug(msg.toString());
}
OPCPackage pkg = null;
try
{
File ooxmlTempFile = TempFileProvider.createTempFile(this.getClass().getSimpleName() + "_ooxml", sourceExtension);
reader.getContent(ooxmlTempFile);
// Load the file
pkg = OPCPackage.open(ooxmlTempFile.getPath());
// Does it have a thumbnail?
PackageRelationshipCollection rels =
pkg.getRelationshipsByType(PackageRelationshipTypes.THUMBNAIL);
if (rels.size() > 0)
{
// Get the thumbnail part
PackageRelationship tRel = rels.getRelationship(0);
PackagePart tPart = pkg.getPart(tRel);
// Write it to the target
InputStream tStream = tPart.getInputStream();
writer.putContent( tStream );
tStream.close();
}
else
{
log.debug("No thumbnail present in " + reader.toString());
throw new UnimportantTransformException(NO_THUMBNAIL_PRESENT_IN_FILE + targetMimetype);
}
}
catch (IOException e)
{
throw new AlfrescoRuntimeException("Unable to transform " + sourceExtension + " file.", e);
}
finally
{
if (pkg != null)
{
pkg.close();
}
}
}
示例13: transform
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
@Override
public void transform(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception
{
// get mimetypes
String sourceMimetype = getMimetype(reader);
String targetMimetype = getMimetype(writer);
// get the extensions to use
MimetypeService mimetypeService = getMimetypeService();
String sourceExtension = mimetypeService.getExtension(sourceMimetype);
String targetExtension = mimetypeService.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);
}
// create required temp files
File sourceFile = TempFileProvider.createTempFile(getClass().getSimpleName() + "_source_", "." + sourceExtension);
File targetFile = TempFileProvider.createTempFile(getClass().getSimpleName() + "_target_", "." + targetExtension);
// pull reader file into source temp file
reader.getContent(sourceFile);
transformInternal(sourceFile, sourceMimetype, targetFile, targetMimetype, options);
// check that the file was created
if (!targetFile.exists() || targetFile.length() == 0)
{
throw new ContentIOException("alfresco-pdf-renderer transformation failed to write output file");
}
// upload the output image
writer.putContent(targetFile);
// done
if (logger.isDebugEnabled())
{
logger.debug("Transformation completed: \n" +
" source: " + reader + "\n" +
" target: " + writer + "\n" +
" options: " + options);
}
}
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:49,代码来源:AlfrescoPdfRendererContentTransformerWorker.java