Mercurial > dive4elements > gnv-client
view gnv/src/main/java/de/intevation/gnv/action/SwitchLanguageAction.java @ 1145:dfe1ac687c7f tip
added tags
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:16:15 +0200 |
parents | 28a0628b11b0 |
children |
line wrap: on
line source
/* * Copyright (c) 2010 by Intevation GmbH * * This program is free software under the LGPL (>=v2.1) * Read the file LGPL.txt coming with the software for details * or visit http://www.gnu.org/licenses/ if it does not exist. */ package de.intevation.gnv.action; import de.intevation.gnv.action.sessionmodel.SessionModel; import de.intevation.gnv.action.sessionmodel.SessionModelFactory; import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; import java.util.Locale; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.apache.struts.Globals; 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 { if (isSessionExhausted(request)) { return sessionExhaustedForward(mapping, form, request, response); } SessionModelFactory factory = SessionModelFactory.getInstance(); SessionModel sm = factory.getSessionModel(request); Locale locale = switchLanguage(sm.getCurrentLocale()); sm.setCurrentLocale(locale); ArtifactObject artifactFactory = sm.getSelectedArtifactFactory(); if (artifactFactory == null) { request.getSession().setAttribute(Globals.LOCALE_KEY, locale); return mapping.findForward(SUCCSESS_FORWARD_ID); } 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 :