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:13:44 UTC
svn commit: r470548 - in /incubator/xap/trunk/src/xap/xml/xmodify:
CommandDirective.js DirectiveSet.js UpdateDirective.js Xmodify.js
XmodifyNamespaceHandler.js
Author: bbuffone
Date: Thu Nov 2 14:13:43 2006
New Revision: 470548
URL: http://svn.apache.org/viewvc?view=rev&rev=470548
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/xml/xmodify/CommandDirective.js
incubator/xap/trunk/src/xap/xml/xmodify/DirectiveSet.js
incubator/xap/trunk/src/xap/xml/xmodify/UpdateDirective.js
incubator/xap/trunk/src/xap/xml/xmodify/Xmodify.js
incubator/xap/trunk/src/xap/xml/xmodify/XmodifyNamespaceHandler.js
Modified: incubator/xap/trunk/src/xap/xml/xmodify/CommandDirective.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/xmodify/CommandDirective.js?view=diff&rev=470548&r1=470547&r2=470548
==============================================================================
--- incubator/xap/trunk/src/xap/xml/xmodify/CommandDirective.js (original)
+++ incubator/xap/trunk/src/xap/xml/xmodify/CommandDirective.js Thu Nov 2 14:13:43 2006
@@ -22,7 +22,7 @@
Xap.require("xap.util.LogFactory");
Xap.require("google.xpath");
- /**
+/**
* @fileoverview An object embodying a particular operation (e.g., <code>append</code>) to be performed
* on a targetted part of the UI document (as specifically using either
* XPath or a Xap-specific syntax wrappering <code>getElementById()</code>.<b>
@@ -59,9 +59,8 @@
// Constructors.
//----------------------------------------------------------------------
-xap.xml.xmodify.CommandDirective = function(elemDirectiveElement)
+xap.xml.xmodify.CommandDirective = function(elemDirectiveElement, session)
{
-
/* Call our superclass' xap.xml.xmodify.UpdateDirective */
xap.xml.xmodify.UpdateDirective.call( this, elemDirectiveElement );
@@ -74,9 +73,10 @@
if ((this._commandArguments.length == 0) &&
(this._strType == "set-attribute") ) /* We'll replace this with a mustHaveArgs() func */
{
- throw new xap.xml.xmodify.XmodifyException(xap.xml.xmodify.XmodifyException.COMMAND_EXPECTS_ONE_ARG,"set-attribute") ;
-
+ throw new xap.xml.xmodify.XmodifyException(xap.xml.xmodify.XmodifyException.COMMAND_EXPECTS_ONE_ARG,"set-attribute") ;
}
+
+ this._session = session;
}
xap.xml.xmodify.CommandDirective.s_log = xap.util.LogFactory.getLog( "xap.xml.xmodify.Xmodify" );
@@ -105,10 +105,9 @@
throw new
xap.xml.xmodify.XmodifyException(
xap.xml.xmodify.XmodifyException.ZERO_RESULTS,
- this._selectAttr
- );
+ this._selectAttr);
}
-
+
/* @TODO: Switch on type, use ints, not strs */
switch (directiveType) {
case xap.xml.xmodify.UpdateDirective.DIRECTIVE_APPEND:
@@ -138,6 +137,12 @@
case xap.xml.xmodify.UpdateDirective.DIRECTIVE_CLONE:
this._handleClone(uiDocumentNode);
break;
+ case xap.xml.xmodify.UpdateDirective.DIRECTIVE_EMBED_XAL:
+ this._handleEmbedXal(uiDocumentNode);
+ break;
+ case xap.xml.xmodify.UpdateDirective.DIRECTIVE_SET_INNER_HTML:
+ this._handleSetInnerHtml(uiDocumentNode);
+ break;
default:
xap.xml.xmodify.UpdateDirective.s_log.debug("Unhandled command : "+this._strType);
} /* end switch */
@@ -173,15 +178,15 @@
//handle the id('xxx') syntax instead of full xpath
//IMPORTANT do we need to support this, this is a feature
//of xmodify and not our xpath
- if ( selectString && selectString.indexOf("id(")==0){
- var id = selectString.substring(3);
+ if ( selectString && selectString.indexOf("id(")==0){
+ var id = selectString.substring(3);
var aposIndex = id.indexOf("'");
var lastAposIndex = id.lastIndexOf("'");
- id = id.substring(aposIndex+1,lastAposIndex);
+ id = id.substring(aposIndex+1,lastAposIndex);
var target = uiDocumentNode.getElementById(id);
- if( target && typeof target != "undefined"){
- targetNodesArray.push(target) ;
- }
+ if( target && typeof target != "undefined"){
+ targetNodesArray.push(target) ;
+ }
}
//handle #ID syntax
@@ -192,10 +197,8 @@
if( target && typeof target != "undefined"){
targetNodesArray.push(target) ;
}
- }
- //otherwise run an xpath statement
- else {
+ } else {
var currentContext = new google.ExprContext(uiDocumentNode) ;
var parsedXPathExpr = google.xpathParse(localSelectString) ;
@@ -214,7 +217,6 @@
**/
xap.xml.xmodify.CommandDirective.prototype._handleAppend = function(uiDocumentNode)
{
-
var targetNodes = this._commandTargets ;
var elemsToAppend = this._commandArguments;
xap.xml.xmodify.CommandDirective.s_log.debug (
@@ -530,7 +532,7 @@
= function(index,parent,contextNode, xpathResultIndex)
{
var arrArguments = this._commandArguments ;
- for (var ii=0; ii<arrArguments.length; ++i ) {
+ for (var ii=0; ii<arrArguments.length; ++ii ) {
// unresolved argument: (arbitrary xml | String | CloneDirective |
// ValueOfDirective)*
@@ -615,8 +617,7 @@
if ( parent == null ) {
throw new xap.xml.xmodify.XmodifyException(
xap.xml.xmodify.XmodifyException.INVALID_INSERT_AFTER_BECAUSE_OF_PARENT,
- "'undefined'"
- )
+ "'undefined'");
}
} else if (currentNode.nodeType == google.DOM_ATTRIBUTE_NODE) {
//TODO we might want to make it work in the future.
@@ -624,13 +625,11 @@
// API on the Element: setAttributeAt
throw new xap.xml.xmodify.XmodifyException(
xap.xml.xmodify.XmodifyException.CHILDREN_CANT_BE_ADDED,
- parent.nodeName
- ) ;
+ parent.nodeName);
} else {
throw new xap.xml.xmodify.XmodifyException(
xap.xml.xmodify.XmodifyException.INVALID_INSERT_BEFORE_BECAUSE_OF_PARENT,
- currentNode.nodeName
- ) ;
+ currentNode.nodeName);
}
// Do the simple thing, at this point:
@@ -917,8 +916,6 @@
this._clones = new Array(this._commandTargets.length) ;
-
-
for (var ll=0; ll<this._commandTargets.length; ++ll) {
var toClone = this._commandTargets[ll] ;
if (toClone.nodeType == google.DOM_ELEMENT_NODE) {
@@ -928,14 +925,61 @@
throw new xap.xml.xmodify.XmodifyException(
xap.xml.xmodify.XmodifyException.CANT_BLANK_TO_NODE_TYPE,
"Clone",
- currentNode.nodeType
- ) ;
+ currentNode.nodeType);
}
}
}
/**
+ * Called to embed the xal components into the html document.
+ */
+xap.xml.xmodify.CommandDirective.prototype._handleEmbedXal = function(node){
+ Xap.require("xap.bridges.basic.HtmlHostBridge");
+ var targetNodes = this._commandTargets;
+ var elemsToAppend = this._commandArguments;
+ var uiDocument = this._session.getDocumentContainer().getUiDocument();
+
+ for (var i=0; i<targetNodes.length; i++) {
+ var parentElement = targetNodes[i] ;
+
+ //create the element and add it to the document
+ var hostElement = uiDocument.createElement("htmlHost", null, "http://www.openxal.org/xal");
+ hostElement = uiDocument.getRootElement().appendChild(hostElement);
+
+ //get the handler and set up the peer.
+ var htmlHostBridge = this._session.getUiDocumentHandler().getHandlerForElement(hostElement);
+
+ //now actually setup the html host.
+ htmlHostBridge.createHost(parentElement, "dojo");
+
+ for (var ii=0; ii<elemsToAppend.length;ii++){
+ hostElement.appendChild(elemsToAppend[ii]);
+ }
+ }
+}
+
+/**
+ * Called when a set-innerhtml xModify tag is found need to add the contents of the child
+ * for the current node to the innerHTML of the context node.
+ */
+xap.xml.xmodify.CommandDirective.prototype._handleSetInnerHtml = function(node){
+ var targetNodes = this._commandTargets;
+ var elemsToAppend = this._commandArguments;
+ var uiDocument = this._session.getDocumentContainer().getUiDocument();
+
+ for (var i=0; i<targetNodes.length; i++) {
+ var parentElement = targetNodes[i] ;
+
+ for (var ii=0; ii<elemsToAppend.length;ii++){
+ if( elemsToAppend[ii].nodeType == google.DOM_TEXT_NODE && elemsToAppend[ii].nodeValue) {
+ parentElement.innerHTML = elemsToAppend[ii].nodeValue;
+ }
+ }
+ }
+}
+
+/**
* Format the supplied document into a pretty printed output string
* Used in debug statements only.
* @param document
@@ -977,6 +1021,7 @@
//return the new html node
return htmlNode;
}
+
//End of xap.xml.xmodify.CommandDirective
Modified: incubator/xap/trunk/src/xap/xml/xmodify/DirectiveSet.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/xmodify/DirectiveSet.js?view=diff&rev=470548&r1=470547&r2=470548
==============================================================================
--- incubator/xap/trunk/src/xap/xml/xmodify/DirectiveSet.js (original)
+++ incubator/xap/trunk/src/xap/xml/xmodify/DirectiveSet.js Thu Nov 2 14:13:43 2006
@@ -20,8 +20,8 @@
Xap.require("xap.xml.xmodify.CommandDirective");
-xap.xml.xmodify.DirectiveSet = function( modificationsElement ){
- this._directives = this._createDirectives(modificationsElement.childNodes);
+xap.xml.xmodify.DirectiveSet = function( modificationsElement, session){
+ this._directives = this._createDirectives(modificationsElement.childNodes, session);
}
xap.xml.xmodify.DirectiveSet.prototype.execute = function(uiDocument)
@@ -30,12 +30,12 @@
i < this._directives.length;
i++)
{ // Seems to want the root element here:
- this._directives[i].execute(uiDocument/*.getRootElement()*/);
+ this._directives[i].execute(uiDocument);
}
}
-xap.xml.xmodify.DirectiveSet.prototype._createDirectives = function(elemsDirectives)
+xap.xml.xmodify.DirectiveSet.prototype._createDirectives = function(elemsDirectives, session)
{
var dirs = new Array();
@@ -43,7 +43,7 @@
i < elemsDirectives.length;
i++)
{
- dirs[dirs.length] = new xap.xml.xmodify.CommandDirective (elemsDirectives[i]);
+ dirs[dirs.length] = new xap.xml.xmodify.CommandDirective (elemsDirectives[i], session);
} /* end for i */
Modified: incubator/xap/trunk/src/xap/xml/xmodify/UpdateDirective.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/xmodify/UpdateDirective.js?view=diff&rev=470548&r1=470547&r2=470548
==============================================================================
--- incubator/xap/trunk/src/xap/xml/xmodify/UpdateDirective.js (original)
+++ incubator/xap/trunk/src/xap/xml/xmodify/UpdateDirective.js Thu Nov 2 14:13:43 2006
@@ -16,11 +16,9 @@
*/
Xap.provide('xap.xml.xmodify.UpdateDirective');
-
Xap.require("xap.xml.xmodify.XmodifyException");
-
- /**
+/**
* Base class for XMLUpdate xap.xml.xmodify.CommandDirective.
*
* @version modeled after Java $Revision: 1.6 $
@@ -65,6 +63,11 @@
xap.xml.xmodify.UpdateDirective.DIRECTIVE_REMOVE_CHILD = 14;
xap.xml.xmodify.UpdateDirective.DIRECTIVE_REMOVE_CHILDREN = 15;
+/**
+ * Used only by HTML documents.
+ */
+xap.xml.xmodify.UpdateDirective.DIRECTIVE_EMBED_XAL = 16;
+xap.xml.xmodify.UpdateDirective.DIRECTIVE_SET_INNER_HTML = 17;
/**
* Used to do integer/string translation:
@@ -86,6 +89,12 @@
xap.xml.xmodify.UpdateDirective.DIRECTIVE_NAMES[xap.xml.xmodify.UpdateDirective.DIRECTIVE_CREATE_DOCUMENT] = "create-document" ;
xap.xml.xmodify.UpdateDirective.DIRECTIVE_NAMES[xap.xml.xmodify.UpdateDirective.DIRECTIVE_REMOVE_CHILD] = "remove-child" ;
xap.xml.xmodify.UpdateDirective.DIRECTIVE_NAMES[xap.xml.xmodify.UpdateDirective.DIRECTIVE_REMOVE_CHILDREN] = "remove-children" ;
+
+/**
+ * Used only by HTML documents.
+ */
+xap.xml.xmodify.UpdateDirective.DIRECTIVE_NAMES[xap.xml.xmodify.UpdateDirective.DIRECTIVE_EMBED_XAL] = "embed-xal" ;
+xap.xml.xmodify.UpdateDirective.DIRECTIVE_NAMES[xap.xml.xmodify.UpdateDirective.DIRECTIVE_SET_INNER_HTML] = "set-innerhtml" ;
//--------------------------------------------------------------------
// Package Protected Class Methods.
Modified: incubator/xap/trunk/src/xap/xml/xmodify/Xmodify.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/xmodify/Xmodify.js?view=diff&rev=470548&r1=470547&r2=470548
==============================================================================
--- incubator/xap/trunk/src/xap/xml/xmodify/Xmodify.js (original)
+++ incubator/xap/trunk/src/xap/xml/xmodify/Xmodify.js Thu Nov 2 14:13:43 2006
@@ -83,10 +83,11 @@
* @version Modeled after Java $Revision: 1.20 $
*/
-xap.xml.xmodify.Xmodify = function( modificationsElement )
+xap.xml.xmodify.Xmodify = function( modificationsElement, session)
{
this._modificationsElement = modificationsElement;
- this._directiveSet = new xap.xml.xmodify.DirectiveSet(modificationsElement);
+ this._session = session;
+ this._directiveSet = new xap.xml.xmodify.DirectiveSet(modificationsElement, session);
var checkThisOutOnDebugging = true ;
}
@@ -108,27 +109,25 @@
// Public Methods. (publc instance methods)
//-----------------------------------------------------------------------
-xap.xml.xmodify.Xmodify.prototype.execute = function (documentContainer)
-{
+xap.xml.xmodify.Xmodify.prototype.execute = function (){
/*
* Execute our commandsDoc on the UIDocument from the container
- */
+ */
var executionDocument = this._modificationsElement.getAttribute("document");
var uiDoc = null;
-
+
if (executionDocument == null || executionDocument == "xal"){
- uiDoc = documentContainer.getUiDocument();
+ uiDoc = this._session.getDocumentContainer().getUiDocument();
}else if (executionDocument == "html"){
uiDoc = document;
}
-
- /*
+
+ /*
* Start the machinery put into place on creation:
*/
this._directiveSet.execute(uiDoc);
xap.xml.xmodify.Xmodify.s_log.debug(uiDoc);
-
} /* end execute */
//-----------------------------------------------------------------------
Modified: incubator/xap/trunk/src/xap/xml/xmodify/XmodifyNamespaceHandler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/xmodify/XmodifyNamespaceHandler.js?view=diff&rev=470548&r1=470547&r2=470548
==============================================================================
--- incubator/xap/trunk/src/xap/xml/xmodify/XmodifyNamespaceHandler.js (original)
+++ incubator/xap/trunk/src/xap/xml/xmodify/XmodifyNamespaceHandler.js Thu Nov 2 14:13:43 2006
@@ -57,8 +57,8 @@
* @throws UpdateException
*/
xap.xml.xmodify.XmodifyNamespaceHandler.prototype.receiveDispatch = function( element ) {
- var xmodify = new xap.xml.xmodify.Xmodify( element );
- xmodify.execute( this._session.getDocumentContainer() );
+ var xmodify = new xap.xml.xmodify.Xmodify(element, this._session);
+ xmodify.execute();
}