• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MimeTypesUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.liferay.portal.kernel.util.MimeTypesUtil的典型用法代码示例。如果您正苦于以下问题:Java MimeTypesUtil类的具体用法?Java MimeTypesUtil怎么用?Java MimeTypesUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MimeTypesUtil类属于com.liferay.portal.kernel.util包,在下文中一共展示了MimeTypesUtil类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: uploadImage

import com.liferay.portal.kernel.util.MimeTypesUtil; //导入依赖的package包/类
/**
 * Upload image.
 * 
 * @param image
 *            the image
 * @return the uri
 * @throws SystemException
 *             the system exception
 * @throws URISyntaxException
 *             the uRI syntax exception
 * @throws IOException
 * @throws PortalException
 */
public static URI uploadImage(UploadedFile image) throws SystemException, URISyntaxException, IOException, PortalException,
        NullPointerException {

    LiferayFacesContext lfc = LiferayFacesContext.getInstance();
    ThemeDisplay td = lfc.getThemeDisplay();

    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setScopeGroupId(td.getScopeGroupId());

    long imageFolderId = Long.parseLong(PropsUtil.get("image.folder.id"));
    DLFolder folder;

    try {
        /* Check if folder for image exists */
        folder = DLFolderLocalServiceUtil.getDLFolder(imageFolderId);
        LOG.debug("Folder for app images exists.");
    } catch (PortalException e) {
        /* If not -> create */
        folder = DLFolderLocalServiceUtil.createDLFolder(imageFolderId);
        folder.setName("App-Images");
        DLFolderLocalServiceUtil.addDLFolder(folder);
        LOG.debug("Created folder for app images.");
    }

    String uuidExt = null;
    FileEntry file = null;

    uuidExt = td.getUser().getScreenName() + "_" + UUID.randomUUID().toString() + "_" + new Date().getTime() + "_";

    file = DLAppLocalServiceUtil.addFileEntry(td.getUserId(), td.getScopeGroupId(), folder.getFolderId(), uuidExt + image.getName(),
            MimeTypesUtil.getContentType(image.getName()), uuidExt + image.getName(), uuidExt + image.getName(), "new",
            image.getBytes(), serviceContext);

    return new URI(td.getPortalURL() + "/c/document_library/get_file?uuid=" + file.getUuid() + "&groupId=" + td.getScopeGroupId());
}
 
开发者ID:fraunhoferfokus,项目名称:odp-manage-datasets-portlet,代码行数:49,代码来源:ImageGalleryUtils.java


示例2: getAddEntrySpecifiedArgs

import com.liferay.portal.kernel.util.MimeTypesUtil; //导入依赖的package包/类
@Override
protected Map<String, Object> getAddEntrySpecifiedArgs(
	RequestContext requestContext) throws Exception {

	long repositoryId = requestContext.getLong(
		DMFolderHandler.REPOSITORY_LIST, requestContext.getGroupId());

	File uploadedFile = requestContext.getFile(
		getDisplayFieldName(UPLOAD_FILE));

	Map<String, Object> args = new HashMap<String, Object>(2);

	args.put("file", uploadedFile);
	args.put("mimeType", MimeTypesUtil.getContentType(uploadedFile));
	args.put("repositoryId", repositoryId);
	args.put("sourceFileName", uploadedFile.getName());

	return args;
}
 
开发者ID:sorin-pop,项目名称:data-manipulator,代码行数:20,代码来源:DMDocumentHandler.java


示例3: updateServiceFileTemplate

import com.liferay.portal.kernel.util.MimeTypesUtil; //导入依赖的package包/类
public ServiceFileTemplate updateServiceFileTemplate(long userId, long groupId, long folderId, long serviceInfoId,
		String fileTemplateNo, String templateName, String sourceFileName, InputStream inputStream,
		ServiceContext serviceContext) throws PortalException, IOException {

	long fileEntryId = 0;

	if (inputStream != null) {
		String mimeType = MimeTypesUtil.getContentType(sourceFileName);
		int size = FileUtil.getBytes(inputStream).length;

		FileEntry fileEntry = dlAppLocalService.addFileEntry(userId, groupId, folderId, sourceFileName, mimeType,
				templateName, templateName, StringPool.BLANK, inputStream, size, serviceContext);

		fileEntryId = fileEntry.getFileEntryId();
	}

	ServiceFileTemplatePK fileTemplatePK = new ServiceFileTemplatePK(serviceInfoId, fileTemplateNo);

	ServiceFileTemplate serviceFileTemplate = serviceFileTemplatePersistence.fetchByPrimaryKey(fileTemplatePK);

	// remove old fileEntry
	if (serviceFileTemplate.getFileEntryId() != 0) {
		dlAppLocalService.deleteFileEntry(serviceFileTemplate.getFileEntryId());
	}

	serviceFileTemplate.setTemplateName(templateName);
	serviceFileTemplate.setFileEntryId(fileEntryId);

	return serviceFileTemplatePersistence.update(serviceFileTemplate);
}
 
开发者ID:VietOpenCPS,项目名称:opencps-v2,代码行数:31,代码来源:ServiceFileTemplateLocalServiceImpl.java


示例4: addDLFileEntry

import com.liferay.portal.kernel.util.MimeTypesUtil; //导入依赖的package包/类
protected void addDLFileEntry(
		long parentFolderId, String fileName, InputStream inputStream,
		long length)
	throws Exception {

	setServiceContext(fileName);

	FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(
		userId, groupId, parentFolderId, fileName,
		MimeTypesUtil.getContentType(fileName),
		FileUtil.stripExtension(fileName), StringPool.BLANK,
		StringPool.BLANK, inputStream, length, serviceContext);

	_fileEntries.put(fileName, fileEntry);
}
 
开发者ID:rivetlogic,项目名称:liferay-evernote,代码行数:16,代码来源:FileSystemImporter.java


示例5: addServiceFileTemplate

import com.liferay.portal.kernel.util.MimeTypesUtil; //导入依赖的package包/类
public ServiceFileTemplate addServiceFileTemplate(long userId, long groupId, long folderId, long serviceInfoId,
		String fileTemplateNo, String templateName, String sourceFileName, InputStream inputStream,
		ServiceContext serviceContext) throws PortalException, IOException {

	long fileEntryId = 0;

	serviceContext.setAddGroupPermissions(true);
	serviceContext.setAddGuestPermissions(true);

	if (inputStream != null) {
		String mimeType = MimeTypesUtil.getContentType(sourceFileName);
		int size = FileUtil.getBytes(inputStream).length;

		// FileEntry fileEntry =
		//
		// dlAppLocalService.addFileEntry(userId, groupId, folderId,
		// sourceFileName, mimeType,
		// sourceFileName, sourceFileName, sourceFileName,
		// inputStream, size, serviceContext);
		
		try {
			FileEntry fileEntry = dlAppLocalService.addFileEntry(userId, groupId, folderId, sourceFileName, mimeType,
					sourceFileName, sourceFileName, sourceFileName, inputStream, size, serviceContext);

			fileEntryId = fileEntry.getFileEntryId();
		} catch (Exception e) {
			_log.error(e);
		}
		
		
	}

	ServiceFileTemplatePK fileTemplatePK = new ServiceFileTemplatePK(serviceInfoId, fileTemplateNo);

	ServiceFileTemplate serviceFileTemplate = serviceFileTemplatePersistence.create(fileTemplatePK);

	serviceFileTemplate.setTemplateName(templateName);
	serviceFileTemplate.setFileEntryId(fileEntryId);

	return serviceFileTemplatePersistence.update(serviceFileTemplate);
}
 
开发者ID:VietOpenCPS,项目名称:opencps-v2,代码行数:42,代码来源:ServiceFileTemplateLocalServiceImpl.java


示例6: uploadFile

import com.liferay.portal.kernel.util.MimeTypesUtil; //导入依赖的package包/类
/**
 * 
 * @param userId
 * @param groupId
 * @param inputStream
 * @param sourceFileName
 * @param fileType
 * @param fileSize
 * @param destination
 * @param serviceContext
 * @return null if inputStream is null or sourceFileName is null
 * @throws Exception
 */
public static FileEntry uploadFile(long userId, long groupId, long fileEntryId, InputStream inputStream, String sourceFileName,
		String fileType, long fileSize, String destination, ServiceContext serviceContext) 
	throws Exception {
	
	FileEntry fileEntry = null;

	if (inputStream != null && Validator.isNotNull(sourceFileName)) {
		
		if(Validator.isNull(fileType)) {
			fileType = MimeTypesUtil.getContentType(sourceFileName);
		}
		
		if(fileSize == 0) {
			fileSize = inputStream.available();
			//byte[] bytes = FileUtil.getBytes(inputStream, -1, false);
			//fileSize = bytes.length;
		}
		
		String title = getFileName(sourceFileName);

		serviceContext.setAddGroupPermissions(true);
		serviceContext.setAddGuestPermissions(true);

		Calendar calendar = Calendar.getInstance();

		calendar.setTime(new Date());
		
		if(destination == null) {
			destination = StringPool.BLANK;
		}

		destination += calendar.get(Calendar.YEAR) + StringPool.SLASH;
		destination += calendar.get(Calendar.MONTH) + StringPool.SLASH;
		destination += calendar.get(Calendar.DAY_OF_MONTH);

		DLFolder dlFolder = DLFolderUtil.getTargetFolder(userId, groupId, groupId, false, 0, destination,
				StringPool.BLANK, false, serviceContext);

		User user = UserLocalServiceUtil.getUser(serviceContext.getUserId());

		PermissionChecker checker = PermissionCheckerFactoryUtil.create(user);
		PermissionThreadLocal.setPermissionChecker(checker);
		
		if(fileEntryId > 0) {
			fileEntry = DLAppLocalServiceUtil.updateFileEntry(userId, fileEntryId, sourceFileName, 
					fileType, title, title, title, true, inputStream, fileSize, serviceContext);
		} else {
			fileEntry = DLAppLocalServiceUtil.addFileEntry(userId, groupId, dlFolder.getFolderId(), title,
				fileType, title, title,
				StringPool.BLANK, inputStream, fileSize, serviceContext);
		}

	}

	return fileEntry;
}
 
开发者ID:VietOpenCPS,项目名称:opencps-v2,代码行数:70,代码来源:FileUploadUtils.java


示例7: updateIGImageEntries

import com.liferay.portal.kernel.util.MimeTypesUtil; //导入依赖的package包/类
protected void updateIGImageEntries() throws Exception {
	Connection con = null;
	PreparedStatement ps = null;
	ResultSet rs = null;

	try {
		con = DataAccess.getUpgradeOptimizedConnection();

		ps = con.prepareStatement("select * from IGImage");

		rs = ps.executeQuery();

		while (rs.next()) {
			String uuid = rs.getString("uuid_");
			long imageId = rs.getLong("imageId");
			long groupId = rs.getLong("groupId");
			long companyId = rs.getLong("companyId");
			long userId = rs.getLong("userId");
			String userName = rs.getString("userName");
			Timestamp createDate = rs.getTimestamp("createDate");
			Timestamp modifiedDate = rs.getTimestamp("modifiedDate");
			long folderId = rs.getLong("folderId");
			String title = rs.getString("name");
			String description = rs.getString("description");
			long smallImageId = rs.getLong("smallImageId");
			long largeImageId = rs.getLong("largeImageId");
			long custom1ImageId = rs.getLong("custom1ImageId");
			long custom2ImageId = rs.getLong("custom2ImageId");

			Object[] image = getImage(largeImageId);

			if (image == null) {
				continue;
			}

			String extension = (String)image[0];

			String mimeType = MimeTypesUtil.getContentType(
				"A." + extension);

			String name = String.valueOf(
				increment(DLFileEntry.class.getName()));

			long size = (Long)image[1];

			try {
				addDLFileEntry(
					uuid, imageId, groupId, companyId, userId, userName,
					userId, userName, createDate, modifiedDate, groupId,
					folderId, name, extension, mimeType, title, description,
					StringPool.BLANK, "1.0", size, 0, smallImageId,
					largeImageId, custom1ImageId, custom2ImageId);
			}
			catch (Exception e) {
				title = title.concat(StringPool.SPACE).concat(
					String.valueOf(imageId));

				addDLFileEntry(
					uuid, imageId, groupId, companyId, userId, userName,
					userId, userName, createDate, modifiedDate, groupId,
					folderId, name, extension, mimeType, title, description,
					StringPool.BLANK, "1.0", size, 0, smallImageId,
					largeImageId, custom1ImageId, custom2ImageId);
			}

			addDLFileVersion(
				increment(), groupId, companyId, userId, userName,
				createDate, groupId, folderId, imageId, extension, mimeType,
				title, description, StringPool.BLANK, StringPool.BLANK, 0,
				"1.0", size, 0, userId, userName, modifiedDate);
		}

		runSQL("drop table IGImage");
	}
	finally {
		DataAccess.cleanUp(con, ps, rs);
	}
}
 
开发者ID:camaradosdeputadosoficial,项目名称:edemocracia,代码行数:79,代码来源:UpgradeImageGallery.java



注:本文中的com.liferay.portal.kernel.util.MimeTypesUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FoldingBuilder类代码示例发布时间:2022-05-21
下一篇:
Java XMLUtils类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap