incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtu...@apache.org
Subject svn commit: r468522 - in /incubator/xap/trunk: WebContent/examples/dataBinding/nestedIterators.xal src/xap/data/bridge/IteratorBridge.js src/xap/data/datasource/SimpleDocumentDataSource.js src/xap/util/TypeUtils.js src/xap/xml/dom/XapElement.js
Date Fri, 27 Oct 2006 20:24:46 GMT
Author: mturyn
Date: Fri Oct 27 13:24:45 2006
New Revision: 468522

URL: http://svn.apache.org/viewvc?view=rev&rev=468522
Log:
Still trying to improve handling of result nodes (e.g., if there's a text node child, use
its string).

Added:
    incubator/xap/trunk/src/xap/util/TypeUtils.js   (with props)
Modified:
    incubator/xap/trunk/WebContent/examples/dataBinding/nestedIterators.xal
    incubator/xap/trunk/src/xap/data/bridge/IteratorBridge.js
    incubator/xap/trunk/src/xap/data/datasource/SimpleDocumentDataSource.js
    incubator/xap/trunk/src/xap/xml/dom/XapElement.js

Modified: incubator/xap/trunk/WebContent/examples/dataBinding/nestedIterators.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/dataBinding/nestedIterators.xal?view=diff&rev=468522&r1=468521&r2=468522
==============================================================================
--- incubator/xap/trunk/WebContent/examples/dataBinding/nestedIterators.xal (original)
+++ incubator/xap/trunk/WebContent/examples/dataBinding/nestedIterators.xal Fri Oct 27 13:24:45
2006
@@ -11,67 +11,64 @@
 		source="customers.xml"
 	/>
 
+<binding 
+	dataSource="myDataSource" 
+	select="concat('# Customers: ',count(/customers/customer))" 
+	id="customerCount"
+/>
 
-	<xm:modifications>
-		<xm:append select="/xal">
-			<xal:table width="60%">
-		        <!--  column>
-		          <header text="Cust id"/>
-		        </column>
-		        
-		        <column>
-		          <header text="First"/>
-		        </column>
-		        
-		        <column>
-		          <header text="Last"/>
-		        </column>
-		        
-		        <column>
-		          <header text="Phone"/>
-		        </column>
-		
-		        <column>
-		          <header text="Title"/>
-		        </column>
-		        <column>
-		          <header text="Last"/>
-		        </column -->			
-			
-				<!-- Iterator -->
-				<data:iterator 
-					name="customer-iterator" 
-					dataSource="myDataSource" 
-					select="/customers/customer"
-				>
-					<row>			
-						<cell text="[outer iterator] customer id" fontWeight="8pt" color="#AAaaAA"/>
				
-						<cell text="{ *('@custid') }" />
-						<data:iterator select="*" name="middle-iterator">   
+<borderLayout/>
+      <table borderPosition="center">
+      
+        <column>
+          <header text="Cust id"/>
+        </column>
+        
+        <column>
+          <header text="First"/>
+        </column>
+        
+        <column>
+          <header text="Last"/>
+        </column>
+        
+        <column>
+          <header text="Phone"/>
+        </column>
+
+        <column>
+          <header text="Title"/>
+        </column>
+        <column>
+          <header text="Last"/>
+        </column>
+	
+	<data:iterator  name="customer-iterator" dataSource="myDataSource" select="/customers/customer">
+            <row>
+            	<cell text="[outer iterator]" fontSize="8pt"  alignHorizontal="right"/>
+         		<cell text="{ *('@custid') }"/>
+       			<data:iterator select="*">   
+               		<row>
+               			<cell/>
+                		<cell text="[middle]" fontSize="7pt"  alignHorizontal="right"/>
+						<cell text="{ *( 'text()' ) }"/>
+					
+						<data:iterator  dataSource="customer-iterator" select="/">
 							<row>
-								<cell text="[middle iterator] customer node as text" fontWeight="8pt" color="#AAaaAA"/>
-								<cell text=" . . . . . . " color="#FFFFFF"/>								
-								<cell backgroundColor="#FFddFF" text="{ *( 'text()' ) }"/>
-						
-								<data:iterator
-									dataSource="customer-iterator" 
-									select="*"
-									name="inmost-iterator"
-								>
-									<row>
-										<cell text=" . . . . . . " color="#FFFFFF"/>										
-										<cell text="[inmost iterator] customer as text" fontSize="8pt" color="#AAaaAA"/>
-										<cell text=" . . . . . . " color="#FFFFFF"/>
-										<cell backgroundColor="#ddFFFF" text="{ *( 'text()' ) }"/>
-									</row>
-								</data:iterator><!-- inmost iterator -->					
+								<cell/>
+								<cell/>
+								<cell text="[inmost]" fontSize="6pt" alignHorizontal="right"/>
+								<cell text="{ *( 'text()' ) }"/>
 							</row>
-						</data:iterator> <!-- Middle iterator. -->
+						</data:iterator>
+				
 					</row>
-				</data:iterator><!-- Customer iterator. -->
-			</xal:table>
-
-		</xm:append>
-	</xm:modifications>
+				</data:iterator> 
+            </row>
+      </data:iterator>
+      </table>
+      
+      <!--  label text="{ bind(binding://customerCount) }" borderPosition="south" height="30"
/ -->
+      
 </xal>
 <!-- -->

Modified: incubator/xap/trunk/src/xap/data/bridge/IteratorBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/bridge/IteratorBridge.js?view=diff&rev=468522&r1=468521&r2=468522
==============================================================================
--- incubator/xap/trunk/src/xap/data/bridge/IteratorBridge.js (original)
+++ incubator/xap/trunk/src/xap/data/bridge/IteratorBridge.js Fri Oct 27 13:24:45 2006
@@ -98,7 +98,7 @@
         dataSource = this.getDataSourceContainer().getDataSource(dataSourceId);
     }
 	//if there is a data source, use it
-	if (dataSource != null) {
+	if (dataSource) {
 		i = new xap.data.controller.Iterator(select, bindingType, element, name, this.getSession());
 		i.iterate(dataSource);
 	}
@@ -110,7 +110,7 @@
 											 element, 
 											 name,  
 											 this.getSession()
-											 ) ;    
+											 ) ; 
 
 		// The iterate call will handle parent not found
 		i.iterate() ;

Modified: incubator/xap/trunk/src/xap/data/datasource/SimpleDocumentDataSource.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/datasource/SimpleDocumentDataSource.js?view=diff&rev=468522&r1=468521&r2=468522
==============================================================================
--- incubator/xap/trunk/src/xap/data/datasource/SimpleDocumentDataSource.js (original)
+++ incubator/xap/trunk/src/xap/data/datasource/SimpleDocumentDataSource.js Fri Oct 27 13:24:45
2006
@@ -134,17 +134,21 @@
 		// their values:
 		theData = new Array(rawData.length) ;
 		for(var jj=0; jj <rawData.length; ++jj){
-			theData[jj] = rawData[jj].nodeValue ;
+			var firstTextNode 
+				= xap.xml.dom.XapElement.getFirstTextChild(rawData[jj]) ;
+			// If a text node, use its text value:
+			if (firstTextNode != null ){
+				theData[jj] = firstTextNode.nodeValue ;
+			} else {	
+				theData[jj] = rawData[jj].nodeValue ;
+			}
 		}
 		// Special, common, case---why do
 		// I suddenly wish this were C?
 		if( theData.length == 1 ){
 			theData = theData[0] ;
 		}
-		// If a text node, use its text value:
-		if (theData.nodeName && theData.nodeName=="#text"){
-			theData = theData.nodeValue ;
-		}
+
 	}
 	
 		

Added: incubator/xap/trunk/src/xap/util/TypeUtils.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/TypeUtils.js?view=auto&rev=468522
==============================================================================
--- incubator/xap/trunk/src/xap/util/TypeUtils.js (added)
+++ incubator/xap/trunk/src/xap/util/TypeUtils.js Fri Oct 27 13:24:45 2006
@@ -0,0 +1,87 @@
+
+/**
+ * @fileoverview Provides utilities for the conversion of 
+ * results from queries on data sources into the results we'd
+ * expect.
+**/ 
+
+/**
+ * TypeUtils provides methods for converting Objects of one type
+ * into another type.  For example, a Vector of String objects that represent 
+ * Integers can be converted into an Integer[] where each element is an 
+ * Integer using convert( myVector, Integer[].class ).
+ * 
+ * <p/>
+ * 
+ * When the Object to convert is a Vector returned as a result of an XPath 
+ * query, the individual objects in the Vector will first get converted into 
+ * String objects according to the following rules:
+ * 
+ * <ul>
+ * <li>Text -> Text.getText() </li>
+ * <li>Attribute -> Attribute.getValue() </li>
+ * <li>Element -> Element.getFirstTextChild() </li>
+ * </ul>
+ * 
+ * The resulted String then will be converted into the final desired 
+ * type.  The only exception is when the desired type is simply Object.class.
+ * In this case the transformation described above will not take place 
+ * and the original passed in Object will get returned unmodified.
+ * 
+ * <p/>
+ * 
+ * For example: <br/></br>
+ * (assume myDoc is a com.nexaweb.xml.Document object. We are using it 
+ * as the context for the XPath query below) <br/><br/>
+ * 
+ * <code>('result' will be an array)
+ * var result = XPath.evaluate("/customers/customer", myDoc); 
+ * str = TypeConversionService.convertToString( result ); 
+ * </code><br/>
+ * Assuming the 'resultVector' returned by the XPath query contains 
+ * com.nexaweb.xml.Element objects, after the conversion 'str' will be 
+ * the first text child of the first Element in 'result'.  
+ * However, calling <code>TypeConversionService.convert( v, Object.class )</code>

+ * will return the result unmodified.
+ * 
+ * <p/>
+ * 
+ * When converting from an Array type into a non-Array
+ * type (i.e. from an Array into a Date or from a String[] into an Integer) the
+ * first element of the Array will be extracted (if there are more
+ * than 1 element) and this element will undergo the conversion. <br/><br/>
+ * 
+ * <b>Special case:</b> <br/><br/>
+ * When converting from an Array result of an XPath query into a 
+ * non-Array type, the first element of the Array will first 
+ * get converted into a String accoring to rules described above.  Then the 
+ * resulted String will be converted into the final desired type.  If you copy 
+ * the XPath result into a new Array and pass in the copy, the Objects in the 
+ * Array will not get converted into Strings first.
+ * 
+ * @author ikaplansky
+ * @author mturyn 
+**/
+
+Xap.provide("xap.util.TypeUtils") ;
+//Xap.require() ;
+
+xap.util.TypeUtils = function(){
+}
+
+Xap.setupClassAsSubclassOf("xap.util.TypeUtils","Object") ;
+
+
+
+//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;
+    }
+}

Propchange: incubator/xap/trunk/src/xap/util/TypeUtils.js
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/xap/trunk/src/xap/xml/dom/XapElement.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/dom/XapElement.js?view=diff&rev=468522&r1=468521&r2=468522
==============================================================================
--- incubator/xap/trunk/src/xap/xml/dom/XapElement.js (original)
+++ incubator/xap/trunk/src/xap/xml/dom/XapElement.js Fri Oct 27 13:24:45 2006
@@ -1016,6 +1016,27 @@
 }
 
 
+/**
+ * This will return the first text node of this element.  If this element
+ * has multiple text nodes ONLY the first text node is returned.
+ * 
+ * @param node{XNode}
+ * @return {String} The first text node of the element.
+ */
+xap.xml.dom.XapElement.getFirstTextChild = function(node) {
+	var result=null ;
+	var children = node.childNodes ;
+	for(var i=0; i< children.length ; i++) {
+		if(children[i].nodeType == google.DOM_TEXT_NODE ) {
+			result =  children[i] ;
+			break ;
+		}
+	}
+	return result ;
+}
+
+
+
 //-----------------------------------------------------------------------
 // Array Helpers.
 //-----------------------------------------------------------------------



Mime
View raw message