View Javadoc
1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
20   *  
21   *  
22   *******************************************************************************/
23  package com.gisgraphy.webapp.action;
24  
25  import java.io.IOException;
26  import java.io.PrintWriter;
27  
28  import javax.servlet.http.HttpServletResponse;
29  
30  import org.apache.struts2.ServletActionContext;
31  
32  import com.gisgraphy.webapp.listener.StartupListener;
33  
34  /**
35   * This class is used to reload the drop-downs initialized in the
36   * StartupListener.
37   * 
38   * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
39   */
40  public class ReloadAction extends BaseAction {
41      private static final long serialVersionUID = 295460450224891051L;
42  
43      /**
44       * Method that calls StartupListener.setContext() and returns user to
45       * referrer location (or does a popup if none found).
46       * 
47       * @return sucess when everything goes right
48       * @throws IOException
49       *                 when response.sendRedirect fails
50       */
51      @Override
52      public String execute() throws IOException {
53  	StartupListener.setupContext(getSession().getServletContext());
54  
55  	String referer = getRequest().getHeader("Referer");
56  	HttpServletResponse response = ServletActionContext.getResponse();
57  
58  	if (referer != null) {
59  	    log.info("reload complete, reloading user back to: " + referer);
60  	    saveMessage(getText("reload.succeeded"));
61  	    response.sendRedirect(response.encodeRedirectURL(referer));
62  	    return SUCCESS;
63  	} else {
64  	    response.setContentType("text/html");
65  
66  	    PrintWriter out = response.getWriter();
67  
68  	    out.println("<html>");
69  	    out.println("<head>");
70  	    out.println("<title>Context Reloaded</title>");
71  	    out.println("</head>");
72  	    out.println("<body bgcolor=\"white\">");
73  	    out.println("<script type=\"text/javascript\">");
74  	    out
75  		    .println("alert('Reloading options succeeded! Click OK to continue.');");
76  	    out.println("history.back();");
77  	    out.println("</script>");
78  	    out.println("</body>");
79  	    out.println("</html>");
80  	}
81  
82  	return SUCCESS;
83      }
84  }