Author: chris.laprun(a)jboss.com
Date: 2011-08-02 17:50:32 -0400 (Tue, 02 Aug 2011)
New Revision: 6985
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java
Log:
- Rewrote getDisplayName using code from UserNode and PortalRequestContext to get proper
display of the node name...
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java 2011-08-02
21:48:34 UTC (rev 6984)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java 2011-08-02
21:50:32 UTC (rev 6985)
@@ -22,13 +22,19 @@
package org.gatein.portal.api.impl.portal;
+import org.exoplatform.commons.utils.ExpressionUtil;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.portal.application.PortalRequestContext;
+import org.exoplatform.portal.mop.Described;
+import org.exoplatform.portal.mop.description.DescriptionService;
import org.exoplatform.portal.mop.navigation.NavigationService;
import org.exoplatform.portal.mop.navigation.NodeContext;
import org.exoplatform.portal.mop.navigation.NodeModel;
import org.exoplatform.portal.mop.navigation.NodeState;
import org.exoplatform.portal.mop.navigation.Scope;
import org.exoplatform.portal.webui.util.Util;
+import org.exoplatform.services.resources.ResourceBundleManager;
import org.gatein.api.GateIn;
import org.gatein.api.id.Context;
import org.gatein.api.id.GenericContext;
@@ -41,12 +47,16 @@
import org.gatein.api.util.IterableIdentifiableCollection;
import org.gatein.api.util.Query;
import org.gatein.common.net.URLTools;
+import org.gatein.common.text.EntityEncoder;
+import org.gatein.common.util.EmptyResourceBundle;
import org.gatein.portal.api.impl.GateInImpl;
import org.gatein.portal.api.impl.util.AdaptedIterableIdentifiableCollection;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Iterator;
+import java.util.Locale;
+import java.util.ResourceBundle;
import java.util.regex.Pattern;
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
@@ -57,6 +67,8 @@
private Id<Navigation> id;
private final GateInImpl gateIn;
private URI uri;
+ private String displayName;
+ private ResourceBundle bundle;
private final static Context CONTEXT =
GenericContext.builder().requiredComponent("navigation", Navigation.class,
Pattern.compile("[a-z0-9]+")).build();
@@ -273,9 +285,67 @@
public String getDisplayName()
{
- return context.getState().getLabel();
+ // basically duplicating code from UserNode and PortalRequestContext because we
can't use it as is
+ if (displayName == null)
+ {
+ String resolvedLabel = null;
+
+ String id = context.getId();
+
+ if (context.getState().getLabel() != null)
+ {
+ resolvedLabel = ExpressionUtil.getExpressionValue(getBundle(),
context.getState().getLabel());
+ }
+ else if (id != null)
+ {
+ Locale userLocale = getUserLocale();
+ DescriptionService descriptionService = gateIn.getDescriptionService();
+ Described.State description = descriptionService.resolveDescription(id,
userLocale);
+ if (description != null)
+ {
+ resolvedLabel = description.getName();
+ }
+ }
+
+ //
+ if (resolvedLabel == null)
+ {
+ resolvedLabel = getName();
+ }
+
+ //
+ this.displayName = EntityEncoder.FULL.encode(resolvedLabel);
+ }
+ return displayName;
}
+ public Locale getUserLocale()
+ {
+ return Util.getPortalRequestContext().getLocale();
+ }
+
+
+ public ResourceBundle getBundle()
+ {
+ if (bundle == null)
+ {
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ ResourceBundleManager rbMgr =
(ResourceBundleManager)container.getComponentInstanceOfType(ResourceBundleManager.class);
+ Locale locale = Util.getPortalRequestContext().getLocale();
+ bundle = rbMgr.getNavigationResourceBundle(
+ locale.getLanguage(),
+ site.getComponent(GateInImpl.SITE_OWNER_COMPONENT),
+ site.getComponent(GateInImpl.SITE_NAME_COMPONENT));
+
+ if (bundle == null)
+ {
+ bundle = EmptyResourceBundle.INSTANCE;
+ }
+ }
+ return bundle;
+ }
+
+
public GateIn getGateIn()
{
return gateIn;
Show replies by date