diff --git a/bnd.bnd b/bnd.bnd index 75aacf7..334fb42 100644 --- a/bnd.bnd +++ b/bnd.bnd @@ -1,7 +1,7 @@ Bundle-Name: onlyoffice-integration-web Bundle-SymbolicName: onlyoffice.integration.web Bundle-Version: 2.4.0 -Import-Package: !org.apache.log,*;version="0" +Import-Package: !org.apache.log,!org.apache.log4j,*;version="0" -metatype: * -includeresource:\ lib/httpclient.jar=httpclient-*.jar,\ \ No newline at end of file diff --git a/build.gradle b/build.gradle index e8df203..174d941 100644 --- a/build.gradle +++ b/build.gradle @@ -20,9 +20,11 @@ dependencies { compileOnly group: "org.osgi", name: "org.osgi.framework", version: "1.9.0" compileOnly group: "org.json", name: "json" compileOnly group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0" + compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.clay", version: "4.0.0" compileInclude group: "org.apache.httpcomponents", name: "httpclient", version: "4.5.8" compileInclude group: "org.apache.avalon.framework", name: "avalon-framework-api", version: "4.3.1" + compileInclude group: "com.liferay", name: "com.liferay.petra.function", version: "5.7.2" cssBuilder group: "com.liferay", name: "com.liferay.css.builder", version: "3.0.2" } \ No newline at end of file diff --git a/src/main/java/onlyoffice/integration/api/OnlyOfficeApi.java b/src/main/java/onlyoffice/integration/api/OnlyOfficeApi.java index fa8ec0e..e229474 100644 --- a/src/main/java/onlyoffice/integration/api/OnlyOfficeApi.java +++ b/src/main/java/onlyoffice/integration/api/OnlyOfficeApi.java @@ -125,7 +125,8 @@ private void saveAs (HttpServletRequest request, HttpServletResponse response) t String uniqueFileName = DLUtil.getUniqueFileName( file.getRepositoryId(), file.getFolderId(), - fileName.substring(0, fileName.lastIndexOf(".") + 1) + fileType + fileName.substring(0, fileName.lastIndexOf(".") + 1) + fileType, + false ); ServiceContext serviceContext = ServiceContextFactory.getInstance(OnlyOfficeDocumentConvert.class.getName(), request); diff --git a/src/main/java/onlyoffice/integration/api/OnlyOfficeDocumentApi.java b/src/main/java/onlyoffice/integration/api/OnlyOfficeDocumentApi.java index 57a7f0f..36889f2 100644 --- a/src/main/java/onlyoffice/integration/api/OnlyOfficeDocumentApi.java +++ b/src/main/java/onlyoffice/integration/api/OnlyOfficeDocumentApi.java @@ -22,7 +22,6 @@ import java.io.InputStream; import java.net.URL; import java.net.URLConnection; -import java.util.Scanner; import javax.servlet.Servlet; import javax.servlet.ServletException; @@ -250,10 +249,10 @@ private void updateFile(FileEntry fileEntry, Long userId, String url, DLVersionN InputStream in = con.getInputStream(); _dlApp.updateFileEntry(userId, fileEntry.getFileEntryId(), fileEntry.getFileName(), fileEntry.getMimeType(), - fileEntry.getTitle(), fileEntry.getDescription(), "ONLYOFFICE Edit",dlVersionNumberIncrease, in, - con.getContentLength(), serviceContext); + fileEntry.getTitle(), fileEntry.getDescription(), "", "", dlVersionNumberIncrease, in, + con.getContentLength(), null, null, null, serviceContext); - _dlAppService.checkInFileEntry(fileEntry.getFileEntryId(), dlVersionNumberIncrease, "ONLYOFFICE Edit", serviceContext); + _dlAppService.checkInFileEntry(fileEntry.getFileEntryId(), dlVersionNumberIncrease, "", serviceContext); } catch (Exception e) { String msg = "Couldn't download or save file: " + e.getMessage(); _log.error(msg, e); diff --git a/src/main/java/onlyoffice/integration/api/OnlyOfficeDocumentConvert.java b/src/main/java/onlyoffice/integration/api/OnlyOfficeDocumentConvert.java index 3d68dd0..a6053aa 100644 --- a/src/main/java/onlyoffice/integration/api/OnlyOfficeDocumentConvert.java +++ b/src/main/java/onlyoffice/integration/api/OnlyOfficeDocumentConvert.java @@ -117,9 +117,9 @@ private void savefile(HttpServletRequest request, FileEntry fileEntry, String ur InputStream in = con.getInputStream(); ServiceContext serviceContext = ServiceContextFactory.getInstance(OnlyOfficeDocumentConvert.class.getName(), request); - _dlApp.addFileEntry(user.getUserId(), fileEntry.getRepositoryId(), fileEntry.getFolderId(), filename, - _convert.getMimeType(_convert.convertsTo(fileEntry.getExtension())), filename, fileEntry.getDescription(), "ONLYOFFICE Convert", - in, con.getContentLength(), serviceContext); + _dlApp.addFileEntry(filename, user.getUserId(), fileEntry.getRepositoryId(), fileEntry.getFolderId(), filename, + _convert.getMimeType(_convert.convertsTo(fileEntry.getExtension())), filename, fileEntry.getDescription(), "", + "", in, con.getContentLength(), null, null, null, serviceContext); _log.info("Document saved."); } diff --git a/src/main/java/onlyoffice/integration/permission/OnlyOfficePermissionUtils.java b/src/main/java/onlyoffice/integration/permission/OnlyOfficePermissionUtils.java index 5f838c8..d8a3059 100644 --- a/src/main/java/onlyoffice/integration/permission/OnlyOfficePermissionUtils.java +++ b/src/main/java/onlyoffice/integration/permission/OnlyOfficePermissionUtils.java @@ -26,7 +26,6 @@ import com.liferay.portal.kernel.security.permission.PermissionChecker; import com.liferay.portal.kernel.security.permission.PermissionCheckerFactoryUtil; import com.liferay.portal.kernel.security.permission.resource.ModelResourcePermission; -import com.liferay.portal.kernel.security.permission.resource.ModelResourcePermissionHelper; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @@ -38,8 +37,7 @@ public static boolean saveAs(FileEntry file, User user) throws PortalException { PermissionChecker checker = PermissionCheckerFactoryUtil.create(user); return file.containsPermission(checker, ActionKeys.VIEW) && - ModelResourcePermissionHelper.contains( - _folderModelResourcePermission, checker, file.getGroupId(), + _folderModelResourcePermission.contains(checker, file.getFolderId(), ActionKeys.ADD_DOCUMENT); } diff --git a/src/main/java/onlyoffice/integration/ui/ConvertActionPortlet.java b/src/main/java/onlyoffice/integration/ui/ConvertActionPortlet.java index a648e83..54fd13d 100644 --- a/src/main/java/onlyoffice/integration/ui/ConvertActionPortlet.java +++ b/src/main/java/onlyoffice/integration/ui/ConvertActionPortlet.java @@ -27,6 +27,7 @@ @Component( immediate = true, property = { + "javax.portlet.version=3.0", "com.liferay.portlet.add-default-resource=true", "com.liferay.portlet.display-category=category.hidden", "com.liferay.portlet.header-portlet-css=/css/main.css", diff --git a/src/main/java/onlyoffice/integration/ui/CreateMVCActionCommand.java b/src/main/java/onlyoffice/integration/ui/CreateMVCActionCommand.java index d23de82..44a9b39 100644 --- a/src/main/java/onlyoffice/integration/ui/CreateMVCActionCommand.java +++ b/src/main/java/onlyoffice/integration/ui/CreateMVCActionCommand.java @@ -89,7 +89,7 @@ protected void doProcessAction(ActionRequest actionRequest, ActionResponse actio File sourceFile = FileUtil.createTempFile(streamSourceFile); String mimeType = MimeTypesUtil.getContentType(sourceFile); - String uniqueFileName = DLUtil.getUniqueFileName(repositoryId, folderId, title + "." + type); + String uniqueFileName = DLUtil.getUniqueFileName(repositoryId, folderId, title + "." + type, false); ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(), actionRequest); diff --git a/src/main/java/onlyoffice/integration/ui/CreateMVCRenderCommand.java b/src/main/java/onlyoffice/integration/ui/CreateMVCRenderCommand.java index 840659a..c1676df 100644 --- a/src/main/java/onlyoffice/integration/ui/CreateMVCRenderCommand.java +++ b/src/main/java/onlyoffice/integration/ui/CreateMVCRenderCommand.java @@ -20,7 +20,7 @@ import com.liferay.document.library.constants.DLPortletKeys; import com.liferay.portal.kernel.portlet.bridges.mvc.MVCRenderCommand; -import com.liferay.portal.kernel.portlet.bridges.mvc.MVCRenderConstants; +import com.liferay.portal.kernel.portlet.bridges.mvc.constants.MVCRenderConstants; import com.liferay.portal.kernel.util.PortalUtil; import javax.portlet.PortletException; import javax.portlet.RenderRequest; diff --git a/src/main/java/onlyoffice/integration/ui/EditActionPortlet.java b/src/main/java/onlyoffice/integration/ui/EditActionPortlet.java index f9a209d..fb55d13 100644 --- a/src/main/java/onlyoffice/integration/ui/EditActionPortlet.java +++ b/src/main/java/onlyoffice/integration/ui/EditActionPortlet.java @@ -27,6 +27,7 @@ @Component( immediate = true, property = { + "javax.portlet.version=3.0", "com.liferay.portlet.add-default-resource=true", "com.liferay.portlet.display-category=category.hidden", "com.liferay.portlet.header-portlet-css=/css/main.css", diff --git a/src/main/java/onlyoffice/integration/ui/EditMenuContext.java b/src/main/java/onlyoffice/integration/ui/EditMenuContext.java index e93317a..d88912f 100644 --- a/src/main/java/onlyoffice/integration/ui/EditMenuContext.java +++ b/src/main/java/onlyoffice/integration/ui/EditMenuContext.java @@ -18,11 +18,11 @@ package onlyoffice.integration.ui; +import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; import java.util.UUID; -import javax.portlet.MutableRenderParameters; import javax.portlet.PortletRequest; import javax.portlet.PortletURL; import javax.portlet.WindowStateException; @@ -31,6 +31,7 @@ import com.liferay.document.library.display.context.BaseDLViewFileVersionDisplayContext; import com.liferay.document.library.display.context.DLViewFileVersionDisplayContext; +import com.liferay.frontend.taglib.clay.servlet.taglib.util.DropdownItem; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.language.LanguageUtil; import com.liferay.portal.kernel.log.Log; @@ -44,18 +45,14 @@ import com.liferay.portal.kernel.security.permission.PermissionChecker; import com.liferay.portal.kernel.security.permission.PermissionCheckerFactory; import com.liferay.portal.kernel.servlet.taglib.ui.JavaScriptMenuItem; -import com.liferay.portal.kernel.servlet.taglib.ui.JavaScriptToolbarItem; import com.liferay.portal.kernel.servlet.taglib.ui.JavaScriptUIItem; import com.liferay.portal.kernel.servlet.taglib.ui.Menu; import com.liferay.portal.kernel.servlet.taglib.ui.MenuItem; -import com.liferay.portal.kernel.servlet.taglib.ui.ToolbarItem; import com.liferay.portal.kernel.servlet.taglib.ui.URLMenuItem; -import com.liferay.portal.kernel.servlet.taglib.ui.URLToolbarItem; import com.liferay.portal.kernel.servlet.taglib.ui.URLUIItem; import com.liferay.portal.kernel.settings.PortletInstanceSettingsLocator; import com.liferay.portal.kernel.settings.Settings; import com.liferay.portal.kernel.settings.SettingsException; -import com.liferay.portal.kernel.settings.SettingsFactoryUtil; import com.liferay.portal.kernel.settings.TypedSettings; import com.liferay.portal.kernel.theme.PortletDisplay; import com.liferay.portal.kernel.theme.ThemeDisplay; @@ -108,26 +105,30 @@ public EditMenuContext( } public Menu getMenu() throws PortalException { - Menu menu = super.getMenu(); - List list = menu.getMenuItems(); - + List menuItems = new ArrayList(); + List list = super.getActionDropdownItems(); + for (DropdownItem dropdownItem : list) { + MenuItem menuItem = DropdownItemToMenuItem(dropdownItem); + menuItems.add(menuItem); + } if (showAction()) { if (_canView) { URLMenuItem item = new URLMenuItem(); InitViewItem(item); - list.add(item); + menuItems.add(item); } if (_canConvert) { JavaScriptMenuItem item = new JavaScriptMenuItem(); InitConvertItem(item); - list.add(item); + menuItems.add(item); } } - + Menu menu = new Menu(); + menu.setMenuItems(menuItems); return menu; } - @Override + /* public List getToolbarItems() throws PortalException { List toolbarItems = super.getToolbarItems(); @@ -143,7 +144,22 @@ public List getToolbarItems() throws PortalException { } return toolbarItems; } + */ + + private MenuItem DropdownItemToMenuItem(DropdownItem dropdownItem) { + URLMenuItem menuItem = new URLMenuItem(); + if (dropdownItem.get("icon") != null) { + menuItem.setIcon((String)dropdownItem.get("icon")); + } + String key = (String)dropdownItem.get("key"); + menuItem.setKey(key); + menuItem.setLabel(LanguageUtil.get(request, _resourceBundle, key)); + menuItem.setTarget("_blank"); + menuItem.setURL(getDocUrl()); + return menuItem; + } + private void InitViewItem(URLUIItem item) { String labelKey = "onlyoffice-context-action-view"; @@ -229,9 +245,10 @@ private boolean showAction() throws SettingsException { return true; } - Settings settings = SettingsFactoryUtil.getSettings( + PortletInstanceSettingsLocator settingsLocator = new PortletInstanceSettingsLocator( - _themeDisplay.getLayout(), portletDisplay.getId())); + _themeDisplay.getLayout(), portletDisplay.getId()); + Settings settings = settingsLocator.getSettings(); TypedSettings typedSettings = new TypedSettings(settings); diff --git a/src/main/java/onlyoffice/integration/ui/EditToolbarContributorContext.java b/src/main/java/onlyoffice/integration/ui/EditToolbarContributorContext.java index 1bbbf35..736f433 100644 --- a/src/main/java/onlyoffice/integration/ui/EditToolbarContributorContext.java +++ b/src/main/java/onlyoffice/integration/ui/EditToolbarContributorContext.java @@ -28,7 +28,6 @@ import com.liferay.portal.kernel.repository.model.Folder; import com.liferay.portal.kernel.security.permission.ActionKeys; import com.liferay.portal.kernel.security.permission.resource.ModelResourcePermission; -import com.liferay.portal.kernel.security.permission.resource.ModelResourcePermissionHelper; import com.liferay.portal.kernel.servlet.taglib.ui.MenuItem; import com.liferay.portal.kernel.servlet.taglib.ui.URLMenuItem; import com.liferay.portal.kernel.theme.PortletDisplay; @@ -55,8 +54,8 @@ public void updatePortletTitleMenuItems(List menuItems, Folder folder, PortletRequest portletRequest, PortletResponse portletResponse) { try { long folderId = folder != null ? folder.getFolderId() : 0L; - Boolean hasPermission = ModelResourcePermissionHelper.contains(_dlFolderModelResourcePermission, - themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), folderId, ActionKeys.ADD_DOCUMENT); + Boolean hasPermission = _dlFolderModelResourcePermission.contains( + themeDisplay.getPermissionChecker(), folderId, ActionKeys.ADD_DOCUMENT); if (hasPermission) { Layout layout = themeDisplay.getLayout(); diff --git a/src/main/java/onlyoffice/integration/ui/OnlyofficePreviewRendererProvider.java b/src/main/java/onlyoffice/integration/ui/OnlyofficePreviewRendererProvider.java index 9eb5c89..15e59e9 100644 --- a/src/main/java/onlyoffice/integration/ui/OnlyofficePreviewRendererProvider.java +++ b/src/main/java/onlyoffice/integration/ui/OnlyofficePreviewRendererProvider.java @@ -18,6 +18,8 @@ package onlyoffice.integration.ui; +import java.util.Set; + import com.liferay.document.library.preview.DLPreviewRenderer; import com.liferay.document.library.preview.DLPreviewRendererProvider; import com.liferay.portal.kernel.log.Log; @@ -25,8 +27,6 @@ import com.liferay.portal.kernel.repository.model.FileVersion; import com.liferay.portal.kernel.util.WebKeys; -import java.util.Optional; - import javax.servlet.RequestDispatcher; import javax.servlet.ServletContext; @@ -40,12 +40,11 @@ public OnlyofficePreviewRendererProvider(ServletContext servletContext, OnlyOffi } @Override - public Optional getPreviewDLPreviewRendererOptional(FileVersion fileVersion) { + public DLPreviewRenderer getPreviewDLPreviewRenderer(FileVersion fileVersion) { if (!_config.webPreview()) { - return Optional.empty(); + return null; } - - return Optional.of( (request, response) -> { + return (request, response) -> { RequestDispatcher requestDispatcher = _servletContext.getRequestDispatcher("/preview.jsp"); request.setAttribute("fileEntryId", fileVersion.getFileEntryId()); @@ -55,17 +54,24 @@ public Optional getPreviewDLPreviewRendererOptional(FileVersi } requestDispatcher.include(request, response); - }); + }; } - + @Override - public Optional getThumbnailDLPreviewRendererOptional(FileVersion fileVersion) { + public DLPreviewRenderer getThumbnailDLPreviewRenderer(FileVersion fileVersion) { // TODO Auto-generated method stub - return Optional.empty(); + return null; } private OnlyOfficeConfigManager _config; private final ServletContext _servletContext; private static final Log _log = LogFactoryUtil.getLog(OnlyofficePreviewRendererProvider.class); + + @Override + public Set getMimeTypes() { + // TODO Auto-generated method stub + return null; + } + }