List of usage examples for com.liferay.portal.kernel.repository.model FileVersion getExtension
public String getExtension();
From source file:com.liferay.document.library.internal.exportimport.data.handler.test.FileEntryStagedModelDataHandlerTest.java
License:Open Source License
@Override protected void validateImportedStagedModel(StagedModel stagedModel, StagedModel importedStagedModel) throws Exception { Assert.assertTrue(//from w ww .ja v a2 s . c om String.valueOf(stagedModel.getCreateDate()) + StringPool.SPACE + importedStagedModel.getCreateDate(), DateUtil.equals(stagedModel.getCreateDate(), importedStagedModel.getCreateDate())); Assert.assertEquals(stagedModel.getUuid(), importedStagedModel.getUuid()); FileEntry fileEntry = (FileEntry) stagedModel; FileEntry importedFileEntry = (FileEntry) importedStagedModel; Assert.assertEquals(fileEntry.getFileName(), importedFileEntry.getFileName()); Assert.assertEquals(fileEntry.getExtension(), importedFileEntry.getExtension()); Assert.assertEquals(fileEntry.getMimeType(), importedFileEntry.getMimeType()); Assert.assertEquals(fileEntry.getTitle(), importedFileEntry.getTitle()); Assert.assertEquals(fileEntry.getDescription(), importedFileEntry.getDescription()); Assert.assertEquals(fileEntry.getSize(), importedFileEntry.getSize()); FileVersion latestFileVersion = fileEntry.getLatestFileVersion(); FileVersion importedLatestFileVersion = importedFileEntry.getLatestFileVersion(); Assert.assertEquals(latestFileVersion.getUuid(), importedLatestFileVersion.getUuid()); Assert.assertEquals(latestFileVersion.getFileName(), importedLatestFileVersion.getFileName()); Assert.assertEquals(latestFileVersion.getExtension(), importedLatestFileVersion.getExtension()); Assert.assertEquals(latestFileVersion.getMimeType(), importedLatestFileVersion.getMimeType()); Assert.assertEquals(latestFileVersion.getTitle(), importedLatestFileVersion.getTitle()); Assert.assertEquals(latestFileVersion.getDescription(), importedLatestFileVersion.getDescription()); Assert.assertEquals(latestFileVersion.getSize(), importedLatestFileVersion.getSize()); Assert.assertEquals(latestFileVersion.getStatus(), importedLatestFileVersion.getStatus()); }
From source file:com.liferay.document.library.service.test.DLFileVersionUpdateTest.java
License:Open Source License
protected void testVersionUpdate(String addFileName, byte[] addBytes, String addMimeType, String updateFileName, byte[] updateBytes, String updateMimeType) throws PortalException { String description = StringPool.BLANK; String changeLog = StringPool.BLANK; ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId()); FileEntry fileEntry = DLAppServiceUtil.addFileEntry(group.getGroupId(), parentFolder.getFolderId(), addFileName, addMimeType, addFileName, description, changeLog, addBytes, serviceContext); fileEntry = DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), updateFileName, updateMimeType, updateFileName, description, changeLog, false, updateBytes, serviceContext); FileVersion fileVersion = fileEntry.getFileVersion(); Assert.assertEquals(DLFileEntryConstants.VERSION_DEFAULT, fileVersion.getVersion()); Assert.assertEquals(updateMimeType, fileVersion.getMimeType()); Assert.assertEquals(updateBytes.length, fileVersion.getSize()); Assert.assertEquals(fileVersion.getExtension(), fileEntry.getExtension()); Assert.assertEquals(fileVersion.getMimeType(), fileEntry.getMimeType()); Assert.assertEquals(fileVersion.getSize(), fileEntry.getSize()); }
From source file:com.liferay.document.library.web.internal.portlet.action.CompareVersionsMVCRenderCommand.java
License:Open Source License
protected void compareVersions(RenderRequest renderRequest) throws Exception { long sourceFileVersionId = ParamUtil.getLong(renderRequest, "sourceFileVersionId"); long targetFileVersionId = ParamUtil.getLong(renderRequest, "targetFileVersionId"); FileVersion sourceFileVersion = _dlAppService.getFileVersion(sourceFileVersionId); InputStream sourceIs = sourceFileVersion.getContentStream(false); String sourceExtension = sourceFileVersion.getExtension(); if (sourceExtension.equals("css") || sourceExtension.equals("htm") || sourceExtension.equals("html") || sourceExtension.equals("js") || sourceExtension.equals("txt") || sourceExtension.equals("xml")) { String sourceContent = HtmlUtil.escape(StringUtil.read(sourceIs)); sourceIs = new UnsyncByteArrayInputStream(sourceContent.getBytes(StringPool.UTF8)); }// w w w . java2 s .c o m FileVersion targetFileVersion = _dlAppLocalService.getFileVersion(targetFileVersionId); InputStream targetIs = targetFileVersion.getContentStream(false); String targetExtension = targetFileVersion.getExtension(); if (targetExtension.equals("css") || targetExtension.equals("htm") || targetExtension.equals("html") || targetExtension.equals("js") || targetExtension.equals("txt") || targetExtension.equals("xml")) { String targetContent = HtmlUtil.escape(StringUtil.read(targetIs)); targetIs = new UnsyncByteArrayInputStream(targetContent.getBytes(StringPool.UTF8)); } if (DocumentConversionUtil.isEnabled()) { if (DocumentConversionUtil.isConvertBeforeCompare(sourceExtension)) { String sourceTempFileId = DLUtil.getTempFileId(sourceFileVersion.getFileEntryId(), sourceFileVersion.getVersion()); sourceIs = new FileInputStream( DocumentConversionUtil.convert(sourceTempFileId, sourceIs, sourceExtension, "txt")); } if (DocumentConversionUtil.isConvertBeforeCompare(targetExtension)) { String targetTempFileId = DLUtil.getTempFileId(targetFileVersion.getFileEntryId(), targetFileVersion.getVersion()); targetIs = new FileInputStream( DocumentConversionUtil.convert(targetTempFileId, targetIs, targetExtension, "txt")); } } List<DiffResult>[] diffResults = DiffUtil.diff(new InputStreamReader(sourceIs), new InputStreamReader(targetIs)); renderRequest.setAttribute(WebKeys.DIFF_RESULTS, diffResults); renderRequest.setAttribute(WebKeys.SOURCE_NAME, sourceFileVersion.getTitle() + StringPool.SPACE + sourceFileVersion.getVersion()); renderRequest.setAttribute(WebKeys.TARGET_NAME, targetFileVersion.getTitle() + StringPool.SPACE + targetFileVersion.getVersion()); }
From source file:com.liferay.document.library.web.internal.portlet.action.GetFileActionHelper.java
License:Open Source License
protected void getFile(long fileEntryId, long folderId, String name, String title, String version, long fileShortcutId, String uuid, long groupId, String targetExtension, HttpServletRequest request, HttpServletResponse response) throws Exception { if (name.startsWith("DLFE-")) { name = name.substring(5);/*from w w w.j ava2 s.c o m*/ } name = FileUtil.stripExtension(name); FileEntry fileEntry = null; if (Validator.isNotNull(uuid) && (groupId > 0)) { fileEntry = DLAppServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId); folderId = fileEntry.getFolderId(); } if (fileEntryId > 0) { fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId); } else if (fileShortcutId <= 0) { if (Validator.isNotNull(title)) { fileEntry = DLAppServiceUtil.getFileEntry(groupId, folderId, title); } else if (Validator.isNotNull(name)) { DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.fetchFileEntryByName(groupId, folderId, name); if (dlFileEntry == null) { // LPS-30374 List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil.getFileEntries(folderId, name); if (!dlFileEntries.isEmpty()) { dlFileEntry = dlFileEntries.get(0); } } if (dlFileEntry != null) { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); DLFileEntryPermission.check(permissionChecker, dlFileEntry, ActionKeys.VIEW); fileEntry = new LiferayFileEntry(dlFileEntry); } } } else { FileShortcut fileShortcut = DLAppServiceUtil.getFileShortcut(fileShortcutId); fileEntryId = fileShortcut.getToFileEntryId(); fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId); } if (Validator.isNull(version)) { if ((fileEntry != null) && Validator.isNotNull(fileEntry.getVersion())) { version = fileEntry.getVersion(); } else { throw new NoSuchFileEntryException("{fileEntryId=" + fileEntryId + "}"); } } FileVersion fileVersion = fileEntry.getFileVersion(version); InputStream is = fileVersion.getContentStream(true); String fileName = fileVersion.getTitle(); String sourceExtension = fileVersion.getExtension(); if (Validator.isNotNull(sourceExtension) && !fileName.endsWith(StringPool.PERIOD + sourceExtension)) { fileName += StringPool.PERIOD + sourceExtension; } long contentLength = fileVersion.getSize(); String contentType = fileVersion.getMimeType(); if (Validator.isNotNull(targetExtension)) { String id = DLUtil.getTempFileId(fileEntry.getFileEntryId(), version); File convertedFile = DocumentConversionUtil.convert(id, is, sourceExtension, targetExtension); if (convertedFile != null) { fileName = FileUtil.stripExtension(fileName).concat(StringPool.PERIOD).concat(targetExtension); is = new FileInputStream(convertedFile); contentLength = convertedFile.length(); contentType = MimeTypesUtil.getContentType(fileName); } } FlashMagicBytesUtil.Result flashMagicBytesUtilResult = FlashMagicBytesUtil.check(is); if (flashMagicBytesUtilResult.isFlash()) { fileName = FileUtil.stripExtension(fileName) + ".swf"; } is = flashMagicBytesUtilResult.getInputStream(); ServletResponseUtil.sendFile(request, response, fileName, is, contentLength, contentType); }
From source file:com.liferay.image.editor.hook.action.EditFileEntryAction.java
License:Open Source License
protected void updateImage(ActionRequest actionRequest) throws Exception { long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId"); if (fileEntryId == 0) { throw new NoSuchFileEntryException(); }/* ww w. j av a2 s. c o m*/ FileEntry fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId); String blob = ParamUtil.getString(actionRequest, "blob"); if (Validator.isNull(blob)) { throw new NoSuchImageException(); } String mimeType = fileEntry.getMimeType(); FileVersion latestFileVersion = fileEntry.getLatestFileVersion(); String extension = latestFileVersion.getExtension(); File imageFile = ActionUtil.getImageFromBlob(blob, extension); FileEntry tempFileEntry = TempFileUtil.addTempFile(fileEntry.getGroupId(), fileEntry.getUserId(), fileEntry.getTitle() + fileEntry.getVersion(), _TEMP_FOLDER_NAME, imageFile, mimeType); try { ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); String sourceFileName = fileEntry.getTitle(); if (!sourceFileName.endsWith(extension)) { sourceFileName.concat(extension); } fileEntry = DLAppServiceUtil.updateFileEntry(fileEntryId, sourceFileName, mimeType, fileEntry.getTitle(), fileEntry.getDescription(), ActionUtil.getChangeLog(actionRequest), false, imageFile, serviceContext); AssetPublisherUtil.addAndStoreSelection(actionRequest, DLFileEntry.class.getName(), fileEntry.getFileEntryId(), -1); AssetPublisherUtil.addRecentFolderId(actionRequest, DLFileEntry.class.getName(), fileEntry.getFolderId()); return; } catch (Exception e) { e.printStackTrace(); } finally { if (tempFileEntry != null) { TempFileUtil.deleteTempFile(tempFileEntry.getFileEntryId()); } } }
From source file:com.liferay.item.selector.taglib.internal.util.ItemSelectorRepositoryEntryBrowserUtil.java
License:Open Source License
public static JSONObject getItemMetadataJSONObject(FileEntry fileEntry, Locale locale) throws PortalException { JSONObject itemMetadataJSONObject = JSONFactoryUtil.createJSONObject(); JSONArray groupsJSONArray = JSONFactoryUtil.createJSONArray(); JSONObject firstTabJSONObject = JSONFactoryUtil.createJSONObject(); JSONArray firstTabDataJSONArray = JSONFactoryUtil.createJSONArray(); FileVersion latestFileVersion = fileEntry.getLatestFileVersion(); firstTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "format"), HtmlUtil.escape(latestFileVersion.getExtension()))); firstTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "size"), TextFormatter.formatStorageSize(fileEntry.getSize(), locale))); firstTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "name"), HtmlUtil.escape(DLUtil.getTitleWithExtension(fileEntry)))); Date modifiedDate = fileEntry.getModifiedDate(); firstTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "modified"), LanguageUtil.format(locale, "x-ago-by-x", new Object[] { LanguageUtil.getTimeDescription(locale, System.currentTimeMillis() - modifiedDate.getTime(), true), HtmlUtil.escape(fileEntry.getUserName()) }))); firstTabJSONObject.put("data", firstTabDataJSONArray); firstTabJSONObject.put("title", LanguageUtil.get(locale, "file-info")); groupsJSONArray.put(firstTabJSONObject); JSONObject secondTabJSONObject = JSONFactoryUtil.createJSONObject(); JSONArray secondTabDataJSONArray = JSONFactoryUtil.createJSONArray(); secondTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "version"), HtmlUtil.escape(latestFileVersion.getVersion()))); secondTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "status"), WorkflowConstants.getStatusLabel(latestFileVersion.getStatus()))); secondTabJSONObject.put("data", secondTabDataJSONArray); secondTabJSONObject.put("title", LanguageUtil.get(locale, "version")); groupsJSONArray.put(secondTabJSONObject); itemMetadataJSONObject.put("groups", groupsJSONArray); return itemMetadataJSONObject; }
From source file:com.liferay.portlet.documentlibrary.action.GetFileAction.java
License:Open Source License
protected void getFile(long fileEntryId, long folderId, String title, String version, long fileShortcutId, String uuid, long groupId, String targetExtension, ThemeDisplay themeDisplay, HttpServletRequest request, HttpServletResponse response) throws Exception { FileEntry fileEntry = null;// w ww . ja v a 2s.c o m if (Validator.isNotNull(uuid) && (groupId > 0)) { fileEntry = DLAppServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId); folderId = fileEntry.getFolderId(); } if (fileEntryId > 0) { fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId); } else if (fileShortcutId <= 0) { if (Validator.isNotNull(title)) { fileEntry = DLAppServiceUtil.getFileEntry(groupId, folderId, title); } } else { DLFileShortcut fileShortcut = DLAppServiceUtil.getFileShortcut(fileShortcutId); fileEntryId = fileShortcut.getToFileEntryId(); fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId); } if (Validator.isNull(version)) { if (Validator.isNotNull(fileEntry.getVersion())) { version = fileEntry.getVersion(); } else { throw new NoSuchFileEntryException(); } } FileVersion fileVersion = fileEntry.getFileVersion(version); InputStream is = fileVersion.getContentStream(true); String fileName = fileVersion.getTitle(); long contentLength = fileVersion.getSize(); String contentType = fileVersion.getMimeType(); if (Validator.isNotNull(targetExtension)) { String id = DLUtil.getTempFileId(fileEntry.getFileEntryId(), version); String sourceExtension = fileVersion.getExtension(); if (!fileName.endsWith(StringPool.PERIOD + sourceExtension)) { fileName += StringPool.PERIOD + sourceExtension; } File convertedFile = DocumentConversionUtil.convert(id, is, sourceExtension, targetExtension); if (convertedFile != null) { fileName = FileUtil.stripExtension(fileName).concat(StringPool.PERIOD).concat(targetExtension); is = new FileInputStream(convertedFile); contentLength = convertedFile.length(); contentType = MimeTypesUtil.getContentType(fileName); } } ServletResponseUtil.sendFile(request, response, fileName, is, contentLength, contentType); }
From source file:com.liferay.portlet.documentlibrary.util.AudioProcessorImpl.java
License:Open Source License
private void _generateAudio(FileVersion fileVersion) throws Exception { String tempFileId = DLUtil.getTempFileId(fileVersion.getFileEntryId(), fileVersion.getVersion()); File audioTempFile = _getAudioTempFile(tempFileId, fileVersion.getExtension()); File previewTempFile = getPreviewTempFile(tempFileId); try {//from w ww . j a va2 s.com if (!PrefsPropsUtil.getBoolean(PropsKeys.XUGGLER_ENABLED, PropsValues.XUGGLER_ENABLED) || _hasAudio(fileVersion)) { return; } if (_isGeneratePreview(fileVersion)) { File file = null; if (fileVersion instanceof LiferayFileVersion) { try { LiferayFileVersion liferayFileVersion = (LiferayFileVersion) fileVersion; file = liferayFileVersion.getFile(false); } catch (UnsupportedOperationException uoe) { } } if (file == null) { InputStream inputStream = fileVersion.getContentStream(false); FileUtil.write(audioTempFile, inputStream); file = audioTempFile; } try { _generateAudioXuggler(fileVersion, file, previewTempFile); } catch (Exception e) { _log.error(e, e); } } } catch (NoSuchFileEntryException nsfee) { } finally { _fileVersionIds.remove(fileVersion.getFileVersionId()); FileUtil.delete(audioTempFile); FileUtil.delete(previewTempFile); } }
From source file:com.liferay.portlet.documentlibrary.util.ImageProcessorImpl.java
License:Open Source License
@Override protected String getThumbnailType(FileVersion fileVersion) { String type = fileVersion.getExtension(); if (type.equals("jpeg")) { type = "jpg"; }//from w w w. ja v a2 s. c o m return type; }
From source file:com.liferay.portlet.documentlibrary.util.PDFProcessorImpl.java
License:Open Source License
private void _generateImages(FileVersion fileVersion) throws Exception { try {/*from w ww. j a va 2s. c om*/ if (_hasImages(fileVersion)) { return; } String extension = fileVersion.getExtension(); if (extension.equals("pdf")) { if (fileVersion instanceof LiferayFileVersion) { try { LiferayFileVersion liferayFileVersion = (LiferayFileVersion) fileVersion; File file = liferayFileVersion.getFile(false); _generateImages(fileVersion, file); return; } catch (UnsupportedOperationException uoe) { } } InputStream inputStream = fileVersion.getContentStream(false); _generateImages(fileVersion, inputStream); } else if (DocumentConversionUtil.isEnabled()) { InputStream inputStream = fileVersion.getContentStream(false); String tempFileId = DLUtil.getTempFileId(fileVersion.getFileEntryId(), fileVersion.getVersion()); File file = DocumentConversionUtil.convert(tempFileId, inputStream, extension, "pdf"); _generateImages(fileVersion, file); } } catch (NoSuchFileEntryException nsfee) { } finally { _fileVersionIds.remove(fileVersion.getFileVersionId()); } }