Project

General

Profile

1
<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
2
<html>
3
<head>
4
<title>
5
<a href='http://mapbuilder.sourceforge.net'>Community Map Builder</a> 27 Apr 2008 Overview
6
</title>
7
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
8
<script>
9
function asd() {
10
	
11
		parent.document.title="Config.js Overview";
12
	
13
}
14
</script>
15
</head>
16
<body bgcolor="white" onload="asd();">
17

    
18
<!-- ========== START OF NAVBAR ========== -->
19
<a name="navbar_top"><!-- --></a>
20
<table border="0" width="100%" cellpadding="1" cellspacing="0">
21
<tr>
22
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
23
<a name="navbar_top_firstrow"><!-- --></a>
24
<table border="0" cellpadding="0" cellspacing="3">
25
  <tr align="center" valign="top">
26
  
27
  
28
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
29
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
30
  
31

    
32
  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
33
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
34
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
35
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
36
  </tr>
37
</table>
38
</td>
39
<td bgcolor="#EEEEFF" align="right" valign="top">
40
<em>
41
<b><a href='http://mapbuilder.sourceforge.net'>Community Map Builder</a> 27 Apr 2008</b></em>
42
</td>
43
</tr>
44

    
45
<tr>
46
<td bgcolor="white" class="NavBarCell2"><font size="-2">
47
&nbsp;PREV&nbsp;
48
&nbsp;NEXT</font></td>
49
<td bgcolor="white" class="NavBarCell2"><font size="-2">
50
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
51
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
52
&nbsp;&nbsp;
53
<script>
54
  <!--
55
  if(window==top) {
56
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
57
  }
58
  //-->
59
</script>
60
<noscript>
61
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
62
</noscript>
63
</font></td>
64
</tr>
65
</table>
66
<!-- =========== END OF NAVBAR =========== -->
67

    
68
<hr>
69
<center>
70
	
71
	   <h2>Config.js</h2>
72
	
73
</center>
74

    
75
	
76

    
77

    
78
<h4>Summary</h4>
79
<p>
80
	
81
		No overview generated for 'Config.js'<BR/><BR/>
82
	
83
</p>
84

    
85
<hr>
86

    
87

    
88
    <table border="1" cellpadding="3" cellspacing="0" width="100%">
89
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
90
    <td colspan=2><font size="+2">
91
    
92
        <b>Class Summary</b>
93
    
94
    </font></td>
95
    </tr>
96
    
97
    <tr bgcolor="white" class="TableRowColor">
98
    <td width="15%"><b><a href="Config.html">Config</a></b></td>
99
    <td>&nbsp;</td>
100
    </tr>
101
    
102
    </table>
103
    <hr/> 
104

    
105

    
106
<!-- ========== METHOD SUMMARY =========== -->
107

    
108
<!-- ========== END METHOD SUMMARY =========== -->
109

    
110

    
111
        <pre class="sourceview"><span class="comment">/*
112
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
113
$Id: Config.js 3893 2008-02-29 18:22:13Z ahocevar $
114
*/</span>
115
<span class="comment">
116
// Ensure this object's dependancies are loaded.</span>
117
mapbuilder.loadScript(baseDir+<span class="literal">"/model/ModelBase.js"</span>);
118

    
119
<span class="comment">/**
120
 * The config object is the parent model of all mapbuilder objects.
121
 * The application creates a global object called 'config' which represents
122
 * the mapbuilder configuration xml file passed in as a parameter.
123
 * Config is a model like any other model.  
124
 * Any mapbuilder object can be de-referenced by using the 'config.objects' 
125
 * property as in config.objects.idValueFromConfig.
126
 * The schema for the config can be found at /mabuilder/lib/schemas/config.xsd
127
 *
128
 * <span class="attrib">@constructor</span>
129
 * <span class="attrib">@base</span> ModelBase
130
 * <span class="attrib">@author</span> adair
131
 * <span class="attrib">@requires</span> Sarissa
132
 * <span class="attrib">@param</span> url URL of the configuration file.
133
 */</span>
134
<span class="reserved">function</span> Config(url) {
135
<span class="comment">/**
136
 * open the application specific configuration document, passed in aas the url argument.
137
 */</span>
138
  <span class="reserved">this</span>.doc = Sarissa.getDomDocument();
139
  <span class="reserved">this</span>.doc.async = false;
140
  <span class="reserved">this</span>.doc.validateOnParse=false;  //IE6 SP2 parsing bug
141
  <span class="reserved">if</span>(_SARISSA_IS_SAFARI)
142
  {
143
  var xmlhttp = new XMLHttpRequest();
144
  xmlhttp.open(<span class="literal">"GET"</span>, url, false);
145
  xmlhttp.send(null);
146
  <span class="reserved">this</span>.doc = xmlhttp.responseXML;
147
  }<span class="reserved">else</span>
148
   {
149
  <span class="reserved">this</span>.doc.load(url);
150
  }
151
  <span class="reserved">if</span> (Sarissa.getParseErrorText(<span class="reserved">this</span>.doc) != Sarissa.PARSED_OK){
152
    alert(<span class="literal">"error loading config document: "</span> + url );//+ <span class="literal">" - "</span> + Sarissa.getParseErrorText(<span class="reserved">this</span>.doc) );
153
  }
154
  <span class="reserved">this</span>.url = url;
155
  <span class="reserved">this</span>.namespace = <span class="literal">"xmlns:mb='"</span>+mbNsUrl+<span class="literal">"'"</span>;
156
  <span class="reserved">if</span>(! _SARISSA_IS_SAFARI ){ 
157
  <span class="reserved">this</span>.doc.setProperty(<span class="literal">"SelectionLanguage"</span>, <span class="literal">"XPath"</span>);
158
  Sarissa.setXpathNamespaces(<span class="reserved">this</span>.doc, <span class="reserved">this</span>.namespace);}
159

    
160
<span class="comment">/**
161
 * Set the serializeUrl and proxyUrl values from a global configuration document
162
 * Optional, these can also be set in individual config docs.
163
 */</span>
164
  var configDoc = Sarissa.getDomDocument();
165
  configDoc.async = false;
166
  configDoc.validateOnParse=false;  //IE6 SP2 parsing bug
167
  <span class="reserved">if</span>(_SARISSA_IS_SAFARI){
168
    var xmlhttp = new XMLHttpRequest();
169
    xmlhttp.open(<span class="literal">"GET"</span>, baseDir+<span class="literal">"/"</span>+mbServerConfig, false);
170
    xmlhttp.send(null);
171
    configDoc = xmlhttp.responseXML;
172
  }<span class="reserved">else</span>
173
   {
174
    configDoc.load(baseDir+<span class="literal">"/"</span>+mbServerConfig);
175
   }
176
  <span class="reserved">if</span> (Sarissa.getParseErrorText(configDoc) != Sarissa.PARSED_OK) {
177
<span class="comment">    //alert("error loading server config document: " + baseDir+"/"+mbServerConfig );</span>
178
  } <span class="reserved">else</span> {
179
  <span class="reserved">if</span>(! _SARISSA_IS_SAFARI ){
180
    configDoc.setProperty(<span class="literal">"SelectionLanguage"</span>, <span class="literal">"XPath"</span>);
181
    Sarissa.setXpathNamespaces(configDoc, <span class="reserved">this</span>.namespace);
182
    }
183
    <span class="reserved">this</span>.proxyUrl = Mapbuilder.getProperty(configDoc, <span class="literal">"/mb:MapbuilderConfig/mb:proxyUrl"</span>, <span class="reserved">this</span>.proxyUrl);
184
    <span class="reserved">this</span>.serializeUrl = Mapbuilder.getProperty(configDoc, <span class="literal">"/mb:MapbuilderConfig/mb:serializeUrl"</span>, <span class="reserved">this</span>.serializeUrl);
185
  }
186
  configDoc = null;
187

    
188
  <span class="comment">/**
189
   * Dynamic loading of the javascript files for objects defined in the Config file.
190
   * <span class="attrib">@private</span>
191
   */</span>
192
  <span class="reserved">this</span>.loadConfigScripts=<span class="reserved">function</span>(){
193
<span class="comment">    // load css stylesheets that were requested before skindir was known.</span>
194
    <span class="reserved">if</span> (mapbuilder.cssToLoad) {
195
      <span class="reserved">for</span> (var i=0; i&lt;mapbuilder.cssToLoad.length; i++) {
196
        loadCss(mapbuilder.cssToLoad[i]);
197
      }
198
      mapbuilder.cssToLoad = null;
199
    }
200
<span class="comment">    
201
    // Load script files for all components that don't have &lt;scriptfile&gt; specified</span>
202
<span class="comment">    // in the config file.</span>
203
    mapbuilder.loadScriptsFromXpath(<span class="reserved">this</span>.doc.selectNodes(<span class="literal">"//mb:models/*"</span>),<span class="literal">"model/"</span>);
204
    mapbuilder.loadScriptsFromXpath(<span class="reserved">this</span>.doc.selectNodes(<span class="literal">"//mb:widgets/*"</span>),<span class="literal">"widget/"</span>);
205
    mapbuilder.loadScriptsFromXpath(<span class="reserved">this</span>.doc.selectNodes(<span class="literal">"//mb:tools/*"</span>),<span class="literal">"tool/"</span>);
206
<span class="comment">
207
    //TBD: Deprecate the following block and move into loadScriptsFromXpath instead.</span>
208
<span class="comment">    //load all scriptfiles called for in the config file.  There seems to be a </span>
209
<span class="comment">    //problem if this is done anywhere except in the page &lt;HEAD&gt; element.</span>
210
    var scriptFileNodes = <span class="reserved">this</span>.doc.selectNodes(<span class="literal">"//mb:scriptFile"</span>);
211
    <span class="reserved">for</span> (var i=0; i&lt;scriptFileNodes.length; i++ ) {
212
      scriptFile = getNodeValue(scriptFileNodes[i]);
213
      mapbuilder.loadScript(scriptFile);
214
    }
215
  }
216

    
217
  <span class="comment">/**
218
  * multilingual support; defaults to english 
219
  * Set via a "language" parameter in the URL, 
220
  * or by setting a global "language" Javascript variable in the page &lt;HEAD&gt;.
221
  * Retrieve the language value from the global conifg object as "config.lang"
222
  */</span>
223
  <span class="reserved">this</span>.defaultLang = <span class="literal">"en"</span>;
224
  <span class="reserved">this</span>.lang = <span class="reserved">this</span>.defaultLang;
225
  <span class="reserved">if</span> (window.cgiArgs[<span class="literal">"language"</span>]) {
226
    <span class="reserved">this</span>.lang = window.cgiArgs[<span class="literal">"language"</span>];
227
  } <span class="reserved">else</span> <span class="reserved">if</span> (window.language) {
228
    <span class="reserved">this</span>.lang = window.language;
229
  }
230
<span class="comment">
231
  //set some global application properties</span>
232
  var modelNode = <span class="reserved">this</span>.doc.documentElement;
233
  <span class="reserved">this</span>.skinDir = Mapbuilder.getProperty(modelNode, <span class="literal">"mb:skinDir"</span>);
234
  <span class="reserved">this</span>.proxyUrl = Mapbuilder.getProperty(modelNode, <span class="literal">"mb:proxyUrl"</span>, <span class="reserved">this</span>.proxyUrl);
235
  <span class="reserved">this</span>.serializeUrl = Mapbuilder.getProperty(modelNode, <span class="literal">"mb:serializeUrl"</span>, <span class="reserved">this</span>.serializeUrl);
236

    
237
  <span class="comment">/**
238
   * Convenience method to load widgetText from a dir.
239
   * Has the possible side-effect of changing config.lang to config.defaultLang
240
   * if the widgetText for the selected language is not found.
241
   * <span class="attrib">@param</span> config the config object
242
   * <span class="attrib">@param</span> dir    the base dir for the widget text
243
   * <span class="attrib">@private</span>
244
   */</span>
245
  <span class="reserved">function</span> loadWidgetText(config, dir) {
246
    var widgetFile = <span class="literal">"/widgetText.xml"</span>;
247
    var widgetText;
248
    var widgetTextUrl = dir + <span class="literal">"/"</span> + config.lang + widgetFile;
249
    widgetText = Sarissa.getDomDocument();
250
    widgetText.async = false;
251
    widgetText.validateOnParse=false;  //IE6 SP2 parsing bug
252
    
253
    <span class="reserved">if</span> (typeof(inlineXSL)!=<span class="literal">"undefined"</span>) {
254
      var xmlString = inlineXSL[widgetTextUrl];
255
      xmlString = xmlString.replace(/DOUBLE_QUOTE/g,<span class="literal">"\"</span><span class="literal">");
256
      widgetText = (new DOMParser()).parseFromString(xmlString, "</span>text/xml<span class="literal">");
257
    }
258
    else {
259
      if (_SARISSA_IS_SAFARI) {
260
        var xmlhttp = new XMLHttpRequest();
261
        xmlhttp.open("</span>GET<span class="literal">", widgetTextUrl, false);
262
        xmlhttp.send(null);
263
        widgetText = xmlhttp.responseXML;
264
      }
265
      else {
266
        try {
267
          widgetText.load(widgetTextUrl);
268
        }
269
        catch (ignoredErr) {}
270
      }
271
    }      
272
    if (Sarissa.getParseErrorText(widgetText) != Sarissa.PARSED_OK) {
273
      var errMsg = "</span>Error loading widgetText document: <span class="literal">" + widgetTextUrl;
274
      if (config.lang == config.defaultLang) {
275
        alert(errMsg);
276
      }
277
      else {
278
        // Try to fall back on default language
279
        alert(errMsg + "</span>\nFalling back on default language=\<span class="literal">""</span> + config.defaultLang + <span class="literal">"\"</span><span class="literal">");
280
        config.lang = config.defaultLang;
281
        widgetTextUrl = dir + "</span>/<span class="literal">" + config.lang + widgetFile;
282
        if(_SARISSA_IS_SAFARI) {
283
          var xmlhttp = new XMLHttpRequest();
284
          xmlhttp.open("</span>GET<span class="literal">", widgetTextUrl, false);
285
          xmlhttp.send(null);
286
          widgetText = xmlhttp.responseXML;
287
        }
288
        else {
289
          widgetText.load(widgetTextUrl);
290
        }
291
        if (Sarissa.getParseErrorText(widgetText) != Sarissa.PARSED_OK) {
292
          alert("</span>Falling back on default language failed!<span class="literal">");
293
        }
294
      }
295
    }
296
    if(! _SARISSA_IS_SAFARI) {
297
      widgetText.setProperty("</span>SelectionLanguage<span class="literal">", "</span>XPath<span class="literal">");
298
      Sarissa.setXpathNamespaces(widgetText, config.namespace);
299
    }
300
    return widgetText;
301
  }
302
  
303
  // Load widgetText
304
  this.widgetText = loadWidgetText(this, baseDir + "</span>/text<span class="literal">");
305
  // Try to load userWidgetText
306
  userWidgetTextDir = modelNode.selectSingleNode("</span>mb:userWidgetTextDir<span class="literal">");
307
  if (userWidgetTextDir) {
308
    var userWidgetText = loadWidgetText(this, getNodeValue(userWidgetTextDir));
309
    if (userWidgetText) {
310
      // User has specified userWidgetText, merge with widgetText
311
      var userWidgets = userWidgetText.selectSingleNode("</span>/mb:WidgetText/mb:widgets<span class="literal">");
312
      var configWidgets = this.widgetText.selectSingleNode("</span>/mb:WidgetText/mb:widgets<span class="literal">");
313
      if (userWidgets &amp;&amp; configWidgets) {
314
        // Merge &lt;widgets/&gt; texts
315
        Sarissa.copyChildNodes(userWidgets, configWidgets, true);
316
      }
317
      var userMessages = userWidgetText.selectSingleNode("</span>/mb:WidgetText/mb:messages<span class="literal">");
318
      var configMessages = this.widgetText.selectSingleNode("</span>/mb:WidgetText/mb:messages<span class="literal">");
319
      if (userMessages &amp;&amp; configMessages) {
320
        // Merge &lt;messages/&gt; texts
321
        Sarissa.copyChildNodes(userMessages, configMessages, true);
322
      }
323
    }
324
  }
325

    
326
  /**
327
  * the objects property holds a reference to every mapbuilder javascript object
328
  * created.  Each object is added as a property of config.objects using the
329
  * value of the object id from the configuration file
330
  */
331
  this.objects = new Object();
332

    
333
  // Inherit the ModelBase functions and parameters
334
  ModelBase.apply(this, new Array(modelNode));
335

    
336
  /**
337
   * Load a model and its child models, widgets and tools.
338
   * This function can be called at any time to load a new model or replace an
339
   * existing model object.
340
   * @param modelId   the id of the model in config XML to be updated
341
   * @param modelUrl  URL of the XML model document to be loaded
342
   */
343
  this.loadModel = function( modelId, modelUrl ) {
344
    var model = this.objects[modelId];
345
    if (model &amp;&amp; modelUrl) {
346
      var httpPayload = new Object();
347
      httpPayload.method = model.method;
348
      httpPayload.url = modelUrl;
349
      model.newRequest(model,httpPayload);
350
    } else {
351
      alert(mbGetMessage("</span>errorLoadingModel<span class="literal">", modelId, modelUrl));
352
    }
353
  }
354

    
355
  /**
356
   * Repaint the widget passed in.  
357
   * This function can be called at any time to paint the widget.
358
   * @param widget   a pointer to the widget object to be painted.
359
   */
360
  this.paintWidget = function( widget ) {
361
    if (widget) {
362
      widget.paint(widget, widget.id);
363
    } else {
364
      alert(mbGetMessage("</span>errorPaintingWidget"));
365
    }
366
  }
367
}
368

    
369
<span class="comment">/**
370
* Initialise the global config object for Mozilla browsers.
371
*/</span>
372
<span class="reserved">if</span> (document.readyState==null){
373
<span class="comment">  // Mozilla</span>
374
  mapbuilder.setLoadState(MB_LOAD_CONFIG);
375
  config=new Config(mbConfigUrl);
376
  config[config.id] = config;
377
  config.loadConfigScripts();
378
}
379
</pre>
380
	<hr>
381

    
382

    
383

    
384
<!-- ========== START OF NAVBAR ========== -->
385
<a name="navbar_top"><!-- --></a>
386
<table border="0" width="100%" cellpadding="1" cellspacing="0">
387
<tr>
388
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
389
<a name="navbar_top_firstrow"><!-- --></a>
390
<table border="0" cellpadding="0" cellspacing="3">
391
  <tr align="center" valign="top">
392
  
393
  
394
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
395
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
396
  
397

    
398
  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
399
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
400
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
401
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
402
  </tr>
403
</table>
404
</td>
405
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
406
<b><a href='http://mapbuilder.sourceforge.net'>Community Map Builder</a> 27 Apr 2008</b></em>
407
</td>
408
</tr>
409

    
410
<tr>
411
<td bgcolor="white" class="NavBarCell2"><font size="-2">
412
&nbsp;PREV&nbsp;
413
&nbsp;NEXT</font></td>
414
<td bgcolor="white" class="NavBarCell2"><font size="-2">
415
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
416
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
417
&nbsp;&nbsp;
418
<script>
419
  <!--
420
  if(window==top) {
421
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
422
  }
423
  //-->
424
</script>
425
<noscript>
426
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
427
</noscript>
428
</font></td>
429
</tr>
430
</table>
431
<!-- =========== END OF NAVBAR =========== -->
432

    
433
<hr>
434
<font size="-1">
435

    
436
</font>
437
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Sun Apr 27 20:30:54 2008</div>
438
</body>
439
</html>
(223-223/316)