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:18:49 UTC
svn commit: r470560 - in /incubator/xap/trunk/src/xap: Xap.js
session/ClientSession.js
Author: bbuffone
Date: Thu Nov 2 14:18:49 2006
New Revision: 470560
URL: http://svn.apache.org/viewvc?view=rev&rev=470560
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.
Modified:
incubator/xap/trunk/src/xap/Xap.js
incubator/xap/trunk/src/xap/session/ClientSession.js
Modified: incubator/xap/trunk/src/xap/Xap.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/Xap.js?view=diff&rev=470560&r1=470559&r2=470560
==============================================================================
--- incubator/xap/trunk/src/xap/Xap.js (original)
+++ incubator/xap/trunk/src/xap/Xap.js Thu Nov 2 14:18:49 2006
@@ -17,6 +17,42 @@
Xap = function () {}
+/**
+ * START OF PUBLIC METHODS FOR THE XAP CLASS USED TO
+ * CREATE THE APPLICATION WITH IN A WEB PAGE.
+ */
+
+/**
+ * Static method to create an application.
+ */
+Xap.createApplication = function(applicationConfig) {
+ Xap.require("xap.application.Application");
+ var application = new xap.application.Application(applicationConfig);
+
+ //create the application.
+ application.create();
+ return application;
+}
+
+/**
+ * Static method to create applications objects for all the embedded applications.
+ */
+Xap.createEmbeddedApplications = function() {
+ Xap.require("xap.html.HtmlConnector");
+
+ xap.html.HtmlConnector.scanPage();
+ xap.html.HtmlConnector.createEmbeddedApplications();
+
+ //return the xap applications
+ return window.xapApplications;
+}
+
+
+/**
+ * START OF PRIVATE METHODS AND VARIABLE FOR THE XAP CLASS.
+ * ALSO PUBLIC PROVIDE and REQUIRE METHODS
+ *
+ */
dojo.hostenv.setModulePrefix("dojo", "../dojo/src");
dojo.hostenv.setModulePrefix("xap", "../xap");
@@ -32,33 +68,37 @@
djConfig.baseRelativePath = "../../src/dojo/";
}
+Xap.ourLoadedClasses = new Object() ;
+
Xap.kwCompoundRequire = function(){
dojo.kwCompoundRequire.apply(dojo, arguments);
}
+/**
+ * Method is used to declare that the class contained in the file is avaible for use.
+ * This works similar to a Java:
+ * package com.nexaweb.MyClass;
+ *
+ */
Xap.provide = function(){
dojo.provide.apply(dojo,arguments);
}
-
-
-// We use these repeatedly, why re-create them each time?
-Xap.trailingSlashRegexp = /^.*\/$/ ;
-Xap.allFullstopsRegexp = /\./g ;
-Xap.anyAsteriskRegexp = /\*/g ;
-
-Xap.ourLoadedClasses = new Object() ;
-
+/**
+ * Method is used to require a class be loaded. This
+ * works similar to a Java:
+ * import com.nexaweb.MyClass;
+ *
+ */
Xap.require = function(){
-// Modules will have to go through Dojo:
+ // Modules will have to go through Dojo:
var toLoad = arguments[0] ;
var notModule = (toLoad.search(Xap.anyAsteriskRegexp)==-1) ;
-//
-//
-// Don't overload, don't depend on ArrayHelper being around:
+
+ // Don't overload, don't depend on ArrayHelper being around:
var alreadyLoaded = (Xap.ourLoadedClasses[toLoad])?true:false ;
if( alreadyLoaded ){
Xap._logString += "\nRedundant load attempt: "+toLoad ;
@@ -67,16 +107,13 @@
// do we need to reload this file?
//---is it in the "debuggables" list?--are we reloading everything?
- var needToDebugLoad = notModule
- && (Xap._debugAll
- || (Xap._debugLoad && Xap._debuggables[toLoad])
- ) ;
-
+ var needToDebugLoad = notModule &&
+ (Xap._debugAll ||
+ (Xap._debugLoad && Xap._debuggables[toLoad]));
try {
dojo.require.apply(dojo,arguments) ;
if(needToDebugLoad){
-
Xap.addDebuggables([toLoad]) ;
Xap.ourLoadedClasses[toLoad] = true ;
}
@@ -85,256 +122,6 @@
}
}
-
-Xap.addDebuggables = function(){
- if( !Xap._debuggables ){
- Xap._debuggables = new Object() ;
- }
- for (var ii=0; ii<arguments.length; ++ii ){
- Xap._debuggables[arguments[ii]] = true ;
- }
-}
-
-
-
-Xap._loadDebuggable = function(str){
- var path = str.replace(Xap.allFullstopsRegexp,"/") ;
- if ( !Xap._sourceRootDir.match(Xap.trailingSlashRegexp)){
- Xap._sourceRootDir +="/" ;
- }
- path = Xap._sourceRootDir +"src/"+path +".js" ;
- //alert(path) ;
- xap.util.Utils.importFile(path) ;
-}
-
-Xap._loadDebuggables = function(pathHolderObj){
- if( !pathHolderObj){
- // Default behavior:
- Xap._loadDebuggables(Xap._debuggables) ;
- return ;
- } else {
- for (var nom in pathHolderObj){
- Xap._loadDebuggable( nom ) ;
- }
- }
-}
-
-Xap.debugLoad = function(){
- Xap._addDebuggables(arguments) ;
- Xap._loadDebuggables() ;
-}
-
-
-
-/**
-
-/**
- * @private
- * Looks for nodes with the criteria we want
-**/
-Xap._findAppElements = function(){
- Xap.require("google.xpath");
- 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 ;
-
-}
-
-Xap.APPLICATION_CONTEXT_ATTRIBUTE__NAME="xapContext" ;
-Xap.APPLICATION_ID_ATTRIBUTE__NAME = "xapId" ;
-Xap.APPLICATION_SOURCE_ATTRIBUTE__NAME = "xapSrc" ;
-Xap.APPLICATION_TOOLKIT_ATTRIBUTE__NAME = "xapToolkit" ;
-
-// Use this count to create xaplet i.d.'s if they're not supplied:
-Xap.xapletCount = 0 ;
-
-Xap.getNextXapLabel = function(){
- return "unlabelled_xaplet_"+ (++Xap.xapletCount) ;
-}
-
-
-Xap.scanPage= function(){
- var allPossibleContainerNodes = Xap._findAppElements() ;
- if( !window.xapSessionIds){
- window.xapSessionIds = new Array( 0 ) ;
- }
- // information may already be here from a script in the html file:
- if( !Xap.predefinedSessions){
- // ...or not:
- Xap.predefinedSessions = new Array( 0 ) ;
- }
- for (var i =0; i<allPossibleContainerNodes.length; i++){
- var thisSessionsParameters = new Object() ;
- var element = allPossibleContainerNodes[i] ;
- if( !element.getAttribute ){
- continue;
- }
- // The HTML DOM node from which we're getting all these attributes....
- thisSessionsParameters.xapHome = element ;
-
- // What's the XAL file?---required
- thisSessionsParameters.xapSrc = element.getAttribute(Xap.APPLICATION_SOURCE_ATTRIBUTE__NAME);
- if(! thisSessionsParameters.xapSrc ){
- continue ;
- }
-
-
- // What's the i.d.?---if none passed in, generate one:
- thisSessionsParameters.xapId = element.getAttribute(Xap.APPLICATION_ID_ATTRIBUTE__NAME);
- var passedInId = true ;
-
- if(! thisSessionsParameters.xapId ){
- passedInId = false ;
- thisSessionsParameters.xapId = Xap.getNextXapLabel() ;
- }
-
- // What's the toolkit?---dojo?---defaults to zimbra if null
- thisSessionsParameters.xapToolkit = element.getAttribute(Xap.APPLICATION_TOOLKIT_ATTRIBUTE__NAME);
-
- // what's the load context for plugin.xml or its equivalent?---default to boot context:
- thisSessionsParameters.xapContext = Xap._sourceRootDir ;
- if( element.getAttribute(Xap.APPLICATION_CONTEXT_ATTRIBUTE__NAME)){
- thisSessionsParameters.xapContext = element.getAttribute(Xap.APPLICATION_CONTEXT_ATTRIBUTE__NAME) ;
- };
-
- Xap.predefinedSessions.push(thisSessionsParameters) ;
-
- }
-}
-
-
-/**
- * Uses the data gathered into Xap.predefinedSessions to create them:
-**/
-Xap.createAllPredefinedSessions = function(){
- // Gather any information on sessions found in the page
- Xap.scanPage() ;
-
- for( var j=0; j<Xap.predefinedSessions.length; ++j ){
- var thisSessionDef = Xap.predefinedSessions[j] ;
- var thisElementsAppName = thisSessionDef.xapId ;
- var src = thisSessionDef.xapSrc ;
- var toolkit = thisSessionDef.xapToolkit ;
- var context = thisSessionDef.xapContext ;
- var element = thisSessionDef.xapHome ;
- // If this is a string, then it's the _i.d._ for the
- // home element rather than the element itself:
- if( element && typeof element == "string"){
- element = document.getElementById(element) ;
- }
- if (!element){
- element = document.body ;
- }
- thisSessionDef.xapHome = element ;
-
-
- var session = Xap.createSession(context, src, toolkit , element);
- // these might be handy to keep around:
- session[Xap.APPLICATION_ID_ATTRIBUTE__NAME] = thisElementsAppName ;
- session[Xap.APPLICATION_SOURCE_ATTRIBUTE__NAME ] = src ;
- session[Xap.APPLICATION_TOOLKIT_ATTRIBUTE__NAME ] = toolkit ;
- session[Xap.APPLICATION_CONTEXT_ATTRIBUTE__NAME] = context ;
-
- session.domContainer = element ;
- if (window[thisElementsAppName]==null){
- window[thisElementsAppName]= session;
- window.xapSessionIds.push( thisElementsAppName ) ;
- } else{
- //TODO throw some error?
- }
- }
-}
-
-
-
-
-Xap.defineSession = function(src, xapletName,xapHomeId,context,toolkit){
-
- if( !src ){
- throw new xap.util.Exception("No source (.xal) file given for this xap application.") ;
- }
-
- if( !Xap.predefinedSessions){
- Xap.predefinedSessions = new Array( 0 ) ;
- }
- var newSess = new Object() ;
- newSess.xapId = xapletName ;
- if (!xapletName){
- newSess.xapId = Xap.getNextXapLabel() ;
- }
- newSess.xapContext = Xap._sourceRootDir ;
- if( context ){
- newSess.xapContext = context ;
- }
- newSess.xapSrc = src ;
- newSess.xapToolkit = toolkit ;
- newSess.xapHome = xapHomeId ;
- if( !newSess.xapHome ){
- newSess.xapHome = document.body ;
- }
-
-
- Xap.predefinedSessions.push(newSess) ;
-}
-
-
-
-Xap.bootstrap = function( sourceRootDir,loadType ) {
- // Will need this later to hold dojo configuration information:
- if (!djConfig){
- if (!config){
- djConfig={} ;
- } else {
- djConfig = config ;
- }
- }
-
-
- // debugger-friendlier loader?:
- Xap._debugLoad = (loadType)?true:false ;
- Xap._debugAll = (loadType && loadType == "debugAll") ;
- if( !Xap._debuggables ){
- Xap._debuggables = new Object() ;
- }
-
- Xap._logString = "" ;
- Xap._showLog = function(){
- prompt("",Xap._logString.replace(/\n/g,"^")) ;
- }
-
- Xap._sourceRootDir = sourceRootDir;
- Xap.loadXap( sourceRootDir );
-
-// We've done all the "real" loading, now let's attach code to source files
-// previously targetted for debugger-friendly (specified before we bootstrap):
-//Later: don't load automatically, wait for latest possible moment:
-// if( Xap._debugLoad ){
-// Xap._loadDebuggables() ;
-// }
-
-}
-
-Xap.createSession = function( context, startPage,toolkitType , element) {
- Xap.require("xap.session.ClientSession");
- var session = new xap.session.ClientSession( context,toolkitType ,element );
- session._start( startPage );
- return session;
-}
-
-
-
-
-Xap.loadXap = function( sourceRootDir ) {
-
-}
-
-
Xap.resolveConstructor = function(aString){
var result ;
Modified: incubator/xap/trunk/src/xap/session/ClientSession.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/session/ClientSession.js?view=diff&rev=470560&r1=470559&r2=470560
==============================================================================
--- incubator/xap/trunk/src/xap/session/ClientSession.js (original)
+++ incubator/xap/trunk/src/xap/session/ClientSession.js Thu Nov 2 14:18:49 2006
@@ -9,6 +9,7 @@
*
* 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.
*
@@ -80,10 +81,7 @@
var uiDocument = this._documentContainer.getUiDocument();
this._uiDocumentHandler = new xap.taghandling.PluginDocumentHandler( this,
uiDocument, xap.xml.DocumentContainer.UI_DOCUMENT_NAME );
-
-
- //TODO handle this in a better way
- this._createInitialDocument(toolkitType, parentElement);
+
}
xap.session.ClientSession.s_log = xap.util.LogFactory.getLog( "xap.session.ClientSession" );
@@ -210,125 +208,90 @@
}
}
+xap.session.ClientSession.prototype.getUiDocumentHandler = function() {
+ return this._uiDocumentHandler;
+}
+
+
//-----------------------------------------------------------------------
// Private Methods.
//-----------------------------------------------------------------------
-xap.session.ClientSession.prototype._start = function( startPage ) {
- this._processConfiguration();
- var requestService = this.getRequestService();
- try{
- requestService.retrieveStartPage( startPage );
+xap.session.ClientSession.prototype._start = function( appConfigObject ) {
+ //enable logging if needed.
+ if(appConfigObject.loggingEnabled != null) {
+ if(appConfigObject.loggingEnabled == "true") {
+ xap.util.LogFactory.enableLogging()
+ } else {
+ xap.util.LogFactory.disableLogging();
+ }
}
- catch( exception ){
- this.handleException( exception);
+
+ //process any plugin class or files.
+ if (appConfigObject.pluginFiles){
+ this._processPluginConfigurationFiles( appConfigObject.pluginFiles );
}
-}
+ if (appConfigObject.pluginClasses){
+ this._processPluginConfigurationClasses( appConfigObject.pluginClasses );
+ }
+
+ if (appConfigObject.element != null){
+ this._createInitialDocument(appConfigObject.toolkitType, appConfigObject.element);
+ }
-xap.session.ClientSession.prototype._processPluginConfiguration = function (pluginNode){
- var children = pluginNode.childNodes;
var requestService = this.getRequestService();
- for( var i = 0; i < children.length; i++ ) {
- var child = children[ i ];
- var localName = child.getLocalName();
- if (localName=="plugin-file"){
- var fileLocation = child.getAttribute("file");
- if (fileLocation){
- var response = requestService.retrieve(this._webappContext + fileLocation);
- this._pluginRegistry.addPluginDescription(response.responseText);
- }
- }
- else if (localName=="plugin-class"){
- var className = child.getAttribute("class");
- this._pluginRegistry.loadLifecycleObject(className);
+
+ try{
+ if (appConfigObject.startPage){
+ requestService.retrieveAndProcess( appConfigObject.startPage );
}
}
+ catch( exception ){
+ this.handleException( exception);
+ }
}
-xap.session.ClientSession.prototype._processConfiguration = function() {
- var configFilePath = this._webappContext + "XapConfig.xml";
- var configString = this.getRequestService().retrieve( configFilePath ).responseText;
- if( configString && configString != null ) {
- try {
- var parser = new xap.xml.sax.SaxParser( new xap.xml.sax.SaxContentHandler() );
- var doc = parser.parse( configString );
- var root = doc.getRootElement();
- var children = root.childNodes;
- for( var i = 0; i < children.length; i++ ) {
- var child = children[ i ];
- var localName = child.getLocalName();
- if( localName == "log-configuration" ) {
- var enabled = child.getAttribute( "logging-enabled" );
- if( enabled != null ) {
- if( enabled == "true" ) {
- xap.util.LogFactory.enableLogging()
- } else {
- xap.util.LogFactory.disableLogging();
- }
- }
- }
- else if (localName=="plugins"){
- this._processPluginConfiguration( child );
- }
- }
- } catch ( e ) {
- xap.session.ClientSession.s_log.error( "Exception parsing config:" + configString );
- }
+xap.session.ClientSession.prototype._processPluginConfigurationFiles = function (pluginFiles){
+ var requestService = this.getRequestService();
+ for( var i = 0; i < pluginFiles.length; i++ ) {
+ var fileLocation = pluginFiles[ i ];
+ var response = requestService.retrieve(this._webappContext + fileLocation);
+ this._pluginRegistry.addPluginDescription(response.responseText);
}
}
-
-
-xap.session.ClientSession.prototype.getUiDocumentHandler = function() {
- return this._uiDocumentHandler;
+xap.session.ClientSession.prototype._processPluginConfigurationClasses = function (pluginClasses){
+ for( var i = 0; i < pluginClasses.length; i++ ) {
+ var className = pluginClasses[ i ];
+ this._pluginRegistry.loadLifecycleObject(className);
+ }
}
+/**
+ * This function creates the intitial xml document for the session.
+ * This function is only called if there is a starting page.
+ */
xap.session.ClientSession.prototype._createInitialDocument = function(toolkitType, parentElement) {
- var parentElementWrapper = null ;
-
- //create a zimbra parentElementWrapper object
- //create an abstractTagImpl
- var handler = new xap.taghandling.AbstractTagImpl();
+ Xap.require("xap.bridges.basic.HtmlHostBridge");
-
-// If the handler handles a dojo widget, its relevant dom node will be the parentElement;
-// if zimbroid, it will have to be found some other way Zimbra will handle:
- if( toolkitType && toolkitType=="dojo"){
- parentElementWrapper = parentElement!=null? parentElement : document.body ;
-
- handler.getNodeForChildren = function(){
- return parentElement ;
- }
+ //create a HtmlHostBridge this is the the xal application will live.
+ var htmlHostBridge = new xap.bridges.basic.HtmlHostBridge();
+
+ var uiDocument = this.getDocumentContainer().getUiDocument();
+ htmlHostBridge.setElement( uiDocument.getRootElement() );
+ htmlHostBridge.setSession( this );
- handler.childAdded = function( e ) {
- var childElement = e.getChange();
- var childHandler = this.getUiContentHandler().getHandlerForElement( childElement );
- this.addChild(childHandler, e.getIndex());
- }
-
- handler.addChild = function(child, index){
- if (child.getRootDomNode()){
- this.getNodeForChildren().appendChild(child.getRootDomNode());
- }
- }
- } else {
- parentElementWrapper = new DwtShell( "MainShell", false, null, null, true );
- handler.getNodeForChildren = function(){
- return parentElementWrapper ;
- }
- }
-
+ //initalize the html host bridge This really does nothing but
+ //we do it anyways
+ htmlHostBridge.init();
+
+ //create the actual host of the widgets in the document.
+ htmlHostBridge.createHost(parentElement, toolkitType);
+
+ //keep track of the handlers.
+ this.getUiDocumentHandler().setHandlerForElement(htmlHostBridge.getElement(), htmlHostBridge);
+ this.getUiDocumentHandler().setHandlerForElement(uiDocument.getRootElement(), htmlHostBridge);
- var uiDocument = this.getDocumentContainer().getUiDocument();
- handler.setElement( uiDocument.getRootElement() );
- handler.setSession( this );
-
- this.getUiDocumentHandler().setHandlerForElement(
- handler.getElement(), handler );
- handler.init();
-
- //have the parentElementWrapper be the peer of the xap.taghandling.AbstractTagImpl
- handler.setPeer( parentElementWrapper );
- uiDocument.getRootElement().addStructureChangeListener( handler );
+ uiDocument.getRootElement().addStructureChangeListener( htmlHostBridge );
}