Monday, November 08, 2010 at 12:03 AM.
system.verbs.builtins.html.getPath
on getPath (adrSource, adrDest, adrPageTable=nil) {
<<Revised for performance Sat, May 16, 1998 at 12:16:06 AM by PBS
<<Old code:
<<on getPath (adrSource, adrDest, pageTable=nil) //5.0.1. Generate a URL for an odb page.
<<local (nomad, commonTable)
<<local (url = "", url2 = "")
<<
<<if pageTable == nil
<<try
<<pageTable = html.data.adrPageTable
<<else
<<pageTable = @websites.["#data"]
<<if typeOf (adrDest) == tableType //it's an error if it's a table.
<<scriptError ("Can't calculate path to \"" + adrDest + "\" because it's a table.")
<<if typeOf (adrSource^) != tableType
<<adrSource = parentOf (adrSource^)
<<
<<Find the common table.
<<commonTable = adrSource
<<loop //walk backwards, looking for a common table.
<<if table.tableContains (commonTable, adrDest)
<<break //found it
<<commonTable = parentOf (commonTable^)
<<url = "../" + url
<<if commonTable == @root or commonTable == nil
<<break
<<
<<Walk back from the destination to the common table.
<<nomad = parentOf (adrDest^)
<<loop
<<if nomad == commonTable
<<break
<<bundle //check for an #ftpSite table.
<<try
<<url2 = nomad^.["#ftpSite"].url + url2
<<break
<<try
<<url2 = nomad^.["#prefs"].["#ftpSite"].url + url2
<<break
<<try
<<url2 = nomad^.["#prefs"].["ftpSite"].url + url2
<<break
<<url2 = nameOf (nomad^) + "/" + url2
<<nomad = parentOf (nomad^)
<<
<<url2 = url2 + html.normalizeName (nameOf (adrDest^), pageTable, adrDest)
<<local (fileExtension)
<<if string.lower (html.getPref ("responder")) == "websiteframework"
<<fileExtension = ".wsf"
<<else
<<fileExtension = html.getPagePref ("fileExtension", adrDest)
<<url2 = url2 + fileExtension
<<if (url2 beginsWith "http://") or (url2 beginsWith "file:///") //it's a fully-qualified URL.
<<url = url2
<<else //it's a relative URL.
<<url = url + url2
<<
<<return (url)
local (flSameWebsite = false);
local (urlPrefix = "", path = "", fileExtension = "");
local (adrSourceRoot, adrDestRoot);
if adrPageTable == nil { //get the current page table address
adrPageTable = html.getPageTableAddress ()};
bundle { //if the pages are on the same level, return now
if parentOf (adrSource^) == parentOf (adrDest^) {
local (fileExtension = html.getPagePref ("fileExtension", adrDest, adrPageTable));
local (fname = html.normalizeName (nameOf (adrDest^)));
if html.inResponder (adrPageTable) {
return (fname + ".wsf")};
return (fname + fileExtension)}};
bundle { //get the root tables of adrSource and adrDest
on getSourceRoot () {
local (nomad = adrSource);
if typeOf (adrSource^) != tableType {
nomad = parentOf (nomad^)};
loop {
if defined (nomad^.["#ftpSite"]) {
return (nomad)};
if defined (nomad^.["#prefs"].ftpSite) {
return (nomad)};
if defined (nomad^.["#prefs"].["#ftpSite"]) {
return (nomad)};
nomad = parentOf (nomad^);
if nomad == nil or nomad == @root {
scriptError ("Can't get the root table of \"" + nameOf (adrSource^) + "\" because it has no #ftpSite table.")};
urlPrefix = "../" + urlPrefix}};
on getDestRoot () {
local (nomad = parentOf (adrDest^));
loop {
if fileExtension == "" {
if defined (nomad^.["#fileExtension"]) {
fileExtension = nomad^.["#fileExtension"]}
else {
if defined (nomad^.["#prefs"].fileExtension) {
fileExtension = nomad^.["#prefs"].fileExtension}
else {
if defined (nomad^.["#prefs"].["#fileExtension"]) {
fileExtension = nomad^.["#prefs"].["#fileExtension"]}}}};
if defined (nomad^.["#ftpSite"]) {
return (nomad)};
if defined (nomad^.["#prefs"].ftpSite) {
return (nomad)};
if defined (nomad^.["#prefs"].["#ftpSite"]) {
return (nomad)};
path = nameOf (nomad^) + "/" + path;
nomad = parentOf (nomad^);
if nomad == nil or nomad == @root {
scriptError ("Can't get the root table of \"" + nameOf (adrDest^) + "\" because it has no #ftpSite table.")}}};
adrSourceRoot = getSourceRoot ();
adrDestRoot = getDestRoot ()};
bundle { //are the two pages in the same website?
flSameWebsite = (adrSourceRoot == adrDestRoot)};
if flSameWebsite { //generate a relative URL
local (fname = html.normalizeName (nameOf (adrDest^), adrPageTable, adrDest));
local (foundFileExtension = fileExtension);
if html.inResponder (adrPageTable) {
fileExtension = ".wsf"}
else {
fileExtension = html.getOneDirective ("fileExtension", adrDest^);
if fileExtension == "" {
fileExtension = foundFileExtension};
if fileExtension == "" {
fileExtension = html.getPagePref ("fileExtension", adrDest, adrPageTable)}};
return (urlPrefix + path + fname + fileExtension)}
else { //generate a hard-coded URL
local (destPageTable, fileExtension);
new (tableType, @destPageTable);
html.buildPageTable (adrDest, @destPageTable);
fileExtension = html.getPagePref ("fileExtension", adrDest, adrPageTable);
if not (destPageTable.fname endsWith fileExtension) {
destPageTable.fname = html.normalizeName (nameOf (adrDest^), @destPageTable, adrDest);
destPageTable.fname = destPageTable.fname + fileExtension};
if not (destPageTable.url endsWith destPageTable.fname) {
destPageTable.url = string.popSuffix (destPageTable.url, '/');
destPageTable.url = destPageTable.url + "/" + destPageTable.fname};
return (destPageTable.url)}}
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.