Skip to content

Commit

Permalink
fix: Fix Access to Current User Locale using Context rather that UIPo…
Browse files Browse the repository at this point in the history
…rtalApplication - Meeds-io/MIPs#159
  • Loading branch information
boubaker committed Dec 8, 2024
1 parent efa2c32 commit 8c49e70
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public List<HistoryBean> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</td>
</tr>
</table>
<div style="margin: auto;width:427px;"><img src="<%=uicomponent.getLinkStateImage(Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale())%>" height="46" width="472" border="0" alt="<%=uicomponent.getStateName()%>"/><br /></div>
<div style="margin: auto;width:427px;"><img src="<%=uicomponent.getLinkStateImage(Util.getPortalRequestContext().getLocale())%>" height="46" width="472" border="0" alt="<%=uicomponent.getStateName()%>"/><br /></div>

<div class="UIAction">
<% for(action in uicomponent.getActions()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</td>
</tr>
</table>
<div style="margin: auto;width:427px;"><img src="<%=uicomponent.getLinkStateImage(Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale())%>" height="46" width="472" border="0" alt="<%=uicomponent.getStateName()%>"/><br /></div>
<div style="margin: auto;width:427px;"><img src="<%=uicomponent.getLinkStateImage(Util.getPortalRequestContext().getLocale())%>" height="46" width="472" border="0" alt="<%=uicomponent.getStateName()%>"/><br /></div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ public List<SelectItemOption<String>> 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<SelectItemOption<String>> languages = new ArrayList<>() ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() ;
Expand Down

0 comments on commit 8c49e70

Please sign in to comment.