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 jm...@apache.org on 2006/11/16 08:11:58 UTC

svn commit: r475622 - /incubator/xap/trunk/src/xap/util/TypeUtils.js

Author: jmargaris
Date: Thu Nov 16 00:11:57 2006
New Revision: 475622

URL: http://svn.apache.org/viewvc?view=rev&rev=475622
Log:
totally revamped

Modified:
    incubator/xap/trunk/src/xap/util/TypeUtils.js

Modified: incubator/xap/trunk/src/xap/util/TypeUtils.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/TypeUtils.js?view=diff&rev=475622&r1=475621&r2=475622
==============================================================================
--- incubator/xap/trunk/src/xap/util/TypeUtils.js (original)
+++ incubator/xap/trunk/src/xap/util/TypeUtils.js Thu Nov 16 00:11:57 2006
@@ -64,24 +64,48 @@
 **/
 
 Xap.provide("xap.util.TypeUtils") ;
-//Xap.require() ;
+Xap.require("google.*");
 
 xap.util.TypeUtils = function(){
 }
 
-Xap.setupClassAsSubclassOf("xap.util.TypeUtils","Object") ;
 
+xap.util.TypeUtils.convertToString  = function( obj ) {
+	
+	//if it is a collection unwrap it
+	obj = xap.util.TypeUtils._unwrapCollection(obj);
+	
+	//if it is now a dom type unwrap that
+	obj = xap.util.TypeUtils._unwrapDomType(obj);
+	return "" + obj;
+}
 
+xap.util.TypeUtils._unwrapDomType = function(obj){
+	if (obj instanceof google.XNode){
+		if (obj.nodeType==google.DOM_TEXT_NODE){
+			return obj.nodeValue;
+		}
+		else if (obj.nodeType==google.DOM_ATTRIBUTE_NODE){
+			return obj.nodeValue;
+		}
+		else if (obj.nodeType==google.DOM_ELEMENT_NODE){
+			if (obj.firstChild && obj.firstChild.nodeType==google.DOM_TEXT_NODE){
+				return obj.firstChild.nodeValue;
+			}
+		}
+	}
+	
+	//not an attribute, element or text node
+	return obj;	
+}
 
-//private static Object 
-xap.util.TypeUtils.convertKnownType ( obj ) {
-    if ( obj instanceof Attribute ) {
-        return ((Attribute) obj).getValue();
-    } else if ( obj instanceof Text ) {
-        return ((Text) obj).getText();
-    } else if ( obj instanceof Element ) {
-        return ((Element) obj).getFirstTextChild();
-    } else {
-        return obj;
-    }
+xap.util.TypeUtils._unwrapCollection = function(obj){
+	if (obj instanceof Array){
+		if (obj.length>0){
+			//TODO should we recurse on this for a nested array?
+			return obj[0];
+		}
+	}
+	return obj;
+	
 }