Monday, November 08, 2010 at 12:03 AM.


on writeFile (f, adrData, type=nil, creator=nil, creationDate=nil, adrPageTable=nil) {
	<<4/14/98 by PBS: New in 5.1. Bottleneck script for writing files.
		<<Use this instead of file.writeWholeFile.
		<<This script is key to supporting rendering to places other than the file system.
		<<Change notes:
			<<Added file.sureFilePath call for previews.
				<<Tue, Aug 11, 1998 at 9:06:19 PM by PBS
	local (adrFtpSite, adrScript, adrStorage);
	local (method, path);
	if adrPageTable == nil {
		adrPageTable = html.getPageTableAddress ()};
	<<Don't write a file if this is a dynamic page.
		<<Return quickly.
	if defined (adrPageTable^.requestHeaders) {
	adrStorage = html.getFileWriterStorage ();
	if not defined (adrStorage^) { //not using fileWriters framework
		return (file.writeWholeFile (f, adrData^, type, creator, creationDate))};
	if adrPageTable == nil {
		adrPageTable = html.getPageTableAddress ()};
	if creationDate == nil {
		creationDate = ()};
	<<Is this a preview? Previews are always written to disk.
	if defined (adrPageTable^.flPreview) and (adrPageTable^.flPreview) {
		adrStorage^.flPreview = true; //html.callFileWriterShutdown looks for this
		file.sureFilePath (f);
		return (file.writeWholeFile (f, adrData^, type, creator, creationDate))};
	<<Get the FTP site and transport method.
	method = adrPageTable^.fileWriter;
	<<Get the address of the file writer script.
	bundle {
		try {
			adrScript = adrStorage^.adrWriteScript}
		else {
			if not defined (user.html.fileWriters) {
				new (tableType, @user.html.fileWriters)};
			if defined (user.html.fileWriters.[method]) {
				adrScript = @user.html.fileWriters.[method].write}
			else {
				if defined (html.fileWriters.[method]) {
					adrScript = @html.fileWriters.[method].write}};
			adrStorage^.adrWriteScript = adrScript}};
	<<Convert the disk path to a relative, slash-delimited path.
	bundle {
		local (folder);
		try {
			folder = adrPageTable^.siteRootFolder}
		else {
			folder = html.getSiteFolder (adrPageTable);
			adrPageTable^.siteRootFolder = folder};
		adrStorage^.siteFolder = folder;
		path = string.mid (f, sizeOf (folder), infinity);
		path = string.replaceAll (path, file.getPathChar (), "/");
		if path beginsWith "/" {
			path = string.mid (path, 2, infinity)}};
	<<Call the file writer script.
	return (adrScript^ (adrData, path, type, creator, creationDate, adrPageTable, adrStorage))}

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.