From 8c49e70a1c59a3a760b4dc39d7e4031e6bbc1f06 Mon Sep 17 00:00:00 2001 From: Boubaker Khanfir Date: Sun, 8 Dec 2024 08:32:39 +0100 Subject: [PATCH] fix: Fix Access to Current User Locale using Context rather that UIPortalApplication - Meeds-io/MIPs#159 --- .../plugins/webui/UIPublicationLogList.java | 2 +- .../publication/UIPublicationStatus.gtmpl | 2 +- .../staticredirect/publication.gtmpl | 2 +- .../webui/viewer/AbstractCloudFileViewer.java | 2 +- .../ecm/webui/viewer/PDFViewer.java | 4 +- .../ecm/webui/viewer/TextViewer.java | 2 +- .../webui/viewer/AbstractFileForm.java | 2 +- .../component/explorer/UIDocumentInfo.java | 77 +++++++++++++------ .../explorer/UIDocumentNodeList.java | 2 +- .../explorer/search/UISearchResult.java | 2 +- .../exoplatform/wcm/webui/seo/UISEOForm.java | 2 +- .../artifacts/templates/comment/view1.gtmpl | 2 +- 12 files changed, 66 insertions(+), 35 deletions(-) diff --git a/core/publication-plugins/src/main/java/org/exoplatform/services/ecm/publication/plugins/webui/UIPublicationLogList.java b/core/publication-plugins/src/main/java/org/exoplatform/services/ecm/publication/plugins/webui/UIPublicationLogList.java index adc2c00f061..64b430a9e84 100644 --- a/core/publication-plugins/src/main/java/org/exoplatform/services/ecm/publication/plugins/webui/UIPublicationLogList.java +++ b/core/publication-plugins/src/main/java/org/exoplatform/services/ecm/publication/plugins/webui/UIPublicationLogList.java @@ -79,7 +79,7 @@ public List getLog() throws NotInPublicationLifecycleException, Exc String[] values = new String[currentLog.length - 4]; System.arraycopy(currentLog, 4, values, 0, currentLog.length-4); String description = publicationService.getLocalizedAndSubstituteLog(getCurrentNode(), - Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale(), currentLog[3], values); + Util.getPortalRequestContext().getLocale(), currentLog[3], values); bean.setDescription(description); list.add(bean); } diff --git a/core/publication-plugins/src/main/resources/groovy/wcm/webui/publication/UIPublicationStatus.gtmpl b/core/publication-plugins/src/main/resources/groovy/wcm/webui/publication/UIPublicationStatus.gtmpl index 2699048b314..2c607069b5d 100644 --- a/core/publication-plugins/src/main/resources/groovy/wcm/webui/publication/UIPublicationStatus.gtmpl +++ b/core/publication-plugins/src/main/resources/groovy/wcm/webui/publication/UIPublicationStatus.gtmpl @@ -28,7 +28,7 @@ -
<%=uicomponent.getStateName()%>
+
<%=uicomponent.getStateName()%>
<% for(action in uicomponent.getActions()) { diff --git a/core/publication-plugins/src/main/resources/resources/templates/staticredirect/publication.gtmpl b/core/publication-plugins/src/main/resources/resources/templates/staticredirect/publication.gtmpl index a735a311905..32743e39076 100644 --- a/core/publication-plugins/src/main/resources/resources/templates/staticredirect/publication.gtmpl +++ b/core/publication-plugins/src/main/resources/resources/templates/staticredirect/publication.gtmpl @@ -28,7 +28,7 @@ -
<%=uicomponent.getStateName()%>
+
<%=uicomponent.getStateName()%>
diff --git a/core/viewer/src/main/java/org/exoplatform/ecm/webui/viewer/AbstractCloudFileViewer.java b/core/viewer/src/main/java/org/exoplatform/ecm/webui/viewer/AbstractCloudFileViewer.java index ca58ac97400..1ceafdca9ef 100644 --- a/core/viewer/src/main/java/org/exoplatform/ecm/webui/viewer/AbstractCloudFileViewer.java +++ b/core/viewer/src/main/java/org/exoplatform/ecm/webui/viewer/AbstractCloudFileViewer.java @@ -127,7 +127,7 @@ public boolean isViewable() { * @return the resource bundle */ public String appRes(String key) { - Locale locale = Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale(); + Locale locale = Util.getPortalRequestContext().getLocale(); ResourceBundleService resourceBundleService = WCMCoreUtils.getService(ResourceBundleService.class); ResourceBundle resourceBundle = resourceBundleService.getResourceBundle( new String[] { "locale.clouddrive.CloudDrive", diff --git a/core/viewer/src/main/java/org/exoplatform/ecm/webui/viewer/PDFViewer.java b/core/viewer/src/main/java/org/exoplatform/ecm/webui/viewer/PDFViewer.java index 910163a1893..79a268589bd 100644 --- a/core/viewer/src/main/java/org/exoplatform/ecm/webui/viewer/PDFViewer.java +++ b/core/viewer/src/main/java/org/exoplatform/ecm/webui/viewer/PDFViewer.java @@ -156,7 +156,7 @@ public int getMaximumOfPage() throws Exception { public String getResourceBundle(String key) { try { - Locale locale = Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale(); + Locale locale = Util.getPortalRequestContext().getLocale(); ResourceBundleService resourceBundleService = WCMCoreUtils.getService(ResourceBundleService.class); ResourceBundle resourceBundle = resourceBundleService.getResourceBundle(localeFile, locale, this.getClass().getClassLoader()); @@ -168,7 +168,7 @@ public String getResourceBundle(String key) { public String getResource(String key) { try { - Locale locale = Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale(); + Locale locale = Util.getPortalRequestContext().getLocale(); ResourceBundleService resourceBundleService = WCMCoreUtils.getService(ResourceBundleService.class); sharedResourcesBundleNames = resourceBundleService.getSharedResourceBundleNames(); sharedResourceBundle = resourceBundleService.getResourceBundle(sharedResourcesBundleNames, locale); diff --git a/core/viewer/src/main/java/org/exoplatform/ecm/webui/viewer/TextViewer.java b/core/viewer/src/main/java/org/exoplatform/ecm/webui/viewer/TextViewer.java index 0dd5df0c53b..2c1e294b081 100644 --- a/core/viewer/src/main/java/org/exoplatform/ecm/webui/viewer/TextViewer.java +++ b/core/viewer/src/main/java/org/exoplatform/ecm/webui/viewer/TextViewer.java @@ -46,7 +46,7 @@ public TextViewer() throws Exception { public String getResource(String key) { try { - Locale locale = Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale(); + Locale locale = Util.getPortalRequestContext().getLocale(); ResourceBundleService resourceBundleService = WCMCoreUtils.getService(ResourceBundleService.class); sharedResourcesBundleNames = resourceBundleService.getSharedResourceBundleNames(); sharedResourceBundle = resourceBundleService.getResourceBundle(sharedResourcesBundleNames, locale); diff --git a/core/webui-clouddrives/src/main/java/org/exoplatform/services/cms/clouddrives/webui/viewer/AbstractFileForm.java b/core/webui-clouddrives/src/main/java/org/exoplatform/services/cms/clouddrives/webui/viewer/AbstractFileForm.java index ca560e0a427..946fb8c94b7 100644 --- a/core/webui-clouddrives/src/main/java/org/exoplatform/services/cms/clouddrives/webui/viewer/AbstractFileForm.java +++ b/core/webui-clouddrives/src/main/java/org/exoplatform/services/cms/clouddrives/webui/viewer/AbstractFileForm.java @@ -107,7 +107,7 @@ public boolean isViewable() { * @return the resource bundle */ public String appRes(String key) { - Locale locale = Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale(); + Locale locale = Util.getPortalRequestContext().getLocale(); ResourceBundleService resourceBundleService = WCMCoreUtils.getService(ResourceBundleService.class); ResourceBundle resourceBundle = resourceBundleService.getResourceBundle( new String[] { "locale.clouddrive.CloudDrive", diff --git a/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/UIDocumentInfo.java b/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/UIDocumentInfo.java index 2adcb99149c..f8daa05fbb4 100644 --- a/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/UIDocumentInfo.java +++ b/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/UIDocumentInfo.java @@ -16,7 +16,49 @@ */ package org.exoplatform.ecm.webui.component.explorer; +import java.awt.Image; +import java.io.InputStream; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; + +import javax.imageio.ImageIO; +import javax.jcr.AccessDeniedException; +import javax.jcr.Item; +import javax.jcr.ItemNotFoundException; +import javax.jcr.Node; +import javax.jcr.NodeIterator; +import javax.jcr.PathNotFoundException; +import javax.jcr.Property; +import javax.jcr.PropertyType; +import javax.jcr.ReferentialIntegrityException; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.Value; +import javax.jcr.lock.LockException; +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.nodetype.NodeDefinition; +import javax.jcr.nodetype.NodeType; +import javax.jcr.query.Query; +import javax.jcr.query.QueryManager; +import javax.jcr.query.QueryResult; +import javax.jcr.version.VersionException; + import org.apache.commons.lang3.StringUtils; + import org.exoplatform.commons.utils.LazyPageList; import org.exoplatform.commons.utils.ListAccess; import org.exoplatform.commons.utils.ListAccessImpl; @@ -38,7 +80,6 @@ import org.exoplatform.ecm.webui.utils.PermissionUtil; import org.exoplatform.ecm.webui.utils.Utils; import org.exoplatform.portal.webui.util.Util; -import org.exoplatform.portal.webui.workspace.UIPortalApplication; import org.exoplatform.resolver.ResourceResolver; import org.exoplatform.services.cms.clipboard.ClipboardService; import org.exoplatform.services.cms.comments.CommentsService; @@ -48,7 +89,11 @@ import org.exoplatform.services.cms.drives.DriveData; import org.exoplatform.services.cms.drives.ManageDriveService; import org.exoplatform.services.cms.i18n.MultiLanguageService; -import org.exoplatform.services.cms.link.*; +import org.exoplatform.services.cms.link.ItemLinkAware; +import org.exoplatform.services.cms.link.LinkManager; +import org.exoplatform.services.cms.link.LinkUtils; +import org.exoplatform.services.cms.link.NodeFinder; +import org.exoplatform.services.cms.link.NodeLinkAware; import org.exoplatform.services.cms.templates.TemplateService; import org.exoplatform.services.cms.thumbnail.ThumbnailPlugin; import org.exoplatform.services.cms.thumbnail.ThumbnailService; @@ -74,30 +119,16 @@ import org.exoplatform.webui.application.portlet.PortletRequestContext; import org.exoplatform.webui.config.annotation.ComponentConfig; import org.exoplatform.webui.config.annotation.EventConfig; -import org.exoplatform.webui.core.*; +import org.exoplatform.webui.core.UIApplication; +import org.exoplatform.webui.core.UIComponent; +import org.exoplatform.webui.core.UIPageIterator; +import org.exoplatform.webui.core.UIPopupContainer; +import org.exoplatform.webui.core.UIRightClickPopupMenu; import org.exoplatform.webui.event.Event; import org.exoplatform.webui.event.EventListener; import org.exoplatform.webui.exception.MessageException; import org.exoplatform.webui.ext.UIExtensionManager; -import javax.imageio.ImageIO; -import javax.jcr.*; -import javax.jcr.lock.LockException; -import javax.jcr.nodetype.ConstraintViolationException; -import javax.jcr.nodetype.NodeDefinition; -import javax.jcr.nodetype.NodeType; -import javax.jcr.query.Query; -import javax.jcr.query.QueryManager; -import javax.jcr.query.QueryResult; -import javax.jcr.version.VersionException; -import java.awt.*; -import java.io.InputStream; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.List; -import java.util.regex.Matcher; - /** * Created by The eXo Platform SARL * Author : Dang Van Minh @@ -967,8 +998,8 @@ public String getThumbnailSize(Node node) throws Exception { } public DateFormat getSimpleDateFormat() { - Locale locale = Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale(); - return SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT, locale); + Locale locale = Util.getPortalRequestContext().getLocale(); + return DateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT, locale); } public boolean isSymLink(Node node) throws RepositoryException { diff --git a/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/UIDocumentNodeList.java b/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/UIDocumentNodeList.java index e4178f648c2..73af937e4f5 100644 --- a/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/UIDocumentNodeList.java +++ b/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/UIDocumentNodeList.java @@ -243,7 +243,7 @@ public String getDatePropertyValue(Node node, String propertyName) throws Except try { Property property = node.getProperty(propertyName); if(property != null) { - Locale locale = Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale(); + Locale locale = Util.getPortalRequestContext().getLocale(); DateFormat dateFormat = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT, locale); return dateFormat.format(property.getDate().getTime()); } diff --git a/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UISearchResult.java b/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UISearchResult.java index 903c69453be..3ba7905e2db 100644 --- a/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UISearchResult.java +++ b/core/webui-explorer/src/main/java/org/exoplatform/ecm/webui/component/explorer/search/UISearchResult.java @@ -163,7 +163,7 @@ public List getCurrentList() throws Exception { } public DateFormat getSimpleDateFormat() { - Locale locale = Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale(); + Locale locale = Util.getPortalRequestContext().getLocale(); return SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT, locale); } diff --git a/core/webui-seo/src/main/java/org/exoplatform/wcm/webui/seo/UISEOForm.java b/core/webui-seo/src/main/java/org/exoplatform/wcm/webui/seo/UISEOForm.java index d995fed1bd3..26af89f8910 100644 --- a/core/webui-seo/src/main/java/org/exoplatform/wcm/webui/seo/UISEOForm.java +++ b/core/webui-seo/src/main/java/org/exoplatform/wcm/webui/seo/UISEOForm.java @@ -632,7 +632,7 @@ public List> getLanguages() throws Exception { // Get default locale Locale defaultLocale = Locale.getDefault(); // set default locale to current user selected language - Locale.setDefault(Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale()); + Locale.setDefault(Util.getPortalRequestContext().getLocale()); LocaleConfigService localService = WCMCoreUtils.getService(LocaleConfigService.class) ; List> languages = new ArrayList<>() ; diff --git a/ecm-wcm-extension/src/main/webapp/WEB-INF/conf/dms-extension/dms/artifacts/templates/comment/view1.gtmpl b/ecm-wcm-extension/src/main/webapp/WEB-INF/conf/dms-extension/dms/artifacts/templates/comment/view1.gtmpl index 87feb39a074..da646fec06c 100644 --- a/ecm-wcm-extension/src/main/webapp/WEB-INF/conf/dms-extension/dms/artifacts/templates/comment/view1.gtmpl +++ b/ecm-wcm-extension/src/main/webapp/WEB-INF/conf/dms-extension/dms/artifacts/templates/comment/view1.gtmpl @@ -14,7 +14,7 @@ import org.exoplatform.web.application.Parameter ; def commentsNumber = commentsList.size(); def uicomment = uicomponent.getCommentComponent(); if(commentsNumber > 0) { - Locale locale = Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale() ; + Locale locale = Util.getPortalRequestContext().getLocale() ; java.text.SimpleDateFormat commentDateFormat = new java.text.SimpleDateFormat("h:mm a. EEE, MMM d, yyyy", locale) ; def lastComment = commentsList.get(0) ; def rcontext = _ctx.getRequestContext() ;