本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentReader.getMimetype方法的典型用法代码示例。如果您正苦于以下问题:Java ContentReader.getMimetype方法的具体用法?Java ContentReader.getMimetype怎么用?Java ContentReader.getMimetype使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.service.cmr.repository.ContentReader
的用法示例。
在下文中一共展示了ContentReader.getMimetype方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
@Override
protected void render(RenderingContext context)
{
ContentReader contentReader = context.makeContentReader();
String sourceMimeType = contentReader.getMimetype();
// Check that Tika supports the supplied file
AutoDetectParser p = new AutoDetectParser(tikaConfig);
MediaType sourceMediaType = MediaType.parse(sourceMimeType);
if(! p.getParsers().containsKey(sourceMediaType))
{
throw new RenditionServiceException(
"Source mime type of " + sourceMimeType +
" is not supported by Tika for HTML conversions"
);
}
// Make the HTML Version using Tika
// This will also extract out any images as found
generateHTML(p, context);
}
示例2: strictMimetypeCheck
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
private void strictMimetypeCheck(ContentReader reader, TransformationOptions options, String sourceMimetype)
throws UnsupportedTransformationException
{
if (strictMimeTypeCheck && depth.get() == 1)
{
String differentType = getMimetypeService().getMimetypeIfNotMatches(reader.getReader());
if (!transformerConfig.strictMimetypeCheck(sourceMimetype, differentType))
{
String fileName = transformerDebug.getFileName(options, true, 0);
String readerSourceMimetype = reader.getMimetype();
String message = "Transformation of ("+fileName+
") has not taken place because the declared mimetype ("+
readerSourceMimetype+") does not match the detected mimetype ("+
differentType+").";
logger.warn(message);
throw new UnsupportedTransformationException(message);
}
}
}
示例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: guessMimetype
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Guess the mimetype for the given filename - uses the extension to match on system mimetype map
*/
public void guessMimetype(String filename)
{
ContentService contentService = services.getContentService();
ContentReader reader = contentService.getReader(nodeRef, property);
// MNT-12265 Browser sets a mimetype based on extension of file. But mimeType from browser can be
// different as mapped in Alfresco for current extension. Therefore we need to guess a mimetype based on
// map in Alfresco
String typeByExt = services.getMimetypeService().guessMimetype(filename);
if (reader != null && reader.getMimetype() != null && !typeByExt.equals(MimetypeMap.MIMETYPE_BINARY))
{
setMimetype(typeByExt);
}
else
{
setMimetype(services.getMimetypeService().guessMimetype(filename, reader));
}
}
示例5: guessMimetype
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Uses Tika to try to identify the mimetype of the file, falling back on
* {@link #guessMimetype(String)} for an extension based one if Tika can't
* help.
*/
public String guessMimetype(String filename, ContentReader reader)
{
// ALF-10813: MimetypeMap.guessMimetype consumes 30% of file upload time
// Let's only 'guess' if we need to
if (reader != null && reader.getMimetype() != null && !reader.getMimetype().equals(MimetypeMap.MIMETYPE_BINARY))
{
// It was set to something other than the default.
// Possibly someone used this method before (like the UI does) or
// they just
// know what their files are.
return reader.getMimetype();
}
InputStream input = (reader != null ? reader.getContentInputStream() : null);
return guessMimetype(filename, input);
}
示例6: checkIsSupported
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* Checks if the mimetype is supported.
*
* @param reader the reader to check
* @throws AlfrescoRuntimeException if the mimetype is not supported
*/
protected void checkIsSupported(ContentReader reader)
{
String mimetype = reader.getMimetype();
if (!isSupported(mimetype))
{
throw new AlfrescoRuntimeException(
"Metadata extracter does not support mimetype: " + mimetype + "\n" +
" reader: " + reader + "\n" +
" supported: " + supportedMimetypes + "\n" +
" extracter: " + this);
}
}
示例7: isTransformable
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* @see org.alfresco.service.cmr.repository.ContentService#isTransformable(org.alfresco.service.cmr.repository.ContentReader, org.alfresco.service.cmr.repository.ContentWriter, org.alfresco.service.cmr.repository.TransformationOptions)
*/
public boolean isTransformable(ContentReader reader, ContentWriter writer, TransformationOptions options)
{
// check that source and target mimetypes are available
String sourceMimetype = reader.getMimetype();
if (sourceMimetype == null)
{
throw new AlfrescoRuntimeException("The content reader mimetype must be set: " + reader);
}
String targetMimetype = writer.getMimetype();
if (targetMimetype == null)
{
throw new AlfrescoRuntimeException("The content writer mimetype must be set: " + writer);
}
long sourceSize = reader.getSize();
try
{
// look for a transformer
transformerDebug.pushAvailable(reader.getContentUrl(), sourceMimetype, targetMimetype, options);
List<ContentTransformer> transformers = getActiveTransformers(sourceMimetype, sourceSize, targetMimetype, options);
transformerDebug.availableTransformers(transformers, sourceSize, options, "ContentService.isTransformable(...)");
return transformers.size() > 0;
}
finally
{
transformerDebug.popAvailable();
}
}
示例8: streamContentImpl
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
protected void streamContentImpl(WebScriptRequest req, WebScriptResponse res,
ContentReader reader, NodeRef nodeRef, QName propertyQName,
boolean attach, Date modified, String eTag, String attachFileName)
throws IOException
{
delegate.setAttachment(req, res, attach, attachFileName);
// establish mimetype
String mimetype = reader.getMimetype();
String extensionPath = req.getExtensionPath();
if (mimetype == null || mimetype.length() == 0)
{
mimetype = MimetypeMap.MIMETYPE_BINARY;
int extIndex = extensionPath.lastIndexOf('.');
if (extIndex != -1)
{
String ext = extensionPath.substring(extIndex + 1);
mimetype = mimetypeService.getMimetype(ext);
}
}
// set mimetype for the content and the character encoding + length for the stream
res.setContentType(mimetype);
res.setContentEncoding(reader.getEncoding());
res.setHeader("Content-Length", Long.toString(reader.getSize()));
// set caching
Cache cache = new Cache();
cache.setNeverCache(false);
cache.setMustRevalidate(true);
cache.setMaxAge(0L);
cache.setLastModified(modified);
cache.setETag(eTag);
res.setCache(cache);
}
示例9: BinaryProperty
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* This is the preferred constructor to use. Takes the properties from content reader that it needs.
* @param reader ContentReader
*/
public BinaryProperty(ContentReader reader)
{
super();
this.mimeType = reader.getMimetype();
this.encoding = reader.getEncoding();
this.length = reader.getSize();
this.locale = reader.getLocale();
}
示例10: newPost
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* @see org.alfresco.repo.blog.BlogIntegrationService#newPost(BlogDetails, NodeRef, QName, boolean)
*/
public void newPost(BlogDetails blogDetails, NodeRef nodeRef, QName contentProperty, boolean publish)
{
// Get the blog implementation
BlogIntegrationImplementation implementation = getImplementation(blogDetails.getImplementationName());
// Check that this node has not already been posted to a blog
if (this.nodeService.hasAspect(nodeRef, ASPECT_BLOG_POST) == true)
{
throw new BlogIntegrationRuntimeException("Can not create new blog post since this conten has already been posted to a blog.");
}
// Get the posts body
ContentReader contentReader = this.contentService.getReader(nodeRef, contentProperty);
if (contentReader == null)
{
throw new BlogIntegrationRuntimeException("No content found for new blog entry.");
}
// Check the mimetype
String body = null;
if (supportedMimetypes.contains(contentReader.getMimetype()) == true)
{
// Get the content
body = contentReader.getContentString();
}
else
{
throw new BlogIntegrationRuntimeException("The content mimetype '" + contentReader.getMimetype() + "' is not supported.");
}
// Get the posts title
String title = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
if (title == null || title.length() == 0)
{
if (body.length() > 23)
{
// Get the title from the first 22 character plus ' ...'
title = body.substring(0, 23) + " ...";
}
else
{
title = body;
}
}
// Post the new blog entry
String postId = implementation.newPost(blogDetails, title, body, true);
// Get the blog details node if the is one
NodeRef blogDetailsNodeRef = blogDetails.getNodeRef();
if (blogDetailsNodeRef != null)
{
// Now get the details of the newly created post
Map<String, Object> details = implementation.getPost(blogDetails, postId);
String link = (String)details.get("link");
// Add the details of the new post to the node
Map<QName, Serializable> props = new HashMap<QName, Serializable>(5);
props.put(PROP_POST_ID, postId);
if (link != null)
{
props.put(PROP_LINK, link);
}
Date now = new Date();
props.put(PROP_POSTED, now);
props.put(PROP_LAST_UPDATE, now);
props.put(PROP_PUBLISHED, Boolean.valueOf(publish));
this.nodeService.addAspect(nodeRef, ASPECT_BLOG_POST, props);
// Associate to the blog details
this.nodeService.createAssociation(nodeRef, blogDetailsNodeRef, ASSOC_BLOG_DETAILS);
}
}
示例11: updatePost
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* @see org.alfresco.repo.blog.BlogIntegrationService#updatePost(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, boolean)
*/
public void updatePost(NodeRef nodeRef, QName contentProperty, boolean publish)
{
// Get the blog details and post id
BlogDetails blogDetails = null;
String postId = null;
if (this.nodeService.hasAspect(nodeRef, ASPECT_BLOG_POST) == true)
{
List<AssociationRef> assocs = this.nodeService.getTargetAssocs(nodeRef, ASSOC_BLOG_DETAILS);
if (assocs.size() == 0)
{
throw new BlogIntegrationRuntimeException("Can not resolve blog details for update because blogDetails association is not populated.");
}
else
{
blogDetails = BlogDetails.createBlogDetails(this.nodeService, assocs.get(0).getTargetRef());
postId = (String)this.nodeService.getProperty(nodeRef, PROP_POST_ID);
}
}
else
{
throw new BlogIntegrationRuntimeException("Can not update blog post as this node has not been previously posted to a blog.");
}
// Get the blog implementation
BlogIntegrationImplementation implementation = getImplementation(blogDetails.getImplementationName());
// Get the posts title
String title = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
if (title == null || title.length() == 0)
{
throw new BlogIntegrationRuntimeException("No title available for update blog post. Set the title property and re-try.");
}
// Get the posts body
ContentReader contentReader = this.contentService.getReader(nodeRef, contentProperty);
if (contentReader == null)
{
throw new BlogIntegrationRuntimeException("No content found for update blog entry.");
}
// Check the mimetype
String body = null;
if (supportedMimetypes.contains(contentReader.getMimetype()) == true)
{
// Get the content
body = contentReader.getContentString();
}
else
{
throw new BlogIntegrationRuntimeException("The content mimetype '" + contentReader.getMimetype() + "' is not supported.");
}
// Update the blog post
boolean result = implementation.updatePost(blogDetails, postId, title, body, publish);
// Check the return result
if (result == false)
{
throw new BlogIntegrationRuntimeException("The update of the post unexpectedly failed. Check your blog for more information.");
}
// Now get the details of the newly created post
Map<String, Object> details = implementation.getPost(blogDetails, postId);
String link = (String)details.get("link");
// Update the post details accordingly
Map<QName, Serializable> props = this.nodeService.getProperties(nodeRef);
Date now = new Date();
props.put(PROP_LAST_UPDATE, now);
props.put(PROP_PUBLISHED, Boolean.valueOf(publish));
props.put(PROP_LINK, link);
this.nodeService.setProperties(nodeRef, props);
}
示例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包/类
/**
* @see org.alfresco.repo.content.transform.ContentTransformerRegistry
* @see org.alfresco.repo.content.transform.ContentTransformer
*/
public void transform(ContentReader reader, ContentWriter writer, TransformationOptions options)
throws NoTransformerException, ContentIOException
{
// check that source and target mimetypes are available
if (reader == null)
{
throw new AlfrescoRuntimeException("The content reader must be set");
}
String sourceMimetype = reader.getMimetype();
if (sourceMimetype == null)
{
throw new AlfrescoRuntimeException("The content reader mimetype must be set: " + reader);
}
String targetMimetype = writer.getMimetype();
if (targetMimetype == null)
{
throw new AlfrescoRuntimeException("The content writer mimetype must be set: " + writer);
}
long sourceSize = reader.getSize();
try
{
// look for a transformer
transformerDebug.pushAvailable(reader.getContentUrl(), sourceMimetype, targetMimetype, options);
List<ContentTransformer> transformers = getActiveTransformers(sourceMimetype, sourceSize, targetMimetype, options);
transformerDebug.availableTransformers(transformers, sourceSize, options, "ContentService.transform(...)");
int count = transformers.size();
if (count == 0)
{
throw new NoTransformerException(sourceMimetype, targetMimetype);
}
if (count == 1 || !transformerFailover)
{
ContentTransformer transformer = transformers.size() == 0 ? null : transformers.get(0);
transformer.transform(reader, writer, options);
}
else
{
failoverTransformers(reader, writer, options, targetMimetype, transformers);
}
}
finally
{
if (transformerDebug.isEnabled())
{
transformerDebug.popAvailable();
debugTransformations(sourceMimetype, targetMimetype, sourceSize, options);
}
}
}
示例14: executeImpl
import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(Action, NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (!nodeService.exists(actionedUponNodeRef))
{
// Node is gone
return;
}
ContentReader reader = contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT);
// The reader may be null, e.g. for folders and the like
if (reader == null || reader.getMimetype() == null)
{
if(logger.isDebugEnabled())
{
logger.debug("no content or mimetype - do nothing");
}
// No content to extract data from
return;
}
String mimetype = reader.getMimetype();
MetadataEmbedder embedder = metadataExtracterRegistry.getEmbedder(mimetype);
if (embedder == null)
{
if(logger.isDebugEnabled())
{
logger.debug("no embedder for mimetype:" + mimetype);
}
// There is no embedder to use
return;
}
ContentWriter writer = contentService.getWriter(actionedUponNodeRef, ContentModel.PROP_CONTENT, true);
// The writer may be null, e.g. for folders and the like
if (writer == null || writer.getMimetype() == null)
{
if(logger.isDebugEnabled())
{
logger.debug("no content or mimetype - do nothing");
}
// No content to embed data in
return;
}
// Get all the node's properties
Map<QName, Serializable> nodeProperties = nodeService.getProperties(actionedUponNodeRef);
try
{
embedder.embed(nodeProperties, reader, writer);
}
catch (Throwable e)
{
// Extracters should attempt to handle all error conditions and embed
// as much as they can. If, however, one should fail, we don't want the
// action itself to fail. We absorb and report the exception here.
if (logger.isDebugEnabled())
{
logger.debug(
"Metadata embedding failed: \n" +
" Extracter: " + this + "\n" +
" Node: " + actionedUponNodeRef + "\n" +
" Content: " + writer,
e);
}
else
{
logger.warn(
"Metadata embedding failed (turn on DEBUG for full error): \n" +
" Extracter: " + this + "\n" +
" Node: " + actionedUponNodeRef + "\n" +
" Content: " + writer + "\n" +
" Failure: " + e.getMessage());
}
}
}