Mercurial > dive4elements > gnv-client
changeset 706:2659a5b1fa1e
Added a link (and a controller) to toggle between german and english language (issue254).
gnv/trunk@970 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 23 Apr 2010 07:55:05 +0000 |
parents | f550bd27a3f1 |
children | cb1bae26e7ae |
files | gnv/ChangeLog gnv/src/main/java/de/intevation/gnv/action/DescribeUIAction.java gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java gnv/src/main/java/de/intevation/gnv/action/SwitchLanguageAction.java gnv/src/main/java/de/intevation/gnv/action/sessionmodel/DefaultSessionModel.java gnv/src/main/java/de/intevation/gnv/action/sessionmodel/SessionModel.java gnv/src/main/java/de/intevation/gnv/action/sessionmodel/SessionModelFactory.java gnv/src/main/webapp/WEB-INF/config/struts-config.xml gnv/src/main/webapp/WEB-INF/jsp/header.jsp |
diffstat | 9 files changed, 150 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv/ChangeLog Thu Apr 22 12:58:44 2010 +0000 +++ b/gnv/ChangeLog Fri Apr 23 07:55:05 2010 +0000 @@ -1,3 +1,35 @@ +2010-04-23 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + Issue254 + + * src/main/java/de/intevation/gnv/action/SwitchLanguageAction.java: New + controller to toggle between german and english language. + + * src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java, + src/main/java/de/intevation/gnv/action/DescribeUIAction.java: Use the + locale stored in the artifact to create the user interface. At the + beginning, this will be the locale of the request object. If the user + chooses another language by calling the SwitchLanguageAction controller, + this locale becomes the prefered locale, and the browser settings are no + more relevant. + + * src/main/java/de/intevation/gnv/action/sessionmodel/SessionModel.java, + src/main/java/de/intevation/gnv/action/sessionmodel/DefaultSessionModel.java: + Now, the SessionModel has two methods to set and retrieve the current + locale which is used to create a language specific user interface. + + * src/main/java/de/intevation/gnv/action/sessionmodel/SessionModelFactory.java: + Initial creation of the SessionModel gets the locale of the request + object. If this locale is changed by the user via SwitchLanguageAction + controller, changes in the browser settings won't have an effect anymore. + + * src/main/webapp/WEB-INF/config/struts-config.xml: Add the controller to + switch between languages. + + * src/main/webapp/WEB-INF/jsp/header.jsp: The header contains a link to + toggle between german and english language - a click on it will trigger + the SwitchLanguageAction. + 2010-04-22 Ingo Weinzierl <ingo.weinzierl@intevation.de> Issue221
--- a/gnv/src/main/java/de/intevation/gnv/action/DescribeUIAction.java Thu Apr 22 12:58:44 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/DescribeUIAction.java Fri Apr 23 07:55:05 2010 +0000 @@ -15,6 +15,7 @@ import de.intevation.gnv.util.XMLUtils; import de.intevation.gnv.util.XSLTransformer; +import java.util.Locale; import java.util.ResourceBundle; import javax.servlet.http.HttpServletRequest; @@ -73,10 +74,12 @@ // render describe document and create user interface SessionModel sm = SessionModelFactory.getInstance().getSessionModel( request); + Locale tmp = sm.getCurrentLocale(); + Locale locale = tmp != null ? tmp : request.getLocale(); ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory - .getInstance().getArtifactDatabaseClient(request.getLocale()); - request.getSession().setAttribute(Globals.LOCALE_KEY, request.getLocale()); + .getInstance().getArtifactDatabaseClient(locale); + request.getSession().setAttribute(Globals.LOCALE_KEY, locale); ArtifactDescription artifactDescription = adc.getCurrentStepDescription( @@ -87,7 +90,7 @@ Node currentUI = artifactDescription.getCurrentUI(); if (currentUI != null) { ResourceBundle res = ResourceBundle.getBundle( - "applicationMessages", adc.getLocale()); + "applicationMessages", locale); String editText = res.getString("gnviewer.history.back.button"); XSLTransformer transformer = new XSLTransformer();
--- a/gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java Thu Apr 22 12:58:44 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java Fri Apr 23 07:55:05 2010 +0000 @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.Locale; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -63,6 +64,10 @@ SessionModel sm = SessionModelFactory.getInstance() .getSessionModel(request); ArtifactDescription ad = sm.getArtifactDescription(); + + Locale tmp = sm.getCurrentLocale(); + Locale locale = tmp != null ? tmp : request.getLocale(); + if (ad != null){ Collection<String> inputParameter = ad.getInputParameter(); Collection<InputParameter> ips = null; @@ -77,8 +82,8 @@ } } ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory - .getInstance() - .getArtifactDatabaseClient(getLocale(request)); + .getInstance().getArtifactDatabaseClient(locale); + Map outs = ad.getOutputModes(); if (outs == null || outs.isEmpty()) { // TODO: Woher kommt der zu erreichende Status; @@ -103,8 +108,6 @@ ); } catch (ArtifactDatabaseInputException e) { - log.debug("================ CATCH ME ======================"); - log.debug("===== ERROR MSG: " + e.getMessage()); log.error(e, e); request.setAttribute( CommunicationKeys.REQUEST_EXCEPTION_INPUT_ID,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/SwitchLanguageAction.java Fri Apr 23 07:55:05 2010 +0000 @@ -0,0 +1,62 @@ +package de.intevation.gnv.action; + +import de.intevation.gnv.action.sessionmodel.SessionModel; +import de.intevation.gnv.action.sessionmodel.SessionModelFactory; + +import java.util.Locale; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; + +/** + * Toggle the current language used to create the user interface. Two + * languages are available now - german and english. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class SwitchLanguageAction extends DescribeUIAction { + + public static Logger logger = Logger.getLogger(SwitchLanguageAction.class); + + @Override + public ActionForward execute( + ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response + ) throws Exception + { + SessionModelFactory factory = SessionModelFactory.getInstance(); + SessionModel sm = factory.getSessionModel(request); + + sm.setCurrentLocale(switchLanguage(sm.getCurrentLocale())); + + return super.execute(mapping, form, request, response); + } + + + /** + * This method toggles between german and english language. + * + * @param currentLocale The locale which is currently used. + * @return an english locale, if the current locale is german - otherwise + * a german locale. + */ + protected Locale switchLanguage(Locale currentLocale) { + if (currentLocale.getLanguage().equals(Locale.GERMAN.getLanguage())) { + logger.info("Switch from german to english locale."); + return Locale.ENGLISH; + } + else { + logger.info("Switch from english to german locale."); + return Locale.GERMAN; + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/gnv/src/main/java/de/intevation/gnv/action/sessionmodel/DefaultSessionModel.java Thu Apr 22 12:58:44 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/sessionmodel/DefaultSessionModel.java Fri Apr 23 07:55:05 2010 +0000 @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.Iterator; +import java.util.Locale; import org.apache.log4j.Logger; @@ -39,11 +40,22 @@ private Collection<ArtifactStatisticsSet> statistics = null; + private Locale currentLocale; + /** * Constructor */ public DefaultSessionModel() { - super(); + this(null); + } + + /** + * Constructor + * + * @param currentLocale A locale used to create the user interface. + */ + public DefaultSessionModel(Locale currentLocale) { + this.currentLocale = currentLocale; } @@ -141,5 +153,13 @@ public void setStatistics(Collection<ArtifactStatisticsSet> statistics) { this.statistics = statistics; } + + public Locale getCurrentLocale() { + return currentLocale; + } + + public void setCurrentLocale(Locale currentLocale) { + this.currentLocale = currentLocale; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/gnv/src/main/java/de/intevation/gnv/action/sessionmodel/SessionModel.java Thu Apr 22 12:58:44 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/sessionmodel/SessionModel.java Fri Apr 23 07:55:05 2010 +0000 @@ -8,6 +8,7 @@ import java.io.Serializable; import java.util.Collection; +import java.util.Locale; /** * This interface describe basic methods to store artifacts and diagram options. @@ -43,5 +44,9 @@ void setStatistics(Collection<ArtifactStatisticsSet> statistics); Collection<ArtifactStatisticsSet> getStatistics(); + + void setCurrentLocale(Locale locale); + + Locale getCurrentLocale(); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/gnv/src/main/java/de/intevation/gnv/action/sessionmodel/SessionModelFactory.java Thu Apr 22 12:58:44 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/sessionmodel/SessionModelFactory.java Fri Apr 23 07:55:05 2010 +0000 @@ -54,7 +54,7 @@ if (obj instanceof SessionModel) { sm = (SessionModel) obj; } else { - sm = new DefaultSessionModel(); + sm = new DefaultSessionModel(request.getLocale()); request.getSession().setAttribute(SESSION_MODEL_ID, sm); }
--- a/gnv/src/main/webapp/WEB-INF/config/struts-config.xml Thu Apr 22 12:58:44 2010 +0000 +++ b/gnv/src/main/webapp/WEB-INF/config/struts-config.xml Fri Apr 23 07:55:05 2010 +0000 @@ -7,7 +7,7 @@ <global-forwards> <forward name="entrance" path="/start.do"/> </global-forwards> - + <action-mappings> <action path="/version" type="de.intevation.gnv.action.ArtifactDatabaseActionBase" @@ -219,6 +219,20 @@ name="success" path="/WEB-INF/jsp/mainlayout.jsp"/> </action> + <action path="/language" + type="de.intevation.gnv.action.SwitchLanguageAction" + scope="request" + validate="false"> + <forward + name="success" + path="/WEB-INF/jsp/mainlayout.jsp"/> + <forward + name="back" + path="/gnv/back.do"/> + <forward + name="selectfis" + path="/gnv/selectFis.do"/> + </action> </action-mappings> <message-resources parameter="applicationMessages" null="false"/>
--- a/gnv/src/main/webapp/WEB-INF/jsp/header.jsp Thu Apr 22 12:58:44 2010 +0000 +++ b/gnv/src/main/webapp/WEB-INF/jsp/header.jsp Fri Apr 23 07:55:05 2010 +0000 @@ -17,7 +17,7 @@ <td align="right"> <a class="headerLineLinks" href="/gnv"><bean:message key="gnviewer.header.restart"/></a> <font size="1.5em" color="white">·</font> - <a class="headerLineLinks" href=""><bean:message key="gnviewer.header.language"/></a> + <a class="headerLineLinks" href="<%=response.encodeURL("language.do?uid="+System.currentTimeMillis())%>"><bean:message key="gnviewer.header.language"/></a> <font size="1.5em" color="white">·</font> <a class="headerLineLinks" href=""><bean:message key="gnviewer.header.info"/></a> </td>