KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ashkelon > pages > Trail


1 package org.ashkelon.pages;
2
3 import org.ashkelon.util.*;
4 import java.util.*;
5 import javax.servlet.http.*;
6
7 /**
8  * @author Eitan Suez
9  */

10 public class Trail extends Page
11 {
12    public Trail()
13    {
14       super();
15       log.setPrefix("trail");
16    }
17    
18    public String JavaDoc handleRequest()
19    {
20       String JavaDoc cmd = ServletUtils.getCommand(request);
21       if (cmd.equals("trail.reset"))
22       {
23          return resetTrail(request);
24       }
25       return null;
26    }
27    
28    private String JavaDoc resetTrail(HttpServletRequest request)
29    {
30       HttpSession session = request.getSession(true);
31       LinkedList trail = (LinkedList) session.getAttribute("trail");
32       if (trail == null || trail.isEmpty())
33          return "pkg";
34       
35       String JavaDoc[] lastPair = (String JavaDoc[]) trail.getLast();
36       String JavaDoc last_uri = lastPair[0];
37       
38       String JavaDoc cmd = "pkg";
39       if (last_uri.indexOf("?") > 0)
40       {
41          String JavaDoc queryString = StringUtils.split(last_uri, "?")[1];
42          String JavaDoc[] pairs = StringUtils.split(queryString, "&");
43          String JavaDoc[] name_value;
44          for (int i=0; i<pairs.length; i++)
45          {
46             name_value = StringUtils.split(pairs[i], "=");
47             request.setAttribute(name_value[0], name_value[1]);
48             if ("cmd".equals(name_value[0]))
49                cmd = name_value[1];
50          }
51       }
52       session.setAttribute("trail", new LinkedList());
53       log.traceln("trail has been reset");
54       return cmd;
55    }
56   
57 }
58
Popular Tags