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/02 22:14:02 UTC

svn commit: r470550 - in /incubator/xap/trunk/src/xap/html: ./ HtmlConnector.js

Author: bbuffone
Date: Thu Nov  2 14:14:02 2006
New Revision: 470550

URL: http://svn.apache.org/viewvc?view=rev&rev=470550
Log:
I have updated the starting process of the XAP engine with the HTML page.
This changes is defined in emails from me on the 8/29.  
This changes break compatibilty with existing samples. 
To see how the new process works check out the new samples in 
the startup folder.

Added:
    incubator/xap/trunk/src/xap/html/
    incubator/xap/trunk/src/xap/html/HtmlConnector.js

Added: incubator/xap/trunk/src/xap/html/HtmlConnector.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/html/HtmlConnector.js?view=auto&rev=470550
==============================================================================
--- incubator/xap/trunk/src/xap/html/HtmlConnector.js (added)
+++ incubator/xap/trunk/src/xap/html/HtmlConnector.js Thu Nov  2 14:14:02 2006
@@ -0,0 +1,161 @@
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+ 
+Xap.provide("xap.html.HtmlConnector");
+
+/**
+ * HtmlConnector allows developers to easily connect html 
+ * events and widgets to the Xap functionality.
+ *
+ */
+xap.html.HtmlConnector = function () {}
+
+/**
+ * These methods below are used only for the page scaning and will be
+ * replace with the OpenAjax functionality shortly.
+ */
+ 
+ 
+/**
+ *  @private
+ *  Looks for nodes with the criteria we want
+ */  
+xap.html.HtmlConnector._findAppElements = function(){
+	var currentContext =   new google.ExprContext(document) ;
+	
+    // The following _should_ work, but I think google's XPath
+    // is a little broken---an earlier attempt to run //*[id='anId']
+    // in xap.xml.xmodify.Xmodify code didn't work, either	
+    //	var parsedXPathExpr = google.xpathParse("//*[@appName]") ;
+	var parsedXPathExpr = google.xpathParse("//") ;
+	var targetNodes = parsedXPathExpr.evaluate( currentContext );
+	var targetNodesArray = targetNodes.nodeSetValue();	
+	
+	return targetNodesArray ;
+
+}
+
+/**
+ * Use this count to create xaplet i.d.'s if they're not supplied:
+ */
+xap.html.HtmlConnector.xapletCount = 0 ;
+
+/**
+ *  
+ */
+xap.html.HtmlConnector.getNextXapLabel = function(){
+	return "unlabelled_xaplet_"+ (++xap.html.HtmlConnector.xapletCount) ;
+}
+
+/**
+ * Embedded attributes for xap.
+ */
+xap.html.HtmlConnector.APPLICATION_CONTEXT_ATTRIBUTE__NAME="context";
+xap.html.HtmlConnector.APPLICATION_ID_ATTRIBUTE__NAME = "applicationName";
+xap.html.HtmlConnector.APPLICATION_SOURCE_ATTRIBUTE__NAME = "startPage";
+xap.html.HtmlConnector.APPLICATION_TOOLKIT_ATTRIBUTE__NAME = "toolkitType";
+xap.html.HtmlConnector.APPLICATION_CONFIGFILEPATH_ATTRIBUTE__NAME = "configFilePath";
+xap.html.HtmlConnector.APPLICATION_CONTEXT_DEFAULT="../../";
+xap.html.HtmlConnector.APPLICATION_TOOLKITTYPE_DEFAULT="dojo";
+xap.html.HtmlConnector.APPLICATION_CONFIGFILEPATH_DEFAULT = "../../XapConfig.js";
+
+/**
+ * This method runs through the HTML page and looks for all interesting
+ * elements that we may added as applications
+ */
+xap.html.HtmlConnector.scanPage = function(){
+	
+	//search html dom and try to find the application.
+	var allPossibleContainerNodes = xap.html.HtmlConnector._findAppElements();
+	
+	//see if the xap Application array has been initialized.
+	if (window.xapApplications == null){
+		window.xapApplications = new Array(0);
+	}
+	
+	// information may already be here from a script in the html file:
+	if (Xap.embeddedApplications == null){
+	    // ...or not:
+		Xap.embeddedApplications = new Array(0);
+	}
+	
+	for (var i=0; i<allPossibleContainerNodes.length; ++i){
+		var element = allPossibleContainerNodes[i] ; 	
+		if(!element.getAttribute){
+			continue;
+		}
+		
+		// What's the XAL file?---required
+		var startPage = element.getAttribute(xap.html.HtmlConnector.APPLICATION_SOURCE_ATTRIBUTE__NAME);	
+		if(!startPage){
+		    continue;
+		}
+		
+		// What's the i.d.?---if none passed in, generate one:	
+		var applicationId = element.getAttribute(xap.html.HtmlConnector.APPLICATION_ID_ATTRIBUTE__NAME);
+		if(!applicationId){
+			applicationId = xap.html.HtmlConnector.getNextXapLabel();
+		}
+			
+		// what's the load context for plugin.xml or its equivalent?---default to boot context:
+		var context = element.getAttribute(xap.html.HtmlConnector.APPLICATION_CONTEXT_ATTRIBUTE__NAME);
+		if(context==null){
+			context = xap.html.HtmlConnector.APPLICATION_CONTEXT_DEFAULT;
+		}
+		
+		// what's the load context for plugin.xml or its equivalent?---default to boot context:
+		var configFilePath = element.getAttribute(xap.html.HtmlConnector.APPLICATION_CONFIGFILEPATH_ATTRIBUTE__NAME);
+		if(configFilePath==null){
+			configFilePath = xap.html.HtmlConnector.APPLICATION_CONFIGFILEPATH_DEFAULT;
+		}
+		
+		// what's the load context for plugin.xml or its equivalent?---default to boot context:
+		var toolkitType = element.getAttribute(xap.html.HtmlConnector.APPLICATION_TOOLKIT_ATTRIBUTE__NAME);
+		if(toolkitType==null){
+			toolkitType = xap.html.HtmlConnector.APPLICATION_TOOLKITTYPE_DEFAULT;
+		}
+
+		var myApplicationConfig = {
+			    applicationName: applicationId,
+				startPage: startPage,
+				context: context,
+				scanPage: false,
+				element: element,
+				configFilePath: configFilePath
+		};
+						
+		Xap.embeddedApplications.push(myApplicationConfig);		
+	}
+}
+
+/**
+ * Called after the page was scaned to create the found applications.
+ * for each one of the found application definitions create the 
+ */
+xap.html.HtmlConnector.createEmbeddedApplications = function(){
+	
+	//loop through all the application configuration objects
+	for (var j=0; j<Xap.embeddedApplications.length; ++j){
+	    
+		var thisPredefinedApplication = Xap.embeddedApplications[j];
+
+        //create the application for this object
+        var app = Xap.createApplication(thisPredefinedApplication);
+        window.xapApplications[thisPredefinedApplication.applicationName] = app;
+	}
+}
+