You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by mt...@apache.org on 2006/07/24 18:46:35 UTC

svn commit: r425145 - in /incubator/xap/trunk: WebContent/examples/dojo/dojo1.html src/xap/Xap.js

Author: mturyn
Date: Mon Jul 24 11:46:35 2006
New Revision: 425145

URL: http://svn.apache.org/viewvc?rev=425145&view=rev
Log:
Added a crude but (so far) effective debugger-friendly loader, designed so that files to be loaded with <script/> tags _after_ they (and, significantly, files on which they depend via dojo.require()) have been Dojo-loaded.

This is redundant, but acceptable for debugging.

There are two mechanisms for adding a file to the list of ones accessible to the debugger (tested with Venkman, but should hold true otherwise).  Either a specific list of classes can be provided to Xap after Xap.js is read in, but before bootstrapping, via (e.g.):

<script ...>Xap.addDebuggables("xap.bridges.dojo.DojoButtonBridge","xap.taghandling.AbstractTagImpl");</script>

and then a second parameter is given to Xap.bootstrap()---anything but the string "debugAll".  These files, and only these files, will then be loaded with script tags.

Otherwise, you can invoke Xap.bootstrap(<path>, "debugAll"), in which case every file loaded with Xap.require() during bootstrapping will be reloaded via <script/>s.

Modified:
    incubator/xap/trunk/WebContent/examples/dojo/dojo1.html
    incubator/xap/trunk/src/xap/Xap.js

Modified: incubator/xap/trunk/WebContent/examples/dojo/dojo1.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/dojo/dojo1.html?rev=425145&r1=425144&r2=425145&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/dojo/dojo1.html (original)
+++ incubator/xap/trunk/WebContent/examples/dojo/dojo1.html Mon Jul 24 11:46:35 2006
@@ -20,10 +20,22 @@
     <script language="JavaScript" type="text/javascript" src="../../src/xap/util/Utils.js"></script>
     <script language="JavaScript" type="text/javascript" src="../../src/xap/Xap.js"></script>
     
+
+    <script language="JavaScript" type="text/javascript">    	
+		Xap.addDebuggables( 
+						"xap.bridges.dojo.DojoButtonBridge",
+						"xap.taghandling.AbstractTagImpl",
+						"xap.bridges.dojo.DojoWidgetBridge"
+							) ;
+    </script>
    
     <script language="JavaScript" type="text/javascript">
-    	Xap.bootstrap( "../../", true);
+    	Xap.bootstrap( "../../", "debugAll");
   	</script>
+
+    	
+
+    	
   	
   	  <!-- SECTION 2 -->
 	<script type="text/javascript">
@@ -46,7 +58,7 @@
 	<h1>Xaplet embedded in a table cell:</h1>
 	
 	<table id="bigtable" border="4px" borderColor="#8866AA" width="80%" height="80%"
-		style="left:10%;top:10%;opacity:80%"
+		style="left:10%;top:10%"
 		cellpadding="20em" cellspacing="2px"
 		>
 		<tr><th width="30%">0.</th><th>1.</th></tr>

Modified: incubator/xap/trunk/src/xap/Xap.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/Xap.js?rev=425145&r1=425144&r2=425145&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/Xap.js (original)
+++ incubator/xap/trunk/src/xap/Xap.js Mon Jul 24 11:46:35 2006
@@ -33,20 +33,60 @@
 
 
 Xap.require = function(){
-	djConfig.debugAtAllCosts = Xap._debugLoad ;
-	djConfig.isDebug =  Xap._debugLoad ;
 	
 	try {		
 		dojo.require.apply(dojo,arguments) ;
+		if (Xap._debugAll && arguments[0].search(/\*/)==-1){
+			Xap.addDebuggables(arguments[0]) ;				
+		}
 	} catch (ee) {
 		Xap._logString += '\n'+ee ;
 	}
-	
-	if(  Xap._debugLoad ){
-	    dojo.hostenv.writeIncludes();
+
+}
+
+Xap.addDebuggables = function(){
+	if( !Xap._debuggables ){
+		Xap._debuggables = new Array(0) ;
+	}
+	for (var ii=0; ii<arguments.length; ++ii ){
+		Xap._debuggables.push(arguments[ii]) ;
 	}
 }
 
+
+Xap._loadDebuggable = function(str){
+	var path = str.replace(/\./g,"/") ;
+	// This actually creates a path like "../..//src",
+	// which is unpleasant but consistent with the
+	// rest of the usage in bootstrapZimbra() (meaning
+	// we won't repeat-load the file, since it will be
+	// found in Utils.s_pathCache, instead of looking like
+	// a new path) and doesn't hurt.
+	path = Xap._sourceRootDir +"/src/"+path +".js" ;
+	//alert(path) ;
+	xap.util.Utils.importFile(path) ;
+}
+
+Xap._loadDebuggables = function(pathArr){
+	if( !pathArr ){
+	// Default behavior:
+		Xap._loadDebuggables(Xap._debuggables) ;
+		return ;
+	} else { 
+		for (var ii=0; ii<pathArr.length; ++ii){
+			Xap._loadDebuggable( pathArr[ii] ) ;
+		}
+	}
+}
+
+Xap.debugLoad = function(){
+	Xap._addDebuggables(arguments) ;
+	Xap._loadDebuggables() ;
+}
+
+
+
 /**
 
 /**
@@ -105,12 +145,20 @@
 Xap.bootstrap = function( sourceRootDir,loadType ) {
 	// Will need this later to hold dojo configuration information:
 	if (!djConfig){
-		djConfig={} ;
+		if (!config){
+			djConfig={} ;
+		} else {
+			djConfig = config ;
+		}
 	}
 
 
 	// debugger-friendlier loader?:
 	Xap._debugLoad = (loadType)?true:false ;
+	Xap._debugAll = (loadType && loadType == "debugAll") ;
+	if( !Xap._debuggables ){
+		Xap._debuggables = new Array(0) ;
+	}
 
 	Xap._logString = "" ;
 	Xap._showLog = function(){
@@ -120,6 +168,13 @@
 	Xap._sourceRootDir = sourceRootDir;
 	Xap.loadXap( sourceRootDir );
 	Xap.loadZimbra( sourceRootDir );
+	
+// We've done all the "real" loading, now let's attach code to source files 
+// previously targetted for debugger-friendly (specified before we bootstrap):
+	if( Xap._debugLoad ){
+		//xap.util.Utils.interrogate(Xap._debuggables) ;
+		Xap._loadDebuggables() ;
+	}
 }
 
 Xap.createSession = function( context, startPage,toolkitType , element) {
@@ -214,7 +269,7 @@
 	//xap.requestservice
 	Xap.require("xap.requestservice.RequestService" ) ;
 	Xap.require("xap.requestservice.NetServiceListener" ) ;
-	
+
 }
 
 



Debugging

Posted by Michael Turyn <MT...@nexaweb.com>.
 I've put in a method that lets the Venkman debugger for Mozilla see
files we're loading.

BACKGROUND:  Venkman "normally" knows where to look for code by hooking
into the Mozilla loading process when a <script/> tag is encountered,
e.g.:
	    <script language="JavaScript" type="text/javascript"
src="../../src/xap/Xap.js"></script>
....  Dojo, by contrast, grabs the entire source-file as a string via an
XMLHttpRequest, then eval()'s it---the debugger then doesn't understand
where the source comes from.  (Conceivably, one could arrange for
Venkman to be given this information directly, but it's not something
for which I've time...)


You're supposed to be able to allow debugging by changing a few Dojo
parameters, at which point dojo.require() will examine the file for
required additional files, and add it and them to a load list---it will
then later, when the user calls "dojo.writeIncludes()", write out (you
guessed it) a bunch of <script/> tags.  Nice, clean...doesn't seem to
work well within my time constraints.  Files remain unloaded, Dojo seems
to have a hard time finding its alternate require() code and the
writeInclude()...and it's hard to debug this.

Instead, now, before Xap.bootstrap() is called, you can specify a list
of files to be reloaded with <script/> tags for the debugger's sake
(using xap.util.Utils.importFile()).  Then, when you bootstrap, a second
parameter should be added, and the files will be reloaded.

A special case:  if that second parameter is "debugAll", then _any_ call
to Xap.require() will also reload with <script/>s, with the effect that
any of the classes we use will be brought in---this will probably slow
things down a lot, but might be necessary when looking for the source of
a problem.

(We don't do Dojo XOR <script/> loading because we use Dojo's [useful!]
dependency mechanism, so require()ing a single file can also trigger the
loading of a whole bunch of them; therefore we need to keep the
Dojo-based loading regardless.)

I hope this will make life easier for people working on this project, or
who might want to understand the code by stepping through it in a
debugger (that's how I seem to understand it best).