RedirectToFromCallingService.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  *  2004 Modified by Romain Beaugrand
00027  * 
00028  */
00029 
00030 package org.openmobileis.services.common;
00031 
00032 import java.io.IOException;
00033 import java.util.Hashtable;
00034 
00035 import javax.servlet.ServletException;
00036 import javax.servlet.http.HttpServletRequest;
00037 import javax.servlet.http.HttpServletResponse;
00038 import javax.servlet.http.HttpSession;
00039 
00040 import org.openmobileis.services.Service;
00041 import org.openmobileis.services.navigation.NavigationBarManager;
00042 import org.openmobileis.services.servlet.OpenmisHttpServletRequest;
00043 import org.openmobileis.common.util.log.*;
00044 
00049 public class RedirectToFromCallingService extends Service {
00050 
00054         public RedirectToFromCallingService() {
00055                 super();
00056         }
00057 
00061         public void run(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
00062                 
00063             OpenmisHttpServletRequest openmisReq = (OpenmisHttpServletRequest)req;
00064             
00065                 // begin search
00066                 String to = req.getParameter("to");
00067                 if (to != null) { // start redirect
00068                         //remove to parameter
00069                     openmisReq.removeParameter("to");
00070                         //res.getCallingServiceManager().pushCallingService(this.getServiceUri(), req);
00071                     HttpSession session = req.getSession();
00072                         CallingServiceManager callServManager = CallingServiceManager.getManager();
00073                         callServManager.pushCallingService(this.getServiceUri(), req);
00074                         //update navigation bar
00075                         String uri = (String)req.getParameter("from");
00076                         if (uri != null)        {
00077                                 NavigationBarManager.getManager().updateRequestParametersForRedirectService(uri, req);
00078                         }
00079                   res.sendRedirect(to);
00080                 } else  { //manage redirect return
00081                         String from = (String)req.getParameter("from");
00082                         if (from == null)       {
00083                             HttpSession session = req.getSession();
00084                                 CallingServiceManager callServManager = CallingServiceManager.getManager();
00085                                 callServManager.peekToTheSpecifiedCallingService(this.getServiceUri());
00086                                 //res.getCallingServiceManager().peekToTheSpecifiedCallingService(this.getServiceUri());
00087                                 //Hashtable oldParameterList = res.getCallingServiceManager().getCallingServiceParameters();
00088                                 Hashtable oldParameterList = callServManager.getCallingServiceParameters();
00089                                 //res.getCallingServiceManager().popCallingService();
00090                                 callServManager.popCallingService();
00091                                 if (oldParameterList != null)   {
00092                                         //manage old request in new one
00093                                     openmisReq.addParameters(oldParameterList);
00094                                         from = (String)req.getParameter("from");
00095                                 }
00096                         }
00097                         if (from!=null) {
00098                                 res.sendRedirect(from);                         
00099                         } else {
00100                         LogManager.traceError(LogServices.WEBSERVICE, "RedirectToFromCallingService can't find to service");
00101                         ServletTools.sendErrorPage("Internal Error" , "No service specified to return", "/index", res);
00102                         }       
00103                 }
00104         }
00105 
00106   
00107   public String getName() {
00108     return "calendar.RedirectToFromCallingService";
00109   }
00110   
00114   public String getServiceUri() {
00115     return ServiceManager.getManager().getServiceBaseURI()+"/admin/redirectService";
00116   }
00117 
00118 }

Generated on Mon Dec 4 11:03:29 2006 for OpenMobileIS by  doxygen 1.5.1-p1