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 2007/02/23 05:10:47 UTC

svn commit: r510832 [2/2] - in /incubator/xap/trunk: codebase/src/xap/xml/xmodify/ unittests/testsrc/xap/xmodify/

Modified: incubator/xap/trunk/codebase/src/xap/xml/xmodify/XmodifyNamespaceHandler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/xml/xmodify/XmodifyNamespaceHandler.js?view=diff&rev=510832&r1=510831&r2=510832
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/xml/xmodify/XmodifyNamespaceHandler.js (original)
+++ incubator/xap/trunk/codebase/src/xap/xml/xmodify/XmodifyNamespaceHandler.js Thu Feb 22 21:10:45 2007
@@ -33,7 +33,7 @@
  */
 xap.xml.xmodify.XmodifyNamespaceHandler = function(){
  	
-}
+};
 
 xap.xml.xmodify.XmodifyNamespaceHandler.MODIFICATIONS_TAG = "modifications";
 
@@ -47,7 +47,7 @@
 xap.xml.xmodify.XmodifyNamespaceHandler.prototype.pluginLoaded = function( session ){
 	session.getNamespaceHandlerManager().addHandler("http://openxal.org/core/xmodify", this);
 	this._session = session;
-}
+};
 
 /**
  * This method is called when an element with the XModify namespace is 
@@ -61,6 +61,6 @@
 xap.xml.xmodify.XmodifyNamespaceHandler.prototype.receiveDispatch = function( element ) {
     var xmodify = new xap.xml.xmodify.Xmodify(element, this._session);
     xmodify.execute();
-}
+};
 
 

Modified: incubator/xap/trunk/unittests/testsrc/xap/xmodify/_TestxModifyHTML.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/unittests/testsrc/xap/xmodify/_TestxModifyHTML.html?view=diff&rev=510832&r1=510831&r2=510832
==============================================================================
--- incubator/xap/trunk/unittests/testsrc/xap/xmodify/_TestxModifyHTML.html (original)
+++ incubator/xap/trunk/unittests/testsrc/xap/xmodify/_TestxModifyHTML.html Thu Feb 22 21:10:45 2007
@@ -48,12 +48,17 @@
 Xap.require("xap.session.ClientSession");
 Xap.require("xap.xml.ParserFactory");
 Xap.require("xap.requestservice.RequestService");
-var setupOnce = true;
-function setUp() {
-    xap.xml.xmodify.Xmodify.DEBUG=true;
-    
-    if (setupOnce == false) return;
-    
+
+function setUpPage() {
+
+	// debug window
+	document.w = window.open('','debug');
+   	xap.xml.xmodify.CommandDirective.s_log.setLevel(xap.log.Logger.DEBUG);
+	xap.xml.xmodify.CommandDirective.s_log.addAppender({ doAppend: function(logEvent) {
+		document.w.document.write(logEvent.getRenderedMessage());
+		document.w.document.write('<br />');
+	}});
+
 	try {
    		var app = new xap.application.Application() ;
    		var session = new xap.session.ClientSession(app) ;
@@ -62,68 +67,105 @@
     	// index.xal contains xap.xml.xmodify.Xmodify instructions that need to get executed
     	var content = requestService.retrieve( "/jsunit/testsrc/xap/xmodify/xmodifyHTML.xal" ); 
  		var parser = xap.xml.ParserFactory.getParser();
-		var commandsDoc = parser.parse( content.responseText );
+		var commands = parser.parse( content.responseText );
 		
  		/////////////////////////////////////////////////
  		// Here is what I need from xap.xml.xmodify.Xmodify:
  		/////////////////////////////////////////////////
- 		var xmodify = new xap.xml.xmodify.Xmodify( commandsDoc.firstChild.firstChild, session);
-		xmodify.execute( document ); 		
+ 		var xmodify = new xap.xml.xmodify.Xmodify( commands.firstChild.firstChild, session );
+		xmodify.execute(); 		
 	} catch (ee) {
 		// Need a catch here, even though we mean to do 
 		// nothing interesting:
 			throw ee ;
 	} finally {
 		// The reason for the try{} above
-		xap.xml.xmodify.Xmodify.DEBUG=false; 		    
-		setupOnce = false;
+		setUpPageStatus = 'complete';
 	}
 }
 
+
+//================================================================================
+
+
+function testAppendElement(){
+	var element = document.getElementById("myTable");
+	var childElements = element.getElementsByTagName("TR");
+	assertEquals("Check append element worked correctly", 7, childElements.length);						
+}
+
+
 function testSetAttribute(){
-	var rootElement = document.getElementById("username");
-	assertTrue( "Check set attribute worked correctly Element", 
-					rootElement.getAttribute("value") == "Yeppie!" );						
+	var element = document.getElementById("username");
+	assertEquals( "Check set attribute worked correctly", 
+		"Yeppie!", element.getAttribute("value"));						
 }
 
 function testRemoveAttribute(){
-	var rootElement = document.getElementById("username");
-	assertTrue( "Check set attribute worked correctly Element, attribute = " + rootElement.getAttribute("test"), 
-					rootElement.getAttribute("test") == null ||
-					rootElement.getAttribute("test") == "");						
+	var element = document.getElementById("username");
+	assertTrue("Check remove attribute worked correctly", 
+		element.getAttribute("test") === null || element.getAttribute("test") === "");						
 }
 
 function testRemoveElement(){
-	var rootElement = document.getElementById("password");
-	assertTrue( "Check set remove element worked correctly Element", 
-					rootElement == null);						
+	var element = document.getElementById("password");
+	assertNull("Check remove element worked correctly", element);						
 }
 
+
 function testReplaceElement(){
-	var rootElement = document.getElementById("mouseOverArea");
-	assertTrue( "Check set remove element worked correctly Element, nodeValue = " + rootElement.childNodes[0].nodeValue, 
-					rootElement.childNodes[0].nodeValue == "This button will disable all the fields.");						
+	var element = document.getElementById("mouseOverArea");
+	assertEquals("Check replace element worked correctly", 
+					"This button will disable all the fields.", element.childNodes[0].nodeValue);						
 }
 
 function testInsertBeforeElement(){
-	var rootElement = document.getElementById("insertBeforeRow");
-	assertTrue( "Check insert before element worked correctly Element, nodeValue = " + rootElement.innerHTML, 
-					rootElement.nextSibling.getAttribute("id")  == "insertRow");						
+	var element = document.getElementById("insertBeforeRow");
+	assertEquals("Check insert before element worked correctly", 
+					"insertRow", element.nextSibling.getAttribute("id"));						
 }
 
 function testInsertAfterElement(){
-	var rootElement = document.getElementById("insertAfterRow");
-	assertTrue( "Check insert after element worked correctly Element, nodeValue = " + rootElement.innerHTML, 
-					rootElement.previousSibling.getAttribute("id")  == "insertRow");						
+	var element = document.getElementById("insertAfterRow");
+	assertEquals("Check insert after element worked correctly", 
+					"insertRow", element.previousSibling.getAttribute("id"));						
 }
 
-function testAppendElement(){
-	var rootElement = document.getElementById("myTable");
-	var childElements = rootElement.getElementsByTagName("TR");
-	assertTrue( "Check append element worked correctly Element, nodeValue = " + childElements.length, 
-					childElements.length == 8);						
+function testInsertAtElement(){
+	var element = document.getElementById("insertAt");
+	assertEquals("Check insert at element worked correctly", 
+					'<br>insert text<br>', element.innerHTML);						
 }
 
+function testReplaceChildren(){
+	var element = document.getElementById("replaceChildren");
+	assertEquals("Check replace children worked correctly", 
+					2, element.childNodes.length);						
+}
+
+
+function testAppendWithVariable(){
+	var element = document.getElementById("appendWithVariableTarget");
+	assertEquals("Check variable worked correctly", 
+					'<br>alias<br>me', element.innerHTML);						
+}
+
+
+
+function testAppendWithClone(){
+	var element = document.getElementById("appendWithCloneTarget");
+	assertEquals("Check clone worked correctly", 
+					'clone<br>me', element.innerHTML);						
+}
+
+function testSetInnerHtml(){
+	var element = document.getElementById("setInnerHtml");
+	assertEquals("Check set-innerhtml worked correctly", 
+					'text here', element.innerHTML);						
+}
+
+
+
 </script>
     <table height="100%" style="width:100%">
         <tr><td valign="top" width="50%">
@@ -189,63 +231,65 @@
         		    		        <hr/>
         		    		</td></tr>
         		    	    <tr>
-        		    	        <td valign="top"><table width="100%" height="100%" id="myTable">
-        		    	            <tr>
-        		    	                <th style="border-bottom: 1px solid #000000">Customer ID</th>
-        		    	                <th style="border-bottom: 1px solid #000000">Name</th>
-        		    	                <th style="border-bottom: 1px solid #000000">Email</th>
-        		    	                <th style="border-bottom: 1px solid #000000">Address</th>
-        		    	                <th style="border-bottom: 1px solid #000000">Phone Number</th>
-        		    	                <th style="border-bottom: 1px solid #000000">Pending Orders</th>
-        		    	            </tr>
-        		    	            <tr type="insertRow" id="insertRow">
-        		    	                <td colspan="2"">This row will is the index for insert before and after macros.</td>
-        		    	            </tr>
-        		    	            <tr type="data">
-        		    	                <td>1</td>
-        		    	                <td>Robert</td>
-        		    	                <td>bbuffone@acme.com</td>
-        		    	                <td>555 Boston Road Boston, MA</td>
-        		    	                <td>555-555-5555</td>
-        		    	                <td>20</td>
-        		    	            </tr>
-        		    	            <tr type="data">
-        		    	                <td>1</td>
-        		    	                <td>Robert</td>
-        		    	                <td>bbuffone@acme.com</td>
-        		    	                <td>555 Boston Road Boston, MA</td>
-        		    	                <td>555-555-5555</td>
-        		    	                <td>20</td>
-        		    	            </tr>
-        		    	            <tr type="data">
-        		    	                <td>1</td>
-        		    	                <td>Robert</td>
-        		    	                <td>bbuffone@acme.com</td>
-        		    	                <td>555 Boston Road Boston, MA</td>
-        		    	                <td>555-555-5555</td>
-        		    	                <td>20</td>
-        		    	            </tr>
-        		    	            <tr type="data">
-        		    	                <td>1</td>
-        		    	                <td>Robert</td>
-        		    	                <td>bbuffone@acme.com</td>
-        		    	                <td>555 Boston Road Boston, MA</td>
-        		    	                <td>555-555-5555</td>
-        		    	                <td>20</td>
-        		    	            </tr>
-        		    	            <tr type="data">
-        		    	                <td>1</td>
-        		    	                <td>Robert</td>
-        		    	                <td>bbuffone@acme.com</td>
-        		    	                <td>555 Boston Road Boston, MA</td>
-        		    	                <td>555-555-5555</td>
-        		    	                <td>20</td>
-        		    	            </tr>
-        		    	            <tr height="95%">
-        		    	               <td colspan="6" style="border-top:1px solid #000000">                   		    	         
-        		    	               </td>
-        		    	            </tr>
-        		    	        </table></td>
+        		    	        <td valign="top">
+        		    	        	<table width="100%" height="100%" id="myTable">
+	        		    	            <tr>
+	        		    	                <th style="border-bottom: 1px solid #000000">Customer ID</th>
+	        		    	                <th style="border-bottom: 1px solid #000000">Name</th>
+	        		    	                <th style="border-bottom: 1px solid #000000">Email</th>
+	        		    	                <th style="border-bottom: 1px solid #000000">Address</th>
+	        		    	                <th style="border-bottom: 1px solid #000000">Phone Number</th>
+	        		    	                <th style="border-bottom: 1px solid #000000">Pending Orders</th>
+	        		    	            </tr>
+	        		    	            <tr type="insertRow" id="insertRow">
+	        		    	                <td colspan="2"">This row will is the index for insert before and after macros.</td>
+	        		    	            </tr>
+	        		    	            <tr type="data">
+	        		    	                <td>1</td>
+	        		    	                <td>Robert</td>
+	        		    	                <td>bbuffone@acme.com</td>
+	        		    	                <td>555 Boston Road Boston, MA</td>
+	        		    	                <td>555-555-5555</td>
+	        		    	                <td>20</td>
+	        		    	            </tr>
+	        		    	            <tr type="data">
+	        		    	                <td>1</td>
+	        		    	                <td>Robert</td>
+	        		    	                <td>bbuffone@acme.com</td>
+	        		    	                <td>555 Boston Road Boston, MA</td>
+	        		    	                <td>555-555-5555</td>
+	        		    	                <td>20</td>
+	        		    	            </tr>
+	        		    	            <tr type="data">
+	        		    	                <td>1</td>
+	        		    	                <td>Robert</td>
+	        		    	                <td>bbuffone@acme.com</td>
+	        		    	                <td>555 Boston Road Boston, MA</td>
+	        		    	                <td>555-555-5555</td>
+	        		    	                <td>20</td>
+	        		    	            </tr>
+	        		    	            <tr type="data">
+	        		    	                <td>1</td>
+	        		    	                <td>Robert</td>
+	        		    	                <td>bbuffone@acme.com</td>
+	        		    	                <td>555 Boston Road Boston, MA</td>
+	        		    	                <td>555-555-5555</td>
+	        		    	                <td>20</td>
+	        		    	            </tr>
+	        		    	            <tr type="data">
+	        		    	                <td>1</td>
+	        		    	                <td>Robert</td>
+	        		    	                <td>bbuffone@acme.com</td>
+	        		    	                <td>555 Boston Road Boston, MA</td>
+	        		    	                <td>555-555-5555</td>
+	        		    	                <td>20</td>
+	        		    	            </tr>
+	        		    	            <tr height="95%">
+	        		    	               <td colspan="6" style="border-top:1px solid #000000">                   		    	         
+	        		    	               </td>
+	        		    	            </tr>
+	        		    	        </table>
+        		    	        </td>
         		    	        <td width="30%" valign="top" align="right">
         		    	           <input type="submit" value="Clear Table" onclick="handleMacro('clearTable')">
         		    	           <input type="submit" value="Fill Table" onclick="handleMacro('fillTable')">
@@ -255,6 +299,22 @@
         		    	    </tr>
         		    	</table>  
    		    </td></tr>
-  		 </table>        		
+  		 </table>
+  		 
+  		 <div id="replaceChildren"> one <br /> two </div>
+  		 
+  		 <div id="appendWithVariableSource"><br />me</div>
+  		 <div id="appendWithVariableTarget"><br />alias</div>
+  		 
+  		 <div id="appendWithCloneSource">clone<br />me</div>
+  		 <div id="appendWithCloneTarget"></div>
+  		 
+  		 <div id="setInnerHtml"></div>
+  		 
+  		 
+  		 <div id="insertAt"><br /><br /></div>
+  		 
+  		 
+  		 	
 </body>
 </html>

Modified: incubator/xap/trunk/unittests/testsrc/xap/xmodify/xmodify.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/unittests/testsrc/xap/xmodify/xmodify.xal?view=diff&rev=510832&r1=510831&r2=510832
==============================================================================
--- incubator/xap/trunk/unittests/testsrc/xap/xmodify/xmodify.xal (original)
+++ incubator/xap/trunk/unittests/testsrc/xap/xmodify/xmodify.xal Thu Feb 22 21:10:45 2007
@@ -60,7 +60,7 @@
 			<attribute name="lastName" value="Dobbs"/>
 		</xm:set-attribute>
 		<!--
-        Test removing children.
+        Test removing children (replace with nothing).
         -->
 		<xm:append select="/xal/button[@id='button2']">
 			<button bgColor="#FF0000" height="100px" text="new child" width="100px" x="100px"
@@ -70,7 +70,7 @@
 			<button bgColor="#FF0000" height="100px" text="new child" width="100px" x="100px"
 				y="100px"/>
 		</xm:append>
-		<xm:remove-children select="/xal/button[@id='button2']"/>
+		<xm:replace-children select="/xal/button[@id='button2']"/>
 		
 		<!-- test replace children -->
 		<xm:append select="/xal">

Modified: incubator/xap/trunk/unittests/testsrc/xap/xmodify/xmodifyHTML.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/unittests/testsrc/xap/xmodify/xmodifyHTML.xal?view=diff&rev=510832&r1=510831&r2=510832
==============================================================================
--- incubator/xap/trunk/unittests/testsrc/xap/xmodify/xmodifyHTML.xal (original)
+++ incubator/xap/trunk/unittests/testsrc/xap/xmodify/xmodifyHTML.xal Thu Feb 22 21:10:45 2007
@@ -39,7 +39,7 @@
              Enable all text input fields in the application
          -->
          <xm:remove-attribute select="//INPUT[@type='text']">
-             <attribute name="test"/>
+             <xm:attribute name="test"/>
          </xm:remove-attribute>             
        
          <!--
@@ -48,58 +48,89 @@
          <xm:remove-element select="//INPUT[@type='password']"/>
          
          <!--
-             Macro will change the text of all input fields in the browser to Yeppie!
+             Macro will update target table with the new content
          -->
          <xm:remove-element select="//TR[@type='data']"/>
-        
-             <xm:append select="//TABLE[@id='myTable']/TBODY">
-                     <tr type="data">
-                         <td>10</td>
-                         <td>Robert</td>
-                         <td>bbuffone@acme.com</td>
-                         <td>555 Boston Road Boston, MA</td>
-                         <td>555-555-5555</td>
-                         <td>20</td>
-                     </tr>
-                     <tr type="data">
-                         <td>19</td>
-                         <td>Robert</td>
-                         <td>bbuffone@acme.com</td>
-                         <td>555 Boston Road Boston, MA</td>
-                         <td>555-555-5555</td>
-                         <td>20</td>
-                     </tr>
-                     <tr type="data">
-                         <td>18</td>
-                         <td>Robert</td>
-                         <td>bbuffone@acme.com</td>
-                         <td>555 Boston Road Boston, MA</td>
-                         <td>555-555-5555</td>
-                         <td>20</td>
-                     </tr>
-                 </xm:append>
-        
-                 <xm:insert-before select="//TR[@type='insertRow']">
-                     <tr type="data" id="insertBeforeRow">
-                         <td colspan="6">This row was inserted using the insert before modification statement</td>
-                     </tr>
-                 </xm:insert-before>
          
-                 <xm:insert-after select="//TR[@type='insertRow']">
-                     <tr type="data" id="insertAfterRow">
-                         <td colspan="6">This row was inserted using the insert after modification statement </td>
-                     </tr>
-                 </xm:insert-after>
-        
+         <xm:append select="//TABLE[@id='myTable']/TBODY">
+                 <tr>
+                     <td>10</td>
+                     <td>Robert</td>
+                     <td>bbuffone@acme.com</td>
+                     <td>555 Boston Road Boston, MA</td>
+                     <td>555-555-5555</td>
+                     <td>20</td>
+                 </tr>
+                 <tr>
+                     <td>19</td>
+                     <td>Robert</td>
+                     <td>bbuffone@acme.com</td>
+                     <td>555 Boston Road Boston, MA</td>
+                     <td>555-555-5555</td>
+                     <td>20</td>
+                 </tr>
+         </xm:append>
+    
+         <xm:insert-before select="//TR[@type='insertRow']">
+             <tr id="insertBeforeRow">
+                 <td colspan="6">This row was inserted using the insert before modification statement</td>
+             </tr>
+         </xm:insert-before>
+ 
+         <xm:insert-after select="//TR[@type='insertRow']">
+             <tr id="insertAfterRow">
+                 <td colspan="6">This row was inserted using the insert after modification statement </td>
+             </tr>
+         </xm:insert-after>
+    
+         <xm:insert-at select="id('insertAt')" index="1">
+         	<![CDATA[insert text]]>
+         </xm:insert-at>
+    
          <!--
              Macros handles the mouse overs for all controls. 
          --> 
-                <xm:replace select="id('mouseOverArea')">
-                     <div style="100%;width:100%background-color:#ff0000" id="mouseOverArea">
-                         <![CDATA[This button will disable all the fields.]]>
-                     </div>
-                 </xm:replace>
+        <xm:replace select="id('mouseOverArea')">
+             <div style="100%;width:100%background-color:#ff0000" id="mouseOverArea">
+                 <![CDATA[This button will disable all the fields.]]>
+             </div>
+         </xm:replace>
+
+         <!--
+             Replace children 
+         --> 
+        <xm:replace-children select="id('replaceChildren')">
+             <div>
+                 abc
+             </div>
+             <div>
+                 def
+             </div>
+         </xm:replace-children>
+
         
+        <!--
+        	Using of variable/value-of combo
+        -->
+    	<xm:variable name="myVar" select="id('appendWithVariableSource')/node()" clone="true" />
+    	<xm:append select="id('appendWithVariableTarget')">
+    		<xm:value-of name="myVar" />
+    	</xm:append>
+
+
+        <!--
+        	Copy one element into another.
+        -->
+    	<xm:append select="id('appendWithCloneTarget')">
+    		<xm:clone select="id('appendWithCloneSource')/node()" />
+    	</xm:append>
+
+        <!--
+        	Set inner html for target nodes.
+        -->
+    	<xm:set-innerhtml select="id('setInnerHtml')"><![CDATA[text here]]></xm:set-innerhtml>
+    	
+    	
 
       </xm:modifications>
 </xal>