You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2008/09/29 03:19:42 UTC

svn commit: r699949 - in /tuscany/branches/sca-equinox/modules/implementation-widget-runtime/src/test/resources/content: atomModel.js storeJS.html

Author: jsdelfino
Date: Sun Sep 28 18:19:42 2008
New Revision: 699949

URL: http://svn.apache.org/viewvc?rev=699949&view=rev
Log:
Pulled from trunk. Changes from SVN revision r699491.

Modified:
    tuscany/branches/sca-equinox/modules/implementation-widget-runtime/src/test/resources/content/atomModel.js
    tuscany/branches/sca-equinox/modules/implementation-widget-runtime/src/test/resources/content/storeJS.html

Modified: tuscany/branches/sca-equinox/modules/implementation-widget-runtime/src/test/resources/content/atomModel.js
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/implementation-widget-runtime/src/test/resources/content/atomModel.js?rev=699949&r1=699948&r2=699949&view=diff
==============================================================================
--- tuscany/branches/sca-equinox/modules/implementation-widget-runtime/src/test/resources/content/atomModel.js (original)
+++ tuscany/branches/sca-equinox/modules/implementation-widget-runtime/src/test/resources/content/atomModel.js Sun Sep 28 18:19:42 2008
@@ -119,10 +119,6 @@
    this.type = type;
    if (!type) this.type = "text"; // If undefined or null, use text
    
-   this.getValue = function() {
-      return this.value;
-   };
-
    this.setText = function(content) {
       this.content = content;
    };
@@ -131,6 +127,10 @@
       return this.content;
    };
 
+   this.getValue = function() {
+      return this.content;
+   };
+
    this.setType = function(type) {
       if ((type != "text") && (type != "html") && (type != "xhtml")) {
          error( "Text type must be one of text, html, or xhtml" );
@@ -662,12 +662,18 @@
          if (node.nodeType == 1 /*Node.ELEMENT_NODE*/) {
             var tagName = node.tagName;
             if (tagName == "title" ) {
-               var title = new Text( getTextContent( node ) );
-               title.setType( "text" );
+               var text = getTextContent( node );
+               var type = node.getAttribute( "type" );
+               if ( type == undefined )
+                  type = "text";
+               var title = new Text( text, type );
                this.setTitle( title );
             } else if ( tagName == "subtitle" ) {
-               var title = new Text( getTextContent( node ) );
-               title.setType( "text" );
+               var text = getTextContent( node );
+               var type = node.getAttribute( "type" );
+               if ( type == undefined )
+                  type = "text";
+               var title = new Text( text, type );
                this.setSubTitle( title );
             } else if ( tagName == "id" ) {
                var id = new Id( getTextContent( node ) );
@@ -677,17 +683,19 @@
                var date = new Date( dateText ); // 2008-09-21T23:06:43.921Z
                this.setUpdated( date );
             } else if ( tagName == "link" ) {
-               var href = node.attributes[ "href" ];
-               var link = new Link( href.value );
-               var rel = node.attributes[ "rel" ];
-               link.setRelation( rel.value );
+               // var href = node.attributes[ "href" ]; // Works on modern browsers.
+               var attrVal = node.getAttribute( "href" );
+               var link = new Link( attrVal );
+               attrVal = node.getAttribute( "rel" );
+               if ( attrVal )
+                  link.setRelation( attrVal );
                this.addLink( link );
             } else if ( tagName == "content" ) {
-               var content = new Text( getTextContent( node ) );
-               var attr = node.attributes[ "type" ];
-               if ( attr != null ) {
-                  content.setType( attr.value );
-               }
+               var text = getTextContent( node );
+               var type = node.getAttribute( "type" );
+               if (type == undefined)
+                  type = "text";
+               var content = new Text( text, type );
                this.setContent( content );
             } else {
                // To Do - implement rest of nodes
@@ -1047,11 +1055,6 @@
       }
    }
    this.readFromNode = function( feedNode ) {
-      var entries = this.getEntries();
-      var entryCount = 0;
-      if ( entries != null ) {
-         entryCount = entries.length;
-      }
       // Expect feed node
       var childNodes = feedNode.childNodes;
       for ( var i = 0; i < childNodes.length; i++ ) {
@@ -1059,12 +1062,18 @@
          if (node.nodeType == 1 /*Node.ELEMENT_NODE*/) {
             var tagName = node.tagName;
             if (tagName == "title" ) {
-               var title = new Text( getTextContent( node ) );
-               title.setType( "text" );
+               var text = getTextContent( node );
+               var type = node.getAttribute( "type" );
+               if ( type == undefined )
+                  type = "text";
+               var title = new Text( text, type );
                this.setTitle( title );
             } else if ( tagName == "subtitle" ) {
-               var title = new Text( getTextContent( node ) );
-               title.setType( "text" );
+               var text = getTextContent( node );
+               var type = node.getAttribute( "type" );
+               if ( type == undefined )
+                  type = "text";
+               var title = new Text( text, type );
                this.setSubTitle( title );
             } else if ( tagName == "entry" ) {
                var entry = new Entry();
@@ -1078,10 +1087,12 @@
                var date = new Date( dateText ); //2008-09-21T23:06:53.750Z
                this.setUpdated( date );
             } else if ( tagName == "link" ) {
-               var href = node.attributes[ "href" ];
-               var link = new Link( href.value );
-               var rel = node.attributes[ "rel" ];
-               link.setRelation( rel.value );
+               // var href = node.attributes[ "href" ]; // Works on modern browsers.
+               var attrVal = node.getAttribute( "href" );
+               var link = new Link( attrVal );
+               attrVal = node.getAttribute( "rel" );
+               if ( attrVal )
+                  link.setRelation( attrVal );
                this.addLink( link );
             } else {
                // To Do - implement rest of nodes
@@ -1113,7 +1124,21 @@
 }
 
 /* Returns inner text on both IE and modern browsers. */
-function getTextContent(obj) {
-   // innerText for IE, textContent for others, "" for others.
-   return (obj.innerText) ? obj.innerText : (obj.textContent) ? obj.textContent : "";
+function getTextContent(node) {
+   // innerText for IE, textContent for others, child text node, "" for others.
+   if ( node.innerText )
+      return node.innerText;
+   if ( node.textContent )
+      return node.textContent;
+   if ( node.hasChildNodes() ) {
+      var childNodes = node.childNodes
+      for ( var j = 0; j < childNodes.length; j++ ) {
+         var childNode = childNodes[ j ];
+         var childType = childNode.nodeType;
+         if (childNode.nodeType == 3 /*Node.TEXT_NODE*/) {
+            return childNode.nodeValue;
+         }
+      } 
+   }
+   return undefined;
 } 
\ No newline at end of file

Modified: tuscany/branches/sca-equinox/modules/implementation-widget-runtime/src/test/resources/content/storeJS.html
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/implementation-widget-runtime/src/test/resources/content/storeJS.html?rev=699949&r1=699948&r2=699949&view=diff
==============================================================================
--- tuscany/branches/sca-equinox/modules/implementation-widget-runtime/src/test/resources/content/storeJS.html (original)
+++ tuscany/branches/sca-equinox/modules/implementation-widget-runtime/src/test/resources/content/storeJS.html Sun Sep 28 18:19:42 2008
@@ -55,7 +55,7 @@
 	}
 	
 	function shoppingCart_getResponse(feedDoc) {
-	    // var xmlString = new XMLSerializer().serializeToString(feed);
+	    // var xmlString = new XMLSerializer().serializeToString(feedDoc);
 	    // alert("shoppingCart_getResponse feed xml=" + xmlString);
 		var feed = new Feed( feedDoc );
 		
@@ -65,7 +65,7 @@
 			var list = "";
 			for (var i=0; i<entries.length; i++) {
 				// var item = entries[i].getElementsByTagName("content")[0].firstChild.nodeValue;
-				var item = entries[i].getContent().getText();
+				var item = entries[ i ].getContent().getText();
 				list += item + ' <br>';
 			}
 			document.getElementById("shoppingCart").innerHTML = list;