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 2007/03/01 19:11:20 UTC

svn commit: r513446 - /incubator/xap/trunk/codebase/src/xap/util/Utils.js

Author: mturyn
Date: Thu Mar  1 11:11:20 2007
New Revision: 513446

URL: http://svn.apache.org/viewvc?view=rev&rev=513446
Log:
1.) Removed code that had been transferred to xap.util.Debug.
2.) Improved interrogate():
	a.) Separated out the single-level object properties dump from the prompt displaying it,
           making it usable in other contexts.
    b.) Separated-out fields from functions, when reporting the latter is desired.
	c.) Alphabetised results (within field/function blocks).

Modified:
    incubator/xap/trunk/codebase/src/xap/util/Utils.js

Modified: incubator/xap/trunk/codebase/src/xap/util/Utils.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/util/Utils.js?view=diff&rev=513446&r1=513445&r2=513446
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/util/Utils.js (original)
+++ incubator/xap/trunk/codebase/src/xap/util/Utils.js Thu Mar  1 11:11:20 2007
@@ -27,37 +27,45 @@
 
 xap.util.Utils = function(){}
 
-xap.util.Utils.importFile = function( path ) {
-	if( xap.util.Utils.s_pathCache == null ) {
-		xap.util.Utils.s_pathCache = new Object();
-	}
-	if ( xap.util.Utils.s_pathCache[path] ){
-		return;
-	}
-	xap.util.Utils.s_pathCache[path] = true;
-	var scriptElement = "<script language=\"JavaScript\" " +
-		"type=\"text/javascript\" src=\"" + path + "\"></script>";
-	document.write( scriptElement );
-}
-
-xap.util.Utils.s_pathCache = null;
-
 /**
  * Method for debugging---less than a full object-dump, more than toString()
 **/
-xap.util.Utils.interrogate = function(obj,withFun){
+xap.util.Utils.oneLevelObjectDump = function(obj,withFun,maxLength){
 	var s="" ;
+	var fieldsArr = new Array(0);
+	var methsArr = new Array(0);	
 	if (typeof obj != "object"){
 		s = "<not an object>" ;
 	} else {
 		for (var keyy in obj){ 
-			var valStr = ""+obj[keyy] ; 
-			if (valStr.substring(0,8)=="function" && !withFun){
+			if (!withFun && typeof obj[keyy] == "function"){
 				continue ;
 			}
-			s += "^"+keyy+':'+valStr ;
+			var valStr = ""+obj[keyy] ;
+			if(maxLength && (valStr.length > maxLength)){
+				var newValStr = "";
+				var nTrimmed = valStr.length -  maxLength ;
+				newValStr += valStr.substring(0,Math.round((2*maxLength)/3)) ;
+				newValStr += "...<"+nTrimmed+" characters>..." ;
+				newValStr += valStr.substring(valStr.length - Math.round((1*maxLength)/3)) ;
+				valStr = newValStr ;
+			}
+			if (typeof obj[keyy] == "function"){
+				methsArr.push(""+keyy+':'+valStr) ;
+			} else {
+				fieldsArr.push(""+keyy+':'+valStr) ;
+			}
 		}
+		fieldsArr = fieldsArr.sort() ;
+		methsArr = methsArr.sort() ;
+		var membersArr = Array.concat(fieldsArr,methsArr) ;
+		s = membersArr.join("\n") ;
 	}
+	return s ;
+}
+
+xap.util.Utils.interrogate = function(obj,withFun,maxLength){
+	var s = xap.util.Utils.oneLevelObjectDump(obj,withFun,maxLength) ;
 	// Puts the result, with CR/LFs turned to carets, into
 	// the copyable part of a prompt box:
 	prompt("",s.replace(/[\r\n]/g,"^")) ;