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 2007/01/05 02:20:07 UTC
svn commit: r492852 - in /incubator/xap/trunk:
WebContent/examples/dataBinding/ WebContent/examples/widgets/
src/xap/bridges/basic/ src/xap/bridges/google/ src/xap/bridges/yahoo/
src/xap/data/controller/ src/xap/xml/dom/ testsrc/xap/xml/
Author: jmargaris
Date: Thu Jan 4 18:20:06 2007
New Revision: 492852
URL: http://svn.apache.org/viewvc?view=rev&rev=492852
Log:
getOwnerDocument removed in favor of ownerDocument, way ownerDocument
is tracked cleaned up, other cleanup in XML DOM.
Modified:
incubator/xap/trunk/WebContent/examples/dataBinding/mcoAttribute.xal
incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js
incubator/xap/trunk/src/xap/bridges/basic/XInclude.js
incubator/xap/trunk/src/xap/bridges/google/GoogleMarkerBridge.js
incubator/xap/trunk/src/xap/bridges/yahoo/YahooMarkerBridge.js
incubator/xap/trunk/src/xap/data/controller/Iterator.js
incubator/xap/trunk/src/xap/xml/dom/Document.js
incubator/xap/trunk/src/xap/xml/dom/XapElement.js
incubator/xap/trunk/testsrc/xap/xml/_TestDocument.js
incubator/xap/trunk/testsrc/xap/xml/_TestElement.js
Modified: incubator/xap/trunk/WebContent/examples/dataBinding/mcoAttribute.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/dataBinding/mcoAttribute.xal?view=diff&rev=492852&r1=492851&r2=492852
==============================================================================
--- incubator/xap/trunk/WebContent/examples/dataBinding/mcoAttribute.xal (original)
+++ incubator/xap/trunk/WebContent/examples/dataBinding/mcoAttribute.xal Thu Jan 4 18:20:06 2007
@@ -208,7 +208,7 @@
id="testComponent_8"
/>
- </freePane>
+ </xal:freePane>
</xm:append>
</xm:modifications>
</xal>
Modified: incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js?view=diff&rev=492852&r1=492851&r2=492852
==============================================================================
--- incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js (original)
+++ incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js Thu Jan 4 18:20:06 2007
@@ -115,7 +115,7 @@
//no error. Because we still found element in hashtable?
AttributeTester.prototype.insertBefore = function( element ){
alert("insert before");
- var newElement = element.getOwnerDocument().createElement("freePane","http://openxal.org/ui");
+ var newElement = element.ownerDocument.createElement("freePane","http://openxal.org/ui");
newElement.setAttribute("backgroundColor","yellow");
newElement.setAttribute("width","30px");
newElement.setAttribute("height","30px");
@@ -135,7 +135,7 @@
AttributeTester.prototype.addBorderComponent = function( parent, borderPosition ){
alert("add border component");
- var newElement = parent.getOwnerDocument().createElement("freePane","http://openxal.org/ui");
+ var newElement = parent.ownerDocument.createElement("freePane","http://openxal.org/ui");
newElement.setAttribute("backgroundColor","yellow");
newElement.setAttribute("borderPosition", borderPosition);
newElement.setAttribute("width","30px");
@@ -149,7 +149,7 @@
AttributeTester.newOptionItemCount=-1;
AttributeTester.prototype.appendListItem = function(element,selectedP) {
alert("append");
- var newElement = element.getOwnerDocument().createElement("listItem", "http://openxal.org/ui");
+ var newElement = element.ownerDocument.createElement("listItem", "http://openxal.org/ui");
var caption="originally " ;
caption += ((selectedP)?"selected.":"not selected.") ;
newElement.setAttribute("text", ""+(++AttributeTester.newOptionItemCount)+": new text, " + caption);
Modified: incubator/xap/trunk/src/xap/bridges/basic/XInclude.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/basic/XInclude.js?view=diff&rev=492852&r1=492851&r2=492852
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/basic/XInclude.js (original)
+++ incubator/xap/trunk/src/xap/bridges/basic/XInclude.js Thu Jan 4 18:20:06 2007
@@ -70,7 +70,7 @@
var newChild = null;
if ("text"==parseType){
- newChild = thisElement.getOwnerDocument().createTextNode(text);
+ newChild = thisElement.ownerDocument.createTextNode(text);
}
else{
var parser = xap.xml.ParserFactory.getParser();
Modified: incubator/xap/trunk/src/xap/bridges/google/GoogleMarkerBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/google/GoogleMarkerBridge.js?view=diff&rev=492852&r1=492851&r2=492852
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/google/GoogleMarkerBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/google/GoogleMarkerBridge.js Thu Jan 4 18:20:06 2007
@@ -78,7 +78,7 @@
//use the default icon.
var marker = null;
if (icon!=null&&icon!=""){
- var iconElement = this.getElement().getOwnerDocument().getElementById(icon);
+ var iconElement = this.getElement().ownerDocument.getElementById(icon);
if (iconElement!=null){
var iconHandler = this.getUiContentHandler().getHandlerForElement( iconElement );
marker = new GMarker(point, iconHandler.getPeer());
Modified: incubator/xap/trunk/src/xap/bridges/yahoo/YahooMarkerBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/yahoo/YahooMarkerBridge.js?view=diff&rev=492852&r1=492851&r2=492852
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/yahoo/YahooMarkerBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/yahoo/YahooMarkerBridge.js Thu Jan 4 18:20:06 2007
@@ -78,7 +78,7 @@
//use the default icon.
var marker = null;
if (icon!=null&&icon!=""){
- var iconElement = this.getElement().getOwnerDocument().getElementById(icon);
+ var iconElement = this.getElement().ownerDocument.getElementById(icon);
if (iconElement!=null){
var iconHandler = this.getUiContentHandler().getHandlerForElement( iconElement );
marker = new YMarker(point, iconHandler.getPeer(), this.getElement().getAttribute("id"));
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=492852&r1=492851&r2=492852
==============================================================================
--- incubator/xap/trunk/src/xap/data/controller/Iterator.js (original)
+++ incubator/xap/trunk/src/xap/data/controller/Iterator.js Thu Jan 4 18:20:06 2007
@@ -55,7 +55,7 @@
this._select = select;
this._bindingType = type;
this._iteratorElement = iteratorElement;
- this._iteratorPlaceHolderElement = iteratorElement.getOwnerDocument().createElement("iteratorPlaceHolder");
+ this._iteratorPlaceHolderElement = iteratorElement.ownerDocument.createElement("iteratorPlaceHolder");
this._parentElement = iteratorElement.getParent();
this._parentLocation = new xap.data.controller.ElementLocation(iteratorElement.getParent());
this._parentLocation.setLocationListener(this);
Modified: incubator/xap/trunk/src/xap/xml/dom/Document.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/dom/Document.js?view=diff&rev=492852&r1=492851&r2=492852
==============================================================================
--- incubator/xap/trunk/src/xap/xml/dom/Document.js (original)
+++ incubator/xap/trunk/src/xap/xml/dom/Document.js Thu Jan 4 18:20:06 2007
@@ -65,7 +65,6 @@
xap.xml.dom.Document = function( rootElement ) {
google.XDocument.call(this);
this._rootElement = rootElement;
- this._documentEncoding = null;
this._structureChangeListeners = [];
this._attributeChangeListeners = [];
@@ -82,29 +81,19 @@
// Constants.
//-----------------------------------------------------------------------
-/**
- * @private
- */
+/** @private */
xap.xml.dom.Document.XML_DECL_WITHOUT_ENC = "<?xml version=\"1.0\"?>";
-/**
- * @private
- */
+/** @private */
xap.xml.dom.Document.BEFORE_ADD = 0;
-/**
- * @private
- */
+/** @private */
xap.xml.dom.Document.BEFORE_REMOVE = 1;
-/**
- * @private
- */
+/** @private */
xap.xml.dom.Document.ON_ADD = 2;
-/**
- * @private
- */
+/** @private */
xap.xml.dom.Document.ON_REMOVE = 3;
@@ -119,11 +108,14 @@
* @param ns The namespace of the new node
*/
xap.xml.dom.Document.prototype.createElement = function(localName, ns, prefix) {
- if( localName == null ) {
+ if( !localName ) {
throw new xap.xml.InvalidXmlException(
xap.xml.InvalidXmlException.NULL_LOCALNAME_MSGID,
new Array( "xap.xml.dom.Document.createElement" ));
}
+
+ //note we are passing in NO owner doc here! only is set when node actually
+ //becomes part of the document
var e = new xap.xml.dom.XapElement(localName, null, null, null,this._uidProvider );
//if there is no namespace then create it with a blank one
@@ -140,12 +132,6 @@
return this._rootElement;
}
-/**
- * @return The encoding of this xap.xml.dom.Document
- */
-xap.xml.dom.Document.prototype.getEncoding = function() {
- return this._documentEncoding;
-}
/**
* Adds an xap.xml.dom.events.AttributeChangeListener to this xap.xml.dom.Document
@@ -199,7 +185,7 @@
//TODO waht about appendChild and remove child()? we need to
//override those too?
- if ( root == null && this._rootElement == null ) {
+ if ( !root && !this._rootElement ) {
// If the old root was null and the new root is null then we're
// already in the desired state, don't fire any events, just
// return.
@@ -209,7 +195,7 @@
// remove the current root element from this xap.xml.dom.Document.
this._removeExistingRoot();
- if ( root != null ) {
+ if ( root) {
var event = new xap.xml.dom.events.StructureChangeEvent( null, root );
@@ -224,20 +210,19 @@
this._rootElement = event.getChange();
- if ( this._rootElement.getParent() != null ) {
+ if ( this._rootElement.getParent() ) {
// remove the to-be root from its current parent and owner
// document.
this._rootElement.getParent().removeChild( this._rootElement );
}
- else if ( this._rootElement.getOwnerDocument() != null &&
- this._rootElement.getOwnerDocument().getRootElement() == this._rootElement ) {
+ else if ( this._rootElement.ownerDocument &&
+ this._rootElement.ownerDocument.getRootElement() == this._rootElement ) {
// Another possibility is that the to-be root is the
// root element of another document. Make sure that
// the other document is correctly maintained.
- this._rootElement.getOwnerDocument().setRootElement( null );
+ this._rootElement.ownerDocument.setRootElement( null );
}
- this._rootElement._setOwnerDocument( this );
//this should handle the xdocument hookup
this.appendChild(this._rootElement);
@@ -296,36 +281,12 @@
-/**
- * Returns the prefix associated with the specified namespace.
- * This method is used by the studio, be careful to consult them
- * if modifying its behavior. If the namespace is not currently
- * associated with a prefix, this method returns null.
- *
- * @param namespace The namespace for which a prefix is desired.
- * @private
- */
-xap.xml.dom.Document.prototype._getPrefixForNamespace = function ( namespace ) {
- if ( this._prefixToNamespaceMap == null ) {
- return null;
- }
- var prefix = null;
- for( var key in this._prefixToNamespaceMap ) {
- var nspc = this._prefixToNamespaceMap[key];
- if ( nspc == namespace ) {
- prefix = key;
- if( prefix != null ) {
- return prefix;
- }
- }
- }
- return prefix;
-}
/**
* @private
*/
xap.xml.dom.Document.prototype._addDocumentFragmentToIdMapAndCheckForPrefixCollisions = function( e ) {
+ e.ownerDocument = this;
this._addIdToElementMapping( e.getAttribute( "id" ), e );
this._checkPrefixForCollisionAndRegister( e );
e._notifyListenersOnAddedToDocument( this );
@@ -341,6 +302,7 @@
* @private
*/
xap.xml.dom.Document.prototype._removeDocumentFragmentFromIdMap = function( e ) {
+ delete e.ownerDocument;
delete (this._idToElementMap[e.getAttribute( "id" )]);
e._notifyListenersOnRemovedFromDocument( this );
for( var i=0; i < e.childNodes.length; i++ ) {
@@ -350,53 +312,18 @@
}
}
}
-
-/**
- * Returns the namespace associated with the given prefix. If no namespace
- * exists for that prefix, null is returned.
- *
- * @param prefix The prefix to look up.
- * @return The namespace associated with the supplied prefix.
- * @private
- */
-xap.xml.dom.Document.prototype._getNamespaceForPrefix = function( prefix ) {
- if( this._prefixToNamespaceMap == null) {
- return null;
- }
- return this._prefixToNamespaceMap[prefix];
-}
-
-/**
- * This method will register the supplied prefix/namespace pair. If the
- * prefix is already registered with a different namespace value, an
- * Exception is thrown.
- *
- * @param prefix The prefix to register
- * @param ns The namespace to register for the prefix
- * @throws Exception if the prefix supplied is already
- * registered with a different namespace.
- * @private
- */
-xap.xml.dom.Document.prototype._registerPrefix = function( prefix, ns ) {
- if( this._prefixToNamespaceMap == null ) {
- this._prefixToNamespaceMap = new Object();
- }
- this._prefixToNamespaceMap[prefix] = ns;
-}
-
/**
* @private
*/
xap.xml.dom.Document.prototype._removeExistingRoot = function() {
- if ( this._rootElement != null ) {
+ if ( this._rootElement ) {
var event = new xap.xml.dom.events.StructureChangeEvent( null, this._rootElement );
this._notifyListenersOfStructureChange
( this._structureChangeListeners, event, xap.xml.dom.Document.BEFORE_REMOVE );
- this._rootElement._setOwnerDocument( null );
this.removeChild(this._rootElement);
this._removeDocumentFragmentFromIdMap( this._rootElement );
@@ -410,7 +337,7 @@
* @private
*/
xap.xml.dom.Document.prototype._notifyListenersOfStructureChange = function( v, e, type ) {
- if ( v != null ) {
+ if ( v ) {
for ( var i = 0; i < v.length; i ++ ) {
var listener = v[i];
switch ( type ) {
@@ -452,13 +379,10 @@
* @private
*/
xap.xml.dom.Document.prototype._checkPrefixForCollisionAndRegister = function( e ) {
- if( e.getPrefix() == null ) {
+ if( !e.getPrefix()) {
return;
}
- if( this._prefixToNamespaceMap == null ) {
- this._prefixToNamespaceMap = new Object();
- }
- if( this._prefixToNamespaceMap[e.getPrefix()] != null ) {
+ if( this._prefixToNamespaceMap[e.getPrefix()]) {
var currentNs = this._prefixToNamespaceMap[e.getPrefix()];
var newNs = e.getNamespaceUri();
if( currentNs != newNs ) {
@@ -479,7 +403,7 @@
*/
xap.xml.dom.Document.prototype._toStringHelper = function( prettyPrint, withInternalIds ) {
var elementOutput = "";
- if( this._rootElement != null ) {
+ if( this._rootElement ) {
if( withInternalIds ) {
elementOutput = this._rootElement.toXml( prettyPrint );
} else {
@@ -487,16 +411,7 @@
this._rootElement.toXmlWithoutAutoAssignedIds( prettyPrint );
}
}
- var sbuf = "";
- // calculate initial length of string buffer (since total size is
- // already known). And append the xml decl to it.
- if( this._documentEncoding == null ) {
- sbuf += xap.xml.dom.Document.XML_DECL_WITHOUT_ENC;
- } else {
- sbuf += "<?xml version=\"1.0\" encoding=\"" + this._documentEncoding +
- "\"?>";
- }
-
+ var sbuf = xap.xml.dom.Document.XML_DECL_WITHOUT_ENC;
if( prettyPrint ) {
sbuf += "\n";
}
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=492852&r1=492851&r2=492852
==============================================================================
--- incubator/xap/trunk/src/xap/xml/dom/XapElement.js (original)
+++ incubator/xap/trunk/src/xap/xml/dom/XapElement.js Thu Jan 4 18:20:06 2007
@@ -61,19 +61,18 @@
// This array is an alternating list of listner object and the listener
// class it was added as.
- this._documentOwnershipListeners = null;
- this._attributeChangeListeners = null;
- this._structureChangeListeners = null;
+ this._documentOwnershipListeners = [];
+ this._attributeChangeListeners = [];
+ this._structureChangeListeners = [];
- this._ownerDocument = ownerDoc;
-
- if ( id != null ) {
- this.setAttribute( "id", id );
+ if ( id ) {
+ this.setAttribute( "id", id );
}
- else if ( uidProvider != null ) {
+ else if ( uidProvider ) {
this.setAttribute( "id", uidProvider.nextId() );
}
}
+
xap.xml.dom.XapElement.prototype = new google.XNode();
// Venkman gets class string from here:
@@ -152,8 +151,7 @@
* an end-use assigned one.
*/
xap.xml.dom.XapElement.isGeneratedId = function( id ) {
- return ( id != null &&
- id.indexOf( xap.util.UidProvider.XAP_ID_PREFIX, 0 ) != -1 );
+ return ( id && id.indexOf( xap.util.UidProvider.XAP_ID_PREFIX, 0 ) != -1 );
}
@@ -224,11 +222,14 @@
*/
xap.xml.dom.XapElement.prototype.setAttribute = function(name, value, baseUrl){
- var doc = this.getOwnerDocument();
+ //NOTE this is tricky because NULL values are not ok but "" is ok...
+ //TODO clean this up and check for NULL/UNDEF better
+
+ var doc = this.ownerDocument;
//flag that indicates if we are setting the id att
if( "id" == name ) {
- if ( doc != null ) {
+ if ( doc ) {
throw new xap.util.Exception
( xap.util.ResourceDictionary.getMessage
( xap.xml.dom.XapElement.CANNOT_SET_ID_ATTRIBUTE_WHEN_PART_OF_DOCUMENT,
@@ -268,8 +269,8 @@
* @param {String} name The name of the attribute to remove.
*/
xap.xml.dom.XapElement.prototype.removeAttribute = function(name) {
- var doc = this.getOwnerDocument();
- if (doc!=null && name=="id"){
+ var doc = this.ownerDocument;
+ if (doc && name=="id"){
throw "Can't change ID of element already in document";
}
@@ -288,8 +289,7 @@
//the document type or something like that? Maybe when we add to a doc
//that expects IDs we should assign them then instead of here?
if ( "id" == name ) {
- setAttribute( "id", ( doc == null ? this._createUniqueElementId() :
- doc._getUidProvider().nextId() ) );
+ setAttribute( "id", ( doc ? doc._getUidProvider().nextId() : this._createUniqueElementId()));
}
return name;
@@ -352,14 +352,10 @@
* @param {google.XNode} child The child text or element node to remove.
*/
xap.xml.dom.XapElement.prototype.removeChild = function(child){
- if ( this.childNodes == null ) {
- return null;
- }
-
var index = 0; //TODO fill in correctly
//TODO what if o is not a child?
- if(child == null){
+ if(!child){
// throw new xap.util.Exception
// ( xap.util.ResourceDictionary.getMessage
// ( CANNOT_REMOVE_NULL_CHILD, ElementImpl.class ) );
@@ -371,7 +367,7 @@
return null;
}
- var doc = this.getOwnerDocument();
+ var doc = this.ownerDocument;
var structureChangeListenerExists = this._doAnyStructureChangeListenersExist( doc );
var event = null;
@@ -388,10 +384,9 @@
//if we are removing an element node we have to remove it from
//our ID map and clean up owner doc stuff
if (child.nodeType==google.DOM_ELEMENT_NODE){
- if ( doc != null ) {
+ if ( doc ) {
doc._removeDocumentFragmentFromIdMap( child );
}
- child._ownerDocument = null;
}
//notify listeners on attribute change
@@ -402,25 +397,6 @@
//TODO child here could be changed by the before event?
return child;
}
-
-
-/**
- * Returns the owner document. We should probably defeature
- * this at some point or unify it with the XNode impl.
- */
-xap.xml.dom.XapElement.prototype.getOwnerDocument = function() {
- if ( this._ownerDocument == null ) {
- if ( this.getParent() == null ) {
- return null;
- }
-
- if (this.getParent().getOwnerDocument){
- return this.getParent().getOwnerDocument();
- }
- }
- return this._ownerDocument;
-}
-
/**
*
* For compatibility with existing code we don't consider
@@ -650,7 +626,7 @@
}
- var doc = this.getOwnerDocument();
+ var doc = this.ownerDocument;
var structureChangeListenersExist = this._doAnyStructureChangeListenersExist( doc );
var event = null;
@@ -661,7 +637,7 @@
// added, so make sure that what we add is the subtree on the
// event, not the element passed to this method.
newNode = event.getChange();
- if ( newNode == null ) {
+ if ( !newNode ) {
throw new xap.xml.dom.events.ChangeRejectedException
( xap.xml.dom.events.ChangeRejectedException.CHANGE_CHILD_TO_NULL_MSGID,
null, null, event );
@@ -675,17 +651,17 @@
// on the element (the element belongs to a document) that it
// is removed from that document prior to being added to this
// document.
- if ( newNode._ownerDocument != null ) {
+ if ( newNode.ownerDocument ) {
// if this is the root element of the document
// remove it from the document(since it no longer belongs there)
- if ( newNode._ownerDocument.getRootElement() == newNode ) {
- newNode._ownerDocument.setRootElement( null );
+ if ( newNode.ownerDocument.getRootElement() == newNode ) {
+ newNode.ownerDocument.setRootElement( null );
}
- newNode._ownerDocument = null;
+ delete newNode.ownerDocument;
}
- if ( doc != null ) {
+ if ( doc ) {
// this call does a deep traversal of the element being
// inserted and checks for ID conflicts with existing elements
// in the document and checkes to make sure there are no
@@ -711,19 +687,6 @@
return newNode;
}
-/**
- * A simple accessor for the owner document.
- *
- * @private
- *
- * @param doc the owner document.
- */
-xap.xml.dom.XapElement.prototype._setOwnerDocument = function( doc ) {
- this._ownerDocument = doc;
-}
-
-
-
/**
* A simple accessor for the namespace URI.
@@ -796,25 +759,16 @@
/** @private */
xap.xml.dom.XapElement.prototype._getAttributeChangeListeners = function() {
- if( this._attributeChangeListeners == null ) {
- this._attributeChangeListeners = new Array();
- }
return this._attributeChangeListeners;
}
/** @private */
xap.xml.dom.XapElement.prototype._getStructureChangeListeners = function() {
- if( this._structureChangeListeners == null ) {
- this._structureChangeListeners = new Array();
- }
return this._structureChangeListeners;
}
/** @private */
xap.xml.dom.XapElement.prototype._getDocumentOwnershipListeners = function() {
- if( this._documentOwnershipListeners == null ) {
- this._documentOwnershipListeners = new Array();
- }
return this._documentOwnershipListeners;
}
@@ -839,7 +793,7 @@
// if its a string, simply print it XML-encoded
sbuf += xap.util.XmlUtils.encode( node.nodeValue );
} else {
- if ( prettyPrint && node.getParent() != null ) {
+ if ( prettyPrint && node.getParent() ) {
var index = xap.util.ArrayHelper.indexOf(node.getParent().childNodes, node );
if ( index == -1 ) { // NOPMD
// I added this because the if clause below throws
@@ -856,7 +810,7 @@
}
sbuf += '<'; // print START_TAG
- if( node.getPrefix() != null ) {
+ if( node.getPrefix() ) {
// if the element has a prefix print that before the tag name
sbuf += node.getPrefix() + ':';
}
@@ -866,8 +820,8 @@
// on this element. This is to handle the case where the namespace
// is inherited, it should not be printed on every child element
var printNamespaceAtt = false;
- if( node.getNamespaceUri() != null ) {
- if( node.getParent() != null ) {
+ if( node.getNamespaceUri() != null ) { //"" namespace URI is ok!
+ if( node.getParent() ) {
var myNS = node.getNamespaceUri();
var parentNS = node.getParent().getNamespaceUri();
@@ -890,10 +844,11 @@
if( printNamespaceAtt == true ){
sbuf += " ";
// determine correct namespace attribute to use
- if( node.getPrefix() == null ) {
- sbuf += "xmlns";
- } else {
+ if( node.getPrefix() ) {
sbuf += "xmlns:" + node.getPrefix();
+
+ } else {
+ sbuf += "xmlns";
}
sbuf += "=\"" + xap.util.XmlUtils.encode(node.getNamespaceUri()) + "\"";
}
@@ -956,7 +911,7 @@
}
sbuf += "</";
- if( node.getPrefix() != null ) {
+ if( node.getPrefix() ) {
sbuf += node.getPrefix() + ':';
}
sbuf += node.getLocalName() + '>';
@@ -1024,28 +979,15 @@
* @private
*/
xap.xml.dom.XapElement.prototype._doAnyAttributeChangeListenersExist = function( doc ) {
- var normalListeners = null;
- if ( doc != null ) {
- normalListeners = doc._attributeChangeListeners;
- }
-
- var thisElementsAttributeListeners = this._getAttributeChangeListeners() ;
-
- return (thisElementsAttributeListeners != null
- && thisElementsAttributeListeners.length > 0
- ) ||
- ( normalListeners != null && normalListeners.length > 0 );
+ return ( (doc && doc._attributeChangeListeners.length>0) ||
+ (this._getAttributeChangeListeners().length > 0 ));
+
}
/** @private */
xap.xml.dom.XapElement.prototype._doAnyStructureChangeListenersExist = function( doc ) {
- var normalListeners = null;
- if ( doc != null ) {
- normalListeners = doc._structureChangeListeners;
- }
-
- return this._getStructureChangeListeners().length > 0 ||
- ( normalListeners != null && normalListeners.length > 0 );
+ return ( (doc && doc._structureChangeListeners.length>0) ||
+ (this._getStructureChangeListeners().length > 0 ));
}
@@ -1054,9 +996,6 @@
* @return {int}
*/
xap.xml.dom.XapElement.prototype.indexOfChild = function(aChild) {
- if(this.childNodes == null){
- return -1;
- }
return xap.util.ArrayHelper.indexOf(this.childNodes, aChild);
}
/**
@@ -1064,9 +1003,6 @@
* @return {int}
*/
xap.xml.dom.XapElement.prototype.getChildCount = function() {
- if(this.childNodes == null){
- return 0;
- }
return this.childNodes.length ;
}
@@ -1138,12 +1074,13 @@
//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() ) ));
+ var doc = this.ownerDocument;
+ if (doc && doc._getUidProvider()){
+ e.setAttribute( "id", doc._getUidProvider().nextId());
+ }
+ else{
+ e.setAttribute( "id", xap.xml.dom.XapElement._createUniqueElementId());
+ }
}
}
@@ -1172,7 +1109,7 @@
* @private
*/
xap.xml.dom.XapElement.prototype._encodeEverythingButSingleTicks = function( s ) {
- if ( s == null ) { return ""; }
+ if ( !s ) { return ""; }
var buffer = new Array( s.length );
var c;
for ( var i = 0; i < s.length; i++ ) {
Modified: incubator/xap/trunk/testsrc/xap/xml/_TestDocument.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/xml/_TestDocument.js?view=diff&rev=492852&r1=492851&r2=492852
==============================================================================
--- incubator/xap/trunk/testsrc/xap/xml/_TestDocument.js (original)
+++ incubator/xap/trunk/testsrc/xap/xml/_TestDocument.js Thu Jan 4 18:20:06 2007
@@ -41,12 +41,9 @@
assertTrue( "doc._checkPrefixForCollisionAndRegister", doc._checkPrefixForCollisionAndRegister != null );
assertTrue( "doc.createElement", doc.createElement != null );
assertTrue( "doc.getElementById", doc.getElementById != null );
- assertTrue( "doc._getNamespaceForPrefix", doc._getNamespaceForPrefix != null );
- assertTrue( "doc", doc._getPrefixForNamespace != null );
assertTrue( "doc.getRootElement", doc.getRootElement != null );
assertTrue( "doc._getUidProvider", doc._getUidProvider != null );
assertTrue( "doc._notifyListenersOfStructureChange", doc._notifyListenersOfStructureChange != null );
- assertTrue( "doc._registerPrefix", doc._registerPrefix != null );
assertTrue( "doc.removeAttributeChangeListener", doc.removeAttributeChangeListener != null );
assertTrue( "doc._removeDocumentFragmentFromIdMap", doc._removeDocumentFragmentFromIdMap != null );
assertTrue( "doc._removeExistingRoot", doc._removeExistingRoot != null );
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=492852&r1=492851&r2=492852
==============================================================================
--- incubator/xap/trunk/testsrc/xap/xml/_TestElement.js (original)
+++ incubator/xap/trunk/testsrc/xap/xml/_TestElement.js Thu Jan 4 18:20:06 2007
@@ -54,7 +54,6 @@
assertTrue( "el.getAttribute", el.getAttribute != null );
assertTrue( "el.getLocalName", el.getLocalName != null );
assertTrue( "el.getNamespaceUri", el.getNamespaceUri != null );
- assertTrue( "el.getOwnerDocument", el.getOwnerDocument != null );
assertTrue( "el.getParent", el.getParent != null );
assertTrue( "el.getPrefix", el.getPrefix != null );
assertTrue( "el.removeAttributeChangeListener", el.removeAttributeChangeListener != null );