diff options
| author | sostler <sbostler@gmail.com> | 2010-02-27 23:22:29 -0500 |
|---|---|---|
| committer | sostler <sbostler@gmail.com> | 2010-02-27 23:22:29 -0500 |
| commit | 8e0b068b1d6929af82ef348a47b235dd89196c11 (patch) | |
| tree | 64b5b4caa125c9db737ba1033dd871c2f0b3b108 /webcam/com/adobe | |
| parent | 19603b846364d0f22d725d35321435badc5e41e8 (diff) | |
Fixed CLRF
Diffstat (limited to 'webcam/com/adobe')
26 files changed, 6647 insertions, 6647 deletions
diff --git a/webcam/com/adobe/crypto/MD5.as b/webcam/com/adobe/crypto/MD5.as index d1bba3f..f5c0e02 100644 --- a/webcam/com/adobe/crypto/MD5.as +++ b/webcam/com/adobe/crypto/MD5.as @@ -1,256 +1,256 @@ -/*
-Adobe Systems Incorporated(r) Source Code License Agreement
-Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
-Please read this Source Code License Agreement carefully before using
-the source code.
-
-Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
-no-charge, royalty-free, irrevocable copyright license, to reproduce,
-prepare derivative works of, publicly display, publicly perform, and
-distribute this source code and such derivative works in source or
-object code form without any attribution requirements.
-
-The name "Adobe Systems Incorporated" must not be used to endorse or promote products
-derived from the source code without prior written permission.
-
-You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
-against any loss, damage, claims or lawsuits, including attorney's
-fees that arise or result from your use or distribution of the source
-code.
-
-THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
-ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
-NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
-OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF
-ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package com.adobe.crypto {
-
- import com.adobe.utils.IntUtil;
-
- /**
- * The MD5 Message-Digest Algorithm
- *
- * Implementation based on algorithm description at
- * http://www.faqs.org/rfcs/rfc1321.html
- */
- public class MD5 {
-
- /**
- * Performs the MD5 hash algorithm on a string.
- *
- * @param s The string to hash
- * @return A string containing the hash value of s
- * @langversion ActionScript 3.0
- * @playerversion Flash 9.0
- * @tiptext
- */
- public static function hash( s:String ):String {
- // initialize the md buffers
- var a:int = 1732584193;
- var b:int = -271733879;
- var c:int = -1732584194;
- var d:int = 271733878;
-
- // variables to store previous values
- var aa:int;
- var bb:int;
- var cc:int;
- var dd:int;
-
- // create the blocks from the string and
- // save the length as a local var to reduce
- // lookup in the loop below
- var x:Array = createBlocks( s );
- var len:int = x.length;
-
- // loop over all of the blocks
- for ( var i:int = 0; i < len; i += 16) {
- // save previous values
- aa = a;
- bb = b;
- cc = c;
- dd = d;
-
- // Round 1
- a = ff( a, b, c, d, x[i+ 0], 7, -680876936 ); // 1
- d = ff( d, a, b, c, x[i+ 1], 12, -389564586 ); // 2
- c = ff( c, d, a, b, x[i+ 2], 17, 606105819 ); // 3
- b = ff( b, c, d, a, x[i+ 3], 22, -1044525330 ); // 4
- a = ff( a, b, c, d, x[i+ 4], 7, -176418897 ); // 5
- d = ff( d, a, b, c, x[i+ 5], 12, 1200080426 ); // 6
- c = ff( c, d, a, b, x[i+ 6], 17, -1473231341 ); // 7
- b = ff( b, c, d, a, x[i+ 7], 22, -45705983 ); // 8
- a = ff( a, b, c, d, x[i+ 8], 7, 1770035416 ); // 9
- d = ff( d, a, b, c, x[i+ 9], 12, -1958414417 ); // 10
- c = ff( c, d, a, b, x[i+10], 17, -42063 ); // 11
- b = ff( b, c, d, a, x[i+11], 22, -1990404162 ); // 12
- a = ff( a, b, c, d, x[i+12], 7, 1804603682 ); // 13
- d = ff( d, a, b, c, x[i+13], 12, -40341101 ); // 14
- c = ff( c, d, a, b, x[i+14], 17, -1502002290 ); // 15
- b = ff( b, c, d, a, x[i+15], 22, 1236535329 ); // 16
-
- // Round 2
- a = gg( a, b, c, d, x[i+ 1], 5, -165796510 ); // 17
- d = gg( d, a, b, c, x[i+ 6], 9, -1069501632 ); // 18
- c = gg( c, d, a, b, x[i+11], 14, 643717713 ); // 19
- b = gg( b, c, d, a, x[i+ 0], 20, -373897302 ); // 20
- a = gg( a, b, c, d, x[i+ 5], 5, -701558691 ); // 21
- d = gg( d, a, b, c, x[i+10], 9, 38016083 ); // 22
- c = gg( c, d, a, b, x[i+15], 14, -660478335 ); // 23
- b = gg( b, c, d, a, x[i+ 4], 20, -405537848 ); // 24
- a = gg( a, b, c, d, x[i+ 9], 5, 568446438 ); // 25
- d = gg( d, a, b, c, x[i+14], 9, -1019803690 ); // 26
- c = gg( c, d, a, b, x[i+ 3], 14, -187363961 ); // 27
- b = gg( b, c, d, a, x[i+ 8], 20, 1163531501 ); // 28
- a = gg( a, b, c, d, x[i+13], 5, -1444681467 ); // 29
- d = gg( d, a, b, c, x[i+ 2], 9, -51403784 ); // 30
- c = gg( c, d, a, b, x[i+ 7], 14, 1735328473 ); // 31
- b = gg( b, c, d, a, x[i+12], 20, -1926607734 ); // 32
-
- // Round 3
- a = hh( a, b, c, d, x[i+ 5], 4, -378558 ); // 33
- d = hh( d, a, b, c, x[i+ 8], 11, -2022574463 ); // 34
- c = hh( c, d, a, b, x[i+11], 16, 1839030562 ); // 35
- b = hh( b, c, d, a, x[i+14], 23, -35309556 ); // 36
- a = hh( a, b, c, d, x[i+ 1], 4, -1530992060 ); // 37
- d = hh( d, a, b, c, x[i+ 4], 11, 1272893353 ); // 38
- c = hh( c, d, a, b, x[i+ 7], 16, -155497632 ); // 39
- b = hh( b, c, d, a, x[i+10], 23, -1094730640 ); // 40
- a = hh( a, b, c, d, x[i+13], 4, 681279174 ); // 41
- d = hh( d, a, b, c, x[i+ 0], 11, -358537222 ); // 42
- c = hh( c, d, a, b, x[i+ 3], 16, -722521979 ); // 43
- b = hh( b, c, d, a, x[i+ 6], 23, 76029189 ); // 44
- a = hh( a, b, c, d, x[i+ 9], 4, -640364487 ); // 45
- d = hh( d, a, b, c, x[i+12], 11, -421815835 ); // 46
- c = hh( c, d, a, b, x[i+15], 16, 530742520 ); // 47
- b = hh( b, c, d, a, x[i+ 2], 23, -995338651 ); // 48
-
- // Round 4
- a = ii( a, b, c, d, x[i+ 0], 6, -198630844 ); // 49
- d = ii( d, a, b, c, x[i+ 7], 10, 1126891415 ); // 50
- c = ii( c, d, a, b, x[i+14], 15, -1416354905 ); // 51
- b = ii( b, c, d, a, x[i+ 5], 21, -57434055 ); // 52
- a = ii( a, b, c, d, x[i+12], 6, 1700485571 ); // 53
- d = ii( d, a, b, c, x[i+ 3], 10, -1894986606 ); // 54
- c = ii( c, d, a, b, x[i+10], 15, -1051523 ); // 55
- b = ii( b, c, d, a, x[i+ 1], 21, -2054922799 ); // 56
- a = ii( a, b, c, d, x[i+ 8], 6, 1873313359 ); // 57
- d = ii( d, a, b, c, x[i+15], 10, -30611744 ); // 58
- c = ii( c, d, a, b, x[i+ 6], 15, -1560198380 ); // 59
- b = ii( b, c, d, a, x[i+13], 21, 1309151649 ); // 60
- a = ii( a, b, c, d, x[i+ 4], 6, -145523070 ); // 61
- d = ii( d, a, b, c, x[i+11], 10, -1120210379 ); // 62
- c = ii( c, d, a, b, x[i+ 2], 15, 718787259 ); // 63
- b = ii( b, c, d, a, x[i+ 9], 21, -343485551 ); // 64
-
- a += aa;
- b += bb;
- c += cc;
- d += dd;
- }
-
- // Finish up by concatening the buffers with their hex output
- return IntUtil.toHex( a ) + IntUtil.toHex( b ) + IntUtil.toHex( c ) + IntUtil.toHex( d );
- }
-
- /**
- * Auxiliary function f as defined in RFC
- */
- private static function f( x:int, y:int, z:int ):int {
- return ( x & y ) | ( (~x) & z );
- }
-
- /**
- * Auxiliary function g as defined in RFC
- */
- private static function g( x:int, y:int, z:int ):int {
- return ( x & z ) | ( y & (~z) );
- }
-
- /**
- * Auxiliary function h as defined in RFC
- */
- private static function h( x:int, y:int, z:int ):int {
- return x ^ y ^ z;
- }
-
- /**
- * Auxiliary function i as defined in RFC
- */
- private static function i( x:int, y:int, z:int ):int {
- return y ^ ( x | (~z) );
- }
-
- /**
- * A generic transformation function. The logic of ff, gg, hh, and
- * ii are all the same, minus the function used, so pull that logic
- * out and simplify the method bodies for the transoformation functions.
- */
- private static function transform( func:Function, a:int, b:int, c:int, d:int, x:int, s:int, t:int):int {
- var tmp:int = a + int( func( b, c, d ) ) + x + t;
- return IntUtil.rol( tmp, s ) + b;
- }
-
- /**
- * ff transformation function
- */
- private static function ff ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
- return transform( f, a, b, c, d, x, s, t );
- }
-
- /**
- * gg transformation function
- */
- private static function gg ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
- return transform( g, a, b, c, d, x, s, t );
- }
-
- /**
- * hh transformation function
- */
- private static function hh ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
- return transform( h, a, b, c, d, x, s, t );
- }
-
- /**
- * ii transformation function
- */
- private static function ii ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
- return transform( i, a, b, c, d, x, s, t );
- }
-
- /**
- * Converts a string to a sequence of 16-word blocks
- * that we'll do the processing on. Appends padding
- * and length in the process.
- *
- * @param s The string to split into blocks
- * @return An array containing the blocks that s was
- * split into.
- */
- private static function createBlocks( s:String ):Array {
- var blocks:Array = new Array();
- var len:int = s.length * 8;
- var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
- for( var i:int = 0; i < len; i += 8 ) {
- blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( i % 32 );
- }
-
- // append padding and length
- blocks[ len >> 5 ] |= 0x80 << ( len % 32 );
- blocks[ ( ( ( len + 64 ) >>> 9 ) << 4 ) + 14 ] = len;
- return blocks;
- }
-
- }
+/* +Adobe Systems Incorporated(r) Source Code License Agreement +Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + +Please read this Source Code License Agreement carefully before using +the source code. + +Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable copyright license, to reproduce, +prepare derivative works of, publicly display, publicly perform, and +distribute this source code and such derivative works in source or +object code form without any attribution requirements. + +The name "Adobe Systems Incorporated" must not be used to endorse or promote products +derived from the source code without prior written permission. + +You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and +against any loss, damage, claims or lawsuits, including attorney's +fees that arise or result from your use or distribution of the source +code. + +THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT +ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF +NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA +OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.crypto { + + import com.adobe.utils.IntUtil; + + /** + * The MD5 Message-Digest Algorithm + * + * Implementation based on algorithm description at + * http://www.faqs.org/rfcs/rfc1321.html + */ + public class MD5 { + + /** + * Performs the MD5 hash algorithm on a string. + * + * @param s The string to hash + * @return A string containing the hash value of s + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0 + * @tiptext + */ + public static function hash( s:String ):String { + // initialize the md buffers + var a:int = 1732584193; + var b:int = -271733879; + var c:int = -1732584194; + var d:int = 271733878; + + // variables to store previous values + var aa:int; + var bb:int; + var cc:int; + var dd:int; + + // create the blocks from the string and + // save the length as a local var to reduce + // lookup in the loop below + var x:Array = createBlocks( s ); + var len:int = x.length; + + // loop over all of the blocks + for ( var i:int = 0; i < len; i += 16) { + // save previous values + aa = a; + bb = b; + cc = c; + dd = d; + + // Round 1 + a = ff( a, b, c, d, x[i+ 0], 7, -680876936 ); // 1 + d = ff( d, a, b, c, x[i+ 1], 12, -389564586 ); // 2 + c = ff( c, d, a, b, x[i+ 2], 17, 606105819 ); // 3 + b = ff( b, c, d, a, x[i+ 3], 22, -1044525330 ); // 4 + a = ff( a, b, c, d, x[i+ 4], 7, -176418897 ); // 5 + d = ff( d, a, b, c, x[i+ 5], 12, 1200080426 ); // 6 + c = ff( c, d, a, b, x[i+ 6], 17, -1473231341 ); // 7 + b = ff( b, c, d, a, x[i+ 7], 22, -45705983 ); // 8 + a = ff( a, b, c, d, x[i+ 8], 7, 1770035416 ); // 9 + d = ff( d, a, b, c, x[i+ 9], 12, -1958414417 ); // 10 + c = ff( c, d, a, b, x[i+10], 17, -42063 ); // 11 + b = ff( b, c, d, a, x[i+11], 22, -1990404162 ); // 12 + a = ff( a, b, c, d, x[i+12], 7, 1804603682 ); // 13 + d = ff( d, a, b, c, x[i+13], 12, -40341101 ); // 14 + c = ff( c, d, a, b, x[i+14], 17, -1502002290 ); // 15 + b = ff( b, c, d, a, x[i+15], 22, 1236535329 ); // 16 + + // Round 2 + a = gg( a, b, c, d, x[i+ 1], 5, -165796510 ); // 17 + d = gg( d, a, b, c, x[i+ 6], 9, -1069501632 ); // 18 + c = gg( c, d, a, b, x[i+11], 14, 643717713 ); // 19 + b = gg( b, c, d, a, x[i+ 0], 20, -373897302 ); // 20 + a = gg( a, b, c, d, x[i+ 5], 5, -701558691 ); // 21 + d = gg( d, a, b, c, x[i+10], 9, 38016083 ); // 22 + c = gg( c, d, a, b, x[i+15], 14, -660478335 ); // 23 + b = gg( b, c, d, a, x[i+ 4], 20, -405537848 ); // 24 + a = gg( a, b, c, d, x[i+ 9], 5, 568446438 ); // 25 + d = gg( d, a, b, c, x[i+14], 9, -1019803690 ); // 26 + c = gg( c, d, a, b, x[i+ 3], 14, -187363961 ); // 27 + b = gg( b, c, d, a, x[i+ 8], 20, 1163531501 ); // 28 + a = gg( a, b, c, d, x[i+13], 5, -1444681467 ); // 29 + d = gg( d, a, b, c, x[i+ 2], 9, -51403784 ); // 30 + c = gg( c, d, a, b, x[i+ 7], 14, 1735328473 ); // 31 + b = gg( b, c, d, a, x[i+12], 20, -1926607734 ); // 32 + + // Round 3 + a = hh( a, b, c, d, x[i+ 5], 4, -378558 ); // 33 + d = hh( d, a, b, c, x[i+ 8], 11, -2022574463 ); // 34 + c = hh( c, d, a, b, x[i+11], 16, 1839030562 ); // 35 + b = hh( b, c, d, a, x[i+14], 23, -35309556 ); // 36 + a = hh( a, b, c, d, x[i+ 1], 4, -1530992060 ); // 37 + d = hh( d, a, b, c, x[i+ 4], 11, 1272893353 ); // 38 + c = hh( c, d, a, b, x[i+ 7], 16, -155497632 ); // 39 + b = hh( b, c, d, a, x[i+10], 23, -1094730640 ); // 40 + a = hh( a, b, c, d, x[i+13], 4, 681279174 ); // 41 + d = hh( d, a, b, c, x[i+ 0], 11, -358537222 ); // 42 + c = hh( c, d, a, b, x[i+ 3], 16, -722521979 ); // 43 + b = hh( b, c, d, a, x[i+ 6], 23, 76029189 ); // 44 + a = hh( a, b, c, d, x[i+ 9], 4, -640364487 ); // 45 + d = hh( d, a, b, c, x[i+12], 11, -421815835 ); // 46 + c = hh( c, d, a, b, x[i+15], 16, 530742520 ); // 47 + b = hh( b, c, d, a, x[i+ 2], 23, -995338651 ); // 48 + + // Round 4 + a = ii( a, b, c, d, x[i+ 0], 6, -198630844 ); // 49 + d = ii( d, a, b, c, x[i+ 7], 10, 1126891415 ); // 50 + c = ii( c, d, a, b, x[i+14], 15, -1416354905 ); // 51 + b = ii( b, c, d, a, x[i+ 5], 21, -57434055 ); // 52 + a = ii( a, b, c, d, x[i+12], 6, 1700485571 ); // 53 + d = ii( d, a, b, c, x[i+ 3], 10, -1894986606 ); // 54 + c = ii( c, d, a, b, x[i+10], 15, -1051523 ); // 55 + b = ii( b, c, d, a, x[i+ 1], 21, -2054922799 ); // 56 + a = ii( a, b, c, d, x[i+ 8], 6, 1873313359 ); // 57 + d = ii( d, a, b, c, x[i+15], 10, -30611744 ); // 58 + c = ii( c, d, a, b, x[i+ 6], 15, -1560198380 ); // 59 + b = ii( b, c, d, a, x[i+13], 21, 1309151649 ); // 60 + a = ii( a, b, c, d, x[i+ 4], 6, -145523070 ); // 61 + d = ii( d, a, b, c, x[i+11], 10, -1120210379 ); // 62 + c = ii( c, d, a, b, x[i+ 2], 15, 718787259 ); // 63 + b = ii( b, c, d, a, x[i+ 9], 21, -343485551 ); // 64 + + a += aa; + b += bb; + c += cc; + d += dd; + } + + // Finish up by concatening the buffers with their hex output + return IntUtil.toHex( a ) + IntUtil.toHex( b ) + IntUtil.toHex( c ) + IntUtil.toHex( d ); + } + + /** + * Auxiliary function f as defined in RFC + */ + private static function f( x:int, y:int, z:int ):int { + return ( x & y ) | ( (~x) & z ); + } + + /** + * Auxiliary function g as defined in RFC + */ + private static function g( x:int, y:int, z:int ):int { + return ( x & z ) | ( y & (~z) ); + } + + /** + * Auxiliary function h as defined in RFC + */ + private static function h( x:int, y:int, z:int ):int { + return x ^ y ^ z; + } + + /** + * Auxiliary function i as defined in RFC + */ + private static function i( x:int, y:int, z:int ):int { + return y ^ ( x | (~z) ); + } + + /** + * A generic transformation function. The logic of ff, gg, hh, and + * ii are all the same, minus the function used, so pull that logic + * out and simplify the method bodies for the transoformation functions. + */ + private static function transform( func:Function, a:int, b:int, c:int, d:int, x:int, s:int, t:int):int { + var tmp:int = a + int( func( b, c, d ) ) + x + t; + return IntUtil.rol( tmp, s ) + b; + } + + /** + * ff transformation function + */ + private static function ff ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int { + return transform( f, a, b, c, d, x, s, t ); + } + + /** + * gg transformation function + */ + private static function gg ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int { + return transform( g, a, b, c, d, x, s, t ); + } + + /** + * hh transformation function + */ + private static function hh ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int { + return transform( h, a, b, c, d, x, s, t ); + } + + /** + * ii transformation function + */ + private static function ii ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int { + return transform( i, a, b, c, d, x, s, t ); + } + + /** + * Converts a string to a sequence of 16-word blocks + * that we'll do the processing on. Appends padding + * and length in the process. + * + * @param s The string to split into blocks + * @return An array containing the blocks that s was + * split into. + */ + private static function createBlocks( s:String ):Array { + var blocks:Array = new Array(); + var len:int = s.length * 8; + var mask:int = 0xFF; // ignore hi byte of characters > 0xFF + for( var i:int = 0; i < len; i += 8 ) { + blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( i % 32 ); + } + + // append padding and length + blocks[ len >> 5 ] |= 0x80 << ( len % 32 ); + blocks[ ( ( ( len + 64 ) >>> 9 ) << 4 ) + 14 ] = len; + return blocks; + } + + } }
\ No newline at end of file diff --git a/webcam/com/adobe/crypto/SHA1.as b/webcam/com/adobe/crypto/SHA1.as index 823ea5d..793157d 100644 --- a/webcam/com/adobe/crypto/SHA1.as +++ b/webcam/com/adobe/crypto/SHA1.as @@ -1,268 +1,268 @@ -/*
-Adobe Systems Incorporated(r) Source Code License Agreement
-Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
-Please read this Source Code License Agreement carefully before using
-the source code.
-
-Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
-no-charge, royalty-free, irrevocable copyright license, to reproduce,
-prepare derivative works of, publicly display, publicly perform, and
-distribute this source code and such derivative works in source or
-object code form without any attribution requirements.
-
-The name "Adobe Systems Incorporated" must not be used to endorse or promote products
-derived from the source code without prior written permission.
-
-You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
-against any loss, damage, claims or lawsuits, including attorney's
-fees that arise or result from your use or distribution of the source
-code.
-
-THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
-ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
-NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
-OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF
-ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package com.adobe.crypto
-{
- import com.adobe.utils.IntUtil;
- import flash.utils.ByteArray;
- import mx.utils.Base64Encoder;
-
- /**
- * US Secure Hash Algorithm 1 (SHA1)
- *
- * Implementation based on algorithm description at
- * http://www.faqs.org/rfcs/rfc3174.html
- */
- public class SHA1
- {
- /**
- * Performs the SHA1 hash algorithm on a string.
- *
- * @param s The string to hash
- * @return A string containing the hash value of s
- * @langversion ActionScript 3.0
- * @playerversion 9.0
- * @tiptext
- */
- public static function hash( s:String ):String
- {
- var blocks:Array = createBlocksFromString( s );
- var byteArray:ByteArray = hashBlocks( blocks );
-
- return IntUtil.toHex( byteArray.readInt(), true )
- + IntUtil.toHex( byteArray.readInt(), true )
- + IntUtil.toHex( byteArray.readInt(), true )
- + IntUtil.toHex( byteArray.readInt(), true )
- + IntUtil.toHex( byteArray.readInt(), true );
- }
-
- /**
- * Performs the SHA1 hash algorithm on a ByteArray.
- *
- * @param data The ByteArray data to hash
- * @return A string containing the hash value of data
- * @langversion ActionScript 3.0
- * @playerversion 9.0
- */
- public static function hashBytes( data:ByteArray ):String
- {
- var blocks:Array = SHA1.createBlocksFromByteArray( data );
- var byteArray:ByteArray = hashBlocks(blocks);
-
- return IntUtil.toHex( byteArray.readInt(), true )
- + IntUtil.toHex( byteArray.readInt(), true )
- + IntUtil.toHex( byteArray.readInt(), true )
- + IntUtil.toHex( byteArray.readInt(), true )
- + IntUtil.toHex( byteArray.readInt(), true );
- }
-
- /**
- * Performs the SHA1 hash algorithm on a string, then does
- * Base64 encoding on the result.
- *
- * @param s The string to hash
- * @return The base64 encoded hash value of s
- * @langversion ActionScript 3.0
- * @playerversion 9.0
- * @tiptext
- */
- public static function hashToBase64( s:String ):String
- {
- var blocks:Array = SHA1.createBlocksFromString( s );
- var byteArray:ByteArray = hashBlocks(blocks);
-
- // ByteArray.toString() returns the contents as a UTF-8 string,
- // which we can't use because certain byte sequences might trigger
- // a UTF-8 conversion. Instead, we convert the bytes to characters
- // one by one.
- var charsInByteArray:String = "";
- byteArray.position = 0;
- for (var j:int = 0; j < byteArray.length; j++)
- {
- var byte:uint = byteArray.readUnsignedByte();
- charsInByteArray += String.fromCharCode(byte);
- }
-
- var encoder:Base64Encoder = new Base64Encoder();
- encoder.encode(charsInByteArray);
- return encoder.flush();
- }
-
- private static function hashBlocks( blocks:Array ):ByteArray
- {
- // initialize the h's
- var h0:int = 0x67452301;
- var h1:int = 0xefcdab89;
- var h2:int = 0x98badcfe;
- var h3:int = 0x10325476;
- var h4:int = 0xc3d2e1f0;
-
- var len:int = blocks.length;
- var w:Array = new Array( 80 );
-
- // loop over all of the blocks
- for ( var i:int = 0; i < len; i += 16 ) {
-
- // 6.1.c
- var a:int = h0;
- var b:int = h1;
- var c:int = h2;
- var d:int = h3;
- var e:int = h4;
-
- // 80 steps to process each block
- // TODO: unroll for faster execution, or 4 loops of
- // 20 each to avoid the k and f function calls
- for ( var t:int = 0; t < 80; t++ ) {
-
- if ( t < 16 ) {
- // 6.1.a
- w[ t ] = blocks[ i + t ];
- } else {
- // 6.1.b
- w[ t ] = IntUtil.rol( w[ t - 3 ] ^ w[ t - 8 ] ^ w[ t - 14 ] ^ w[ t - 16 ], 1 );
- }
-
- // 6.1.d
- var temp:int = IntUtil.rol( a, 5 ) + f( t, b, c, d ) + e + int( w[ t ] ) + k( t );
-
- e = d;
- d = c;
- c = IntUtil.rol( b, 30 );
- b = a;
- a = temp;
- }
-
- // 6.1.e
- h0 += a;
- h1 += b;
- h2 += c;
- h3 += d;
- h4 += e;
- }
-
- var byteArray:ByteArray = new ByteArray();
- byteArray.writeInt(h0);
- byteArray.writeInt(h1);
- byteArray.writeInt(h2);
- byteArray.writeInt(h3);
- byteArray.writeInt(h4);
- byteArray.position = 0;
- return byteArray;
- }
-
- /**
- * Performs the logical function based on t
- */
- private static function f( t:int, b:int, c:int, d:int ):int {
- if ( t < 20 ) {
- return ( b & c ) | ( ~b & d );
- } else if ( t < 40 ) {
- return b ^ c ^ d;
- } else if ( t < 60 ) {
- return ( b & c ) | ( b & d ) | ( c & d );
- }
- return b ^ c ^ d;
- }
-
- /**
- * Determines the constant value based on t
- */
- private static function k( t:int ):int {
- if ( t < 20 ) {
- return 0x5a827999;
- } else if ( t < 40 ) {
- return 0x6ed9eba1;
- } else if ( t < 60 ) {
- return 0x8f1bbcdc;
- }
- return 0xca62c1d6;
- }
-
- /**
- * Converts a ByteArray to a sequence of 16-word blocks
- * that we'll do the processing on. Appends padding
- * and length in the process.
- *
- * @param data The data to split into blocks
- * @return An array containing the blocks into which data was split
- */
- private static function createBlocksFromByteArray( data:ByteArray ):Array
- {
- var oldPosition:int = data.position;
- data.position = 0;
-
- var blocks:Array = new Array();
- var len:int = data.length * 8;
- var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
- for( var i:int = 0; i < len; i += 8 )
- {
- blocks[ i >> 5 ] |= ( data.readByte() & mask ) << ( 24 - i % 32 );
- }
-
- // append padding and length
- blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
- blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
-
- data.position = oldPosition;
-
- return blocks;
- }
-
- /**
- * Converts a string to a sequence of 16-word blocks
- * that we'll do the processing on. Appends padding
- * and length in the process.
- *
- * @param s The string to split into blocks
- * @return An array containing the blocks that s was split into.
- */
- private static function createBlocksFromString( s:String ):Array
- {
- var blocks:Array = new Array();
- var len:int = s.length * 8;
- var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
- for( var i:int = 0; i < len; i += 8 ) {
- blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( 24 - i % 32 );
- }
-
- // append padding and length
- blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
- blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
- return blocks;
- }
-
- }
+/* +Adobe Systems Incorporated(r) Source Code License Agreement +Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + +Please read this Source Code License Agreement carefully before using +the source code. + +Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable copyright license, to reproduce, +prepare derivative works of, publicly display, publicly perform, and +distribute this source code and such derivative works in source or +object code form without any attribution requirements. + +The name "Adobe Systems Incorporated" must not be used to endorse or promote products +derived from the source code without prior written permission. + +You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and +against any loss, damage, claims or lawsuits, including attorney's +fees that arise or result from your use or distribution of the source +code. + +THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT +ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF +NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA +OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.crypto +{ + import com.adobe.utils.IntUtil; + import flash.utils.ByteArray; + import mx.utils.Base64Encoder; + + /** + * US Secure Hash Algorithm 1 (SHA1) + * + * Implementation based on algorithm description at + * http://www.faqs.org/rfcs/rfc3174.html + */ + public class SHA1 + { + /** + * Performs the SHA1 hash algorithm on a string. + * + * @param s The string to hash + * @return A string containing the hash value of s + * @langversion ActionScript 3.0 + * @playerversion 9.0 + * @tiptext + */ + public static function hash( s:String ):String + { + var blocks:Array = createBlocksFromString( s ); + var byteArray:ByteArray = hashBlocks( blocks ); + + return IntUtil.toHex( byteArray.readInt(), true ) + + IntUtil.toHex( byteArray.readInt(), true ) + + IntUtil.toHex( byteArray.readInt(), true ) + + IntUtil.toHex( byteArray.readInt(), true ) + + IntUtil.toHex( byteArray.readInt(), true ); + } + + /** + * Performs the SHA1 hash algorithm on a ByteArray. + * + * @param data The ByteArray data to hash + * @return A string containing the hash value of data + * @langversion ActionScript 3.0 + * @playerversion 9.0 + */ + public static function hashBytes( data:ByteArray ):String + { + var blocks:Array = SHA1.createBlocksFromByteArray( data ); + var byteArray:ByteArray = hashBlocks(blocks); + + return IntUtil.toHex( byteArray.readInt(), true ) + + IntUtil.toHex( byteArray.readInt(), true ) + + IntUtil.toHex( byteArray.readInt(), true ) + + IntUtil.toHex( byteArray.readInt(), true ) + + IntUtil.toHex( byteArray.readInt(), true ); + } + + /** + * Performs the SHA1 hash algorithm on a string, then does + * Base64 encoding on the result. + * + * @param s The string to hash + * @return The base64 encoded hash value of s + * @langversion ActionScript 3.0 + * @playerversion 9.0 + * @tiptext + */ + public static function hashToBase64( s:String ):String + { + var blocks:Array = SHA1.createBlocksFromString( s ); + var byteArray:ByteArray = hashBlocks(blocks); + + // ByteArray.toString() returns the contents as a UTF-8 string, + // which we can't use because certain byte sequences might trigger + // a UTF-8 conversion. Instead, we convert the bytes to characters + // one by one. + var charsInByteArray:String = ""; + byteArray.position = 0; + for (var j:int = 0; j < byteArray.length; j++) + { + var byte:uint = byteArray.readUnsignedByte(); + charsInByteArray += String.fromCharCode(byte); + } + + var encoder:Base64Encoder = new Base64Encoder(); + encoder.encode(charsInByteArray); + return encoder.flush(); + } + + private static function hashBlocks( blocks:Array ):ByteArray + { + // initialize the h's + var h0:int = 0x67452301; + var h1:int = 0xefcdab89; + var h2:int = 0x98badcfe; + var h3:int = 0x10325476; + var h4:int = 0xc3d2e1f0; + + var len:int = blocks.length; + var w:Array = new Array( 80 ); + + // loop over all of the blocks + for ( var i:int = 0; i < len; i += 16 ) { + + // 6.1.c + var a:int = h0; + var b:int = h1; + var c:int = h2; + var d:int = h3; + var e:int = h4; + + // 80 steps to process each block + // TODO: unroll for faster execution, or 4 loops of + // 20 each to avoid the k and f function calls + for ( var t:int = 0; t < 80; t++ ) { + + if ( t < 16 ) { + // 6.1.a + w[ t ] = blocks[ i + t ]; + } else { + // 6.1.b + w[ t ] = IntUtil.rol( w[ t - 3 ] ^ w[ t - 8 ] ^ w[ t - 14 ] ^ w[ t - 16 ], 1 ); + } + + // 6.1.d + var temp:int = IntUtil.rol( a, 5 ) + f( t, b, c, d ) + e + int( w[ t ] ) + k( t ); + + e = d; + d = c; + c = IntUtil.rol( b, 30 ); + b = a; + a = temp; + } + + // 6.1.e + h0 += a; + h1 += b; + h2 += c; + h3 += d; + h4 += e; + } + + var byteArray:ByteArray = new ByteArray(); + byteArray.writeInt(h0); + byteArray.writeInt(h1); + byteArray.writeInt(h2); + byteArray.writeInt(h3); + byteArray.writeInt(h4); + byteArray.position = 0; + return byteArray; + } + + /** + * Performs the logical function based on t + */ + private static function f( t:int, b:int, c:int, d:int ):int { + if ( t < 20 ) { + return ( b & c ) | ( ~b & d ); + } else if ( t < 40 ) { + return b ^ c ^ d; + } else if ( t < 60 ) { + return ( b & c ) | ( b & d ) | ( c & d ); + } + return b ^ c ^ d; + } + + /** + * Determines the constant value based on t + */ + private static function k( t:int ):int { + if ( t < 20 ) { + return 0x5a827999; + } else if ( t < 40 ) { + return 0x6ed9eba1; + } else if ( t < 60 ) { + return 0x8f1bbcdc; + } + return 0xca62c1d6; + } + + /** + * Converts a ByteArray to a sequence of 16-word blocks + * that we'll do the processing on. Appends padding + * and length in the process. + * + * @param data The data to split into blocks + * @return An array containing the blocks into which data was split + */ + private static function createBlocksFromByteArray( data:ByteArray ):Array + { + var oldPosition:int = data.position; + data.position = 0; + + var blocks:Array = new Array(); + var len:int = data.length * 8; + var mask:int = 0xFF; // ignore hi byte of characters > 0xFF + for( var i:int = 0; i < len; i += 8 ) + { + blocks[ i >> 5 ] |= ( data.readByte() & mask ) << ( 24 - i % 32 ); + } + + // append padding and length + blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 ); + blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len; + + data.position = oldPosition; + + return blocks; + } + + /** + * Converts a string to a sequence of 16-word blocks + * that we'll do the processing on. Appends padding + * and length in the process. + * + * @param s The string to split into blocks + * @return An array containing the blocks that s was split into. + */ + private static function createBlocksFromString( s:String ):Array + { + var blocks:Array = new Array(); + var len:int = s.length * 8; + var mask:int = 0xFF; // ignore hi byte of characters > 0xFF + for( var i:int = 0; i < len; i += 8 ) { + blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( 24 - i % 32 ); + } + + // append padding and length + blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 ); + blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len; + return blocks; + } + + } }
\ No newline at end of file diff --git a/webcam/com/adobe/crypto/WSSEUsernameToken.as b/webcam/com/adobe/crypto/WSSEUsernameToken.as index b0c40f9..58a3360 100644 --- a/webcam/com/adobe/crypto/WSSEUsernameToken.as +++ b/webcam/com/adobe/crypto/WSSEUsernameToken.as @@ -1,117 +1,117 @@ -/*
-Adobe Systems Incorporated(r) Source Code License Agreement
-Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
-Please read this Source Code License Agreement carefully before using
-the source code.
-
-Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
-no-charge, royalty-free, irrevocable copyright license, to reproduce,
-prepare derivative works of, publicly display, publicly perform, and
-distribute this source code and such derivative works in source or
-object code form without any attribution requirements.
-
-The name "Adobe Systems Incorporated" must not be used to endorse or promote products
-derived from the source code without prior written permission.
-
-You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
-against any loss, damage, claims or lawsuits, including attorney's
-fees that arise or result from your use or distribution of the source
-code.
-
-THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
-ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
-NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
-OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF
-ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package com.adobe.crypto
-{
- import mx.formatters.DateFormatter;
- import mx.utils.Base64Encoder;
-
- /**
- * Web Services Security Username Token
- *
- * Implementation based on algorithm description at
- * http://www.oasis-open.org/committees/wss/documents/WSS-Username-02-0223-merged.pdf
- */
- public class WSSEUsernameToken
- {
- /**
- * Generates a WSSE Username Token.
- *
- * @param username The username
- * @param password The password
- * @param nonce A cryptographically random nonce (if null, the nonce
- * will be generated)
- * @param timestamp The time at which the token is generated (if null,
- * the time will be set to the moment of execution)
- * @return The generated token
- * @langversion ActionScript 3.0
- * @playerversion Flash 9.0
- * @tiptext
- */
- public static function getUsernameToken(username:String, password:String, nonce:String=null, timestamp:Date=null):String
- {
- if (nonce == null)
- {
- nonce = generateNonce();
- }
- nonce = base64Encode(nonce);
-
- var created:String = generateTimestamp(timestamp);
-
- var password64:String = getBase64Digest(nonce,
- created,
- password);
-
- var token:String = new String("UsernameToken Username=\"");
- token += username + "\", " +
- "PasswordDigest=\"" + password64 + "\", " +
- "Nonce=\"" + nonce + "\", " +
- "Created=\"" + created + "\"";
- return token;
- }
-
- private static function generateNonce():String
- {
- // Math.random returns a Number between 0 and 1. We don't want our
- // nonce to contain invalid characters (e.g. the period) so we
- // strip them out before returning the result.
- var s:String = Math.random().toString();
- return s.replace(".", "");
- }
-
- internal static function base64Encode(s:String):String
- {
- var encoder:Base64Encoder = new Base64Encoder();
- encoder.encode(s);
- return encoder.flush();
- }
-
- internal static function generateTimestamp(timestamp:Date):String
- {
- if (timestamp == null)
- {
- timestamp = new Date();
- }
- var dateFormatter:DateFormatter = new DateFormatter();
- dateFormatter.formatString = "YYYY-MM-DDTJJ:NN:SS"
- return dateFormatter.format(timestamp) + "Z";
- }
-
- internal static function getBase64Digest(nonce:String, created:String, password:String):String
- {
- return SHA1.hashToBase64(nonce + created + password);
- }
- }
+/* +Adobe Systems Incorporated(r) Source Code License Agreement +Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + +Please read this Source Code License Agreement carefully before using +the source code. + +Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable copyright license, to reproduce, +prepare derivative works of, publicly display, publicly perform, and +distribute this source code and such derivative works in source or +object code form without any attribution requirements. + +The name "Adobe Systems Incorporated" must not be used to endorse or promote products +derived from the source code without prior written permission. + +You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and +against any loss, damage, claims or lawsuits, including attorney's +fees that arise or result from your use or distribution of the source +code. + +THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT +ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF +NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA +OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.crypto +{ + import mx.formatters.DateFormatter; + import mx.utils.Base64Encoder; + + /** + * Web Services Security Username Token + * + * Implementation based on algorithm description at + * http://www.oasis-open.org/committees/wss/documents/WSS-Username-02-0223-merged.pdf + */ + public class WSSEUsernameToken + { + /** + * Generates a WSSE Username Token. + * + * @param username The username + * @param password The password + * @param nonce A cryptographically random nonce (if null, the nonce + * will be generated) + * @param timestamp The time at which the token is generated (if null, + * the time will be set to the moment of execution) + * @return The generated token + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0 + * @tiptext + */ + public static function getUsernameToken(username:String, password:String, nonce:String=null, timestamp:Date=null):String + { + if (nonce == null) + { + nonce = generateNonce(); + } + nonce = base64Encode(nonce); + + var created:String = generateTimestamp(timestamp); + + var password64:String = getBase64Digest(nonce, + created, + password); + + var token:String = new String("UsernameToken Username=\""); + token += username + "\", " + + "PasswordDigest=\"" + password64 + "\", " + + "Nonce=\"" + nonce + "\", " + + "Created=\"" + created + "\""; + return token; + } + + private static function generateNonce():String + { + // Math.random returns a Number between 0 and 1. We don't want our + // nonce to contain invalid characters (e.g. the period) so we + // strip them out before returning the result. + var s:String = Math.random().toString(); + return s.replace(".", ""); + } + + internal static function base64Encode(s:String):String + { + var encoder:Base64Encoder = new Base64Encoder(); + encoder.encode(s); + return encoder.flush(); + } + + internal static function generateTimestamp(timestamp:Date):String + { + if (timestamp == null) + { + timestamp = new Date(); + } + var dateFormatter:DateFormatter = new DateFormatter(); + dateFormatter.formatString = "YYYY-MM-DDTJJ:NN:SS" + return dateFormatter.format(timestamp) + "Z"; + } + + internal static function getBase64Digest(nonce:String, created:String, password:String):String + { + return SHA1.hashToBase64(nonce + created + password); + } + } }
\ No newline at end of file diff --git a/webcam/com/adobe/errors/IllegalStateError.as b/webcam/com/adobe/errors/IllegalStateError.as index 681cf91..2c83e36 100644 --- a/webcam/com/adobe/errors/IllegalStateError.as +++ b/webcam/com/adobe/errors/IllegalStateError.as @@ -1,66 +1,66 @@ -/*
- Adobe Systems Incorporated(r) Source Code License Agreement
- Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
- Please read this Source Code License Agreement carefully before using
- the source code.
-
- Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
- no-charge, royalty-free, irrevocable copyright license, to reproduce,
- prepare derivative works of, publicly display, publicly perform, and
- distribute this source code and such derivative works in source or
- object code form without any attribution requirements.
-
- The name "Adobe Systems Incorporated" must not be used to endorse or promote products
- derived from the source code without prior written permission.
-
- You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
- against any loss, damage, claims or lawsuits, including attorney's
- fees that arise or result from your use or distribution of the source
- code.
-
- THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
- ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
- NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
- OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package com.adobe.errors
-{
- /**
- * This class represents an Error that is thrown when a method is called when
- * the receiving instance is in an invalid state.
- *
- * For example, this may occur if a method has been called, and other properties
- * in the instance have not been initialized properly.
- *
- * @langversion ActionScript 3.0
- * @playerversion Flash 9.0
- * @tiptext
- *
- */
- public class IllegalStateError extends Error
- {
- /**
- * Constructor
- *
- * @param message A message describing the error in detail.
- *
- * @langversion ActionScript 3.0
- * @playerversion Flash 9.0
- * @tiptext
- */
- public function IllegalStateError(message:String)
- {
- super(message);
- }
- }
+/* + Adobe Systems Incorporated(r) Source Code License Agreement + Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + + Please read this Source Code License Agreement carefully before using + the source code. + + Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, + no-charge, royalty-free, irrevocable copyright license, to reproduce, + prepare derivative works of, publicly display, publicly perform, and + distribute this source code and such derivative works in source or + object code form without any attribution requirements. + + The name "Adobe Systems Incorporated" must not be used to endorse or promote products + derived from the source code without prior written permission. + + You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and + against any loss, damage, claims or lawsuits, including attorney's + fees that arise or result from your use or distribution of the source + code. + + THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT + ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF + NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA + OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.errors +{ + /** + * This class represents an Error that is thrown when a method is called when + * the receiving instance is in an invalid state. + * + * For example, this may occur if a method has been called, and other properties + * in the instance have not been initialized properly. + * + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0 + * @tiptext + * + */ + public class IllegalStateError extends Error + { + /** + * Constructor + * + * @param message A message describing the error in detail. + * + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0 + * @tiptext + */ + public function IllegalStateError(message:String) + { + super(message); + } + } }
\ No newline at end of file diff --git a/webcam/com/adobe/images/BitString.as b/webcam/com/adobe/images/BitString.as index 7e1ff14..5d89c93 100644 --- a/webcam/com/adobe/images/BitString.as +++ b/webcam/com/adobe/images/BitString.as @@ -1,42 +1,42 @@ -/*
- Adobe Systems Incorporated(r) Source Code License Agreement
- Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
- Please read this Source Code License Agreement carefully before using
- the source code.
-
- Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
- no-charge, royalty-free, irrevocable copyright license, to reproduce,
- prepare derivative works of, publicly display, publicly perform, and
- distribute this source code and such derivative works in source or
- object code form without any attribution requirements.
-
- The name "Adobe Systems Incorporated" must not be used to endorse or promote products
- derived from the source code without prior written permission.
-
- You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
- against any loss, damage, claims or lawsuits, including attorney's
- fees that arise or result from your use or distribution of the source
- code.
-
- THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
- ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
- NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
- OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-package com.adobe.images
-{
- public class BitString
- {
- public var len:int = 0;
- public var val:int = 0;
- }
+/* + Adobe Systems Incorporated(r) Source Code License Agreement + Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + + Please read this Source Code License Agreement carefully before using + the source code. + + Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, + no-charge, royalty-free, irrevocable copyright license, to reproduce, + prepare derivative works of, publicly display, publicly perform, and + distribute this source code and such derivative works in source or + object code form without any attribution requirements. + + The name "Adobe Systems Incorporated" must not be used to endorse or promote products + derived from the source code without prior written permission. + + You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and + against any loss, damage, claims or lawsuits, including attorney's + fees that arise or result from your use or distribution of the source + code. + + THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT + ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF + NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA + OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +package com.adobe.images +{ + public class BitString + { + public var len:int = 0; + public var val:int = 0; + } }
\ No newline at end of file diff --git a/webcam/com/adobe/images/JPGEncoder.as b/webcam/com/adobe/images/JPGEncoder.as index 4c6ad63..1679976 100644 --- a/webcam/com/adobe/images/JPGEncoder.as +++ b/webcam/com/adobe/images/JPGEncoder.as @@ -1,651 +1,651 @@ -/*
- Adobe Systems Incorporated(r) Source Code License Agreement
- Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
- Please read this Source Code License Agreement carefully before using
- the source code.
-
- Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
- no-charge, royalty-free, irrevocable copyright license, to reproduce,
- prepare derivative works of, publicly display, publicly perform, and
- distribute this source code and such derivative works in source or
- object code form without any attribution requirements.
-
- The name "Adobe Systems Incorporated" must not be used to endorse or promote products
- derived from the source code without prior written permission.
-
- You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
- against any loss, damage, claims or lawsuits, including attorney's
- fees that arise or result from your use or distribution of the source
- code.
-
- THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
- ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
- NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
- OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-package com.adobe.images
-{
- import flash.geom.*;
- import flash.display.*;
- import flash.utils.*;
-
- /**
- * Class that converts BitmapData into a valid JPEG
- */
- public class JPGEncoder
- {
-
- // Static table initialization
-
- private var ZigZag:Array = [
- 0, 1, 5, 6,14,15,27,28,
- 2, 4, 7,13,16,26,29,42,
- 3, 8,12,17,25,30,41,43,
- 9,11,18,24,31,40,44,53,
- 10,19,23,32,39,45,52,54,
- 20,22,33,38,46,51,55,60,
- 21,34,37,47,50,56,59,61,
- 35,36,48,49,57,58,62,63
- ];
-
- private var YTable:Array = new Array(64);
- private var UVTable:Array = new Array(64);
- private var fdtbl_Y:Array = new Array(64);
- private var fdtbl_UV:Array = new Array(64);
-
- private function initQuantTables(sf:int):void
- {
- var i:int;
- var t:Number;
- var YQT:Array = [
- 16, 11, 10, 16, 24, 40, 51, 61,
- 12, 12, 14, 19, 26, 58, 60, 55,
- 14, 13, 16, 24, 40, 57, 69, 56,
- 14, 17, 22, 29, 51, 87, 80, 62,
- 18, 22, 37, 56, 68,109,103, 77,
- 24, 35, 55, 64, 81,104,113, 92,
- 49, 64, 78, 87,103,121,120,101,
- 72, 92, 95, 98,112,100,103, 99
- ];
- for (i = 0; i < 64; i++) {
- t = Math.floor((YQT[i]*sf+50)/100);
- if (t < 1) {
- t = 1;
- } else if (t > 255) {
- t = 255;
- }
- YTable[ZigZag[i]] = t;
- }
- var UVQT:Array = [
- 17, 18, 24, 47, 99, 99, 99, 99,
- 18, 21, 26, 66, 99, 99, 99, 99,
- 24, 26, 56, 99, 99, 99, 99, 99,
- 47, 66, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99
- ];
- for (i = 0; i < 64; i++) {
- t = Math.floor((UVQT[i]*sf+50)/100);
- if (t < 1) {
- t = 1;
- } else if (t > 255) {
- t = 255;
- }
- UVTable[ZigZag[i]] = t;
- }
- var aasf:Array = [
- 1.0, 1.387039845, 1.306562965, 1.175875602,
- 1.0, 0.785694958, 0.541196100, 0.275899379
- ];
- i = 0;
- for (var row:int = 0; row < 8; row++)
- {
- for (var col:int = 0; col < 8; col++)
- {
- fdtbl_Y[i] = (1.0 / (YTable [ZigZag[i]] * aasf[row] * aasf[col] * 8.0));
- fdtbl_UV[i] = (1.0 / (UVTable[ZigZag[i]] * aasf[row] * aasf[col] * 8.0));
- i++;
- }
- }
- }
-
- private var YDC_HT:Array;
- private var UVDC_HT:Array;
- private var YAC_HT:Array;
- private var UVAC_HT:Array;
-
- private function computeHuffmanTbl(nrcodes:Array, std_table:Array):Array
- {
- var codevalue:int = 0;
- var pos_in_table:int = 0;
- var HT:Array = new Array();
- for (var k:int=1; k<=16; k++) {
- for (var j:int=1; j<=nrcodes[k]; j++) {
- HT[std_table[pos_in_table]] = new BitString();
- HT[std_table[pos_in_table]].val = codevalue;
- HT[std_table[pos_in_table]].len = k;
- pos_in_table++;
- codevalue++;
- }
- codevalue*=2;
- }
- return HT;
- }
-
- private var std_dc_luminance_nrcodes:Array = [0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0];
- private var std_dc_luminance_values:Array = [0,1,2,3,4,5,6,7,8,9,10,11];
- private var std_ac_luminance_nrcodes:Array = [0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d];
- private var std_ac_luminance_values:Array = [
- 0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,
- 0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,
- 0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08,
- 0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,
- 0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,
- 0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28,
- 0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,
- 0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,
- 0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,
- 0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,
- 0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,
- 0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89,
- 0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,
- 0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,
- 0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,
- 0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,
- 0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,
- 0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,
- 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,
- 0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
- 0xf9,0xfa
- ];
-
- private var std_dc_chrominance_nrcodes:Array = [0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0];
- private var std_dc_chrominance_values:Array = [0,1,2,3,4,5,6,7,8,9,10,11];
- private var std_ac_chrominance_nrcodes:Array = [0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77];
- private var std_ac_chrominance_values:Array = [
- 0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,
- 0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,
- 0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,
- 0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,
- 0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,
- 0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26,
- 0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,
- 0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,
- 0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,
- 0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,
- 0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,
- 0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87,
- 0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,
- 0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,
- 0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,
- 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,
- 0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,
- 0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,
- 0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,
- 0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
- 0xf9,0xfa
- ];
-
- private function initHuffmanTbl():void
- {
- YDC_HT = computeHuffmanTbl(std_dc_luminance_nrcodes,std_dc_luminance_values);
- UVDC_HT = computeHuffmanTbl(std_dc_chrominance_nrcodes,std_dc_chrominance_values);
- YAC_HT = computeHuffmanTbl(std_ac_luminance_nrcodes,std_ac_luminance_values);
- UVAC_HT = computeHuffmanTbl(std_ac_chrominance_nrcodes,std_ac_chrominance_values);
- }
-
- private var bitcode:Array = new Array(65535);
- private var category:Array = new Array(65535);
-
- private function initCategoryNumber():void
- {
- var nrlower:int = 1;
- var nrupper:int = 2;
- var nr:int;
- for (var cat:int=1; cat<=15; cat++) {
- //Positive numbers
- for (nr=nrlower; nr<nrupper; nr++) {
- category[32767+nr] = cat;
- bitcode[32767+nr] = new BitString();
- bitcode[32767+nr].len = cat;
- bitcode[32767+nr].val = nr;
- }
- //Negative numbers
- for (nr=-(nrupper-1); nr<=-nrlower; nr++) {
- category[32767+nr] = cat;
- bitcode[32767+nr] = new BitString();
- bitcode[32767+nr].len = cat;
- bitcode[32767+nr].val = nrupper-1+nr;
- }
- nrlower <<= 1;
- nrupper <<= 1;
- }
- }
-
- // IO functions
-
- private var byteout:ByteArray;
- private var bytenew:int = 0;
- private var bytepos:int = 7;
-
- private function writeBits(bs:BitString):void
- {
- var value:int = bs.val;
- var posval:int = bs.len-1;
- while ( posval >= 0 ) {
- if (value & uint(1 << posval) ) {
- bytenew |= uint(1 << bytepos);
- }
- posval--;
- bytepos--;
- if (bytepos < 0) {
- if (bytenew == 0xFF) {
- writeByte(0xFF);
- writeByte(0);
- }
- else {
- writeByte(bytenew);
- }
- bytepos=7;
- bytenew=0;
- }
- }
- }
-
- private function writeByte(value:int):void
- {
- byteout.writeByte(value);
- }
-
- private function writeWord(value:int):void
- {
- writeByte((value>>8)&0xFF);
- writeByte((value )&0xFF);
- }
-
- // DCT & quantization core
-
- private function fDCTQuant(data:Array, fdtbl:Array):Array
- {
- var tmp0:Number, tmp1:Number, tmp2:Number, tmp3:Number, tmp4:Number, tmp5:Number, tmp6:Number, tmp7:Number;
- var tmp10:Number, tmp11:Number, tmp12:Number, tmp13:Number;
- var z1:Number, z2:Number, z3:Number, z4:Number, z5:Number, z11:Number, z13:Number;
- var i:int;
- /* Pass 1: process rows. */
- var dataOff:int=0;
- for (i=0; i<8; i++) {
- tmp0 = data[dataOff+0] + data[dataOff+7];
- tmp7 = data[dataOff+0] - data[dataOff+7];
- tmp1 = data[dataOff+1] + data[dataOff+6];
- tmp6 = data[dataOff+1] - data[dataOff+6];
- tmp2 = data[dataOff+2] + data[dataOff+5];
- tmp5 = data[dataOff+2] - data[dataOff+5];
- tmp3 = data[dataOff+3] + data[dataOff+4];
- tmp4 = data[dataOff+3] - data[dataOff+4];
-
- /* Even part */
- tmp10 = tmp0 + tmp3; /* phase 2 */
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
-
- data[dataOff+0] = tmp10 + tmp11; /* phase 3 */
- data[dataOff+4] = tmp10 - tmp11;
-
- z1 = (tmp12 + tmp13) * 0.707106781; /* c4 */
- data[dataOff+2] = tmp13 + z1; /* phase 5 */
- data[dataOff+6] = tmp13 - z1;
-
- /* Odd part */
- tmp10 = tmp4 + tmp5; /* phase 2 */
- tmp11 = tmp5 + tmp6;
- tmp12 = tmp6 + tmp7;
-
- /* The rotator is modified from fig 4-8 to avoid extra negations. */
- z5 = (tmp10 - tmp12) * 0.382683433; /* c6 */
- z2 = 0.541196100 * tmp10 + z5; /* c2-c6 */
- z4 = 1.306562965 * tmp12 + z5; /* c2+c6 */
- z3 = tmp11 * 0.707106781; /* c4 */
-
- z11 = tmp7 + z3; /* phase 5 */
- z13 = tmp7 - z3;
-
- data[dataOff+5] = z13 + z2; /* phase 6 */
- data[dataOff+3] = z13 - z2;
- data[dataOff+1] = z11 + z4;
- data[dataOff+7] = z11 - z4;
-
- dataOff += 8; /* advance pointer to next row */
- }
-
- /* Pass 2: process columns. */
- dataOff = 0;
- for (i=0; i<8; i++) {
- tmp0 = data[dataOff+ 0] + data[dataOff+56];
- tmp7 = data[dataOff+ 0] - data[dataOff+56];
- tmp1 = data[dataOff+ 8] + data[dataOff+48];
- tmp6 = data[dataOff+ 8] - data[dataOff+48];
- tmp2 = data[dataOff+16] + data[dataOff+40];
- tmp5 = data[dataOff+16] - data[dataOff+40];
- tmp3 = data[dataOff+24] + data[dataOff+32];
- tmp4 = data[dataOff+24] - data[dataOff+32];
-
- /* Even part */
- tmp10 = tmp0 + tmp3; /* phase 2 */
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
-
- data[dataOff+ 0] = tmp10 + tmp11; /* phase 3 */
- data[dataOff+32] = tmp10 - tmp11;
-
- z1 = (tmp12 + tmp13) * 0.707106781; /* c4 */
- data[dataOff+16] = tmp13 + z1; /* phase 5 */
- data[dataOff+48] = tmp13 - z1;
-
- /* Odd part */
- tmp10 = tmp4 + tmp5; /* phase 2 */
- tmp11 = tmp5 + tmp6;
- tmp12 = tmp6 + tmp7;
-
- /* The rotator is modified from fig 4-8 to avoid extra negations. */
- z5 = (tmp10 - tmp12) * 0.382683433; /* c6 */
- z2 = 0.541196100 * tmp10 + z5; /* c2-c6 */
- z4 = 1.306562965 * tmp12 + z5; /* c2+c6 */
- z3 = tmp11 * 0.707106781; /* c4 */
-
- z11 = tmp7 + z3; /* phase 5 */
- z13 = tmp7 - z3;
-
- data[dataOff+40] = z13 + z2; /* phase 6 */
- data[dataOff+24] = z13 - z2;
- data[dataOff+ 8] = z11 + z4;
- data[dataOff+56] = z11 - z4;
-
- dataOff++; /* advance pointer to next column */
- }
-
- // Quantize/descale the coefficients
- for (i=0; i<64; i++) {
- // Apply the quantization and scaling factor & Round to nearest integer
- data[i] = Math.round((data[i]*fdtbl[i]));
- }
- return data;
- }
-
- // Chunk writing
-
- private function writeAPP0():void
- {
- writeWord(0xFFE0); // marker
- writeWord(16); // length
- writeByte(0x4A); // J
- writeByte(0x46); // F
- writeByte(0x49); // I
- writeByte(0x46); // F
- writeByte(0); // = "JFIF",'\0'
- writeByte(1); // versionhi
- writeByte(1); // versionlo
- writeByte(0); // xyunits
- writeWord(1); // xdensity
- writeWord(1); // ydensity
- writeByte(0); // thumbnwidth
- writeByte(0); // thumbnheight
- }
-
- private function writeSOF0(width:int, height:int):void
- {
- writeWord(0xFFC0); // marker
- writeWord(17); // length, truecolor YUV JPG
- writeByte(8); // precision
- writeWord(height);
- writeWord(width);
- writeByte(3); // nrofcomponents
- writeByte(1); // IdY
- writeByte(0x11); // HVY
- writeByte(0); // QTY
- writeByte(2); // IdU
- writeByte(0x11); // HVU
- writeByte(1); // QTU
- writeByte(3); // IdV
- writeByte(0x11); // HVV
- writeByte(1); // QTV
- }
-
- private function writeDQT():void
- {
- writeWord(0xFFDB); // marker
- writeWord(132); // length
- writeByte(0);
- var i:int;
- for (i=0; i<64; i++) {
- writeByte(YTable[i]);
- }
- writeByte(1);
- for (i=0; i<64; i++) {
- writeByte(UVTable[i]);
- }
- }
-
- private function writeDHT():void
- {
- writeWord(0xFFC4); // marker
- writeWord(0x01A2); // length
- var i:int;
-
- writeByte(0); // HTYDCinfo
- for (i=0; i<16; i++) {
- writeByte(std_dc_luminance_nrcodes[i+1]);
- }
- for (i=0; i<=11; i++) {
- writeByte(std_dc_luminance_values[i]);
- }
-
- writeByte(0x10); // HTYACinfo
- for (i=0; i<16; i++) {
- writeByte(std_ac_luminance_nrcodes[i+1]);
- }
- for (i=0; i<=161; i++) {
- writeByte(std_ac_luminance_values[i]);
- }
-
- writeByte(1); // HTUDCinfo
- for (i=0; i<16; i++) {
- writeByte(std_dc_chrominance_nrcodes[i+1]);
- }
- for (i=0; i<=11; i++) {
- writeByte(std_dc_chrominance_values[i]);
- }
-
- writeByte(0x11); // HTUACinfo
- for (i=0; i<16; i++) {
- writeByte(std_ac_chrominance_nrcodes[i+1]);
- }
- for (i=0; i<=161; i++) {
- writeByte(std_ac_chrominance_values[i]);
- }
- }
-
- private function writeSOS():void
- {
- writeWord(0xFFDA); // marker
- writeWord(12); // length
- writeByte(3); // nrofcomponents
- writeByte(1); // IdY
- writeByte(0); // HTY
- writeByte(2); // IdU
- writeByte(0x11); // HTU
- writeByte(3); // IdV
- writeByte(0x11); // HTV
- writeByte(0); // Ss
- writeByte(0x3f); // Se
- writeByte(0); // Bf
- }
-
- // Core processing
- private var DU:Array = new Array(64);
-
- private function processDU(CDU:Array, fdtbl:Array, DC:Number, HTDC:Array, HTAC:Array):Number
- {
- var EOB:BitString = HTAC[0x00];
- var M16zeroes:BitString = HTAC[0xF0];
- var i:int;
-
- var DU_DCT:Array = fDCTQuant(CDU, fdtbl);
- //ZigZag reorder
- for (i=0;i<64;i++) {
- DU[ZigZag[i]]=DU_DCT[i];
- }
- var Diff:int = DU[0] - DC; DC = DU[0];
- //Encode DC
- if (Diff==0) {
- writeBits(HTDC[0]); // Diff might be 0
- } else {
- writeBits(HTDC[category[32767+Diff]]);
- writeBits(bitcode[32767+Diff]);
- }
- //Encode ACs
- var end0pos:int = 63;
- for (; (end0pos>0)&&(DU[end0pos]==0); end0pos--) {
- };
- //end0pos = first element in reverse order !=0
- if ( end0pos == 0) {
- writeBits(EOB);
- return DC;
- }
- i = 1;
- while ( i <= end0pos ) {
- var startpos:int = i;
- for (; (DU[i]==0) && (i<=end0pos); i++) {
- }
- var nrzeroes:int = i-startpos;
- if ( nrzeroes >= 16 ) {
- for (var nrmarker:int=1; nrmarker <= nrzeroes/16; nrmarker++) {
- writeBits(M16zeroes);
- }
- nrzeroes = int(nrzeroes&0xF);
- }
- writeBits(HTAC[nrzeroes*16+category[32767+DU[i]]]);
- writeBits(bitcode[32767+DU[i]]);
- i++;
- }
- if ( end0pos != 63 ) {
- writeBits(EOB);
- }
- return DC;
- }
-
- private var YDU:Array = new Array(64);
- private var UDU:Array = new Array(64);
- private var VDU:Array = new Array(64);
-
- private function RGB2YUV(img:BitmapData, xpos:int, ypos:int):void
- {
- var pos:int=0;
- for (var y:int=0; y<8; y++) {
- for (var x:int=0; x<8; x++) {
- var P:uint = img.getPixel32(xpos+x,ypos+y);
- var R:Number = Number((P>>16)&0xFF);
- var G:Number = Number((P>> 8)&0xFF);
- var B:Number = Number((P )&0xFF);
- YDU[pos]=((( 0.29900)*R+( 0.58700)*G+( 0.11400)*B))-128;
- UDU[pos]=(((-0.16874)*R+(-0.33126)*G+( 0.50000)*B));
- VDU[pos]=((( 0.50000)*R+(-0.41869)*G+(-0.08131)*B));
- pos++;
- }
- }
- }
-
- /**
- * Constructor for JPEGEncoder class
- *
- * @param quality The quality level between 1 and 100 that detrmines the
- * level of compression used in the generated JPEG
- * @langversion ActionScript 3.0
- * @playerversion Flash 9.0
- * @tiptext
- */
- public function JPGEncoder(quality:Number = 50)
- {
- if (quality <= 0) {
- quality = 1;
- }
- if (quality > 100) {
- quality = 100;
- }
- var sf:int = 0;
- if (quality < 50) {
- sf = int(5000 / quality);
- } else {
- sf = int(200 - quality*2);
- }
- // Create tables
- initHuffmanTbl();
- initCategoryNumber();
- initQuantTables(sf);
- }
-
- /**
- * Created a JPEG image from the specified BitmapData
- *
- * @param image The BitmapData that will be converted into the JPEG format.
- * @return a ByteArray representing the JPEG encoded image data.
- * @langversion ActionScript 3.0
- * @playerversion Flash 9.0
- * @tiptext
- */
- public function encode(image:BitmapData):ByteArray
- {
- // Initialize bit writer
- byteout = new ByteArray();
- bytenew=0;
- bytepos=7;
-
- // Add JPEG headers
- writeWord(0xFFD8); // SOI
- writeAPP0();
- writeDQT();
- writeSOF0(image.width,image.height);
- writeDHT();
- writeSOS();
-
-
- // Encode 8x8 macroblocks
- var DCY:Number=0;
- var DCU:Number=0;
- var DCV:Number=0;
- bytenew=0;
- bytepos=7;
- for (var ypos:int=0; ypos<image.height; ypos+=8) {
- for (var xpos:int=0; xpos<image.width; xpos+=8) {
- RGB2YUV(image, xpos, ypos);
- DCY = processDU(YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT);
- DCU = processDU(UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT);
- DCV = processDU(VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT);
- }
- }
-
- // Do the bit alignment of the EOI marker
- if ( bytepos >= 0 ) {
- var fillbits:BitString = new BitString();
- fillbits.len = bytepos+1;
- fillbits.val = (1<<(bytepos+1))-1;
- writeBits(fillbits);
- }
-
- writeWord(0xFFD9); //EOI
- return byteout;
- }
- }
-}
+/* + Adobe Systems Incorporated(r) Source Code License Agreement + Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + + Please read this Source Code License Agreement carefully before using + the source code. + + Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, + no-charge, royalty-free, irrevocable copyright license, to reproduce, + prepare derivative works of, publicly display, publicly perform, and + distribute this source code and such derivative works in source or + object code form without any attribution requirements. + + The name "Adobe Systems Incorporated" must not be used to endorse or promote products + derived from the source code without prior written permission. + + You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and + against any loss, damage, claims or lawsuits, including attorney's + fees that arise or result from your use or distribution of the source + code. + + THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT + ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF + NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA + OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +package com.adobe.images +{ + import flash.geom.*; + import flash.display.*; + import flash.utils.*; + + /** + * Class that converts BitmapData into a valid JPEG + */ + public class JPGEncoder + { + + // Static table initialization + + private var ZigZag:Array = [ + 0, 1, 5, 6,14,15,27,28, + 2, 4, 7,13,16,26,29,42, + 3, 8,12,17,25,30,41,43, + 9,11,18,24,31,40,44,53, + 10,19,23,32,39,45,52,54, + 20,22,33,38,46,51,55,60, + 21,34,37,47,50,56,59,61, + 35,36,48,49,57,58,62,63 + ]; + + private var YTable:Array = new Array(64); + private var UVTable:Array = new Array(64); + private var fdtbl_Y:Array = new Array(64); + private var fdtbl_UV:Array = new Array(64); + + private function initQuantTables(sf:int):void + { + var i:int; + var t:Number; + var YQT:Array = [ + 16, 11, 10, 16, 24, 40, 51, 61, + 12, 12, 14, 19, 26, 58, 60, 55, + 14, 13, 16, 24, 40, 57, 69, 56, + 14, 17, 22, 29, 51, 87, 80, 62, + 18, 22, 37, 56, 68,109,103, 77, + 24, 35, 55, 64, 81,104,113, 92, + 49, 64, 78, 87,103,121,120,101, + 72, 92, 95, 98,112,100,103, 99 + ]; + for (i = 0; i < 64; i++) { + t = Math.floor((YQT[i]*sf+50)/100); + if (t < 1) { + t = 1; + } else if (t > 255) { + t = 255; + } + YTable[ZigZag[i]] = t; + } + var UVQT:Array = [ + 17, 18, 24, 47, 99, 99, 99, 99, + 18, 21, 26, 66, 99, 99, 99, 99, + 24, 26, 56, 99, 99, 99, 99, 99, + 47, 66, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99 + ]; + for (i = 0; i < 64; i++) { + t = Math.floor((UVQT[i]*sf+50)/100); + if (t < 1) { + t = 1; + } else if (t > 255) { + t = 255; + } + UVTable[ZigZag[i]] = t; + } + var aasf:Array = [ + 1.0, 1.387039845, 1.306562965, 1.175875602, + 1.0, 0.785694958, 0.541196100, 0.275899379 + ]; + i = 0; + for (var row:int = 0; row < 8; row++) + { + for (var col:int = 0; col < 8; col++) + { + fdtbl_Y[i] = (1.0 / (YTable [ZigZag[i]] * aasf[row] * aasf[col] * 8.0)); + fdtbl_UV[i] = (1.0 / (UVTable[ZigZag[i]] * aasf[row] * aasf[col] * 8.0)); + i++; + } + } + } + + private var YDC_HT:Array; + private var UVDC_HT:Array; + private var YAC_HT:Array; + private var UVAC_HT:Array; + + private function computeHuffmanTbl(nrcodes:Array, std_table:Array):Array + { + var codevalue:int = 0; + var pos_in_table:int = 0; + var HT:Array = new Array(); + for (var k:int=1; k<=16; k++) { + for (var j:int=1; j<=nrcodes[k]; j++) { + HT[std_table[pos_in_table]] = new BitString(); + HT[std_table[pos_in_table]].val = codevalue; + HT[std_table[pos_in_table]].len = k; + pos_in_table++; + codevalue++; + } + codevalue*=2; + } + return HT; + } + + private var std_dc_luminance_nrcodes:Array = [0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0]; + private var std_dc_luminance_values:Array = [0,1,2,3,4,5,6,7,8,9,10,11]; + private var std_ac_luminance_nrcodes:Array = [0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d]; + private var std_ac_luminance_values:Array = [ + 0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12, + 0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07, + 0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08, + 0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0, + 0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16, + 0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28, + 0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39, + 0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49, + 0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59, + 0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69, + 0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79, + 0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89, + 0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98, + 0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7, + 0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6, + 0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5, + 0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4, + 0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2, + 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea, + 0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8, + 0xf9,0xfa + ]; + + private var std_dc_chrominance_nrcodes:Array = [0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0]; + private var std_dc_chrominance_values:Array = [0,1,2,3,4,5,6,7,8,9,10,11]; + private var std_ac_chrominance_nrcodes:Array = [0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77]; + private var std_ac_chrominance_values:Array = [ + 0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21, + 0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71, + 0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91, + 0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0, + 0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34, + 0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26, + 0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38, + 0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48, + 0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58, + 0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68, + 0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78, + 0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87, + 0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96, + 0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5, + 0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4, + 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3, + 0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2, + 0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda, + 0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9, + 0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8, + 0xf9,0xfa + ]; + + private function initHuffmanTbl():void + { + YDC_HT = computeHuffmanTbl(std_dc_luminance_nrcodes,std_dc_luminance_values); + UVDC_HT = computeHuffmanTbl(std_dc_chrominance_nrcodes,std_dc_chrominance_values); + YAC_HT = computeHuffmanTbl(std_ac_luminance_nrcodes,std_ac_luminance_values); + UVAC_HT = computeHuffmanTbl(std_ac_chrominance_nrcodes,std_ac_chrominance_values); + } + + private var bitcode:Array = new Array(65535); + private var category:Array = new Array(65535); + + private function initCategoryNumber():void + { + var nrlower:int = 1; + var nrupper:int = 2; + var nr:int; + for (var cat:int=1; cat<=15; cat++) { + //Positive numbers + for (nr=nrlower; nr<nrupper; nr++) { + category[32767+nr] = cat; + bitcode[32767+nr] = new BitString(); + bitcode[32767+nr].len = cat; + bitcode[32767+nr].val = nr; + } + //Negative numbers + for (nr=-(nrupper-1); nr<=-nrlower; nr++) { + category[32767+nr] = cat; + bitcode[32767+nr] = new BitString(); + bitcode[32767+nr].len = cat; + bitcode[32767+nr].val = nrupper-1+nr; + } + nrlower <<= 1; + nrupper <<= 1; + } + } + + // IO functions + + private var byteout:ByteArray; + private var bytenew:int = 0; + private var bytepos:int = 7; + + private function writeBits(bs:BitString):void + { + var value:int = bs.val; + var posval:int = bs.len-1; + while ( posval >= 0 ) { + if (value & uint(1 << posval) ) { + bytenew |= uint(1 << bytepos); + } + posval--; + bytepos--; + if (bytepos < 0) { + if (bytenew == 0xFF) { + writeByte(0xFF); + writeByte(0); + } + else { + writeByte(bytenew); + } + bytepos=7; + bytenew=0; + } + } + } + + private function writeByte(value:int):void + { + byteout.writeByte(value); + } + + private function writeWord(value:int):void + { + writeByte((value>>8)&0xFF); + writeByte((value )&0xFF); + } + + // DCT & quantization core + + private function fDCTQuant(data:Array, fdtbl:Array):Array + { + var tmp0:Number, tmp1:Number, tmp2:Number, tmp3:Number, tmp4:Number, tmp5:Number, tmp6:Number, tmp7:Number; + var tmp10:Number, tmp11:Number, tmp12:Number, tmp13:Number; + var z1:Number, z2:Number, z3:Number, z4:Number, z5:Number, z11:Number, z13:Number; + var i:int; + /* Pass 1: process rows. */ + var dataOff:int=0; + for (i=0; i<8; i++) { + tmp0 = data[dataOff+0] + data[dataOff+7]; + tmp7 = data[dataOff+0] - data[dataOff+7]; + tmp1 = data[dataOff+1] + data[dataOff+6]; + tmp6 = data[dataOff+1] - data[dataOff+6]; + tmp2 = data[dataOff+2] + data[dataOff+5]; + tmp5 = data[dataOff+2] - data[dataOff+5]; + tmp3 = data[dataOff+3] + data[dataOff+4]; + tmp4 = data[dataOff+3] - data[dataOff+4]; + + /* Even part */ + tmp10 = tmp0 + tmp3; /* phase 2 */ + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + data[dataOff+0] = tmp10 + tmp11; /* phase 3 */ + data[dataOff+4] = tmp10 - tmp11; + + z1 = (tmp12 + tmp13) * 0.707106781; /* c4 */ + data[dataOff+2] = tmp13 + z1; /* phase 5 */ + data[dataOff+6] = tmp13 - z1; + + /* Odd part */ + tmp10 = tmp4 + tmp5; /* phase 2 */ + tmp11 = tmp5 + tmp6; + tmp12 = tmp6 + tmp7; + + /* The rotator is modified from fig 4-8 to avoid extra negations. */ + z5 = (tmp10 - tmp12) * 0.382683433; /* c6 */ + z2 = 0.541196100 * tmp10 + z5; /* c2-c6 */ + z4 = 1.306562965 * tmp12 + z5; /* c2+c6 */ + z3 = tmp11 * 0.707106781; /* c4 */ + + z11 = tmp7 + z3; /* phase 5 */ + z13 = tmp7 - z3; + + data[dataOff+5] = z13 + z2; /* phase 6 */ + data[dataOff+3] = z13 - z2; + data[dataOff+1] = z11 + z4; + data[dataOff+7] = z11 - z4; + + dataOff += 8; /* advance pointer to next row */ + } + + /* Pass 2: process columns. */ + dataOff = 0; + for (i=0; i<8; i++) { + tmp0 = data[dataOff+ 0] + data[dataOff+56]; + tmp7 = data[dataOff+ 0] - data[dataOff+56]; + tmp1 = data[dataOff+ 8] + data[dataOff+48]; + tmp6 = data[dataOff+ 8] - data[dataOff+48]; + tmp2 = data[dataOff+16] + data[dataOff+40]; + tmp5 = data[dataOff+16] - data[dataOff+40]; + tmp3 = data[dataOff+24] + data[dataOff+32]; + tmp4 = data[dataOff+24] - data[dataOff+32]; + + /* Even part */ + tmp10 = tmp0 + tmp3; /* phase 2 */ + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + data[dataOff+ 0] = tmp10 + tmp11; /* phase 3 */ + data[dataOff+32] = tmp10 - tmp11; + + z1 = (tmp12 + tmp13) * 0.707106781; /* c4 */ + data[dataOff+16] = tmp13 + z1; /* phase 5 */ + data[dataOff+48] = tmp13 - z1; + + /* Odd part */ + tmp10 = tmp4 + tmp5; /* phase 2 */ + tmp11 = tmp5 + tmp6; + tmp12 = tmp6 + tmp7; + + /* The rotator is modified from fig 4-8 to avoid extra negations. */ + z5 = (tmp10 - tmp12) * 0.382683433; /* c6 */ + z2 = 0.541196100 * tmp10 + z5; /* c2-c6 */ + z4 = 1.306562965 * tmp12 + z5; /* c2+c6 */ + z3 = tmp11 * 0.707106781; /* c4 */ + + z11 = tmp7 + z3; /* phase 5 */ + z13 = tmp7 - z3; + + data[dataOff+40] = z13 + z2; /* phase 6 */ + data[dataOff+24] = z13 - z2; + data[dataOff+ 8] = z11 + z4; + data[dataOff+56] = z11 - z4; + + dataOff++; /* advance pointer to next column */ + } + + // Quantize/descale the coefficients + for (i=0; i<64; i++) { + // Apply the quantization and scaling factor & Round to nearest integer + data[i] = Math.round((data[i]*fdtbl[i])); + } + return data; + } + + // Chunk writing + + private function writeAPP0():void + { + writeWord(0xFFE0); // marker + writeWord(16); // length + writeByte(0x4A); // J + writeByte(0x46); // F + writeByte(0x49); // I + writeByte(0x46); // F + writeByte(0); // = "JFIF",'\0' + writeByte(1); // versionhi + writeByte(1); // versionlo + writeByte(0); // xyunits + writeWord(1); // xdensity + writeWord(1); // ydensity + writeByte(0); // thumbnwidth + writeByte(0); // thumbnheight + } + + private function writeSOF0(width:int, height:int):void + { + writeWord(0xFFC0); // marker + writeWord(17); // length, truecolor YUV JPG + writeByte(8); // precision + writeWord(height); + writeWord(width); + writeByte(3); // nrofcomponents + writeByte(1); // IdY + writeByte(0x11); // HVY + writeByte(0); // QTY + writeByte(2); // IdU + writeByte(0x11); // HVU + writeByte(1); // QTU + writeByte(3); // IdV + writeByte(0x11); // HVV + writeByte(1); // QTV + } + + private function writeDQT():void + { + writeWord(0xFFDB); // marker + writeWord(132); // length + writeByte(0); + var i:int; + for (i=0; i<64; i++) { + writeByte(YTable[i]); + } + writeByte(1); + for (i=0; i<64; i++) { + writeByte(UVTable[i]); + } + } + + private function writeDHT():void + { + writeWord(0xFFC4); // marker + writeWord(0x01A2); // length + var i:int; + + writeByte(0); // HTYDCinfo + for (i=0; i<16; i++) { + writeByte(std_dc_luminance_nrcodes[i+1]); + } + for (i=0; i<=11; i++) { + writeByte(std_dc_luminance_values[i]); + } + + writeByte(0x10); // HTYACinfo + for (i=0; i<16; i++) { + writeByte(std_ac_luminance_nrcodes[i+1]); + } + for (i=0; i<=161; i++) { + writeByte(std_ac_luminance_values[i]); + } + + writeByte(1); // HTUDCinfo + for (i=0; i<16; i++) { + writeByte(std_dc_chrominance_nrcodes[i+1]); + } + for (i=0; i<=11; i++) { + writeByte(std_dc_chrominance_values[i]); + } + + writeByte(0x11); // HTUACinfo + for (i=0; i<16; i++) { + writeByte(std_ac_chrominance_nrcodes[i+1]); + } + for (i=0; i<=161; i++) { + writeByte(std_ac_chrominance_values[i]); + } + } + + private function writeSOS():void + { + writeWord(0xFFDA); // marker + writeWord(12); // length + writeByte(3); // nrofcomponents + writeByte(1); // IdY + writeByte(0); // HTY + writeByte(2); // IdU + writeByte(0x11); // HTU + writeByte(3); // IdV + writeByte(0x11); // HTV + writeByte(0); // Ss + writeByte(0x3f); // Se + writeByte(0); // Bf + } + + // Core processing + private var DU:Array = new Array(64); + + private function processDU(CDU:Array, fdtbl:Array, DC:Number, HTDC:Array, HTAC:Array):Number + { + var EOB:BitString = HTAC[0x00]; + var M16zeroes:BitString = HTAC[0xF0]; + var i:int; + + var DU_DCT:Array = fDCTQuant(CDU, fdtbl); + //ZigZag reorder + for (i=0;i<64;i++) { + DU[ZigZag[i]]=DU_DCT[i]; + } + var Diff:int = DU[0] - DC; DC = DU[0]; + //Encode DC + if (Diff==0) { + writeBits(HTDC[0]); // Diff might be 0 + } else { + writeBits(HTDC[category[32767+Diff]]); + writeBits(bitcode[32767+Diff]); + } + //Encode ACs + var end0pos:int = 63; + for (; (end0pos>0)&&(DU[end0pos]==0); end0pos--) { + }; + //end0pos = first element in reverse order !=0 + if ( end0pos == 0) { + writeBits(EOB); + return DC; + } + i = 1; + while ( i <= end0pos ) { + var startpos:int = i; + for (; (DU[i]==0) && (i<=end0pos); i++) { + } + var nrzeroes:int = i-startpos; + if ( nrzeroes >= 16 ) { + for (var nrmarker:int=1; nrmarker <= nrzeroes/16; nrmarker++) { + writeBits(M16zeroes); + } + nrzeroes = int(nrzeroes&0xF); + } + writeBits(HTAC[nrzeroes*16+category[32767+DU[i]]]); + writeBits(bitcode[32767+DU[i]]); + i++; + } + if ( end0pos != 63 ) { + writeBits(EOB); + } + return DC; + } + + private var YDU:Array = new Array(64); + private var UDU:Array = new Array(64); + private var VDU:Array = new Array(64); + + private function RGB2YUV(img:BitmapData, xpos:int, ypos:int):void + { + var pos:int=0; + for (var y:int=0; y<8; y++) { + for (var x:int=0; x<8; x++) { + var P:uint = img.getPixel32(xpos+x,ypos+y); + var R:Number = Number((P>>16)&0xFF); + var G:Number = Number((P>> 8)&0xFF); + var B:Number = Number((P )&0xFF); + YDU[pos]=((( 0.29900)*R+( 0.58700)*G+( 0.11400)*B))-128; + UDU[pos]=(((-0.16874)*R+(-0.33126)*G+( 0.50000)*B)); + VDU[pos]=((( 0.50000)*R+(-0.41869)*G+(-0.08131)*B)); + pos++; + } + } + } + + /** + * Constructor for JPEGEncoder class + * + * @param quality The quality level between 1 and 100 that detrmines the + * level of compression used in the generated JPEG + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0 + * @tiptext + */ + public function JPGEncoder(quality:Number = 50) + { + if (quality <= 0) { + quality = 1; + } + if (quality > 100) { + quality = 100; + } + var sf:int = 0; + if (quality < 50) { + sf = int(5000 / quality); + } else { + sf = int(200 - quality*2); + } + // Create tables + initHuffmanTbl(); + initCategoryNumber(); + initQuantTables(sf); + } + + /** + * Created a JPEG image from the specified BitmapData + * + * @param image The BitmapData that will be converted into the JPEG format. + * @return a ByteArray representing the JPEG encoded image data. + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0 + * @tiptext + */ + public function encode(image:BitmapData):ByteArray + { + // Initialize bit writer + byteout = new ByteArray(); + bytenew=0; + bytepos=7; + + // Add JPEG headers + writeWord(0xFFD8); // SOI + writeAPP0(); + writeDQT(); + writeSOF0(image.width,image.height); + writeDHT(); + writeSOS(); + + + // Encode 8x8 macroblocks + var DCY:Number=0; + var DCU:Number=0; + var DCV:Number=0; + bytenew=0; + bytepos=7; + for (var ypos:int=0; ypos<image.height; ypos+=8) { + for (var xpos:int=0; xpos<image.width; xpos+=8) { + RGB2YUV(image, xpos, ypos); + DCY = processDU(YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT); + DCU = processDU(UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT); + DCV = processDU(VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT); + } + } + + // Do the bit alignment of the EOI marker + if ( bytepos >= 0 ) { + var fillbits:BitString = new BitString(); + fillbits.len = bytepos+1; + fillbits.val = (1<<(bytepos+1))-1; + writeBits(fillbits); + } + + writeWord(0xFFD9); //EOI + return byteout; + } + } +} diff --git a/webcam/com/adobe/images/PNGEncoder.as b/webcam/com/adobe/images/PNGEncoder.as index f40e575..bb86444 100644 --- a/webcam/com/adobe/images/PNGEncoder.as +++ b/webcam/com/adobe/images/PNGEncoder.as @@ -1,144 +1,144 @@ -/*
- Adobe Systems Incorporated(r) Source Code License Agreement
- Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
- Please read this Source Code License Agreement carefully before using
- the source code.
-
- Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
- no-charge, royalty-free, irrevocable copyright license, to reproduce,
- prepare derivative works of, publicly display, publicly perform, and
- distribute this source code and such derivative works in source or
- object code form without any attribution requirements.
-
- The name "Adobe Systems Incorporated" must not be used to endorse or promote products
- derived from the source code without prior written permission.
-
- You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
- against any loss, damage, claims or lawsuits, including attorney's
- fees that arise or result from your use or distribution of the source
- code.
-
- THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
- ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
- NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
- OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-package com.adobe.images
-{
- import flash.geom.*;
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.utils.ByteArray;
-
- /**
- * Class that converts BitmapData into a valid PNG
- */
- public class PNGEncoder
- {
- /**
- * Created a PNG image from the specified BitmapData
- *
- * @param image The BitmapData that will be converted into the PNG format.
- * @return a ByteArray representing the PNG encoded image data.
- * @langversion ActionScript 3.0
- * @playerversion Flash 9.0
- * @tiptext
- */
- public static function encode(img:BitmapData):ByteArray {
- // Create output byte array
- var png:ByteArray = new ByteArray();
- // Write PNG signature
- png.writeUnsignedInt(0x89504e47);
- png.writeUnsignedInt(0x0D0A1A0A);
- // Build IHDR chunk
- var IHDR:ByteArray = new ByteArray();
- IHDR.writeInt(img.width);
- IHDR.writeInt(img.height);
- IHDR.writeUnsignedInt(0x08060000); // 32bit RGBA
- IHDR.writeByte(0);
- writeChunk(png,0x49484452,IHDR);
- // Build IDAT chunk
- var IDAT:ByteArray= new ByteArray();
- for(var i:int=0;i < img.height;i++) {
- // no filter
- IDAT.writeByte(0);
- var p:uint;
- var j:int;
- if ( !img.transparent ) {
- for(j=0;j < img.width;j++) {
- p = img.getPixel(j,i);
- IDAT.writeUnsignedInt(
- uint(((p&0xFFFFFF) << 8)|0xFF));
- }
- } else {
- for(j=0;j < img.width;j++) {
- p = img.getPixel32(j,i);
- IDAT.writeUnsignedInt(
- uint(((p&0xFFFFFF) << 8)|
- (p>>>24)));
- }
- }
- }
- IDAT.compress();
- writeChunk(png,0x49444154,IDAT);
- // Build IEND chunk
- writeChunk(png,0x49454E44,null);
- // return PNG
- return png;
- }
-
- private static var crcTable:Array;
- private static var crcTableComputed:Boolean = false;
-
- private static function writeChunk(png:ByteArray,
- type:uint, data:ByteArray):void {
- if (!crcTableComputed) {
- crcTableComputed = true;
- crcTable = [];
- var c:uint;
- for (var n:uint = 0; n < 256; n++) {
- c = n;
- for (var k:uint = 0; k < 8; k++) {
- if (c & 1) {
- c = uint(uint(0xedb88320) ^
- uint(c >>> 1));
- } else {
- c = uint(c >>> 1);
- }
- }
- crcTable[n] = c;
- }
- }
- var len:uint = 0;
- if (data != null) {
- len = data.length;
- }
- png.writeUnsignedInt(len);
- var p:uint = png.position;
- png.writeUnsignedInt(type);
- if ( data != null ) {
- png.writeBytes(data);
- }
- var e:uint = png.position;
- png.position = p;
- c = 0xffffffff;
- for (var i:int = 0; i < (e-p); i++) {
- c = uint(crcTable[
- (c ^ png.readUnsignedByte()) &
- uint(0xff)] ^ uint(c >>> 8));
- }
- c = uint(c^uint(0xffffffff));
- png.position = e;
- png.writeUnsignedInt(c);
- }
- }
+/* + Adobe Systems Incorporated(r) Source Code License Agreement + Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + + Please read this Source Code License Agreement carefully before using + the source code. + + Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, + no-charge, royalty-free, irrevocable copyright license, to reproduce, + prepare derivative works of, publicly display, publicly perform, and + distribute this source code and such derivative works in source or + object code form without any attribution requirements. + + The name "Adobe Systems Incorporated" must not be used to endorse or promote products + derived from the source code without prior written permission. + + You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and + against any loss, damage, claims or lawsuits, including attorney's + fees that arise or result from your use or distribution of the source + code. + + THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT + ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF + NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA + OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +package com.adobe.images +{ + import flash.geom.*; + import flash.display.Bitmap; + import flash.display.BitmapData; + import flash.utils.ByteArray; + + /** + * Class that converts BitmapData into a valid PNG + */ + public class PNGEncoder + { + /** + * Created a PNG image from the specified BitmapData + * + * @param image The BitmapData that will be converted into the PNG format. + * @return a ByteArray representing the PNG encoded image data. + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0 + * @tiptext + */ + public static function encode(img:BitmapData):ByteArray { + // Create output byte array + var png:ByteArray = new ByteArray(); + // Write PNG signature + png.writeUnsignedInt(0x89504e47); + png.writeUnsignedInt(0x0D0A1A0A); + // Build IHDR chunk + var IHDR:ByteArray = new ByteArray(); + IHDR.writeInt(img.width); + IHDR.writeInt(img.height); + IHDR.writeUnsignedInt(0x08060000); // 32bit RGBA + IHDR.writeByte(0); + writeChunk(png,0x49484452,IHDR); + // Build IDAT chunk + var IDAT:ByteArray= new ByteArray(); + for(var i:int=0;i < img.height;i++) { + // no filter + IDAT.writeByte(0); + var p:uint; + var j:int; + if ( !img.transparent ) { + for(j=0;j < img.width;j++) { + p = img.getPixel(j,i); + IDAT.writeUnsignedInt( + uint(((p&0xFFFFFF) << 8)|0xFF)); + } + } else { + for(j=0;j < img.width;j++) { + p = img.getPixel32(j,i); + IDAT.writeUnsignedInt( + uint(((p&0xFFFFFF) << 8)| + (p>>>24))); + } + } + } + IDAT.compress(); + writeChunk(png,0x49444154,IDAT); + // Build IEND chunk + writeChunk(png,0x49454E44,null); + // return PNG + return png; + } + + private static var crcTable:Array; + private static var crcTableComputed:Boolean = false; + + private static function writeChunk(png:ByteArray, + type:uint, data:ByteArray):void { + if (!crcTableComputed) { + crcTableComputed = true; + crcTable = []; + var c:uint; + for (var n:uint = 0; n < 256; n++) { + c = n; + for (var k:uint = 0; k < 8; k++) { + if (c & 1) { + c = uint(uint(0xedb88320) ^ + uint(c >>> 1)); + } else { + c = uint(c >>> 1); + } + } + crcTable[n] = c; + } + } + var len:uint = 0; + if (data != null) { + len = data.length; + } + png.writeUnsignedInt(len); + var p:uint = png.position; + png.writeUnsignedInt(type); + if ( data != null ) { + png.writeBytes(data); + } + var e:uint = png.position; + png.position = p; + c = 0xffffffff; + for (var i:int = 0; i < (e-p); i++) { + c = uint(crcTable[ + (c ^ png.readUnsignedByte()) & + uint(0xff)] ^ uint(c >>> 8)); + } + c = uint(c^uint(0xffffffff)); + png.position = e; + png.writeUnsignedInt(c); + } + } }
\ No newline at end of file diff --git a/webcam/com/adobe/net/DynamicURLLoader.as b/webcam/com/adobe/net/DynamicURLLoader.as index ae69f22..9b16a61 100644 --- a/webcam/com/adobe/net/DynamicURLLoader.as +++ b/webcam/com/adobe/net/DynamicURLLoader.as @@ -1,58 +1,58 @@ -/*
- Adobe Systems Incorporated(r) Source Code License Agreement
- Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
- Please read this Source Code License Agreement carefully before using
- the source code.
-
- Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
- no-charge, royalty-free, irrevocable copyright license, to reproduce,
- prepare derivative works of, publicly display, publicly perform, and
- distribute this source code and such derivative works in source or
- object code form without any attribution requirements.
-
- The name "Adobe Systems Incorporated" must not be used to endorse or promote products
- derived from the source code without prior written permission.
-
- You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
- against any loss, damage, claims or lawsuits, including attorney's
- fees that arise or result from your use or distribution of the source
- code.
-
- THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
- ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
- NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
- OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package com.adobe.net
-{
- import flash.net.URLLoader;
-
- /**
- * Class that provides a dynamic implimentation of the URLLoader class.
- *
- * This class provides no API implimentations. However, since the class is
- * declared as dynamic, it can be used in place of URLLoader, and allow
- * you to dynamically attach properties to it (which URLLoader does not allow).
- *
- * @langversion ActionScript 3.0
- * @playerversion Flash 9.0
- * @tiptext
- */
- public dynamic class DynamicURLLoader extends URLLoader
- {
- public function DynamicURLLoader()
- {
- super();
- }
- }
+/* + Adobe Systems Incorporated(r) Source Code License Agreement + Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + + Please read this Source Code License Agreement carefully before using + the source code. + + Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, + no-charge, royalty-free, irrevocable copyright license, to reproduce, + prepare derivative works of, publicly display, publicly perform, and + distribute this source code and such derivative works in source or + object code form without any attribution requirements. + + The name "Adobe Systems Incorporated" must not be used to endorse or promote products + derived from the source code without prior written permission. + + You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and + against any loss, damage, claims or lawsuits, including attorney's + fees that arise or result from your use or distribution of the source + code. + + THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT + ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF + NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA + OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.net +{ + import flash.net.URLLoader; + + /** + * Class that provides a dynamic implimentation of the URLLoader class. + * + * This class provides no API implimentations. However, since the class is + * declared as dynamic, it can be used in place of URLLoader, and allow + * you to dynamically attach properties to it (which URLLoader does not allow). + * + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0 + * @tiptext + */ + public dynamic class DynamicURLLoader extends URLLoader + { + public function DynamicURLLoader() + { + super(); + } + } }
\ No newline at end of file diff --git a/webcam/com/adobe/net/IURIResolver.as b/webcam/com/adobe/net/IURIResolver.as index ed8acd8..658a95a 100644 --- a/webcam/com/adobe/net/IURIResolver.as +++ b/webcam/com/adobe/net/IURIResolver.as @@ -1,79 +1,79 @@ -/*
- Adobe Systems Incorporated(r) Source Code License Agreement
- Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
- Please read this Source Code License Agreement carefully before using
- the source code.
-
- Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
- no-charge, royalty-free, irrevocable copyright license, to reproduce,
- prepare derivative works of, publicly display, publicly perform, and
- distribute this source code and such derivative works in source or
- object code form without any attribution requirements.
-
- The name "Adobe Systems Incorporated" must not be used to endorse or promote products
- derived from the source code without prior written permission.
-
- You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
- against any loss, damage, claims or lawsuits, including attorney's
- fees that arise or result from your use or distribution of the source
- code.
-
- THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
- ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
- NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
- OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package com.adobe.net
-{
- /**
- * The URI class cannot know about DNS aliases, virtual hosts, or
- * symbolic links that may be involved. The application can provide
- * an implementation of this interface to resolve the URI before the
- * URI class makes any comparisons. For example, a web host has
- * two aliases:
- *
- * <p><code>
- * http://www.site.com/
- * http://www.site.net/
- * </code></p>
- *
- * <p>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.</p>
- *
- * <p>Use the URI.resolver accessor to assign a custom resolver to
- * the URI class. Any resolver specified is global to all instances
- * of URI.</p>
- *
- * <p>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;
- }
+/* + Adobe Systems Incorporated(r) Source Code License Agreement + Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + + Please read this Source Code License Agreement carefully before using + the source code. + + Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, + no-charge, royalty-free, irrevocable copyright license, to reproduce, + prepare derivative works of, publicly display, publicly perform, and + distribute this source code and such derivative works in source or + object code form without any attribution requirements. + + The name "Adobe Systems Incorporated" must not be used to endorse or promote products + derived from the source code without prior written permission. + + You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and + against any loss, damage, claims or lawsuits, including attorney's + fees that arise or result from your use or distribution of the source + code. + + THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT + ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF + NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA + OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.net +{ + /** + * The URI class cannot know about DNS aliases, virtual hosts, or + * symbolic links that may be involved. The application can provide + * an implementation of this interface to resolve the URI before the + * URI class makes any comparisons. For example, a web host has + * two aliases: + * + * <p><code> + * http://www.site.com/ + * http://www.site.net/ + * </code></p> + * + * <p>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.</p> + * + * <p>Use the URI.resolver accessor to assign a custom resolver to + * the URI class. Any resolver specified is global to all instances + * of URI.</p> + * + * <p>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 --git a/webcam/com/adobe/net/URI.as b/webcam/com/adobe/net/URI.as index 8ec9acd..40e1cbc 100644 --- a/webcam/com/adobe/net/URI.as +++ b/webcam/com/adobe/net/URI.as @@ -1,2469 +1,2469 @@ -/*
-Adobe Systems Incorporated(r) Source Code License Agreement
-Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
-Please read this Source Code License Agreement carefully before using
-the source code.
-
-Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
-no-charge, royalty-free, irrevocable copyright license, to reproduce,
-prepare derivative works of, publicly display, publicly perform, and
-distribute this source code and such derivative works in source or
-object code form without any attribution requirements.
-
-The name "Adobe Systems Incorporated" must not be used to endorse or promote products
-derived from the source code without prior written permission.
-
-You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
-against any loss, damage, claims or lawsuits, including attorney's
-fees that arise or result from your use or distribution of the source
-code.
-
-THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
-ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
-NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
-OR ITS SUPPLIERS 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 SOURCE CODE, 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".
- *
- * <p>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.</p>
- *
- * <p>URI's fall into one of three categories:
- * <ul>
- * <li><scheme>:<scheme-specific-part>#<fragment> (non-hierarchical)</li>
- * <li><scheme>:<authority><path>?<query>#<fragment> (hierarchical)</li>
- * <li><path>?<query>#<fragment> (relative hierarchical)</li>
- * </ul></p>
- *
- * <p>The query and fragment parts are optional.</p>
- *
- * <p>This class supports both non-hierarchical and hierarchical URI's</p>
- *
- * <p>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.</p>
- *
- * @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:
- * <scheme>:<authority><path>?<query>#<fragment>
- *
- * For simplicity, we parse the URI in the following order:
- *
- * 1. Fragment (anchors)
- * 2. Query (CGI stuff)
- * 3. Scheme ("http")
- * 4. Authority (host name)
- * 5. Username/Password (if any)
- * 6. Port (server port if any)
- * 7. Path (/homepages/mypage.html)
- *
- * The reason for this order is to minimize any parsing ambiguities.
- * Fragments and queries can contain almost anything (they are parts
- * that can contain custom data with their own syntax). Parsing
- * them out first removes a large chance of parsing errors. This
- * method expects well formed URI's, but performing the parse in
- * this order makes us a little more tolerant of user error.
- *
- * REGEXP
- * Why doesn't this use regular expressions to parse the URI? We
- * have found that in a real world scenario, URI's are not always
- * well formed. Sometimes characters that should have been escaped
- * are not, and those situations would break a regexp pattern. This
- * function attempts to be smart about what it is parsing based on
- * location of characters relative to eachother. This function has
- * been proven through real-world use to parse the vast majority
- * of URI's correctly.
- *
- * NOTE
- * It is assumed that the string in URI form is escaped. This function
- * does not escape anything. If you constructed the URI string by
- * hand, and used this to parse in the URI and still need it escaped,
- * call forceEscape() on your URI object.
- *
- * Parsing Assumptions
- * This routine assumes that the URI being passed is well formed.
- * Passing things like local paths, malformed URI's, and the such
- * will result in parsing errors. This function can handle
- * - absolute hierarchical (e.g. "http://something.com/index.html),
- * - relative hierarchical (e.g. "../images/flower.gif"), or
- * - non-hierarchical URIs (e.g. "mailto:jsmith@fungoo.com").
- *
- * Anything else will probably result in a parsing error, or a bogus
- * URI object.
- *
- * Note that non-hierarchical URIs *MUST* have a scheme, otherwise
- * they will be mistaken for relative URI's.
- *
- * If you are not sure what is being passed to you (like manually
- * entered text from UI), you can construct a blank URI object and
- * call unknownToURI() passing in the unknown string.
- *
- * @return true if successful, false if there was some kind of
- * parsing error
- */
- protected function parseURI(uri:String) : Boolean
- {
- var baseURI:String = uri;
- var index:int, index2:int;
-
- // Make sure this object is clean before we start. If it was used
- // before and we are now parsing a new URI, we don't want any stale
- // info lying around.
- initialize();
-
- // Remove any fragments (anchors) from the URI
- index = baseURI.indexOf("#");
- if (index != -1)
- {
- // Store the fragment piece if any
- if (baseURI.length > (index + 1)) // +1 is to skip the '#'
- _fragment = baseURI.substr(index + 1, baseURI.length - (index + 1));
-
- // Trim off the fragment
- baseURI = baseURI.substr(0, index);
- }
-
- // We need to strip off any CGI parameters (eg '?param=bob')
- index = baseURI.indexOf("?");
- if (index != -1)
- {
- if (baseURI.length > (index + 1))
- _query = baseURI.substr(index + 1, baseURI.length - (index + 1)); // +1 is to skip the '?'
-
- // Trim off the query
- baseURI = baseURI.substr(0, index);
- }
-
- // Now try to find the scheme part
- index = baseURI.search(':');
- index2 = baseURI.search('/');
-
- var containsColon:Boolean = (index != -1);
- var containsSlash:Boolean = (index2 != -1);
-
- // This value is indeterminate if "containsColon" is false.
- // (if there is no colon, does the slash come before or
- // after said non-existing colon?)
- var colonBeforeSlash:Boolean = (!containsSlash || index < index2);
-
- // If it has a colon and it's before the first slash, we will treat
- // it as a scheme. If a slash is before a colon, there must be a
- // stray colon in a path or something. In which case, the colon is
- // not the separator for the scheme. Technically, we could consider
- // this an error, but since this is not an ambiguous state (we know
- // 100% that this has no scheme), we will keep going.
- if (containsColon && colonBeforeSlash)
- {
- // We found a scheme
- _scheme = baseURI.substr(0, index);
-
- // Normalize the scheme
- _scheme = _scheme.toLowerCase();
-
- baseURI = baseURI.substr(index + 1);
-
- if (baseURI.substr(0, 2) == "//")
- {
- // This is a hierarchical URI
- _nonHierarchical = "";
-
- // Trim off the "//"
- baseURI = baseURI.substr(2, baseURI.length - 2);
- }
- else
- {
- // This is a non-hierarchical URI like "mailto:bob@mail.com"
- _nonHierarchical = baseURI;
-
- if ((_valid = validateURI()) == false)
- initialize(); // Bad URI. Clear it.
-
- // No more parsing to do for this case
- return isValid();
- }
- }
- else
- {
- // No scheme. We will consider this a relative URI
- _scheme = "";
- _relative = true;
- _nonHierarchical = "";
- }
-
- // Ok, what we have left is everything after the <scheme>://
-
- // Now that we have stripped off any query and fragment parts, we
- // need to split the authority from the path
-
- if (isRelative())
- {
- // Don't bother looking for the authority. It's a relative URI
- _authority = "";
- _port = "";
- _path = baseURI;
- }
- else
- {
- // Check for malformed UNC style file://///server/type/path/
- // By the time we get here, we have already trimmed the "file://"
- // so baseURI will be ///server/type/path. If baseURI only
- // has one slash, we leave it alone because that is valid (that
- // is the case of "file:///path/to/file.txt" where there is no
- // server - implicit "localhost").
- if (baseURI.substr(0, 2) == "//")
- {
- // Trim all leading slashes
- while(baseURI.charAt(0) == "/")
- baseURI = baseURI.substr(1, baseURI.length - 1);
- }
-
- index = baseURI.search('/');
- if (index == -1)
- {
- // No path. We must have passed something like "http://something.com"
- _authority = baseURI;
- _path = "";
- }
- else
- {
- _authority = baseURI.substr(0, index);
- _path = baseURI.substr(index, baseURI.length - index);
- }
-
- // Check to see if the URI has any username or password information.
- // For example: ftp://username:password@server.com
- index = _authority.search('@');
- if (index != -1)
- {
- // We have a username and possibly a password
- _username = _authority.substr(0, index);
-
- // Remove the username/password from the authority
- _authority = _authority.substr(index + 1); // Skip the '@'
-
- // Now check to see if the username also has a password
- index = _username.search(':');
- if (index != -1)
- {
- _password = _username.substring(index + 1, _username.length);
- _username = _username.substr(0, index);
- }
- else
- _password = "";
- }
- else
- {
- _username = "";
- _password = "";
- }
-
- // Lastly, check to see if the authorty has a port number.
- // This is parsed after the username/password to avoid conflicting
- // with the ':' in the 'username:password' if one exists.
- index = _authority.search(':');
- if (index != -1)
- {
- _port = _authority.substring(index + 1, _authority.length); // skip the ':'
- _authority = _authority.substr(0, index);
- }
- else
- {
- _port = "";
- }
-
- // Lastly, normalize the authority. Domain names
- // are case insensitive.
- _authority = _authority.toLowerCase();
- }
-
- if ((_valid = validateURI()) == false)
- initialize(); // Bad URI. Clear it
-
- return isValid();
- }
-
-
- /********************************************************************
- * Copy function.
- */
- public function copyURI(uri:URI) : void
- {
- this._scheme = uri._scheme;
- this._authority = uri._authority;
- this._username = uri._username;
- this._password = uri._password;
- this._port = uri._port;
- this._path = uri._path;
- this._query = uri._query;
- this._fragment = uri._fragment;
- this._nonHierarchical = uri._nonHierarchical;
-
- this._valid = uri._valid;
- this._relative = uri._relative;
- }
-
-
- /**
- * @private
- * Checks if the given string only contains a-z or A-Z.
- */
- protected function verifyAlpha(str:String) : Boolean
- {
- var pattern:RegExp = /[^a-z]/;
- var index:int;
-
- str = str.toLowerCase();
- index = str.search(pattern);
-
- if (index == -1)
- return true;
- else
- return false;
- }
-
- /**
- * Is this a valid URI?
- *
- * @return true if this object represents a valid URI, false
- * otherwise.
- */
- public function isValid() : Boolean
- {
- return this._valid;
- }
-
-
- /**
- * Is this URI an absolute URI? An absolute URI is a complete, fully
- * qualified reference to a resource. e.g. http://site.com/index.htm
- * Non-hierarchical URI's are always absolute.
- */
- public function isAbsolute() : Boolean
- {
- return !this._relative;
- }
-
-
- /**
- * Is this URI a relative URI? Relative URI's do not have a scheme
- * and only contain a relative path with optional anchor and query
- * parts. e.g. "../reports/index.htm". Non-hierarchical URI's
- * will never be relative.
- */
- public function isRelative() : Boolean
- {
- return this._relative;
- }
-
-
- /**
- * Does this URI point to a resource that is a directory/folder?
- * The URI specification dictates that any path that ends in a slash
- * is a directory. This is needed to be able to perform correct path
- * logic when combining relative URI's with absolute URI's to
- * obtain the correct absolute URI to a resource.
- *
- * @see URI.chdir
- *
- * @return true if this URI represents a directory resource, false
- * if this URI represents a file resource.
- */
- public function isDirectory() : Boolean
- {
- if (_path.length == 0)
- return false;
-
- return (_path.charAt(path.length - 1) == '/');
- }
-
-
- /**
- * Is this URI a hierarchical URI? URI's can be
- */
- public function isHierarchical() : Boolean
- {
- return hierState;
- }
-
-
- /**
- * The scheme of the URI.
- */
- public function get scheme() : String
- {
- return URI.unescapeChars(_scheme);
- }
- public function set scheme(schemeStr:String) : void
- {
- // Normalize the scheme
- var normalized:String = schemeStr.toLowerCase();
- _scheme = URI.fastEscapeChars(normalized, URI.URIschemeExcludedBitmap);
- }
-
-
- /**
- * The authority (host) of the URI. Only valid for
- * hierarchical URI's. If the URI is relative, this will
- * be an empty string. When setting this value, the string
- * given is assumed to be unescaped. When retrieving this
- * value, the resulting string is unescaped.
- */
- public function get authority() : String
- {
- return URI.unescapeChars(_authority);
- }
- public function set authority(authorityStr:String) : void
- {
- // Normalize the authority
- authorityStr = authorityStr.toLowerCase();
-
- _authority = URI.fastEscapeChars(authorityStr,
- URI.URIauthorityExcludedBitmap);
-
- // Only hierarchical URI's can have an authority, make
- // sure this URI is of the proper format.
- this.hierState = true;
- }
-
-
- /**
- * The username of the URI. Only valid for hierarchical
- * URI's. If the URI is relative, this will be an empty
- * string.
- *
- * <p>The URI specification allows for authentication
- * credentials to be embedded in the URI as such:</p>
- *
- * <p>http://user:passwd@host/path/to/file.htm</p>
- *
- * <p>When setting this value, the string
- * given is assumed to be unescaped. When retrieving this
- * value, the resulting string is unescaped.</p>
- */
- 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:
- *
- * <p>http://site.com:8080/index.htm</p>
- */
- 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.
- *
- * <p>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.</p>
- *
- * <p>An absolute path may look like:</p>
- * <listing>/full/path/to/my/file.htm</listing>
- *
- * <p>A relative path may look like:</p>
- * <listing>
- * path/to/my/file.htm
- * ../images/logo.gif
- * ../../reports/index.htm
- * </listing>
- *
- * <p>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:</p>
- *
- * <listing>http:/site.com/path/to/file.htm</listing>
- *
- * <p>This absolute URI has an absolute path of "/path/to/file.htm".</p>
- *
- * <p>Relative URI's can have either absolute paths or relative paths.
- * All of the following relative URI's are valid:</p>
- *
- * <listing>
- * /absolute/path/to/file.htm
- * path/to/file.htm
- * ../path/to/file.htm
- * </listing>
- */
- public function get path() : String
- {
- return URI.unescapeChars(_path);
- }
- public function set path(pathStr:String) : void
- {
- this._path = URI.fastEscapeChars(pathStr, URI.URIpathExcludedBitmap);
-
- if (this._scheme == UNKNOWN_SCHEME)
- {
- // We set the path. This is a valid URI now.
- this._scheme = "";
- }
-
- // Only hierarchical URI's can have a path.
- hierState = true;
- }
-
-
- /**
- * The query (CGI) portion of the URI. This part is valid for
- * both hierarchical and non-hierarchical URI's.
- *
- * <p>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.
- *
- * <p>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:</p>
- *
- * <listing>http://site.com/script.php?param1=value1¶m2=value2</listing>
- *
- * <p>This class has specific support for this query syntax</p>
- *
- * <p>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.</p>
- *
- * 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.
- *
- * <p>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.</p>
- *
- * <p>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.</p>
- *
- * @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.
- *
- * <p>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.</p>
- *
- * @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.
- *
- * <p>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.</p>
- *
- * @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.
- *
- * <p>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.</p>
- *
- * @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:
- *
- * <listing>
- * var query:Object = uri.getQueryByMap();
- * var value:String = query["param"]; // get a value
- * query["param2"] = "foo"; // set a new value
- * </listing>
- *
- * @return Object that contains the name/value pairs of the query.
- *
- * @see #setQueryByMap
- * @see #getQueryValue
- * @see #setQueryValue
- */
- public function getQueryByMap() : Object
- {
- var queryStr:String;
- var pair:String;
- var pairs:Array;
- var item:Array;
- var name:String, value:String;
- var index:int;
- var map:Object = new Object();
-
-
- // We need the raw query string, no unescaping.
- queryStr = this._query;
-
- pairs = queryStr.split('&');
- for each (pair in pairs)
- {
- if (pair.length == 0)
- continue;
-
- item = pair.split('=');
-
- if (item.length > 0)
- name = item[0];
- else
- continue; // empty array
-
- if (item.length > 1)
- value = item[1];
- else
- value = "";
-
- name = queryPartUnescape(name);
- value = queryPartUnescape(value);
-
- map[name] = value;
- }
-
- return map;
- }
-
-
- /**
- * Set the query part of this URI using the given object as the
- * content source. Any member of the object that has a value of
- * null will not be in the resulting query.
- *
- * @param map object that contains the name/value pairs as
- * members of that object.
- *
- * @see #getQueryByMap
- * @see #getQueryValue
- * @see #setQueryValue
- */
- public function setQueryByMap(map:Object) : void
- {
- var item:String;
- var name:String, value:String;
- var queryStr:String = "";
- var tmpPair:String;
- var foo:String;
-
- for (item in map)
- {
- name = item;
- value = map[item];
-
- if (value == null)
- value = "";
-
- // Need to escape the name/value pair so that they
- // don't conflict with the query syntax (specifically
- // '=', '&', and <whitespace>).
- name = queryPartEscape(name);
- value = queryPartEscape(value);
-
- tmpPair = name;
-
- if (value.length > 0)
- {
- tmpPair += "=";
- tmpPair += value;
- }
-
- if (queryStr.length != 0)
- queryStr += '&'; // Add the separator
-
- queryStr += tmpPair;
- }
-
- // We don't want to escape. We already escaped the
- // individual name/value pairs. If we escaped the
- // query string again by assigning it to "query",
- // we would have double escaping.
- _query = queryStr;
- }
-
-
- /**
- * Similar to Escape(), except this also escapes characters that
- * would conflict with the name/value pair query syntax. This is
- * intended to be called on each individual "name" and "value"
- * in the query making sure that nothing in the name or value
- * strings contain characters that would conflict with the query
- * syntax (e.g. '=' and '&').
- *
- * @param unescaped unescaped string that is to be escaped.
- *
- * @return escaped string.
- *
- * @see #queryUnescape
- */
- static public function queryPartEscape(unescaped:String) : String
- {
- var escaped:String = unescaped;
- escaped = URI.fastEscapeChars(unescaped, URI.URIqueryPartExcludedBitmap);
- return escaped;
- }
-
-
- /**
- * Unescape the individual name/value string pairs.
- *
- * @param escaped escaped string to be unescaped
- *
- * @return unescaped string
- *
- * @see #queryEscape
- */
- static public function queryPartUnescape(escaped:String) : String
- {
- var unescaped:String = escaped;
- unescaped = unescapeChars(unescaped);
- return unescaped;
- }
-
- /**
- * Output this URI as a string. The resulting string is properly
- * escaped and well formed for machine processing.
- */
- public function toString() : String
- {
- if (this == null)
- return "";
- else
- return toStringInternal(false);
- }
-
- /**
- * Output the URI as a string that is easily readable by a human.
- * This outputs the URI with all escape sequences unescaped to
- * their character representation. This makes the URI easier for
- * a human to read, but the URI could be completely invalid
- * because some unescaped characters may now cause ambiguous parsing.
- * This function should only be used if you want to display a URI to
- * a user. This function should never be used outside that specific
- * case.
- *
- * @return the URI in string format with all escape sequences
- * unescaped.
- *
- * @see #toString
- */
- public function toDisplayString() : String
- {
- return toStringInternal(true);
- }
-
-
- /**
- * @private
- *
- * The guts of toString()
- */
- protected function toStringInternal(forDisplay:Boolean) : String
- {
- var uri:String = "";
- var part:String = "";
-
- if (isHierarchical() == false)
- {
- // non-hierarchical URI
-
- uri += (forDisplay ? this.scheme : _scheme);
- uri += ":";
- uri += (forDisplay ? this.nonHierarchical : _nonHierarchical);
- }
- else
- {
- // Hierarchical URI
-
- if (isRelative() == false)
- {
- // If it is not a relative URI, then we want the scheme and
- // authority parts in the string. If it is relative, we
- // do NOT want this stuff.
-
- if (_scheme.length != 0)
- {
- part = (forDisplay ? this.scheme : _scheme);
- uri += part + ":";
- }
-
- if (_authority.length != 0 || isOfType("file"))
- {
- uri += "//";
-
- // Add on any username/password associated with this
- // authority
- if (_username.length != 0)
- {
- part = (forDisplay ? this.username : _username);
- uri += part;
-
- if (_password.length != 0)
- {
- part = (forDisplay ? this.password : _password);
- uri += ":" + part;
- }
-
- uri += "@";
- }
-
- // add the authority
- part = (forDisplay ? this.authority : _authority);
- uri += part;
-
- // Tack on the port number, if any
- if (port.length != 0)
- uri += ":" + port;
- }
- }
-
- // Tack on the path
- part = (forDisplay ? this.path : _path);
- uri += part;
-
- } // end hierarchical part
-
- // Both non-hier and hierarchical have query and fragment parts
-
- // Add on the query and fragment parts
- if (_query.length != 0)
- {
- part = (forDisplay ? this.query : _query);
- uri += "?" + part;
- }
-
- if (fragment.length != 0)
- {
- part = (forDisplay ? this.fragment : _fragment);
- uri += "#" + part;
- }
-
- return uri;
- }
-
- /**
- * Forcefully ensure that this URI is properly escaped.
- *
- * <p>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.</p>
- */
- 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:
- *
- * <listing>http://something.com/path/to/my/page.html?form=yes&name=bob#anchor</listing>
- *
- * <p>This will return ".html".</p>
- *
- * @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.
- *
- * <p>For example, if the URI is:</p>
- * <listing>http://something.com/some/path/to/my/file.html</listing>
- * <p>this function will return "file.html".</p>
- *
- * @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.
- *
- * <p>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:<br/>
- * 1. http://something.com/a/b/c/ (directory)<br/>
- * 2. http://something.com/a/b/c (not directory)<br/>
- * you will get:<br/>
- * 1. http://something.com/a/b/c/d<br/>
- * 2. http://something.com/a/b/d<br/></p>
- *
- * <p>See RFC 2396, Appendix C for more info.</p>
- *
- * @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 final:String = this.scheme + ":" + ref;
-
- return constructURI(final);
- }
- 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:
- *
- * <listing>
- * var uri1:URI = new URI("http://something.com/path/to/some/file.html");
- * var uri2:URI = new URI("http://something.com/path/to/another/file.html");
- *
- * uri1.MakeRelativePath(uri2);</listing>
- *
- * <p>uri1 will have a final value of "../some/file.html"</p>
- *
- * <p>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:</p>
- *
- * <p>../../../../../../some/path/to/my/file.html</p>
- *
- * @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.
- *
- * <p>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.</p>
- *
- * <p>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.</p>
- *
- * <p>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.</p>
- *
- * @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
+/* +Adobe Systems Incorporated(r) Source Code License Agreement +Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + +Please read this Source Code License Agreement carefully before using +the source code. + +Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable copyright license, to reproduce, +prepare derivative works of, publicly display, publicly perform, and +distribute this source code and such derivative works in source or +object code form without any attribution requirements. + +The name "Adobe Systems Incorporated" must not be used to endorse or promote products +derived from the source code without prior written permission. + +You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and +against any loss, damage, claims or lawsuits, including attorney's +fees that arise or result from your use or distribution of the source +code. + +THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT +ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF +NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA +OR ITS SUPPLIERS 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 SOURCE CODE, 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". + * + * <p>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.</p> + * + * <p>URI's fall into one of three categories: + * <ul> + * <li><scheme>:<scheme-specific-part>#<fragment> (non-hierarchical)</li> + * <li><scheme>:<authority><path>?<query>#<fragment> (hierarchical)</li> + * <li><path>?<query>#<fragment> (relative hierarchical)</li> + * </ul></p> + * + * <p>The query and fragment parts are optional.</p> + * + * <p>This class supports both non-hierarchical and hierarchical URI's</p> + * + * <p>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.</p> + * + * @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: + * <scheme>:<authority><path>?<query>#<fragment> + * + * For simplicity, we parse the URI in the following order: + * + * 1. Fragment (anchors) + * 2. Query (CGI stuff) + * 3. Scheme ("http") + * 4. Authority (host name) + * 5. Username/Password (if any) + * 6. Port (server port if any) + * 7. Path (/homepages/mypage.html) + * + * The reason for this order is to minimize any parsing ambiguities. + * Fragments and queries can contain almost anything (they are parts + * that can contain custom data with their own syntax). Parsing + * them out first removes a large chance of parsing errors. This + * method expects well formed URI's, but performing the parse in + * this order makes us a little more tolerant of user error. + * + * REGEXP + * Why doesn't this use regular expressions to parse the URI? We + * have found that in a real world scenario, URI's are not always + * well formed. Sometimes characters that should have been escaped + * are not, and those situations would break a regexp pattern. This + * function attempts to be smart about what it is parsing based on + * location of characters relative to eachother. This function has + * been proven through real-world use to parse the vast majority + * of URI's correctly. + * + * NOTE + * It is assumed that the string in URI form is escaped. This function + * does not escape anything. If you constructed the URI string by + * hand, and used this to parse in the URI and still need it escaped, + * call forceEscape() on your URI object. + * + * Parsing Assumptions + * This routine assumes that the URI being passed is well formed. + * Passing things like local paths, malformed URI's, and the such + * will result in parsing errors. This function can handle + * - absolute hierarchical (e.g. "http://something.com/index.html), + * - relative hierarchical (e.g. "../images/flower.gif"), or + * - non-hierarchical URIs (e.g. "mailto:jsmith@fungoo.com"). + * + * Anything else will probably result in a parsing error, or a bogus + * URI object. + * + * Note that non-hierarchical URIs *MUST* have a scheme, otherwise + * they will be mistaken for relative URI's. + * + * If you are not sure what is being passed to you (like manually + * entered text from UI), you can construct a blank URI object and + * call unknownToURI() passing in the unknown string. + * + * @return true if successful, false if there was some kind of + * parsing error + */ + protected function parseURI(uri:String) : Boolean + { + var baseURI:String = uri; + var index:int, index2:int; + + // Make sure this object is clean before we start. If it was used + // before and we are now parsing a new URI, we don't want any stale + // info lying around. + initialize(); + + // Remove any fragments (anchors) from the URI + index = baseURI.indexOf("#"); + if (index != -1) + { + // Store the fragment piece if any + if (baseURI.length > (index + 1)) // +1 is to skip the '#' + _fragment = baseURI.substr(index + 1, baseURI.length - (index + 1)); + + // Trim off the fragment + baseURI = baseURI.substr(0, index); + } + + // We need to strip off any CGI parameters (eg '?param=bob') + index = baseURI.indexOf("?"); + if (index != -1) + { + if (baseURI.length > (index + 1)) + _query = baseURI.substr(index + 1, baseURI.length - (index + 1)); // +1 is to skip the '?' + + // Trim off the query + baseURI = baseURI.substr(0, index); + } + + // Now try to find the scheme part + index = baseURI.search(':'); + index2 = baseURI.search('/'); + + var containsColon:Boolean = (index != -1); + var containsSlash:Boolean = (index2 != -1); + + // This value is indeterminate if "containsColon" is false. + // (if there is no colon, does the slash come before or + // after said non-existing colon?) + var colonBeforeSlash:Boolean = (!containsSlash || index < index2); + + // If it has a colon and it's before the first slash, we will treat + // it as a scheme. If a slash is before a colon, there must be a + // stray colon in a path or something. In which case, the colon is + // not the separator for the scheme. Technically, we could consider + // this an error, but since this is not an ambiguous state (we know + // 100% that this has no scheme), we will keep going. + if (containsColon && colonBeforeSlash) + { + // We found a scheme + _scheme = baseURI.substr(0, index); + + // Normalize the scheme + _scheme = _scheme.toLowerCase(); + + baseURI = baseURI.substr(index + 1); + + if (baseURI.substr(0, 2) == "//") + { + // This is a hierarchical URI + _nonHierarchical = ""; + + // Trim off the "//" + baseURI = baseURI.substr(2, baseURI.length - 2); + } + else + { + // This is a non-hierarchical URI like "mailto:bob@mail.com" + _nonHierarchical = baseURI; + + if ((_valid = validateURI()) == false) + initialize(); // Bad URI. Clear it. + + // No more parsing to do for this case + return isValid(); + } + } + else + { + // No scheme. We will consider this a relative URI + _scheme = ""; + _relative = true; + _nonHierarchical = ""; + } + + // Ok, what we have left is everything after the <scheme>:// + + // Now that we have stripped off any query and fragment parts, we + // need to split the authority from the path + + if (isRelative()) + { + // Don't bother looking for the authority. It's a relative URI + _authority = ""; + _port = ""; + _path = baseURI; + } + else + { + // Check for malformed UNC style file://///server/type/path/ + // By the time we get here, we have already trimmed the "file://" + // so baseURI will be ///server/type/path. If baseURI only + // has one slash, we leave it alone because that is valid (that + // is the case of "file:///path/to/file.txt" where there is no + // server - implicit "localhost"). + if (baseURI.substr(0, 2) == "//") + { + // Trim all leading slashes + while(baseURI.charAt(0) == "/") + baseURI = baseURI.substr(1, baseURI.length - 1); + } + + index = baseURI.search('/'); + if (index == -1) + { + // No path. We must have passed something like "http://something.com" + _authority = baseURI; + _path = ""; + } + else + { + _authority = baseURI.substr(0, index); + _path = baseURI.substr(index, baseURI.length - index); + } + + // Check to see if the URI has any username or password information. + // For example: ftp://username:password@server.com + index = _authority.search('@'); + if (index != -1) + { + // We have a username and possibly a password + _username = _authority.substr(0, index); + + // Remove the username/password from the authority + _authority = _authority.substr(index + 1); // Skip the '@' + + // Now check to see if the username also has a password + index = _username.search(':'); + if (index != -1) + { + _password = _username.substring(index + 1, _username.length); + _username = _username.substr(0, index); + } + else + _password = ""; + } + else + { + _username = ""; + _password = ""; + } + + // Lastly, check to see if the authorty has a port number. + // This is parsed after the username/password to avoid conflicting + // with the ':' in the 'username:password' if one exists. + index = _authority.search(':'); + if (index != -1) + { + _port = _authority.substring(index + 1, _authority.length); // skip the ':' + _authority = _authority.substr(0, index); + } + else + { + _port = ""; + } + + // Lastly, normalize the authority. Domain names + // are case insensitive. + _authority = _authority.toLowerCase(); + } + + if ((_valid = validateURI()) == false) + initialize(); // Bad URI. Clear it + + return isValid(); + } + + + /******************************************************************** + * Copy function. + */ + public function copyURI(uri:URI) : void + { + this._scheme = uri._scheme; + this._authority = uri._authority; + this._username = uri._username; + this._password = uri._password; + this._port = uri._port; + this._path = uri._path; + this._query = uri._query; + this._fragment = uri._fragment; + this._nonHierarchical = uri._nonHierarchical; + + this._valid = uri._valid; + this._relative = uri._relative; + } + + + /** + * @private + * Checks if the given string only contains a-z or A-Z. + */ + protected function verifyAlpha(str:String) : Boolean + { + var pattern:RegExp = /[^a-z]/; + var index:int; + + str = str.toLowerCase(); + index = str.search(pattern); + + if (index == -1) + return true; + else + return false; + } + + /** + * Is this a valid URI? + * + * @return true if this object represents a valid URI, false + * otherwise. + */ + public function isValid() : Boolean + { + return this._valid; + } + + + /** + * Is this URI an absolute URI? An absolute URI is a complete, fully + * qualified reference to a resource. e.g. http://site.com/index.htm + * Non-hierarchical URI's are always absolute. + */ + public function isAbsolute() : Boolean + { + return !this._relative; + } + + + /** + * Is this URI a relative URI? Relative URI's do not have a scheme + * and only contain a relative path with optional anchor and query + * parts. e.g. "../reports/index.htm". Non-hierarchical URI's + * will never be relative. + */ + public function isRelative() : Boolean + { + return this._relative; + } + + + /** + * Does this URI point to a resource that is a directory/folder? + * The URI specification dictates that any path that ends in a slash + * is a directory. This is needed to be able to perform correct path + * logic when combining relative URI's with absolute URI's to + * obtain the correct absolute URI to a resource. + * + * @see URI.chdir + * + * @return true if this URI represents a directory resource, false + * if this URI represents a file resource. + */ + public function isDirectory() : Boolean + { + if (_path.length == 0) + return false; + + return (_path.charAt(path.length - 1) == '/'); + } + + + /** + * Is this URI a hierarchical URI? URI's can be + */ + public function isHierarchical() : Boolean + { + return hierState; + } + + + /** + * The scheme of the URI. + */ + public function get scheme() : String + { + return URI.unescapeChars(_scheme); + } + public function set scheme(schemeStr:String) : void + { + // Normalize the scheme + var normalized:String = schemeStr.toLowerCase(); + _scheme = URI.fastEscapeChars(normalized, URI.URIschemeExcludedBitmap); + } + + + /** + * The authority (host) of the URI. Only valid for + * hierarchical URI's. If the URI is relative, this will + * be an empty string. When setting this value, the string + * given is assumed to be unescaped. When retrieving this + * value, the resulting string is unescaped. + */ + public function get authority() : String + { + return URI.unescapeChars(_authority); + } + public function set authority(authorityStr:String) : void + { + // Normalize the authority + authorityStr = authorityStr.toLowerCase(); + + _authority = URI.fastEscapeChars(authorityStr, + URI.URIauthorityExcludedBitmap); + + // Only hierarchical URI's can have an authority, make + // sure this URI is of the proper format. + this.hierState = true; + } + + + /** + * The username of the URI. Only valid for hierarchical + * URI's. If the URI is relative, this will be an empty + * string. + * + * <p>The URI specification allows for authentication + * credentials to be embedded in the URI as such:</p> + * + * <p>http://user:passwd@host/path/to/file.htm</p> + * + * <p>When setting this value, the string + * given is assumed to be unescaped. When retrieving this + * value, the resulting string is unescaped.</p> + */ + 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: + * + * <p>http://site.com:8080/index.htm</p> + */ + 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. + * + * <p>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.</p> + * + * <p>An absolute path may look like:</p> + * <listing>/full/path/to/my/file.htm</listing> + * + * <p>A relative path may look like:</p> + * <listing> + * path/to/my/file.htm + * ../images/logo.gif + * ../../reports/index.htm + * </listing> + * + * <p>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:</p> + * + * <listing>http:/site.com/path/to/file.htm</listing> + * + * <p>This absolute URI has an absolute path of "/path/to/file.htm".</p> + * + * <p>Relative URI's can have either absolute paths or relative paths. + * All of the following relative URI's are valid:</p> + * + * <listing> + * /absolute/path/to/file.htm + * path/to/file.htm + * ../path/to/file.htm + * </listing> + */ + public function get path() : String + { + return URI.unescapeChars(_path); + } + public function set path(pathStr:String) : void + { + this._path = URI.fastEscapeChars(pathStr, URI.URIpathExcludedBitmap); + + if (this._scheme == UNKNOWN_SCHEME) + { + // We set the path. This is a valid URI now. + this._scheme = ""; + } + + // Only hierarchical URI's can have a path. + hierState = true; + } + + + /** + * The query (CGI) portion of the URI. This part is valid for + * both hierarchical and non-hierarchical URI's. + * + * <p>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. + * + * <p>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:</p> + * + * <listing>http://site.com/script.php?param1=value1¶m2=value2</listing> + * + * <p>This class has specific support for this query syntax</p> + * + * <p>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.</p> + * + * 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. + * + * <p>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.</p> + * + * <p>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.</p> + * + * @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. + * + * <p>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.</p> + * + * @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. + * + * <p>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.</p> + * + * @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. + * + * <p>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.</p> + * + * @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: + * + * <listing> + * var query:Object = uri.getQueryByMap(); + * var value:String = query["param"]; // get a value + * query["param2"] = "foo"; // set a new value + * </listing> + * + * @return Object that contains the name/value pairs of the query. + * + * @see #setQueryByMap + * @see #getQueryValue + * @see #setQueryValue + */ + public function getQueryByMap() : Object + { + var queryStr:String; + var pair:String; + var pairs:Array; + var item:Array; + var name:String, value:String; + var index:int; + var map:Object = new Object(); + + + // We need the raw query string, no unescaping. + queryStr = this._query; + + pairs = queryStr.split('&'); + for each (pair in pairs) + { + if (pair.length == 0) + continue; + + item = pair.split('='); + + if (item.length > 0) + name = item[0]; + else + continue; // empty array + + if (item.length > 1) + value = item[1]; + else + value = ""; + + name = queryPartUnescape(name); + value = queryPartUnescape(value); + + map[name] = value; + } + + return map; + } + + + /** + * Set the query part of this URI using the given object as the + * content source. Any member of the object that has a value of + * null will not be in the resulting query. + * + * @param map object that contains the name/value pairs as + * members of that object. + * + * @see #getQueryByMap + * @see #getQueryValue + * @see #setQueryValue + */ + public function setQueryByMap(map:Object) : void + { + var item:String; + var name:String, value:String; + var queryStr:String = ""; + var tmpPair:String; + var foo:String; + + for (item in map) + { + name = item; + value = map[item]; + + if (value == null) + value = ""; + + // Need to escape the name/value pair so that they + // don't conflict with the query syntax (specifically + // '=', '&', and <whitespace>). + name = queryPartEscape(name); + value = queryPartEscape(value); + + tmpPair = name; + + if (value.length > 0) + { + tmpPair += "="; + tmpPair += value; + } + + if (queryStr.length != 0) + queryStr += '&'; // Add the separator + + queryStr += tmpPair; + } + + // We don't want to escape. We already escaped the + // individual name/value pairs. If we escaped the + // query string again by assigning it to "query", + // we would have double escaping. + _query = queryStr; + } + + + /** + * Similar to Escape(), except this also escapes characters that + * would conflict with the name/value pair query syntax. This is + * intended to be called on each individual "name" and "value" + * in the query making sure that nothing in the name or value + * strings contain characters that would conflict with the query + * syntax (e.g. '=' and '&'). + * + * @param unescaped unescaped string that is to be escaped. + * + * @return escaped string. + * + * @see #queryUnescape + */ + static public function queryPartEscape(unescaped:String) : String + { + var escaped:String = unescaped; + escaped = URI.fastEscapeChars(unescaped, URI.URIqueryPartExcludedBitmap); + return escaped; + } + + + /** + * Unescape the individual name/value string pairs. + * + * @param escaped escaped string to be unescaped + * + * @return unescaped string + * + * @see #queryEscape + */ + static public function queryPartUnescape(escaped:String) : String + { + var unescaped:String = escaped; + unescaped = unescapeChars(unescaped); + return unescaped; + } + + /** + * Output this URI as a string. The resulting string is properly + * escaped and well formed for machine processing. + */ + public function toString() : String + { + if (this == null) + return ""; + else + return toStringInternal(false); + } + + /** + * Output the URI as a string that is easily readable by a human. + * This outputs the URI with all escape sequences unescaped to + * their character representation. This makes the URI easier for + * a human to read, but the URI could be completely invalid + * because some unescaped characters may now cause ambiguous parsing. + * This function should only be used if you want to display a URI to + * a user. This function should never be used outside that specific + * case. + * + * @return the URI in string format with all escape sequences + * unescaped. + * + * @see #toString + */ + public function toDisplayString() : String + { + return toStringInternal(true); + } + + + /** + * @private + * + * The guts of toString() + */ + protected function toStringInternal(forDisplay:Boolean) : String + { + var uri:String = ""; + var part:String = ""; + + if (isHierarchical() == false) + { + // non-hierarchical URI + + uri += (forDisplay ? this.scheme : _scheme); + uri += ":"; + uri += (forDisplay ? this.nonHierarchical : _nonHierarchical); + } + else + { + // Hierarchical URI + + if (isRelative() == false) + { + // If it is not a relative URI, then we want the scheme and + // authority parts in the string. If it is relative, we + // do NOT want this stuff. + + if (_scheme.length != 0) + { + part = (forDisplay ? this.scheme : _scheme); + uri += part + ":"; + } + + if (_authority.length != 0 || isOfType("file")) + { + uri += "//"; + + // Add on any username/password associated with this + // authority + if (_username.length != 0) + { + part = (forDisplay ? this.username : _username); + uri += part; + + if (_password.length != 0) + { + part = (forDisplay ? this.password : _password); + uri += ":" + part; + } + + uri += "@"; + } + + // add the authority + part = (forDisplay ? this.authority : _authority); + uri += part; + + // Tack on the port number, if any + if (port.length != 0) + uri += ":" + port; + } + } + + // Tack on the path + part = (forDisplay ? this.path : _path); + uri += part; + + } // end hierarchical part + + // Both non-hier and hierarchical have query and fragment parts + + // Add on the query and fragment parts + if (_query.length != 0) + { + part = (forDisplay ? this.query : _query); + uri += "?" + part; + } + + if (fragment.length != 0) + { + part = (forDisplay ? this.fragment : _fragment); + uri += "#" + part; + } + + return uri; + } + + /** + * Forcefully ensure that this URI is properly escaped. + * + * <p>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.</p> + */ + 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: + * + * <listing>http://something.com/path/to/my/page.html?form=yes&name=bob#anchor</listing> + * + * <p>This will return ".html".</p> + * + * @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. + * + * <p>For example, if the URI is:</p> + * <listing>http://something.com/some/path/to/my/file.html</listing> + * <p>this function will return "file.html".</p> + * + * @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. + * + * <p>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:<br/> + * 1. http://something.com/a/b/c/ (directory)<br/> + * 2. http://something.com/a/b/c (not directory)<br/> + * you will get:<br/> + * 1. http://something.com/a/b/c/d<br/> + * 2. http://something.com/a/b/d<br/></p> + * + * <p>See RFC 2396, Appendix C for more info.</p> + * + * @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 final:String = this.scheme + ":" + ref; + + return constructURI(final); + } + 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: + * + * <listing> + * var uri1:URI = new URI("http://something.com/path/to/some/file.html"); + * var uri2:URI = new URI("http://something.com/path/to/another/file.html"); + * + * uri1.MakeRelativePath(uri2);</listing> + * + * <p>uri1 will have a final value of "../some/file.html"</p> + * + * <p>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:</p> + * + * <p>../../../../../../some/path/to/my/file.html</p> + * + * @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. + * + * <p>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.</p> + * + * <p>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.</p> + * + * <p>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.</p> + * + * @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 --git a/webcam/com/adobe/net/URIEncodingBitmap.as b/webcam/com/adobe/net/URIEncodingBitmap.as index e85ac55..9c0239c 100644 --- a/webcam/com/adobe/net/URIEncodingBitmap.as +++ b/webcam/com/adobe/net/URIEncodingBitmap.as @@ -1,142 +1,142 @@ -/*
- Adobe Systems Incorporated(r) Source Code License Agreement
- Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
- Please read this Source Code License Agreement carefully before using
- the source code.
-
- Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
- no-charge, royalty-free, irrevocable copyright license, to reproduce,
- prepare derivative works of, publicly display, publicly perform, and
- distribute this source code and such derivative works in source or
- object code form without any attribution requirements.
-
- The name "Adobe Systems Incorporated" must not be used to endorse or promote products
- derived from the source code without prior written permission.
-
- You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
- against any loss, damage, claims or lawsuits, including attorney's
- fees that arise or result from your use or distribution of the source
- code.
-
- THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
- ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
- NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
- OR ITS SUPPLIERS 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 SOURCE CODE, 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;
- }
- }
- }
+/* + Adobe Systems Incorporated(r) Source Code License Agreement + Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + + Please read this Source Code License Agreement carefully before using + the source code. + + Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, + no-charge, royalty-free, irrevocable copyright license, to reproduce, + prepare derivative works of, publicly display, publicly perform, and + distribute this source code and such derivative works in source or + object code form without any attribution requirements. + + The name "Adobe Systems Incorporated" must not be used to endorse or promote products + derived from the source code without prior written permission. + + You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and + against any loss, damage, claims or lawsuits, including attorney's + fees that arise or result from your use or distribution of the source + code. + + THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT + ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF + NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA + OR ITS SUPPLIERS 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 SOURCE CODE, 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 --git a/webcam/com/adobe/net/proxies/RFC2817Socket.as b/webcam/com/adobe/net/proxies/RFC2817Socket.as index 3657da4..c52ee39 100644 --- a/webcam/com/adobe/net/proxies/RFC2817Socket.as +++ b/webcam/com/adobe/net/proxies/RFC2817Socket.as @@ -1,204 +1,204 @@ -/*
- Adobe Systems Incorporated(r) Source Code License Agreement
- Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
- Please read this Source Code License Agreement carefully before using
- the source code.
-
- Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
- no-charge, royalty-free, irrevocable copyright license, to reproduce,
- prepare derivative works of, publicly display, publicly perform, and
- distribute this source code and such derivative works in source or
- object code form without any attribution requirements.
-
- The name "Adobe Systems Incorporated" must not be used to endorse or promote products
- derived from the source code without prior written permission.
-
- You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
- against any loss, damage, claims or lawsuits, including attorney's
- fees that arise or result from your use or distribution of the source
- code.
-
- THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
- ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
- NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
- OR ITS SUPPLIERS 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 SOURCE CODE, 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)
- {
- if (host != null && port != 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);
- }
- }
- }
+/* + Adobe Systems Incorporated(r) Source Code License Agreement + Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + + Please read this Source Code License Agreement carefully before using + the source code. + + Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, + no-charge, royalty-free, irrevocable copyright license, to reproduce, + prepare derivative works of, publicly display, publicly perform, and + distribute this source code and such derivative works in source or + object code form without any attribution requirements. + + The name "Adobe Systems Incorporated" must not be used to endorse or promote products + derived from the source code without prior written permission. + + You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and + against any loss, damage, claims or lawsuits, including attorney's + fees that arise or result from your use or distribution of the source + code. + + THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT + ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF + NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA + OR ITS SUPPLIERS 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 SOURCE CODE, 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) + { + if (host != null && port != 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 --git a/webcam/com/adobe/serialization/json/JSON.as b/webcam/com/adobe/serialization/json/JSON.as index d43c420..1d2477e 100644 --- a/webcam/com/adobe/serialization/json/JSON.as +++ b/webcam/com/adobe/serialization/json/JSON.as @@ -1,88 +1,88 @@ -/*
-Adobe Systems Incorporated(r) Source Code License Agreement
-Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
-Please read this Source Code License Agreement carefully before using
-the source code.
-
-Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
-no-charge, royalty-free, irrevocable copyright license, to reproduce,
-prepare derivative works of, publicly display, publicly perform, and
-distribute this source code and such derivative works in source or
-object code form without any attribution requirements.
-
-The name "Adobe Systems Incorporated" must not be used to endorse or promote products
-derived from the source code without prior written permission.
-
-You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
-against any loss, damage, claims or lawsuits, including attorney's
-fees that arise or result from your use or distribution of the source
-code.
-
-THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
-ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
-NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
-OR ITS SUPPLIERS 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 SOURCE CODE, 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:
- * <code>
- * // 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 );
- * </code>
- */
- 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 {
-
- var encoder:JSONEncoder = new JSONEncoder( o );
- return encoder.getString();
-
- }
-
- /**
- * Decodes a JSON string into a native object.
- *
- * @param s The JSON string representing the object
- * @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 ):* {
-
- var decoder:JSONDecoder = new JSONDecoder( s )
- return decoder.getValue();
-
- }
-
- }
-
+/* +Adobe Systems Incorporated(r) Source Code License Agreement +Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + +Please read this Source Code License Agreement carefully before using +the source code. + +Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable copyright license, to reproduce, +prepare derivative works of, publicly display, publicly perform, and +distribute this source code and such derivative works in source or +object code form without any attribution requirements. + +The name "Adobe Systems Incorporated" must not be used to endorse or promote products +derived from the source code without prior written permission. + +You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and +against any loss, damage, claims or lawsuits, including attorney's +fees that arise or result from your use or distribution of the source +code. + +THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT +ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF +NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA +OR ITS SUPPLIERS 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 SOURCE CODE, 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: + * <code> + * // 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 ); + * </code> + */ + 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 { + + var encoder:JSONEncoder = new JSONEncoder( o ); + return encoder.getString(); + + } + + /** + * Decodes a JSON string into a native object. + * + * @param s The JSON string representing the object + * @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 ):* { + + var decoder:JSONDecoder = new JSONDecoder( s ) + return decoder.getValue(); + + } + + } + }
\ No newline at end of file diff --git a/webcam/com/adobe/serialization/json/JSONDecoder.as b/webcam/com/adobe/serialization/json/JSONDecoder.as index be06317..833438d 100644 --- a/webcam/com/adobe/serialization/json/JSONDecoder.as +++ b/webcam/com/adobe/serialization/json/JSONDecoder.as @@ -1,218 +1,218 @@ -/*
-Adobe Systems Incorporated(r) Source Code License Agreement
-Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
-Please read this Source Code License Agreement carefully before using
-the source code.
-
-Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
-no-charge, royalty-free, irrevocable copyright license, to reproduce,
-prepare derivative works of, publicly display, publicly perform, and
-distribute this source code and such derivative works in source or
-object code form without any attribution requirements.
-
-The name "Adobe Systems Incorporated" must not be used to endorse or promote products
-derived from the source code without prior written permission.
-
-You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
-against any loss, damage, claims or lawsuits, including attorney's
-fees that arise or result from your use or distribution of the source
-code.
-
-THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
-ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
-NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
-OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF
-ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package com.adobe.serialization.json {
-
- public class JSONDecoder {
-
- /** 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
- * @langversion ActionScript 3.0
- * @playerversion Flash 9.0
- * @tiptext
- */
- public function JSONDecoder( s:String ) {
-
- tokenizer = new JSONTokenizer( s );
-
- nextToken();
- value = parseValue();
- }
-
- /**
- * 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;
- }
-
- // 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();
- } 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;
- }
-
- // 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();
- } 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 {
-
- 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;
-
- default:
- tokenizer.parseError( "Unexpected " + token.value );
-
- }
- return null;
- }
- }
-}
+/* +Adobe Systems Incorporated(r) Source Code License Agreement +Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + +Please read this Source Code License Agreement carefully before using +the source code. + +Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable copyright license, to reproduce, +prepare derivative works of, publicly display, publicly perform, and +distribute this source code and such derivative works in source or +object code form without any attribution requirements. + +The name "Adobe Systems Incorporated" must not be used to endorse or promote products +derived from the source code without prior written permission. + +You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and +against any loss, damage, claims or lawsuits, including attorney's +fees that arise or result from your use or distribution of the source +code. + +THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT +ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF +NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA +OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.serialization.json { + + public class JSONDecoder { + + /** 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 + * @langversion ActionScript 3.0 + * @playerversion Flash 9.0 + * @tiptext + */ + public function JSONDecoder( s:String ) { + + tokenizer = new JSONTokenizer( s ); + + nextToken(); + value = parseValue(); + } + + /** + * 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; + } + + // 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(); + } 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; + } + + // 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(); + } 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 { + + 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; + + default: + tokenizer.parseError( "Unexpected " + token.value ); + + } + return null; + } + } +} diff --git a/webcam/com/adobe/serialization/json/JSONEncoder.as b/webcam/com/adobe/serialization/json/JSONEncoder.as index f8b195c..f371a17 100644 --- a/webcam/com/adobe/serialization/json/JSONEncoder.as +++ b/webcam/com/adobe/serialization/json/JSONEncoder.as @@ -1,302 +1,302 @@ -/*
-Adobe Systems Incorporated(r) Source Code License Agreement
-Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
-Please read this Source Code License Agreement carefully before using
-the source code.
-
-Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
-no-charge, royalty-free, irrevocable copyright license, to reproduce,
-prepare derivative works of, publicly display, publicly perform, and
-distribute this source code and such derivative works in source or
-object code form without any attribution requirements.
-
-The name "Adobe Systems Incorporated" must not be used to endorse or promote products
-derived from the source code without prior written permission.
-
-You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
-against any loss, damage, claims or lawsuits, including attorney's
-fees that arise or result from your use or distribution of the source
-code.
-
-THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
-ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
-NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
-OR ITS SUPPLIERS 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 SOURCE CODE, 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 <code>a</code>
- */
- 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 <code>o</code>
- */
- 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" ) )
- {
- // 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 + "}";
- }
-
-
- }
-
-}
+/* +Adobe Systems Incorporated(r) Source Code License Agreement +Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + +Please read this Source Code License Agreement carefully before using +the source code. + +Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable copyright license, to reproduce, +prepare derivative works of, publicly display, publicly perform, and +distribute this source code and such derivative works in source or +object code form without any attribution requirements. + +The name "Adobe Systems Incorporated" must not be used to endorse or promote products +derived from the source code without prior written permission. + +You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and +against any loss, damage, claims or lawsuits, including attorney's +fees that arise or result from your use or distribution of the source +code. + +THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT +ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF +NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA +OR ITS SUPPLIERS 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 SOURCE CODE, 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 <code>a</code> + */ + 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 <code>o</code> + */ + 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" ) ) + { + // 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 --git a/webcam/com/adobe/serialization/json/JSONParseError.as b/webcam/com/adobe/serialization/json/JSONParseError.as index 5042b35..b8c0ecf 100644 --- a/webcam/com/adobe/serialization/json/JSONParseError.as +++ b/webcam/com/adobe/serialization/json/JSONParseError.as @@ -1,90 +1,90 @@ -/*
-Adobe Systems Incorporated(r) Source Code License Agreement
-Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
-Please read this Source Code License Agreement carefully before using
-the source code.
-
-Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
-no-charge, royalty-free, irrevocable copyright license, to reproduce,
-prepare derivative works of, publicly display, publicly perform, and
-distribute this source code and such derivative works in source or
-object code form without any attribution requirements.
-
-The name "Adobe Systems Incorporated" must not be used to endorse or promote products
-derived from the source code without prior written permission.
-
-You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
-against any loss, damage, claims or lawsuits, including attorney's
-fees that arise or result from your use or distribution of the source
-code.
-
-THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
-ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
-NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
-OR ITS SUPPLIERS 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 SOURCE CODE, 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;
- }
- }
-
+/* +Adobe Systems Incorporated(r) Source Code License Agreement +Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + +Please read this Source Code License Agreement carefully before using +the source code. + +Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable copyright license, to reproduce, +prepare derivative works of, publicly display, publicly perform, and +distribute this source code and such derivative works in source or +object code form without any attribution requirements. + +The name "Adobe Systems Incorporated" must not be used to endorse or promote products +derived from the source code without prior written permission. + +You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and +against any loss, damage, claims or lawsuits, including attorney's +fees that arise or result from your use or distribution of the source +code. + +THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT +ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF +NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA +OR ITS SUPPLIERS 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 SOURCE CODE, 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 --git a/webcam/com/adobe/serialization/json/JSONToken.as b/webcam/com/adobe/serialization/json/JSONToken.as index 54b1332..51e3714 100644 --- a/webcam/com/adobe/serialization/json/JSONToken.as +++ b/webcam/com/adobe/serialization/json/JSONToken.as @@ -1,107 +1,107 @@ -/*
-Adobe Systems Incorporated(r) Source Code License Agreement
-Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
-Please read this Source Code License Agreement carefully before using
-the source code.
-
-Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
-no-charge, royalty-free, irrevocable copyright license, to reproduce,
-prepare derivative works of, publicly display, publicly perform, and
-distribute this source code and such derivative works in source or
-object code form without any attribution requirements.
-
-The name "Adobe Systems Incorporated" must not be used to endorse or promote products
-derived from the source code without prior written permission.
-
-You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
-against any loss, damage, claims or lawsuits, including attorney's
-fees that arise or result from your use or distribution of the source
-code.
-
-THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
-ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
-NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
-OR ITS SUPPLIERS 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 SOURCE CODE, 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;
- }
-
- }
-
+/* +Adobe Systems Incorporated(r) Source Code License Agreement +Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + +Please read this Source Code License Agreement carefully before using +the source code. + +Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable copyright license, to reproduce, +prepare derivative works of, publicly display, publicly perform, and +distribute this source code and such derivative works in source or +object code form without any attribution requirements. + +The name "Adobe Systems Incorporated" must not be used to endorse or promote products +derived from the source code without prior written permission. + +You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and +against any loss, damage, claims or lawsuits, including attorney's +fees that arise or result from your use or distribution of the source +code. + +THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT +ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF +NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA +OR ITS SUPPLIERS 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 SOURCE CODE, 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 --git a/webcam/com/adobe/serialization/json/JSONTokenType.as b/webcam/com/adobe/serialization/json/JSONTokenType.as index e78173e..398a0f4 100644 --- a/webcam/com/adobe/serialization/json/JSONTokenType.as +++ b/webcam/com/adobe/serialization/json/JSONTokenType.as @@ -1,70 +1,70 @@ -/*
-Adobe Systems Incorporated(r) Source Code License Agreement
-Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
-Please read this Source Code License Agreement carefully before using
-the source code.
-
-Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
-no-charge, royalty-free, irrevocable copyright license, to reproduce,
-prepare derivative works of, publicly display, publicly perform, and
-distribute this source code and such derivative works in source or
-object code form without any attribution requirements.
-
-The name "Adobe Systems Incorporated" must not be used to endorse or promote products
-derived from the source code without prior written permission.
-
-You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
-against any loss, damage, claims or lawsuits, including attorney's
-fees that arise or result from your use or distribution of the source
-code.
-
-THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
-ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
-NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
-OR ITS SUPPLIERS 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 SOURCE CODE, 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;
-
- }
-
+/* +Adobe Systems Incorporated(r) Source Code License Agreement +Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + +Please read this Source Code License Agreement carefully before using +the source code. + +Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable copyright license, to reproduce, +prepare derivative works of, publicly display, publicly perform, and +distribute this source code and such derivative works in source or +object code form without any attribution requirements. + +The name "Adobe Systems Incorporated" must not be used to endorse or promote products +derived from the source code without prior written permission. + +You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and +against any loss, damage, claims or lawsuits, including attorney's +fees that arise or result from your use or distribution of the source +code. + +THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT +ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF +NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA +OR ITS SUPPLIERS 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 SOURCE CODE, 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; + + } + }
\ No newline at end of file diff --git a/webcam/com/adobe/serialization/json/JSONTokenizer.as b/webcam/com/adobe/serialization/json/JSONTokenizer.as index 2516446..077414d 100644 --- a/webcam/com/adobe/serialization/json/JSONTokenizer.as +++ b/webcam/com/adobe/serialization/json/JSONTokenizer.as @@ -1,550 +1,550 @@ -/*
-Adobe Systems Incorporated(r) Source Code License Agreement
-Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
-Please read this Source Code License Agreement carefully before using
-the source code.
-
-Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
-no-charge, royalty-free, irrevocable copyright license, to reproduce,
-prepare derivative works of, publicly display, publicly perform, and
-distribute this source code and such derivative works in source or
-object code form without any attribution requirements.
-
-The name "Adobe Systems Incorporated" must not be used to endorse or promote products
-derived from the source code without prior written permission.
-
-You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
-against any loss, damage, claims or lawsuits, including attorney's
-fees that arise or result from your use or distribution of the source
-code.
-
-THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
-ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
-NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
-OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF
-ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package com.adobe.serialization.json {
-
- public class JSONTokenizer {
-
- /** 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;
-
- /**
- * 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 ) {
- jsonString = s;
- 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 '"': // 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 {
- // the token for the string we'll try to read
- var token:JSONToken = new JSONToken();
- token.type = JSONTokenType.STRING;
-
- // the string to store the string we'll try to read
- var string:String = "";
-
- // advance past the first "
- nextChar();
-
- while ( ch != '"' && ch != '' ) {
-
- // unescape the escape sequences in the string
- if ( ch == '\\' ) {
-
- // get the next character so we know what
- // to unescape
- nextChar();
-
- switch ( ch ) {
-
- case '"': // quotation mark
- string += '"';
- break;
-
- case '/': // solidus
- string += "/";
- break;
-
- case '\\': // reverse solidus
- string += '\\';
- break;
-
- case 'b': // bell
- string += '\b';
- break;
-
- case 'f': // form feed
- string += '\f';
- break;
-
- case 'n': // newline
- string += '\n';
- break;
-
- case 'r': // carriage return
- string += '\r';
- break;
-
- case 't': // horizontal tab
- string += '\t'
- break;
-
- case 'u':
- // convert a unicode escape sequence
- // to it's character value - expecting
- // 4 hex digits
-
- // save the characters as a string we'll convert to an int
- var hexValue:String = "";
-
- // try to find 4 hex characters
- for ( var i:int = 0; i < 4; i++ ) {
- // get the next character and determine
- // if it's a valid hex digit or not
- if ( !isHexDigit( nextChar() ) ) {
- parseError( " Excepted a hex digit, but found: " + ch );
- }
- // valid, add it to the value
- hexValue += ch;
- }
-
- // convert hexValue to an integer, and use that
- // integrer value to create a character to add
- // to our string.
- string += String.fromCharCode( parseInt( hexValue, 16 ) );
-
- break;
-
- default:
- // couldn't unescape the sequence, so just
- // pass it through
- string += '\\' + ch;
-
- }
-
- } else {
- // didn't have to unescape, so add the character to the string
- string += ch;
-
- }
-
- // move to the next character
- nextChar();
-
- }
-
- // we read past the end of the string without closing it, which
- // is a parse error
- if ( ch == '' ) {
- parseError( "Unterminated string literal" );
- }
-
- // move past the closing " in the input string
- nextChar();
-
- // attach to the string to the token so we can return it
- token.value = string;
-
- return token;
- }
-
- /**
- * 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 token for the number we'll try to read
- var token:JSONToken = new JSONToken();
- token.type = JSONTokenType.NUMBER;
-
- // 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" );
- }
- }
- 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 ) ) {
- 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 {
- skipWhite();
- skipComments();
- skipWhite();
- }
-
- /**
- * 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 {
- return ( ch == ' ' || ch == '\t' || ch == '\n' );
- }
-
- /**
- * 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 digit [0-9].
- *
- * @return True if the character passed in is a digit
- */
- private function isHexDigit( ch:String ):Boolean {
- // get the uppercase value of ch so we only have
- // to compare the value between 'A' and 'F'
- var uc:String = ch.toUpperCase();
-
- // a hex digit is a digit of A-F, inclusive ( using
- // our uppercase constraint )
- return ( isDigit( ch ) || ( uc >= 'A' && uc <= '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 );
- }
- }
-
-}
+/* +Adobe Systems Incorporated(r) Source Code License Agreement +Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + +Please read this Source Code License Agreement carefully before using +the source code. + +Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable copyright license, to reproduce, +prepare derivative works of, publicly display, publicly perform, and +distribute this source code and such derivative works in source or +object code form without any attribution requirements. + +The name "Adobe Systems Incorporated" must not be used to endorse or promote products +derived from the source code without prior written permission. + +You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and +against any loss, damage, claims or lawsuits, including attorney's +fees that arise or result from your use or distribution of the source +code. + +THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT +ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF +NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA +OR ITS SUPPLIERS 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 SOURCE CODE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.adobe.serialization.json { + + public class JSONTokenizer { + + /** 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; + + /** + * 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 ) { + jsonString = s; + 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 '"': // 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 { + // the token for the string we'll try to read + var token:JSONToken = new JSONToken(); + token.type = JSONTokenType.STRING; + + // the string to store the string we'll try to read + var string:String = ""; + + // advance past the first " + nextChar(); + + while ( ch != '"' && ch != '' ) { + + // unescape the escape sequences in the string + if ( ch == '\\' ) { + + // get the next character so we know what + // to unescape + nextChar(); + + switch ( ch ) { + + case '"': // quotation mark + string += '"'; + break; + + case '/': // solidus + string += "/"; + break; + + case '\\': // reverse solidus + string += '\\'; + break; + + case 'b': // bell + string += '\b'; + break; + + case 'f': // form feed + string += '\f'; + break; + + case 'n': // newline + string += '\n'; + break; + + case 'r': // carriage return + string += '\r'; + break; + + case 't': // horizontal tab + string += '\t' + break; + + case 'u': + // convert a unicode escape sequence + // to it's character value - expecting + // 4 hex digits + + // save the characters as a string we'll convert to an int + var hexValue:String = ""; + + // try to find 4 hex characters + for ( var i:int = 0; i < 4; i++ ) { + // get the next character and determine + // if it's a valid hex digit or not + if ( !isHexDigit( nextChar() ) ) { + parseError( " Excepted a hex digit, but found: " + ch ); + } + // valid, add it to the value + hexValue += ch; + } + + // convert hexValue to an integer, and use that + // integrer value to create a character to add + // to our string. + string += String.fromCharCode( parseInt( hexValue, 16 ) ); + + break; + + default: + // couldn't unescape the sequence, so just + // pass it through + string += '\\' + ch; + + } + + } else { + // didn't have to unescape, so add the character to the string + string += ch; + + } + + // move to the next character + nextChar(); + + } + + // we read past the end of the string without closing it, which + // is a parse error + if ( ch == '' ) { + parseError( "Unterminated string literal" ); + } + + // move past the closing " in the input string + nextChar(); + + // attach to the string to the token so we can return it + token.value = string; + + return token; + } + + /** + * 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 token for the number we'll try to read + var token:JSONToken = new JSONToken(); + token.type = JSONTokenType.NUMBER; + + // 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" ); + } + } + 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 ) ) { + 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 { + skipWhite(); + skipComments(); + skipWhite(); + } + + /** + * 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 { + return ( ch == ' ' || ch == '\t' || ch == '\n' ); + } + + /** + * 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 digit [0-9]. + * + * @return True if the character passed in is a digit + */ + private function isHexDigit( ch:String ):Boolean { + // get the uppercase value of ch so we only have + // to compare the value between 'A' and 'F' + var uc:String = ch.toUpperCase(); + + // a hex digit is a digit of A-F, inclusive ( using + // our uppercase constraint ) + return ( isDigit( ch ) || ( uc >= 'A' && uc <= '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 --git a/webcam/com/adobe/utils/ArrayUtil.as b/webcam/com/adobe/utils/ArrayUtil.as index 79f499b..c535602 100644 --- a/webcam/com/adobe/utils/ArrayUtil.as +++ b/webcam/com/adobe/utils/ArrayUtil.as @@ -1,190 +1,190 @@ -/*
- Adobe Systems Incorporated(r) Source Code License Agreement
- Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
- Please read this Source Code License Agreement carefully before using
- the source code.
-
- Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
- no-charge, royalty-free, irrevocable copyright license, to reproduce,
- prepare derivative works of, publicly display, publicly perform, and
- distribute this source code and such derivative works in source or
- object code form without any attribution requirements.
-
- The name "Adobe Systems Incorporated" must not be used to endorse or promote products
- derived from the source code without prior written permission.
-
- You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
- against any loss, damage, claims or lawsuits, including attorney's
- fees that arise or result from your use or distribution of the source
- code.
-
- THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
- ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
- NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
- OR ITS SUPPLIERS 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 SOURCE CODE, 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;
- }
- }
-}
+/* + Adobe Systems Incorporated(r) Source Code License Agreement + Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + + Please read this Source Code License Agreement carefully before using + the source code. + + Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, + no-charge, royalty-free, irrevocable copyright license, to reproduce, + prepare derivative works of, publicly display, publicly perform, and + distribute this source code and such derivative works in source or + object code form without any attribution requirements. + + The name "Adobe Systems Incorporated" must not be used to endorse or promote products + derived from the source code without prior written permission. + + You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and + against any loss, damage, claims or lawsuits, including attorney's + fees that arise or result from your use or distribution of the source + code. + + THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT + ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF + NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA + OR ITS SUPPLIERS 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 SOURCE CODE, 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 --git a/webcam/com/adobe/utils/IntUtil.as b/webcam/com/adobe/utils/IntUtil.as index 6b677ef..591edc0 100644 --- a/webcam/com/adobe/utils/IntUtil.as +++ b/webcam/com/adobe/utils/IntUtil.as @@ -1,69 +1,69 @@ -
-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;
- }
- }
-
+ +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 --git a/webcam/com/adobe/utils/NumberFormatter.as b/webcam/com/adobe/utils/NumberFormatter.as index 60b9667..53b2501 100644 --- a/webcam/com/adobe/utils/NumberFormatter.as +++ b/webcam/com/adobe/utils/NumberFormatter.as @@ -1,77 +1,77 @@ -/*
- Adobe Systems Incorporated(r) Source Code License Agreement
- Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
- Please read this Source Code License Agreement carefully before using
- the source code.
-
- Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
- no-charge, royalty-free, irrevocable copyright license, to reproduce,
- prepare derivative works of, publicly display, publicly perform, and
- distribute this source code and such derivative works in source or
- object code form without any attribution requirements.
-
- The name "Adobe Systems Incorporated" must not be used to endorse or promote products
- derived from the source code without prior written permission.
-
- You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
- against any loss, damage, claims or lawsuits, including attorney's
- fees that arise or result from your use or distribution of the source
- code.
-
- THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
- ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
- NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
- OR ITS SUPPLIERS 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 SOURCE CODE, 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;
- }
-
- }
+/* + Adobe Systems Incorporated(r) Source Code License Agreement + Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + + Please read this Source Code License Agreement carefully before using + the source code. + + Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, + no-charge, royalty-free, irrevocable copyright license, to reproduce, + prepare derivative works of, publicly display, publicly perform, and + distribute this source code and such derivative works in source or + object code form without any attribution requirements. + + The name "Adobe Systems Incorporated" must not be used to endorse or promote products + derived from the source code without prior written permission. + + You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and + against any loss, damage, claims or lawsuits, including attorney's + fees that arise or result from your use or distribution of the source + code. + + THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT + ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF + NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA + OR ITS SUPPLIERS 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 SOURCE CODE, 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 --git a/webcam/com/adobe/utils/XMLUtil.as b/webcam/com/adobe/utils/XMLUtil.as index 1a902ef..8524a0b 100644 --- a/webcam/com/adobe/utils/XMLUtil.as +++ b/webcam/com/adobe/utils/XMLUtil.as @@ -1,171 +1,171 @@ -/*
- Adobe Systems Incorporated(r) Source Code License Agreement
- Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
- Please read this Source Code License Agreement carefully before using
- the source code.
-
- Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
- no-charge, royalty-free, irrevocable copyright license, to reproduce,
- prepare derivative works of, publicly display, publicly perform, and
- distribute this source code and such derivative works in source or
- object code form without any attribution requirements.
-
- The name "Adobe Systems Incorporated" must not be used to endorse or promote products
- derived from the source code without prior written permission.
-
- You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
- against any loss, damage, claims or lawsuits, including attorney's
- fees that arise or result from your use or distribution of the source
- code.
-
- THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
- ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
- NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
- OR ITS SUPPLIERS 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 SOURCE CODE, 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;
- }
- }
+/* + Adobe Systems Incorporated(r) Source Code License Agreement + Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + + Please read this Source Code License Agreement carefully before using + the source code. + + Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, + no-charge, royalty-free, irrevocable copyright license, to reproduce, + prepare derivative works of, publicly display, publicly perform, and + distribute this source code and such derivative works in source or + object code form without any attribution requirements. + + The name "Adobe Systems Incorporated" must not be used to endorse or promote products + derived from the source code without prior written permission. + + You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and + against any loss, damage, claims or lawsuits, including attorney's + fees that arise or result from your use or distribution of the source + code. + + THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT + ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF + NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA + OR ITS SUPPLIERS 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 SOURCE CODE, 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 --git a/webcam/com/adobe/webapis/ServiceBase.as b/webcam/com/adobe/webapis/ServiceBase.as index cbd7ac8..27ffbb0 100644 --- a/webcam/com/adobe/webapis/ServiceBase.as +++ b/webcam/com/adobe/webapis/ServiceBase.as @@ -1,51 +1,51 @@ -/*
- Adobe Systems Incorporated(r) Source Code License Agreement
- Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
- Please read this Source Code License Agreement carefully before using
- the source code.
-
- Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
- no-charge, royalty-free, irrevocable copyright license, to reproduce,
- prepare derivative works of, publicly display, publicly perform, and
- distribute this source code and such derivative works in source or
- object code form without any attribution requirements.
-
- The name "Adobe Systems Incorporated" must not be used to endorse or promote products
- derived from the source code without prior written permission.
-
- You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
- against any loss, damage, claims or lawsuits, including attorney's
- fees that arise or result from your use or distribution of the source
- code.
-
- THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
- ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
- NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
- OR ITS SUPPLIERS 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 SOURCE CODE, 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()
- {
- }
-
- }
+/* + Adobe Systems Incorporated(r) Source Code License Agreement + Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + + Please read this Source Code License Agreement carefully before using + the source code. + + Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, + no-charge, royalty-free, irrevocable copyright license, to reproduce, + prepare derivative works of, publicly display, publicly perform, and + distribute this source code and such derivative works in source or + object code form without any attribution requirements. + + The name "Adobe Systems Incorporated" must not be used to endorse or promote products + derived from the source code without prior written permission. + + You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and + against any loss, damage, claims or lawsuits, including attorney's + fees that arise or result from your use or distribution of the source + code. + + THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT + ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF + NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA + OR ITS SUPPLIERS 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 SOURCE CODE, 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 --git a/webcam/com/adobe/webapis/URLLoaderBase.as b/webcam/com/adobe/webapis/URLLoaderBase.as index dad2b2c..41e7b33 100644 --- a/webcam/com/adobe/webapis/URLLoaderBase.as +++ b/webcam/com/adobe/webapis/URLLoaderBase.as @@ -1,111 +1,111 @@ -/*
- Adobe Systems Incorporated(r) Source Code License Agreement
- Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
- Please read this Source Code License Agreement carefully before using
- the source code.
-
- Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
- no-charge, royalty-free, irrevocable copyright license, to reproduce,
- prepare derivative works of, publicly display, publicly perform, and
- distribute this source code and such derivative works in source or
- object code form without any attribution requirements.
-
- The name "Adobe Systems Incorporated" must not be used to endorse or promote products
- derived from the source code without prior written permission.
-
- You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
- against any loss, damage, claims or lawsuits, including attorney's
- fees that arise or result from your use or distribution of the source
- code.
-
- THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
- ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
- NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
- OR ITS SUPPLIERS 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 SOURCE CODE, 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);
- }
- }
+/* + Adobe Systems Incorporated(r) Source Code License Agreement + Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + + Please read this Source Code License Agreement carefully before using + the source code. + + Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, + no-charge, royalty-free, irrevocable copyright license, to reproduce, + prepare derivative works of, publicly display, publicly perform, and + distribute this source code and such derivative works in source or + object code form without any attribution requirements. + + The name "Adobe Systems Incorporated" must not be used to endorse or promote products + derived from the source code without prior written permission. + + You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and + against any loss, damage, claims or lawsuits, including attorney's + fees that arise or result from your use or distribution of the source + code. + + THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT + ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF + NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA + OR ITS SUPPLIERS 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 SOURCE CODE, 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 --git a/webcam/com/adobe/webapis/events/ServiceEvent.as b/webcam/com/adobe/webapis/events/ServiceEvent.as index d83ab25..5ed5737 100644 --- a/webcam/com/adobe/webapis/events/ServiceEvent.as +++ b/webcam/com/adobe/webapis/events/ServiceEvent.as @@ -1,78 +1,78 @@ -/*
- Adobe Systems Incorporated(r) Source Code License Agreement
- Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
-
- Please read this Source Code License Agreement carefully before using
- the source code.
-
- Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
- no-charge, royalty-free, irrevocable copyright license, to reproduce,
- prepare derivative works of, publicly display, publicly perform, and
- distribute this source code and such derivative works in source or
- object code form without any attribution requirements.
-
- The name "Adobe Systems Incorporated" must not be used to endorse or promote products
- derived from the source code without prior written permission.
-
- You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
- against any loss, damage, claims or lawsuits, including attorney's
- fees that arise or result from your use or distribution of the source
- code.
-
- THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
- ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
- NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
- OR ITS SUPPLIERS 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 SOURCE CODE, 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;
- }
-
-
- }
+/* + Adobe Systems Incorporated(r) Source Code License Agreement + Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved. + + Please read this Source Code License Agreement carefully before using + the source code. + + Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive, + no-charge, royalty-free, irrevocable copyright license, to reproduce, + prepare derivative works of, publicly display, publicly perform, and + distribute this source code and such derivative works in source or + object code form without any attribution requirements. + + The name "Adobe Systems Incorporated" must not be used to endorse or promote products + derived from the source code without prior written permission. + + You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and + against any loss, damage, claims or lawsuits, including attorney's + fees that arise or result from your use or distribution of the source + code. + + THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT + ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF + NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA + OR ITS SUPPLIERS 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 SOURCE CODE, 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; + } + + + } }
\ No newline at end of file |
