flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject [08/49] git commit: [flex-asjs] [refs/heads/develop] - copy(), equals() and some fixes
Date Sun, 10 Apr 2016 22:48:19 GMT
copy(), equals() and some fixes


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/a2d921d0
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/a2d921d0
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/a2d921d0

Branch: refs/heads/develop
Commit: a2d921d019e164efb6607949defdb1bcc2536784
Parents: 988296e
Author: Harbs <harbs@in-tools.com>
Authored: Sun Feb 7 00:02:13 2016 +0200
Committer: Harbs <harbs@in-tools.com>
Committed: Sun Feb 7 00:02:13 2016 +0200

----------------------------------------------------------------------
 frameworks/projects/XML/as/src/QName.as |  3 +-
 frameworks/projects/XML/as/src/XML.as   | 98 ++++++++++++++++++++++++++--
 2 files changed, 96 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a2d921d0/frameworks/projects/XML/as/src/QName.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/XML/as/src/QName.as b/frameworks/projects/XML/as/src/QName.as
index d24b7a7..2ceb487 100644
--- a/frameworks/projects/XML/as/src/QName.as
+++ b/frameworks/projects/XML/as/src/QName.as
@@ -49,6 +49,7 @@ package
 			{
 				_uri = qNameOrUri.uri;
 				_localName = qNameOrUri.localName;
+				_prefix = qNameOrUri.prefix;
 			}
 			else if(qNameOrUri is Namespace)
 			{
@@ -102,7 +103,7 @@ package
 
 		public function equals(name:QName):Boolean
 		{
-			return this.uri == name.uri && this.prefix == name.prefix && this.localName
== name.localName;
+			return this.uri == name.uri && this.localName == name.localName; // this.prefix
== name.prefix &&
 		}
 		public function matches(name:QName):Boolean
 		{

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a2d921d0/frameworks/projects/XML/as/src/XML.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/XML/as/src/XML.as b/frameworks/projects/XML/as/src/XML.as
index 8be71e2..d077ae8 100644
--- a/frameworks/projects/XML/as/src/XML.as
+++ b/frameworks/projects/XML/as/src/XML.as
@@ -150,7 +150,7 @@ package
 			xml.setNodeKind("attribute");
 			xml.setName(att.name);
 			xml.setValue(att.value);
-			parent.
+			parent.addChild(xml);
 			return xml;
 		}
 		static private function iterateElement(node:Element,xml:XML):void
@@ -283,7 +283,7 @@ package
 
 		public function XML(xml:String = null)
 		{
-			if(xml != "")
+			if(xml)
 			{
 				var parser:DOMParser = new DOMParser();
 				// get error namespace. It's different in different browsers.
@@ -627,7 +627,23 @@ package
 				  c. Let c.[[Parent]] = y
 				6. Return y
 			*/
-			return null;
+			var i:int;
+			var xml:XML = new XML();
+			xml.setNodeKind(_nodeKind);
+			xml.setName(name());
+			xml.setValue(_value);
+			for(i-0;i<_namespaces.length;i++)
+			{
+				xml.addNamespace(new Namespace(_namespaces[i]));
+			}
+			//parent should be null by default
+			for(i=0;i<_attributes.length;i++)
+				xml.addChild(_attributes[i].copy());
+
+			for(i=0;i<_children.length;i++)
+				xml.addChild(_children[i].copy());
+			
+			return xml;
 		}
 		
 		/**
@@ -702,7 +718,7 @@ package
 			return null;
 		}
 
-		public function equals(xml:XML):Boolean
+		public function equals(xml:*):Boolean
 		{
 			/*
 				When the [[Equals]] method of an XML object x is called with value V, the following steps
are taken:
@@ -723,6 +739,66 @@ package
 				  b. If r == false, return false
 				10. Return true
 			*/
+			var i:int;
+			if(!(xml is XML))
+				return false;
+
+			if(xml.nodeKind() != _nodeKind)
+				return false;
+
+			if(!name().equals(xml.name()))
+				return false;
+			var selfAttrs:Array = getAttributeArray();
+			var xmlAttrs:Array = xml.getAttributeArray();
+			if(selfAttrs.length != xmlAttrs.length)
+				return false;
+			//length comparison should not be necessary because xml always has a length of 1
+			if(getValue() != xml.getValue())
+				return false;
+
+			for(i=0;i<selfAttrs.length;i++)
+			{
+				if(!xml.hasAttribute(selfAttrs[i]))
+					return false;
+			}
+			var selfChldrn:Array = getChildrenArray();
+			var xmlChildren:Array = xml.getChildrenArray();
+			if(selfChldrn.length != xmlChildren.length)
+				return false;
+			
+			for(i=0;i<selfChldrn.length;i++)
+			{
+				if(!selfChldrn[i].equals(xmlChildren[i]))
+					return false;
+			}
+			return true;
+		}
+
+		public function hasAttribute(nameOrXML:*,value:String=null):Boolean
+		{
+			if(!_attributes)
+				return false;
+			var name:QName;
+			if(nameOrXML is XML)
+			{
+				name = nameOrXML.name();
+				value = nameOrXML.getValue();
+			}
+			else
+			{
+				name = new QName(nameOrXML);
+			}
+			var i:int;
+			for(i=0;i<_attributes.length;i++)
+			{
+				if(name.matches(_attributes[i].name()))
+				{
+					if(!value)
+						return true;
+					return value == _attributes[i].getValue();
+				}
+			}
+			return false;
 		}
 
 		private function getAncestorNamespaces(namespaces:Array):Array
@@ -756,6 +832,15 @@ package
 			return namespaces;
 		}
 
+		public function getAttributeArray():Array
+		{
+			return _attributes ? _attributes.slice() : [];
+		}
+		public function getChildrenArray():Array
+		{
+			return _children ? _children.slice() : [];
+		}
+
 		public function getIndexOf(elem:XML):int
 		{
 			return _children.indexOf(elem);
@@ -772,6 +857,11 @@ package
 			}
 			return "";
 		}
+
+		public function getValue():String
+		{
+			return _value;
+		}
 		/**
 		 * Checks to see whether the XML object contains complex content.
 		 * 


Mime
View raw message