1
|
/*
|
2
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
3
|
$Id: Logger.js 3091 2007-08-09 12:21:54Z gjvoosten $
|
4
|
*/
|
5
|
|
6
|
// Ensure this object's dependancies are loaded.
|
7
|
mapbuilder.loadScript(baseDir+"/model/ModelBase.js");
|
8
|
|
9
|
/**
|
10
|
* Records a log of events that occur over the course of mapbuilder execution
|
11
|
* @constructor
|
12
|
* @base ModelBase
|
13
|
* @author Mike Adair
|
14
|
* @param modelNode Pointer to the xml node for this model from the config file.
|
15
|
* @param parent The parent model for the object.
|
16
|
*/
|
17
|
function Logger(modelNode, parent) {
|
18
|
// Inherit the ModelBase functions and parameters
|
19
|
ModelBase.apply(this, new Array(modelNode, parent));
|
20
|
this.namespace = "xmlns:mb='http://mapbuilder.sourceforge.net/mapbuilder'";
|
21
|
|
22
|
//create a new document
|
23
|
this.doc = Sarissa.getDomDocument("http://mapbuilder.sourceforge.net/mapbuilder","mb:Logger");//!no prefix on the URL
|
24
|
Sarissa.setXpathNamespaces(this.doc, this.namespace);
|
25
|
this.doc.async = false;
|
26
|
this.doc.validateOnParse=false; //IE6 SP2 parsing bug
|
27
|
|
28
|
/**
|
29
|
* appends a new entry in the log file
|
30
|
* @param evenType the name of the event that occured
|
31
|
* @param listenerId the ID of the listener object
|
32
|
* @param targetId the ID of the object passed to the listener function
|
33
|
* @param paramValue any parameter info supplied to the listener function
|
34
|
*/
|
35
|
this.logEvent = function(eventType, listenerId, targetId, paramValue) {
|
36
|
var eventLog = this.doc.createElement("event");
|
37
|
eventLog.setAttribute("time", new Date().getTime());
|
38
|
eventLog.setAttribute("listener", listenerId);
|
39
|
eventLog.setAttribute("target", targetId);
|
40
|
if (paramValue) eventLog.setAttribute("param", paramValue);
|
41
|
eventLog.appendChild(this.doc.createTextNode(eventType));
|
42
|
this.doc.documentElement.appendChild(eventLog);
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* clears all entries in the log file
|
47
|
*/
|
48
|
this.clearLog = function() {
|
49
|
while (this.doc.documentElement.hasChildNodes() ) {
|
50
|
this.doc.documentElement.removeChild(this.doc.documentElement.firstChild);
|
51
|
}
|
52
|
this.callListeners("refresh");
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* save the log by http post to the serializeUrl URL provided
|
57
|
*/
|
58
|
this.saveLog = function() {
|
59
|
if (config.serializeUrl) {
|
60
|
var tempDoc = postLoad(config.serializeUrl,logger.doc);
|
61
|
tempDoc.setProperty("SelectionLanguage", "XPath");
|
62
|
Sarissa.setXpathNamespaces(tempDoc, "xmlns:xlink='http://www.w3.org/1999/xlink'");
|
63
|
var onlineResource = tempDoc.selectSingleNode("//OnlineResource");
|
64
|
var fileUrl = onlineResource.attributes.getNamedItem("xlink:href").nodeValue;
|
65
|
alert(mbGetMessage("eventLogSaved", fileUrl));
|
66
|
} else {
|
67
|
alert(mbGetMessage("unableToSaveLog"));
|
68
|
}
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* save the log by http post to the serializeUrl URL provided
|
73
|
*/
|
74
|
this.refreshLog = function(objRef) {
|
75
|
objRef.callListeners("refresh");
|
76
|
}
|
77
|
|
78
|
if (parent) parent.addListener("refresh",this.refreshLog, this);
|
79
|
window.onunload = this.saveLog; //automatically save the log when the page unloads
|
80
|
window.logger = this; //global reference to the logger model
|
81
|
}
|