Java Code Examples for org.alfresco.service.cmr.repository.ContentWriter#guessMimetype()
The following examples show how to use
org.alfresco.service.cmr.repository.ContentWriter#guessMimetype() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileFolderServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@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; }
Example 2
Source File: FullTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@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()); }
Example 3
Source File: LockableAspectInterceptorTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
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(); }
Example 4
Source File: TestPeople.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
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, avatarR, false, null); return avatarRef; }
Example 5
Source File: FilesystemBulkImportItemVersion.java From alfresco-bulk-import with Apache License 2.0 | 5 votes |
/** * @see org.alfresco.extension.bulkimport.source.BulkImportItemVersion#putContent(org.alfresco.service.cmr.repository.ContentWriter) */ @Override public void putContent(final ContentWriter writer) { writer.guessMimetype(contentReference.getName()); writer.putContent(contentReference); writer.guessEncoding(); }