本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentWriter.guessMimetype方法的典型用法代码示例。如果您正苦于以下问题:Java ContentWriter.guessMimetype方法的具体用法?Java ContentWriter.guessMimetype怎么用?Java ContentWriter.guessMimetype使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.service.cmr.repository.ContentWriter
的用法示例。
在下文中一共展示了ContentWriter.guessMimetype方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canGuessMimeType
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
@Test
public void canGuessMimeType()
{
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
ContentService contentService = (ContentService) ctx.getBean("ContentService");
NodeService nodeService = (NodeService) ctx.getBean("NodeService");
StoreRef storeRef = nodeService.createStore("workspace", getClass().getName()+UUID.randomUUID());
NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
NodeRef nodeRef = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, getClass().getSimpleName()),
ContentModel.TYPE_CONTENT).getChildRef();
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
// Pre-condition of test is that we're testing with a potentially problematic BackingStoreAwareCacheWriter
// rather than a FileContentWriter, which we would expect to work.
assertTrue(writer instanceof BackingStoreAwareCacheWriter);
String content = "This is some content";
writer.putContent(content);
writer.guessMimetype("myfile.txt");
assertEquals("text/plain", writer.getMimetype());
}
示例2: getWriter
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
@Override
public ContentWriter getWriter(NodeRef nodeRef)
{
FileInfo fileInfo = toFileInfo(nodeRef, false);
if (fileInfo.isFolder())
{
throw new InvalidTypeException("Unable to get a content writer for a folder: " + fileInfo);
}
final ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
// Ensure that a mimetype is set based on the filename (ALF-6560)
// This has been removed from the create code in 3.4 to prevent insert-update behaviour
// of the ContentData.
if (writer.getMimetype() == null)
{
final String name = fileInfo.getName();
writer.guessMimetype(name);
}
// Done
return writer;
}
示例3: writeData
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private void writeData(String fileName, final NodeRef fileNodeRef)
{
nodeService.addAspect(fileNodeRef, ContentModel.ASPECT_NO_CONTENT, null);
// Access the content
ContentWriter writer = fileFolderService.getWriter(fileNodeRef);
// set content properties
writer.guessMimetype(fileName);
writer.guessEncoding();
// Get the input stream from the request data
InputStream is = getClass().getClassLoader().getResourceAsStream(
"farmers_markets_list_2003.doc");
// Write the new data to the content node
writer.putContent(is);
// write info about author
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.SYSTEM_USER_NAME);
this.transactionService.getRetryingTransactionHelper().doInTransaction(
new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable
{
// Create the action
Action action = actionService.createAction(ContentMetadataExtracter.EXECUTOR_NAME);
try
{
actionService.executeAction(action, fileNodeRef);
}
catch (Throwable th)
{
// do nothing
}
return null;
}
});
AuthenticationUtil.popAuthentication();
}
示例4: createAvatarDirect
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private NodeRef createAvatarDirect(NodeRef personRef, File avatarFile)
{
// create new avatar node
nodeService.addAspect(personRef, ContentModel.ASPECT_PREFERENCES, null);
ChildAssociationRef assoc = nodeService.createNode(
personRef,
ContentModel.ASSOC_PREFERENCE_IMAGE,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "origAvatar"),
ContentModel.TYPE_CONTENT);
final NodeRef avatarRef = assoc.getChildRef();
// JSF client compatibility?
nodeService.createAssociation(personRef, avatarRef, ContentModel.ASSOC_AVATAR);
// upload the avatar content
ContentService contentService = applicationContext.getBean("ContentService", ContentService.class);
ContentWriter writer = contentService.getWriter(avatarRef, ContentModel.PROP_CONTENT, true);
writer.guessMimetype(avatarFile.getName());
writer.putContent(avatarFile);
Rendition avatarR = new Rendition();
avatarR.setId("avatar");
Renditions renditions = applicationContext.getBean("Renditions", Renditions.class);
renditions.createRendition(avatarRef.getId(), avatarR, false, null);
return avatarRef;
}