- ThinkInSQL is a persistence solution written in both Java and C# that we've been using and evolving from a C++ one started in 1993, both now open-sourced under the GNU Lesser General Public License.
- 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();
int max=(maxLevels > 0 ? Math.min(maxLevels,stea.length) : stea.length);
for (int i=1;i <= max;i++)
{
b.append(i==1?"":delim).append(stea[i].getClassName())
.append(".").append(stea[i].getMethodName())
.append(":").append(stea[i].getLineNumber());
}
return b.toString();
}
..we used this once to track down where were 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"));
}
- LabelRunner is a pair of handy classes for printing labels, originally designed for use with the fabulous iText open source PDF generation library.
/**
* Provides an algorithm to print labels - issues callbacks to consumer
* for printing and paging events. Note that the iText coordinate
* system is used.
*/
public class LabelRunner
{
public int CountAcross;
public int CountDown;
public boolean DownThenAcross;
public float HorizSpace;
public float LabelHeight;
public float LabelWidth;
public int SkipLabels=0;
public float StartX;
public float StartY;
public ILabelPrinter ThePrinter;
public float VertSpace;
//
public void initAvery5160(ILabelPrinter p)
{
CountAcross=3;
CountDown=10;
HorizSpace=9;
LabelHeight=72f;
LabelWidth=189f;
StartX = 18;
StartY = 744;
ThePrinter = p;
VertSpace=0;
}
//
public void initAvery5163(ILabelPrinter p)
{
CountAcross=2;
CountDown=5;
HorizSpace=12;
LabelHeight=146f;
LabelWidth=288f;
StartX = 18;
StartY = 740;
ThePrinter = p;
VertSpace=0;
}
//
public void initAvery6751(ILabelPrinter p)
{
CountAcross=2;
CountDown=15;
HorizSpace=38;
LabelHeight=50f;
LabelWidth=247.5f;
StartX = 38;
StartY = 744;
ThePrinter = p;
VertSpace=0;
}
//
public void run() throws Exception
{
float x=StartX;
float y=StartY;
float stepX = LabelWidth + HorizSpace;
float stepY = 0 - (LabelHeight + VertSpace);
int label=1;
int labelsPerPage= CountDown*CountAcross;
ThePrinter.labelStartPage();
boolean bContinue=true;
while (bContinue)
{
if (label > SkipLabels)
{
bContinue = ThePrinter.labelPrint(label - SkipLabels,x,y);
}
label++;
if (labelsPerPage==1 || label % labelsPerPage == 1)
{
ThePrinter.labelEndPage();
ThePrinter.labelStartPage();
x = StartX;
y = StartY;
}
else
{
if (DownThenAcross)
{
if (label % CountDown == 1)
{
x += stepX;
y = StartY;
}
else
{
y += stepY;
}
}
else
{
if (label % CountAcross == 1)
{
x = StartX;
y += stepY;
}
else
{
x += stepX;
}
}
}
}
ThePrinter.labelEndDocument();
}
}
/**
* Defines behavior required of consumers of LabelRunner
*/
public interface ILabelPrinter
{
/**
* End a document of labels.
*/
void labelEndDocument() throws Exception;
/**
* End a page of labels.
*/
void labelEndPage() throws Exception;
/**
* Print a label, return whether to continue printing.
*/
boolean labelPrint(int label, float x, float y) throws Exception;
/**
* Start a new page of labels.
*/
void labelStartPage() throws Exception;
}
- 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.
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.
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*/}