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 2006/11/29 02:57:11 UTC
svn commit: r480355 - in /incubator/xap/trunk: src/xap/data/controller/
src/xap/xml/dom/ src/xap/xml/xmodify/ testsrc/xap/xml/ testsrc/xap/xmodify/
Author: jmargaris
Date: Tue Nov 28 18:57:11 2006
New Revision: 480355
URL: http://svn.apache.org/viewvc?view=rev&rev=480355
Log:
xmodify now supports replace-children
and fixed issue with clone node not doing what it was supposed
to, cloning auto-generated ids
Modified:
incubator/xap/trunk/src/xap/data/controller/Iterator.js
incubator/xap/trunk/src/xap/xml/dom/XapElement.js
incubator/xap/trunk/src/xap/xml/xmodify/CommandDirective.js
incubator/xap/trunk/src/xap/xml/xmodify/Xmodify.js
incubator/xap/trunk/testsrc/xap/xml/_TestElement.js
incubator/xap/trunk/testsrc/xap/xmodify/_TestxModify.html
incubator/xap/trunk/testsrc/xap/xmodify/xmodify.xal
Modified: incubator/xap/trunk/src/xap/data/controller/Iterator.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/controller/Iterator.js?view=diff&rev=480355&r1=480354&r2=480355
==============================================================================
--- incubator/xap/trunk/src/xap/data/controller/Iterator.js (original)
+++ incubator/xap/trunk/src/xap/data/controller/Iterator.js Tue Nov 28 18:57:11 2006
@@ -408,7 +408,7 @@
var location = null;
if (child instanceof xap.xml.dom.XapElement) {
/*Element*/
- var childClone = (child).deepClone(false);
+ var childClone = child.deepClone();
if (this._bindingType != xap.data.controller.BindingType.ONE_TIME) {
location = new xap.data.controller.ElementLocation(childClone);
this._iteratedLocations.addElement(location);
Modified: incubator/xap/trunk/src/xap/xml/dom/XapElement.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/dom/XapElement.js?view=diff&rev=480355&r1=480354&r2=480355
==============================================================================
--- incubator/xap/trunk/src/xap/xml/dom/XapElement.js (original)
+++ incubator/xap/trunk/src/xap/xml/dom/XapElement.js Tue Nov 28 18:57:11 2006
@@ -605,21 +605,21 @@
/**
* Creates a shallow clone of the element.
* @type xap.xml.dom.XapElement
- * @param withIds If true the clone will have the same ID as the original
- * element; auto-generated IDs are never cloned.
+ * @param withGeneratedIds If true the clone will have the same ID as the original
+ * element even if the original element's id was auto generated
*/
-xap.xml.dom.XapElement.prototype.clone = function ( withIds ) {
- return this._cloneHelper( false, withIds, null );
+xap.xml.dom.XapElement.prototype.clone = function ( withGeneratedIds ) {
+ return this._cloneHelper( false, withGeneratedIds );
}
/**
* Creates a deep clone of the element.
* @type xap.xml.dom.XapElement
- * @param withIds If true the clones will have the same IDs as the original
- * elements; auto-generated IDs are never cloned.
+ * @param withGeneratedIds If true the clone will have the same ID as the original
+ * element even if the original element's id was auto generated
*/
-xap.xml.dom.XapElement.prototype.deepClone = function( withIds ) {
- return this._cloneHelper( true, withIds, null );
+xap.xml.dom.XapElement.prototype.deepClone = function( withGeneratedIds ) {
+ return this._cloneHelper( true, withGeneratedIds);
}
//-----------------------------------------------------------------------
@@ -1113,7 +1113,7 @@
/**
* @private
*/
-xap.xml.dom.XapElement.prototype._cloneHelper = function( deep, withIds, parser ) {
+xap.xml.dom.XapElement.prototype._cloneHelper = function( deep, withGeneratedIds ) {
var e = new xap.xml.dom.XapElement( this.nodeName );
e._setNamespaceUri( this._namespaceUri );
@@ -1127,29 +1127,25 @@
e.baseUrl = this.baseUrl;
}
- if ( withIds == false ) {
+
+ if (withGeneratedIds){
+ //if specifically set to true do nothing, just copy over all ids whether
+ //they were generated or not
+ }
+ else {
var id = e.getAttribute( "id" );
- if ( xap.xml.dom.XapElement.isGeneratedId( id ) ) {
- // This is kind of weird. We are going to use this element's
- // unique ID generation, because in the case of cloning
- // elements for use in XUpdate we need a common scheme for
- // generating IDs between the client and the server. So when
- // Xupdate clones an element it will provide the parser that
- // originally parsed the XUpdate document, so that we can use
- // its logic to synchronize the ID generation between client
- // and server.
- if ( parser != null ) {
- e.setAttribute( "id", parser.getNextElementId() );
- } else {
- var doc = this.getOwnerDocument();
- e.setAttribute( "id", (doc == null ?
- xap.xml.dom.XapElement._createUniqueElementId() :
- ( doc._getUidProvider() == null ?
- xap.xml.dom.XapElement._createUniqueElementId() :
- doc._getUidProvider().nextId() ) ));
- }
- }
- }
+
+ //if the id was generated replace it with a new generated one
+ if ( xap.xml.dom.XapElement.isGeneratedId( id ) ) {
+
+ var doc = this.getOwnerDocument();
+ e.setAttribute( "id", (doc == null ?
+ xap.xml.dom.XapElement._createUniqueElementId() :
+ ( doc._getUidProvider() == null ?
+ xap.xml.dom.XapElement._createUniqueElementId() :
+ doc._getUidProvider().nextId() ) ));
+ }
+ }
if ( deep == false ) {
return e;
@@ -1158,7 +1154,7 @@
for ( var i = 0; i < this.childNodes.length; i++ ) {
var o = this.childNodes[i];
if (o.nodeType==google.DOM_ELEMENT_NODE){
- var childCopy = o._cloneHelper( deep, withIds, parser );
+ var childCopy = o._cloneHelper( deep, withGeneratedIds );
e.appendChild( childCopy );
}
else if (o.nodeType==google.DOM_TEXT_NODE){
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=480355&r1=480354&r2=480355
==============================================================================
--- incubator/xap/trunk/src/xap/xml/xmodify/CommandDirective.js (original)
+++ incubator/xap/trunk/src/xap/xml/xmodify/CommandDirective.js Tue Nov 28 18:57:11 2006
@@ -134,6 +134,9 @@
case xap.xml.xmodify.UpdateDirective.DIRECTIVE_REMOVE_CHILDREN:
this._handleRemoveChildren(uiDocumentNode);
break;
+ case xap.xml.xmodify.UpdateDirective.DIRECTIVE_REPLACE_CHILDREN:
+ this._handleReplaceChildren(uiDocumentNode);
+ break;
case xap.xml.xmodify.UpdateDirective.DIRECTIVE_CLONE:
this._handleClone(uiDocumentNode);
break;
@@ -252,7 +255,7 @@
for (var j = 0; j < elemsToAppend.length; j++){
try {
if (currentNode instanceof google.XNode){
- currentNode.appendChild(elemsToAppend[j].deepClone(true));
+ currentNode.appendChild(elemsToAppend[j].deepClone());
} else if (this._bHtmlDocument){
currentNode.appendChild(this.makeNodeHTML(elemsToAppend[j]));
}
@@ -339,6 +342,36 @@
+xap.xml.xmodify.CommandDirective.prototype._handleReplaceChildren = function(uiDocumentNode){
+ var targetNodes = this._commandTargets ;
+ var elemsToAppend = this._commandArguments;
+
+ //IMPORTANT if we get an exception what is the right granularity to continue??
+ for (var i=0; i<targetNodes.length; i++){
+ var elem = targetNodes[i];
+
+ //if it is not an element you can't replace the children
+ //technically document could allow this too...
+ if (elem.nodeType!=google.DOM_ELEMENT_NODE){
+ continue;
+ }
+
+ //remove each child
+ while(elem.childNodes.length>0){
+ elem.removeChild(elem.childNodes[0]);
+ }
+
+ //then stick on the new ones
+ for (var j = 0; j < elemsToAppend.length; j++){
+ if (elem instanceof google.XNode){
+ elem.appendChild(elemsToAppend[j].deepClone());
+ } else if (this._bHtmlDocument){
+ elem.appendChild(this.makeNodeHTML(elemsToAppend[j]));
+ }
+ }
+ }
+}
+
/**
* Removes the nodes held in <code>this._commandArguments</code> (and
* their subtrees, if any).
@@ -717,13 +750,13 @@
var nextOldChild = oldChild.nextSibling ;
if (true||nextOldChild != null){
parent.insertBefore(
- newChild.deepClone(true),
+ newChild.deepClone(),
nextOldChild
);
} else {
// If there is no next sibling before which to insert,
// we can just append it to the end of the child list:
- parent.appendChild(newChild.deepClone(true));
+ parent.appendChild(newChild.deepClone());
}
} else if (this._bHtmlDocument){
var nextOldChild = oldChild.nextSibling ;
@@ -759,7 +792,7 @@
// Just try it for XNode and descendants so far:
if (oldChild instanceof google.XNode){
parent.insertBefore(
- newChild.deepClone(true),
+ newChild.deepClone(),
oldChild
);
} else if (this._bHtmlDocument){
@@ -845,7 +878,7 @@
) ;
try {
parent.insertBefore(
- newChild.deepClone(true),
+ newChild.deepClone(),
oldChild
);
} catch (insertionException){
@@ -919,7 +952,7 @@
for (var ll=0; ll<this._commandTargets.length; ++ll) {
var toClone = this._commandTargets[ll] ;
if (toClone.nodeType == google.DOM_ELEMENT_NODE) {
- var cloned = toClone.deepClone(true) ;
+ var cloned = toClone.deepClone() ;
this._clones[ll] = clone ;
} else {
throw new xap.xml.xmodify.XmodifyException(
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=480355&r1=480354&r2=480355
==============================================================================
--- incubator/xap/trunk/src/xap/xml/xmodify/Xmodify.js (original)
+++ incubator/xap/trunk/src/xap/xml/xmodify/Xmodify.js Tue Nov 28 18:57:11 2006
@@ -116,7 +116,7 @@
var executionDocument = this._modificationsElement.getAttribute("document");
var uiDoc = null;
- if (executionDocument == null || executionDocument == "xal"){
+ if (executionDocument == null || executionDocument == "ui"){
uiDoc = this._session.getDocumentContainer().getUiDocument();
}else if (executionDocument == "html"){
uiDoc = document;
Modified: incubator/xap/trunk/testsrc/xap/xml/_TestElement.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/xml/_TestElement.js?view=diff&rev=480355&r1=480354&r2=480355
==============================================================================
--- incubator/xap/trunk/testsrc/xap/xml/_TestElement.js (original)
+++ incubator/xap/trunk/testsrc/xap/xml/_TestElement.js Tue Nov 28 18:57:11 2006
@@ -101,8 +101,6 @@
el.setAttribute("id","myPanel");
//TODO this needs to be a lot better
- var c = el.deepClone( false );
-
- var d = el.deepClone( true );
- assertTrue("clone with IDs", d.getAttribute("id") == "myPanel");
+ var d = el.deepClone();
+ assertTrue("clone an assigned ID", d.getAttribute("id") == "myPanel");
}
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=480355&r1=480354&r2=480355
==============================================================================
--- incubator/xap/trunk/testsrc/xap/xmodify/_TestxModify.html (original)
+++ incubator/xap/trunk/testsrc/xap/xmodify/_TestxModify.html Tue Nov 28 18:57:11 2006
@@ -145,6 +145,21 @@
}
+function testReplaceChildren(){
+ var panel1 = uiDoc.getElementById("panel1");
+ var panel2 = uiDoc.getElementById("panel2");
+
+ assertTrue("Panel1 has 2 children", panel1.childNodes.length==2);
+ assertTrue("Panel2 has 2 children", panel2.childNodes.length==2);
+
+ assertTrue("Panel1 child1 is a label", panel1.childNodes[0].nodeName=="label");
+ assertTrue("Panel1 child2 is a checkbox", panel1.childNodes[1].nodeName=="checkBox");
+ assertTrue("Panel2 child1 is a label", panel2.childNodes[0].nodeName=="label");
+ assertTrue("Panel2 child2 is a checkbox", panel2.childNodes[1].nodeName=="checkBox");
+
+ assertTrue("Panels have different children", panel1.childNodes[0]!=panel2.childNodes[0]);
+}
+
</script>
</body>
</html>
Modified: incubator/xap/trunk/testsrc/xap/xmodify/xmodify.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/xmodify/xmodify.xal?view=diff&rev=480355&r1=480354&r2=480355
==============================================================================
--- incubator/xap/trunk/testsrc/xap/xmodify/xmodify.xal (original)
+++ incubator/xap/trunk/testsrc/xap/xmodify/xmodify.xal Tue Nov 28 18:57:11 2006
@@ -50,5 +50,20 @@
y="100px"/>
</xm:append>
<xm:remove-children select="/xal/button[@id='button2']"/>
+
+ <!-- test replace children -->
+ <xm:append select="/xal">
+ <panel id="panel1">
+ <button text="A button"/>
+ </panel>
+ <panel id="panel2">
+ <button text="A button"/>
+ </panel>
+ </xm:append>
+ <xm:replace-children select="/xal/panel">
+ <label/>
+ <checkBox/>
+ </xm:replace-children>
+
</xm:modifications>
</xal>