Monday, November 08, 2010 at 12:03 AM.
system.verbs.builtins.html.fileWriters.odb.write
on write (adrData, path, type, creator, creationDate, adrPageTable, adrStorage) {
<<This script is called whenever a file needs to be written somewhere.
<<Parameters:
<<adrData: this is the address of data the file should contain.
<<path: path is a relative, /-delimited path.
<<It's relative to the ftpSite^.folder.
<<type: the file type.
<<creator: the file creator.
<<creationDate: should be the creation data of the file.
<<adrPageTable: the address of the current page data table.
<<This script doesn't have to write the file immediately --
<<it could defer writing until the shutdown script is called.
<<Changes:
<<Thu, Jun 3, 1999 at 10:21:35 PM by PBS
<<Put brackets around elements in path, so table names like 1999 would become ["1999"].
<<Reworked the bundle that gets odbAddress from the ftpSite to avoid using try statements.
local (adrFtpSite);
local (objectName, adrItem);
local (templateName = html.getCurrentTemplateName (adrPageTable));
on assureTablePath (s) {
table.sureDatabaseOpen (s);
local (pathList = string.parseAddress (s));
local (adr = @[pathList [1]]);
local (i);
if not defined (adr^) {
new (tableType, adr)};
for i = 2 to sizeOf (pathList) - 1 {
adr = @adr^.[pathList [i]];
if not defined (adr^) {
new (tableType, adr)}};
return (adr)};
on getSuffix (s, chsep = '.') {
local (i, suffix = "");
for i = sizeOf (s) downto 1 {
local (ch = s [i]);
if ch == chsep {
break};
suffix = ch + suffix};
return (suffix)};
adrFtpSite = html.getSiteTable (adrPageTable);
bundle { //get the odb address specified in the #ftpSite
on setDest (adrOdbAddress) {
if typeOf (adrOdbAddress^) == scriptType {
adrItem = adrOdbAddress^ ()}
else {
adrItem = string (adrOdbAddress^)}};
if defined (adrFtpSite^.[templateName].odbAddress) {
setDest (@adrFtpSite^.[templateName].odbAddress)}
else {
setDest (@adrFtpSite^.odbAddress)}};
objectName = getSuffix (path, '/');
if path contains "/" {
path = string.popSuffix (path, '/');
<<Make brackets out of fields in path. PBS 6/3/99
local (ct = 1);
local (oldPath = path);
path = "";
loop {
local (s = string.nthField (oldPath, '/', ct));
if s == "" {
break};
s = "[\"" + s + "\"]";
path = path + "." + s;
ct++}}
else {
path = ""};
path = string.replaceAll (path, "/", ".");
path = path + ".[\"" + objectName + "\"]";
if not (path beginsWith ".") {
path = "." + path};
adrItem = adrItem + path;
assureTablePath (adrItem);
if typeOf (adrData^) == stringType {
wp.newTextObject (adrData^, adrItem)}
else {
try {delete (adrItem)};
adrItem^ = adrData^};
if not defined (adrStorage^.adrDatabase) { //save adrDatabase for shutdown script
local (adrDatabase = string.parseAddress (adrItem));
adrDatabase = adrDatabase [1];
adrStorage^.adrDatabase = adrDatabase};
return (true)}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.