Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C1D02200B35 for ; Tue, 5 Jul 2016 09:11:26 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C03E3160A60; Tue, 5 Jul 2016 07:11:26 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 43CDD160A4F for ; Tue, 5 Jul 2016 09:11:25 +0200 (CEST) Received: (qmail 11380 invoked by uid 500); 5 Jul 2016 07:11:24 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 11372 invoked by uid 99); 5 Jul 2016 07:11:24 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Jul 2016 07:11:24 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3CD72EAD99; Tue, 5 Jul 2016 07:11:24 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: harbs@apache.org To: commits@flex.apache.org Date: Tue, 05 Jul 2016 07:11:24 -0000 Message-Id: <2e03171806794a009bc12860a78c29e3@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: [flex-asjs] [refs/heads/develop] - Added BinaryURLLoader and some utility classes. archived-at: Tue, 05 Jul 2016 07:11:26 -0000 Repository: flex-asjs Updated Branches: refs/heads/develop a215d7f9a -> 28f8f5c2f Added BinaryURLLoader and some utility classes. Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/43064b48 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/43064b48 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/43064b48 Branch: refs/heads/develop Commit: 43064b4856886ebd517a8e60ddd8b38a34ac5df5 Parents: a215d7f Author: yishayw Authored: Mon Jul 4 17:51:31 2016 +0300 Committer: yishayw Committed: Tue Jul 5 09:05:24 2016 +0300 ---------------------------------------------------------------------- .../projects/Core/src/main/flex/CoreClasses.as | 3 +- .../org/apache/flex/events/ProgressEvent.as | 79 ++++++++ .../flex/org/apache/flex/utils/BinaryData.as | 4 + .../Network/src/main/flex/NetworkClasses.as | 2 + .../flex/org/apache/flex/net/BinaryUploader.as | 61 +------ .../flex/org/apache/flex/net/HTTPConstants.as | 93 ++++++++++ .../flex/org/apache/flex/net/HTTPService.as | 101 +---------- .../main/flex/org/apache/flex/net/HTTPUtils.as | 27 +++ .../org/apache/flex/net/url/BinaryURLLoader.as | 65 +++++++ .../flex/org/apache/flex/net/url/URLRequest.as | 65 +++++++ .../flex/org/apache/flex/net/url/URLStream.as | 180 +++++++++++++++++++ 11 files changed, 529 insertions(+), 151 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/43064b48/frameworks/projects/Core/src/main/flex/CoreClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/CoreClasses.as b/frameworks/projects/Core/src/main/flex/CoreClasses.as index 1e201a0..49c813e 100644 --- a/frameworks/projects/Core/src/main/flex/CoreClasses.as +++ b/frameworks/projects/Core/src/main/flex/CoreClasses.as @@ -98,7 +98,8 @@ internal class CoreClasses import org.apache.flex.core.UIButtonBase; UIButtonBase; } import org.apache.flex.events.CustomEvent; CustomEvent; - import org.apache.flex.events.Event; Event; + import org.apache.flex.events.Event; Event; + import org.apache.flex.events.ProgressEvent; ProgressEvent; import org.apache.flex.events.EventDispatcher; EventDispatcher; import org.apache.flex.events.IEventDispatcher; IEventDispatcher; import org.apache.flex.events.MouseEvent; MouseEvent; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/43064b48/frameworks/projects/Core/src/main/flex/org/apache/flex/events/ProgressEvent.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/ProgressEvent.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/ProgressEvent.as new file mode 100644 index 0000000..f4f0150 --- /dev/null +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/ProgressEvent.as @@ -0,0 +1,79 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.events +{ + + /** + * The ProgressEvent + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class ProgressEvent extends Event + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function ProgressEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false, + current:Number = NaN, total:Number = NaN) + { + super(type, bubbles, cancelable); + this.current = current; + this.total = total; + } + + /** + * The current value. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public var current:Number; + + /** + * The total value. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public var total:Number; + + /** + * The name of the event. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public static const PROGRESS:String = "progress"; + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/43064b48/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as index 373ee8e..73cfe2a 100644 --- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as @@ -379,6 +379,10 @@ public class BinaryData } } + public function doNothing():void + { + var b:String = "bla"; + } /** * A method to extend the size of the binary data * so you can write more bytes to it. Not all http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/43064b48/frameworks/projects/Network/src/main/flex/NetworkClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/NetworkClasses.as b/frameworks/projects/Network/src/main/flex/NetworkClasses.as index cf88050..3477a84 100644 --- a/frameworks/projects/Network/src/main/flex/NetworkClasses.as +++ b/frameworks/projects/Network/src/main/flex/NetworkClasses.as @@ -18,6 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package { + /** * @private @@ -27,6 +28,7 @@ package */ internal class NetworkClasses { + import org.apache.flex.net.url.BinaryURLLoader; BinaryURLLoader; } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/43064b48/frameworks/projects/Network/src/main/flex/org/apache/flex/net/BinaryUploader.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/BinaryUploader.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/BinaryUploader.as index 03c0d78..0a9a58f 100644 --- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/BinaryUploader.as +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/BinaryUploader.as @@ -25,7 +25,6 @@ package org.apache.flex.net import flash.net.URLLoader; import flash.net.URLRequest; import flash.net.URLRequestHeader; - import flash.net.URLRequestMethod; } COMPILE::JS { @@ -35,7 +34,6 @@ package org.apache.flex.net import org.apache.flex.core.IBead; import org.apache.flex.core.IStrand; import org.apache.flex.events.Event; - import org.apache.flex.events.EventDispatcher; import org.apache.flex.utils.BinaryData; //-------------------------------------- @@ -101,55 +99,6 @@ package org.apache.flex.net */ public class BinaryUploader extends HTTPServiceBase implements IStrand, IBead { - /** - * The GET request method. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public static const HTTP_METHOD_GET:String = "GET"; - - /** - * The POST request method. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public static const HTTP_METHOD_POST:String = "POST"; - - /** - * The PUT request method. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public static const HTTP_METHOD_PUT:String = "PUT"; - - /** - * The DELETE request method. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public static const HTTP_METHOD_DELETE:String = "DELETE"; - - /** - * Constructor. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement - */ public function BinaryUploader() { super(); @@ -246,7 +195,7 @@ package org.apache.flex.net } } - private var _method:String = HTTP_METHOD_POST; + private var _method:String = HTTPConstants.POST; /** * The HTTP method for the upload. @@ -572,14 +521,14 @@ package org.apache.flex.net sawContentType = true; } } - if (method != HTTP_METHOD_GET && !sawContentType) + if (method != HTTPConstants.GET && !sawContentType) { urlHeader = new URLRequestHeader(HTTPHeader.CONTENT_TYPE, contentType); request.requestHeaders.push(urlHeader); } if (binaryData) { - if (method == HTTP_METHOD_GET) + if (method == HTTPConstants.GET) { if (url.indexOf("?") != -1) url += binaryData.data.toString(); @@ -606,7 +555,7 @@ package org.apache.flex.net var binaryData:String = null; if (_binaryData != null) { - if (_method === HTTP_METHOD_GET) { + if (_method === HTTPConstants.GET) { if (url.indexOf('?') !== -1) { url += _binaryData.data; } else { @@ -633,7 +582,7 @@ package org.apache.flex.net } } - if (_method !== HTTP_METHOD_GET && + if (_method !== HTTPConstants.GET && !sawContentType && binaryData) { element.setRequestHeader( HTTPHeader.CONTENT_TYPE, _contentType); http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/43064b48/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPConstants.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPConstants.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPConstants.as new file mode 100644 index 0000000..10dac43 --- /dev/null +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPConstants.as @@ -0,0 +1,93 @@ +package org.apache.flex.net +{ + public final class HTTPConstants extends Object + { + /** + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public static const GET:String = "GET"; + + /** + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public static const POST:String = "POST"; + + /** + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public static const PUT:String = "PUT"; + + /** + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public static const DELETE:String = "DELETE"; + + /** + * Dispatched when the request is complete. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public static const COMPLETE:String = "complete"; + + /** + * Dispatched if an error occurs in the server communication. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public static const IO_ERROR:String = "ioError"; + + /** + * Dispatched when an httpStatus code is received from the server. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public static const STATUS:String = "httpStatus"; + + /** + * Dispatched if Adobe AIR is able to detect and return the status + * code for the request. Unlike the httpStatus event, the httpResponseStatus + * event is delivered before any response data. Also, the httpResponseStatus + * event includes values for the responseHeaders and responseURL properties + * (which are undefined for an httpStatus event. Note that the + * httpResponseStatus event (if any) will be sent before + * (and in addition to) any complete or error event. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public static const RESPONSE_STATUS:String = "httpResponseStatus"; + + + + public function HTTPConstants() + { + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/43064b48/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPService.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPService.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPService.as index 39820b7..e46ee14 100644 --- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPService.as +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPService.as @@ -25,7 +25,6 @@ package org.apache.flex.net import flash.net.URLLoader; import flash.net.URLRequest; import flash.net.URLRequestHeader; - import flash.net.URLRequestMethod; } COMPILE::JS { @@ -35,7 +34,7 @@ package org.apache.flex.net import org.apache.flex.core.IBead; import org.apache.flex.core.IStrand; import org.apache.flex.events.Event; - import org.apache.flex.events.EventDispatcher; + import org.apache.flex.net.HTTPConstants; //-------------------------------------- // Events @@ -103,92 +102,6 @@ package org.apache.flex.net public class HTTPService extends HTTPServiceBase implements IStrand, IBead { /** - * @copy org.apache.flex.net.BinaryUploader#HTTP_METHOD_GET - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public static const HTTP_METHOD_GET:String = "GET"; - - /** - * @copy org.apache.flex.net.BinaryUploader#HTTP_METHOD_POST - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public static const HTTP_METHOD_POST:String = "POST"; - - /** - * @copy org.apache.flex.net.BinaryUploader#HTTP_METHOD_PUT - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public static const HTTP_METHOD_PUT:String = "PUT"; - - /** - * @copy org.apache.flex.net.BinaryUploader#HTTP_METHOD_DELETE - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public static const HTTP_METHOD_DELETE:String = "DELETE"; - - /** - * Dispatched when the request is complete. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public static const EVENT_COMPLETE:String = "complete"; - - /** - * Dispatched if an error occurs in the server communication. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public static const EVENT_IO_ERROR:String = "ioError"; - - /** - * Dispatched when an httpStatus code is received from the server. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public static const EVENT_HTTP_STATUS:String = "httpStatus"; - - /** - * Dispatched if Adobe AIR is able to detect and return the status - * code for the request. Unlike the httpStatus event, the httpResponseStatus - * event is delivered before any response data. Also, the httpResponseStatus - * event includes values for the responseHeaders and responseURL properties - * (which are undefined for an httpStatus event. Note that the - * httpResponseStatus event (if any) will be sent before - * (and in addition to) any complete or error event. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public static const EVENT_HTTP_RESPONSE_STATUS:String = "httpResponseStatus"; - - /** * Constructor. * * @langversion 3.0 @@ -197,7 +110,7 @@ package org.apache.flex.net * @productversion FlexJS 0.0 * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement */ - public function HTTPService() + public function HTTPService() { super(); @@ -290,7 +203,7 @@ package org.apache.flex.net } } - private var _method:String = HTTP_METHOD_GET; + private var _method:String = HTTPConstants.GET; /** * @copy org.apache.flex.net.BinaryUploader#method @@ -622,14 +535,14 @@ package org.apache.flex.net sawContentType = true; } } - if (method != HTTP_METHOD_GET && !sawContentType && contentData != null) + if (method != HTTPConstants.GET && !sawContentType && contentData != null) { urlHeader = new URLRequestHeader(HTTPHeader.CONTENT_TYPE, contentType); request.requestHeaders.push(urlHeader); } if (contentData) { - if (method == HTTP_METHOD_GET) + if (method == HTTPConstants.GET) { if (url.indexOf("?") != -1) url += contentData; @@ -655,7 +568,7 @@ package org.apache.flex.net var contentData:String = null; if (_contentData != null) { - if (_method === HTTP_METHOD_GET) { + if (_method === HTTPConstants.GET) { if (url.indexOf('?') !== -1) { url += _contentData; } else { @@ -682,7 +595,7 @@ package org.apache.flex.net } } - if (_method !== HTTP_METHOD_GET && + if (_method !== HTTPConstants.GET && !sawContentType && contentData) { element.setRequestHeader( HTTPHeader.CONTENT_TYPE, _contentType); http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/43064b48/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPUtils.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPUtils.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPUtils.as new file mode 100644 index 0000000..494d9da --- /dev/null +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPUtils.as @@ -0,0 +1,27 @@ +package org.apache.flex.net +{ + public class HTTPUtils + { + public function HTTPUtils() + { + } + static public function encodeUrlVariables(data:Object):String + { + if(!data) + return ""; + var b:Array = []; + var x:String; + for(x in data) + { + b.push(encodeURI(x)); + b.push("="); + b.push(encodeURI(data[x])); + b.push("&"); + } + if(b.length) + b.pop() + return b.join(""); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/43064b48/frameworks/projects/Network/src/main/flex/org/apache/flex/net/url/BinaryURLLoader.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/url/BinaryURLLoader.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/url/BinaryURLLoader.as new file mode 100644 index 0000000..f08111e --- /dev/null +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/url/BinaryURLLoader.as @@ -0,0 +1,65 @@ +package org.apache.flex.net.url +{ + + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.events.ProgressEvent; + import org.apache.flex.net.HTTPConstants; + import org.apache.flex.utils.BinaryData; + + public class BinaryURLLoader extends EventDispatcher + { + + public var data:BinaryData; + + private var stream:URLStream; + + public var bytesLoaded:uint = 0; + + public var bytesTotal:uint = 0; + + public function BinaryURLLoader(request:URLRequest = null) + { + super(); + stream = new URLStream(); + stream.addEventListener(HTTPConstants.COMPLETE, onComplete); + } + + public function load(request:URLRequest):void + { + stream.load(request); + } + + public function close():void + { + stream.close(); + } + + private function redirectEvent(event:Event):void + { + dispatchEvent(event); + } + + private function onComplete(event:Event):void + { + data = stream.response; + if (data) + { + dispatchEvent(event); + } + else + { + // TODO dipatch error event? + dispatchEvent(new Event(HTTPConstants.IO_ERROR)); + } + } + + private function onProgress(event:ProgressEvent):void + { + this.bytesLoaded = event.current + this.bytesTotal = event.total; + dispatchEvent(event); + } + } +} + http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/43064b48/frameworks/projects/Network/src/main/flex/org/apache/flex/net/url/URLRequest.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/url/URLRequest.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/url/URLRequest.as new file mode 100644 index 0000000..df397e5 --- /dev/null +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/url/URLRequest.as @@ -0,0 +1,65 @@ +package org.apache.flex.net.url +{ + public final class URLRequest extends Object + { + + private static const kInvalidParamError:uint = 2004; + private var _url:String; + private var _data:Object; + private var _contentType:String = "application/x-www-form-urlencoded"; + + public function URLRequest(url:String = null) + { + super(); + if(url != null) + { + this.url = url; + } + this.requestHeaders = []; + } + + public function get contentType():String + { + return _contentType; + } + + public function set contentType(value:String):void + { + _contentType = value; + } + + public function get data():Object + { + return _data; + } + + public function set data(value:Object):void + { + _data = value; + } + + public function get url() : String{ + return _url; + } + + public function set url(param1:String) : void{ + _url = param1; + } + + public function get requestHeaders() : Array { return null; }; + + public function set requestHeaders(value:Array) : void + { + //if(value != null) + //{ + //this.setRequestHeaders(value.filter(this.filterRequestHeaders)); + //} + //else + //{ + //this.setRequestHeaders(value); + //} + } + + } +} + http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/43064b48/frameworks/projects/Network/src/main/flex/org/apache/flex/net/url/URLStream.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/url/URLStream.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/url/URLStream.as new file mode 100644 index 0000000..8430bb7 --- /dev/null +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/url/URLStream.as @@ -0,0 +1,180 @@ + +package org.apache.flex.net.url +{ + + + + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.events.ProgressEvent; + import org.apache.flex.net.HTTPConstants; + import org.apache.flex.net.HTTPUtils; + import org.apache.flex.utils.BinaryData; + + COMPILE::SWF + { + import flash.net.URLRequestHeader; + import flash.events.IOErrorEvent; + import flash.net.URLVariables; + import flash.events.Event; + import flash.events.ProgressEvent; + import flash.net.URLRequest; + import flash.net.URLStream; + import flash.utils.ByteArray; + } + + + + public class URLStream extends EventDispatcher + { + COMPILE::JS + { + private var xhr:XMLHttpRequest; + } + + COMPILE::SWF + { + private var flashUrlStream:flash.net.URLStream + } + + public function URLStream() + { + super(); + } + + public function get response():BinaryData + { + COMPILE::JS + { + var ab:ArrayBuffer = xhr.response as ArrayBuffer; + var bd:BinaryData = new BinaryData(ab); + return bd; + } + COMPILE::SWF + { + var ba:ByteArray = new ByteArray(); + flashUrlStream.readBytes(ba); + var bd:BinaryData = new BinaryData(ba); + return bd; + } + } + + public function load(urlRequest:org.apache.flex.net.url.URLRequest):void + { + COMPILE::JS { + xhr = new XMLHttpRequest(); + xhr.open("POST", urlRequest.url); + xhr.responseType = "arraybuffer"; + xhr.addEventListener("readystatechange", xhr_onreadystatechange,false); + xhr.addEventListener("progress", xhr_progress, false); + xhr.setRequestHeader("Content-type", urlRequest.contentType); + xhr.send(HTTPUtils.encodeUrlVariables(urlRequest.data)); + } + COMPILE::SWF + { + flashUrlStream = new flash.net.URLStream(); + var req:flash.net.URLRequest = new flash.net.URLRequest(urlRequest.url); + var hdr:URLRequestHeader = new URLRequestHeader("Content-type", urlRequest.contentType); + req.requestHeaders.push(hdr); + req.data = new flash.net.URLVariables(HTTPUtils.encodeUrlVariables(urlRequest.data)); + req.method = HTTPConstants.POST; + flashUrlStream.addEventListener(flash.events.ProgressEvent.PROGRESS, flash_progress); + flashUrlStream.addEventListener(flash.events.Event.COMPLETE, flash_complete); + flashUrlStream.addEventListener(IOErrorEvent.IO_ERROR, flash_onIoError); + flashUrlStream.load(req); + } + } + + COMPILE::SWF + protected function flash_onIoError(event:IOErrorEvent):void + { + trace("io error: " + event.text); + } + + COMPILE::SWF + protected function flash_complete(event:flash.events.Event):void + { + dispatchEvent(new org.apache.flex.events.Event(HTTPConstants.COMPLETE)); + } + COMPILE::SWF + protected function flash_progress(event:flash.events.ProgressEvent):void + { + var progressEvent:org.apache.flex.events.ProgressEvent = new org.apache.flex.events.ProgressEvent(org.apache.flex.events.ProgressEvent.PROGRESS); + progressEvent.current = event.bytesLoaded; + progressEvent.total = event.bytesTotal; + dispatchEvent(progressEvent); + } + + + private function xhr_progress(e:Object):void + { + dispatchEvent(new org.apache.flex.events.ProgressEvent(org.apache.flex.events.ProgressEvent.PROGRESS, false, false, e.loaded, e.total)); + } + + COMPILE::JS + private function xhr_onreadystatechange(e:*):void + { + if (xhr.readyState == 4 && xhr.status == 200) + { + dispatchEvent(new org.apache.flex.events.Event(HTTPConstants.COMPLETE)); + }else if (xhr.readyState==4&&xhr.status==404){ + // dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR)); + } + } + + + // public function readBytes(b:ByteArray, offset:uint = 0, length:uint = 0):void { + // } + + public function readBoolean():Boolean { return false } + + public function readByte():int { return 0 } + + public function readUnsignedByte():uint { return 0 } + + public function readShort():int { return 0 } + + public function readUnsignedShort():uint { return 0 } + + public function readUnsignedInt():uint { return 0 } + + public function readInt():int { return 0 } + + public function readFloat():Number { return 0 } + + public function readDouble():Number { return 0 } + + public function readMultiByte(param1:uint, param2:String):String { return null; } + + public function readUTF():String { return null } + + public function readUTFBytes(param1:uint):String { return null; } + + public function get connected():Boolean { return false } + + public function get bytesAvailable():uint { return 0; } + + public function close():void {/**/ } + + public function readObject():* { return null; } + + public function get objectEncoding():uint { return 0; } + + public function set objectEncoding(param1:uint):void {/**/ } + + public function get endian():String { return null; } + + public function set endian(param1:String):void {/**/ } + + public function get diskCacheEnabled():Boolean { return false } + + public function get position():Number { return 0; } + + public function set position(param1:Number):void {/**/ } + + public function get length():Number { return 0; } + + public function stop():void {/**/ } + } +} +