Stacktrace on Demand is a java utility method for when you want to know where in the call stack you
are, even though you may not be handling an exception.
public static String stackTrace(int maxLevels,String delim)
{
StringBuilder b = new StringBuilder("");
Exception t=new Exception();
t.fillInStackTrace();
StackTraceElement[] stea = t.getStackTrace();
for (int i=1; i <= (maxLevels > 0 ? Math.min(maxLevels,stea.length) : stea.length); i++)
{
b.append(i==1?"":delim).append(stea[i].getClassName())
.append(".").append(stea[i].getMethodName())
.append(":").append(stea[i].getLineNumber());
}
return b.toString();
}
..I used this once to track down where I was forgetting to set an audit column:
if (oaRejBy==0)
{
oaRejBy = db.getTempValue(Database.TempKeys.UserRow,0);
StringKit.println("Rejected By hack activated {0}-{1}-{2} uid {3}\n\t{4}",
SiteNum,oaOrder,oaTagNum,oaRejBy,
StringKit.stackTrace(8,"\n\t"));
}
WindowIdentifier is a JavaScript hack to differentiate between multiple browser windows open for the same Http session.
var WindowIdentifier = new function() {
/*
Window Identifier will place the window's open time in the form element named in accord
with the OpenTimeControlId constant below, and will also modify all anchors on the page
to include the open time in their query strings. If you are emitting link buttons, you
will need to augment them server side. Also expected on the form is an element named for
the PrvOpenTimeControlId value, which also gets added to anchors.
On the server side, if the client chooses open link in new window or in new tab, you will
not know it when emitting the first page to the new window, but as soon as they go anywhere
else in that window, your server side code will see that the values for the OpenTimeControlId
and PrvOpenTimeControlId parameters are both > 0 and not equal.
This means in the case of a location bar, or cookie-crumb-trail that many applications include,
that you want to track per window, your new window needs to clone the location bar of the
old one, and you may consider removing the last entry from the first window's location bar.
Be warned - if the user opens a new window or tab, then goes back to the first window and
starts navigating before doing anything in window two, weirdness could ensue.
Another challenge to consider is logout, if the user has multiple windows open, you could
change your logout to force the window to close, but not invalidate the Http Session. Recall
that you may not know if any window was closed by the user, and thus whether any given window
is the last one open so no perfectly seamless solution seems possible.
*/
this.setOpenTime = setOpenTime;
//private constants
var OpenTimeControlId="ot";
var PrvOpenTimeControlId="pot";
//exclude login page
var Exclusions = new Array("index.jsp");
//
function setOpenTime()
{
for (var i=0;i<Exclusions.length;i++)
{
if (-1 < window.location.href.toLowerCase().indexOf("/" + Exclusions[i].toLowerCase()))
return;
}
//we need a "slot" that will persist between requests - these work for IE 6,7 & Firefox 3
var ot = window.ActiveXObject ? window.name : navigator.openTime;
if (ot==null || ot=="" || isNaN(ot))
{
var d = new Date();
ot = Number(d.getHours() + "" + d.getMinutes() + d.getSeconds() + d.getMilliseconds());
if (window.ActiveXObject)
window.name=ot;
else
navigator.openTime = ot;
}
try
{
var ctlOt = document.getElementById(OpenTimeControlId);
var ctlPot = document.getElementById(PrvOpenTimeControlId);
if (ctlOt == null || ctlPot == null)
{
alert("You need form elements named '" + OpenTimeControlId
+ "' and '" + PrvOpenTimeControlId + "'"
+ " to use WindowIdentifier");
return;
}
ctlOt.value = ot;
var pot = Number(ctlPot.value);
var aa = document.getElementsByTagName("A");
for (var i=0;aa!=null && i<aa.length;i++)
{
aa[i].href = setParameter(setParameter(aa[i].href,OpenTimeControlId,ot),PrvOpenTimeControlId,pot);
}
}
catch(e)
{
alert("setOpenTime error: " + e);
}
}
function setParameter(url,parmName,parmVal)
{
try
{
var parmAt = Math.max(url.indexOf("&" + parmName + "="),url.indexOf("?" + parmName + "="));
if (parmAt == -1)
{
if (url.charAt(url.length-1)!="?")
url += url.indexOf("?") == -1 ? "?" : "&";
return url + parmName + "=" + parmVal;
}
var andAt = url.indexOf("&",parmAt + 1);
if (andAt==-1)
return url.substring(0,parmAt + 1) + parmName + "=" + parmVal;
return url.substring(0,parmAt + 1) + parmName + "=" + parmVal + url.substring(andAt);
}
catch(e)
{
alert("setParameter error: " + e);
}
}
/*end WindowIdentifier*/}