# HG changeset patch
# User mas01mj
# Date 1284482830 0
# Node ID 3a0b9700b3d2633093f074f046b96ffbed6cd5ad
# Parent 65134dd772fc4ae012d2b66d09548e17ebd5bc17
* Initial AS3 commit
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/.svnignore
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/.svnignore Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,4 @@
+build
+.settings
+.project
+.as3_classpath
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/build.properties
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/build.properties Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,16 @@
+flex.dir = /Applications/eclipse36/plugins/com.powerflasher.fdt.shippedflex_3.3.0.4852_1001/flex/
+
+src.dir = src
+
+compiler.as3 = true
+compiler.strict = true
+compiler.warnings = true
+compiler.benchmark = true
+compiler.use-network = true
+compiler.encoding = UTF-8
+compiler.config = ${flex.dir}/frameworks/flex-config.xml
+FLEX_HOME=${flex.dir}
+
+project.class = ${src.dir}/Main.as
+project.swf = as3bridge.swf
+
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/build.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/build.xml Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,36 @@
+
+
+
setUp
tearDown
.assertTrue
with a boolean, or assertEquals
+ * with two primitive values that should match.
+ * testMethod
constructor parameter is how we
+ * create and run a single test case and test method.
+ */
+ public function TestCase(testMethod:String = null) {
+ var description:XML = describeType(this);
+ var className:Object = description.@name;
+ var methods:XMLList = description..method.((@name+"").match("^test"));
+ if(testMethod != null) {
+ testMethods = testMethod.split(", ").join(",").split(",");
+ if(testMethods.length == 1) {
+ runSingle = true;
+ }
+ } else {
+ setTestMethods(methods);
+ }
+ setName(className.toString());
+ resolveLayoutManager();
+ asyncQueue = [];
+ }
+
+ private function resolveLayoutManager():void {
+ // Avoid creating import dependencies on flex framework
+ // If you have the framework.swc in your classpath,
+ // the layout manager will be found, if not, a mcok
+ // will be used.
+ try {
+ var manager:Class = getDefinitionByName("mx.managers.LayoutManager") as Class;
+ layoutManager = manager["getInstance"]();
+ if(!layoutManager.hasOwnProperty("resetAll")) {
+ throw new Error("TestCase :: mx.managers.LayoutManager missing resetAll method");
+ }
+ }
+ catch(e:Error) {
+ layoutManager = new Object();
+ layoutManager.resetAll = function():void {
+ };
+ }
+ }
+
+ /**
+ * Sets the name of a TestCase
+ * @param name The name to set
+ */
+ public function setName(name:String):void {
+ fName = name;
+ }
+
+ protected function setTestMethods(methodNodes:XMLList):void {
+ testMethods = new Array();
+ var methodNames:Object = methodNodes.@name;
+ var name:String;
+ for each(var item:Object in methodNames) {
+ name = item.toString();
+ testMethods.push(name);
+ }
+ }
+
+ public function getTestMethods():Array {
+ return testMethods;
+ }
+
+ /**
+ * Counts the number of test cases executed by run(TestResult result).
+ */
+ public function countTestCases():int {
+ return testMethods.length;
+ }
+
+ /**
+ * Creates a default TestResult object
+ *
+ * @see TestResult
+ */
+ protected function createResult():TestResult {
+ return new TestResult();
+ }
+
+ /**
+ * A convenience method to run this test, collecting the results with
+ * either the TestResult provided or a default, new TestResult object.
+ * Expects either:
+ * run():void // will return the newly created TestResult
+ * run(result:TestResult):TestResult // will use the TestResult
+ * that was passed in.
+ *
+ * @see TestResult
+ */
+ public function run():void {
+ getResult().run(this);
+ }
+
+ public function setResult(result:TestListener):void {
+ this.result = result;
+ }
+
+ internal function getResult():TestListener {
+ return (result == null) ? createResult() : result;
+ }
+
+ /**
+ * Runs the bare test sequence.
+ * @throws Error if any exception is thrown
+ */
+ public function runBare():void {
+ if(isComplete) {
+ return;
+ }
+ var name:String;
+ var itr:Iterator = getMethodIterator();
+ if(itr.hasNext()) {
+ name = String(itr.next());
+ currentState = PRE_SET_UP;
+ runMethod(name);
+ }
+ else {
+ cleanUp();
+ getResult().endTest(this);
+ isComplete = true;
+ dispatchEvent(new Event(Event.COMPLETE));
+ }
+ }
+
+ private function getMethodIterator():Iterator {
+ if(methodIterator == null) {
+ methodIterator = new ArrayIterator(testMethods);
+ }
+ return methodIterator;
+ }
+
+ /**
+ * Override this method in Asynchronous test cases
+ * or any other time you want to perform additional
+ * member cleanup after all test methods have run
+ **/
+ protected function cleanUp():void {
+ }
+
+ private function runMethod(methodName:String):void {
+ try {
+ if(currentState == PRE_SET_UP) {
+ currentState = SET_UP;
+ getResult().startTestMethod(this, methodName);
+ setUp(); // setUp may be async and change the state of methodIsAsynchronous
+ }
+ currentMethod = methodName;
+ if(!waitForAsync()) {
+ currentState = RUN_METHOD;
+ this[methodName]();
+ }
+ }
+ catch(assertionFailedError:AssertionFailedError) {
+ getResult().addFailure(this, assertionFailedError);
+ }
+ catch(unknownError:Error) {
+ getResult().addError(this, unknownError);
+ }
+ finally {
+ if(!waitForAsync()) {
+ runTearDown();
+ }
+ }
+ }
+
+ /**
+ * Sets up the fixture, for example, instantiate a mock object.
+ * This method is called before each test is executed.
+ * throws Exception on error.
+ *
+ * @example This method is usually overridden in your concrete test cases:
+ * TestCase
doesn't do anything on tearDown
,
+ * It's a good idea to call super.tearDown()
in your subclasses. Many projects
+ * wind up using some common fixtures which can often be extracted out a common project
+ * TestCase
.
+ *
+ * tearDown
is not called when we tell a test case to execute
+ * a single test method.
+ *
+ * @throws Error on error.
+ *
+ * @example This method is usually overridden in your concrete test cases:
+ * DisplayObjectContainer
that will be used by
+ * addChild
and removeChild
helper methods.
+ **/
+ public function getContext():DisplayObjectContainer {
+ return context;
+ }
+
+ /**
+ * Called from within setUp
or the body of any test method.
+ *
+ * Any call to addAsync
, will prevent test execution from continuing
+ * until the duration
(in milliseconds) is exceeded, or the function returned by addAsync
+ * is called. addAsync
can be called any number of times within a particular
+ * test method, and will block execution until each handler has returned.
+ *
+ * Following is an example of how to use the addAsync
feature:
+ * addAsync
block.
+ **/
+ protected function addAsync(handler:Function = null, duration:Number=DEFAULT_TIMEOUT, failureHandler:Function=null):Function {
+ if(handler == null) {
+ handler = function(args:*):* {return;};
+ }
+ var async:AsyncOperation = new AsyncOperation(this, handler, duration, failureHandler);
+ asyncQueue.push(async);
+ return async.getCallback();
+ }
+
+ internal function asyncOperationTimeout(async:AsyncOperation, duration:Number, isError:Boolean=true):void {
+ if(isError) getResult().addError(this, new IllegalOperationError("TestCase.timeout (" + duration + "ms) exceeded on an asynchronous operation."));
+ asyncOperationComplete(async);
+ }
+
+ internal function asyncOperationComplete(async:AsyncOperation):void{
+ // remove operation from queue
+ var i:int = asyncQueue.indexOf(async);
+ asyncQueue.splice(i,1);
+ // if we still need to wait, return
+ if(waitForAsync()) return;
+ if(currentState == SET_UP) {
+ runMethod(currentMethod);
+ }
+ else if(currentState == RUN_METHOD) {
+ runTearDown();
+ }
+ }
+
+ private function waitForAsync():Boolean{
+ return asyncQueue.length > 0;
+ }
+
+ protected function runTearDown():void {
+ if(currentState == TEAR_DOWN) {
+ return;
+ }
+ currentState = TEAR_DOWN;
+ if(isComplete) {
+ return;
+ }
+ if(!runSingle) {
+ getResult().endTestMethod(this, currentMethod);
+ tearDown();
+ layoutManager.resetAll();
+ }
+ setTimeout(runBare, 5);
+ }
+
+ /**
+ * Helper method for testing DisplayObject
s.
+ *
+ * This method allows you to more easily add and manage DisplayObject
+ * instances in your TestCase
.
+ *
+ * If you are using the regular TestRunner
, you cannot add Flex classes.
+ *
+ * If you are using a FlexRunner
base class, you can add either
+ * regular DisplayObject
s or IUIComponent
s.
+ *
+ * Usually, this method is called within setUp
, and removeChild
+ * is called from within tearDown
. Using these methods, ensures that added
+ * children will be subsequently removed, even when tests fail.
+ *
+ * Here is an example of the addChild
method:
+ * DisplayObject
s.
+ *
+ * Update: This method should no longer fail if the provided DisplayObject
+ * has already been removed.
+ **/
+ protected function removeChild(child:DisplayObject):DisplayObject {
+ if(child == null) {
+ return null;
+ }
+ try {
+ return getContext().removeChild(child);
+ }
+ catch(e:Error) {
+ }
+ return null;
+ }
+ }
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/asunit/framework/TestCaseExample.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/asunit/framework/TestCaseExample.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,73 @@
+package asunit.framework {
+ import asunit.framework.TestCase;
+ import flash.display.Sprite;
+ import flash.events.Event;
+ import flash.events.IEventDispatcher;
+ import flash.events.EventDispatcher;
+ import flash.utils.setTimeout;
+
+ // TestCase subclasses should always end with 'Test', the example
+ // doesn't because we don't want TestSuites in this directory.
+ public class TestCaseExample extends TestCase {
+ private var date:Date;
+ private var sprite:Sprite;
+
+ // TestCase constructors must be implemented as follows
+ // so that we can execute a single method on them from
+ // the TestRunner
+ public function TestCaseExample(testMethod:String = null) {
+ super(testMethod);
+ }
+
+ // This method will be called before every test method
+ override protected function setUp():void {
+ date = new Date();
+// sprite = new Sprite();
+// addChild(sprite);
+ }
+
+ // This method will be called after every test method
+ // but only if we're executing the entire TestCase,
+ // the tearDown method won't be called if we're
+ // calling start(MyTestCase, "someMethod");
+ override protected function tearDown():void {
+// removeChild(sprite);
+// sprite = null;
+ date = null;
+ }
+
+ // This is auto-created by the XULUI and ensures that
+ // our objects are actually created as we expect.
+ public function testInstantiated():void {
+ assertTrue("Date instantiated", date is Date);
+// assertTrue("Sprite instantiated", sprite is Sprite);
+ }
+
+ // This is an example of a typical test method
+ public function testMonthGetterSetter():void {
+ date.month = 1;
+ assertEquals(1, date.month);
+ }
+
+ // This is an asynchronous test method
+ public function testAsyncFeature():void {
+ // create a new object that dispatches events...
+ var dispatcher:IEventDispatcher = new EventDispatcher();
+ // get a TestCase async event handler reference
+ // the 2nd arg is an optional timeout in ms. (default=1000ms )
+ var handler:Function = addAsync(changeHandler, 2000);
+ // subscribe to your event dispatcher using the returned handler
+ dispatcher.addEventListener(Event.CHANGE, handler);
+ // cause the event to be dispatched.
+ // either immediately:
+ //dispatcher.dispatchEvent(new Event(Event.CHANGE));
+ // or in the future < your assigned timeout
+ setTimeout( dispatcher.dispatchEvent, 200, new Event(Event.CHANGE));
+ }
+
+ protected function changeHandler(event:Event):void {
+ // perform assertions in your handler
+ assertEquals(Event.CHANGE, event.type);
+ }
+ }
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/asunit/framework/TestFailure.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/asunit/framework/TestFailure.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,58 @@
+package asunit.framework {
+ import asunit.errors.AssertionFailedError;
+
+ /**
+ * A TestFailure
collects a failed test together with
+ * the caught exception.
+ * @see TestResult
+ */
+ public class TestFailure {
+ protected var fFailedTest:Test;
+ protected var fFailedTestMethod:String;
+ protected var fThrownException:Error;
+
+ /**
+ * Constructs a TestFailure with the given test and exception.
+ */
+ public function TestFailure(failedTest:Test, thrownException:Error) {
+ fFailedTest = failedTest;
+ fFailedTestMethod = failedTest.getCurrentMethod();
+ fThrownException = thrownException;
+ }
+
+ public function failedFeature():String {
+ return failedTest().getName() + '.' + fFailedTestMethod;
+ }
+
+ public function failedMethod():String {
+ return fFailedTestMethod;
+ }
+
+ /**
+ * Gets the failed test case.
+ */
+ public function failedTest():Test {
+ return fFailedTest;
+ }
+ /**
+ * Gets the thrown exception.
+ */
+ public function thrownException():Error {
+ return fThrownException;
+ }
+ /**
+ * Returns a short description of the failure.
+ */
+ public function toString():String {
+ return "";
+ }
+
+ public function exceptionMessage():String {
+ return thrownException().message;
+ }
+
+ public function isFailure():Boolean {
+ return thrownException() is AssertionFailedError;
+ }
+ }
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/asunit/framework/TestListener.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/asunit/framework/TestListener.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,35 @@
+package asunit.framework {
+ import asunit.errors.AssertionFailedError;
+
+ public interface TestListener {
+
+ /**
+ * Run the provided Test.
+ */
+ function run(test:Test):void;
+ /**
+ * A test started.
+ */
+ function startTest(test:Test):void;
+ /**
+ * A failure occurred.
+ */
+ function addFailure(test:Test, t:AssertionFailedError):void;
+ /**
+ * An error occurred.
+ */
+ function addError(test:Test, t:Error):void;
+ /**
+ * A test method has begun execution.
+ */
+ function startTestMethod(test:Test, methodName:String):void;
+ /**
+ * A test method has completed.
+ */
+ function endTestMethod(test:Test, methodName:String):void;
+ /**
+ * A test ended.
+ */
+ function endTest(test:Test):void;
+ }
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/asunit/framework/TestMethod.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/asunit/framework/TestMethod.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,38 @@
+package asunit.framework {
+
+ import flash.utils.getTimer;
+
+ /**
+ * A TestFailure
collects a failed test together with
+ * the caught exception.
+ * @see TestResult
+ */
+ public class TestMethod {
+ protected var test:Test;
+ protected var method:String;
+
+ private var _duration:Number;
+ private var start:Number;
+
+ /**
+ * Constructs a TestMethod with a given Test and method name.
+ */
+ public function TestMethod(test:Test, method:String) {
+ this.test = test;
+ this.method = method;
+ start = getTimer();
+ }
+
+ public function getName():String {
+ return method;
+ }
+
+ public function endTest(test:Test):void {
+ _duration = (getTimer() - start) * .001;
+ }
+
+ public function duration():Number {
+ return _duration;
+ }
+ }
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/asunit/framework/TestResult.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/asunit/framework/TestResult.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,174 @@
+package asunit.framework {
+ import asunit.errors.AssertionFailedError;
+ import asunit.errors.InstanceNotFoundError;
+
+ /**
+ * A TestResult
collects the results of executing
+ * a test case. It is an instance of the Collecting Parameter pattern.
+ * The test framework distinguishes between failures and errors.
+ * A failure is anticipated and checked for with assertions. Errors are
+ * unanticipated problems like an ArrayIndexOutOfBoundsException
.
+ *
+ * @see Test
+ */
+ public class TestResult implements TestListener {
+ protected var fFailures:Array;
+ protected var fErrors:Array;
+ protected var fListeners:Array;
+ protected var fRunTests:int;
+ private var fStop:Boolean;
+
+ public function TestResult() {
+ fFailures = new Array();
+ fErrors = new Array();
+ fListeners = new Array();
+ fRunTests = 0;
+ fStop = false;
+ }
+ /**
+ * Adds an error to the list of errors. The passed in exception
+ * caused the error.
+ */
+ public function addError(test:Test, t:Error):void {
+ fErrors.push(new TestFailure(test, t));
+ var len:uint = fListeners.length;
+ var item:TestListener;
+ for(var i:uint; i < len; i++) {
+ item = TestListener(fListeners[i]);
+ item.addError(test, t);
+ }
+ }
+ /**
+ * Adds a failure to the list of failures. The passed in exception
+ * caused the failure.
+ */
+ public function addFailure(test:Test, t:AssertionFailedError):void {
+ fFailures.push(new TestFailure(test, t));
+ var len:uint = fListeners.length;
+ var item:TestListener;
+ for(var i:uint; i < len; i++) {
+ item = TestListener(fListeners[i]);
+ item.addFailure(test, t);
+ }
+ }
+ /**
+ * Registers a TestListener
+ */
+ public function addListener(listener:TestListener):void {
+ fListeners.push(listener);
+ }
+ /**
+ * Unregisters a TestListener
+ */
+ public function removeListener(listener:TestListener):void {
+ var len:uint = fListeners.length;
+ for(var i:uint; i < len; i++) {
+ if(fListeners[i] == listener) {
+ fListeners.splice(i, 1);
+ return;
+ }
+ }
+ throw new InstanceNotFoundError("removeListener called without listener in list");
+ }
+ /**
+ * Gets the number of detected errors.
+ */
+ public function errorCount():int {
+ return fErrors.length;
+ }
+ /**
+ * Returns an Enumeration for the errors
+ */
+ public function errors():Array {
+ return fErrors;
+ }
+ /**
+ * Gets the number of detected failures.
+ */
+ public function failureCount():int {
+ return fFailures.length;
+ }
+ /**
+ * Returns an Enumeration for the failures
+ */
+ public function failures():Array {
+ return fFailures;
+ }
+
+ /**
+ * Runs a TestCase.
+ */
+ public function run(test:Test):void {
+ startTest(test);
+ test.runBare();
+ }
+ /**
+ * Gets the number of run tests.
+ */
+ public function runCount():int {
+ return fRunTests;
+ }
+ /**
+ * Checks whether the test run should stop
+ */
+ public function shouldStop():Boolean {
+ return fStop;
+ }
+ /**
+ * Informs the result that a test will be started.
+ */
+ public function startTest(test:Test):void {
+ var count:int = test.countTestCases();
+ fRunTests += count;
+
+ var len:uint = fListeners.length;
+ var item:TestListener;
+ for(var i:uint; i < len; i++) {
+ item = TestListener(fListeners[i]);
+ item.startTest(test);
+ }
+ }
+
+ public function startTestMethod(test:Test, method:String):void {
+ var len:uint = fListeners.length;
+ var item:TestListener;
+ for(var i:uint; i < len; i++) {
+ item = TestListener(fListeners[i]);
+ item.startTestMethod(test, method);
+ }
+ }
+
+ public function endTestMethod(test:Test, method:String):void {
+ var len:uint = fListeners.length;
+ var item:TestListener;
+ for(var i:uint; i < len; i++) {
+ item = TestListener(fListeners[i]);
+ item.endTestMethod(test, method);
+ }
+ }
+
+ /**
+ * Informs the result that a test was completed.
+ */
+ public function endTest(test:Test):void {
+ var len:uint = fListeners.length;
+ var item:TestListener;
+ for(var i:uint; i < len; i++) {
+ item = TestListener(fListeners[i]);
+ item.endTest(test);
+ }
+ }
+ /**
+ * Marks that the test run should stop.
+ */
+ public function stop():void {
+ fStop = true;
+ }
+ /**
+ * Returns whether the entire test was successful or not.
+ */
+ public function wasSuccessful():Boolean {
+ return failureCount() == 0 && errorCount() == 0;
+ }
+ }
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/asunit/framework/TestSuite.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/asunit/framework/TestSuite.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,113 @@
+package asunit.framework {
+ import asunit.util.ArrayIterator;
+ import asunit.util.Iterator;
+
+ import flash.display.DisplayObjectContainer;
+ import flash.events.Event;
+
+ /**
+ * A TestSuite
is a Composite
of Tests.
+ *
+ * @see Test
+ * @see TestCase
+ *
+ * @includeExample TestSuiteExample.as
+ */
+ public class TestSuite extends TestCase implements Test {
+ private var fTests:Array = new Array();
+ private var testsCompleteCount:Number = 0;
+ private var iterator:ArrayIterator;
+ private var isRunning:Boolean;
+
+ public function TestSuite() {
+ super();
+ fTests = new Array();
+ }
+
+ protected override function setTestMethods(methodNodes:XMLList):void {
+ testMethods = new Array();
+ }
+
+ /**
+ * Adds a test instance to the suite.
+ */
+ public function addTest(test:Test):void {
+ if (!test.getIsComplete())
+ fTests.push(test);
+ }
+
+ /**
+ * Counts the number of tests that will be run by this Suite.
+ */
+ public override function countTestCases():int {
+ var count:int;
+ for each(var test:TestCase in fTests) {
+ count = count + test.countTestCases();
+ }
+ return count;
+ }
+
+ /**
+ * Runs the tests and collects their result in a TestResult.
+ */
+ public override function run():void {
+ var result:TestListener = getResult();
+ var test:Test;
+ var itr:Iterator = getIterator();
+ while(itr.hasNext()) {
+ isRunning = true;
+ test = Test(itr.next());
+ test.setResult(result);
+ test.addEventListener(Event.COMPLETE, testCompleteHandler);
+ test.run();
+ if(!test.getIsComplete()) {
+ isRunning = false;
+ break;
+ }
+ }
+ }
+
+ private function getIterator():ArrayIterator {
+ if(iterator == null) {
+ iterator = new ArrayIterator(fTests);
+ }
+ return iterator;
+ }
+
+ private function testCompleteHandler(event:Event):void {
+ if(!isRunning) {
+ run();
+ }
+ if(++testsCompleteCount >= testCount()) {
+ dispatchEvent(new Event(Event.COMPLETE));
+ }
+ }
+
+ /**
+ * Returns the number of tests in this suite
+ */
+ public function testCount():int {
+ return fTests.length;
+ }
+
+ public override function toString():String {
+ return getName();
+ }
+
+ public override function getIsComplete():Boolean {
+ for each(var test:TestCase in fTests) {
+ if(!test.getIsComplete()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public override function setContext(context:DisplayObjectContainer):void {
+ super.setContext(context);
+ for each(var test:Test in fTests) {
+ test.setContext(context);
+ }
+ }
+ }
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/asunit/runner/BaseTestRunner.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/asunit/runner/BaseTestRunner.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,15 @@
+package asunit.runner {
+ import flash.display.Sprite;
+
+ /**
+ * Base class for all test runners.
+ * This class was born live on stage in Sardinia during XP2000.
+ */
+ public class BaseTestRunner extends Sprite {
+
+ // Filters stack frames from internal JUnit classes
+ public static function getFilteredTrace(stack:String):String {
+ return stack;
+ }
+ }
+ }
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/asunit/runner/TestSuiteLoader.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/asunit/runner/TestSuiteLoader.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,9 @@
+package asunit.runner {
+
+ public interface TestSuiteLoader {
+ // throws ClassNotFoundException
+ function load(suiteClassName:String):Class;
+ // throws ClassNotFoundException
+ function reload(aClass:Class):Class;
+ }
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/asunit/runner/Version.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/asunit/runner/Version.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,11 @@
+package asunit.runner {
+
+ public class Version {
+ private static var version:String = "3.0";
+
+ public static function id():String {
+ return version.toString();
+ }
+
+ }
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/asunit/textui/FlexRunner.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/asunit/textui/FlexRunner.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,25 @@
+package asunit.textui {
+ import asunit.framework.TestResult;
+
+ import mx.core.Application;
+
+ /**
+ * The FlexTestRunner
should be the base class for your
+ * test harness if you're testing a project that uses Flex components.
+ *
+ * @includeExample FlexRunnerExample.mxml
+ **/
+ public class FlexRunner extends Application {
+ protected var runner:TestRunner;
+
+ override protected function createChildren():void {
+ super.createChildren();
+ runner = new FlexTestRunner();
+ rawChildren.addChild(runner);
+ }
+
+ public function start(testCase:Class, testMethod:String = null, showTrace:Boolean = false):TestResult {
+ return runner.start(testCase, testMethod, showTrace);
+ }
+ }
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/asunit/textui/FlexTestRunner.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/asunit/textui/FlexTestRunner.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,58 @@
+package asunit.textui {
+ import flash.display.DisplayObject;
+ import flash.events.Event;
+ import mx.core.IUIComponent;
+ import asunit.textui.TestRunner;
+
+ /**
+ * @private
+ **/
+ public class FlexTestRunner extends TestRunner {
+
+ public function FlexTestRunner() {
+ setPrinter(new ResultPrinter());
+ }
+
+ protected override function addedHandler(event:Event):void {
+ if(event.target === this) {
+ parent.addEventListener(Event.RESIZE, resizeHandler);
+ resizeHandler(new Event(Event.RESIZE));
+ }
+ else {
+ event.stopPropagation();
+ }
+ }
+
+ public override function set width(w:Number):void {
+ fPrinter.width = w;
+ }
+
+ public override function set height(h:Number):void {
+ fPrinter.height = h;
+ }
+
+ public function resizeHandler(event:Event):void {
+ width = parent.width;
+ height = parent.height;
+ }
+
+ public override function addChild(child:DisplayObject):DisplayObject {
+ if(parent && child is IUIComponent) {
+ // AND check for 'is' UIUComponent...
+ return parent.addChild(child);
+ }
+ else {
+ return super.addChild(child);
+ }
+ }
+
+ public override function removeChild(child:DisplayObject):DisplayObject {
+ if(child is IUIComponent) {
+ return parent.removeChild(child);
+ }
+ else {
+ return super.removeChild(child);
+ }
+ }
+ }
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/asunit/textui/ResultPrinter.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/asunit/textui/ResultPrinter.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,298 @@
+package asunit.textui {
+ import asunit.errors.AssertionFailedError;
+ import asunit.framework.Test;
+ import asunit.framework.TestFailure;
+ import asunit.framework.TestListener;
+ import asunit.framework.TestResult;
+ import asunit.runner.BaseTestRunner;
+ import asunit.runner.Version;
+
+ import flash.display.Sprite;
+ import flash.events.*;
+ import flash.system.Capabilities;
+ import flash.text.TextField;
+ import flash.text.TextFormat;
+ import flash.utils.getTimer;
+ import flash.utils.setInterval;
+ import flash.utils.setTimeout;
+
+ /**
+ * This is the base class for collecting test output and formatting for different
+ * displays.
+ *
+ * This class simply presents test results as if they were being shown on a terminal.
+ *
+ * The XMLResultPrinter
provides a good example of how this class can
+ * be subclassed and used to emit different/additional output.
+ *
+ * @see XMLResultPrinter
+ **/
+ public class ResultPrinter extends Sprite implements TestListener {
+ private var fColumn:int = 0;
+ private var textArea:TextField;
+ private var gutter:uint = 0;
+ private var backgroundColor:uint = 0x333333;
+ private var bar:SuccessBar;
+ private var barHeight:Number = 3;
+ private var showTrace:Boolean;
+ protected var startTime:Number;
+ protected var testTimes:Array;
+
+ public function ResultPrinter(showTrace:Boolean = false) {
+ this.showTrace = showTrace;
+ testTimes = new Array();
+ configureAssets();
+ println();
+
+ // Create a loop so that the FDBTask
+ // can halt execution properly:
+ setInterval(function():void {
+ }, 500);
+ }
+
+ private function configureAssets():void {
+ textArea = new TextField();
+ textArea.background = true;
+ textArea.backgroundColor = backgroundColor;
+ textArea.border = true;
+ textArea.wordWrap = true;
+ var format:TextFormat = new TextFormat();
+ format.font = "Verdana";
+ format.size = 10;
+ format.color = 0xFFFFFF;
+ textArea.defaultTextFormat = format;
+ addChild(textArea);
+ println("AsUnit " + Version.id() + " by Luke Bayes and Ali Mills");
+ println("");
+ println("Flash Player version: " + Capabilities.version);
+
+ bar = new SuccessBar();
+ addChild(bar);
+ }
+
+ public function setShowTrace(showTrace:Boolean):void {
+ this.showTrace = showTrace;
+ }
+
+ public override function set width(w:Number):void {
+ textArea.x = gutter;
+ textArea.width = w - gutter*2;
+ bar.x = gutter;
+ bar.width = textArea.width;
+ }
+
+ public override function set height(h:Number):void {
+ textArea.height = h - ((gutter*2) + barHeight);
+ textArea.y = gutter;
+ bar.y = h - (gutter + barHeight);
+ bar.height = barHeight;
+ }
+
+ public function println(...args:Array):void {
+ textArea.appendText(args.toString() + "\n");
+ }
+
+ public function print(...args:Array):void {
+ textArea.appendText(args.toString());
+ }
+
+ /**
+ * API for use by textui.TestRunner
+ */
+
+ public function run(test:Test):void {
+ }
+
+ public function printResult(result:TestResult, runTime:Number):void {
+ printHeader(runTime);
+ printErrors(result);
+ printFailures(result);
+ printFooter(result);
+
+ bar.setSuccess(result.wasSuccessful());
+ if(showTrace) {
+ trace(textArea.text.split("\r").join("\n"));
+ }
+ }
+
+ /* Internal methods
+ */
+ protected function printHeader(runTime:Number):void {
+ println();
+ println();
+ println("Time: " + elapsedTimeAsString(runTime));
+ }
+
+ protected function printErrors(result:TestResult):void {
+ printDefects(result.errors(), result.errorCount(), "error");
+ }
+
+ protected function printFailures(result:TestResult):void {
+ printDefects(result.failures(), result.failureCount(), "failure");
+ }
+
+ protected function printDefects(booBoos:Object, count:int, type:String):void {
+ if (count == 0) {
+ return;
+ }
+ if (count == 1) {
+ println("There was " + count + " " + type + ":");
+ }
+ else {
+ println("There were " + count + " " + type + "s:");
+ }
+ var i:uint;
+ for each (var item:TestFailure in booBoos) {
+ printDefect(TestFailure(item), i);
+ i++;
+ }
+ }
+
+ public function printDefect(booBoo:TestFailure, count:int ):void { // only public for testing purposes
+ printDefectHeader(booBoo, count);
+ printDefectTrace(booBoo);
+ }
+
+ protected function printDefectHeader(booBoo:TestFailure, count:int):void {
+ // I feel like making this a println, then adding a line giving the throwable a chance to print something
+ // before we get to the stack trace.
+ var startIndex:uint = textArea.text.length;
+ println(count + ") " + booBoo.failedFeature());
+ var endIndex:uint = textArea.text.length;
+
+ var format:TextFormat = textArea.getTextFormat();
+ format.bold = true;
+
+ // GROSS HACK because of bug in flash player - TextField isn't accepting formats...
+ setTimeout(onFormatTimeout, 1, format, startIndex, endIndex);
+ }
+
+ public function onFormatTimeout(format:TextFormat, startIndex:uint, endIndex:uint):void {
+ textArea.setTextFormat(format, startIndex, endIndex);
+ }
+
+ protected function printDefectTrace(booBoo:TestFailure):void {
+ println(BaseTestRunner.getFilteredTrace(booBoo.thrownException().getStackTrace()));
+ }
+
+ protected function printFooter(result:TestResult):void {
+ println();
+ if (result.wasSuccessful()) {
+ print("OK");
+ println (" (" + result.runCount() + " test" + (result.runCount() == 1 ? "": "s") + ")");
+ } else {
+ println("FAILURES!!!");
+ println("Tests run: " + result.runCount()+
+ ", Failures: "+result.failureCount()+
+ ", Errors: "+result.errorCount());
+ }
+
+ printTimeSummary();
+ println();
+ }
+
+ protected function printTimeSummary():void {
+ testTimes.sortOn('duration', Array.NUMERIC | Array.DESCENDING);
+ println();
+ println();
+ println('Time Summary:');
+ println();
+ var len:Number = testTimes.length;
+ for(var i:Number = 0; i < len; i++) {
+ println(testTimes[i].toString());
+ }
+ }
+
+ /**
+ * Returns the formatted string of the elapsed time.
+ * Duplicated from BaseTestRunner. Fix it.
+ */
+ protected function elapsedTimeAsString(runTime:Number):String {
+ return Number(runTime/1000).toString();
+ }
+
+ /**
+ * @see asunit.framework.TestListener#addError(Test, Throwable)
+ */
+ public function addError(test:Test, t:Error):void {
+ print("E");
+ }
+
+ /**
+ * @see asunit.framework.TestListener#addFailure(Test, AssertionFailedError)
+ */
+ public function addFailure(test:Test, t:AssertionFailedError):void {
+ print("F");
+ }
+
+ /**
+ * @see asunit.framework.TestListener#endTestMethod(test, testMethod);
+ */
+ public function startTestMethod(test:Test, methodName:String):void {
+ }
+
+ /**
+ * @see asunit.framework.TestListener#endTestMethod(test, testMethod);
+ */
+ public function endTestMethod(test:Test, methodName:String):void {
+ }
+
+ /**
+ * @see asunit.framework.TestListener#startTest(Test)
+ */
+ public function startTest(test:Test):void {
+ startTime = getTimer();
+ var count:uint = test.countTestCases();
+ for(var i:uint; i < count; i++) {
+ print(".");
+ if (fColumn++ >= 80) {
+ println();
+ fColumn = 0;
+ }
+ }
+ }
+
+ /**
+ * @see asunit.framework.TestListener#endTest(Test)
+ */
+ public function endTest(test:Test):void {
+ var duration:Number = getTimer() - startTime;
+ testTimes.push(TestTime.create(test, duration));
+ }
+ }
+}
+
+import flash.display.Sprite;
+
+class SuccessBar extends Sprite {
+ private var myWidth:uint;
+ private var myHeight:uint;
+ private var bgColor:uint;
+ private var passingColor:uint = 0x00FF00;
+ private var failingColor:uint = 0xFD0000;
+
+ public function SuccessBar() {
+ }
+
+ public function setSuccess(success:Boolean):void {
+ bgColor = (success) ? passingColor : failingColor;
+ draw();
+ }
+
+ public override function set width(num:Number):void {
+ myWidth = num;
+ draw();
+ }
+
+ public override function set height(num:Number):void {
+ myHeight = num;
+ draw();
+ }
+
+ private function draw():void {
+ graphics.clear();
+ graphics.beginFill(bgColor);
+ graphics.drawRect(0, 0, myWidth, myHeight);
+ graphics.endFill();
+ }
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/asunit/textui/TestRunner.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/asunit/textui/TestRunner.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,174 @@
+package asunit.textui {
+ import asunit.framework.Test;
+ import asunit.framework.TestResult;
+
+ import flash.display.MovieClip;
+ import flash.display.StageAlign;
+ import flash.display.StageScaleMode;
+ import flash.events.Event;
+ import flash.system.fscommand;
+ import flash.utils.clearInterval;
+ import flash.utils.describeType;
+ import flash.utils.getTimer;
+ import flash.utils.setInterval;
+ import flash.utils.Timer;
+ import flash.events.TimerEvent;
+ import flash.display.DisplayObject;
+
+ /**
+ * The base class for ActionScript 3.0 test harness.
+ *
+ * The TestRunner
should be extended by your
+ * concrete runner for your project.
+ *
+ * If you're building a Flex application, you will need to
+ * extend the FlexRunner
+ *
+ * Your concrete runner will usually look like the following:
+ * TestCase
or TestSuite
provided.
+ *
+ * If a concrete TestCase
is provided to the start
method,
+ * you can also provide the string name of a single test method to execute.
+ *
+ * This will run the TestCase
setUp
method, then
+ * the test method name that was provided, and will not run tearDown
.
+ *
+ * This is a great way to build visual components in isolation and verify that they
+ * behave as expected.
+ *
+ * @example The start method can accept a concrete test case and test method name:
+ * XMLResultPrinter
is used to transform AsUnit test results
+ * to JUnit-compatible XML content.
+ *
+ * This printer will send JUnit-compatible XML content to trace output. The XML content
+ * will be enclosed by '<XMLResultPrinter/>' tags.
+ *
+ * @includeExample XMLResultPrinterExample.as
+ * @includeExample XMLResultPrinterExample.xml
+ **/
+ public class XMLResultPrinter extends ResultPrinter {
+
+ protected var results:Dictionary;
+
+ public function XMLResultPrinter() {
+ results = new Dictionary();
+ }
+
+ override public function startTest(test:Test):void {
+ super.startTest(test);
+ var result:TestListener = new XMLTestResult(test);
+ results[test.getName()] = result;
+ result.startTest(test);
+ }
+
+ override public function endTest(test:Test):void {
+ super.endTest(test);
+ results[test.getName()].endTest(test);
+ }
+
+ override public function startTestMethod(test:Test, methodName:String):void {
+ super.startTestMethod(test, methodName);
+ results[test.getName()].startTestMethod(test, methodName);
+ }
+
+ override public function endTestMethod(test:Test, methodName:String):void {
+ super.endTestMethod(test, methodName);
+ results[test.getName()].endTestMethod(test, methodName);
+ }
+
+ override public function addFailure(test:Test, t:AssertionFailedError):void {
+ super.addFailure(test, t);
+ results[test.getName()].addFailure(test, t);
+ }
+
+ override public function addError(test:Test, t:Error):void {
+ super.addError(test, t);
+ results[test.getName()].addError(test, t);
+ }
+
+ override public function printResult(result:TestResult, runTime:Number):void {
+ super.printResult(result, runTime);
+ trace("
+ * http://www.site.com/
+ * http://www.site.net/
+ *
The application can provide an implementation that automatically + * resolves site.net to site.com before URI compares two URI objects. + * Only the application can know and understand the context in which + * the URI's are being used.
+ * + *Use the URI.resolver accessor to assign a custom resolver to + * the URI class. Any resolver specified is global to all instances + * of URI.
+ * + *URI will call this before performing URI comparisons in the + * URI.getRelation() and URI.getCommonParent() functions. + * + * @see URI.getRelation + * @see URI.getCommonParent + * + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0 + */ + public interface IURIResolver + { + /** + * Implement this method to provide custom URI resolution for + * your application. + * + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0 + */ + function resolve(uri:URI) : URI; + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/net/MimeTypeMap.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/net/MimeTypeMap.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,200 @@ +/* + Copyright (c) 2008, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +package com.adobe.net +{ + public class MimeTypeMap + { + private var types:Array = + [["application/andrew-inset","ez"], + ["application/atom+xml","atom"], + ["application/mac-binhex40","hqx"], + ["application/mac-compactpro","cpt"], + ["application/mathml+xml","mathml"], + ["application/msword","doc"], + ["application/octet-stream","bin","dms","lha","lzh","exe","class","so","dll","dmg"], + ["application/oda","oda"], + ["application/ogg","ogg"], + ["application/pdf","pdf"], + ["application/postscript","ai","eps","ps"], + ["application/rdf+xml","rdf"], + ["application/smil","smi","smil"], + ["application/srgs","gram"], + ["application/srgs+xml","grxml"], + ["application/vnd.adobe.apollo-application-installer-package+zip","air"], + ["application/vnd.mif","mif"], + ["application/vnd.mozilla.xul+xml","xul"], + ["application/vnd.ms-excel","xls"], + ["application/vnd.ms-powerpoint","ppt"], + ["application/vnd.rn-realmedia","rm"], + ["application/vnd.wap.wbxml","wbxml"], + ["application/vnd.wap.wmlc","wmlc"], + ["application/vnd.wap.wmlscriptc","wmlsc"], + ["application/voicexml+xml","vxml"], + ["application/x-bcpio","bcpio"], + ["application/x-cdlink","vcd"], + ["application/x-chess-pgn","pgn"], + ["application/x-cpio","cpio"], + ["application/x-csh","csh"], + ["application/x-director","dcr","dir","dxr"], + ["application/x-dvi","dvi"], + ["application/x-futuresplash","spl"], + ["application/x-gtar","gtar"], + ["application/x-hdf","hdf"], + ["application/x-javascript","js"], + ["application/x-koan","skp","skd","skt","skm"], + ["application/x-latex","latex"], + ["application/x-netcdf","nc","cdf"], + ["application/x-sh","sh"], + ["application/x-shar","shar"], + ["application/x-shockwave-flash","swf"], + ["application/x-stuffit","sit"], + ["application/x-sv4cpio","sv4cpio"], + ["application/x-sv4crc","sv4crc"], + ["application/x-tar","tar"], + ["application/x-tcl","tcl"], + ["application/x-tex","tex"], + ["application/x-texinfo","texinfo","texi"], + ["application/x-troff","t","tr","roff"], + ["application/x-troff-man","man"], + ["application/x-troff-me","me"], + ["application/x-troff-ms","ms"], + ["application/x-ustar","ustar"], + ["application/x-wais-source","src"], + ["application/xhtml+xml","xhtml","xht"], + ["application/xml","xml","xsl"], + ["application/xml-dtd","dtd"], + ["application/xslt+xml","xslt"], + ["application/zip","zip"], + ["audio/basic","au","snd"], + ["audio/midi","mid","midi","kar"], + ["audio/mp4","f4a"], + ["audio/mp4","f4b"], + ["audio/mpeg","mp3","mpga","mp2"], + ["audio/x-aiff","aif","aiff","aifc"], + ["audio/x-mpegurl","m3u"], + ["audio/x-pn-realaudio","ram","ra"], + ["audio/x-wav","wav"], + ["chemical/x-pdb","pdb"], + ["chemical/x-xyz","xyz"], + ["image/bmp","bmp"], + ["image/cgm","cgm"], + ["image/gif","gif"], + ["image/ief","ief"], + ["image/jpeg","jpg","jpeg","jpe"], + ["image/png","png"], + ["image/svg+xml","svg"], + ["image/tiff","tiff","tif"], + ["image/vnd.djvu","djvu","djv"], + ["image/vnd.wap.wbmp","wbmp"], + ["image/x-cmu-raster","ras"], + ["image/x-icon","ico"], + ["image/x-portable-anymap","pnm"], + ["image/x-portable-bitmap","pbm"], + ["image/x-portable-graymap","pgm"], + ["image/x-portable-pixmap","ppm"], + ["image/x-rgb","rgb"], + ["image/x-xbitmap","xbm"], + ["image/x-xpixmap","xpm"], + ["image/x-xwindowdump","xwd"], + ["model/iges","igs","iges"], + ["model/mesh","msh","mesh","silo"], + ["model/vrml","wrl","vrml"], + ["text/calendar","ics","ifb"], + ["text/css","css"], + ["text/html","html","htm"], + ["text/plain","txt","asc"], + ["text/richtext","rtx"], + ["text/rtf","rtf"], + ["text/sgml","sgml","sgm"], + ["text/tab-separated-values","tsv"], + ["text/vnd.wap.wml","wml"], + ["text/vnd.wap.wmlscript","wmls"], + ["text/x-setext","etx"], + ["video/mp4","f4v"], + ["video/mp4","f4p"], + ["video/mpeg","mpg","mpeg","mpe"], + ["video/quicktime","mov","qt"], + ["video/vnd.mpegurl","m4u","mxu"], + ["video/x-flv","flv"], + ["video/x-msvideo","avi"], + ["video/x-sgi-movie","movie"], + ["x-conference/x-cooltalk","ice"]]; + + /** + * Returns the mimetype for the given extension. + */ + public function getMimeType(extension:String):String + { + extension = extension.toLocaleLowerCase(); + for each (var a:Array in types) + { + for each (var b:String in a) + { + if (b == extension) + { + return a[0]; + } + } + } + return null; + } + + /** + * Returns the prefered extension for the given mimetype. + */ + public function getExtension(mimetype:String):String + { + mimetype = mimetype.toLocaleLowerCase(); + for each (var a:Array in types) + { + if (a[0] == mimetype) + { + return a[1]; + } + } + return null; + } + + /** + * Adds a mimetype to the map. The order of the extensions matters. The most preferred should come first. + */ + public function addMimeType(mimetype:String, extensions:Array):void + { + var newType:Array = [mimetype]; + for each (var a:String in extensions) + { + newType.push(a); + } + types.push(newType); + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/net/URI.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/net/URI.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,2466 @@ +/* + Copyright (c) 2008, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.net +{ + import flash.utils.ByteArray; + + /** + * This class implements functions and utilities for working with URI's + * (Universal Resource Identifiers). For technical description of the + * URI syntax, please see RFC 3986 at http://www.ietf.org/rfc/rfc3986.txt + * or do a web search for "rfc 3986". + * + *
The most important aspect of URI's to understand is that URI's + * and URL's are not strings. URI's are complex data structures that + * encapsulate many pieces of information. The string version of a + * URI is the serialized representation of that data structure. This + * string serialization is used to provide a human readable + * representation and a means to transport the data over the network + * where it can then be parsed back into its' component parts.
+ * + *URI's fall into one of three categories: + *
The query and fragment parts are optional.
+ * + *This class supports both non-hierarchical and hierarchical URI's
+ * + *This class is intended to be used "as-is" for the vast majority + * of common URI's. However, if your application requires a custom + * URI syntax (e.g. custom query syntax or special handling of + * non-hierarchical URI's), this class can be fully subclassed. If you + * intended to subclass URI, please see the source code for complete + * documation on protected members and protected fuctions.
+ * + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0 + */ + public class URI + { + // Here we define which characters must be escaped for each + // URI part. The characters that must be escaped for each + // part differ depending on what would cause ambiguous parsing. + // RFC 3986 sec. 2.4 states that characters should only be + // encoded when they would conflict with subcomponent delimiters. + // We don't want to over-do the escaping. We only want to escape + // the minimum needed to prevent parsing problems. + + // space and % must be escaped in all cases. '%' is the delimiter + // for escaped characters. + public static const URImustEscape:String = " %"; + + // Baseline of what characters must be escaped + public static const URIbaselineEscape:String = URImustEscape + ":?#/@"; + + // Characters that must be escaped in the part part. + public static const URIpathEscape:String = URImustEscape + "?#"; + + // Characters that must be escaped in the query part, if setting + // the query as a whole string. If the query is set by + // name/value, URIqueryPartEscape is used instead. + public static const URIqueryEscape:String = URImustEscape + "#"; + + // This is what each name/value pair must escape "&=" as well + // so they don't conflict with the "param=value¶m2=value2" + // syntax. + public static const URIqueryPartEscape:String = URImustEscape + "#&="; + + // Non-hierarchical URI's can have query and fragment parts, but + // we also want to prevent '/' otherwise it might end up looking + // like a hierarchical URI to the parser. + public static const URInonHierEscape:String = URImustEscape + "?#/"; + + // Baseline uninitialized setting for the URI scheme. + public static const UNKNOWN_SCHEME:String = "unknown"; + + // The following bitmaps are used for performance enhanced + // character escaping. + + // Baseline characters that need to be escaped. Many parts use + // this. + protected static const URIbaselineExcludedBitmap:URIEncodingBitmap = + new URIEncodingBitmap(URIbaselineEscape); + + // Scheme escaping bitmap + protected static const URIschemeExcludedBitmap:URIEncodingBitmap = + URIbaselineExcludedBitmap; + + // User/pass escaping bitmap + protected static const URIuserpassExcludedBitmap:URIEncodingBitmap = + URIbaselineExcludedBitmap; + + // Authority escaping bitmap + protected static const URIauthorityExcludedBitmap:URIEncodingBitmap = + URIbaselineExcludedBitmap; + + // Port escaping bitmap + protected static const URIportExludedBitmap:URIEncodingBitmap = + URIbaselineExcludedBitmap; + + // Path escaping bitmap + protected static const URIpathExcludedBitmap:URIEncodingBitmap = + new URIEncodingBitmap(URIpathEscape); + + // Query (whole) escaping bitmap + protected static const URIqueryExcludedBitmap:URIEncodingBitmap = + new URIEncodingBitmap(URIqueryEscape); + + // Query (individual parts) escaping bitmap + protected static const URIqueryPartExcludedBitmap:URIEncodingBitmap = + new URIEncodingBitmap(URIqueryPartEscape); + + // Fragments are the last part in the URI. They only need to + // escape space, '#', and '%'. Turns out that is what query + // uses too. + protected static const URIfragmentExcludedBitmap:URIEncodingBitmap = + URIqueryExcludedBitmap; + + // Characters that need to be escaped in the non-hierarchical part + protected static const URInonHierexcludedBitmap:URIEncodingBitmap = + new URIEncodingBitmap(URInonHierEscape); + + // Values used by getRelation() + public static const NOT_RELATED:int = 0; + public static const CHILD:int = 1; + public static const EQUAL:int = 2; + public static const PARENT:int = 3; + + //------------------------------------------------------------------- + // protected class members + //------------------------------------------------------------------- + protected var _valid:Boolean = false; + protected var _relative:Boolean = false; + protected var _scheme:String = ""; + protected var _authority:String = ""; + protected var _username:String = ""; + protected var _password:String = ""; + protected var _port:String = ""; + protected var _path:String = ""; + protected var _query:String = ""; + protected var _fragment:String = ""; + protected var _nonHierarchical:String = ""; + protected static var _resolver:IURIResolver = null; + + + /** + * URI Constructor. If no string is given, this will initialize + * this URI object to a blank URI. + */ + public function URI(uri:String = null) : void + { + if (uri == null) + initialize(); + else + constructURI(uri); + } + + + /** + * @private + * Method that loads the URI from the given string. + */ + protected function constructURI(uri:String) : Boolean + { + if (!parseURI(uri)) + _valid = false; + + return isValid(); + } + + + /** + * @private Private initializiation. + */ + protected function initialize() : void + { + _valid = false; + _relative = false; + + _scheme = UNKNOWN_SCHEME; + _authority = ""; + _username = ""; + _password = ""; + _port = ""; + _path = ""; + _query = ""; + _fragment = ""; + + _nonHierarchical = ""; + } + + /** + * @private Accessor to explicitly set/get the hierarchical + * state of the URI. + */ + protected function set hierState(state:Boolean) : void + { + if (state) + { + // Clear the non-hierarchical data + _nonHierarchical = ""; + + // Also set the state vars while we are at it + if (_scheme == "" || _scheme == UNKNOWN_SCHEME) + _relative = true; + else + _relative = false; + + if (_authority.length == 0 && _path.length == 0) + _valid = false; + else + _valid = true; + } + else + { + // Clear the hierarchical data + _authority = ""; + _username = ""; + _password = ""; + _port = ""; + _path = ""; + + _relative = false; + + if (_scheme == "" || _scheme == UNKNOWN_SCHEME) + _valid = false; + else + _valid = true; + } + } + protected function get hierState() : Boolean + { + return (_nonHierarchical.length == 0); + } + + + /** + * @private Functions that performs some basic consistency validation. + */ + protected function validateURI() : Boolean + { + // Check the scheme + if (isAbsolute()) + { + if (_scheme.length <= 1 || _scheme == UNKNOWN_SCHEME) + { + // we probably parsed a C:\ type path or no scheme + return false; + } + else if (verifyAlpha(_scheme) == false) + return false; // Scheme contains bad characters + } + + if (hierState) + { + if (_path.search('\\') != -1) + return false; // local path + else if (isRelative() == false && _scheme == UNKNOWN_SCHEME) + return false; // It's an absolute URI, but it has a bad scheme + } + else + { + if (_nonHierarchical.search('\\') != -1) + return false; // some kind of local path + } + + // Looks like it's ok. + return true; + } + + + /** + * @private + * + * Given a URI in string format, parse that sucker into its basic + * components and assign them to this object. A URI is of the form: + *The URI specification allows for authentication + * credentials to be embedded in the URI as such:
+ * + *http://user:passwd@host/path/to/file.htm
+ * + *When setting this value, the string + * given is assumed to be unescaped. When retrieving this + * value, the resulting string is unescaped.
+ */ + public function get username() : String + { + return URI.unescapeChars(_username); + } + public function set username(usernameStr:String) : void + { + _username = URI.fastEscapeChars(usernameStr, URI.URIuserpassExcludedBitmap); + + // Only hierarchical URI's can have a username. + this.hierState = true; + } + + + /** + * The password of the URI. Similar to username. + * @see URI.username + */ + public function get password() : String + { + return URI.unescapeChars(_password); + } + public function set password(passwordStr:String) : void + { + _password = URI.fastEscapeChars(passwordStr, + URI.URIuserpassExcludedBitmap); + + // Only hierarchical URI's can have a password. + this.hierState = true; + } + + + /** + * The host port number. Only valid for hierarchical URI's. If + * the URI is relative, this will be an empty string. URI's can + * contain the port number of the remote host: + * + *http://site.com:8080/index.htm
+ */ + public function get port() : String + { + return URI.unescapeChars(_port); + } + public function set port(portStr:String) : void + { + _port = URI.escapeChars(portStr); + + // Only hierarchical URI's can have a port. + this.hierState = true; + } + + + /** + * The path portion of the URI. Only valid for hierarchical + * URI's. When setting this value, the string + * given is assumed to be unescaped. When retrieving this + * value, the resulting string is unescaped. + * + *The path portion can be in one of two formats. 1) an absolute + * path, or 2) a relative path. An absolute path starts with a + * slash ('/'), a relative path does not.
+ * + *An absolute path may look like:
+ *A relative path may look like:
+ *Paths can be absolute or relative. Note that this not the same as + * an absolute or relative URI. An absolute URI can only have absolute + * paths. For example:
+ * + *This absolute URI has an absolute path of "/path/to/file.htm".
+ * + *Relative URI's can have either absolute paths or relative paths. + * All of the following relative URI's are valid:
+ * + *This accessor should only be used if a custom query syntax + * is used. This URI class supports the common "param=value" + * style query syntax via the get/setQueryValue() and + * get/setQueryByMap() functions. Those functions should be used + * instead if the common syntax is being used. + * + *
The URI RFC does not specify any particular + * syntax for the query part of a URI. It is intended to allow + * any format that can be agreed upon by the two communicating hosts. + * However, most systems have standardized on the typical CGI + * format:
+ * + *This class has specific support for this query syntax
+ * + *This common query format is an array of name/value + * pairs with its own syntax that is different from the overall URI + * syntax. The query has its own escaping logic. For a query part + * to be properly escaped and unescaped, it must be split into its + * component parts. This accessor escapes/unescapes the entire query + * part without regard for it's component parts. This has the + * possibliity of leaving the query string in an ambiguious state in + * regards to its syntax. If the contents of the query part are + * important, it is recommended that get/setQueryValue() or + * get/setQueryByMap() are used instead.
+ * + * If a different query syntax is being used, a subclass of URI + * can be created to handle that specific syntax. + * + * @see URI.getQueryValue, URI.getQueryByMap + */ + public function get query() : String + { + return URI.unescapeChars(_query); + } + public function set query(queryStr:String) : void + { + _query = URI.fastEscapeChars(queryStr, URI.URIqueryExcludedBitmap); + + // both hierarchical and non-hierarchical URI's can + // have a query. Do not set the hierState. + } + + /** + * Accessor to the raw query data. If you are using a custom query + * syntax, this accessor can be used to get and set the query part + * directly with no escaping/unescaping. This should ONLY be used + * if your application logic is handling custom query logic and + * handling the proper escaping of the query part. + */ + public function get queryRaw() : String + { + return _query; + } + public function set queryRaw(queryStr:String) : void + { + _query = queryStr; + } + + + /** + * The fragment (anchor) portion of the URI. This is valid for + * both hierarchical and non-hierarchical URI's. + */ + public function get fragment() : String + { + return URI.unescapeChars(_fragment); + } + public function set fragment(fragmentStr:String) : void + { + _fragment = URI.fastEscapeChars(fragmentStr, URIfragmentExcludedBitmap); + + // both hierarchical and non-hierarchical URI's can + // have a fragment. Do not set the hierState. + } + + + /** + * The non-hierarchical part of the URI. For example, if + * this URI object represents "mailto:somebody@company.com", + * this will contain "somebody@company.com". This is valid only + * for non-hierarchical URI's. + */ + public function get nonHierarchical() : String + { + return URI.unescapeChars(_nonHierarchical); + } + public function set nonHierarchical(nonHier:String) : void + { + _nonHierarchical = URI.fastEscapeChars(nonHier, URInonHierexcludedBitmap); + + // This is a non-hierarchical URI. + this.hierState = false; + } + + + /** + * Quick shorthand accessor to set the parts of this URI. + * The given parts are assumed to be in unescaped form. If + * the URI is non-hierarchical (e.g. mailto:) you will need + * to call SetScheme() and SetNonHierarchical(). + */ + public function setParts(schemeStr:String, authorityStr:String, + portStr:String, pathStr:String, queryStr:String, + fragmentStr:String) : void + { + this.scheme = schemeStr; + this.authority = authorityStr; + this.port = portStr; + this.path = pathStr; + this.query = queryStr; + this.fragment = fragmentStr; + + hierState = true; + } + + + /** + * URI escapes the given character string. This is similar in function + * to the global encodeURIComponent() function in ActionScript, but is + * slightly different in regards to which characters get escaped. This + * escapes the characters specified in the URIbaselineExluded set (see class + * static members). This is needed for this class to work properly. + * + *If a different set of characters need to be used for the escaping, + * you may use fastEscapeChars() and specify a custom URIEncodingBitmap + * that contains the characters your application needs escaped.
+ * + *Never pass a full URI to this function. A URI can only be properly + * escaped/unescaped when split into its component parts (see RFC 3986 + * section 2.4). This is due to the fact that the URI component separators + * could be characters that would normally need to be escaped.
+ * + * @param unescaped character string to be escaped. + * + * @return escaped character string + * + * @see encodeURIComponent + * @see fastEscapeChars + */ + static public function escapeChars(unescaped:String) : String + { + // This uses the excluded set by default. + return fastEscapeChars(unescaped, URI.URIbaselineExcludedBitmap); + } + + + /** + * Unescape any URI escaped characters in the given character + * string. + * + *Never pass a full URI to this function. A URI can only be properly + * escaped/unescaped when split into its component parts (see RFC 3986 + * section 2.4). This is due to the fact that the URI component separators + * could be characters that would normally need to be escaped.
+ * + * @param escaped the escaped string to be unescaped. + * + * @return unescaped string. + */ + static public function unescapeChars(escaped:String /*, onlyHighASCII:Boolean = false*/) : String + { + // We can just use the default AS function. It seems to + // decode everything correctly + var unescaped:String; + unescaped = decodeURIComponent(escaped); + return unescaped; + } + + /** + * Performance focused function that escapes the given character + * string using the given URIEncodingBitmap as the rule for what + * characters need to be escaped. This function is used by this + * class and can be used externally to this class to perform + * escaping on custom character sets. + * + *Never pass a full URI to this function. A URI can only be properly + * escaped/unescaped when split into its component parts (see RFC 3986 + * section 2.4). This is due to the fact that the URI component separators + * could be characters that would normally need to be escaped.
+ * + * @param unescaped the unescaped string to be escaped + * @param bitmap the set of characters that need to be escaped + * + * @return the escaped string. + */ + static public function fastEscapeChars(unescaped:String, bitmap:URIEncodingBitmap) : String + { + var escaped:String = ""; + var c:String; + var x:int, i:int; + + for (i = 0; i < unescaped.length; i++) + { + c = unescaped.charAt(i); + + x = bitmap.ShouldEscape(c); + if (x) + { + c = x.toString(16); + if (c.length == 1) + c = "0" + c; + + c = "%" + c; + c = c.toUpperCase(); + } + + escaped += c; + } + + return escaped; + } + + + /** + * Is this URI of a particular scheme type? For example, + * passing "http" to a URI object that represents the URI + * "http://site.com/" would return true. + * + * @param scheme scheme to check for + * + * @return true if this URI object is of the given type, false + * otherwise. + */ + public function isOfType(scheme:String) : Boolean + { + // Schemes are never case sensitive. Ignore case. + scheme = scheme.toLowerCase(); + return (this._scheme == scheme); + } + + + /** + * Get the value for the specified named in the query part. This + * assumes the query part of the URI is in the common + * "name1=value1&name2=value2" syntax. Do not call this function + * if you are using a custom query syntax. + * + * @param name name of the query value to get. + * + * @return the value of the query name, empty string if the + * query name does not exist. + */ + public function getQueryValue(name:String) : String + { + var map:Object; + var item:String; + var value:String; + + map = getQueryByMap(); + + for (item in map) + { + if (item == name) + { + value = map[item]; + return value; + } + } + + // Didn't find the specified key + return new String(""); + } + + + /** + * Set the given value on the given query name. If the given name + * does not exist, it will automatically add this name/value pair + * to the query. If null is passed as the value, it will remove + * the given item from the query. + * + *This automatically escapes any characters that may conflict with + * the query syntax so that they are "safe" within the query. The + * strings passed are assumed to be literal unescaped name and value.
+ * + * @param name name of the query value to set + * @param value value of the query item to set. If null, this will + * force the removal of this item from the query. + */ + public function setQueryValue(name:String, value:String) : void + { + var map:Object; + + map = getQueryByMap(); + + // If the key doesn't exist yet, this will create a new pair in + // the map. If it does exist, this will overwrite the previous + // value, which is what we want. + map[name] = value; + + setQueryByMap(map); + } + + + /** + * Get the query of the URI in an Object class that allows for easy + * access to the query data via Object accessors. For example: + * + *Sometimes URI's are constructed by hand using strings outside + * this class. In those cases, it is unlikely the URI has been + * properly escaped. This function forcefully escapes this URI + * by unescaping each part and then re-escaping it. If the URI + * did not have any escaping, the first unescape will do nothing + * and then the re-escape will properly escape everything. If + * the URI was already escaped, the unescape and re-escape will + * essentally be a no-op. This provides a safe way to make sure + * a URI is in the proper escaped form.
+ */ + public function forceEscape() : void + { + // The accessors for each of the members will unescape + // and then re-escape as we get and assign them. + + // Handle the parts that are common for both hierarchical + // and non-hierarchical URI's + this.scheme = this.scheme; + this.setQueryByMap(this.getQueryByMap()); + this.fragment = this.fragment; + + if (isHierarchical()) + { + this.authority = this.authority; + this.path = this.path; + this.port = this.port; + this.username = this.username; + this.password = this.password; + } + else + { + this.nonHierarchical = this.nonHierarchical; + } + } + + + /** + * Does this URI point to a resource of the given file type? + * Given a file extension (or just a file name, this will strip the + * extension), check to see if this URI points to a file of that + * type. + * + * @param extension string that contains a file extension with or + * without a dot ("html" and ".html" are both valid), or a file + * name with an extension (e.g. "index.html"). + * + * @return true if this URI points to a resource with the same file + * file extension as the extension provided, false otherwise. + */ + public function isOfFileType(extension:String) : Boolean + { + var thisExtension:String; + var index:int; + + index = extension.lastIndexOf("."); + if (index != -1) + { + // Strip the extension + extension = extension.substr(index + 1); + } + else + { + // The caller passed something without a dot in it. We + // will assume that it is just a plain extension (e.g. "html"). + // What they passed is exactly what we want + } + + thisExtension = getExtension(true); + + if (thisExtension == "") + return false; + + // Compare the extensions ignoring case + if (compareStr(thisExtension, extension, false) == 0) + return true; + else + return false; + } + + + /** + * Get the ".xyz" file extension from the filename in the URI. + * For example, if we have the following URI: + * + *This will return ".html".
+ * + * @param minusDot If true, this will strip the dot from the extension. + * If true, the above example would have returned "html". + * + * @return the file extension + */ + public function getExtension(minusDot:Boolean = false) : String + { + var filename:String = getFilename(); + var extension:String; + var index:int; + + if (filename == "") + return String(""); + + index = filename.lastIndexOf("."); + + // If it doesn't have an extension, or if it is a "hidden" file, + // it doesn't have an extension. Hidden files on unix start with + // a dot (e.g. ".login"). + if (index == -1 || index == 0) + return String(""); + + extension = filename.substr(index); + + // If the caller does not want the dot, remove it. + if (minusDot && extension.charAt(0) == ".") + extension = extension.substr(1); + + return extension; + } + + /** + * Quick function to retrieve the file name off the end of a URI. + * + *For example, if the URI is:
+ *this function will return "file.html".
+ * + * @param minusExtension true if the file extension should be stripped + * + * @return the file name. If this URI is a directory, the return + * value will be empty string. + */ + public function getFilename(minusExtension:Boolean = false) : String + { + if (isDirectory()) + return String(""); + + var pathStr:String = this.path; + var filename:String; + var index:int; + + // Find the last path separator. + index = pathStr.lastIndexOf("/"); + + if (index != -1) + filename = pathStr.substr(index + 1); + else + filename = pathStr; + + if (minusExtension) + { + // The caller has requested that the extension be removed + index = filename.lastIndexOf("."); + + if (index != -1) + filename = filename.substr(0, index); + } + + return filename; + } + + + /** + * @private + * Helper function to compare strings. + * + * @return true if the two strings are identical, false otherwise. + */ + static protected function compareStr(str1:String, str2:String, + sensitive:Boolean = true) : Boolean + { + if (sensitive == false) + { + str1 = str1.toLowerCase(); + str2 = str2.toLowerCase(); + } + + return (str1 == str2) + } + + /** + * Based on the type of this URI (http, ftp, etc.) get + * the default port used for that protocol. This is + * just intended to be a helper function for the most + * common cases. + */ + public function getDefaultPort() : String + { + if (_scheme == "http") + return String("80"); + else if (_scheme == "ftp") + return String("21"); + else if (_scheme == "file") + return String(""); + else if (_scheme == "sftp") + return String("22"); // ssh standard port + else + { + // Don't know the port for this URI type + return String(""); + } + } + + /** + * @private + * + * This resolves the given URI if the application has a + * resolver interface defined. This function does not + * modify the passed in URI and returns a new URI. + */ + static protected function resolve(uri:URI) : URI + { + var copy:URI = new URI(); + copy.copyURI(uri); + + if (_resolver != null) + { + // A resolver class has been registered. Call it. + return _resolver.resolve(copy); + } + else + { + // No resolver. Nothing to do, but we don't + // want to reuse the one passed in. + return copy; + } + } + + /** + * Accessor to set and get the resolver object used by all URI + * objects to dynamically resolve URI's before comparison. + */ + static public function set resolver(resolver:IURIResolver) : void + { + _resolver = resolver; + } + static public function get resolver() : IURIResolver + { + return _resolver; + } + + /** + * Given another URI, return this URI object's relation to the one given. + * URI's can have 1 of 4 possible relationships. They can be unrelated, + * equal, parent, or a child of the given URI. + * + * @param uri URI to compare this URI object to. + * @param caseSensitive true if the URI comparison should be done + * taking case into account, false if the comparison should be + * performed case insensitive. + * + * @return URI.NOT_RELATED, URI.CHILD, URI.PARENT, or URI.EQUAL + */ + public function getRelation(uri:URI, caseSensitive:Boolean = true) : int + { + // Give the app a chance to resolve these URI's before we compare them. + var thisURI:URI = URI.resolve(this); + var thatURI:URI = URI.resolve(uri); + + if (thisURI.isRelative() || thatURI.isRelative()) + { + // You cannot compare relative URI's due to their lack of context. + // You could have two relative URI's that look like: + // ../../images/ + // ../../images/marketing/logo.gif + // These may appear related, but you have no overall context + // from which to make the comparison. The first URI could be + // from one site and the other URI could be from another site. + return URI.NOT_RELATED; + } + else if (thisURI.isHierarchical() == false || thatURI.isHierarchical() == false) + { + // One or both of the URI's are non-hierarchical. + if (((thisURI.isHierarchical() == false) && (thatURI.isHierarchical() == true)) || + ((thisURI.isHierarchical() == true) && (thatURI.isHierarchical() == false))) + { + // XOR. One is hierarchical and the other is + // non-hierarchical. They cannot be compared. + return URI.NOT_RELATED; + } + else + { + // They are both non-hierarchical + if (thisURI.scheme != thatURI.scheme) + return URI.NOT_RELATED; + + if (thisURI.nonHierarchical != thatURI.nonHierarchical) + return URI.NOT_RELATED; + + // The two non-hierarcical URI's are equal. + return URI.EQUAL; + } + } + + // Ok, this URI and the one we are being compared to are both + // absolute hierarchical URI's. + + if (thisURI.scheme != thatURI.scheme) + return URI.NOT_RELATED; + + if (thisURI.authority != thatURI.authority) + return URI.NOT_RELATED; + + var thisPort:String = thisURI.port; + var thatPort:String = thatURI.port; + + // Different ports are considered completely different servers. + if (thisPort == "") + thisPort = thisURI.getDefaultPort(); + if (thatPort == "") + thatPort = thatURI.getDefaultPort(); + + // Check to see if the port is the default port. + if (thisPort != thatPort) + return URI.NOT_RELATED; + + if (compareStr(thisURI.path, thatURI.path, caseSensitive)) + return URI.EQUAL; + + // Special case check. If we are here, the scheme, authority, + // and port match, and it is not a relative path, but the + // paths did not match. There is a special case where we + // could have: + // http://something.com/ + // http://something.com + // Technically, these are equal. So lets, check for this case. + var thisPath:String = thisURI.path; + var thatPath:String = thatURI.path; + + if ( (thisPath == "/" || thatPath == "/") && + (thisPath == "" || thatPath == "") ) + { + // We hit the special case. These two are equal. + return URI.EQUAL; + } + + // Ok, the paths do not match, but one path may be a parent/child + // of the other. For example, we may have: + // http://something.com/path/to/homepage/ + // http://something.com/path/to/homepage/images/logo.gif + // In this case, the first is a parent of the second (or the second + // is a child of the first, depending on which you compare to the + // other). To make this comparison, we must split the path into + // its component parts (split the string on the '/' path delimiter). + // We then compare the + var thisParts:Array, thatParts:Array; + var thisPart:String, thatPart:String; + var i:int; + + thisParts = thisPath.split("/"); + thatParts = thatPath.split("/"); + + if (thisParts.length > thatParts.length) + { + thatPart = thatParts[thatParts.length - 1]; + if (thatPart.length > 0) + { + // if the last part is not empty, the passed URI is + // not a directory. There is no way the passed URI + // can be a parent. + return URI.NOT_RELATED; + } + else + { + // Remove the empty trailing part + thatParts.pop(); + } + + // This may be a child of the one passed in + for (i = 0; i < thatParts.length; i++) + { + thisPart = thisParts[i]; + thatPart = thatParts[i]; + + if (compareStr(thisPart, thatPart, caseSensitive) == false) + return URI.NOT_RELATED; + } + + return URI.CHILD; + } + else if (thisParts.length < thatParts.length) + { + thisPart = thisParts[thisParts.length - 1]; + if (thisPart.length > 0) + { + // if the last part is not empty, this URI is not a + // directory. There is no way this object can be + // a parent. + return URI.NOT_RELATED; + } + else + { + // Remove the empty trailing part + thisParts.pop(); + } + + // This may be the parent of the one passed in + for (i = 0; i < thisParts.length; i++) + { + thisPart = thisParts[i]; + thatPart = thatParts[i]; + + if (compareStr(thisPart, thatPart, caseSensitive) == false) + return URI.NOT_RELATED; + } + + return URI.PARENT; + } + else + { + // Both URI's have the same number of path components, but + // it failed the equivelence check above. This means that + // the two URI's are not related. + return URI.NOT_RELATED; + } + + // If we got here, the scheme and authority are the same, + // but the paths pointed to two different locations that + // were in different parts of the file system tree + return URI.NOT_RELATED; + } + + /** + * Given another URI, return the common parent between this one + * and the provided URI. + * + * @param uri the other URI from which to find a common parent + * @para caseSensitive true if this operation should be done + * with case sensitive comparisons. + * + * @return the parent URI if successful, null otherwise. + */ + public function getCommonParent(uri:URI, caseSensitive:Boolean = true) : URI + { + var thisURI:URI = URI.resolve(this); + var thatURI:URI = URI.resolve(uri); + + if(!thisURI.isAbsolute() || !thatURI.isAbsolute() || + thisURI.isHierarchical() == false || + thatURI.isHierarchical() == false) + { + // Both URI's must be absolute hierarchical for this to + // make sense. + return null; + } + + var relation:int = thisURI.getRelation(thatURI); + if (relation == URI.NOT_RELATED) + { + // The given URI is not related to this one. No + // common parent. + return null; + } + + thisURI.chdir("."); + thatURI.chdir("."); + + var strBefore:String, strAfter:String; + do + { + relation = thisURI.getRelation(thatURI, caseSensitive); + if(relation == URI.EQUAL || relation == URI.PARENT) + break; + + // If strBefore and strAfter end up being the same, + // we know we are at the root of the path because + // chdir("..") is doing nothing. + strBefore = thisURI.toString(); + thisURI.chdir(".."); + strAfter = thisURI.toString(); + } + while(strBefore != strAfter); + + return thisURI; + } + + + /** + * This function is used to move around in a URI in a way similar + * to the 'cd' or 'chdir' commands on Unix. These operations are + * completely string based, using the context of the URI to + * determine the position within the path. The heuristics used + * to determine the action are based off Appendix C in RFC 2396. + * + *URI paths that end in '/' are considered paths that point to
+ * directories, while paths that do not end in '/' are files. For
+ * example, if you execute chdir("d") on the following URI's:
+ * 1. http://something.com/a/b/c/ (directory)
+ * 2. http://something.com/a/b/c (not directory)
+ * you will get:
+ * 1. http://something.com/a/b/c/d
+ * 2. http://something.com/a/b/d
See RFC 2396, Appendix C for more info.
+ * + * @param reference the URI or path to "cd" to. + * @param escape true if the passed reference string should be URI + * escaped before using it. + * + * @return true if the chdir was successful, false otherwise. + */ + public function chdir(reference:String, escape:Boolean = false) : Boolean + { + var uriReference:URI; + var ref:String = reference; + + if (escape) + ref = URI.escapeChars(reference); + + if (ref == "") + { + // NOOP + return true; + } + else if (ref.substr(0, 2) == "//") + { + // Special case. This is an absolute URI but without the scheme. + // Take the scheme from this URI and tack it on. This is + // intended to make working with chdir() a little more + // tolerant. + var f:String = this.scheme + ":" + ref; + + return constructURI(f); + } + else if (ref.charAt(0) == "?") + { + // A relative URI that is just a query part is essentially + // a "./?query". We tack on the "./" here to make the rest + // of our logic work. + ref = "./" + ref; + } + + // Parse the reference passed in as a URI. This way we + // get any query and fragments parsed out as well. + uriReference = new URI(ref); + + if (uriReference.isAbsolute() || + uriReference.isHierarchical() == false) + { + // If the URI given is a full URI, it replaces this one. + copyURI(uriReference); + return true; + } + + + var thisPath:String, thatPath:String; + var thisParts:Array, thatParts:Array; + var thisIsDir:Boolean = false, thatIsDir:Boolean = false; + var thisIsAbs:Boolean = false, thatIsAbs:Boolean = false; + var lastIsDotOperation:Boolean = false; + var curDir:String; + var i:int; + + thisPath = this.path; + thatPath = uriReference.path; + + if (thisPath.length > 0) + thisParts = thisPath.split("/"); + else + thisParts = new Array(); + + if (thatPath.length > 0) + thatParts = thatPath.split("/"); + else + thatParts = new Array(); + + if (thisParts.length > 0 && thisParts[0] == "") + { + thisIsAbs = true; + thisParts.shift(); // pop the first one off the array + } + if (thisParts.length > 0 && thisParts[thisParts.length - 1] == "") + { + thisIsDir = true; + thisParts.pop(); // pop the last one off the array + } + + if (thatParts.length > 0 && thatParts[0] == "") + { + thatIsAbs = true; + thatParts.shift(); // pop the first one off the array + } + if (thatParts.length > 0 && thatParts[thatParts.length - 1] == "") + { + thatIsDir = true; + thatParts.pop(); // pop the last one off the array + } + + if (thatIsAbs) + { + // The reference is an absolute path (starts with a slash). + // It replaces this path wholesale. + this.path = uriReference.path; + + // And it inherits the query and fragment + this.queryRaw = uriReference.queryRaw; + this.fragment = uriReference.fragment; + + return true; + } + else if (thatParts.length == 0 && uriReference.query == "") + { + // The reference must have only been a fragment. Fragments just + // get appended to whatever the current path is. We don't want + // to overwrite any query that may already exist, so this case + // only takes on the new fragment. + this.fragment = uriReference.fragment; + return true; + } + else if (thisIsDir == false && thisParts.length > 0) + { + // This path ends in a file. It goes away no matter what. + thisParts.pop(); + } + + // By default, this assumes the query and fragment of the reference + this.queryRaw = uriReference.queryRaw; + this.fragment = uriReference.fragment; + + // Append the parts of the path from the passed in reference + // to this object's path. + thisParts = thisParts.concat(thatParts); + + for(i = 0; i < thisParts.length; i++) + { + curDir = thisParts[i]; + lastIsDotOperation = false; + + if (curDir == ".") + { + thisParts.splice(i, 1); + i = i - 1; // account for removing this item + lastIsDotOperation = true; + } + else if (curDir == "..") + { + if (i >= 1) + { + if (thisParts[i - 1] == "..") + { + // If the previous is a "..", we must have skipped + // it due to this URI being relative. We can't + // collapse leading ".."s in a relative URI, so + // do nothing. + } + else + { + thisParts.splice(i - 1, 2); + i = i - 2; // move back to account for the 2 we removed + } + } + else + { + // This is the first thing in the path. + + if (isRelative()) + { + // We can't collapse leading ".."s in a relative + // path. Do noting. + } + else + { + // This is an abnormal case. We have dot-dotted up + // past the base of our "file system". This is a + // case where we had a /path/like/this.htm and were + // given a path to chdir to like this: + // ../../../../../../mydir + // Obviously, it has too many ".." and will take us + // up beyond the top of the URI. However, according + // RFC 2396 Appendix C.2, we should try to handle + // these abnormal cases appropriately. In this case, + // we will do what UNIX command lines do if you are + // at the root (/) of the filesystem and execute: + // # cd ../../../../../bin + // Which will put you in /bin. Essentially, the extra + // ".."'s will just get eaten. + + thisParts.splice(i, 1); + i = i - 1; // account for the ".." we just removed + } + } + + lastIsDotOperation = true; + } + } + + var finalPath:String = ""; + + // If the last thing in the path was a "." or "..", then this thing is a + // directory. If the last thing isn't a dot-op, then we don't want to + // blow away any information about the directory (hence the "|=" binary + // assignment). + thatIsDir = thatIsDir || lastIsDotOperation; + + // Reconstruct the path with the abs/dir info we have + finalPath = joinPath(thisParts, thisIsAbs, thatIsDir); + + // Set the path (automatically escaping it) + this.path = finalPath; + + return true; + } + + /** + * @private + * Join an array of path parts back into a URI style path string. + * This is used by the various path logic functions to recombine + * a path. This is different than the standard Array.join() + * function because we need to take into account the starting and + * ending path delimiters if this is an absolute path or a + * directory. + * + * @param parts the Array that contains strings of each path part. + * @param isAbs true if the given path is absolute + * @param isDir true if the given path is a directory + * + * @return the combined path string. + */ + protected function joinPath(parts:Array, isAbs:Boolean, isDir:Boolean) : String + { + var pathStr:String = ""; + var i:int; + + for (i = 0; i < parts.length; i++) + { + if (pathStr.length > 0) + pathStr += "/"; + + pathStr += parts[i]; + } + + // If this path is a directory, tack on the directory delimiter, + // but only if the path contains something. Adding this to an + // empty path would make it "/", which is an absolute path that + // starts at the root. + if (isDir && pathStr.length > 0) + pathStr += "/"; + + if (isAbs) + pathStr = "/" + pathStr; + + return pathStr; + } + + /** + * Given an absolute URI, make this relative URI absolute using + * the given URI as a base. This URI instance must be relative + * and the base_uri must be absolute. + * + * @param base_uri URI to use as the base from which to make + * this relative URI into an absolute URI. + * + * @return true if successful, false otherwise. + */ + public function makeAbsoluteURI(base_uri:URI) : Boolean + { + if (isAbsolute() || base_uri.isRelative()) + { + // This URI needs to be relative, and the base needs to be + // absolute otherwise we won't know what to do! + return false; + } + + // Make a copy of the base URI. We don't want to modify + // the passed URI. + var base:URI = new URI(); + base.copyURI(base_uri); + + // ChDir on the base URI. This will preserve any query + // and fragment we have. + if (base.chdir(toString()) == false) + return false; + + // It worked, so copy the base into this one + copyURI(base); + + return true; + } + + + /** + * Given a URI to use as a base from which this object should be + * relative to, convert this object into a relative URI. For example, + * if you have: + * + *uri1 will have a final value of "../some/file.html"
+ * + *Note! This function is brute force. If you have two URI's + * that are completely unrelated, this will still attempt to make + * the relative URI. In that case, you will most likely get a + * relative path that looks something like:
+ * + *../../../../../../some/path/to/my/file.html
+ * + * @param base_uri the URI from which to make this URI relative + * + * @return true if successful, false if the base_uri and this URI + * are not related, of if error. + */ + public function makeRelativeURI(base_uri:URI, caseSensitive:Boolean = true) : Boolean + { + var base:URI = new URI(); + base.copyURI(base_uri); + + var thisParts:Array, thatParts:Array; + var finalParts:Array = new Array(); + var thisPart:String, thatPart:String, finalPath:String; + var pathStr:String = this.path; + var queryStr:String = this.queryRaw; + var fragmentStr:String = this.fragment; + var i:int; + var diff:Boolean = false; + var isDir:Boolean = false; + + if (isRelative()) + { + // We're already relative. + return true; + } + + if (base.isRelative()) + { + // The base is relative. A relative base doesn't make sense. + return false; + } + + + if ( (isOfType(base_uri.scheme) == false) || + (this.authority != base_uri.authority) ) + { + // The schemes and/or authorities are different. We can't + // make a relative path to something that is completely + // unrelated. + return false; + } + + // Record the state of this URI + isDir = isDirectory(); + + // We are based of the directory of the given URI. We need to + // make sure the URI is pointing to a directory. Changing + // directory to "." will remove any file name if the base is + // not a directory. + base.chdir("."); + + thisParts = pathStr.split("/"); + thatParts = base.path.split("/"); + + if (thisParts.length > 0 && thisParts[0] == "") + thisParts.shift(); + + if (thisParts.length > 0 && thisParts[thisParts.length - 1] == "") + { + isDir = true; + thisParts.pop(); + } + + if (thatParts.length > 0 && thatParts[0] == "") + thatParts.shift(); + if (thatParts.length > 0 && thatParts[thatParts.length - 1] == "") + thatParts.pop(); + + + // Now that we have the paths split into an array of directories, + // we can compare the two paths. We start from the left of side + // of the path and start comparing. When we either run out of + // directories (one path is longer than the other), or we find + // a directory that is different, we stop. The remaining parts + // of each path is then used to determine the relative path. For + // example, lets say we have: + // path we want to make relative: /a/b/c/d/e.txt + // path to use as base for relative: /a/b/f/ + // + // This loop will start at the left, and remove directories + // until we get a mismatch or run off the end of one of them. + // In this example, the result will be: + // c/d/e.txt + // f + // + // For every part left over in the base path, we prepend a ".." + // to the relative to get the final path: + // ../c/d/e.txt + while(thatParts.length > 0) + { + if (thisParts.length == 0) + { + // we matched all there is to match, we are done. + // This is the case where "this" object is a parent + // path of the given URI. eg: + // this.path = /a/b/ (thisParts) + // base.path = /a/b/c/d/e/ (thatParts) + break; + } + + thisPart = thisParts[0]; + thatPart = thatParts[0]; + + if (compareStr(thisPart, thatPart, caseSensitive)) + { + thisParts.shift(); + thatParts.shift(); + } + else + break; + } + + // If there are any path info left from the base URI, that means + // **this** object is above the given URI in the file tree. For + // each part left over in the given URI, we need to move up one + // directory to get where we are. + var dotdot:String = ".."; + for (i = 0; i < thatParts.length; i++) + { + finalParts.push(dotdot); + } + + // Append the parts of this URI to any dot-dot's we have + finalParts = finalParts.concat(thisParts); + + // Join the parts back into a path + finalPath = joinPath(finalParts, false /* not absolute */, isDir); + + if (finalPath.length == 0) + { + // The two URI's are exactly the same. The proper relative + // path is: + finalPath = "./"; + } + + // Set the parts of the URI, preserving the original query and + // fragment parts. + setParts("", "", "", finalPath, queryStr, fragmentStr); + + return true; + } + + /** + * Given a string, convert it to a URI. The string could be a + * full URI that is improperly escaped, a malformed URI (e.g. + * missing a protocol like "www.something.com"), a relative URI, + * or any variation there of. + * + *The intention of this function is to take anything that a + * user might manually enter as a URI/URL and try to determine what + * they mean. This function differs from the URI constructor in + * that it makes some assumptions to make it easy to import user + * entered URI data.
+ * + *This function is intended to be a helper function. + * It is not all-knowning and will probably make mistakes + * when attempting to parse a string of unknown origin. If + * your applicaiton is receiving input from the user, your + * application should already have a good idea what the user + * should be entering, and your application should be + * pre-processing the user's input to make sure it is well formed + * before passing it to this function.
+ * + *It is assumed that the string given to this function is + * something the user may have manually entered. Given this, + * the URI string is probably unescaped or improperly escaped. + * This function will attempt to properly escape the URI by + * using forceEscape(). The result is that a toString() call + * on a URI that was created from unknownToURI() may not match + * the input string due to the difference in escaping.
+ * + * @param unknown a potental URI string that should be parsed + * and loaded into this object. + * @param defaultScheme if it is determined that the passed string + * looks like a URI, but it is missing the scheme part, this + * string will be used as the missing scheme. + * + * @return true if the given string was successfully parsed into + * a valid URI object, false otherwise. + */ + public function unknownToURI(unknown:String, defaultScheme:String = "http") : Boolean + { + var temp:String; + + if (unknown.length == 0) + { + this.initialize(); + return false; + } + + // Some users love the backslash key. Fix it. + unknown = unknown.replace(/\\/g, "/"); + + // Check for any obviously missing scheme. + if (unknown.length >= 2) + { + temp = unknown.substr(0, 2); + if (temp == "//") + unknown = defaultScheme + ":" + unknown; + } + + if (unknown.length >= 3) + { + temp = unknown.substr(0, 3); + if (temp == "://") + unknown = defaultScheme + unknown; + } + + // Try parsing it as a normal URI + var uri:URI = new URI(unknown); + + if (uri.isHierarchical() == false) + { + if (uri.scheme == UNKNOWN_SCHEME) + { + this.initialize(); + return false; + } + + // It's a non-hierarchical URI + copyURI(uri); + forceEscape(); + return true; + } + else if ((uri.scheme != UNKNOWN_SCHEME) && + (uri.scheme.length > 0)) + { + if ( (uri.authority.length > 0) || + (uri.scheme == "file") ) + { + // file://... URI + copyURI(uri); + forceEscape(); // ensure proper escaping + return true; + } + else if (uri.authority.length == 0 && uri.path.length == 0) + { + // It's is an incomplete URI (eg "http://") + + setParts(uri.scheme, "", "", "", "", ""); + return false; + } + } + else + { + // Possible relative URI. We can only detect relative URI's + // that start with "." or "..". If it starts with something + // else, the parsing is ambiguous. + var path:String = uri.path; + + if (path == ".." || path == "." || + (path.length >= 3 && path.substr(0, 3) == "../") || + (path.length >= 2 && path.substr(0, 2) == "./") ) + { + // This is a relative URI. + copyURI(uri); + forceEscape(); + return true; + } + } + + // Ok, it looks like we are just a normal URI missing the scheme. Tack + // on the scheme. + uri = new URI(defaultScheme + "://" + unknown); + + // Check to see if we are good now + if (uri.scheme.length > 0 && uri.authority.length > 0) + { + // It was just missing the scheme. + copyURI(uri); + forceEscape(); // Make sure we are properly encoded. + return true; + } + + // don't know what this is + this.initialize(); + return false; + } + + } // end URI class +} // end package \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/net/URIEncodingBitmap.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/net/URIEncodingBitmap.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,139 @@ +/* + Copyright (c) 2008, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.net +{ + import flash.utils.ByteArray; + + /** + * This class implements an efficient lookup table for URI + * character escaping. This class is only needed if you + * create a derived class of URI to handle custom URI + * syntax. This class is used internally by URI. + * + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0* + */ + public class URIEncodingBitmap extends ByteArray + { + /** + * Constructor. Creates an encoding bitmap using the given + * string of characters as the set of characters that need + * to be URI escaped. + * + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0 + */ + public function URIEncodingBitmap(charsToEscape:String) : void + { + var i:int; + var data:ByteArray = new ByteArray(); + + // Initialize our 128 bits (16 bytes) to zero + for (i = 0; i < 16; i++) + this.writeByte(0); + + data.writeUTFBytes(charsToEscape); + data.position = 0; + + while (data.bytesAvailable) + { + var c:int = data.readByte(); + + if (c > 0x7f) + continue; // only escape low bytes + + var enc:int; + this.position = (c >> 3); + enc = this.readByte(); + enc |= 1 << (c & 0x7); + this.position = (c >> 3); + this.writeByte(enc); + } + } + + /** + * Based on the data table contained in this object, check + * if the given character should be escaped. + * + * @param char the character to be escaped. Only the first + * character in the string is used. Any other characters + * are ignored. + * + * @return the integer value of the raw UTF8 character. For + * example, if '%' is given, the return value is 37 (0x25). + * If the character given does not need to be escaped, the + * return value is zero. + * + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0 + */ + public function ShouldEscape(char:String) : int + { + var data:ByteArray = new ByteArray(); + var c:int, mask:int; + + // write the character into a ByteArray so + // we can pull it out as a raw byte value. + data.writeUTFBytes(char); + data.position = 0; + c = data.readByte(); + + if (c & 0x80) + { + // don't escape high byte characters. It can make international + // URI's unreadable. We just want to escape characters that would + // make URI syntax ambiguous. + return 0; + } + else if ((c < 0x1f) || (c == 0x7f)) + { + // control characters must be escaped. + return c; + } + + this.position = (c >> 3); + mask = this.readByte(); + + if (mask & (1 << (c & 0x7))) + { + // we need to escape this, return the numeric value + // of the character + return c; + } + else + { + return 0; + } + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/net/proxies/RFC2817Socket.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/net/proxies/RFC2817Socket.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,198 @@ +/* + Copyright (c) 2008, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +package com.adobe.net.proxies +{ + import flash.events.Event; + import flash.events.IOErrorEvent; + import flash.events.ProgressEvent; + import flash.net.Socket; + + /** + * This class allows TCP socket connections through HTTP proxies in accordance with + * RFC 2817: + * + * ftp://ftp.rfc-editor.org/in-notes/rfc2817.txt + * + * It can also be used to make direct connections to a destination, as well. If you + * pass the host and port into the constructor, no proxy will be used. You can also + * call connect, passing in the host and the port, and if you didn't set the proxy + * info, a direct connection will be made. A proxy is only used after you have called + * the setProxyInfo function. + * + * The connection to and negotiation with the proxy is completely hidden. All the + * same events are thrown whether you are using a proxy or not, and the data you + * receive from the target server will look exact as it would if you were connected + * to it directly rather than through a proxy. + * + * @author Christian Cantrell + * + **/ + public class RFC2817Socket + extends Socket + { + private var proxyHost:String = null; + private var host:String = null; + private var proxyPort:int = 0; + private var port:int = 0; + private var deferredEventHandlers:Object = new Object(); + private var buffer:String = new String(); + + /** + * Construct a new RFC2817Socket object. If you pass in the host and the port, + * no proxy will be used. If you want to use a proxy, instantiate with no + * arguments, call setProxyInfo, then call connect. + **/ + public function RFC2817Socket(host:String = null, port:int = 0) + { + super(host, port); + } + + /** + * Set the proxy host and port number. Your connection will only proxied if + * this function has been called. + **/ + public function setProxyInfo(host:String, port:int):void + { + this.proxyHost = host; + this.proxyPort = port; + + var deferredSocketDataHandler:Object = this.deferredEventHandlers[ProgressEvent.SOCKET_DATA]; + var deferredConnectHandler:Object = this.deferredEventHandlers[Event.CONNECT]; + + if (deferredSocketDataHandler != null) + { + super.removeEventListener(ProgressEvent.SOCKET_DATA, deferredSocketDataHandler.listener, deferredSocketDataHandler.useCapture); + } + + if (deferredConnectHandler != null) + { + super.removeEventListener(Event.CONNECT, deferredConnectHandler.listener, deferredConnectHandler.useCapture); + } + } + + /** + * Connect to the specified host over the specified port. If you want your + * connection proxied, call the setProxyInfo function first. + **/ + public override function connect(host:String, port:int):void + { + if (this.proxyHost == null) + { + this.redirectConnectEvent(); + this.redirectSocketDataEvent(); + super.connect(host, port); + } + else + { + this.host = host; + this.port = port; + super.addEventListener(Event.CONNECT, this.onConnect); + super.addEventListener(ProgressEvent.SOCKET_DATA, this.onSocketData); + super.connect(this.proxyHost, this.proxyPort); + } + } + + private function onConnect(event:Event):void + { + this.writeUTFBytes("CONNECT "+this.host+":"+this.port+" HTTP/1.1\n\n"); + this.flush(); + this.redirectConnectEvent(); + } + + private function onSocketData(event:ProgressEvent):void + { + while (this.bytesAvailable != 0) + { + this.buffer += this.readUTFBytes(1); + if (this.buffer.search(/\r?\n\r?\n$/) != -1) + { + this.checkResponse(event); + break; + } + } + } + + private function checkResponse(event:ProgressEvent):void + { + var responseCode:String = this.buffer.substr(this.buffer.indexOf(" ")+1, 3); + + if (responseCode.search(/^2/) == -1) + { + var ioError:IOErrorEvent = new IOErrorEvent(IOErrorEvent.IO_ERROR); + ioError.text = "Error connecting to the proxy ["+this.proxyHost+"] on port ["+this.proxyPort+"]: " + this.buffer; + this.dispatchEvent(ioError); + } + else + { + this.redirectSocketDataEvent(); + this.dispatchEvent(new Event(Event.CONNECT)); + if (this.bytesAvailable > 0) + { + this.dispatchEvent(event); + } + } + this.buffer = null; + } + + private function redirectConnectEvent():void + { + super.removeEventListener(Event.CONNECT, onConnect); + var deferredEventHandler:Object = this.deferredEventHandlers[Event.CONNECT]; + if (deferredEventHandler != null) + { + super.addEventListener(Event.CONNECT, deferredEventHandler.listener, deferredEventHandler.useCapture, deferredEventHandler.priority, deferredEventHandler.useWeakReference); + } + } + + private function redirectSocketDataEvent():void + { + super.removeEventListener(ProgressEvent.SOCKET_DATA, onSocketData); + var deferredEventHandler:Object = this.deferredEventHandlers[ProgressEvent.SOCKET_DATA]; + if (deferredEventHandler != null) + { + super.addEventListener(ProgressEvent.SOCKET_DATA, deferredEventHandler.listener, deferredEventHandler.useCapture, deferredEventHandler.priority, deferredEventHandler.useWeakReference); + } + } + + public override function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int=0.0, useWeakReference:Boolean=false):void + { + if (type == Event.CONNECT || type == ProgressEvent.SOCKET_DATA) + { + this.deferredEventHandlers[type] = {listener:listener,useCapture:useCapture, priority:priority, useWeakReference:useWeakReference}; + } + else + { + super.addEventListener(type, listener, useCapture, priority, useWeakReference); + } + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/Database.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/Database.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,66 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict +{ + public class Database + { + private var _name:String; + private var _description:String; + + public function Database(name:String, description:String) + { + this._name = name; + this._description = description; + } + + public function set name(name:String):void + { + this._name = name; + } + + public function get name():String + { + return this._name; + } + + public function set description(description:String):void + { + this._description = description; + } + + public function get description():String + { + return this._description; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/Definition.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/Definition.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,71 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict +{ + public class Definition + { + private var _definition:String; + private var _database:String; + private var _term:String; + + public function set definition(definition:String):void + { + this._definition = definition; + } + + public function get definition():String + { + return this._definition; + } + + public function set database(database:String):void + { + this._database = database; + } + + public function get database():String + { + return this._database; + } + + public function set term(term:String):void + { + this._term = term; + } + + public function get term():String + { + return this._term; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/Dict.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/Dict.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,360 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict +{ + import com.adobe.protocols.dict.events.*; + import com.adobe.protocols.dict.util.*; + + import flash.events.Event; + import flash.events.EventDispatcher; + import flash.events.IOErrorEvent; + import flash.events.ProgressEvent; + import flash.events.SecurityErrorEvent; + import flash.net.Socket; + import mx.rpc.http.HTTPService; + import mx.rpc.events.ResultEvent; + import mx.rpc.events.FaultEvent; + import flash.xml.XMLNode; + import mx.utils.StringUtil; + + public class Dict + extends EventDispatcher + { + // Event type names. + //public static var CONNECTED:String = "connected"; + //public static var DISCONNECTED:String = "disconnected"; + public static var IO_ERROR:String = IOErrorEvent.IO_ERROR; + //public static var ERROR:String = "error"; + //public static var SERVERS:String = "servers"; + //public static var DATABASES:String = "databases"; + //public static var MATCH_STRATEGIES:String = "matchStrategies"; + //public static var DEFINITION:String = "definition"; + //public static var DEFINITION_HEADER:String = "definitionHeader"; + //public static var MATCH:String = "match"; + //public static var NO_MATCH:String = "noMatch"; + + public static var FIRST_MATCH:uint = 0; + public static var ALL_DATABASES:uint = 1; + + private var socket:SocketHelper; + + private var dbShortList:Boolean; + + public function Dict() + { + this.socket = new SocketHelper(); + this.socket.addEventListener(Event.CONNECT, connected); + this.socket.addEventListener(Event.CLOSE, disconnected); + this.socket.addEventListener(SocketHelper.COMPLETE_RESPONSE, incomingData); + this.socket.addEventListener(IOErrorEvent.IO_ERROR, ioError); + this.socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityError); + } + + public function connect(server:String, port:uint = 2628):void + { + if (this.socket.connected) + { + this.socket.close(); + } + this.socket.connect(server, port); + } + + public function connectThroughProxy(proxyServer:String, + proxyPort:int, + server:String, + port:uint = 2628):void + { + if (this.socket.connected) + { + this.socket.close(); + } + this.socket.setProxyInfo(proxyServer, proxyPort); + this.socket.connect(server, port); + } + + public function disconnect():void + { + this.socket.close(); + this.disconnected(null); + } + + public function getServers():void + { + var http:HTTPService = new HTTPService(); + http.url = "http://luetzschena-stahmeln.de/dictd/xmllist.php"; + http.addEventListener(ResultEvent.RESULT, incomingServerXML); + http.addEventListener(FaultEvent.FAULT, httpError); + http.resultFormat = HTTPService.RESULT_FORMAT_E4X; + http.send(); + } + + public function getDatabases(shortList:Boolean=true):void + { + this.dbShortList = shortList; + this.socket.writeUTFBytes("show db\r\n"); + this.socket.flush(); + } + + public function getMatchStrategies():void + { + this.socket.writeUTFBytes("show strat\r\n"); + this.socket.flush(); + } + + public function match(database:String, term:String, scope:String="prefix"):void + { + this.socket.writeUTFBytes("match " + database + " " + scope + " \"" + term + "\"\r\n"); + this.socket.flush(); + } + + public function define(database:String, term:String):void + { + this.socket.writeUTFBytes("define " + database + " \"" + term + "\"\r\n"); + this.socket.flush(); + } + + public function lookup(term:String, scope:uint):void + { + var flag:String; + if (scope == Dict.ALL_DATABASES) + { + flag = "*"; + } + else if (scope == Dict.FIRST_MATCH) + { + flag = "!"; + } + this.socket.writeUTFBytes("define " + flag + " \"" + term + "\"\r\n"); + this.socket.flush(); + } + + //// Private functions //// + + private function connected(event:Event):void + { + // Wait to dispatch an event until we get the 220 response. + } + + private function disconnected(event:Event):void + { + dispatchEvent(new DisconnectedEvent(DisconnectedEvent.DISCONNECTED)); + } + + private function incomingServerXML(event:ResultEvent):void + { + var dictd:Namespace = new Namespace("http://www.luetzschena-stahmeln.de/dictd/"); + var result:XML = event.result as XML; + var server:String, description:String; + var servers:Array = new Array(); + for each (var serverNode:XML in result.dictd::server) + { + server = serverNode.dictd::dictdurl; + description = serverNode.dictd::description; + if (StringUtil.trim(server).length != 0 && + StringUtil.trim(description).length != 0) + { + var dServer:DictionaryServer = new DictionaryServer(); + dServer.server = server.replace("dict://", ""); + dServer.description = description; + servers.push(dServer); + } + } + var dEvent:DictionaryServerEvent = new DictionaryServerEvent(DictionaryServerEvent.SERVERS); + dEvent.servers = servers; + dispatchEvent(dEvent); + } + + private function incomingData(event:CompleteResponseEvent):void + { + var rawResponse:String = event.response; + var response:Response = this.parseRawResponse(rawResponse); + var responseCode:uint = response.code; + if (responseCode == 552) // no matches + { + throwNoMatchEvent(response); + } + else if (responseCode >= 400 && responseCode <= 599) // error + { + throwErrorEvent(response); + } + else if (responseCode == 220) // successful connection + { + dispatchEvent(new ConnectedEvent(ConnectedEvent.CONNECTED)); + } + else if (responseCode == 110) // databases are being returned + { + throwDatabasesEvent(response); + } + else if (responseCode == 111) // matches strategies + { + throwMatchStrategiesEvent(response); + } + else if (responseCode == 152) // matches + { + throwMatchEvent(response); + } + else if (responseCode == 150) + { + throwDefinitionHeaderEvent(response); + } + else if (responseCode == 151) + { + throwDefinitionEvent(response); + } + } + + private function ioError(event:IOErrorEvent):void + { + dispatchEvent(event); + } + + private function httpError(event:FaultEvent):void + { + trace("httpError!"); + } + + private function securityError(event:SecurityErrorEvent):void + { + trace("security error!"); + trace(event.text); + } + + // Dispatch new events. + + private function throwDatabasesEvent(response:Response):void + { + var databases:Array = new Array(); + var responseArray:Array = response.body.split("\r\n"); + for each (var line:String in responseArray) + { + var name:String = line.substring(0, line.indexOf(" ")); + if (name == "--exit--") + { + if (this.dbShortList) + { + break; + } + continue; + } + var description:String = line.substring(line.indexOf(" ")+1, line.length).replace(/\"/g,""); + databases.push(new Database(name, description)); + } + var event:DatabaseEvent = new DatabaseEvent(DatabaseEvent.DATABASES); + event.databases = databases; + dispatchEvent(event); + } + + private function throwMatchStrategiesEvent(response:Response):void + { + var strategies:Array = new Array(); + var responseArray:Array = response.body.split("\r\n"); + for each (var line:String in responseArray) + { + var name:String = line.substring(0, line.indexOf(" ")); + var description:String = line.substring(line.indexOf(" ")+1, line.length).replace(/\"/g,""); + strategies.push(new MatchStrategy(name, description)); + } + var event:MatchStrategiesEvent = new MatchStrategiesEvent(MatchStrategiesEvent.MATCH_STRATEGIES); + event.strategies = strategies; + dispatchEvent(event); + } + + private function throwMatchEvent(response:Response):void + { + var matches:Array = new Array(); + var responseArray:Array = response.body.split("\r\n"); + for each (var line:String in responseArray) + { + var match:String = line.substring(line.indexOf(" ")+1, line.length).replace(/\"/g,""); + matches.push(match); + } + var event:MatchEvent = new MatchEvent(MatchEvent.MATCH); + event.matches = matches; + dispatchEvent(event); + } + + private function throwErrorEvent(response:Response):void + { + var event:ErrorEvent = new ErrorEvent(ErrorEvent.ERROR); + event.code = response.code; + event.message = response.headerText; + dispatchEvent(event); + } + + private function throwNoMatchEvent(response:Response):void + { + dispatchEvent(new NoMatchEvent(NoMatchEvent.NO_MATCH)); + } + + private function throwDefinitionHeaderEvent(response:Response):void + { + var event:DefinitionHeaderEvent = new DefinitionHeaderEvent(DefinitionHeaderEvent.DEFINITION_HEADER); + event.definitionCount = uint(response.headerText.substring(0, response.headerText.indexOf(" "))); + dispatchEvent(event); + } + + private function throwDefinitionEvent(response:Response):void + { + var event:DefinitionEvent = new DefinitionEvent(DefinitionEvent.DEFINITION); + var def:Definition = new Definition(); + var headerText:String = response.headerText; + var tokens:Array = headerText.match(/"[^"]+"/g); + def.term = String(tokens[0]).replace(/"/g, ""); + def.database = String(tokens[1]).replace(/"/g, ""); + def.definition = response.body; + event.definition = def; + dispatchEvent(event); + } + + private function parseRawResponse(rawResponse:String):Response + { + var response:Response = new Response(); + var fullHeader:String; + if (rawResponse.indexOf("\r\n") != -1) + { + fullHeader = rawResponse.substring(0, rawResponse.indexOf("\r\n")); + } + else + { + fullHeader = rawResponse; + } + var responseCodeMatch:Array = fullHeader.match(/^\d{3}/); + response.code = uint(responseCodeMatch[0]); + response.headerText = fullHeader.substring(fullHeader.indexOf(" ")+1, fullHeader.length); + var body:String = rawResponse.substring(rawResponse.indexOf("\r\n")+2, rawResponse.length); + body = body.replace(/\r\n\.\./, "\r\n."); + response.body = body; + return response; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/DictionaryServer.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/DictionaryServer.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,60 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict +{ + public class DictionaryServer + { + private var _server:String; + private var _description:String; + + public function set server(server:String):void + { + this._server = server; + } + + public function get server():String + { + return this._server; + } + + public function set description(description:String):void + { + this._description = description; + } + + public function get description():String + { + return this._description; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/MatchStrategy.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/MatchStrategy.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,66 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict +{ + public class MatchStrategy + { + private var _name:String; + private var _description:String; + + public function MatchStrategy(name:String, description:String) + { + this._name = name; + this._description = description; + } + + public function set name(name:String):void + { + this._name = name; + } + + public function get name():String + { + return this._name; + } + + public function set description(description:String):void + { + this._description = description; + } + + public function get description():String + { + return this._description; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/Response.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/Response.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,71 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict +{ + public class Response + { + private var _code:uint; + private var _headerText:String; + private var _body:String; + + public function set code(code:uint):void + { + this._code = code; + } + + public function set headerText(headerText:String):void + { + this._headerText = headerText; + } + + public function set body(body:String):void + { + this._body = body; + } + + public function get code():uint + { + return this._code; + } + + public function get headerText():String + { + return this._headerText; + } + + public function get body():String + { + return this._body; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/events/ConnectedEvent.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/events/ConnectedEvent.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,53 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict.events +{ + import flash.events.Event; + + public class ConnectedEvent extends Event + { + public static const CONNECTED:String = "connected"; + + public function ConnectedEvent(type:String, bubbles:Boolean = false, + cancelable:Boolean = false) + { + super(type, bubbles, cancelable); + } + + public override function clone():Event + { + var out:ConnectedEvent = new ConnectedEvent(type, bubbles, cancelable); + return out; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/events/DatabaseEvent.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/events/DatabaseEvent.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,67 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict.events +{ + import flash.events.Event; + + public class DatabaseEvent extends Event + { + private var _databases:Array; + + public static const DATABASES:String = "databases"; + + public function DatabaseEvent(type:String, bubbles:Boolean = false, + cancelable:Boolean = false) + { + super(type, bubbles, cancelable); + } + + public function set databases(databases:Array):void + { + this._databases = databases; + } + + public function get databases():Array + { + return this._databases; + } + + public override function clone():Event + { + var out:DatabaseEvent = new DatabaseEvent(type, bubbles, cancelable); + out.databases = _databases; + + return out; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/events/DefinitionEvent.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/events/DefinitionEvent.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,70 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict.events +{ + import com.adobe.protocols.dict.Definition; + + import flash.events.Event; + + + public class DefinitionEvent extends Event + { + public static const DEFINITION:String = "definition"; + + private var _definition:Definition; + + public function DefinitionEvent(type:String, bubbles:Boolean = false, + cancelable:Boolean = false) + { + super(type, bubbles, cancelable); + } + + public function set definition(definition:Definition):void + { + this._definition = definition; + } + + public function get definition():Definition + { + return this._definition; + } + + public override function clone():Event + { + var out:DefinitionEvent = new DefinitionEvent(type, bubbles, cancelable); + out.definition = _definition; + + return out; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,69 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict.events +{ + import flash.events.Event; + + public class DefinitionHeaderEvent extends Event + { + public static const DEFINITION_HEADER:String = "definitionHeader"; + + private var _definitionCount:uint; + + public function DefinitionHeaderEvent(type:String, bubbles:Boolean = false, + cancelable:Boolean = false) + { + super(type, bubbles, cancelable); + } + + public function set definitionCount(definitionCount:uint):void + { + this._definitionCount = definitionCount; + } + + public function get definitionCount():uint + { + return this._definitionCount; + } + + public override function clone():Event + { + var out:DefinitionHeaderEvent = new DefinitionHeaderEvent(type, + bubbles, cancelable); + + out.definitionCount = _definitionCount; + + return out; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/events/DictionaryServerEvent.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/events/DictionaryServerEvent.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,69 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict.events +{ + import flash.events.Event; + + public class DictionaryServerEvent extends Event + { + public static const SERVERS:String = "servers"; + + private var _servers:Array; + + public function DictionaryServerEvent(type:String, bubbles:Boolean = false, + cancelable:Boolean = false) + { + super(type, bubbles, cancelable); + } + + public function set servers(servers:Array):void + { + this._servers = servers; + } + + public function get servers():Array + { + return this._servers; + } + + public override function clone():Event + { + var out:DictionaryServerEvent = new DictionaryServerEvent(type, + bubbles, cancelable); + + out.servers = _servers; + + return out; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/events/DisconnectedEvent.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/events/DisconnectedEvent.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,55 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict.events +{ + import flash.events.Event; + + public class DisconnectedEvent extends Event + { + public static const DISCONNECTED:String = "disconnected"; + + public function DisconnectedEvent(type:String, bubbles:Boolean = false, + cancelable:Boolean = false) + { + super(type, bubbles, cancelable); + } + + public override function clone():Event + { + var out:DisconnectedEvent = new DisconnectedEvent(type, bubbles, cancelable); + + return out; + } + + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/events/ErrorEvent.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/events/ErrorEvent.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,80 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict.events +{ + import flash.events.Event; + + public class ErrorEvent extends Event + { + public static const ERROR:String = "error"; + + private var _code:uint; + private var _message:String; + + public function ErrorEvent(type:String, bubbles:Boolean = false, + cancelable:Boolean = false) + { + super(type, bubbles, cancelable); + } + + public function set code(code:uint):void + { + this._code = code; + } + + public function set message(message:String):void + { + this._message = message; + } + + public function get code():uint + { + return this._code; + } + + public function get message():String + { + return this._message; + } + + public override function clone():Event + { + var out:ErrorEvent = new ErrorEvent(type, bubbles, cancelable); + + out.message = _message; + out.code = _code; + + return out; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/events/MatchEvent.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/events/MatchEvent.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,67 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict.events +{ + import flash.events.Event; + + public class MatchEvent extends Event + { + private var _matches:Array; + + public static const MATCH:String = "match"; + + public function MatchEvent(type:String, bubbles:Boolean = false, + cancelable:Boolean = false) + { + super(type, bubbles, cancelable); + } + + public function set matches(matches:Array):void + { + this._matches = matches; + } + + public function get matches():Array + { + return this._matches; + } + + public override function clone():Event + { + var out:MatchEvent = new MatchEvent(type, bubbles, cancelable); + out.matches = _matches; + + return out; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/events/MatchStrategiesEvent.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/events/MatchStrategiesEvent.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,70 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict.events +{ + import flash.events.Event; + + public class MatchStrategiesEvent + extends Event + { + private var _strategies:Array; + + public static const MATCH_STRATEGIES:String = "matchStrategies"; + + public function MatchStrategiesEvent(type:String, bubbles:Boolean = false, + cancelable:Boolean = false) + { + super(type, bubbles, cancelable); + } + + public function set strategies(strategies:Array):void + { + this._strategies = strategies; + } + + public function get strategies():Array + { + return this._strategies; + } + + public override function clone():Event + { + var out:MatchStrategiesEvent = new MatchStrategiesEvent(type, + bubbles, cancelable); + + out.strategies = _strategies; + + return out; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/events/NoMatchEvent.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/events/NoMatchEvent.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,54 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict.events +{ + import flash.events.Event; + + public class NoMatchEvent extends Event + { + public static const NO_MATCH:String = "noMatch"; + + public function NoMatchEvent(type:String, bubbles:Boolean = false, + cancelable:Boolean = false) + { + super(type, bubbles, cancelable); + } + + public override function clone():Event + { + var out:NoMatchEvent = new NoMatchEvent(type, bubbles, cancelable); + + return out; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/util/CompleteResponseEvent.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/util/CompleteResponseEvent.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,68 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict.util +{ + import flash.events.Event; + + public class CompleteResponseEvent extends Event + { + private var _response:String; + + public static const COMPLETE_RESPONSE:String = "completeResponse" + + public function CompleteResponseEvent(type:String, bubbles:Boolean = false, + cancelable:Boolean = false) + { + super(type, bubbles, cancelable); + } + + public function set response(response:String):void + { + this._response = response; + } + + public function get response():String + { + return this._response; + } + + public override function clone():Event + { + var out:CompleteResponseEvent = new CompleteResponseEvent(type, + bubbles, cancelable); + out.response = _response; + + return out; + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/protocols/dict/util/SocketHelper.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/protocols/dict/util/SocketHelper.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,81 @@ +/* + Copyright (c) 2009, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.protocols.dict.util +{ + import com.adobe.net.proxies.RFC2817Socket; + import flash.events.ProgressEvent; + + public class SocketHelper + extends RFC2817Socket + { + private var terminator:String = "\r\n.\r\n"; + private var buffer:String; + public static var COMPLETE_RESPONSE:String = "completeResponse"; + + public function SocketHelper() + { + super(); + buffer = new String(); + addEventListener(ProgressEvent.SOCKET_DATA, incomingData); + } + + private function incomingData(event:ProgressEvent):void + { + buffer += readUTFBytes(bytesAvailable); + buffer = buffer.replace(/250[^\r\n]+\r\n/, ""); // Get rid of all 250s. Don't need them. + var codeStr:String = buffer.substring(0, 3); + if (!isNaN(parseInt(codeStr))) + { + var code:uint = uint(codeStr); + if (code == 150 || code >= 200) + { + buffer = buffer.replace("\r\n", this.terminator); + } + } + + while (buffer.indexOf(this.terminator) != -1) + { + var chunk:String = buffer.substring(0, buffer.indexOf(this.terminator)); + buffer = buffer.substring(chunk.length + this.terminator.length, buffer.length); + throwResponseEvent(chunk); + } + } + + private function throwResponseEvent(response:String):void + { + var responseEvent:CompleteResponseEvent = new CompleteResponseEvent(CompleteResponseEvent.COMPLETE_RESPONSE); + responseEvent.response = response; + dispatchEvent(responseEvent); + } + } +} \ No newline at end of file diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/serialization/json/JSON.as --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/as3/ext/com/adobe/serialization/json/JSON.as Tue Sep 14 16:47:10 2010 +0000 @@ -0,0 +1,86 @@ +/* + Copyright (c) 2008, Adobe Systems Incorporated + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Adobe Systems Incorporated nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.serialization.json +{ + + /** + * This class provides encoding and decoding of the JSON format. + * + * Example usage: + *
+ * // create a JSON string from an internal object
+ * JSON.encode( myObject );
+ *
+ * // read a JSON string into an internal object
+ * var myObject:Object = JSON.decode( jsonString );
+ *
+ */
+ public class JSON
+ {
+ /**
+ * Encodes a object into a JSON string.
+ *
+ * @param o The object to create a JSON string for
+ * @return the JSON string representing o
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function encode( o:Object ):String
+ {
+ return new JSONEncoder( o ).getString();
+ }
+
+ /**
+ * Decodes a JSON string into a native object.
+ *
+ * @param s The JSON string representing the object
+ * @param strict Flag indicating if the decoder should strictly adhere
+ * to the JSON standard or not. The default of true
+ * throws errors if the format does not match the JSON syntax exactly.
+ * Pass false
to allow for non-properly-formatted JSON
+ * strings to be decoded with more leniancy.
+ * @return A native object as specified by s
+ * @throw JSONParseError
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function decode( s:String, strict:Boolean = true ):*
+ {
+ return new JSONDecoder( s, strict ).getValue();
+ }
+
+ }
+
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/serialization/json/JSONDecoder.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/serialization/json/JSONDecoder.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,327 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.serialization.json
+{
+
+ public class JSONDecoder
+ {
+
+ /**
+ * Flag indicating if the parser should be strict about the format
+ * of the JSON string it is attempting to decode.
+ */
+ private var strict:Boolean;
+
+ /** The value that will get parsed from the JSON string */
+ private var value:*;
+
+ /** The tokenizer designated to read the JSON string */
+ private var tokenizer:JSONTokenizer;
+
+ /** The current token from the tokenizer */
+ private var token:JSONToken;
+
+ /**
+ * Constructs a new JSONDecoder to parse a JSON string
+ * into a native object.
+ *
+ * @param s The JSON string to be converted
+ * into a native object
+ * @param strict Flag indicating if the JSON string needs to
+ * strictly match the JSON standard or not.
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public function JSONDecoder( s:String, strict:Boolean )
+ {
+ this.strict = strict;
+ tokenizer = new JSONTokenizer( s, strict );
+
+ nextToken();
+ value = parseValue();
+
+ // Make sure the input stream is empty
+ if ( strict && nextToken() != null )
+ {
+ tokenizer.parseError( "Unexpected characters left in input stream" );
+ }
+ }
+
+ /**
+ * Gets the internal object that was created by parsing
+ * the JSON string passed to the constructor.
+ *
+ * @return The internal object representation of the JSON
+ * string that was passed to the constructor
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public function getValue():*
+ {
+ return value;
+ }
+
+ /**
+ * Returns the next token from the tokenzier reading
+ * the JSON string
+ */
+ private function nextToken():JSONToken
+ {
+ return token = tokenizer.getNextToken();
+ }
+
+ /**
+ * Attempt to parse an array.
+ */
+ private function parseArray():Array
+ {
+ // create an array internally that we're going to attempt
+ // to parse from the tokenizer
+ var a:Array = new Array();
+
+ // grab the next token from the tokenizer to move
+ // past the opening [
+ nextToken();
+
+ // check to see if we have an empty array
+ if ( token.type == JSONTokenType.RIGHT_BRACKET )
+ {
+ // we're done reading the array, so return it
+ return a;
+ }
+ // in non-strict mode an empty array is also a comma
+ // followed by a right bracket
+ else if ( !strict && token.type == JSONTokenType.COMMA )
+ {
+ // move past the comma
+ nextToken();
+
+ // check to see if we're reached the end of the array
+ if ( token.type == JSONTokenType.RIGHT_BRACKET )
+ {
+ return a;
+ }
+ else
+ {
+ tokenizer.parseError( "Leading commas are not supported. Expecting ']' but found " + token.value );
+ }
+ }
+
+ // deal with elements of the array, and use an "infinite"
+ // loop because we could have any amount of elements
+ while ( true )
+ {
+ // read in the value and add it to the array
+ a.push( parseValue() );
+
+ // after the value there should be a ] or a ,
+ nextToken();
+
+ if ( token.type == JSONTokenType.RIGHT_BRACKET )
+ {
+ // we're done reading the array, so return it
+ return a;
+ }
+ else if ( token.type == JSONTokenType.COMMA )
+ {
+ // move past the comma and read another value
+ nextToken();
+
+ // Allow arrays to have a comma after the last element
+ // if the decoder is not in strict mode
+ if ( !strict )
+ {
+ // Reached ",]" as the end of the array, so return it
+ if ( token.type == JSONTokenType.RIGHT_BRACKET )
+ {
+ return a;
+ }
+ }
+ }
+ else
+ {
+ tokenizer.parseError( "Expecting ] or , but found " + token.value );
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Attempt to parse an object.
+ */
+ private function parseObject():Object
+ {
+ // create the object internally that we're going to
+ // attempt to parse from the tokenizer
+ var o:Object = new Object();
+
+ // store the string part of an object member so
+ // that we can assign it a value in the object
+ var key:String
+
+ // grab the next token from the tokenizer
+ nextToken();
+
+ // check to see if we have an empty object
+ if ( token.type == JSONTokenType.RIGHT_BRACE )
+ {
+ // we're done reading the object, so return it
+ return o;
+ }
+ // in non-strict mode an empty object is also a comma
+ // followed by a right bracket
+ else if ( !strict && token.type == JSONTokenType.COMMA )
+ {
+ // move past the comma
+ nextToken();
+
+ // check to see if we're reached the end of the object
+ if ( token.type == JSONTokenType.RIGHT_BRACE )
+ {
+ return o;
+ }
+ else
+ {
+ tokenizer.parseError( "Leading commas are not supported. Expecting '}' but found " + token.value );
+ }
+ }
+
+ // deal with members of the object, and use an "infinite"
+ // loop because we could have any amount of members
+ while ( true )
+ {
+ if ( token.type == JSONTokenType.STRING )
+ {
+ // the string value we read is the key for the object
+ key = String( token.value );
+
+ // move past the string to see what's next
+ nextToken();
+
+ // after the string there should be a :
+ if ( token.type == JSONTokenType.COLON )
+ {
+ // move past the : and read/assign a value for the key
+ nextToken();
+ o[key] = parseValue();
+
+ // move past the value to see what's next
+ nextToken();
+
+ // after the value there's either a } or a ,
+ if ( token.type == JSONTokenType.RIGHT_BRACE )
+ {
+ // we're done reading the object, so return it
+ return o;
+ }
+ else if ( token.type == JSONTokenType.COMMA )
+ {
+ // skip past the comma and read another member
+ nextToken();
+
+ // Allow objects to have a comma after the last member
+ // if the decoder is not in strict mode
+ if ( !strict )
+ {
+ // Reached ",}" as the end of the object, so return it
+ if ( token.type == JSONTokenType.RIGHT_BRACE )
+ {
+ return o;
+ }
+ }
+ }
+ else
+ {
+ tokenizer.parseError( "Expecting } or , but found " + token.value );
+ }
+ }
+ else
+ {
+ tokenizer.parseError( "Expecting : but found " + token.value );
+ }
+ }
+ else
+ {
+ tokenizer.parseError( "Expecting string but found " + token.value );
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Attempt to parse a value
+ */
+ private function parseValue():Object
+ {
+ // Catch errors when the input stream ends abruptly
+ if ( token == null )
+ {
+ tokenizer.parseError( "Unexpected end of input" );
+ }
+
+ switch ( token.type )
+ {
+ case JSONTokenType.LEFT_BRACE:
+ return parseObject();
+
+ case JSONTokenType.LEFT_BRACKET:
+ return parseArray();
+
+ case JSONTokenType.STRING:
+ case JSONTokenType.NUMBER:
+ case JSONTokenType.TRUE:
+ case JSONTokenType.FALSE:
+ case JSONTokenType.NULL:
+ return token.value;
+
+ case JSONTokenType.NAN:
+ if ( !strict )
+ {
+ return token.value;
+ }
+ else
+ {
+ tokenizer.parseError( "Unexpected " + token.value );
+ }
+
+ default:
+ tokenizer.parseError( "Unexpected " + token.value );
+
+ }
+
+ return null;
+ }
+ }
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/serialization/json/JSONEncoder.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/serialization/json/JSONEncoder.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,312 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.serialization.json
+{
+
+ import flash.utils.describeType;
+
+ public class JSONEncoder {
+
+ /** The string that is going to represent the object we're encoding */
+ private var jsonString:String;
+
+ /**
+ * Creates a new JSONEncoder.
+ *
+ * @param o The object to encode as a JSON string
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public function JSONEncoder( value:* ) {
+ jsonString = convertToString( value );
+
+ }
+
+ /**
+ * Gets the JSON string from the encoder.
+ *
+ * @return The JSON string representation of the object
+ * that was passed to the constructor
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public function getString():String {
+ return jsonString;
+ }
+
+ /**
+ * Converts a value to it's JSON string equivalent.
+ *
+ * @param value The value to convert. Could be any
+ * type (object, number, array, etc)
+ */
+ private function convertToString( value:* ):String {
+
+ // determine what value is and convert it based on it's type
+ if ( value is String ) {
+
+ // escape the string so it's formatted correctly
+ return escapeString( value as String );
+
+ } else if ( value is Number ) {
+
+ // only encode numbers that finate
+ return isFinite( value as Number) ? value.toString() : "null";
+
+ } else if ( value is Boolean ) {
+
+ // convert boolean to string easily
+ return value ? "true" : "false";
+
+ } else if ( value is Array ) {
+
+ // call the helper method to convert an array
+ return arrayToString( value as Array );
+
+ } else if ( value is Object && value != null ) {
+
+ // call the helper method to convert an object
+ return objectToString( value );
+ }
+ return "null";
+ }
+
+ /**
+ * Escapes a string accoding to the JSON specification.
+ *
+ * @param str The string to be escaped
+ * @return The string with escaped special characters
+ * according to the JSON specification
+ */
+ private function escapeString( str:String ):String {
+ // create a string to store the string's jsonstring value
+ var s:String = "";
+ // current character in the string we're processing
+ var ch:String;
+ // store the length in a local variable to reduce lookups
+ var len:Number = str.length;
+
+ // loop over all of the characters in the string
+ for ( var i:int = 0; i < len; i++ ) {
+
+ // examine the character to determine if we have to escape it
+ ch = str.charAt( i );
+ switch ( ch ) {
+
+ case '"': // quotation mark
+ s += "\\\"";
+ break;
+
+ //case '/': // solidus
+ // s += "\\/";
+ // break;
+
+ case '\\': // reverse solidus
+ s += "\\\\";
+ break;
+
+ case '\b': // bell
+ s += "\\b";
+ break;
+
+ case '\f': // form feed
+ s += "\\f";
+ break;
+
+ case '\n': // newline
+ s += "\\n";
+ break;
+
+ case '\r': // carriage return
+ s += "\\r";
+ break;
+
+ case '\t': // horizontal tab
+ s += "\\t";
+ break;
+
+ default: // everything else
+
+ // check for a control character and escape as unicode
+ if ( ch < ' ' ) {
+ // get the hex digit(s) of the character (either 1 or 2 digits)
+ var hexCode:String = ch.charCodeAt( 0 ).toString( 16 );
+
+ // ensure that there are 4 digits by adjusting
+ // the # of zeros accordingly.
+ var zeroPad:String = hexCode.length == 2 ? "00" : "000";
+
+ // create the unicode escape sequence with 4 hex digits
+ s += "\\u" + zeroPad + hexCode;
+ } else {
+
+ // no need to do any special encoding, just pass-through
+ s += ch;
+
+ }
+ } // end switch
+
+ } // end for loop
+
+ return "\"" + s + "\"";
+ }
+
+ /**
+ * Converts an array to it's JSON string equivalent
+ *
+ * @param a The array to convert
+ * @return The JSON string representation of a
+ */
+ private function arrayToString( a:Array ):String {
+ // create a string to store the array's jsonstring value
+ var s:String = "";
+
+ // loop over the elements in the array and add their converted
+ // values to the string
+ for ( var i:int = 0; i < a.length; i++ ) {
+ // when the length is 0 we're adding the first element so
+ // no comma is necessary
+ if ( s.length > 0 ) {
+ // we've already added an element, so add the comma separator
+ s += ","
+ }
+
+ // convert the value to a string
+ s += convertToString( a[i] );
+ }
+
+ // KNOWN ISSUE: In ActionScript, Arrays can also be associative
+ // objects and you can put anything in them, ie:
+ // myArray["foo"] = "bar";
+ //
+ // These properties aren't picked up in the for loop above because
+ // the properties don't correspond to indexes. However, we're
+ // sort of out luck because the JSON specification doesn't allow
+ // these types of array properties.
+ //
+ // So, if the array was also used as an associative object, there
+ // may be some values in the array that don't get properly encoded.
+ //
+ // A possible solution is to instead encode the Array as an Object
+ // but then it won't get decoded correctly (and won't be an
+ // Array instance)
+
+ // close the array and return it's string value
+ return "[" + s + "]";
+ }
+
+ /**
+ * Converts an object to it's JSON string equivalent
+ *
+ * @param o The object to convert
+ * @return The JSON string representation of o
+ */
+ private function objectToString( o:Object ):String
+ {
+ // create a string to store the object's jsonstring value
+ var s:String = "";
+
+ // determine if o is a class instance or a plain object
+ var classInfo:XML = describeType( o );
+ if ( classInfo.@name.toString() == "Object" )
+ {
+ // the value of o[key] in the loop below - store this
+ // as a variable so we don't have to keep looking up o[key]
+ // when testing for valid values to convert
+ var value:Object;
+
+ // loop over the keys in the object and add their converted
+ // values to the string
+ for ( var key:String in o )
+ {
+ // assign value to a variable for quick lookup
+ value = o[key];
+
+ // don't add function's to the JSON string
+ if ( value is Function )
+ {
+ // skip this key and try another
+ continue;
+ }
+
+ // when the length is 0 we're adding the first item so
+ // no comma is necessary
+ if ( s.length > 0 ) {
+ // we've already added an item, so add the comma separator
+ s += ","
+ }
+
+ s += escapeString( key ) + ":" + convertToString( value );
+ }
+ }
+ else // o is a class instance
+ {
+ // Loop over all of the variables and accessors in the class and
+ // serialize them along with their values.
+ for each ( var v:XML in classInfo..*.(
+ name() == "variable"
+ ||
+ (
+ name() == "accessor"
+ // Issue #116 - Make sure accessors are readable
+ && (""+attribute( "access" )).charAt( 0 ) == "r" )
+ ) )
+ {
+ // Issue #110 - If [Transient] metadata exists, then we should skip
+ if ( v.metadata && v.metadata.( @name == "Transient" ).length() > 0 )
+ {
+ continue;
+ }
+
+ // When the length is 0 we're adding the first item so
+ // no comma is necessary
+ if ( s.length > 0 ) {
+ // We've already added an item, so add the comma separator
+ s += ","
+ }
+
+ s += escapeString( v.@name.toString() ) + ":"
+ + convertToString( o[ v.@name ] );
+ }
+
+ }
+
+ return "{" + s + "}";
+ }
+
+
+ }
+
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/serialization/json/JSONParseError.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/serialization/json/JSONParseError.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,87 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.serialization.json {
+
+ /**
+ *
+ *
+ */
+ public class JSONParseError extends Error {
+
+ /** The location in the string where the error occurred */
+ private var _location:int;
+
+ /** The string in which the parse error occurred */
+ private var _text:String;
+
+ /**
+ * Constructs a new JSONParseError.
+ *
+ * @param message The error message that occured during parsing
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public function JSONParseError( message:String = "", location:int = 0, text:String = "") {
+ super( message );
+ name = "JSONParseError";
+ _location = location;
+ _text = text;
+ }
+
+ /**
+ * Provides read-only access to the location variable.
+ *
+ * @return The location in the string where the error occurred
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public function get location():int {
+ return _location;
+ }
+
+ /**
+ * Provides read-only access to the text variable.
+ *
+ * @return The string in which the error occurred
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public function get text():String {
+ return _text;
+ }
+ }
+
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/serialization/json/JSONToken.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/serialization/json/JSONToken.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,104 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.serialization.json {
+
+ public class JSONToken {
+
+ private var _type:int;
+ private var _value:Object;
+
+ /**
+ * Creates a new JSONToken with a specific token type and value.
+ *
+ * @param type The JSONTokenType of the token
+ * @param value The value of the token
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public function JSONToken( type:int = -1 /* JSONTokenType.UNKNOWN */, value:Object = null ) {
+ _type = type;
+ _value = value;
+ }
+
+ /**
+ * Returns the type of the token.
+ *
+ * @see com.adobe.serialization.json.JSONTokenType
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public function get type():int {
+ return _type;
+ }
+
+ /**
+ * Sets the type of the token.
+ *
+ * @see com.adobe.serialization.json.JSONTokenType
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public function set type( value:int ):void {
+ _type = value;
+ }
+
+ /**
+ * Gets the value of the token
+ *
+ * @see com.adobe.serialization.json.JSONTokenType
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public function get value():Object {
+ return _value;
+ }
+
+ /**
+ * Sets the value of the token
+ *
+ * @see com.adobe.serialization.json.JSONTokenType
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public function set value ( v:Object ):void {
+ _value = v;
+ }
+
+ }
+
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/serialization/json/JSONTokenType.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/serialization/json/JSONTokenType.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,69 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.serialization.json {
+
+ /**
+ * Class containing constant values for the different types
+ * of tokens in a JSON encoded string.
+ */
+ public class JSONTokenType {
+
+ public static const UNKNOWN:int = -1;
+
+ public static const COMMA:int = 0;
+
+ public static const LEFT_BRACE:int = 1;
+
+ public static const RIGHT_BRACE:int = 2;
+
+ public static const LEFT_BRACKET:int = 3;
+
+ public static const RIGHT_BRACKET:int = 4;
+
+ public static const COLON:int = 6;
+
+ public static const TRUE:int = 7;
+
+ public static const FALSE:int = 8;
+
+ public static const NULL:int = 9;
+
+ public static const STRING:int = 10;
+
+ public static const NUMBER:int = 11;
+
+ public static const NAN:int = 12;
+
+ }
+
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/serialization/json/JSONTokenizer.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/serialization/json/JSONTokenizer.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,702 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.serialization.json {
+
+ public class JSONTokenizer {
+
+ /**
+ * Flag indicating if the tokenizer should only recognize
+ * standard JSON tokens. Setting to false
allows
+ * tokens such as NaN and allows numbers to be formatted as
+ * hex, etc.
+ */
+ private var strict:Boolean;
+
+ /** The object that will get parsed from the JSON string */
+ private var obj:Object;
+
+ /** The JSON string to be parsed */
+ private var jsonString:String;
+
+ /** The current parsing location in the JSON string */
+ private var loc:int;
+
+ /** The current character in the JSON string during parsing */
+ private var ch:String;
+
+ /**
+ * The regular expression used to make sure the string does not
+ * contain invalid control characters.
+ */
+ private var controlCharsRegExp:RegExp = /[\x00-\x1F]/;
+
+ /**
+ * Constructs a new JSONDecoder to parse a JSON string
+ * into a native object.
+ *
+ * @param s The JSON string to be converted
+ * into a native object
+ */
+ public function JSONTokenizer( s:String, strict:Boolean )
+ {
+ jsonString = s;
+ this.strict = strict;
+ loc = 0;
+
+ // prime the pump by getting the first character
+ nextChar();
+ }
+
+ /**
+ * Gets the next token in the input sting and advances
+ * the character to the next character after the token
+ */
+ public function getNextToken():JSONToken
+ {
+ var token:JSONToken = new JSONToken();
+
+ // skip any whitespace / comments since the last
+ // token was read
+ skipIgnored();
+
+ // examine the new character and see what we have...
+ switch ( ch )
+ {
+ case '{':
+ token.type = JSONTokenType.LEFT_BRACE;
+ token.value = '{';
+ nextChar();
+ break
+
+ case '}':
+ token.type = JSONTokenType.RIGHT_BRACE;
+ token.value = '}';
+ nextChar();
+ break
+
+ case '[':
+ token.type = JSONTokenType.LEFT_BRACKET;
+ token.value = '[';
+ nextChar();
+ break
+
+ case ']':
+ token.type = JSONTokenType.RIGHT_BRACKET;
+ token.value = ']';
+ nextChar();
+ break
+
+ case ',':
+ token.type = JSONTokenType.COMMA;
+ token.value = ',';
+ nextChar();
+ break
+
+ case ':':
+ token.type = JSONTokenType.COLON;
+ token.value = ':';
+ nextChar();
+ break;
+
+ case 't': // attempt to read true
+ var possibleTrue:String = "t" + nextChar() + nextChar() + nextChar();
+
+ if ( possibleTrue == "true" )
+ {
+ token.type = JSONTokenType.TRUE;
+ token.value = true;
+ nextChar();
+ }
+ else
+ {
+ parseError( "Expecting 'true' but found " + possibleTrue );
+ }
+
+ break;
+
+ case 'f': // attempt to read false
+ var possibleFalse:String = "f" + nextChar() + nextChar() + nextChar() + nextChar();
+
+ if ( possibleFalse == "false" )
+ {
+ token.type = JSONTokenType.FALSE;
+ token.value = false;
+ nextChar();
+ }
+ else
+ {
+ parseError( "Expecting 'false' but found " + possibleFalse );
+ }
+
+ break;
+
+ case 'n': // attempt to read null
+ var possibleNull:String = "n" + nextChar() + nextChar() + nextChar();
+
+ if ( possibleNull == "null" )
+ {
+ token.type = JSONTokenType.NULL;
+ token.value = null;
+ nextChar();
+ }
+ else
+ {
+ parseError( "Expecting 'null' but found " + possibleNull );
+ }
+
+ break;
+
+ case 'N': // attempt to read NaN
+ var possibleNaN:String = "N" + nextChar() + nextChar();
+
+ if ( possibleNaN == "NaN" )
+ {
+ token.type = JSONTokenType.NAN;
+ token.value = NaN;
+ nextChar();
+ }
+ else
+ {
+ parseError( "Expecting 'NaN' but found " + possibleNaN );
+ }
+
+ break;
+
+ case '"': // the start of a string
+ token = readString();
+ break;
+
+ default:
+ // see if we can read a number
+ if ( isDigit( ch ) || ch == '-' )
+ {
+ token = readNumber();
+ }
+ else if ( ch == '' )
+ {
+ // check for reading past the end of the string
+ return null;
+ }
+ else
+ {
+ // not sure what was in the input string - it's not
+ // anything we expected
+ parseError( "Unexpected " + ch + " encountered" );
+ }
+ }
+
+ return token;
+ }
+
+ /**
+ * Attempts to read a string from the input string. Places
+ * the character location at the first character after the
+ * string. It is assumed that ch is " before this method is called.
+ *
+ * @return the JSONToken with the string value if a string could
+ * be read. Throws an error otherwise.
+ */
+ private function readString():JSONToken
+ {
+ // Rather than examine the string character-by-character, it's
+ // faster to use indexOf to try to and find the closing quote character
+ // and then replace escape sequences after the fact.
+
+ // Start at the current input stream position
+ var quoteIndex:int = loc;
+ do
+ {
+ // Find the next quote in the input stream
+ quoteIndex = jsonString.indexOf( "\"", quoteIndex );
+
+ if ( quoteIndex >= 0 )
+ {
+ // We found the next double quote character in the string, but we need
+ // to make sure it is not part of an escape sequence.
+
+ // Keep looping backwards while the previous character is a backslash
+ var backspaceCount:int = 0;
+ var backspaceIndex:int = quoteIndex - 1;
+ while ( jsonString.charAt( backspaceIndex ) == "\\" )
+ {
+ backspaceCount++;
+ backspaceIndex--;
+ }
+
+ // If we have an even number of backslashes, that means this is the ending quote
+ if ( backspaceCount % 2 == 0 )
+ {
+ break;
+ }
+
+ // At this point, the quote was determined to be part of an escape sequence
+ // so we need to move past the quote index to look for the next one
+ quoteIndex++;
+ }
+ else // There are no more quotes in the string and we haven't found the end yet
+ {
+ parseError( "Unterminated string literal" );
+ }
+ } while ( true );
+
+ // Unescape the string
+ // the token for the string we'll try to read
+ var token:JSONToken = new JSONToken();
+ token.type = JSONTokenType.STRING;
+ // Attach resulting string to the token to return it
+ token.value = unescapeString( jsonString.substr( loc, quoteIndex - loc ) );
+
+ // Move past the closing quote in the input string. This updates the next
+ // character in the input stream to be the character one after the closing quote
+ loc = quoteIndex + 1;
+ nextChar();
+
+ return token;
+ }
+
+ /**
+ * Convert all JavaScript escape characters into normal characters
+ *
+ * @param input The input string to convert
+ * @return Original string with escape characters replaced by real characters
+ */
+ public function unescapeString( input:String ):String
+ {
+ // Issue #104 - If the string contains any unescaped control characters, this
+ // is an error in strict mode
+ if ( strict && controlCharsRegExp.test( input ) )
+ {
+ parseError( "String contains unescaped control character (0x00-0x1F)" );
+ }
+
+ var result:String = "";
+ var backslashIndex:int = 0;
+ var nextSubstringStartPosition:int = 0;
+ var len:int = input.length;
+ do
+ {
+ // Find the next backslash in the input
+ backslashIndex = input.indexOf( '\\', nextSubstringStartPosition );
+
+ if ( backslashIndex >= 0 )
+ {
+ result += input.substr( nextSubstringStartPosition, backslashIndex - nextSubstringStartPosition );
+
+ // Move past the backslash and next character (all escape sequences are
+ // two characters, except for \u, which will advance this further)
+ nextSubstringStartPosition = backslashIndex + 2;
+
+ // Check the next character so we know what to escape
+ var afterBackslashIndex:int = backslashIndex + 1;
+ var escapedChar:String = input.charAt( afterBackslashIndex );
+ switch ( escapedChar )
+ {
+ // Try to list the most common expected cases first to improve performance
+
+ case '"': result += '"'; break; // quotation mark
+ case '\\': result += '\\'; break; // reverse solidus
+ case 'n': result += '\n'; break; // newline
+ case 'r': result += '\r'; break; // carriage return
+ case 't': result += '\t'; break; // horizontal tab
+
+ // Convert a unicode escape sequence to it's character value
+ case 'u':
+
+ // Save the characters as a string we'll convert to an int
+ var hexValue:String = "";
+
+ // Make sure there are enough characters in the string leftover
+ if ( nextSubstringStartPosition + 4 > len )
+ {
+ parseError( "Unexpected end of input. Expecting 4 hex digits after \\u." );
+ }
+
+ // Try to find 4 hex characters
+ for ( var i:int = nextSubstringStartPosition; i < nextSubstringStartPosition + 4; i++ )
+ {
+ // get the next character and determine
+ // if it's a valid hex digit or not
+ var possibleHexChar:String = input.charAt( i );
+ if ( !isHexDigit( possibleHexChar ) )
+ {
+ parseError( "Excepted a hex digit, but found: " + possibleHexChar );
+ }
+
+ // Valid hex digit, add it to the value
+ hexValue += possibleHexChar;
+ }
+
+ // Convert hexValue to an integer, and use that
+ // integer value to create a character to add
+ // to our string.
+ result += String.fromCharCode( parseInt( hexValue, 16 ) );
+ // Move past the 4 hex digits that we just read
+ nextSubstringStartPosition += 4;
+ break;
+
+ case 'f': result += '\f'; break; // form feed
+ case '/': result += '/'; break; // solidus
+ case 'b': result += '\b'; break; // bell
+ default: result += '\\' + escapedChar; // Couldn't unescape the sequence, so just pass it through
+ }
+ }
+ else
+ {
+ // No more backslashes to replace, append the rest of the string
+ result += input.substr( nextSubstringStartPosition );
+ break;
+ }
+
+ } while ( nextSubstringStartPosition < len );
+
+ return result;
+ }
+
+ /**
+ * Attempts to read a number from the input string. Places
+ * the character location at the first character after the
+ * number.
+ *
+ * @return The JSONToken with the number value if a number could
+ * be read. Throws an error otherwise.
+ */
+ private function readNumber():JSONToken
+ {
+ // the string to accumulate the number characters
+ // into that we'll convert to a number at the end
+ var input:String = "";
+
+ // check for a negative number
+ if ( ch == '-' )
+ {
+ input += '-';
+ nextChar();
+ }
+
+ // the number must start with a digit
+ if ( !isDigit( ch ) )
+ {
+ parseError( "Expecting a digit" );
+ }
+
+ // 0 can only be the first digit if it
+ // is followed by a decimal point
+ if ( ch == '0' )
+ {
+ input += ch;
+ nextChar();
+
+ // make sure no other digits come after 0
+ if ( isDigit( ch ) )
+ {
+ parseError( "A digit cannot immediately follow 0" );
+ }
+ // unless we have 0x which starts a hex number, but this
+ // doesn't match JSON spec so check for not strict mode.
+ else if ( !strict && ch == 'x' )
+ {
+ // include the x in the input
+ input += ch;
+ nextChar();
+
+ // need at least one hex digit after 0x to
+ // be valid
+ if ( isHexDigit( ch ) )
+ {
+ input += ch;
+ nextChar();
+ }
+ else
+ {
+ parseError( "Number in hex format require at least one hex digit after \"0x\"" );
+ }
+
+ // consume all of the hex values
+ while ( isHexDigit( ch ) )
+ {
+ input += ch;
+ nextChar();
+ }
+ }
+ }
+ else
+ {
+ // read numbers while we can
+ while ( isDigit( ch ) )
+ {
+ input += ch;
+ nextChar();
+ }
+ }
+
+ // check for a decimal value
+ if ( ch == '.' )
+ {
+ input += '.';
+ nextChar();
+
+ // after the decimal there has to be a digit
+ if ( !isDigit( ch ) )
+ {
+ parseError( "Expecting a digit" );
+ }
+
+ // read more numbers to get the decimal value
+ while ( isDigit( ch ) )
+ {
+ input += ch;
+ nextChar();
+ }
+ }
+
+ // check for scientific notation
+ if ( ch == 'e' || ch == 'E' )
+ {
+ input += "e"
+ nextChar();
+ // check for sign
+ if ( ch == '+' || ch == '-' )
+ {
+ input += ch;
+ nextChar();
+ }
+
+ // require at least one number for the exponent
+ // in this case
+ if ( !isDigit( ch ) )
+ {
+ parseError( "Scientific notation number needs exponent value" );
+ }
+
+ // read in the exponent
+ while ( isDigit( ch ) )
+ {
+ input += ch;
+ nextChar();
+ }
+ }
+
+ // convert the string to a number value
+ var num:Number = Number( input );
+
+ if ( isFinite( num ) && !isNaN( num ) )
+ {
+ // the token for the number that we've read
+ var token:JSONToken = new JSONToken();
+ token.type = JSONTokenType.NUMBER;
+ token.value = num;
+ return token;
+ }
+ else
+ {
+ parseError( "Number " + num + " is not valid!" );
+ }
+
+ return null;
+ }
+
+ /**
+ * Reads the next character in the input
+ * string and advances the character location.
+ *
+ * @return The next character in the input string, or
+ * null if we've read past the end.
+ */
+ private function nextChar():String
+ {
+ return ch = jsonString.charAt( loc++ );
+ }
+
+ /**
+ * Advances the character location past any
+ * sort of white space and comments
+ */
+ private function skipIgnored():void
+ {
+ var originalLoc:int;
+
+ // keep trying to skip whitespace and comments as long
+ // as we keep advancing past the original location
+ do
+ {
+ originalLoc = loc;
+ skipWhite();
+ skipComments();
+ }
+ while ( originalLoc != loc );
+ }
+
+ /**
+ * Skips comments in the input string, either
+ * single-line or multi-line. Advances the character
+ * to the first position after the end of the comment.
+ */
+ private function skipComments():void
+ {
+ if ( ch == '/' )
+ {
+ // Advance past the first / to find out what type of comment
+ nextChar();
+ switch ( ch )
+ {
+ case '/': // single-line comment, read through end of line
+
+ // Loop over the characters until we find
+ // a newline or until there's no more characters left
+ do
+ {
+ nextChar();
+ }
+ while ( ch != '\n' && ch != '' )
+
+ // move past the \n
+ nextChar();
+
+ break;
+
+ case '*': // multi-line comment, read until closing */
+
+ // move past the opening *
+ nextChar();
+
+ // try to find a trailing */
+ while ( true )
+ {
+ if ( ch == '*' )
+ {
+ // check to see if we have a closing /
+ nextChar();
+ if ( ch == '/')
+ {
+ // move past the end of the closing */
+ nextChar();
+ break;
+ }
+ }
+ else
+ {
+ // move along, looking if the next character is a *
+ nextChar();
+ }
+
+ // when we're here we've read past the end of
+ // the string without finding a closing */, so error
+ if ( ch == '' )
+ {
+ parseError( "Multi-line comment not closed" );
+ }
+ }
+
+ break;
+
+ // Can't match a comment after a /, so it's a parsing error
+ default:
+ parseError( "Unexpected " + ch + " encountered (expecting '/' or '*' )" );
+ }
+ }
+
+ }
+
+
+ /**
+ * Skip any whitespace in the input string and advances
+ * the character to the first character after any possible
+ * whitespace.
+ */
+ private function skipWhite():void
+ {
+ // As long as there are spaces in the input
+ // stream, advance the current location pointer
+ // past them
+ while ( isWhiteSpace( ch ) )
+ {
+ nextChar();
+ }
+
+ }
+
+ /**
+ * Determines if a character is whitespace or not.
+ *
+ * @return True if the character passed in is a whitespace
+ * character
+ */
+ private function isWhiteSpace( ch:String ):Boolean
+ {
+ // Check for the whitespace defined in the spec
+ if ( ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' )
+ {
+ return true;
+ }
+ // If we're not in strict mode, we also accept non-breaking space
+ else if ( !strict && ch.charCodeAt( 0 ) == 160 )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Determines if a character is a digit [0-9].
+ *
+ * @return True if the character passed in is a digit
+ */
+ private function isDigit( ch:String ):Boolean
+ {
+ return ( ch >= '0' && ch <= '9' );
+ }
+
+ /**
+ * Determines if a character is a hex digit [0-9A-Fa-f].
+ *
+ * @return True if the character passed in is a hex digit
+ */
+ private function isHexDigit( ch:String ):Boolean
+ {
+ return ( isDigit( ch ) || ( ch >= 'A' && ch <= 'F' ) || ( ch >= 'a' && ch <= 'f' ) );
+ }
+
+ /**
+ * Raises a parsing error with a specified message, tacking
+ * on the error location and the original string.
+ *
+ * @param message The message indicating why the error occurred
+ */
+ public function parseError( message:String ):void
+ {
+ throw new JSONParseError( message, loc, jsonString );
+ }
+ }
+
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/utils/ArrayUtil.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/utils/ArrayUtil.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,187 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.utils
+{
+
+ /**
+ * Class that contains static utility methods for manipulating and working
+ * with Arrays.
+ *
+ * Note that all APIs assume that they are working with well formed arrays.
+ * i.e. they will only manipulate indexed values.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public class ArrayUtil
+ {
+
+ /**
+ * Determines whether the specified array contains the specified value.
+ *
+ * @param arr The array that will be checked for the specified value.
+ *
+ * @param value The object which will be searched for within the array
+ *
+ * @return True if the array contains the value, False if it does not.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function arrayContainsValue(arr:Array, value:Object):Boolean
+ {
+ return (arr.indexOf(value) != -1);
+ }
+
+ /**
+ * Remove all instances of the specified value from the array,
+ *
+ * @param arr The array from which the value will be removed
+ *
+ * @param value The object that will be removed from the array.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function removeValueFromArray(arr:Array, value:Object):void
+ {
+ var len:uint = arr.length;
+
+ for(var i:Number = len; i > -1; i--)
+ {
+ if(arr[i] === value)
+ {
+ arr.splice(i, 1);
+ }
+ }
+ }
+
+ /**
+ * Create a new array that only contains unique instances of objects
+ * in the specified array.
+ *
+ * Basically, this can be used to remove duplication object instances
+ * from an array
+ *
+ * @param arr The array which contains the values that will be used to
+ * create the new array that contains no duplicate values.
+ *
+ * @return A new array which only contains unique items from the specified
+ * array.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function createUniqueCopy(a:Array):Array
+ {
+ var newArray:Array = new Array();
+
+ var len:Number = a.length;
+ var item:Object;
+
+ for (var i:uint = 0; i < len; ++i)
+ {
+ item = a[i];
+
+ if(ArrayUtil.arrayContainsValue(newArray, item))
+ {
+ continue;
+ }
+
+ newArray.push(item);
+ }
+
+ return newArray;
+ }
+
+ /**
+ * Creates a copy of the specified array.
+ *
+ * Note that the array returned is a new array but the items within the
+ * array are not copies of the items in the original array (but rather
+ * references to the same items)
+ *
+ * @param arr The array that will be copies
+ *
+ * @return A new array which contains the same items as the array passed
+ * in.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function copyArray(arr:Array):Array
+ {
+ return arr.slice();
+ }
+
+ /**
+ * Compares two arrays and returns a boolean indicating whether the arrays
+ * contain the same values at the same indexes.
+ *
+ * @param arr1 The first array that will be compared to the second.
+ *
+ * @param arr2 The second array that will be compared to the first.
+ *
+ * @return True if the arrays contains the same values at the same indexes.
+ False if they do not.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function arraysAreEqual(arr1:Array, arr2:Array):Boolean
+ {
+ if(arr1.length != arr2.length)
+ {
+ return false;
+ }
+
+ var len:Number = arr1.length;
+
+ for(var i:Number = 0; i < len; i++)
+ {
+ if(arr1[i] !== arr2[i])
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ }
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/utils/DateUtil.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/utils/DateUtil.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,701 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.utils
+{
+ import mx.formatters.DateBase;
+
+ /**
+ * Class that contains static utility methods for manipulating and working
+ * with Dates.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public class DateUtil
+ {
+
+ /**
+ * Returns the English Short Month name (3 letters) for the Month that
+ * the Date represents.
+ *
+ * @param d The Date instance whose month will be used to retrieve the
+ * short month name.
+ *
+ * @return An English 3 Letter Month abbreviation.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ *
+ * @see SHORT_MONTH
+ */
+ public static function getShortMonthName(d:Date):String
+ {
+ return DateBase.monthNamesShort[d.getMonth()];
+ }
+
+ /**
+ * Returns the index of the month that the short month name string
+ * represents.
+ *
+ * @param m The 3 letter abbreviation representing a short month name.
+ *
+ * @param Optional parameter indicating whether the search should be case
+ * sensitive
+ *
+ * @return A int that represents that month represented by the specifed
+ * short name.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ *
+ * @see SHORT_MONTH
+ */
+ public static function getShortMonthIndex(m:String):int
+ {
+ return DateBase.monthNamesShort.indexOf(m);
+ }
+
+ /**
+ * Returns the English full Month name for the Month that
+ * the Date represents.
+ *
+ * @param d The Date instance whose month will be used to retrieve the
+ * full month name.
+ *
+ * @return An English full month name.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ *
+ * @see FULL_MONTH
+ */
+ public static function getFullMonthName(d:Date):String
+ {
+ return DateBase.monthNamesLong[d.getMonth()];
+ }
+
+ /**
+ * Returns the index of the month that the full month name string
+ * represents.
+ *
+ * @param m A full month name.
+ *
+ * @return A int that represents that month represented by the specifed
+ * full month name.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ *
+ * @see FULL_MONTH
+ */
+ public static function getFullMonthIndex(m:String):int
+ {
+ return DateBase.monthNamesLong.indexOf(m);
+ }
+
+ /**
+ * Returns the English Short Day name (3 letters) for the day that
+ * the Date represents.
+ *
+ * @param d The Date instance whose day will be used to retrieve the
+ * short day name.
+ *
+ * @return An English 3 Letter day abbreviation.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ *
+ * @see SHORT_DAY
+ */
+ public static function getShortDayName(d:Date):String
+ {
+ return DateBase.dayNamesShort[d.getDay()];
+ }
+
+ /**
+ * Returns the index of the day that the short day name string
+ * represents.
+ *
+ * @param m A short day name.
+ *
+ * @return A int that represents that short day represented by the specifed
+ * full month name.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ *
+ * @see SHORT_DAY
+ */
+ public static function getShortDayIndex(d:String):int
+ {
+ return DateBase.dayNamesShort.indexOf(d);
+ }
+
+ /**
+ * Returns the English full day name for the day that
+ * the Date represents.
+ *
+ * @param d The Date instance whose day will be used to retrieve the
+ * full day name.
+ *
+ * @return An English full day name.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ *
+ * @see FULL_DAY
+ */
+ public static function getFullDayName(d:Date):String
+ {
+ return DateBase.dayNamesLong[d.getDay()];
+ }
+
+ /**
+ * Returns the index of the day that the full day name string
+ * represents.
+ *
+ * @param m A full day name.
+ *
+ * @return A int that represents that full day represented by the specifed
+ * full month name.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ *
+ * @see FULL_DAY
+ */
+ public static function getFullDayIndex(d:String):int
+ {
+ return DateBase.dayNamesLong.indexOf(d);
+ }
+
+ /**
+ * Returns a two digit representation of the year represented by the
+ * specified date.
+ *
+ * @param d The Date instance whose year will be used to generate a two
+ * digit string representation of the year.
+ *
+ * @return A string that contains a 2 digit representation of the year.
+ * Single digits will be padded with 0.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function getShortYear(d:Date):String
+ {
+ var dStr:String = String(d.getFullYear());
+
+ if(dStr.length < 3)
+ {
+ return dStr;
+ }
+
+ return (dStr.substr(dStr.length - 2));
+ }
+
+ /**
+ * Compares two dates and returns an integer depending on their relationship.
+ *
+ * Returns -1 if d1 is greater than d2.
+ * Returns 1 if d2 is greater than d1.
+ * Returns 0 if both dates are equal.
+ *
+ * @param d1 The date that will be compared to the second date.
+ * @param d2 The date that will be compared to the first date.
+ *
+ * @return An int indicating how the two dates compare.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function compareDates(d1:Date, d2:Date):int
+ {
+ var d1ms:Number = d1.getTime();
+ var d2ms:Number = d2.getTime();
+
+ if(d1ms > d2ms)
+ {
+ return -1;
+ }
+ else if(d1ms < d2ms)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ /**
+ * Returns a short hour (0 - 12) represented by the specified date.
+ *
+ * If the hour is less than 12 (0 - 11 AM) then the hour will be returned.
+ *
+ * If the hour is greater than 12 (12 - 23 PM) then the hour minus 12
+ * will be returned.
+ *
+ * @param d1 The Date from which to generate the short hour
+ *
+ * @return An int between 0 and 13 ( 1 - 12 ) representing the short hour.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function getShortHour(d:Date):int
+ {
+ var h:int = d.hours;
+
+ if(h == 0 || h == 12)
+ {
+ return 12;
+ }
+ else if(h > 12)
+ {
+ return h - 12;
+ }
+ else
+ {
+ return h;
+ }
+ }
+
+ /**
+ * Returns a string indicating whether the date represents a time in the
+ * ante meridiem (AM) or post meridiem (PM).
+ *
+ * If the hour is less than 12 then "AM" will be returned.
+ *
+ * If the hour is greater than 12 then "PM" will be returned.
+ *
+ * @param d1 The Date from which to generate the 12 hour clock indicator.
+ *
+ * @return A String ("AM" or "PM") indicating which half of the day the
+ * hour represents.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function getAMPM(d:Date):String
+ {
+ return (d.hours > 11)? "PM" : "AM";
+ }
+
+ /**
+ * Parses dates that conform to RFC822 into Date objects. This method also
+ * supports four-digit years (not supported in RFC822), but two-digit years
+ * (referring to the 20th century) are fine, too.
+ *
+ * This function is useful for parsing RSS .91, .92, and 2.0 dates.
+ *
+ * @param str
+ *
+ * @returns
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ *
+ * @see http://asg.web.cmu.edu/rfc/rfc822.html
+ */
+ public static function parseRFC822(str:String):Date
+ {
+ var finalDate:Date;
+ try
+ {
+ var dateParts:Array = str.split(" ");
+ var day:String = null;
+
+ if (dateParts[0].search(/\d/) == -1)
+ {
+ day = dateParts.shift().replace(/\W/, "");
+ }
+
+ var date:Number = Number(dateParts.shift());
+ var month:Number = Number(DateUtil.getShortMonthIndex(dateParts.shift()));
+ var year:Number = Number(dateParts.shift());
+ var timeParts:Array = dateParts.shift().split(":");
+ var hour:Number = int(timeParts.shift());
+ var minute:Number = int(timeParts.shift());
+ var second:Number = (timeParts.length > 0) ? int(timeParts.shift()): 0;
+
+ var milliseconds:Number = Date.UTC(year, month, date, hour, minute, second, 0);
+
+ var timezone:String = dateParts.shift();
+ var offset:Number = 0;
+
+ if (timezone.search(/\d/) == -1)
+ {
+ switch(timezone)
+ {
+ case "UT":
+ offset = 0;
+ break;
+ case "UTC":
+ offset = 0;
+ break;
+ case "GMT":
+ offset = 0;
+ break;
+ case "EST":
+ offset = (-5 * 3600000);
+ break;
+ case "EDT":
+ offset = (-4 * 3600000);
+ break;
+ case "CST":
+ offset = (-6 * 3600000);
+ break;
+ case "CDT":
+ offset = (-5 * 3600000);
+ break;
+ case "MST":
+ offset = (-7 * 3600000);
+ break;
+ case "MDT":
+ offset = (-6 * 3600000);
+ break;
+ case "PST":
+ offset = (-8 * 3600000);
+ break;
+ case "PDT":
+ offset = (-7 * 3600000);
+ break;
+ case "Z":
+ offset = 0;
+ break;
+ case "A":
+ offset = (-1 * 3600000);
+ break;
+ case "M":
+ offset = (-12 * 3600000);
+ break;
+ case "N":
+ offset = (1 * 3600000);
+ break;
+ case "Y":
+ offset = (12 * 3600000);
+ break;
+ default:
+ offset = 0;
+ }
+ }
+ else
+ {
+ var multiplier:Number = 1;
+ var oHours:Number = 0;
+ var oMinutes:Number = 0;
+ if (timezone.length != 4)
+ {
+ if (timezone.charAt(0) == "-")
+ {
+ multiplier = -1;
+ }
+ timezone = timezone.substr(1, 4);
+ }
+ oHours = Number(timezone.substr(0, 2));
+ oMinutes = Number(timezone.substr(2, 2));
+ offset = (((oHours * 3600000) + (oMinutes * 60000)) * multiplier);
+ }
+
+ finalDate = new Date(milliseconds - offset);
+
+ if (finalDate.toString() == "Invalid Date")
+ {
+ throw new Error("This date does not conform to RFC822.");
+ }
+ }
+ catch (e:Error)
+ {
+ var eStr:String = "Unable to parse the string [" +str+ "] into a date. ";
+ eStr += "The internal error was: " + e.toString();
+ throw new Error(eStr);
+ }
+ return finalDate;
+ }
+
+ /**
+ * Returns a date string formatted according to RFC822.
+ *
+ * @param d
+ *
+ * @returns
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ *
+ * @see http://asg.web.cmu.edu/rfc/rfc822.html
+ */
+ public static function toRFC822(d:Date):String
+ {
+ var date:Number = d.getUTCDate();
+ var hours:Number = d.getUTCHours();
+ var minutes:Number = d.getUTCMinutes();
+ var seconds:Number = d.getUTCSeconds();
+ var sb:String = new String();
+ sb += DateBase.dayNamesShort[d.getUTCDay()];
+ sb += ", ";
+
+ if (date < 10)
+ {
+ sb += "0";
+ }
+ sb += date;
+ sb += " ";
+ //sb += DateUtil.SHORT_MONTH[d.getUTCMonth()];
+ sb += DateBase.monthNamesShort[d.getUTCMonth()];
+ sb += " ";
+ sb += d.getUTCFullYear();
+ sb += " ";
+ if (hours < 10)
+ {
+ sb += "0";
+ }
+ sb += hours;
+ sb += ":";
+ if (minutes < 10)
+ {
+ sb += "0";
+ }
+ sb += minutes;
+ sb += ":";
+ if (seconds < 10)
+ {
+ sb += "0";
+ }
+ sb += seconds;
+ sb += " GMT";
+ return sb;
+ }
+
+ /**
+ * Parses dates that conform to the W3C Date-time Format into Date objects.
+ *
+ * This function is useful for parsing RSS 1.0 and Atom 1.0 dates.
+ *
+ * @param str
+ *
+ * @returns
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ *
+ * @see http://www.w3.org/TR/NOTE-datetime
+ */
+ public static function parseW3CDTF(str:String):Date
+ {
+ var finalDate:Date;
+ try
+ {
+ var dateStr:String = str.substring(0, str.indexOf("T"));
+ var timeStr:String = str.substring(str.indexOf("T")+1, str.length);
+ var dateArr:Array = dateStr.split("-");
+ var year:Number = Number(dateArr.shift());
+ var month:Number = Number(dateArr.shift());
+ var date:Number = Number(dateArr.shift());
+
+ var multiplier:Number;
+ var offsetHours:Number;
+ var offsetMinutes:Number;
+ var offsetStr:String;
+
+ if (timeStr.indexOf("Z") != -1)
+ {
+ multiplier = 1;
+ offsetHours = 0;
+ offsetMinutes = 0;
+ timeStr = timeStr.replace("Z", "");
+ }
+ else if (timeStr.indexOf("+") != -1)
+ {
+ multiplier = 1;
+ offsetStr = timeStr.substring(timeStr.indexOf("+")+1, timeStr.length);
+ offsetHours = Number(offsetStr.substring(0, offsetStr.indexOf(":")));
+ offsetMinutes = Number(offsetStr.substring(offsetStr.indexOf(":")+1, offsetStr.length));
+ timeStr = timeStr.substring(0, timeStr.indexOf("+"));
+ }
+ else // offset is -
+ {
+ multiplier = -1;
+ offsetStr = timeStr.substring(timeStr.indexOf("-")+1, timeStr.length);
+ offsetHours = Number(offsetStr.substring(0, offsetStr.indexOf(":")));
+ offsetMinutes = Number(offsetStr.substring(offsetStr.indexOf(":")+1, offsetStr.length));
+ timeStr = timeStr.substring(0, timeStr.indexOf("-"));
+ }
+ var timeArr:Array = timeStr.split(":");
+ var hour:Number = Number(timeArr.shift());
+ var minutes:Number = Number(timeArr.shift());
+ var secondsArr:Array = (timeArr.length > 0) ? String(timeArr.shift()).split(".") : null;
+ var seconds:Number = (secondsArr != null && secondsArr.length > 0) ? Number(secondsArr.shift()) : 0;
+ //var milliseconds:Number = (secondsArr != null && secondsArr.length > 0) ? Number(secondsArr.shift()) : 0;
+
+ var milliseconds:Number = (secondsArr != null && secondsArr.length > 0) ? 1000*parseFloat("0." + secondsArr.shift()) : 0;
+ var utc:Number = Date.UTC(year, month-1, date, hour, minutes, seconds, milliseconds);
+ var offset:Number = (((offsetHours * 3600000) + (offsetMinutes * 60000)) * multiplier);
+ finalDate = new Date(utc - offset);
+
+ if (finalDate.toString() == "Invalid Date")
+ {
+ throw new Error("This date does not conform to W3CDTF.");
+ }
+ }
+ catch (e:Error)
+ {
+ var eStr:String = "Unable to parse the string [" +str+ "] into a date. ";
+ eStr += "The internal error was: " + e.toString();
+ throw new Error(eStr);
+ }
+ return finalDate;
+ }
+
+ /**
+ * Returns a date string formatted according to W3CDTF.
+ *
+ * @param d
+ * @param includeMilliseconds Determines whether to include the
+ * milliseconds value (if any) in the formatted string.
+ *
+ * @returns
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ *
+ * @see http://www.w3.org/TR/NOTE-datetime
+ */
+ public static function toW3CDTF(d:Date,includeMilliseconds:Boolean=false):String
+ {
+ var date:Number = d.getUTCDate();
+ var month:Number = d.getUTCMonth();
+ var hours:Number = d.getUTCHours();
+ var minutes:Number = d.getUTCMinutes();
+ var seconds:Number = d.getUTCSeconds();
+ var milliseconds:Number = d.getUTCMilliseconds();
+ var sb:String = new String();
+
+ sb += d.getUTCFullYear();
+ sb += "-";
+
+ //thanks to "dom" who sent in a fix for the line below
+ if (month + 1 < 10)
+ {
+ sb += "0";
+ }
+ sb += month + 1;
+ sb += "-";
+ if (date < 10)
+ {
+ sb += "0";
+ }
+ sb += date;
+ sb += "T";
+ if (hours < 10)
+ {
+ sb += "0";
+ }
+ sb += hours;
+ sb += ":";
+ if (minutes < 10)
+ {
+ sb += "0";
+ }
+ sb += minutes;
+ sb += ":";
+ if (seconds < 10)
+ {
+ sb += "0";
+ }
+ sb += seconds;
+ if (includeMilliseconds && milliseconds > 0)
+ {
+ sb += ".";
+ sb += milliseconds;
+ }
+ sb += "-00:00";
+ return sb;
+ }
+
+ /**
+ * Converts a date into just after midnight.
+ */
+ public static function makeMorning(d:Date):Date
+ {
+ var d:Date = new Date(d.time);
+ d.hours = 0;
+ d.minutes = 0;
+ d.seconds = 0;
+ d.milliseconds = 0;
+ return d;
+ }
+
+ /**
+ * Converts a date into just befor midnight.
+ */
+ public static function makeNight(d:Date):Date
+ {
+ var d:Date = new Date(d.time);
+ d.hours = 23;
+ d.minutes = 59;
+ d.seconds = 59;
+ d.milliseconds = 999;
+ return d;
+ }
+
+ /**
+ * Sort of converts a date into UTC.
+ */
+ public static function getUTCDate(d:Date):Date
+ {
+ var nd:Date = new Date();
+ var offset:Number = d.getTimezoneOffset() * 60 * 1000;
+ nd.setTime(d.getTime() + offset);
+ return nd;
+ }
+ }
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/utils/DictionaryUtil.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/utils/DictionaryUtil.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,87 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.utils
+{
+ import flash.utils.Dictionary;
+
+ public class DictionaryUtil
+ {
+
+ /**
+ * Returns an Array of all keys within the specified dictionary.
+ *
+ * @param d The Dictionary instance whose keys will be returned.
+ *
+ * @return Array of keys contained within the Dictionary
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function getKeys(d:Dictionary):Array
+ {
+ var a:Array = new Array();
+
+ for (var key:Object in d)
+ {
+ a.push(key);
+ }
+
+ return a;
+ }
+
+ /**
+ * Returns an Array of all values within the specified dictionary.
+ *
+ * @param d The Dictionary instance whose values will be returned.
+ *
+ * @return Array of values contained within the Dictionary
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function getValues(d:Dictionary):Array
+ {
+ var a:Array = new Array();
+
+ for each (var value:Object in d)
+ {
+ a.push(value);
+ }
+
+ return a;
+ }
+
+ }
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/utils/IntUtil.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/utils/IntUtil.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,99 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+package com.adobe.utils {
+
+ import flash.utils.Endian;
+
+ /**
+ * Contains reusable methods for operations pertaining
+ * to int values.
+ */
+ public class IntUtil {
+
+ /**
+ * Rotates x left n bits
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function rol ( x:int, n:int ):int {
+ return ( x << n ) | ( x >>> ( 32 - n ) );
+ }
+
+ /**
+ * Rotates x right n bits
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function ror ( x:int, n:int ):uint {
+ var nn:int = 32 - n;
+ return ( x << nn ) | ( x >>> ( 32 - nn ) );
+ }
+
+ /** String for quick lookup of a hex character based on index */
+ private static var hexChars:String = "0123456789abcdef";
+
+ /**
+ * Outputs the hex value of a int, allowing the developer to specify
+ * the endinaness in the process. Hex output is lowercase.
+ *
+ * @param n The int value to output as hex
+ * @param bigEndian Flag to output the int as big or little endian
+ * @return A string of length 8 corresponding to the
+ * hex representation of n ( minus the leading "0x" )
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function toHex( n:int, bigEndian:Boolean = false ):String {
+ var s:String = "";
+
+ if ( bigEndian ) {
+ for ( var i:int = 0; i < 4; i++ ) {
+ s += hexChars.charAt( ( n >> ( ( 3 - i ) * 8 + 4 ) ) & 0xF )
+ + hexChars.charAt( ( n >> ( ( 3 - i ) * 8 ) ) & 0xF );
+ }
+ } else {
+ for ( var x:int = 0; x < 4; x++ ) {
+ s += hexChars.charAt( ( n >> ( x * 8 + 4 ) ) & 0xF )
+ + hexChars.charAt( ( n >> ( x * 8 ) ) & 0xF );
+ }
+ }
+
+ return s;
+ }
+ }
+
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/utils/NumberFormatter.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/utils/NumberFormatter.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,74 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.utils
+{
+
+ /**
+ * Class that contains static utility methods for formatting Numbers
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ *
+ * @see #mx.formatters.NumberFormatter
+ */
+ public class NumberFormatter
+ {
+
+ /**
+ * Formats a number to include a leading zero if it is a single digit
+ * between -1 and 10.
+ *
+ * @param n The number that will be formatted
+ *
+ * @return A string with single digits between -1 and 10 padded with a
+ * leading zero.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function addLeadingZero(n:Number):String
+ {
+ var out:String = String(n);
+
+ if(n < 10 && n > -1)
+ {
+ out = "0" + out;
+ }
+
+ return out;
+ }
+
+ }
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/utils/StringUtil.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/utils/StringUtil.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,239 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.utils
+{
+
+ /**
+ * Class that contains static utility methods for manipulating Strings.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public class StringUtil
+ {
+
+
+ /**
+ * Does a case insensitive compare or two strings and returns true if
+ * they are equal.
+ *
+ * @param s1 The first string to compare.
+ *
+ * @param s2 The second string to compare.
+ *
+ * @returns A boolean value indicating whether the strings' values are
+ * equal in a case sensitive compare.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function stringsAreEqual(s1:String, s2:String,
+ caseSensitive:Boolean):Boolean
+ {
+ if(caseSensitive)
+ {
+ return (s1 == s2);
+ }
+ else
+ {
+ return (s1.toUpperCase() == s2.toUpperCase());
+ }
+ }
+
+ /**
+ * Removes whitespace from the front and the end of the specified
+ * string.
+ *
+ * @param input The String whose beginning and ending whitespace will
+ * will be removed.
+ *
+ * @returns A String with whitespace removed from the begining and end
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function trim(input:String):String
+ {
+ return StringUtil.ltrim(StringUtil.rtrim(input));
+ }
+
+ /**
+ * Removes whitespace from the front of the specified string.
+ *
+ * @param input The String whose beginning whitespace will will be removed.
+ *
+ * @returns A String with whitespace removed from the begining
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function ltrim(input:String):String
+ {
+ var size:Number = input.length;
+ for(var i:Number = 0; i < size; i++)
+ {
+ if(input.charCodeAt(i) > 32)
+ {
+ return input.substring(i);
+ }
+ }
+ return "";
+ }
+
+ /**
+ * Removes whitespace from the end of the specified string.
+ *
+ * @param input The String whose ending whitespace will will be removed.
+ *
+ * @returns A String with whitespace removed from the end
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function rtrim(input:String):String
+ {
+ var size:Number = input.length;
+ for(var i:Number = size; i > 0; i--)
+ {
+ if(input.charCodeAt(i - 1) > 32)
+ {
+ return input.substring(0, i);
+ }
+ }
+
+ return "";
+ }
+
+ /**
+ * Determines whether the specified string begins with the spcified prefix.
+ *
+ * @param input The string that the prefix will be checked against.
+ *
+ * @param prefix The prefix that will be tested against the string.
+ *
+ * @returns True if the string starts with the prefix, false if it does not.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function beginsWith(input:String, prefix:String):Boolean
+ {
+ return (prefix == input.substring(0, prefix.length));
+ }
+
+ /**
+ * Determines whether the specified string ends with the spcified suffix.
+ *
+ * @param input The string that the suffic will be checked against.
+ *
+ * @param prefix The suffic that will be tested against the string.
+ *
+ * @returns True if the string ends with the suffix, false if it does not.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function endsWith(input:String, suffix:String):Boolean
+ {
+ return (suffix == input.substring(input.length - suffix.length));
+ }
+
+ /**
+ * Removes all instances of the remove string in the input string.
+ *
+ * @param input The string that will be checked for instances of remove
+ * string
+ *
+ * @param remove The string that will be removed from the input string.
+ *
+ * @returns A String with the remove string removed.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function remove(input:String, remove:String):String
+ {
+ return StringUtil.replace(input, remove, "");
+ }
+
+ /**
+ * Replaces all instances of the replace string in the input string
+ * with the replaceWith string.
+ *
+ * @param input The string that instances of replace string will be
+ * replaces with removeWith string.
+ *
+ * @param replace The string that will be replaced by instances of
+ * the replaceWith string.
+ *
+ * @param replaceWith The string that will replace instances of replace
+ * string.
+ *
+ * @returns A new String with the replace string replaced with the
+ * replaceWith string.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function replace(input:String, replace:String, replaceWith:String):String
+ {
+ return input.split(replace).join(replaceWith);
+ }
+
+
+ /**
+ * Specifies whether the specified string is either non-null, or contains
+ * characters (i.e. length is greater that 0)
+ *
+ * @param s The string which is being checked for a value
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ * @tiptext
+ */
+ public static function stringHasValue(s:String):Boolean
+ {
+ //todo: this needs a unit test
+ return (s != null && s.length > 0);
+ }
+ }
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/utils/XMLUtil.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/utils/XMLUtil.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,168 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.utils
+{
+
+ public class XMLUtil
+ {
+ /**
+ * Constant representing a text node type returned from XML.nodeKind.
+ *
+ * @see XML.nodeKind()
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ */
+ public static const TEXT:String = "text";
+
+ /**
+ * Constant representing a comment node type returned from XML.nodeKind.
+ *
+ * @see XML.nodeKind()
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ */
+ public static const COMMENT:String = "comment";
+
+ /**
+ * Constant representing a processing instruction type returned from XML.nodeKind.
+ *
+ * @see XML.nodeKind()
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ */
+ public static const PROCESSING_INSTRUCTION:String = "processing-instruction";
+
+ /**
+ * Constant representing an attribute type returned from XML.nodeKind.
+ *
+ * @see XML.nodeKind()
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ */
+ public static const ATTRIBUTE:String = "attribute";
+
+ /**
+ * Constant representing a element type returned from XML.nodeKind.
+ *
+ * @see XML.nodeKind()
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ */
+ public static const ELEMENT:String = "element";
+
+ /**
+ * Checks whether the specified string is valid and well formed XML.
+ *
+ * @param data The string that is being checked to see if it is valid XML.
+ *
+ * @return A Boolean value indicating whether the specified string is
+ * valid XML.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ */
+ public static function isValidXML(data:String):Boolean
+ {
+ var xml:XML;
+
+ try
+ {
+ xml = new XML(data);
+ }
+ catch(e:Error)
+ {
+ return false;
+ }
+
+ if(xml.nodeKind() != XMLUtil.ELEMENT)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns the next sibling of the specified node relative to the node's parent.
+ *
+ * @param x The node whose next sibling will be returned.
+ *
+ * @return The next sibling of the node. null if the node does not have
+ * a sibling after it, or if the node has no parent.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ */
+ public static function getNextSibling(x:XML):XML
+ {
+ return XMLUtil.getSiblingByIndex(x, 1);
+ }
+
+ /**
+ * Returns the sibling before the specified node relative to the node's parent.
+ *
+ * @param x The node whose sibling before it will be returned.
+ *
+ * @return The sibling before the node. null if the node does not have
+ * a sibling before it, or if the node has no parent.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ */
+ public static function getPreviousSibling(x:XML):XML
+ {
+ return XMLUtil.getSiblingByIndex(x, -1);
+ }
+
+ protected static function getSiblingByIndex(x:XML, count:int):XML
+ {
+ var out:XML;
+
+ try
+ {
+ out = x.parent().children()[x.childIndex() + count];
+ }
+ catch(e:Error)
+ {
+ return null;
+ }
+
+ return out;
+ }
+ }
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/webapis/ServiceBase.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/webapis/ServiceBase.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,48 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+package com.adobe.webapis
+{
+ import flash.events.EventDispatcher;
+
+ /**
+ * Base class for remote service classes.
+ */
+ public class ServiceBase extends EventDispatcher
+ {
+ public function ServiceBase()
+ {
+ }
+
+ }
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/webapis/URLLoaderBase.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/webapis/URLLoaderBase.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,108 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.webapis
+{
+ import flash.events.IOErrorEvent;
+ import flash.events.SecurityErrorEvent;
+ import flash.events.ProgressEvent;
+
+ import com.adobe.net.DynamicURLLoader;
+
+ /**
+ * Dispatched when data is
+ * received as the download operation progresses.
+ *
+ * @eventType flash.events.ProgressEvent.PROGRESS
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ */
+ [Event(name="progress", type="flash.events.ProgressEvent")]
+
+ /**
+ * Dispatched if a call to the server results in a fatal
+ * error that terminates the download.
+ *
+ * @eventType flash.events.IOErrorEvent.IO_ERROR
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ */
+ [Event(name="ioError", type="flash.events.IOErrorEvent")]
+
+ /**
+ * A securityError event occurs if a call attempts to
+ * load data from a server outside the security sandbox.
+ *
+ * @eventType flash.events.SecurityErrorEvent.SECURITY_ERROR
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ */
+ [Event(name="securityError", type="flash.events.SecurityErrorEvent")]
+
+ /**
+ * Base class for services that utilize URLLoader
+ * to communicate with remote APIs / Services.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 9.0
+ */
+ public class URLLoaderBase extends ServiceBase
+ {
+ protected function getURLLoader():DynamicURLLoader
+ {
+ var loader:DynamicURLLoader = new DynamicURLLoader();
+ loader.addEventListener("progress", onProgress);
+ loader.addEventListener("ioError", onIOError);
+ loader.addEventListener("securityError", onSecurityError);
+
+ return loader;
+ }
+
+ private function onIOError(event:IOErrorEvent):void
+ {
+ dispatchEvent(event);
+ }
+
+ private function onSecurityError(event:SecurityErrorEvent):void
+ {
+ dispatchEvent(event);
+ }
+
+ private function onProgress(event:ProgressEvent):void
+ {
+ dispatchEvent(event);
+ }
+ }
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/ext/com/adobe/webapis/events/ServiceEvent.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/ext/com/adobe/webapis/events/ServiceEvent.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,82 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+package com.adobe.webapis.events
+{
+
+ import flash.events.Event;
+
+ /**
+ * Event class that contains data loaded from remote services.
+ *
+ * @author Mike Chambers
+ */
+ public class ServiceEvent extends Event
+ {
+ private var _data:Object = new Object();
+
+ /**
+ * Constructor for ServiceEvent class.
+ *
+ * @param type The type of event that the instance represents.
+ */
+ public function ServiceEvent(type:String, bubbles:Boolean = false,
+ cancelable:Boolean=false)
+ {
+ super(type, bubbles, cancelable);
+ }
+
+ /**
+ * This object contains data loaded in response
+ * to remote service calls, and properties associated with that call.
+ */
+ public function get data():Object
+ {
+ return _data;
+ }
+
+ public function set data(d:Object):void
+ {
+ _data = d;
+ }
+
+ public override function clone():Event
+ {
+ var out:ServiceEvent = new ServiceEvent(type, bubbles, cancelable);
+ out.data = data;
+
+ return out;
+ }
+
+ }
+}
\ No newline at end of file
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/src/Main.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/src/Main.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,22 @@
+package
+{
+ import asunit.textui.TestRunner;
+ import asunit.textui.XMLResultPrinter;
+
+ import tests.AllTests;
+
+ import flash.display.Sprite;
+
+ /**
+ * @author mikej
+ */
+ public class Main extends Sprite
+ {
+ public function Main()
+ {
+ var unittests : TestRunner = new TestRunner();
+ stage.addChild(unittests);
+ unittests.start(tests.AllTests, null, TestRunner.SHOW_TRACE);
+ }
+ }
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/src/org/omras2/audiodb/LookupEvent.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/src/org/omras2/audiodb/LookupEvent.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,32 @@
+package org.omras2.audiodb
+{
+ import org.omras2.audiodb.model.Track;
+
+ import flash.events.Event;
+
+ /**
+ * @author mikej
+ */
+ public class LookupEvent extends Event
+ {
+ public static const COMPLETE : String = "complete";
+
+ private var _track : Track;
+
+ public function LookupEvent(type : String, track : Track, bubbles : Boolean = false, cancelable : Boolean = false)
+ {
+ this._track = track;
+ super(type, bubbles, cancelable);
+ }
+
+ public function get track() : Track
+ {
+ return _track;
+ }
+
+ public override function clone() : Event
+ {
+ return new LookupEvent(type, _track, bubbles, cancelable);
+ }
+ }
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/src/org/omras2/audiodb/Querier.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/src/org/omras2/audiodb/Querier.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,81 @@
+package org.omras2.audiodb
+{
+ import com.adobe.serialization.json.JSON;
+
+ import org.omras2.audiodb.model.Track;
+
+ import flash.events.ErrorEvent;
+ import flash.events.Event;
+ import flash.events.EventDispatcher;
+ import flash.events.IOErrorEvent;
+ import flash.net.URLLoader;
+ import flash.net.URLRequest;
+ import flash.utils.Dictionary;
+
+ /**
+ * @author mikej
+ */
+ public class Querier extends EventDispatcher
+ {
+ private var _endpoint : String;
+
+ private var _trackCache : Dictionary;
+
+ public function Querier(endpoint : String)
+ {
+ this._endpoint = endpoint;
+ this._trackCache = new Dictionary();
+ }
+
+ public function lookup(uid : String) : void
+ {
+ if(_trackCache[uid])
+ {
+ this.dispatchEvent(new LookupEvent(LookupEvent.COMPLETE, _trackCache[uid]));
+ }
+ else
+ {
+ var url : String = _endpoint + "/track/" + uid;
+ var req : URLRequest = new URLRequest(url);
+ var loader : URLLoader = new URLLoader();
+
+ try
+ {
+ loader.load(req);
+ }
+ catch(error : SecurityError)
+ {
+ var err : ErrorEvent = new ErrorEvent(ErrorEvent.ERROR);
+ err.text = error.message;
+ this.dispatchEvent(err);
+ }
+
+ loader.addEventListener(IOErrorEvent.IO_ERROR, this.handleLoadError);
+ loader.addEventListener(Event.COMPLETE, this.handleLoadComplete);
+ }
+ }
+
+ private function handleLoadComplete(event : Event) : void
+ {
+ var data : String = (event.target as URLLoader).data as String;
+ var response : Object = (JSON.decode(data) as Object);
+ if(response['status'] != 'ok')
+ {
+ var err : ErrorEvent = new ErrorEvent(ErrorEvent.ERROR);
+ err.text = response['message'];
+ this.dispatchEvent(err);
+ }
+ else
+ {
+ var track : Track = Track.createFromResponse(response['data']);
+ _trackCache[track.uid] = track;
+ this.dispatchEvent(new LookupEvent(LookupEvent.COMPLETE, track));
+ }
+ }
+
+ private function handleLoadError(event : IOErrorEvent) : void
+ {
+ this.dispatchEvent(event);
+ }
+ }
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/src/org/omras2/audiodb/model/Track.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/src/org/omras2/audiodb/model/Track.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,101 @@
+package org.omras2.audiodb.model
+{
+ import flash.utils.Dictionary;
+
+ /**
+ * @author mikej
+ */
+ public class Track
+ {
+ private var _uid : String;
+ private var _album : String;
+ private var _artist : String;
+ private var _seconds : uint;
+ private var _tracknum : uint;
+ private var _track : String;
+ private var _filename : String;
+
+ public static function createFromResponse(response : Object) : Track
+ {
+ var track : Track = new Track();
+ track.uid = response['uid'];
+ track.album = response['album'];
+ track.artist = response['artist'];
+ track.seconds = response['seconds'];
+ track.tracknum = response['tracknum'];
+ track.track = response['track'];
+ track.filename = response['filename'];
+ return track;
+ }
+
+ public function get uid() : String
+ {
+ return _uid;
+ }
+
+ public function set uid(uid : String) : void
+ {
+ _uid = uid;
+ }
+
+ public function get album() : String
+ {
+ return _album;
+ }
+
+ public function set album(album : String) : void
+ {
+ _album = album;
+ }
+
+ public function get artist() : String
+ {
+ return _artist;
+ }
+
+ public function set artist(artist : String) : void
+ {
+ _artist = artist;
+ }
+
+ public function get seconds() : uint
+ {
+ return _seconds;
+ }
+
+ public function set seconds(seconds : uint) : void
+ {
+ _seconds = seconds;
+ }
+
+ public function get tracknum() : uint
+ {
+ return _tracknum;
+ }
+
+ public function set tracknum(tracknum : uint) : void
+ {
+ _tracknum = tracknum;
+ }
+
+ public function get track() : String
+ {
+ return _track;
+ }
+
+ public function set track(track : String) : void
+ {
+ _track = track;
+ }
+
+ public function get filename() : String
+ {
+ return _filename;
+ }
+
+ public function set filename(filename : String) : void
+ {
+ _filename = filename;
+ }
+ }
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/src/tests/AllTests.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/src/tests/AllTests.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,19 @@
+package
+tests
+{
+ import asunit.framework.TestSuite;
+
+ /**
+ * @author mikej
+ */
+ public class AllTests extends TestSuite
+ {
+ public function AllTests()
+ {
+ super();
+
+ addTest(new TestQuerier("testLookupSuccess"));
+ addTest(new TestQuerier("testLookupFail"));
+ }
+ }
+}
diff -r 65134dd772fc -r 3a0b9700b3d2 bindings/as3/src/tests/TestQuerier.as
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/as3/src/tests/TestQuerier.as Tue Sep 14 16:47:10 2010 +0000
@@ -0,0 +1,54 @@
+package tests
+{
+ import asunit.framework.TestCase;
+
+ import org.omras2.audiodb.LookupEvent;
+ import org.omras2.audiodb.Querier;
+
+ import flash.events.ErrorEvent;
+
+ /**
+ * @author mikej
+ */
+ public class TestQuerier extends TestCase
+ {
+ private var _querier : Querier;
+
+ public function TestQuerier(testMethod : String)
+ {
+ super(testMethod);
+ }
+
+ override protected function setUp() : void
+ {
+ super.setUp();
+ this._querier = new Querier("http://127.0.0.1:8080");
+ }
+
+ public function testLookupSuccess() : void
+ {
+ var handler : Function = addAsync(handleLookupSuccessComplete, 2000);
+ _querier.addEventListener(LookupEvent.COMPLETE, handler);
+ _querier.lookup("AWAL1000");
+ }
+
+ public function testLookupFail() : void
+ {
+ var handler : Function = addAsync(handleLookupFailComplete, 2000);
+ _querier.addEventListener(ErrorEvent.ERROR, handler);
+ _querier.lookup("AWAL10000");
+ }
+
+ private function handleLookupFailComplete(event : ErrorEvent) : void
+ {
+ assertEquals(event.text, 'Invalid key');
+ }
+
+ protected function handleLookupSuccessComplete(event : LookupEvent) : void
+ {
+ assertEquals(event.track.uid, 'AWAL1000');
+ assertEquals(event.track.artist, 'Moscow Drive');
+ assertEquals(event.track.seconds, '221000');
+ }
+ }
+}