I believe Jun has already done something similar. Check out:
https://openacs.org/bboard/q-and-a-fetch-msg.tcl?msg_id=0005JX