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 bb...@apache.org on 2006/11/06 14:26:16 UTC

svn commit: r471745 - in /incubator/xap/trunk/testsrc/xap: xml/_TestParser.html xml/parserTester.js xmodify/_TestxModify.html xmodify/_TestxModifyHTML.html

Author: bbuffone
Date: Mon Nov  6 06:26:16 2006
New Revision: 471745

URL: http://svn.apache.org/viewvc?view=rev&rev=471745
Log:
revert ParserFactory chagnes.

Modified:
    incubator/xap/trunk/testsrc/xap/xml/_TestParser.html
    incubator/xap/trunk/testsrc/xap/xml/parserTester.js
    incubator/xap/trunk/testsrc/xap/xmodify/_TestxModify.html
    incubator/xap/trunk/testsrc/xap/xmodify/_TestxModifyHTML.html

Modified: incubator/xap/trunk/testsrc/xap/xml/_TestParser.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/xml/_TestParser.html?view=diff&rev=471745&r1=471744&r2=471745
==============================================================================
--- incubator/xap/trunk/testsrc/xap/xml/_TestParser.html (original)
+++ incubator/xap/trunk/testsrc/xap/xml/_TestParser.html Mon Nov  6 06:26:16 2006
@@ -22,15 +22,20 @@
 dojo.hostenv.setModulePrefix("dojo", "../dojo/src");
 dojo.hostenv.setModulePrefix("xap", "../xap");
 dojo.hostenv.setModulePrefix("google", "../google");
-	Xap.require("xap.xml.ParserFactory");
+	Xap.require("xap.xml.sax.SaxContentHandler");
+	Xap.require("xap.xml.sax.SaxParser");
 	  
     //-----------------------------------------------------------------------
     // Parser-specific Methods.
     //-----------------------------------------------------------------------
     
     function createDoc(xmlString){
-        var parser = xap.xml.ParserFactory.getParser();
-	    return parser.parse( xmlString ) ;
+	    var handler = new xap.xml.sax.SaxContentHandler();
+        var parser = new xap.xml.sax.SaxParser(handler);
+
+	    parser.setDocumentHandler( handler );
+	    parser.parse( xmlString ) ;
+	    return handler._document ;
     }
 
 
@@ -124,58 +129,16 @@
     }
     
     function testEmptyDocument() {
-        exceptionThrown = false;
-        try{
-	    	var doc = createDoc(EMPTY_DOCUMENT);
-		} catch(ee){
-		    exceptionThrown = true;
-		}
-        
-        assertTrue("An exception should have been thrown for emtpy document.",
-                exceptionThrown);
-    } 
-    
-    function testCompoundNamespacesDocument() {
-        exceptionThrown = false;
-        try{
-	    	var doc = createDoc(COMPOUND_NAMESPACE);
- 
- 	        assertTrue("Compound Namespaces: Make sure the root element has a namespace of http://www.openxal.org/xal.",
-                doc.getRootElement().getNamespaceUri() == "http://www.openxal.org/xal");
- 
- 	        assertTrue("Compound Namespaces: Make sure the root element has a prefix of \"\".",
-                doc.getRootElement().getPrefix() == "");
- 
- 	        assertTrue("Compound Namespaces: Make sure the root element has a namespace of http://www.openxal.org/xmodify.",
-                doc.getRootElement().childNodes[0].getNamespaceUri() == "http://www.openxal.org/xmodify");
- 
- 	        assertTrue("Compound Namespaces: Make sure the root element has a prefix of \"\".",
-                doc.getRootElement().childNodes[0].getPrefix() == "xm");
-		} catch(ee){
-		    exceptionThrown = true;
-		}
-        
-    } 
-       
+        assertSpecificExceptionThrownOnParse(EMPTY_DOCUMENT, 
+                                             "xap.xml.sax.EmptyDocumentException");
+    }    
 
-   /*
    function testDuplicateAttributeNames()  {
-        //var doc = createDoc(DUPLICATE_ATTRIBUTES_ON_ELEMENT);
-        //assertEquals("If there are two attributes with the same name, " +
-        //		"the second one should take precedence.", 
-        //		doc.getRootElement().getAttribute("name"), "value2");
-        		
-		exceptionThrown = false;
-        try{
-	    	doc = createDoc(DUPLICATE_ATTRIBUTES_ON_ELEMENT);
-		} catch(ee){
-	    	exceptionThrown = true;
-		}       
-        assertTrue("An exception should have been thrown for invalid xml duplicate attributes.",
-                exceptionThrown);
-        		
+        var doc = createDoc(DUPLICATE_ATTRIBUTES_ON_ELEMENT);
+        assertEquals("If there are two attributes with the same name, " +
+        		"the second one should take precedence.", 
+        		doc.getRootElement().getAttribute("name"), "value2");
     }
-    */
     
     function testTextAndCdata()  {
     	var doc = createDoc(TEXT_AND_CDATA);
@@ -206,9 +169,7 @@
 		    	var doc = createDoc(EMPLOYEE_XML);
 		  		// Made it here, so
 		  		exceptionThrown = false ;  	
-		} catch(ee) {
-			alert(ee);
-		}
+		} catch(ee) {}
 	
 		assertFalse(exceptionThrown) ;	
 /* Breaks unit test coherence....

Modified: incubator/xap/trunk/testsrc/xap/xml/parserTester.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/xml/parserTester.js?view=diff&rev=471745&r1=471744&r2=471745
==============================================================================
--- incubator/xap/trunk/testsrc/xap/xml/parserTester.js (original)
+++ incubator/xap/trunk/testsrc/xap/xml/parserTester.js Mon Nov  6 06:26:16 2006
@@ -69,7 +69,9 @@
 	resultString += "\n"+index+": "+ theStr;
 
 	try {
-	    var parser = xap.xml.ParserFactory.getParser();
+	    var parser = new SaxParser();
+	    var handler = new SaxContentHandler();
+	    parser.setDocumentHandler( handler );
 	    parser.parse(theStr) ;
 	    //result = Xparse(theStr) ; 
 	    //toXml = retag(result).replace(/<[\/]*ROOT>/g,"") ;

Modified: incubator/xap/trunk/testsrc/xap/xmodify/_TestxModify.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/xmodify/_TestxModify.html?view=diff&rev=471745&r1=471744&r2=471745
==============================================================================
--- incubator/xap/trunk/testsrc/xap/xmodify/_TestxModify.html (original)
+++ incubator/xap/trunk/testsrc/xap/xmodify/_TestxModify.html Mon Nov  6 06:26:16 2006
@@ -32,29 +32,34 @@
 function setUp() {
     xap.xml.xmodify.Xmodify.DEBUG=true;
 	try {
- 	   	var session = new xap.session.ClientSession(null,"dojo",null) ;
     	var requestService = new xap.requestservice.RequestService( null );
     	
     	// index.xal contains xap.xml.xmodify.Xmodify instructions that need to get executed
     	var content = requestService.retrieve( "/jsunit/testsrc/xap/xmodify/xmodify.xal" ); 
- 		var parser = xap.xml.ParserFactory.getParser();
-		var commandsDoc = parser.parse( content.responseText );
+ 		var parser = new xap.xml.sax.SaxParser();
+		var handler = new xap.xml.sax.SaxContentHandler();
+		parser.setDocumentHandler( handler );
+		parser.parse( content.responseText );
+
+		// At this point, 'doc' represents our xap.xml.dom.Document containing xap.xml.xmodify.Xmodify 
+		// instructions
+ 		var commandsDoc = handler._document;
 
  		// Get the container containing the UI doc (also our DOM) representing
  		// the application UI.  All xap.xml.xmodify.Xmodify ops will be executed against this
  		// DOM.
  		var documentContainer = new xap.xml.DocumentContainer();		
 
- 		uiDoc = session.getDocumentContainer().getUiDocument();
- 		uiDoc.setRootElement(uiDoc.createElement("xal"));
- 		
+ 		uiDoc = documentContainer.getUiDocument();
+	
  		/////////////////////////////////////////////////
  		// Here is what I need from xap.xml.xmodify.Xmodify:
  		/////////////////////////////////////////////////
- 		var xmodify = new xap.xml.xmodify.Xmodify(commandsDoc.firstChild.firstChild, session);
+ 		var xmodify = new xap.xml.xmodify.Xmodify( commandsDoc.firstChild.firstChild);
 
-		xmodify.execute(); 		
- 	} catch (ee) {
+		xmodify.execute( documentContainer ); 		
+			
+	} catch (ee) {
 		// Need a catch here, even though we mean to do 
 		// nothing interesting:
 			throw ee ;
@@ -65,19 +70,19 @@
 }
 
 function testRootElement(){
-	var rootElement = uiDoc.getRootElement();
+	var rootElement = uiDoc.getRootElement();	
 	assertTrue( "Check Root Element", 
 					rootElement.getLocalName() == "xal" );						
 }
 
 function testAppendElement(){
 	var rootElement = uiDoc.getRootElement();
-	var element = uiDoc.getElementById("button");
-	var element1 = uiDoc.getElementById("button1");
+	var element = uiDoc.getElementById("x0");
+	var element1 = uiDoc.getElementById("x1");
 	
-	assertTrue( "Check Append Element (button) Exists", 
+	assertTrue( "Check Append Element Exists", 
 					element != null );						
-	assertTrue( "Check Append Element (button1) Exists", 
+	assertTrue( "Check Append Element Exists", 
 					element1 != null );		
 					
 	assertTrue( "Check Append Element has correct parent", 
@@ -91,25 +96,26 @@
  */
 function testInsertElement(){
 	var rootElement = uiDoc.getRootElement();
+	
 	assertTrue( "Check Insert Before", 
-					rootElement.childNodes[1].getAttribute("id") == "button1" );						
+					rootElement.childNodes[1].getLocalName() == "button1" );						
 	assertTrue( "Check Insert After", 
-					rootElement.childNodes[2].getAttribute("id") == "button1a" );															
+					rootElement.childNodes[2].getLocalName() == "button1a" );															
 }
 
 function testNestedInsert(){
 	var rootElement = uiDoc.getRootElement();
-	var element1 = uiDoc.getElementById("button1");
+	var element1 = uiDoc.getElementById("x1");
 		
 	assertTrue( "Check Nested Append Element Exists", 
-					element1.childNodes[0].getAttribute("id") == "buttonnested2" );						
+					element1.childNodes[0].getLocalName() == "buttonnested2" );						
 	assertTrue( "Check Nested Append Element Exists", 
-					element1.childNodes[1].getAttribute("id") == "buttonnested3" );						
+					element1.childNodes[1].getLocalName() == "buttonnested3" );						
 }
 
 function testNestedRemove(){
 	var rootElement = uiDoc.getRootElement();
-	var element1 = uiDoc.getElementById("buttonnested");
+	var element1 = uiDoc.getElementById("y1");
 	
 	assertTrue( "Check remove Element worked", 
 					element1 == null );						
@@ -118,7 +124,7 @@
 
 function testAttributeSet(){
 	var rootElement = uiDoc.getRootElement();
-	var element1 = uiDoc.getElementById("button1");
+	var element1 = uiDoc.getElementById("x1");
 		
 	assertTrue( "Check set attribute BB worked = " + element1.toXml(true), 
 					element1.getAttribute("BB") == "B1" );						
@@ -126,7 +132,7 @@
 
 function testAttributeRemove(){
 	var rootElement = uiDoc.getRootElement();
-	var element1 = uiDoc.getElementById("button1");
+	var element1 = uiDoc.getElementById("x1");
 	
 	assertTrue( "Check set attribute AA worked = " + element1.toXml(true), 
 					element1.getAttribute("AA") == null );						
@@ -135,7 +141,7 @@
 
 function testRemoveChildren(){
 	var rootElement = uiDoc.getRootElement();
-	var element1 = uiDoc.getElementById("button2");
+	var element1 = uiDoc.getElementById("x2");
 	
 	assertTrue( "Check remove children worked child array length = " + element1.childNodes.length, 
 					element1.childNodes.length == 0 );						

Modified: incubator/xap/trunk/testsrc/xap/xmodify/_TestxModifyHTML.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/xmodify/_TestxModifyHTML.html?view=diff&rev=471745&r1=471744&r2=471745
==============================================================================
--- incubator/xap/trunk/testsrc/xap/xmodify/_TestxModifyHTML.html (original)
+++ incubator/xap/trunk/testsrc/xap/xmodify/_TestxModifyHTML.html Mon Nov  6 06:26:16 2006
@@ -25,8 +25,8 @@
 dojo.hostenv.setModulePrefix("xap", "../xap");
 dojo.hostenv.setModulePrefix("google", "../google");
 Xap.require("xap.xml.xmodify.Xmodify");
-Xap.require("xap.session.ClientSession");
-Xap.require("xap.xml.ParserFactory");
+Xap.require("xap.xml.sax.SaxParser");
+Xap.require("xap.xml.sax.SaxContentHandler");
 Xap.require("xap.requestservice.RequestService");
 var setupOnce = true;
 function setUp() {
@@ -35,19 +35,25 @@
     if (setupOnce == false) return;
     
 	try {
-  		var session = new xap.session.ClientSession(null,"dojo",null) ;
     	var requestService = new xap.requestservice.RequestService( null );
     	
     	// 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 parser = new xap.xml.sax.SaxParser();
+		var handler = new xap.xml.sax.SaxContentHandler();
+		parser.setDocumentHandler( handler );
+		parser.parse( content.responseText );
 		
+		// At this point, 'doc' represents our xap.xml.dom.Document containing xap.xml.xmodify.Xmodify 
+		// instructions
+ 		var commandsDoc = handler._document;
+ 			
  		/////////////////////////////////////////////////
  		// Here is what I need from xap.xml.xmodify.Xmodify:
  		/////////////////////////////////////////////////
- 		var xmodify = new xap.xml.xmodify.Xmodify( commandsDoc.firstChild.firstChild, session);
+ 		var xmodify = new xap.xml.xmodify.Xmodify( commandsDoc.firstChild.firstChild);
 		xmodify.execute( document ); 		
+
 	} catch (ee) {
 		// Need a catch here, even though we mean to do 
 		// nothing interesting: