RE: Multiple shunts [1] and more dynamic LanguageShuntFactory [2]
"Aapo Laakkonen" <[email protected]>
| Newsgroups | gmane.comp.web.maverick.general |
|---|---|
| Organization | ProjectCast Oy |
| Message-ID | <001a01c3836d$6bcf0870$51d14e3e@bungle> |
Ok, I did write a patch to LanguageShuntFactory. I attached the files in
this mail.
- LanguageShuntFactory.java is the new patched LanguageShuntFactory
- LanguageShuntFactory.java.old is the old LanguageShuntFactory (in
current CVS)
- LanguageShuntFactory.diff is diff file that can be applied to
LanguageShuntFactory.java.old (or to the version that exists in
repository.
Changes:
LanguageShuntFactory can now be initialized with default-language
attribute like this:
<maverick version="2.0" default-view-type="document">
<modules>
<shunt-factory
provider="org.infohazard.maverick.shunt.LanguageShuntFactory"
default-language="en"/>
</modules>
</maverick>
User can override default-language or Accept-Language headers by using
request attribute:
request.setAttribute("language", "en");
New LanguageShuntFactory tries at first to find a proper mode by using
request attribute ("language"). Next it will try to find proper mode by
using "default-language" attribute and finally it tries to find mode
that matches to one of Accept-Language headers. If all these fail then
it tries to find default mode. If also this fails, it will throw an
exception.
Kind regards
Aapo
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Aapo
Laakkonen
Sent: Thursday, September 25, 2003 3:16 PM
To: [email protected]
Subject: [Mav-user] Multiple shunts [1] and more dynamic
LanguageShuntFactory [2]
[1]
http://www.mail-archive.com/[email protected]/msg00584.html
[2]
http://www.mail-archive.com/[email protected]/msg00545.html
Has anyone done anything to these? I could do a patch to
LanguageShuntFactory [2] to have override capability depending on
Session language attribute.
What should we do to case [1]?
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
[INVALID FOOTER]
LanguageShuntFactory.java
(application/octet-stream, 7.4 KB) - not displayed
LanguageShuntFactory.java.old
(application/octet-stream, 5.3 KB) - not displayed
LanguageShuntFactory.diff
(application/octet-stream, 2.3 KB)
12a13,14
> import org.infohazard.maverick.util.XML;
>
35a38,59
> * <p>Choosing mode from a request attribute "language" is done by
> * setting * request attribute.</p>
> *
> * <p>E.g. request.setAttribute("language", "en");</p>
> *
> * <p>Default mode can be provided using ShuntingFactory attribute
> * "default-language".</p>
> *
> * <pre>
> * <maverick version="2.0" default-view-type="document">
> * <modules>
> * <shunt-factory provider="org.infohazard.maverick.shunt.LanguageShuntFactory" default-language="en"/>
> * </modules>
> * </maverick>
> * </pre>
> *
> * <p>It is not required to user to supply "default-language" attribute
> * or to set request attribute "language". If these are not supplied then
> * the procedure follows as described below. Accept-Language headers are
> * also used if request attribute "language" or "default-language" does
> * not give a proper View.</p>
> *
60a85,92
> /**
> * This is used to provide default language for web application
> */
> protected final static String ATTR_DEFAULT_LANGUAGE = "default-language";
> protected String defaultLanguage;
>
> public final static String KEY_REQUEST_LANGUAGE = "language";
>
108a141,163
> String requestedLanguage;
>
> // At first try to find a mode for requested language
> if (request.getAttribute(KEY_REQUEST_LANGUAGE) != null) {
> requestedLanguage = request.getAttribute(KEY_REQUEST_LANGUAGE).toString();
> View theView = (View) modes.get(requestedLanguage);
> if (theView != null) {
> log.debug("Using mode: " + requestedLanguage);
> return theView;
> }
> }
>
> // Next we try to determine if there exist mode for default language
> if (defaultLanguage != null) {
> View theView = (View) modes.get(defaultLanguage);
> if (theView != null) {
> log.debug("Using mode: " + defaultLanguage);
> return theView;
> }
> }
>
> // And finally we try to find mode based on Accept-Language header
>
179c234
< * Does nothing.
---
> * Provides default language to web application.
182a238
> this.defaultLanguage = XML.getValue(factoryNode, ATTR_DEFAULT_LANGUAGE);