Author: julien_viet
Date: 2010-11-30 15:49:57 -0500 (Tue, 30 Nov 2010)
New Revision: 5389
Modified:
portal/branches/navcontroller/component/resources/src/main/java/org/exoplatform/services/resources/LocaleContextInfo.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/url/ControllerURL.java
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/conf/default-router.xml
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURLProvider.java
Log:
start to implement language in URL
Modified:
portal/branches/navcontroller/component/resources/src/main/java/org/exoplatform/services/resources/LocaleContextInfo.java
===================================================================
---
portal/branches/navcontroller/component/resources/src/main/java/org/exoplatform/services/resources/LocaleContextInfo.java 2010-11-30
18:14:32 UTC (rev 5388)
+++
portal/branches/navcontroller/component/resources/src/main/java/org/exoplatform/services/resources/LocaleContextInfo.java 2010-11-30
20:49:57 UTC (rev 5389)
@@ -38,6 +38,7 @@
private Locale userProfileLocale;
private String remoteUser;
private Locale portalLocale;
+ private Locale requestLocale;
/**
* Setter for supportedLocales
@@ -148,6 +149,24 @@
}
/**
+ * Getter for requestLocale
+ * @return requestLocale
+ */
+ public Locale getRequestLocale()
+ {
+ return requestLocale;
+ }
+
+ /**
+ * Setter for requestLocale
+ * @param requestLocale default locale configured for the request
+ */
+ public void setRequestLocale(Locale requestLocale)
+ {
+ this.requestLocale = requestLocale;
+ }
+
+ /**
* Helper method that returns the locale only if it's supported by portal.
* Otherwise it returns null.
*
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/url/ControllerURL.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/url/ControllerURL.java 2010-11-30
18:14:32 UTC (rev 5388)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/url/ControllerURL.java 2010-11-30
20:49:57 UTC (rev 5389)
@@ -21,6 +21,7 @@
import org.gatein.common.util.ParameterMap;
+import java.util.Locale;
import java.util.Map;
/**
@@ -50,14 +51,18 @@
/** . */
protected MimeType mimeType;
+ /** . */
+ private Locale locale;
+
/**
* Create a resource URL instance.
*
* @param locator the resource locator that can't be null
* @param ajax the ajax mode
+ * @param locale the locale
* @throws NullPointerException if the resource locator is null
*/
- public ControllerURL(L locator, Boolean ajax) throws NullPointerException
+ public ControllerURL(L locator, Boolean ajax, Locale locale) throws
NullPointerException
{
if (locator == null)
{
@@ -67,6 +72,7 @@
//
this.locator = locator;
this.ajax = ajax;
+ this.locale = locale;
this.confirm = null;
this.queryParams = null;
this.mimeType = null;
@@ -170,6 +176,16 @@
this.mimeType = mimeType;
}
+ public Locale getLocale()
+ {
+ return locale;
+ }
+
+ public void setLocale(Locale locale)
+ {
+ this.locale = locale;
+ }
+
public Map<String, String[]> getQueryParameters()
{
if (queryParams == null)
Modified:
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/conf/default-router.xml
===================================================================
---
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/conf/default-router.xml 2010-11-30
18:14:32 UTC (rev 5388)
+++
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/conf/default-router.xml 2010-11-30
20:49:57 UTC (rev 5389)
@@ -13,29 +13,35 @@
<request-param qname="gtn:action" name="portal:action"
required="false"/>
<request-param qname="gtn:objectid" name="objectId"
required="false"/>
+ <!-- Language in URL -->
+
<!-- The public access -->
- <route path="/public/{gtn:sitename}{gtn:path}">
+ <route path="/{gtn:lang}public/{gtn:sitename}{gtn:path}">
+ <path-param qname="gtn:lang" pattern="([A-Za-z]{2}/)?"
encoding="preserve-path"/>
<route-param qname="gtn:access" value="public"/>
<route-param qname="gtn:sitetype" value="portal"/>
<path-param qname="gtn:path" pattern=".*"
encoding="preserve-path"/>
</route>
<!-- The private access -->
- <route path="/private/{gtn:sitename}{gtn:path}">
+ <route path="/{gtn:lang}private/{gtn:sitename}{gtn:path}">
+ <path-param qname="gtn:lang" pattern="([A-Za-z]{2}/)?"
encoding="preserve-path"/>
<route-param qname="gtn:access" value="private"/>
<route-param qname="gtn:sitetype" value="portal"/>
<path-param qname="gtn:path" pattern=".*"
encoding="preserve-path"/>
</route>
<!-- The group access -->
- <route path="/groups/{gtn:sitename}{gtn:path}">
+ <route path="/{gtn:lang}groups/{gtn:sitename}{gtn:path}">
+ <path-param qname="gtn:lang" pattern="([A-Za-z]{2}/)?"
encoding="preserve-path"/>
<route-param qname="gtn:access" value="private"/>
<route-param qname="gtn:sitetype" value="group"/>
<path-param qname="gtn:path" pattern=".*"
encoding="preserve-path"/>
</route>
<!-- The user access -->
- <route path="/users/{gtn:sitename}{gtn:path}">
+ <route path="/{gtn:lang}users/{gtn:sitename}{gtn:path}">
+ <path-param qname="gtn:lang" pattern="([A-Za-z]{2}/)?"
encoding="preserve-path"/>
<route-param qname="gtn:access" value="private"/>
<route-param qname="gtn:sitetype" value="user"/>
<path-param qname="gtn:path" pattern=".*"
encoding="preserve-path"/>
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-11-30
18:14:32 UTC (rev 5388)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-11-30
20:49:57 UTC (rev 5389)
@@ -118,6 +118,9 @@
/** The site name decoded from the request. */
private final String siteName;
+ /** The locale from the request. */
+ private final Locale requestLocale;
+
/** . */
private final HttpServletRequest request_;
@@ -171,7 +174,8 @@
String requestSiteType,
String requestSiteName,
String requestPath,
- String access) throws Exception
+ String access,
+ Locale requestLocale) throws Exception
{
super(app);
@@ -242,6 +246,7 @@
this.siteName = requestSiteName;
this.nodePath_ = requestPath;
this.access = access;
+ this.requestLocale = requestLocale;
// portalURI = requestURI_.substring(0, requestURI_.lastIndexOf(nodePath_)) +
"/";
Map<QualifiedName, String> tmp = new HashMap<QualifiedName, String>();
@@ -273,7 +278,7 @@
@Override
public <R, L extends ResourceLocator<R>> ControllerURL<R, L>
newURL(ResourceType<R, L> resourceType, L locator)
{
- return new PortalURL<R, L>(controllerContext, locator, false, siteType,
siteName, access);
+ return new PortalURL<R, L>(controllerContext, locator, false, requestLocale,
siteType, siteName, access);
}
public ControllerContext getControllerContext()
@@ -332,6 +337,11 @@
return ((UIPortalApplication)uiApplication_).getOrientation();
}
+ public Locale getRequestLocale()
+ {
+ return requestLocale;
+ }
+
public void setLocale(Locale locale)
{
this.locale = locale;
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2010-11-30
18:14:32 UTC (rev 5388)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2010-11-30
20:49:57 UTC (rev 5389)
@@ -34,6 +34,7 @@
import org.exoplatform.webui.core.UIApplication;
import java.util.List;
+import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -68,6 +69,9 @@
/** . */
public static final QualifiedName ACCESS = QualifiedName.create("gtn",
"access");
+ /** . */
+ public static final QualifiedName LANG = QualifiedName.create("gtn",
"lang");
+
public String getHandlerName()
{
return "portal";
@@ -113,13 +117,25 @@
String requestSiteName = controllerContext.getParameter(REQUEST_SITE_NAME);
String access = controllerContext.getParameter(ACCESS);
+ //
+ Locale requestLocale;
+ String lang = controllerContext.getParameter(LANG);
+ if (lang.length() == 0)
+ {
+ requestLocale = null;
+ }
+ else
+ {
+ requestLocale = new Locale(lang.substring(0, 2));
+ }
+
if (requestSiteName == null) {
res.sendRedirect(req.getContextPath());
return;
}
//
PortalApplication app =
controllerContext.getController().getApplication(PortalApplication.PORTAL_APPLICATION_ID);
- PortalRequestContext context = new PortalRequestContext(app, controllerContext,
requestSiteType, requestSiteName, requestPath, access);
+ PortalRequestContext context = new PortalRequestContext(app, controllerContext,
requestSiteType, requestSiteName, requestPath, access, requestLocale);
WebuiRequestContext.setCurrentInstance(context);
UIApplication uiApp = app.getStateManager().restoreUIRootComponent(context);
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java 2010-11-30
18:14:32 UTC (rev 5388)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java 2010-11-30
20:49:57 UTC (rev 5389)
@@ -45,6 +45,12 @@
*/
public Locale determineLocale(LocaleContextInfo context)
{
+ if (context.getRequestLocale() != null)
+ {
+ return context.getRequestLocale();
+ }
+
+ //
Locale locale = null;
if (context.getRemoteUser() == null)
locale = getLocaleConfigForAnonymous(context);
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java 2010-11-30
18:14:32 UTC (rev 5388)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java 2010-11-30
20:49:57 UTC (rev 5389)
@@ -144,6 +144,8 @@
Locale portalLocale = LocaleContextInfo.getLocale(portalLocaleName);
localeCtx.setPortalLocale(portalLocale);
+ localeCtx.setRequestLocale(reqCtx.getRequestLocale());
+
Locale locale = localePolicy.determineLocale(localeCtx);
if (!supportedLocales.contains(locale))
{
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java 2010-11-30
18:14:32 UTC (rev 5388)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java 2010-11-30
20:49:57 UTC (rev 5389)
@@ -27,6 +27,7 @@
import org.exoplatform.web.url.ResourceLocator;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
/**
@@ -51,9 +52,16 @@
/** . */
private PortalURLRenderContext renderContext;
- public PortalURL(ControllerContext requestContext, L locator, Boolean ajax, String
siteType, String siteName, String access)
+ public PortalURL(
+ ControllerContext requestContext,
+ L locator,
+ Boolean ajax,
+ Locale locale,
+ String siteType,
+ String siteName,
+ String access)
{
- super(locator, ajax);
+ super(locator, ajax, locale);
//
if (requestContext == null)
@@ -120,6 +128,19 @@
parameters.put(PortalRequestHandler.REQUEST_SITE_NAME, siteName);
//
+ String lang;
+ Locale locale = getLocale();
+ if (locale != null)
+ {
+ lang = locale.getLanguage() + "/";
+ }
+ else
+ {
+ lang = "";
+ }
+ parameters.put(PortalRequestHandler.LANG, lang);
+
+ //
for (QualifiedName parameterName : locator.getParameterNames())
{
String parameterValue = locator.getParameterValue(parameterName);
@@ -154,7 +175,6 @@
}
//
- String s = renderContext.toString();
- return s;
+ return renderContext.toString();
}
}
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURLProvider.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURLProvider.java 2010-11-30
18:14:32 UTC (rev 5388)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURLProvider.java 2010-11-30
20:49:57 UTC (rev 5389)
@@ -57,8 +57,9 @@
PortalURLProvider portalURLProvider = currentProvider.get();
if (portalURLProvider != null)
{
- L newLocator = locatorProvider.newLocator(resourceType);
- return new PortalURL<R, L>(controllerContext, newLocator, false, siteType,
siteName, access);
+// L newLocator = locatorProvider.newLocator(resourceType);
+// return new PortalURL<R, L>(controllerContext, newLocator, false,
siteType, siteName, access);
+ throw new UnsupportedOperationException("is it used ?");
}
return null;
}