2002-11-22 11:39:11 +00:00
|
|
|
|
2002-12-02 12:18:15 +00:00
|
|
|
/**
|
|
|
|
* get the prototype of any doc-object (either a prototype, a function or a tag)
|
|
|
|
*/
|
2002-11-22 11:39:11 +00:00
|
|
|
function getDocPrototype (obj) {
|
|
|
|
var tmp = obj;
|
|
|
|
while (tmp!=null && tmp.getType () != this.PROTOTYPE) {
|
|
|
|
tmp = tmp.getParentElement ();
|
|
|
|
}
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2002-12-02 12:18:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get a prototype of this docapplication, ie get on of the children of this object
|
|
|
|
*/
|
|
|
|
function getPrototype (name) {
|
|
|
|
return this.getChildElement ("prototype_" + name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-22 11:39:11 +00:00
|
|
|
function getDir (dir, obj) {
|
|
|
|
dir.mkdir ();
|
|
|
|
if (obj.getType () == this.APPLICATION) {
|
|
|
|
return dir;
|
|
|
|
} else {
|
|
|
|
var protoObj = this.getDocPrototype (obj);
|
2002-11-22 14:32:46 +00:00
|
|
|
var dir = new File (dir, protoObj.getElementName ());
|
2002-11-22 11:39:11 +00:00
|
|
|
dir.mkdir ();
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-22 14:32:46 +00:00
|
|
|
function storePage (obj, action, backPath, filename) {
|
|
|
|
if (filename==null)
|
|
|
|
var filename = action + ".html";
|
2002-11-22 11:39:11 +00:00
|
|
|
var str = this.getPage (obj, action, backPath);
|
|
|
|
var appObj = this.getParentElement ();
|
|
|
|
var dir = new File (appObj.getAppDir ().getAbsolutePath (), ".docs");
|
|
|
|
dir = this.getDir (dir, obj);
|
2002-11-22 14:32:46 +00:00
|
|
|
var f = new File (dir, filename);
|
2002-11-22 11:39:11 +00:00
|
|
|
f.remove ();
|
|
|
|
f.open ();
|
|
|
|
f.write (str);
|
|
|
|
f.close ();
|
|
|
|
app.log ("wrote file " + f.toString ());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getPage (obj, action, backPath) {
|
|
|
|
backPath = (backPath==null) ? "" : backPath;
|
|
|
|
res.pushStringBuffer ();
|
|
|
|
eval ("obj." + action + "_action ();");
|
|
|
|
var str = res.popStringBuffer ();
|
2002-11-22 14:32:46 +00:00
|
|
|
// get the baseURI out of the url and replace
|
|
|
|
// it with the given relative prefix
|
2002-12-04 09:35:09 +00:00
|
|
|
// (keep anchors in regex!)
|
|
|
|
var reg = new RegExp ("href=\"" + this.href ("") + "([^\"#]+)([^\"]*)\"");
|
2002-11-22 11:39:11 +00:00
|
|
|
reg.global = true;
|
2002-12-04 09:35:09 +00:00
|
|
|
str = str.replace (reg, "href=\"" + backPath + "$1.html$2\"");
|
|
|
|
var reg = new RegExp ("src=\"" + this.href ("") + "([^\"#]+)([^\"]*)\"");
|
2002-11-22 11:39:11 +00:00
|
|
|
reg.global = true;
|
2002-12-04 09:35:09 +00:00
|
|
|
str = str.replace (reg, "src=\"" + backPath + "$1.html$2\"");
|
2002-11-22 14:32:46 +00:00
|
|
|
// shorten links, so that function files can move up one directory
|
|
|
|
// in the hierarchy
|
|
|
|
var reg = new RegExp ("(prototype_[^/]+/[^/]+)/main.html");
|
|
|
|
reg.global = true;
|
|
|
|
str = str.replace (reg, "$1.html");
|
2002-11-22 11:39:11 +00:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|