taylor 2004/08/04 21:50:29
Modified: portal/src/java/org/apache/jetspeed/request
JetspeedRequestContext.java
portal/src/java/org/apache/jetspeed/localization/impl
LocalizationValveImpl.java
portal/src/java/org/apache/jetspeed/engine/servlet
ServletRequestFactoryImpl.java
ServletRequestImpl.java
Log:
Locale Selector portlet, contributed by Shinsuke Sugaya
This porlet works much like the Locale portlet in J1
You choose a language and it overrides the language for this session
Right now we don't have any portlets with more than just english
We are working on getting some multi-lingual example portlets soon
CVS: ----------------------------------------------------------------------
CVS: PR:
CVS: If this change addresses a PR in the problem report tracking
CVS: database, then enter the PR number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system, such as NCSA,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to Apache by someone else; i.e.,
CVS: they sent us a patch or a new module, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.
Revision Changes Path
1.27 +8 -12
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java
Index: JetspeedRequestContext.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- JetspeedRequestContext.java 1 Aug 2004 15:46:55 -0000 1.26
+++ JetspeedRequestContext.java 5 Aug 2004 04:50:28 -0000 1.27
@@ -15,7 +15,6 @@
*/
package org.apache.jetspeed.request;
-import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Locale;
@@ -61,6 +60,7 @@
{
public static final String PREFERED_LANGUAGE_SESSION_KEY =
"org.apache.jetspeed.prefered.language";
public static final String PREFERED_LOCALE_SESSION_KEY =
"org.apache.jetspeed.prefered.locale";
+ public static final String PREFERED_CHARACTERENCODING_KEY =
"org.apache.jetspeed.prefered.characterencoding";
private HttpServletRequest request;
private HttpServletResponse response;
@@ -274,6 +274,13 @@
*/
public void setCharacterEncoding( String enc )
{
+ String preferedEnc = (String)
request.getSession().getAttribute(PREFERED_CHARACTERENCODING_KEY);
+
+ if (preferedEnc == null || !enc.equals(preferedEnc))
+ {
+ request.setAttribute(PREFERED_CHARACTERENCODING_KEY, enc);
+ }
+
this.encoding = enc;
}
@@ -292,17 +299,6 @@
.getFactory(javax.servlet.http.HttpServletRequest.class);
HttpServletRequest requestWrapper = reqFac.getServletRequest(request,
window);
- if (getCharacterEncoding() != null)
- {
- try
- {
- requestWrapper.setCharacterEncoding(getCharacterEncoding());
- }
- catch (UnsupportedEncodingException e)
- {
- ;
- }
- }
return requestWrapper;
}
1.4 +10 -2
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/localization/impl/LocalizationValveImpl.java
Index: LocalizationValveImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/localization/impl/LocalizationValveImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LocalizationValveImpl.java 13 Jul 2004 21:01:18 -0000 1.3
+++ LocalizationValveImpl.java 5 Aug 2004 04:50:29 -0000 1.4
@@ -22,6 +22,7 @@
import org.apache.jetspeed.pipeline.valve.AbstractValve;
import org.apache.jetspeed.pipeline.valve.LocalizationValve;
import org.apache.jetspeed.pipeline.valve.ValveContext;
+import org.apache.jetspeed.request.JetspeedRequestContext;
import org.apache.jetspeed.request.RequestContext;
/**
@@ -41,8 +42,15 @@
*/
public void invoke( RequestContext request, ValveContext context ) throws
PipelineException
{
+ // TODO Get the prefered locale from user's persistent storage if not anon
user
- Locale locale = request.getRequest().getLocale();
+ Locale locale =
+ (Locale)
request.getRequest().getSession().getAttribute(JetspeedRequestContext.PREFERED_LOCALE_SESSION_KEY);
+
+ if (locale == null)
+ {
+ locale = request.getRequest().getLocale();
+ }
if (locale == null)
{
1.4 +18 -1
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestFactoryImpl.java
Index: ServletRequestFactoryImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestFactoryImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ServletRequestFactoryImpl.java 8 Mar 2004 00:26:30 -0000 1.3
+++ ServletRequestFactoryImpl.java 5 Aug 2004 04:50:29 -0000 1.4
@@ -15,10 +15,12 @@
*/
package org.apache.jetspeed.engine.servlet;
+import java.io.UnsupportedEncodingException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.ServletConfig;
+import org.apache.jetspeed.request.JetspeedRequestContext;
import org.apache.pluto.om.window.PortletWindow;
/**
@@ -47,6 +49,21 @@
{
// TODO: use pool here
HttpServletRequest servletRequest = new ServletRequestImpl(request, window);
+
+ // Set page encoding in order to parse the form data correctly
+ String preferedEnc = (String)
request.getAttribute(JetspeedRequestContext.PREFERED_CHARACTERENCODING_KEY);
+ if (preferedEnc != null)
+ {
+ try
+ {
+ servletRequest.setCharacterEncoding(preferedEnc);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ ;
+ }
+ }
+
return servletRequest;
}
1.20 +61 -1
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java
Index: ServletRequestImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- ServletRequestImpl.java 20 Jul 2004 19:57:25 -0000 1.19
+++ ServletRequestImpl.java 5 Aug 2004 04:50:29 -0000 1.20
@@ -16,10 +16,12 @@
package org.apache.jetspeed.engine.servlet;
import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Locale;
import java.util.Map;
import javax.portlet.PortletRequest;
@@ -42,6 +44,7 @@
import org.apache.pluto.om.entity.PortletEntity;
import org.apache.pluto.om.portlet.PortletApplicationDefinition;
import org.apache.pluto.om.window.PortletWindow;
+import org.apache.pluto.util.Enumerator;
import org.apache.pluto.util.NamespaceMapperAccess;
/**
@@ -252,4 +255,61 @@
}
return value;
}
+
+ /**
+ * @see javax.servlet.ServletRequest#getLocale()
+ */
+ public Locale getLocale()
+ {
+ Locale preferedLocale = (Locale)
getSession().getAttribute(JetspeedRequestContext.PREFERED_LOCALE_SESSION_KEY);
+ if (preferedLocale != null)
+ {
+ return preferedLocale;
+ }
+
+ return super.getLocale();
+ }
+
+ /**
+ * @see javax.servlet.ServletRequest#getLocales()
+ */
+ public Enumeration getLocales()
+ {
+ Locale preferedLocale = (Locale)
getSession().getAttribute(JetspeedRequestContext.PREFERED_LOCALE_SESSION_KEY);
+ if (preferedLocale != null)
+ {
+ ArrayList locales = new ArrayList();
+ locales.add(preferedLocale);
+ Enumeration enum = super.getLocales();
+ while (enum.hasMoreElements())
+ {
+ locales.add(enum.nextElement());
+ }
+ Iterator i =locales.iterator();
+ return new Enumerator(locales);
+ }
+
+ return super.getLocales();
+ }
+
+ /**
+ * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String)
+ */
+ public String getHeader(String name)
+ {
+ // TODO: replace accept-language header
+
+ return super.getHeader(name);
+ }
+
+ /**
+ * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String)
+ */
+ public Enumeration getHeaders(String name)
+ {
+ // TODO: replace accept-language header
+
+ return super.getHeaders(name);
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]