You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ha...@apache.org on 2016/04/11 00:48:15 UTC

[04/49] git commit: [flex-asjs] [refs/heads/develop] - Added some more XML methods

Added some more XML methods


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

Branch: refs/heads/develop
Commit: dc52078ee510a2cb3e1fc1e15d9835ad5cb4b176
Parents: 09c5c4f
Author: Harbs <ha...@in-tools.com>
Authored: Wed Feb 3 17:56:22 2016 +0200
Committer: Harbs <ha...@in-tools.com>
Committed: Wed Feb 3 17:56:22 2016 +0200

----------------------------------------------------------------------
 frameworks/projects/XML/as/src/QName.as |  10 ++
 frameworks/projects/XML/as/src/XML.as   | 147 ++++++++++++++++++++-------
 2 files changed, 120 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/dc52078e/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 a3a1244..d24b7a7 100644
--- a/frameworks/projects/XML/as/src/QName.as
+++ b/frameworks/projects/XML/as/src/QName.as
@@ -104,6 +104,16 @@ package
 		{
 			return this.uri == name.uri && this.prefix == name.prefix && this.localName == name.localName;
 		}
+		public function matches(name:QName):Boolean
+		{
+			if(this.uri == "*" || name.uri == "*")
+				return this.localName == "*" || name.localName == "*" || this.localName == name.localName;
+
+			if(this.localName == "*" || name.localName == "*")
+				return this.uri == name.uri;
+
+			return this.uri == name.uri && this.localName == name.localName;
+		}
 		private var _isAttribute:Boolean;
 		public function get isAttribute():Boolean
 		{

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/dc52078e/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 f1aa656..aad27ce 100644
--- a/frameworks/projects/XML/as/src/XML.as
+++ b/frameworks/projects/XML/as/src/XML.as
@@ -230,6 +230,57 @@ package
 			return value.replace(/^\s+|\s+$/gm,'');
 		}
 
+		/**
+		 * [static] Returns an object with the following properties set to the default values: ignoreComments, ignoreProcessingInstructions, ignoreWhitespace, prettyIndent, and prettyPrinting.
+		 * @return 
+		 * 
+		 */
+		static public function defaultSettings():Object
+		{
+			return {
+			    ignoreComments : true,
+			    ignoreProcessingInstructions : true,
+			    ignoreWhitespace : true,
+			    prettyIndent : 2,
+			    prettyPrinting : true
+			}
+		}
+		
+		/**
+		 * [static] Sets values for the following XML properties: ignoreComments, ignoreProcessingInstructions, ignoreWhitespace, prettyIndent, and prettyPrinting.
+		 * @param rest
+		 * 
+		 */
+		static public function setSettings(value:Object):void
+		{
+			if(!value)
+				return;
+				
+		    ignoreComments = value.ignoreComments === undefined ? ignoreComments : value.ignoreComments;
+		    ignoreProcessingInstructions = value.ignoreProcessingInstructions === undefined ? ignoreProcessingInstructions : value.ignoreProcessingInstructions;
+		    ignoreWhitespace = value.ignoreWhitespace === undefined ? ignoreWhitespace : value.ignoreWhitespace;
+		    prettyIndent = value.prettyIndent === undefined ? prettyIndent : value.prettyIndent;
+		    prettyPrinting = value.prettyPrinting === undefined ? prettyPrinting : value.prettyPrinting;
+		}
+		
+		/**
+		 * [static] Retrieves the following properties: ignoreComments, ignoreProcessingInstructions, ignoreWhitespace, prettyIndent, and prettyPrinting.
+		 * 
+		 * @return 
+		 * 
+		 */
+		static public function settings():Object
+		{
+			return {
+			    ignoreComments : ignoreComments,
+			    ignoreProcessingInstructions : ignoreProcessingInstructions,
+			    ignoreWhitespace : ignoreWhitespace,
+			    prettyIndent : prettyIndent,
+			    prettyPrinting : prettyPrinting
+			}
+		}
+
+
 		public function XML(xml:String = null)
 		{
 			if(xml != "")
@@ -401,11 +452,14 @@ package
 		public function attribute(attributeName:*):XMLList
 		{
 			var i:int;
+			if(attributeName == "*")
+				return attributes();
+
 			attributeName = toAttributeName(attributeName);
 			var list:XMLList = new XMLList();
 			for(i=0;i<_attributes.length;i++)
 			{
-				if(_atributes[i].name().equals(attributeName))
+				if(_atributes[i].name().matches(attributeName))
 					list.appendChild(_atributes[i]);
 			}
 			list.targetObject = this;
@@ -421,7 +475,12 @@ package
 		 */
 		public function attributes():XMLList
 		{
-			return null;
+			var list:XMLList = new XMLList();
+			for(i=0;i<_attributes.length;i++)
+				list.appendChild(_atributes[i]);
+
+			list.targetObject = this;
+			return list;
 		}
 		
 		/**
@@ -435,6 +494,7 @@ package
 		{
 			/*
 			 * 
+			When the [[Get]] method of an XML object x is called with property name P, the following steps are taken:
 			1. If ToString(ToUint32(P)) == P
 			  a. Let list = ToXMLList(x)
 			  b. Return the result of calling the [[Get]] method of list with argument P
@@ -450,7 +510,36 @@ package
 			    i. Call the [[Append]] method of list with argument x[k]
 			6. Return list
 			*/
-			return null;
+			var i:int;
+			var list:XMLList = new XMLList();
+			if(parseInt(name,10).toString() == propertyName)
+			{
+				if(propertyName != "0")
+					return undefined;
+				list.appendChild(this);
+				list.targetObject = this;
+				return list;
+			}
+			propertyName = toXMLName(propertyName);
+			if(propertyName.isAttribute)
+			{
+				for(i=0;i<_attributes.length;i++)
+				{
+					if(propertyName.matches(_attributes[i].name()))
+						list.append(_attributes[i]);
+				}
+			}
+			else
+			{
+				for(i=0;i<_children.length;i++)
+				{
+					if(propertyName.matches(_children[i].name()))
+						list.append(_children[i]);
+				}
+			}
+			list.targetObject = this;
+			list.targetProperty = propertyName;
+			return list;
 		}
 		
 		/**
@@ -475,7 +564,15 @@ package
 		 */
 		public function children():XMLList
 		{
-			return null;
+			var list:XMLList = new XMLList();
+			for(i=0;i<_children.length;i++)
+			{
+				//TODO filter out non-elements
+				if(propertyName.matches(_children[i].name()))
+					list.append(_children[i]);
+			}
+			list.targetObject = this;
+			return list;
 		}
 		
 		/**
@@ -486,7 +583,14 @@ package
 		 */
 		public function comments():XMLList
 		{
-			return null;
+			var list:XMLList = new XMLList();
+			for(i=0;i<_children.length;i++)
+			{
+				if(_children[i].nodeKind() == "comment" && propertyName.matches(_children[i].name()))
+					list.append(_children[i]);
+			}
+			list.targetObject = this;
+			return list;
 		}
 		
 		/**
@@ -498,7 +602,7 @@ package
 		 */
 		public function contains(value:XML):Boolean
 		{
-			return null;
+			return this.equals(value);
 		}
 		
 		/**
@@ -530,16 +634,6 @@ package
 		}
 		
 		/**
-		 * [static] Returns an object with the following properties set to the default values: ignoreComments, ignoreProcessingInstructions, ignoreWhitespace, prettyIndent, and prettyPrinting.
-		 * @return 
-		 * 
-		 */
-		static public function defaultSettings():Object
-		{
-			return null;
-		}
-		
-		/**
 		 * Returns all descendants (children, grandchildren, great-grandchildren, and so on) of the XML object that have the given name parameter.
 		 * 
 		 * @param name
@@ -1246,27 +1340,6 @@ package
 		}
 		
 		/**
-		 * [static] Sets values for the following XML properties: ignoreComments, ignoreProcessingInstructions, ignoreWhitespace, prettyIndent, and prettyPrinting.
-		 * @param rest
-		 * 
-		 */
-		static public function setSettings(... rest):void
-		{
-
-		}
-		
-		/**
-		 * [static] Retrieves the following properties: ignoreComments, ignoreProcessingInstructions, ignoreWhitespace, prettyIndent, and prettyPrinting.
-		 * 
-		 * @return 
-		 * 
-		 */
-		static public function settings():Object
-		{
-			return null;
-		}
-		
-		/**
 		 * Returns an XMLList object of all XML properties of the XML object that represent XML text nodes.
 		 * 
 		 * @return