HistoryObject.java
-------------------
package com.domain.util;
import java.util.*;
import java.text.SimpleDateFormat;
import org.apache.turbine.util.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.httpclient.util.URIUtil;
import org.apache.commons.httpclient.URIException;
/**
* The history object stores each history line item
* for the HistoryTool.
*
[EMAIL PROTECTED] bfolkens
[EMAIL PROTECTED] November 15, 2002
*/
public class HistoryObject
{
private static Log log = LogFactory.getLog(HistoryObject.class);
/**
* Description of the Field
*/
private String pathInfo;
private String title;
/**
* Description of the Field
*/
private Hashtable parameterData;
private Date timestamp;
/**
* Constructor for the HistoryObject object
*/
public HistoryObject()
{
timestamp = new Date();
}
/**
* Gets the time attribute of the HistoryObject object
*
[EMAIL PROTECTED] The time value
*/
public String getTime()
{
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy
hh:mm");
return (sdf.format(timestamp));
}
/**
* Sets the pathInfo attribute of the HistoryObject object
*
[EMAIL PROTECTED] s The new pathInfo value
*/
public void setPathInfo(String s)
{
this.pathInfo = s;
}
/**
* Sets the title attribute of the HistoryObject object
*
[EMAIL PROTECTED] s The new title value
*/
public void setTitle(String s)
{
this.title = s;
}
/**
* Sets the parameterData attribute of the HistoryObject object
*
[EMAIL PROTECTED] m The new parameterData value
*/
public void setParameterData(Hashtable m)
{
this.parameterData = m;
}
/**
* Gets the pathInfo attribute of the HistoryObject object
*
[EMAIL PROTECTED] The pathInfo value
*/
public String getPathInfo()
{
return (pathInfo);
}
/**
* Gets the parameterData attribute of the HistoryObject object
*
[EMAIL PROTECTED] The parameterData value
*/
public Hashtable getParameterData()
{
return (parameterData);
}
/**
* Gets the title attribute of the HistoryObject object
*
[EMAIL PROTECTED] The title value
*/
public String getTitle()
{
return (title);
}
/**
* Get the name of the history object - essentially a line of
history.
*
[EMAIL PROTECTED] The history description line
*/
public String getName()
{
String tmpStr = new String();
Hashtable h = getParameterData();
Enumeration e = h.keys();
while (e.hasMoreElements())
{
try
{
String key = (String) e.nextElement();
String value = (String) h.get(key);
if (!key.equals("Search") &&
!key.equals("searchblank"))
{
tmpStr += "'" + key + "=" +
translate(key, value) + "'";
if (e.hasMoreElements())
{
tmpStr += ", ";
}
}
}
catch (Exception ex)
{
log.error("Cannot format output string for
history: " + ex);
}
}
return (tmpStr);
}
/**
* Translate keys (for example int IDs -> Names) from search forms,
etc
* in the history list. This makes certain int values a lot easier
to read.
*
[EMAIL PROTECTED] key The name of the key to transform
[EMAIL PROTECTED] value Primary key to reference
[EMAIL PROTECTED] Translated key string
[EMAIL PROTECTED] Exception From database access to resolve keys
*/
public String translate(String key, String value)
throws Exception
{
String tmpStr = value;
if (key.equals("Someid"))
{
// Find the id in the database
// i.e. tmpStr =
TbljobPeer.retrieveByPK(value).getName();
}
return (tmpStr);
}
/**
* Gets the URL attribute of the HistoryObject object
*
[EMAIL PROTECTED] data The rundata object from the calling VTL
[EMAIL PROTECTED] The URL value
*/
public String getURL(RunData data)
{
String tmpStr = data.getServerScheme() + "://" +
data.getServerName() + getPathInfo();
Hashtable h = getParameterData();
Enumeration e = h.keys();
if (e.hasMoreElements())
{
tmpStr += "?";
}
while (e.hasMoreElements())
{
String key = (String) e.nextElement();
String value = (String) h.get(key);
if (!key.equals("Search"))
{
try
{
tmpStr += key + "=" +
URIUtil.encodeAll(value);
if (e.hasMoreElements())
{
tmpStr += "&";
}
}
catch (URIException urie)
{
log.error("Cannot format url
correctly for history list:" + urie);
}
}
}
return (tmpStr);
}
}
HistoryList.java
-----------------
package com.domain.tools;
import java.util.*;
import java.lang.reflect.*;
import javax.servlet.http.HttpSession;
import org.apache.turbine.modules.screens.VelocityScreen;
import org.apache.torque.util.Criteria;
import org.apache.velocity.context.Context;
import org.apache.turbine.services.velocity.TurbineVelocity;
import org.apache.turbine.util.*;
import org.apache.turbine.om.*;
import org.apache.turbine.om.security.*;
import com.domain.util.HistoryObject;
import org.apache.turbine.services.pull.ApplicationTool;
import org.apache.turbine.util.pool.Recyclable;
/**
* Description of the Class
*
[EMAIL PROTECTED] bfolkens
[EMAIL PROTECTED] April 18, 2003
*/
public class HistoryList implements ApplicationTool, Recyclable
{
User user = null;
ArrayList historyList = null;
/**
* Initialize the ApplicationTool
*
[EMAIL PROTECTED] user Description of the Parameter
*/
public void init(Object user)
{
// session tool - so use user
this.user = (User) user;
this.historyList = new ArrayList();
}
/**
* Refresh the ApplicationTool
*/
public void refresh()
{
// don't really need much here either
}
/**
* Adds a URL / Page to the history
*
[EMAIL PROTECTED] title The title of the history line
[EMAIL PROTECTED] data The RunData object from the calling VTL
*/
public void addPage(String title, RunData data)
{
String strPathinfo = data.getRequest().getRequestURI();
Map dataList = data.getRequest().getParameterMap();
Hashtable dataHash = new Hashtable();
if (dataList != null && dataList.size() > 0)
{
Iterator i = dataList.entrySet().iterator();
while (i.hasNext())
{
Map.Entry entry = (Map.Entry) i.next();
if (entry != null && entry.getKey() != null
&& entry.getValue() != null)
{
String key = new String((String)
entry.getKey());
String value = new
String(((String[]) entry.getValue())[0]);
if (value != null && value.length()
> 0)
{
dataHash.put(key, value);
}
}
}
}
// Only add a new one if the current one is different from
the "top"
boolean addTop = true;
if(historyList != null && historyList.size() > 0)
{
HistoryObject top =
(HistoryObject)historyList.get(0);
addTop = !top.getTitle().equals(title);
}
if(addTop)
{
HistoryObject historyObject = new HistoryObject();
historyObject.setTitle(title);
historyObject.setPathInfo(strPathinfo);
historyObject.setParameterData(dataHash);
historyList.add(0,historyObject);
if(historyList.size() > 5)
{
historyList.remove(5);
}
}
}
/**
* Gets the history list
*
[EMAIL PROTECTED] The history list
*/
public List getHistory()
{
return (historyList);
}
// Recyclable implementation
/**
* Description of the Method
*/
public void recycle()
{
// don't really need much else
}
private boolean disposed = false;
/**
* Description of the Method
*/
public void dispose()
{
disposed = true;
user = null;
historyList = null;
}
/**
* Gets the disposed attribute of the FormLoader object
*
[EMAIL PROTECTED] The disposed value
*/
public boolean isDisposed()
{
return (disposed);
}
}
-----Original Message-----
From: Daniel Moldovan [mailto:[EMAIL PROTECTED]
Sent: Thursday, December 04, 2003 2:21 AM
To: '[EMAIL PROTECTED]'
Subject: user history action
Hi,
I wonder if anyone can suggest me a history
mechanism. I mean another than the browser's
mechanism. I want to avoid than actions would be
executed again, and I want to skip some screens if
I want to. It should be a flexible mechanism.
If anyone already did this, I would appreciate if
he/she will share it.
Thanks,
Daniel