View Javadoc

1   /*
2    *  ginp - Java Web Application for Viewing Photo Collections
3    *  Copyright (C) 2004  Douglas John Culnane <doug@culnane.net>
4    *
5    *  This library is free software; you can redistribute it and/or
6    *  modify it under the terms of the GNU Lesser General Public
7    *  License as published by the Free Software Foundation; either
8    *  version 2.1 of the License, or any later version.
9    *
10   *  This library is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   *  Lesser General Public License for more details.
14   *
15   *  You should have received a copy of the GNU Lesser General Public
16   *  License along with this library; if not, write to the Free Software
17   *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18   */
19  package net.sf.ginp.commands;
20  
21  import java.util.Locale;
22  import java.util.Vector;
23  
24  import net.sf.ginp.CommandParameter;
25  import net.sf.ginp.GinpModel;
26  
27  /**
28   *  Commmand to set the Models prefured Locale. This is lower case 2 letter 
29   * iso code for the language, and an optional Upper case 2 letter Code for the
30   *  country.
31   *
32   * @author     Doug Culnane
33   * @version    $Revision: 264 $
34   */
35  public class SetLanguageCode implements Command {
36  
37      /**
38       *  Description of the Method
39       *
40       * @param  model   Description of the Parameter
41       * @param  params  Description of the Parameter
42       */
43      public void action(GinpModel model, Vector params) {
44  
45          for (int i = 0; i < params.size(); i++) {
46              CommandParameter  param  = (CommandParameter) params.get(i);
47              if (param.getName().equals("code")) {
48                  if (param.getValue().length() == 5) {
49                      model.setLocale(new Locale(param.getValue().substring(0, 2), 
50                          param.getValue().substring(3, 5)));
51                  } else {
52                      model.setLocale(new Locale(param.getValue()));
53                  }
54              } else if (param.getName().equals("page")) {
55                  // Send the user back to page that the request came from.
56                  model.setCurrentPage(param.getValue());
57              }
58          }
59      }
60  }
61