Java Code Examples for org.alfresco.repo.content.MimetypeMap#MIMETYPE_BINARY
The following examples show how to use
org.alfresco.repo.content.MimetypeMap#MIMETYPE_BINARY .
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: ContentData.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
/** * Create a compound set of data representing a single instance of <i>content</i>. * <p> * In order to ensure data integrity, the {@link #getMimetype() mimetype} * must be set if the {@link #getContentUrl() content URL} is set. * * @param contentUrl the content URL. If this value is non-null, then the * <b>mimetype</b> must be supplied. * @param mimetype the content mimetype. This is mandatory if the <b>contentUrl</b> is specified. * @param size the content size. * @param encoding the content encoding. This is mandatory if the <b>contentUrl</b> is specified. * @param locale the locale of the content (may be <tt>null</tt>). If <tt>null</tt>, the * {@link I18NUtil#getLocale() default locale} will be used. */ public ContentData(String contentUrl, String mimetype, long size, String encoding, Locale locale) { if (contentUrl != null && (mimetype == null || mimetype.length() == 0)) { mimetype = MimetypeMap.MIMETYPE_BINARY; } checkContentUrl(contentUrl, mimetype, encoding); this.contentUrl = contentUrl; this.mimetype = mimetype; this.size = size; this.encoding = encoding; if (locale == null) { locale = I18NUtil.getLocale(); } this.locale = locale; }
Example 2
Source File: ResourceWebScriptPut.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Returns the basic content info from the request. * @param req WebScriptRequest * @return BasicContentInfo */ private BasicContentInfo getContentInfo(WebScriptRequest req) { String encoding = "UTF-8"; String contentType = MimetypeMap.MIMETYPE_BINARY; if (StringUtils.isNotEmpty(req.getContentType())) { MediaType media = MediaType.parseMediaType(req.getContentType()); contentType = media.getType()+'/'+media.getSubtype(); if (media.getCharset() != null) { encoding = media.getCharset().toString(); } } return new ContentInfoImpl(contentType, encoding, -1, Locale.getDefault()); }
Example 3
Source File: ContentInfo.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
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); }
Example 4
Source File: ContentStreamer.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * Streams content back to client from a given File. * * @param req The request * @param res The response * @param file The file whose content is to be streamed. * @param modifiedTime The modified datetime to use for the streamed content. If <tt>null</tt> the * file's timestamp will be used. * @param attach Indicates whether the content should be streamed as an attachment or not * @param attachFileName Optional file name to use when attach is <code>true</code> * @throws IOException */ public void streamContent(WebScriptRequest req, WebScriptResponse res, File file, Long modifiedTime, boolean attach, String attachFileName, Map<String, Object> model) throws IOException { if (logger.isDebugEnabled()) logger.debug("Retrieving content from file " + file.getAbsolutePath() + " (attach: " + attach + ")"); // determine mimetype from file extension String filePath = file.getAbsolutePath(); String mimetype = MimetypeMap.MIMETYPE_BINARY; int extIndex = filePath.lastIndexOf('.'); if (extIndex != -1) { mimetype = mimetypeService.getMimetype(filePath.substring(extIndex + 1)); } // setup file reader and stream FileContentReader reader = new FileContentReader(file); reader.setMimetype(mimetype); reader.setEncoding("UTF-8"); long lastModified = modifiedTime == null ? file.lastModified() : modifiedTime; Date lastModifiedDate = new Date(lastModified); streamContentImpl(req, res, reader, null, null, attach, lastModifiedDate, String.valueOf(lastModifiedDate.getTime()), attachFileName, model); }