com.zentense.step2.util
Class Location

java.lang.Object
  extended by com.zentense.step2.util.Location

public class Location
extends java.lang.Object

This class manipulates URL locations: you can forward to a new location, or just go back, save a URL and restore it afterwards, or cypher URLs. The global variable url is initialized when a new session begins with a new instance of Location.

This class also stores a stack of visited URL locations in this session. Each request is saved except if the request parameter 'forward' is present.

Version:
$Revision: 1.11 $
Author:
Jose R. Cabanes

Nested Class Summary
 class Location.URL
           
 
Constructor Summary
Location()
          Empty constructor
Location(RequestRuntime vm)
          Constructs the location and saves current page
 
Method Summary
 void back()
          Goes to previous URL (goes back!)
 void back(int seq)
          Goes to previous URL (goes back!)
 java.lang.String cypher(RequestRuntime vm, java.lang.String url)
          Cyphers a URL
 java.lang.String decypher(java.lang.String url)
          Decyphers a URL
static void forward(java.lang.String url)
          Forwards to another page in this session
static void forwardExternal(RequestRuntime vm, java.lang.String url)
          Forwards to a URL outside this session.
 java.lang.String getBackURL()
          Gets previous URL (the one you would go if you would click on back button).
 java.lang.String getCheckpointURL()
          Gets checkpoint URL (URL that was saved with save method)
 java.lang.String getCurrentURL()
          Gets the 'current' URL.
 java.lang.String getHREF(java.lang.String name)
           
 int getSequence()
          Gets current sequence number
 Location.URL getURL(HttpServletRequest req)
           
 void initCypher(HttpServletRequest req)
          Creates private key for cyphering URLs
 java.lang.String popRequest()
          Removes last request from the location stack
 void pushRequest(HttpServletRequest req)
          Used internayly by 2step: pushes a request into the location stack
 void refresh()
          Refreshes current URL
 void refresh(int seq)
          Reloads a URL
 void restore()
          Restores a previously saved location
 void save(HttpServletRequest req)
          Saves current url, so it could be restored with restore in the future
 void save(HttpServletRequest req, java.lang.String params)
          Saves current url, so it could be restored with restore.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Location

public Location()
Empty constructor


Location

public Location(RequestRuntime vm)
Constructs the location and saves current page

Parameters:
req - Servlet request whose parameters will be saved
Method Detail

getCurrentURL

public final java.lang.String getCurrentURL()
Gets the 'current' URL. In fact gets the previous URL. Suppose this case: there is a list of items and a link that change list order and then the same page must be rendered. In that case this method may be used for rendering the list again from the action that has changed list order.

Returns:
URL parameters

getBackURL

public final java.lang.String getBackURL()
Gets previous URL (the one you would go if you would click on back button). In fact it returns the URL two places ago in the locations stack. This is this way because it is supposed that the request that calls this method pushes the locations stack

Returns:
URL parameters

getCheckpointURL

public final java.lang.String getCheckpointURL()
Gets checkpoint URL (URL that was saved with save method)

Returns:
URL parameters

save

public final void save(HttpServletRequest req,
                       java.lang.String params)
Saves current url, so it could be restored with restore.

Parameters:
req - Servlet request whose parameters will be saved
params - Extra params to be appended to the URL

save

public final void save(HttpServletRequest req)
Saves current url, so it could be restored with restore in the future

Parameters:
req - Servlet request whose parameters will be saved

getURL

public final Location.URL getURL(HttpServletRequest req)

pushRequest

public final void pushRequest(HttpServletRequest req)
Used internayly by 2step: pushes a request into the location stack

Parameters:
req - Request to be pushed

popRequest

public final java.lang.String popRequest()
Removes last request from the location stack


restore

public final void restore()
                   throws java.lang.Exception
Restores a previously saved location

Parameters:
vm - A RequestRuntime instance
Throws:
java.lang.Exception - If forward fails

refresh

public final void refresh()
                   throws java.lang.Exception
Refreshes current URL

Parameters:
vm - A RequestRuntime instance
Throws:
java.lang.Exception - If forward fails

refresh

public final void refresh(int seq)
                   throws java.lang.Exception
Reloads a URL

Parameters:
vm - A RequestRuntime instance
seq - Sequence number of URL to be refreshed
Throws:
java.lang.Exception - If forward fails

back

public final void back()
                throws java.lang.Exception
Goes to previous URL (goes back!)

Parameters:
vm - A RequestRuntime instance
Throws:
java.lang.Exception - If forward fails

back

public final void back(int seq)
                throws java.lang.Exception
Goes to previous URL (goes back!)

Parameters:
vm - A RequestRuntime instance
seq - Sequence number of URL from where go back
Throws:
java.lang.Exception - If forward fails

forward

public static final void forward(java.lang.String url)
                          throws java.lang.Exception
Forwards to another page in this session

Parameters:
vm - A RequestRuntime instance
url - URL where to go to
Throws:
java.lang.Exception - If forward fails

forwardExternal

public static final void forwardExternal(RequestRuntime vm,
                                         java.lang.String url)
                                  throws java.lang.Exception
Forwards to a URL outside this session.

Parameters:
vm - A RequestRuntime instance
url - URL where to go to
Throws:
java.lang.Exception - If forward fails

getSequence

public final int getSequence()
Gets current sequence number

Returns:
Sequence number

initCypher

public final void initCypher(HttpServletRequest req)
Creates private key for cyphering URLs

Parameters:
req - servlet request

cypher

public final java.lang.String cypher(RequestRuntime vm,
                                     java.lang.String url)
Cyphers a URL

Parameters:
vm - A RequestRuntime instance
url - URL to cypher
Returns:
Cyphered URL

decypher

public final java.lang.String decypher(java.lang.String url)
Decyphers a URL

Parameters:
url - Cyphered URL
Returns:
Original URL

getHREF

public final java.lang.String getHREF(java.lang.String name)

 

© Zentense 2008