Tuesday, April 12, 2011 at 12:01 AM.
system.verbs.builtins.staticText.write
on write (adrdata, path, data) {
<<Changes
<<3/16/11; 11:03:12 AM by DW
<<Call with adrdata == nil if you want to use the global prefs, otherwise pass in the address of the place where you're storing your prefs.
local (adrloc, urlToReturn="", pc = file.getpathchar (), now = clock.now ());
adrdata = statictext.init (adrdata);
data = string (data);
if path beginswith "/" {
path = string.delete (path, 1, 1)};
for adrloc in @adrdata^.locations {
staticText.initLocation (adrdata, nameof (adrloc^));
if adrloc^.prefs.enabled {
local (thispath);
bundle { //set up thispath
thispath = adrloc^.prefs.path;
if not (thispath endswith "/") {
thispath = thispath + "/"};
thispath = thispath + path};
try {
case string.lower (adrloc^.prefs.driver) {
"s3" {
s3.newobject (thispath, data)};
"ftp" {
local (connection = tcp.ftp.openConnection (adrloc^.prefs.server, adrloc^.prefs.username, adrloc^.prefs.password));
tcp.ftp.writefile (connection, data, thispath);
tcp.ftp.closeConnection (connection)};
"filesystem" {
local (f = string.replaceall (thispath, "/", pc));
f = string.replaceall (f, pc + pc, pc);
file.surefilepath (f);
file.writewholefile (f, data)}}}
else {
adrloc^.stats.ctErrors++;
adrloc^.stats.whenLastError = now;
adrloc^.stats.lastError = tryerror};
if adrloc^.prefs.flDefault {
urlToReturn = adrloc^.prefs.url + path};
adrloc^.stats.ctWrites++;
adrloc^.stats.whenLastWrite = now}};
return (urlToReturn)};
bundle { //test code
dialog.alert (write (@config.statictext, "test.txt", clock.now ()))}
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.