1 /* 2 * $Id$ 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 package examples.localization; 23 24 import java.util.Locale; 25 26 import jakarta.servlet.http.HttpServletRequest; 27 import jakarta.servlet.http.HttpServletResponse; 28 import jakarta.servlet.http.HttpSession; 29 30 import org.apache.struts.Globals; 31 import org.apache.struts.action.Action; 32 import org.apache.struts.action.ActionForm; 33 import org.apache.struts.action.ActionForward; 34 import org.apache.struts.action.ActionMapping; 35 36 /** 37 * Retrieve and process data from the submitted form 38 * 39 * @version $Rev$ $Date$ 40 */ 41 public class ProcessLocalizationAction extends Action { 42 private static final long serialVersionUID = 1840482879886795996L; 43 44 // ------------------------------------------------------------ Constructors 45 46 /** 47 * Constructor for ProcessOptionsAction. 48 */ 49 public ProcessLocalizationAction() { 50 super(); 51 } 52 53 // ---------------------------------------------------------- Action Methods 54 55 /** 56 * Process the request and return an <code>ActionForward</code> instance 57 * describing where and how control should be forwarded, or 58 * <code>null</code>if the response has already been completed. 59 * 60 * @param mapping The ActionMapping used to select this instance 61 * @param form The optional ActionForm bean for this request (if any) 62 * @param request The HTTP request we are processing 63 * @param response The HTTP response we are creating 64 * 65 * @exception Exception if the application logic throws an exception 66 * 67 * @return the ActionForward for the next view 68 */ 69 public ActionForward execute( 70 ActionMapping mapping, 71 ActionForm form, 72 HttpServletRequest request, 73 HttpServletResponse response) 74 throws Exception { 75 76 // Extract attributes we will need 77 HttpSession session = request.getSession(); 78 79 // Get locale from request, if any 80 Locale locale = request.getLocale(); 81 82 // If supplied, set Locale based on request parameters; 83 // country and language 84 String language = request.getParameter("language"); 85 String country = request.getParameter("country"); 86 87 if ((language != null && language.length() > 0) 88 && (country != null && country.length() > 0)) { 89 locale = new Locale(language, country); 90 } else if (language != null && language.length() > 0) { 91 locale = new Locale(language); 92 } 93 94 //Save locale 95 session.setAttribute(Globals.LOCALE_KEY, locale); 96 97 // Forward to result page 98 return mapping.findForward("success"); 99 } 100 }