private void doGuessMimetype(String filename) { String mimetype; if (filename != null && filename.startsWith(MimetypeMap.MACOS_RESOURCE_FORK_FILE_NAME_PREFIX)) { mimetype = MimetypeMap.MIMETYPE_APPLEFILE; } else { mimetype = mimetypeService.guessMimetype(filename, getReader()); } setMimetype(mimetype); }
private void doGuessMimetype(String filename) { String mimetype; if (filename != null && filename.startsWith(MimetypeMap.MACOS_RESOURCE_FORK_FILE_NAME_PREFIX)) { mimetype = MimetypeMap.MIMETYPE_APPLEFILE; } else { mimetype = mimetypeService.guessMimetype(filename, getReader()); } setMimetype(mimetype); }
String mimetype = mimetypeService.guessMimetype(contentFile.getName()); String encoding = defaultEncoding; if (!contentFile.isDirectory())
String mimetype = mimetypeService.guessMimetype(contentFile.getName()); String encoding = defaultEncoding; if (!contentFile.isDirectory())
/** * Copy content data from file to file * * @param sess SrvSession * @param tree TreeConnection * @param fromNode NodeRef * @param toNode NodeRef * @param newName String */ private void copyContentData( SrvSession sess, TreeConnection tree, NodeRef fromNode, NodeRef toNode, String newName) { ContentData content = (ContentData) nodeService.getProperty(fromNode, ContentModel.PROP_CONTENT); if ( newName != null) content = ContentData.setMimetype( content, mimetypeService.guessMimetype( newName)); nodeService.setProperty(toNode, ContentModel.PROP_CONTENT, content); }
/** * Copy content data from file to file * * @param sess SrvSession * @param tree TreeConnection * @param fromNode NodeRef * @param toNode NodeRef * @param newName String */ private void copyContentData( SrvSession sess, TreeConnection tree, NodeRef fromNode, NodeRef toNode, String newName) { ContentData content = (ContentData) nodeService.getProperty(fromNode, ContentModel.PROP_CONTENT); if ( newName != null) content = ContentData.setMimetype( content, mimetypeService.guessMimetype( newName)); nodeService.setProperty(toNode, ContentModel.PROP_CONTENT, content); }
/** * 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)); } }
String mimeType = mimetypeService.guessMimetype(reusableContentStream.getFileName(), new FileContentReader(reusableContentStream.file)); reusableContentStream.setMimeType(mimeType);
/** * 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)); } }
writer.setMimetype(mimetypeService.guessMimetype(inFileName)); writer.putContent(file);
private NodeRef createContent(NodeRef parentNodeRef, String fileName, QName contentType) throws IOException { Map<QName,Serializable> properties = new HashMap<QName,Serializable>(); properties.put(ContentModel.PROP_NAME, fileName); properties.put(ContentModel.PROP_TITLE, fileName+" my title"); properties.put(ContentModel.PROP_DESCRIPTION, fileName+" my description"); NodeRef nodeRef = nodeService.getChildByName(parentNodeRef, ContentModel.ASSOC_CONTAINS, fileName); if (nodeRef != null) { nodeService.deleteNode(nodeRef); } nodeRef = nodeService.createNode(parentNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(fileName), contentType, properties).getChildRef(); ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); writer.setMimetype(mimetypeService.guessMimetype(fileName)); writer.putContent("my text content"); return nodeRef; }
private NodeRef createContent(NodeRef parentNodeRef, QName childAssocType, String fileName, QName contentType) throws IOException { Map<QName,Serializable> properties = new HashMap<QName,Serializable>(); properties.put(ContentModel.PROP_NAME, fileName); properties.put(ContentModel.PROP_TITLE, fileName+" my title"); properties.put(ContentModel.PROP_DESCRIPTION, fileName+" my description"); NodeRef nodeRef = nodeService.getChildByName(parentNodeRef, childAssocType, fileName); if (nodeRef != null) { nodeService.deleteNode(nodeRef); } nodeRef = nodeService.createNode(parentNodeRef, childAssocType, QName.createQName(fileName), contentType, properties).getChildRef(); ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); writer.setMimetype(mimetypeService.guessMimetype(fileName)); writer.putContent("my text content"); return nodeRef; }
/** * Extracts the attachments from the given message and adds them to the space. All attachments * are linked back to the original node that they are attached to. * * @param spaceNodeRef the space to add the documents into * @param nodeRef the node to which the documents will be attached * @param message the email message */ protected void addAttachments(NodeRef spaceNodeRef, NodeRef nodeRef, EmailMessage message) { // Add attachments EmailMessagePart[] attachments = message.getAttachments(); for (EmailMessagePart attachment : attachments) { String fileName = attachment.getFileName(); InputStream contentIs = attachment.getContent(); MimetypeService mimetypeService = getMimetypeService(); String mimetype = mimetypeService.guessMimetype(fileName); String encoding = attachment.getEncoding(); NodeRef attachmentNode = addAttachment(getNodeService(), spaceNodeRef, nodeRef, fileName); writeContent(attachmentNode, contentIs, mimetype, encoding); } }
/** * Extracts the attachments from the given message and adds them to the space. All attachments * are linked back to the original node that they are attached to. * * @param spaceNodeRef the space to add the documents into * @param nodeRef the node to which the documents will be attached * @param message the email message */ protected void addAttachments(NodeRef spaceNodeRef, NodeRef nodeRef, EmailMessage message) { // Add attachments EmailMessagePart[] attachments = message.getAttachments(); for (EmailMessagePart attachment : attachments) { String fileName = attachment.getFileName(); InputStream contentIs = attachment.getContent(); MimetypeService mimetypeService = getMimetypeService(); String mimetype = mimetypeService.guessMimetype(fileName); String encoding = attachment.getEncoding(); NodeRef attachmentNode = addAttachment(getNodeService(), spaceNodeRef, nodeRef, fileName); writeContent(attachmentNode, contentIs, mimetype, encoding); } }
private NodeRef updateContent(NodeRef sourceNodeRef, String testFileName) throws FileNotFoundException { File file = ResourceUtils.getFile("classpath:quick/" + testFileName); nodeService.setProperty(sourceNodeRef, ContentModel.PROP_NAME, testFileName); ContentWriter contentWriter = contentService.getWriter(sourceNodeRef, ContentModel.PROP_CONTENT, true); contentWriter.setMimetype(mimetypeService.guessMimetype(testFileName)); contentWriter.putContent(file); return sourceNodeRef; }
/** * Create a new File (cm:content) node as a child of this node. * <p> * Once created the file should have content set using the <code>content</code> property. * * Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call {@link #save()} first. * * @param name Name of the file to create * @param type Type of the file to create (if null, defaults to ContentModel.TYPE_CONTENT) * * @return Newly created Node or null if failed to create. */ public ScriptNode createFile(String name, String type) { ParameterCheck.mandatoryString("Node Name", name); FileInfo fileInfo = this.services.getFileFolderService().create( this.nodeRef, name, type == null ? ContentModel.TYPE_CONTENT : createQName(type)); reset(); ScriptNode file = newInstance(fileInfo.getNodeRef(), this.services, this.scope); file.setMimetype(this.services.getMimetypeService().guessMimetype(name)); return file; }
/** * Create a new File (cm:content) node as a child of this node. * <p> * Once created the file should have content set using the <code>content</code> property. * * Beware: Any unsaved property changes will be lost when this is called. To preserve property changes call {@link #save()} first. * * @param name Name of the file to create * @param type Type of the file to create (if null, defaults to ContentModel.TYPE_CONTENT) * * @return Newly created Node or null if failed to create. */ public ScriptNode createFile(String name, String type) { ParameterCheck.mandatoryString("Node Name", name); FileInfo fileInfo = this.services.getFileFolderService().create( this.nodeRef, name, type == null ? ContentModel.TYPE_CONTENT : createQName(type)); reset(); ScriptNode file = newInstance(fileInfo.getNodeRef(), this.services, this.scope); file.setMimetype(this.services.getMimetypeService().guessMimetype(name)); return file; }
mimetype = this.services.getMimetypeService().guessMimetype(fileName);
mimetype = this.services.getMimetypeService().guessMimetype(fileName);
NodeRef createContentNodeFromQuickFile(String fileName) throws FileNotFoundException { NodeRef rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); NodeRef folderNodeRef = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(getName() + GUID.generate()), ContentModel.TYPE_FOLDER).getChildRef(); File file = ResourceUtils.getFile("classpath:quick/" + fileName); NodeRef contentRef = nodeService.createNode( folderNodeRef, ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS, ContentModel.TYPE_CONTENT, Collections.singletonMap(ContentModel.PROP_NAME, fileName)) .getChildRef(); ContentWriter contentWriter = contentService.getWriter(contentRef, ContentModel.PROP_CONTENT, true); contentWriter.setMimetype(mimetypeService.guessMimetype(fileName)); contentWriter.putContent(file); return contentRef; }