flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject git commit: [flex-asjs] [refs/heads/develop] - Added toXML and toXMLList temporarily comment out uses of assertType until package level functions are fixed
Date Tue, 18 Jul 2017 09:28:39 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/develop e25a086b3 -> add60be72


Added toXML and toXMLList
temporarily comment out uses of assertType until package level functions are fixed


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

Branch: refs/heads/develop
Commit: add60be72e37a32793b96410e644131a6ab1227c
Parents: e25a086
Author: Harbs <harbs@in-tools.com>
Authored: Tue Jul 18 12:28:35 2017 +0300
Committer: Harbs <harbs@in-tools.com>
Committed: Tue Jul 18 12:28:35 2017 +0300

----------------------------------------------------------------------
 frameworks/projects/XML/src/main/flex/XML.as    | 92 +++++++++++---------
 .../projects/XML/src/main/flex/XMLClasses.as    |  2 +
 .../projects/XML/src/main/flex/XMLList.as       | 23 ++++-
 .../main/flex/org/apache/flex/language/toXML.as | 51 +++++++++++
 .../flex/org/apache/flex/language/toXMLList.as  | 51 +++++++++++
 5 files changed, 177 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/add60be7/frameworks/projects/XML/src/main/flex/XML.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/XML/src/main/flex/XML.as b/frameworks/projects/XML/src/main/flex/XML.as
index 7152402..87c6e18 100644
--- a/frameworks/projects/XML/src/main/flex/XML.as
+++ b/frameworks/projects/XML/src/main/flex/XML.as
@@ -311,50 +311,23 @@ package
 		}
 
 
-		public function XML(xml:String = null)
+		public function XML(xml:* = null)
 		{
 			// _origStr = xml;
 			_children = [];
 			if(xml)
 			{
-				var parser:DOMParser = new DOMParser();
-				// get error namespace. It's different in different browsers.
-				var errorNS:String = parser.parseFromString('<', 'application/xml').getElementsByTagName("parsererror")[0].namespaceURI;
-
-				var doc:Document = parser.parseFromString(xml, "application/xml");
-
-				//check for errors
-				if(doc.getElementsByTagNameNS(errorNS, 'parsererror').length > 0)
-        			throw new Error('XML parse error');
-    			for(var i:int=0;i<doc.childNodes.length;i++)
-    			{
-					var node:Element = doc.childNodes[i];
-					if(node.nodeType == 1)
-					{
-						_version = doc.xmlVersion;
-						_encoding = doc.xmlEncoding;
-						_name = new QName();
-						_name.prefix = node.prefix;
-						_name.uri = node.namespaceURI;
-						_name.localName = node.localName;
-						iterateElement(node,this);
-					}
-					else
-					{
-						// Do we record the nodes which are probably processing instructions?
-//						var child:XML = XML.fromNode(node);
-//						addChild(child);
-					}
-
-    			}
-				normalize();
+				var xmlStr:String = "" + xml;
+				if(xmlStr.indexOf("<") == -1)
+				{
+					_nodeKind = "text";
+					_value = xmlStr;
+				}
+				else
+				{
+					parseXMLStr(xmlStr);
+				}
 			}
-			//need to deal with errors https://bugzilla.mozilla.org/show_bug.cgi?id=45566
-			
-			// get rid of nodes we do not want 
-
-			//loop through the child nodes and build XML obejcts for each.
-			
 			Object.defineProperty(this,"0",
 				{
 					"get": function():* { return this; },
@@ -366,6 +339,43 @@ package
 			);
 			
 		}
+
+		private function parseXMLStr(xml:String):void
+		{
+			var parser:DOMParser = new DOMParser();
+			// get error namespace. It's different in different browsers.
+			var errorNS:String = parser.parseFromString('<', 'application/xml').getElementsByTagName("parsererror")[0].namespaceURI;
+
+			var doc:Document = parser.parseFromString(xml, "application/xml");
+
+			//check for errors
+			if(doc.getElementsByTagNameNS(errorNS, 'parsererror').length > 0)
+				throw new Error('XML parse error');
+			for(var i:int=0;i<doc.childNodes.length;i++)
+			{
+				var node:Element = doc.childNodes[i];
+				if(node.nodeType == 1)
+				{
+					_version = doc.xmlVersion;
+					_encoding = doc.xmlEncoding;
+					_name = new QName();
+					_name.prefix = node.prefix;
+					_name.uri = node.namespaceURI;
+					_name.localName = node.localName;
+					iterateElement(node,this);
+				}
+				else
+				{
+					// Do we record the nodes which are probably processing instructions?
+//						var child:XML = XML.fromNode(node);
+//						addChild(child);
+				}
+			}
+			normalize();
+		//need to deal with errors https://bugzilla.mozilla.org/show_bug.cgi?id=45566
+		// get rid of nodes we do not want
+		//loop through the child nodes and build XML obejcts for each.
+		}
 		
 		private var _children:Array;
 		private var _attributes:Array = [];
@@ -396,7 +406,7 @@ package
 		}
 		private function addChildInternal(child:XML):void
 		{
-			assertType(child,XML,"Type must be XML");
+			// assertType(child,XML,"Type must be XML");
 			child.setParent(this);
 			if(child.nodeKind() =="attribute")
 			{
@@ -518,7 +528,7 @@ package
 			}
 			else
 			{
-				assertType(child,XML,"Type must be XML");
+				// assertType(child,XML,"Type must be XML");
 				child.setParent(this);
 				_children.push(child);
 			}
@@ -1448,7 +1458,7 @@ package
 			}
 			else
 			{
-				assertType(child,XML,"Type must be XML");
+				// assertType(child,XML,"Type must be XML");
 				child.setParent(this);
 				_children.unshift(child);
 			}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/add60be7/frameworks/projects/XML/src/main/flex/XMLClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/XML/src/main/flex/XMLClasses.as b/frameworks/projects/XML/src/main/flex/XMLClasses.as
index 7059082..b8fdc5d 100644
--- a/frameworks/projects/XML/src/main/flex/XMLClasses.as
+++ b/frameworks/projects/XML/src/main/flex/XMLClasses.as
@@ -32,6 +32,8 @@ internal class XMLClasses
 		import XMLList; XMLList;
 		import QName; QName;
 		import Namespace; Namespace;
+		import org.apache.flex.language.toXML; toXML;
+		import org.apache.flex.language.toXMLList; toXMLList;
 	}
 }
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/add60be7/frameworks/projects/XML/src/main/flex/XMLList.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/XML/src/main/flex/XMLList.as b/frameworks/projects/XML/src/main/flex/XMLList.as
index e6394f8..4be088c 100644
--- a/frameworks/projects/XML/src/main/flex/XMLList.as
+++ b/frameworks/projects/XML/src/main/flex/XMLList.as
@@ -22,9 +22,30 @@ package
 	public class XMLList
 	{
 		import org.apache.flex.debugging.throwError;
-		public function XMLList()
+		public function XMLList(expression:Object = null)
 		{
 			addIndex(0);
+			if(expression)
+				parseExpression(expression);
+		}
+		private function parseExpression(expression:Object):void
+		{
+			if(expression is XMLList)
+			{
+				targetObject = expression.targetObject;
+				targetProperty = expression.targetProperty;
+
+				var len:int = expression.length();
+				for(var i:int=0;i<len;i++){
+					this[i] = expression[i];
+				}
+			}
+			else if(expression is XML)
+			{
+				this[0] = expression;
+			}
+			else
+				this[0] = new XML(expression);
 		}
 		private var _xmlArray:Array = [];
 		/*

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/add60be7/frameworks/projects/XML/src/main/flex/org/apache/flex/language/toXML.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/XML/src/main/flex/org/apache/flex/language/toXML.as b/frameworks/projects/XML/src/main/flex/org/apache/flex/language/toXML.as
new file mode 100644
index 0000000..9802e6c
--- /dev/null
+++ b/frameworks/projects/XML/src/main/flex/org/apache/flex/language/toXML.as
@@ -0,0 +1,51 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.language
+{
+	COMPILE::JS
+	{
+		import XML; XML;
+		import XMLList; XMLList;
+        import org.apache.flex.debugging.notNull;
+	}
+    /**
+     * @flexjsignorecoercion XML
+     * @flexjsignorecoercion XMLList
+     */
+    COMPILE::JS
+    public function toXML(value:*):XML
+    {
+        notNull(value);
+        if(value is XML)
+            return value as XML;
+        if(value is XMLList)
+            return (value as XMLList).toXML();
+        // Anything other than bool, string or number should cause an error.
+        switch(typeof value)
+        {
+            case "boolean":
+            case "number":
+            case "string":
+                break;
+            default:
+                throw new Error("Incompatible type!");
+        }
+        return new XML(value);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/add60be7/frameworks/projects/XML/src/main/flex/org/apache/flex/language/toXMLList.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/XML/src/main/flex/org/apache/flex/language/toXMLList.as b/frameworks/projects/XML/src/main/flex/org/apache/flex/language/toXMLList.as
new file mode 100644
index 0000000..5147c5c
--- /dev/null
+++ b/frameworks/projects/XML/src/main/flex/org/apache/flex/language/toXMLList.as
@@ -0,0 +1,51 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.language
+{
+	COMPILE::JS
+	{
+		import XML; XML;
+		import XMLList; XMLList;
+        import org.apache.flex.debugging.notNull;
+	}
+    /**
+     * @flexjsignorecoercion XML
+     * @flexjsignorecoercion XMLList
+     */
+    COMPILE::JS
+    public function toXMLList(value:*):XMLList
+    {
+        notNull(value);
+        if(value is XMLList)
+            return value as XMLList;
+        if(value is XML)
+            return new XMLList(value);
+        // Anything other than bool, string or number should cause an error.
+        switch(typeof value)
+        {
+            case "boolean":
+            case "number":
+            case "string":
+                break;
+            default:
+                throw new Error("Incompatible type!");
+        }
+        return new XMLList(value);
+    }
+}
\ No newline at end of file


Mime
View raw message