package org.intermine.web;

/*
 * Copyright (C) 2002-2004 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.List;
import java.util.Arrays;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import org.apache.struts.tiles.TilesRequestProcessor;
import org.apache.struts.Globals;

/**
 * A RequestProcessor that sends you back to start if your session isn't valid
 * @author Mark Woodbridge
 */
public class InterMineRequestProcessor extends TilesRequestProcessor
{
    private static final String LOGON_PATH = "/begin";
    private static final String LOGON_INIT_PATH = "/initBegin";

    /**
     * Paths that can be used as initial pages ie. when there is no session.
     */
    public static final List START_PATHS = Arrays.asList(new String[]
        {LOGON_PATH, LOGON_INIT_PATH, "/classChooser", "/bagBuild", "/examples", "/iqlQuery"});

    /**
     * @see TilesRequestProcessor#processPreprocess
     */
    protected boolean processPreprocess(HttpServletRequest request, HttpServletResponse response) {
        try {
            if (!request.isRequestedSessionIdValid()) {
                if (request.getAttribute(Globals.MESSAGE_KEY) == null) {
                    if (!START_PATHS.contains(processPath(request, response))) {
                        ActionErrors messages = new ActionErrors();
                        messages.add(ActionErrors.GLOBAL_ERROR,
                                     new ActionError("errors.session.nosession"));
                        request.setAttribute(Globals.ERROR_KEY, messages);
                        processForwardConfig(request, response,
                                             new ActionForward(LOGON_PATH + ".do"));
                    }
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return true;
    }
}

@@ -738,16 +738,20 @@
 back to 
+the 
 start if
@@ -1492,19 +1492,16 @@
 dValid()
-) %7B
 %0A       
@@ -1509,20 +1509,19 @@
         
-if (
+&& 
 request.
@@ -1561,19 +1561,16 @@
  == null
-) %7B
 %0A       
@@ -1578,24 +1578,19 @@
         
-    if (
+&& 
 !START_P
@@ -1634,32 +1634,24 @@
 sponse))) %7B%0A
-        
             
@@ -1714,24 +1714,16 @@
         
-        
 messages
@@ -1779,32 +1779,24 @@
             
- 
-       
 new ActionEr
@@ -1825,32 +1825,24 @@
 session%22));%0A
-        
             
@@ -1912,24 +1912,16 @@
         
-   
-     
 processF
@@ -1955,53 +1955,8 @@
 nse,
-%0A                                            
  new
@@ -1996,48 +1996,8 @@
 ));%0A
-                    %7D%0A                %7D%0A
     
@@ -2091,16 +2091,24 @@
       %7D%0A
+        
 %0A       

Tidy up code