Skip to content

Commit

Permalink
Support for Liferay Portal 7.4 GA125
Browse files Browse the repository at this point in the history
  • Loading branch information
villeman7 committed Oct 4, 2024
1 parent c63f88c commit 4b12e20
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 41 deletions.
2 changes: 1 addition & 1 deletion bnd.bnd
Original file line number Diff line number Diff line change
@@ -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,\
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion src/main/java/onlyoffice/integration/api/OnlyOfficeApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
45 changes: 31 additions & 14 deletions src/main/java/onlyoffice/integration/ui/EditMenuContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -108,26 +105,30 @@ public EditMenuContext(
}

public Menu getMenu() throws PortalException {
Menu menu = super.getMenu();
List<MenuItem> list = menu.getMenuItems();

List<MenuItem> menuItems = new ArrayList<MenuItem>();
List<DropdownItem> 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<ToolbarItem> getToolbarItems() throws PortalException {
List<ToolbarItem> toolbarItems = super.getToolbarItems();
Expand All @@ -143,7 +144,22 @@ public List<ToolbarItem> 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";

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -55,8 +54,8 @@ public void updatePortletTitleMenuItems(List<MenuItem> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

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;
import com.liferay.portal.kernel.log.LogFactoryUtil;
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;

Expand All @@ -40,12 +40,11 @@ public OnlyofficePreviewRendererProvider(ServletContext servletContext, OnlyOffi
}

@Override
public Optional<DLPreviewRenderer> 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());
Expand All @@ -55,17 +54,24 @@ public Optional<DLPreviewRenderer> getPreviewDLPreviewRendererOptional(FileVersi
}

requestDispatcher.include(request, response);
});
};
}

@Override
public Optional<DLPreviewRenderer> 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<String> getMimeTypes() {
// TODO Auto-generated method stub
return null;
}

}

0 comments on commit 4b12e20

Please sign in to comment.