e2cc03a6 by Kevin Burton

upload marks

1 parent a330b4c1
Showing 79 changed files with 4888 additions and 0 deletions
...@@ -19,6 +19,7 @@ class Actions { ...@@ -19,6 +19,7 @@ class Actions {
19 19
20 _enqueue_script('date', Tools\url('scripts/date.js', __FILE__)); 20 _enqueue_script('date', Tools\url('scripts/date.js', __FILE__));
21 _enqueue_script('jquery-datepicker', Tools\url('scripts/jquery.datePicker.js', __FILE__), Array('jquery','date')); 21 _enqueue_script('jquery-datepicker', Tools\url('scripts/jquery.datePicker.js', __FILE__), Array('jquery','date'));
22 _enqueue_script('jquery-admin-uploadify', Tools\url('uploadify/jquery.uploadify.v2.1.4.js', __FILE__), Array('jquery','swfobject'));
22 _enqueue_script('jquery-branding', Tools\url('scripts/branding.js', __FILE__), Array('jquery')); 23 _enqueue_script('jquery-branding', Tools\url('scripts/branding.js', __FILE__), Array('jquery'));
23 } 24 }
24 25
......
1 <?php
2 /*
3 Uploadify v2.1.4
4 Release Date: November 8, 2010
5
6 Copyright (c) 2010 Ronnie Garcia, Travis Nickels
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
25 */
26 $fileArray = array();
27 foreach ($_POST as $key => $value) {
28 if ($key != 'folder') {
29 if (file_exists($_SERVER['DOCUMENT_ROOT'] . $_POST['folder'] . '/' . $value)) {
30 $fileArray[$key] = $value;
31 }
32 }
33 }
34 echo json_encode($fileArray);
35 ?>
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.air.logging
34 {
35 import mx.logging.AbstractTarget;
36 import flash.filesystem.File;
37 import flash.filesystem.FileStream;
38 import flash.filesystem.FileMode;
39 import mx.logging.LogEvent;
40 import flash.system.System;
41 import flash.system.Capabilities;
42 import mx.logging.targets.LineFormattedTarget;
43 import mx.core.mx_internal;
44
45 use namespace mx_internal;
46
47 /**
48 * An Adobe AIR only class that provides a log target for the Flex logging
49 * framework, that logs files to a file on the user's system.
50 *
51 * This class will only work when running within Adobe AIR>
52 */
53 public class FileTarget extends LineFormattedTarget
54 {
55 private const DEFAULT_LOG_PATH:String = "app-storage:/application.log";
56
57 private var log:File;
58
59 public function FileTarget(logFile:File = null)
60 {
61 if(logFile != null)
62 {
63 log = logFile;
64 }
65 else
66 {
67 log = new File(DEFAULT_LOG_PATH);
68 }
69 }
70
71 public function get logURI():String
72 {
73 return log.url;
74 }
75
76 mx_internal override function internalLog(message:String):void
77 {
78 write(message);
79 }
80
81 private function write(msg:String):void
82 {
83 var fs:FileStream = new FileStream();
84 fs.open(log, FileMode.APPEND);
85 fs.writeUTFBytes(msg + "\n");
86 fs.close();
87 }
88
89 public function clear():void
90 {
91 var fs:FileStream = new FileStream();
92 fs.open(log, FileMode.WRITE);
93 fs.writeUTFBytes("");
94 fs.close();
95 }
96
97 }
98 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.crypto {
34 import flash.utils.ByteArray;
35 import flash.utils.Endian;
36 import flash.utils.describeType;
37 /**
38 * Keyed-Hashing for Message Authentication
39 * Implementation based on algorithm description at
40 * http://www.faqs.org/rfcs/rfc2104.html
41 */
42 public class HMAC
43 {
44 /**
45 * Performs the HMAC hash algorithm using byte arrays.
46 *
47 * @param secret The secret key
48 * @param message The message to hash
49 * @param algorithm Hash object to use
50 * @return A string containing the hash value of message
51 * @langversion ActionScript 3.0
52 * @playerversion Flash 8.5
53 * @tiptext
54 */
55 public static function hash( secret:String, message:String, algorithm:Object = null ):String
56 {
57 var text:ByteArray = new ByteArray();
58 var k_secret:ByteArray = new ByteArray();
59
60 text.writeUTFBytes(message);
61 k_secret.writeUTFBytes(secret);
62
63 return hashBytes(k_secret, text, algorithm);
64 }
65
66 /**
67 * Performs the HMAC hash algorithm using string.
68 *
69 * @param secret The secret key
70 * @param message The message to hash
71 * @param algorithm Hash object to use
72 * @return A string containing the hash value of message
73 * @langversion ActionScript 3.0
74 * @playerversion Flash 8.5
75 * @tiptext
76 */
77 public static function hashBytes( secret:ByteArray, message:ByteArray, algorithm:Object = null ):String
78 {
79 var ipad:ByteArray = new ByteArray();
80 var opad:ByteArray = new ByteArray();
81 var endian:String = Endian.BIG_ENDIAN;
82
83 if(algorithm == null){
84 algorithm = MD5;
85 }
86
87 if ( describeType(algorithm).@name.toString() == "com.adobe.crypto::MD5" ) {
88 endian = Endian.LITTLE_ENDIAN;
89 }
90
91 if ( secret.length > 64 ) {
92 algorithm.hashBytes(secret);
93 secret = new ByteArray();
94 secret.endian = endian;
95
96 while ( algorithm.digest.bytesAvailable != 0 ) {
97 secret.writeInt(algorithm.digest.readInt());
98 }
99 }
100
101 secret.length = 64
102 secret.position = 0;
103 for ( var x:int = 0; x < 64; x++ ) {
104 var byte:int = secret.readByte();
105 ipad.writeByte(0x36 ^ byte);
106 opad.writeByte(0x5c ^ byte);
107 }
108
109 ipad.writeBytes(message);
110 algorithm.hashBytes(ipad);
111 var tmp:ByteArray = new ByteArray();
112 tmp.endian = endian;
113
114 while ( algorithm.digest.bytesAvailable != 0 ) {
115 tmp.writeInt(algorithm.digest.readInt());
116 }
117 tmp.position = 0;
118
119 while ( tmp.bytesAvailable != 0 ) {
120 opad.writeByte(tmp.readUnsignedByte());
121 }
122 return algorithm.hashBytes( opad );
123 }
124
125 }
126
127 }
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.crypto
34 {
35 import com.adobe.utils.IntUtil;
36 import flash.utils.ByteArray;
37 import mx.utils.Base64Encoder;
38
39 /**
40 * US Secure Hash Algorithm 1 (SHA1)
41 *
42 * Implementation based on algorithm description at
43 * http://www.faqs.org/rfcs/rfc3174.html
44 */
45 public class SHA1
46 {
47 public static var digest:ByteArray;
48
49 /**
50 * Performs the SHA1 hash algorithm on a string.
51 *
52 * @param s The string to hash
53 * @return A string containing the hash value of s
54 * @langversion ActionScript 3.0
55 * @playerversion 9.0
56 * @tiptext
57 */
58 public static function hash( s:String ):String
59 {
60 var blocks:Array = createBlocksFromString( s );
61 var byteArray:ByteArray = hashBlocks( blocks );
62
63 return IntUtil.toHex( byteArray.readInt(), true )
64 + IntUtil.toHex( byteArray.readInt(), true )
65 + IntUtil.toHex( byteArray.readInt(), true )
66 + IntUtil.toHex( byteArray.readInt(), true )
67 + IntUtil.toHex( byteArray.readInt(), true );
68 }
69
70 /**
71 * Performs the SHA1 hash algorithm on a ByteArray.
72 *
73 * @param data The ByteArray data to hash
74 * @return A string containing the hash value of data
75 * @langversion ActionScript 3.0
76 * @playerversion 9.0
77 */
78 public static function hashBytes( data:ByteArray ):String
79 {
80 var blocks:Array = SHA1.createBlocksFromByteArray( data );
81 var byteArray:ByteArray = hashBlocks(blocks);
82
83 return IntUtil.toHex( byteArray.readInt(), true )
84 + IntUtil.toHex( byteArray.readInt(), true )
85 + IntUtil.toHex( byteArray.readInt(), true )
86 + IntUtil.toHex( byteArray.readInt(), true )
87 + IntUtil.toHex( byteArray.readInt(), true );
88 }
89
90 /**
91 * Performs the SHA1 hash algorithm on a string, then does
92 * Base64 encoding on the result.
93 *
94 * @param s The string to hash
95 * @return The base64 encoded hash value of s
96 * @langversion ActionScript 3.0
97 * @playerversion 9.0
98 * @tiptext
99 */
100 public static function hashToBase64( s:String ):String
101 {
102 var blocks:Array = SHA1.createBlocksFromString( s );
103 var byteArray:ByteArray = hashBlocks(blocks);
104
105 // ByteArray.toString() returns the contents as a UTF-8 string,
106 // which we can't use because certain byte sequences might trigger
107 // a UTF-8 conversion. Instead, we convert the bytes to characters
108 // one by one.
109 var charsInByteArray:String = "";
110 byteArray.position = 0;
111 for (var j:int = 0; j < byteArray.length; j++)
112 {
113 var byte:uint = byteArray.readUnsignedByte();
114 charsInByteArray += String.fromCharCode(byte);
115 }
116
117 var encoder:Base64Encoder = new Base64Encoder();
118 encoder.encode(charsInByteArray);
119 return encoder.flush();
120 }
121
122 private static function hashBlocks( blocks:Array ):ByteArray
123 {
124 // initialize the h's
125 var h0:int = 0x67452301;
126 var h1:int = 0xefcdab89;
127 var h2:int = 0x98badcfe;
128 var h3:int = 0x10325476;
129 var h4:int = 0xc3d2e1f0;
130
131 var len:int = blocks.length;
132 var w:Array = new Array( 80 );
133
134 // loop over all of the blocks
135 for ( var i:int = 0; i < len; i += 16 ) {
136
137 // 6.1.c
138 var a:int = h0;
139 var b:int = h1;
140 var c:int = h2;
141 var d:int = h3;
142 var e:int = h4;
143
144 // 80 steps to process each block
145 // TODO: unroll for faster execution, or 4 loops of
146 // 20 each to avoid the k and f function calls
147 for ( var t:int = 0; t < 80; t++ ) {
148
149 if ( t < 16 ) {
150 // 6.1.a
151 w[ t ] = blocks[ i + t ];
152 } else {
153 // 6.1.b
154 w[ t ] = IntUtil.rol( w[ t - 3 ] ^ w[ t - 8 ] ^ w[ t - 14 ] ^ w[ t - 16 ], 1 );
155 }
156
157 // 6.1.d
158 var temp:int = IntUtil.rol( a, 5 ) + f( t, b, c, d ) + e + int( w[ t ] ) + k( t );
159
160 e = d;
161 d = c;
162 c = IntUtil.rol( b, 30 );
163 b = a;
164 a = temp;
165 }
166
167 // 6.1.e
168 h0 += a;
169 h1 += b;
170 h2 += c;
171 h3 += d;
172 h4 += e;
173 }
174
175 var byteArray:ByteArray = new ByteArray();
176 byteArray.writeInt(h0);
177 byteArray.writeInt(h1);
178 byteArray.writeInt(h2);
179 byteArray.writeInt(h3);
180 byteArray.writeInt(h4);
181 byteArray.position = 0;
182
183 digest = new ByteArray();
184 digest.writeBytes(byteArray);
185 digest.position = 0;
186 return byteArray;
187 }
188
189 /**
190 * Performs the logical function based on t
191 */
192 private static function f( t:int, b:int, c:int, d:int ):int {
193 if ( t < 20 ) {
194 return ( b & c ) | ( ~b & d );
195 } else if ( t < 40 ) {
196 return b ^ c ^ d;
197 } else if ( t < 60 ) {
198 return ( b & c ) | ( b & d ) | ( c & d );
199 }
200 return b ^ c ^ d;
201 }
202
203 /**
204 * Determines the constant value based on t
205 */
206 private static function k( t:int ):int {
207 if ( t < 20 ) {
208 return 0x5a827999;
209 } else if ( t < 40 ) {
210 return 0x6ed9eba1;
211 } else if ( t < 60 ) {
212 return 0x8f1bbcdc;
213 }
214 return 0xca62c1d6;
215 }
216
217 /**
218 * Converts a ByteArray to a sequence of 16-word blocks
219 * that we'll do the processing on. Appends padding
220 * and length in the process.
221 *
222 * @param data The data to split into blocks
223 * @return An array containing the blocks into which data was split
224 */
225 private static function createBlocksFromByteArray( data:ByteArray ):Array
226 {
227 var oldPosition:int = data.position;
228 data.position = 0;
229
230 var blocks:Array = new Array();
231 var len:int = data.length * 8;
232 var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
233 for( var i:int = 0; i < len; i += 8 )
234 {
235 blocks[ i >> 5 ] |= ( data.readByte() & mask ) << ( 24 - i % 32 );
236 }
237
238 // append padding and length
239 blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
240 blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
241
242 data.position = oldPosition;
243
244 return blocks;
245 }
246
247 /**
248 * Converts a string to a sequence of 16-word blocks
249 * that we'll do the processing on. Appends padding
250 * and length in the process.
251 *
252 * @param s The string to split into blocks
253 * @return An array containing the blocks that s was split into.
254 */
255 private static function createBlocksFromString( s:String ):Array
256 {
257 var blocks:Array = new Array();
258 var len:int = s.length * 8;
259 var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
260 for( var i:int = 0; i < len; i += 8 ) {
261 blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( 24 - i % 32 );
262 }
263
264 // append padding and length
265 blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
266 blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
267 return blocks;
268 }
269
270 }
271 }
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.crypto
34 {
35 import com.adobe.utils.IntUtil;
36 import flash.utils.ByteArray;
37 import mx.utils.Base64Encoder;
38
39 /**
40 * The SHA-224 algorithm
41 *
42 * @see http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf
43 */
44 public class SHA224
45 {
46 public static var digest:ByteArray;
47
48 /**
49 * Performs the SHA224 hash algorithm on a string.
50 *
51 * @param s The string to hash
52 * @return A string containing the hash value of s
53 * @langversion ActionScript 3.0
54 * @playerversion 9.0
55 * @tiptext
56 */
57 public static function hash( s:String ):String {
58 var blocks:Array = createBlocksFromString( s );
59 var byteArray:ByteArray = hashBlocks( blocks );
60 return IntUtil.toHex( byteArray.readInt(), true )
61 + IntUtil.toHex( byteArray.readInt(), true )
62 + IntUtil.toHex( byteArray.readInt(), true )
63 + IntUtil.toHex( byteArray.readInt(), true )
64 + IntUtil.toHex( byteArray.readInt(), true )
65 + IntUtil.toHex( byteArray.readInt(), true )
66 + IntUtil.toHex( byteArray.readInt(), true );
67 }
68
69 /**
70 * Performs the SHA224 hash algorithm on a ByteArray.
71 *
72 * @param data The ByteArray data to hash
73 * @return A string containing the hash value of data
74 * @langversion ActionScript 3.0
75 * @playerversion 9.0
76 */
77 public static function hashBytes( data:ByteArray ):String
78 {
79 var blocks:Array = createBlocksFromByteArray( data );
80 var byteArray:ByteArray = hashBlocks(blocks);
81 return IntUtil.toHex( byteArray.readInt(), true )
82 + IntUtil.toHex( byteArray.readInt(), true )
83 + IntUtil.toHex( byteArray.readInt(), true )
84 + IntUtil.toHex( byteArray.readInt(), true )
85 + IntUtil.toHex( byteArray.readInt(), true )
86 + IntUtil.toHex( byteArray.readInt(), true )
87 + IntUtil.toHex( byteArray.readInt(), true );
88 }
89
90 /**
91 * Performs the SHA224 hash algorithm on a string, then does
92 * Base64 encoding on the result.
93 *
94 * @param s The string to hash
95 * @return The base64 encoded hash value of s
96 * @langversion ActionScript 3.0
97 * @playerversion 9.0
98 * @tiptext
99 */
100 public static function hashToBase64( s:String ):String
101 {
102 var blocks:Array = createBlocksFromString( s );
103 var byteArray:ByteArray = hashBlocks(blocks);
104
105 // ByteArray.toString() returns the contents as a UTF-8 string,
106 // which we can't use because certain byte sequences might trigger
107 // a UTF-8 conversion. Instead, we convert the bytes to characters
108 // one by one.
109 var charsInByteArray:String = "";
110 byteArray.position = 0;
111 for (var j:int = 0; j < byteArray.length; j++)
112 {
113 var byte:uint = byteArray.readUnsignedByte();
114 charsInByteArray += String.fromCharCode(byte);
115 }
116
117 var encoder:Base64Encoder = new Base64Encoder();
118 encoder.encode(charsInByteArray);
119 return encoder.flush();
120 }
121
122 private static function hashBlocks( blocks:Array ):ByteArray {
123 var h0:int = 0xc1059ed8;
124 var h1:int = 0x367cd507;
125 var h2:int = 0x3070dd17;
126 var h3:int = 0xf70e5939;
127 var h4:int = 0xffc00b31;
128 var h5:int = 0x68581511;
129 var h6:int = 0x64f98fa7;
130 var h7:int = 0xbefa4fa4;
131
132 var k:Array = new Array(0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2);
133
134 var len:int = blocks.length;
135 var w:Array = new Array();
136
137 // loop over all of the blocks
138 for ( var i:int = 0; i < len; i += 16 ) {
139
140 var a:int = h0;
141 var b:int = h1;
142 var c:int = h2;
143 var d:int = h3;
144 var e:int = h4;
145 var f:int = h5;
146 var g:int = h6;
147 var h:int = h7;
148
149 for(var t:int = 0; t < 64; t++) {
150
151 if ( t < 16 ) {
152 w[t] = blocks[ i + t ];
153 if(isNaN(w[t])) { w[t] = 0; }
154 } else {
155 var ws0:int = IntUtil.ror(w[t-15], 7) ^ IntUtil.ror(w[t-15], 18) ^ (w[t-15] >>> 3);
156 var ws1:int = IntUtil.ror(w[t-2], 17) ^ IntUtil.ror(w[t-2], 19) ^ (w[t-2] >>> 10);
157 w[t] = w[t-16] + ws0 + w[t-7] + ws1;
158 }
159
160 var s0:int = IntUtil.ror(a, 2) ^ IntUtil.ror(a, 13) ^ IntUtil.ror(a, 22);
161 var maj:int = (a & b) ^ (a & c) ^ (b & c);
162 var t2:int = s0 + maj;
163 var s1:int = IntUtil.ror(e, 6) ^ IntUtil.ror(e, 11) ^ IntUtil.ror(e, 25);
164 var ch:int = (e & f) ^ ((~e) & g);
165 var t1:int = h + s1 + ch + k[t] + w[t];
166
167 h = g;
168 g = f;
169 f = e;
170 e = d + t1;
171 d = c;
172 c = b;
173 b = a;
174 a = t1 + t2;
175 }
176
177 //Add this chunk's hash to result so far:
178 h0 += a;
179 h1 += b;
180 h2 += c;
181 h3 += d;
182 h4 += e;
183 h5 += f;
184 h6 += g;
185 h7 += h;
186 }
187
188 var byteArray:ByteArray = new ByteArray();
189 byteArray.writeInt(h0);
190 byteArray.writeInt(h1);
191 byteArray.writeInt(h2);
192 byteArray.writeInt(h3);
193 byteArray.writeInt(h4);
194 byteArray.writeInt(h5);
195 byteArray.writeInt(h6);
196 byteArray.position = 0;
197
198 digest = new ByteArray();
199 digest.writeBytes(byteArray);
200 digest.position = 0;
201 return byteArray;
202 }
203
204 /**
205 * Converts a ByteArray to a sequence of 16-word blocks
206 * that we'll do the processing on. Appends padding
207 * and length in the process.
208 *
209 * @param data The data to split into blocks
210 * @return An array containing the blocks into which data was split
211 */
212 private static function createBlocksFromByteArray( data:ByteArray ):Array
213 {
214 var oldPosition:int = data.position;
215 data.position = 0;
216
217 var blocks:Array = new Array();
218 var len:int = data.length * 8;
219 var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
220 for( var i:int = 0; i < len; i += 8 )
221 {
222 blocks[ i >> 5 ] |= ( data.readByte() & mask ) << ( 24 - i % 32 );
223 }
224
225 // append padding and length
226 blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
227 blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
228
229 data.position = oldPosition;
230
231 return blocks;
232 }
233
234 /**
235 * Converts a string to a sequence of 16-word blocks
236 * that we'll do the processing on. Appends padding
237 * and length in the process.
238 *
239 * @param s The string to split into blocks
240 * @return An array containing the blocks that s was split into.
241 */
242 private static function createBlocksFromString( s:String ):Array
243 {
244 var blocks:Array = new Array();
245 var len:int = s.length * 8;
246 var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
247 for( var i:int = 0; i < len; i += 8 ) {
248 blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( 24 - i % 32 );
249 }
250
251 // append padding and length
252 blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
253 blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
254 return blocks;
255 }
256 }
257 }
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.crypto
34 {
35 import com.adobe.utils.IntUtil;
36 import flash.utils.ByteArray;
37 import mx.utils.Base64Encoder;
38
39 /**
40 * The SHA-256 algorithm
41 *
42 * @see http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf
43 */
44 public class SHA256
45 {
46 public static var digest:ByteArray;
47 /**
48 * Performs the SHA256 hash algorithm on a string.
49 *
50 * @param s The string to hash
51 * @return A string containing the hash value of s
52 * @langversion ActionScript 3.0
53 * @playerversion 9.0
54 * @tiptext
55 */
56 public static function hash( s:String ):String {
57 var blocks:Array = createBlocksFromString( s );
58 var byteArray:ByteArray = hashBlocks( blocks );
59
60 return IntUtil.toHex( byteArray.readInt(), true )
61 + IntUtil.toHex( byteArray.readInt(), true )
62 + IntUtil.toHex( byteArray.readInt(), true )
63 + IntUtil.toHex( byteArray.readInt(), true )
64 + IntUtil.toHex( byteArray.readInt(), true )
65 + IntUtil.toHex( byteArray.readInt(), true )
66 + IntUtil.toHex( byteArray.readInt(), true )
67 + IntUtil.toHex( byteArray.readInt(), true );
68 }
69
70 /**
71 * Performs the SHA256 hash algorithm on a ByteArray.
72 *
73 * @param data The ByteArray data to hash
74 * @return A string containing the hash value of data
75 * @langversion ActionScript 3.0
76 * @playerversion 9.0
77 */
78 public static function hashBytes( data:ByteArray ):String
79 {
80 var blocks:Array = createBlocksFromByteArray( data );
81 var byteArray:ByteArray = hashBlocks(blocks);
82
83 return IntUtil.toHex( byteArray.readInt(), true )
84 + IntUtil.toHex( byteArray.readInt(), true )
85 + IntUtil.toHex( byteArray.readInt(), true )
86 + IntUtil.toHex( byteArray.readInt(), true )
87 + IntUtil.toHex( byteArray.readInt(), true )
88 + IntUtil.toHex( byteArray.readInt(), true )
89 + IntUtil.toHex( byteArray.readInt(), true )
90 + IntUtil.toHex( byteArray.readInt(), true );
91 }
92
93 /**
94 * Performs the SHA256 hash algorithm on a string, then does
95 * Base64 encoding on the result.
96 *
97 * @param s The string to hash
98 * @return The base64 encoded hash value of s
99 * @langversion ActionScript 3.0
100 * @playerversion 9.0
101 * @tiptext
102 */
103 public static function hashToBase64( s:String ):String
104 {
105 var blocks:Array = createBlocksFromString( s );
106 var byteArray:ByteArray = hashBlocks(blocks);
107
108 // ByteArray.toString() returns the contents as a UTF-8 string,
109 // which we can't use because certain byte sequences might trigger
110 // a UTF-8 conversion. Instead, we convert the bytes to characters
111 // one by one.
112 var charsInByteArray:String = "";
113 byteArray.position = 0;
114 for (var j:int = 0; j < byteArray.length; j++)
115 {
116 var byte:uint = byteArray.readUnsignedByte();
117 charsInByteArray += String.fromCharCode(byte);
118 }
119
120 var encoder:Base64Encoder = new Base64Encoder();
121 encoder.encode(charsInByteArray);
122 return encoder.flush();
123 }
124
125 private static function hashBlocks( blocks:Array ):ByteArray {
126 var h0:int = 0x6a09e667;
127 var h1:int = 0xbb67ae85;
128 var h2:int = 0x3c6ef372;
129 var h3:int = 0xa54ff53a;
130 var h4:int = 0x510e527f;
131 var h5:int = 0x9b05688c;
132 var h6:int = 0x1f83d9ab;
133 var h7:int = 0x5be0cd19;
134
135 var k:Array = new Array(0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2);
136
137 var len:int = blocks.length;
138 var w:Array = new Array( 64 );
139
140 // loop over all of the blocks
141 for ( var i:int = 0; i < len; i += 16 ) {
142
143 var a:int = h0;
144 var b:int = h1;
145 var c:int = h2;
146 var d:int = h3;
147 var e:int = h4;
148 var f:int = h5;
149 var g:int = h6;
150 var h:int = h7;
151
152 for(var t:int = 0; t < 64; t++) {
153
154 if ( t < 16 ) {
155 w[t] = blocks[ i + t ];
156 if(isNaN(w[t])) { w[t] = 0; }
157 } else {
158 var ws0:int = IntUtil.ror(w[t-15], 7) ^ IntUtil.ror(w[t-15], 18) ^ (w[t-15] >>> 3);
159 var ws1:int = IntUtil.ror(w[t-2], 17) ^ IntUtil.ror(w[t-2], 19) ^ (w[t-2] >>> 10);
160 w[t] = w[t-16] + ws0 + w[t-7] + ws1;
161 }
162
163 var s0:int = IntUtil.ror(a, 2) ^ IntUtil.ror(a, 13) ^ IntUtil.ror(a, 22);
164 var maj:int = (a & b) ^ (a & c) ^ (b & c);
165 var t2:int = s0 + maj;
166 var s1:int = IntUtil.ror(e, 6) ^ IntUtil.ror(e, 11) ^ IntUtil.ror(e, 25);
167 var ch:int = (e & f) ^ ((~e) & g);
168 var t1:int = h + s1 + ch + k[t] + w[t];
169
170 h = g;
171 g = f;
172 f = e;
173 e = d + t1;
174 d = c;
175 c = b;
176 b = a;
177 a = t1 + t2;
178 }
179
180 //Add this chunk's hash to result so far:
181 h0 += a;
182 h1 += b;
183 h2 += c;
184 h3 += d;
185 h4 += e;
186 h5 += f;
187 h6 += g;
188 h7 += h;
189 }
190
191 var byteArray:ByteArray = new ByteArray();
192 byteArray.writeInt(h0);
193 byteArray.writeInt(h1);
194 byteArray.writeInt(h2);
195 byteArray.writeInt(h3);
196 byteArray.writeInt(h4);
197 byteArray.writeInt(h5);
198 byteArray.writeInt(h6);
199 byteArray.writeInt(h7);
200 byteArray.position = 0;
201
202 digest = new ByteArray();
203 digest.writeBytes(byteArray);
204 digest.position = 0;
205 return byteArray;
206 }
207
208 /**
209 * Converts a ByteArray to a sequence of 16-word blocks
210 * that we'll do the processing on. Appends padding
211 * and length in the process.
212 *
213 * @param data The data to split into blocks
214 * @return An array containing the blocks into which data was split
215 */
216 private static function createBlocksFromByteArray( data:ByteArray ):Array
217 {
218 var oldPosition:int = data.position;
219 data.position = 0;
220
221 var blocks:Array = new Array();
222 var len:int = data.length * 8;
223 var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
224 for( var i:int = 0; i < len; i += 8 )
225 {
226 blocks[ i >> 5 ] |= ( data.readByte() & mask ) << ( 24 - i % 32 );
227 }
228
229 // append padding and length
230 blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
231 blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
232
233 data.position = oldPosition;
234
235 return blocks;
236 }
237
238 /**
239 * Converts a string to a sequence of 16-word blocks
240 * that we'll do the processing on. Appends padding
241 * and length in the process.
242 *
243 * @param s The string to split into blocks
244 * @return An array containing the blocks that s was split into.
245 */
246 private static function createBlocksFromString( s:String ):Array
247 {
248 var blocks:Array = new Array();
249 var len:int = s.length * 8;
250 var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
251 for( var i:int = 0; i < len; i += 8 ) {
252 blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( 24 - i % 32 );
253 }
254
255 // append padding and length
256 blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
257 blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
258 return blocks;
259 }
260 }
261 }
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.crypto
34 {
35 import mx.formatters.DateFormatter;
36 import mx.utils.Base64Encoder;
37
38 /**
39 * Web Services Security Username Token
40 *
41 * Implementation based on algorithm description at
42 * http://www.oasis-open.org/committees/wss/documents/WSS-Username-02-0223-merged.pdf
43 */
44 public class WSSEUsernameToken
45 {
46 /**
47 * Generates a WSSE Username Token.
48 *
49 * @param username The username
50 * @param password The password
51 * @param nonce A cryptographically random nonce (if null, the nonce
52 * will be generated)
53 * @param timestamp The time at which the token is generated (if null,
54 * the time will be set to the moment of execution)
55 * @return The generated token
56 * @langversion ActionScript 3.0
57 * @playerversion Flash 9.0
58 * @tiptext
59 */
60 public static function getUsernameToken(username:String, password:String, nonce:String=null, timestamp:Date=null):String
61 {
62 if (nonce == null)
63 {
64 nonce = generateNonce();
65 }
66 nonce = base64Encode(nonce);
67
68 var created:String = generateTimestamp(timestamp);
69
70 var password64:String = getBase64Digest(nonce,
71 created,
72 password);
73
74 var token:String = new String("UsernameToken Username=\"");
75 token += username + "\", " +
76 "PasswordDigest=\"" + password64 + "\", " +
77 "Nonce=\"" + nonce + "\", " +
78 "Created=\"" + created + "\"";
79 return token;
80 }
81
82 private static function generateNonce():String
83 {
84 // Math.random returns a Number between 0 and 1. We don't want our
85 // nonce to contain invalid characters (e.g. the period) so we
86 // strip them out before returning the result.
87 var s:String = Math.random().toString();
88 return s.replace(".", "");
89 }
90
91 internal static function base64Encode(s:String):String
92 {
93 var encoder:Base64Encoder = new Base64Encoder();
94 encoder.encode(s);
95 return encoder.flush();
96 }
97
98 internal static function generateTimestamp(timestamp:Date):String
99 {
100 if (timestamp == null)
101 {
102 timestamp = new Date();
103 }
104 var dateFormatter:DateFormatter = new DateFormatter();
105 dateFormatter.formatString = "YYYY-MM-DDTJJ:NN:SS"
106 return dateFormatter.format(timestamp) + "Z";
107 }
108
109 internal static function getBase64Digest(nonce:String, created:String, password:String):String
110 {
111 return SHA1.hashToBase64(nonce + created + password);
112 }
113 }
114 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.errors
34 {
35 /**
36 * This class represents an Error that is thrown when a method is called when
37 * the receiving instance is in an invalid state.
38 *
39 * For example, this may occur if a method has been called, and other properties
40 * in the instance have not been initialized properly.
41 *
42 * @langversion ActionScript 3.0
43 * @playerversion Flash 9.0
44 * @tiptext
45 *
46 */
47 public class IllegalStateError extends Error
48 {
49 /**
50 * Constructor
51 *
52 * @param message A message describing the error in detail.
53 *
54 * @langversion ActionScript 3.0
55 * @playerversion Flash 9.0
56 * @tiptext
57 */
58 public function IllegalStateError(message:String)
59 {
60 super(message);
61 }
62 }
63 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 package com.adobe.fileformats.vcard
33 {
34 public class Address
35 {
36 public var type:String;
37 public var street:String;
38 public var city:String;
39 public var state:String;
40 public var postalCode:String;
41
42 public function toString():String
43 {
44 return (street + " " + city + ", " + state + " " + postalCode);
45 }
46 }
47 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 package com.adobe.fileformats.vcard
33 {
34 public class Email
35 {
36 public var type:String;
37 public var address:String;
38 }
39 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 package com.adobe.fileformats.vcard
33 {
34 public class Phone
35 {
36 public var type:String;
37 public var number:String;
38 }
39 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 package com.adobe.fileformats.vcard
33 {
34 import flash.utils.ByteArray;
35
36 public class VCard
37 {
38 public var fullName:String;
39 public var orgs:Array;
40 public var title:String;
41 public var image:ByteArray;
42 public var phones:Array;
43 public var emails:Array;
44 public var addresses:Array;
45
46 public function VCard()
47 {
48 orgs = new Array();
49 phones = new Array();
50 emails = new Array();
51 addresses = new Array();
52 }
53 }
54 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 package com.adobe.fileformats.vcard
33 {
34 import mx.utils.Base64Decoder;
35 import mx.utils.StringUtil;
36
37 public class VCardParser
38 {
39 public static function parse(vcardStr:String):Array
40 {
41 var vcards:Array = new Array();
42 var lines:Array = vcardStr.split(/\r\n/);
43 var vcard:VCard;
44 var type:String;
45 var typeTmp:String;
46 var line:String;
47
48 for (var i:uint = 0; i < lines.length; ++i)
49 {
50 line = lines[i];
51 if (line == "BEGIN:VCARD")
52 {
53 vcard = new VCard();
54 }
55 else if (line == "END:VCARD")
56 {
57 if (vcard != null)
58 {
59 vcards.push(vcard);
60 }
61 }
62 else if(line.search(/^ORG/i) != -1)
63 {
64 var org:String = line.substring(4, line.length);
65 var orgArray:Array = org.split(";");
66 for each (var orgToken:String in orgArray)
67 {
68 if (StringUtil.trim(orgToken).length > 0)
69 {
70 vcard.orgs.push(orgToken);
71 }
72 }
73 }
74 else if(line.search(/^TITLE/i) != -1)
75 {
76 var title:String = line.substring(6, line.length);
77 vcard.title = title;
78 }
79 else if (line.search(/^FN:/i) != -1)
80 {
81 var fullName:String = line.substring(3, line.length);
82 vcard.fullName = fullName;
83 }
84 else if (line.search(/^TEL/i) != -1)
85 {
86 type = new String();
87 typeTmp = new String();
88 var phone:Phone = new Phone();
89 var number:String;
90 var phoneTokens:Array = line.split(";");
91 for each (var phoneToken:String in phoneTokens)
92 {
93 if (phoneToken.search(/^TYPE=/i) != -1)
94 {
95 if (phoneToken.indexOf(":") != -1)
96 {
97 typeTmp = phoneToken.substring(5, phoneToken.indexOf(":"));
98 number = phoneToken.substring(phoneToken.indexOf(":")+1, phoneToken.length);
99 }
100 else
101 {
102 typeTmp = phoneToken.substring(5, phoneToken.length);
103 }
104
105 typeTmp = typeTmp.toLocaleLowerCase();
106
107 if (typeTmp == "pref")
108 {
109 continue;
110 }
111 if (type.length != 0)
112 {
113 type += (" ");
114 }
115 type += typeTmp;
116 }
117 }
118 if (type.length > 0 && number != null)
119 {
120 phone.type = type;
121 phone.number = number;
122 }
123 vcard.phones.push(phone);
124 }
125 else if (line.search(/^EMAIL/i) != -1)
126 {
127 type = new String();
128 typeTmp = new String();
129 var email:Email = new Email();
130 var emailAddress:String;
131 var emailTokens:Array = line.split(";");
132 for each (var emailToken:String in emailTokens)
133 {
134 if (emailToken.search(/^TYPE=/i) != -1)
135 {
136 if (emailToken.indexOf(":") != -1)
137 {
138 typeTmp = emailToken.substring(5, emailToken.indexOf(":"));
139 emailAddress = emailToken.substring(emailToken.indexOf(":")+1, emailToken.length);
140 }
141 else
142 {
143 typeTmp = emailToken.substring(5, emailToken.length);
144 }
145
146 typeTmp = typeTmp.toLocaleLowerCase();
147
148 if (typeTmp == "pref" || typeTmp == "internet")
149 {
150 continue;
151 }
152 if (type.length != 0)
153 {
154 type += (" ");
155 }
156 type += typeTmp;
157 }
158 }
159 if (type.length > 0 && emailAddress != null)
160 {
161 email.type = type;
162 email.address = emailAddress;
163 }
164 vcard.emails.push(email);
165 }
166 else if (line.indexOf("ADR;") != -1)
167 {
168 var addressTokens:Array = line.split(";");
169 var address:Address = new Address();
170 for (var j:uint = 0; j < addressTokens.length; ++j)
171 {
172 var addressToken:String = addressTokens[j];
173 if (addressToken.search(/^home:+$/i) != -1) // For Outlook, which uses non-standard vCards.
174 {
175 address.type = "home";
176 }
177 else if (addressToken.search(/^work:+$/i) != -1) // For Outlook, which uses non-standard vCards.
178 {
179 address.type = "work";
180 }
181 if (addressToken.search(/^type=/i) != -1) // The "type" parameter is the standard way (which Address Book uses)
182 {
183 // First, remove the optional ":" character.
184 addressToken = addressToken.replace(/:/,"");
185 var addressType:String = addressToken.substring(5, addressToken.length).toLowerCase();
186 if (addressType == "pref") // Not interested in which one is preferred.
187 {
188 continue;
189 }
190 else if (addressType.indexOf("home") != -1) // home
191 {
192 addressType = "home";
193 }
194 else if (addressType.indexOf("work") != -1) // work
195 {
196 addressType = "work";
197 }
198 else if (addressType.indexOf(",") != -1) // if the comma technique is used, just use the first one
199 {
200 var typeTokens:Array = addressType.split(",");
201 for each (var typeToken:String in typeTokens)
202 {
203 if (typeToken != "pref")
204 {
205 addressType = typeToken;
206 break;
207 }
208 }
209 }
210 address.type = addressType;
211 }
212 else if (addressToken.search(/^\d/) != -1 && address.street == null)
213 {
214 address.street = addressToken.replace(/\\n/, "");
215 address.city = addressTokens[j+1];
216 address.state = addressTokens[j+2];
217 address.postalCode = addressTokens[j+3];
218 }
219 }
220 if (address.type != null && address.street != null)
221 {
222 vcard.addresses.push(address);
223 }
224
225 }
226 else if (line.search(/^PHOTO;BASE64/i) != -1)
227 {
228 var imageStr:String = new String();
229 for (var k:uint = i+1; k < lines.length; ++k)
230 {
231 imageStr += lines[k];
232 //if (lines[k].search(/.+\=$/) != -1) // Very slow in Mac due to RegEx bug
233 if (lines[k].indexOf('=') != -1)
234 {
235 var decoder:Base64Decoder = new Base64Decoder();
236 decoder.decode(imageStr);
237 vcard.image = decoder.flush();
238 break;
239 }
240 }
241 }
242 }
243 return vcards;
244 }
245 }
246 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 package com.adobe.images
33 {
34 public class BitString
35 {
36 public var len:int = 0;
37 public var val:int = 0;
38 }
39 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 package com.adobe.images
33 {
34 import flash.geom.*;
35 import flash.display.Bitmap;
36 import flash.display.BitmapData;
37 import flash.utils.ByteArray;
38
39 /**
40 * Class that converts BitmapData into a valid PNG
41 */
42 public class PNGEncoder
43 {
44 /**
45 * Created a PNG image from the specified BitmapData
46 *
47 * @param image The BitmapData that will be converted into the PNG format.
48 * @return a ByteArray representing the PNG encoded image data.
49 * @langversion ActionScript 3.0
50 * @playerversion Flash 9.0
51 * @tiptext
52 */
53 public static function encode(img:BitmapData):ByteArray {
54 // Create output byte array
55 var png:ByteArray = new ByteArray();
56 // Write PNG signature
57 png.writeUnsignedInt(0x89504e47);
58 png.writeUnsignedInt(0x0D0A1A0A);
59 // Build IHDR chunk
60 var IHDR:ByteArray = new ByteArray();
61 IHDR.writeInt(img.width);
62 IHDR.writeInt(img.height);
63 IHDR.writeUnsignedInt(0x08060000); // 32bit RGBA
64 IHDR.writeByte(0);
65 writeChunk(png,0x49484452,IHDR);
66 // Build IDAT chunk
67 var IDAT:ByteArray= new ByteArray();
68 for(var i:int=0;i < img.height;i++) {
69 // no filter
70 IDAT.writeByte(0);
71 var p:uint;
72 var j:int;
73 if ( !img.transparent ) {
74 for(j=0;j < img.width;j++) {
75 p = img.getPixel(j,i);
76 IDAT.writeUnsignedInt(
77 uint(((p&0xFFFFFF) << 8)|0xFF));
78 }
79 } else {
80 for(j=0;j < img.width;j++) {
81 p = img.getPixel32(j,i);
82 IDAT.writeUnsignedInt(
83 uint(((p&0xFFFFFF) << 8)|
84 (p>>>24)));
85 }
86 }
87 }
88 IDAT.compress();
89 writeChunk(png,0x49444154,IDAT);
90 // Build IEND chunk
91 writeChunk(png,0x49454E44,null);
92 // return PNG
93 return png;
94 }
95
96 private static var crcTable:Array;
97 private static var crcTableComputed:Boolean = false;
98
99 private static function writeChunk(png:ByteArray,
100 type:uint, data:ByteArray):void {
101 if (!crcTableComputed) {
102 crcTableComputed = true;
103 crcTable = [];
104 var c:uint;
105 for (var n:uint = 0; n < 256; n++) {
106 c = n;
107 for (var k:uint = 0; k < 8; k++) {
108 if (c & 1) {
109 c = uint(uint(0xedb88320) ^
110 uint(c >>> 1));
111 } else {
112 c = uint(c >>> 1);
113 }
114 }
115 crcTable[n] = c;
116 }
117 }
118 var len:uint = 0;
119 if (data != null) {
120 len = data.length;
121 }
122 png.writeUnsignedInt(len);
123 var p:uint = png.position;
124 png.writeUnsignedInt(type);
125 if ( data != null ) {
126 png.writeBytes(data);
127 }
128 var e:uint = png.position;
129 png.position = p;
130 c = 0xffffffff;
131 for (var i:int = 0; i < (e-p); i++) {
132 c = uint(crcTable[
133 (c ^ png.readUnsignedByte()) &
134 uint(0xff)] ^ uint(c >>> 8));
135 }
136 c = uint(c^uint(0xffffffff));
137 png.position = e;
138 png.writeUnsignedInt(c);
139 }
140 }
141 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.net
34 {
35 import flash.net.URLLoader;
36
37 /**
38 * Class that provides a dynamic implimentation of the URLLoader class.
39 *
40 * This class provides no API implimentations. However, since the class is
41 * declared as dynamic, it can be used in place of URLLoader, and allow
42 * you to dynamically attach properties to it (which URLLoader does not allow).
43 *
44 * @langversion ActionScript 3.0
45 * @playerversion Flash 9.0
46 * @tiptext
47 */
48 public dynamic class DynamicURLLoader extends URLLoader
49 {
50 public function DynamicURLLoader()
51 {
52 super();
53 }
54 }
55 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.net
34 {
35 /**
36 * The URI class cannot know about DNS aliases, virtual hosts, or
37 * symbolic links that may be involved. The application can provide
38 * an implementation of this interface to resolve the URI before the
39 * URI class makes any comparisons. For example, a web host has
40 * two aliases:
41 *
42 * <p><code>
43 * http://www.site.com/
44 * http://www.site.net/
45 * </code></p>
46 *
47 * <p>The application can provide an implementation that automatically
48 * resolves site.net to site.com before URI compares two URI objects.
49 * Only the application can know and understand the context in which
50 * the URI's are being used.</p>
51 *
52 * <p>Use the URI.resolver accessor to assign a custom resolver to
53 * the URI class. Any resolver specified is global to all instances
54 * of URI.</p>
55 *
56 * <p>URI will call this before performing URI comparisons in the
57 * URI.getRelation() and URI.getCommonParent() functions.
58 *
59 * @see URI.getRelation
60 * @see URI.getCommonParent
61 *
62 * @langversion ActionScript 3.0
63 * @playerversion Flash 9.0
64 */
65 public interface IURIResolver
66 {
67 /**
68 * Implement this method to provide custom URI resolution for
69 * your application.
70 *
71 * @langversion ActionScript 3.0
72 * @playerversion Flash 9.0
73 */
74 function resolve(uri:URI) : URI;
75 }
76 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 package com.adobe.net
33 {
34 public class MimeTypeMap
35 {
36 private var types:Array =
37 [["application/andrew-inset","ez"],
38 ["application/atom+xml","atom"],
39 ["application/mac-binhex40","hqx"],
40 ["application/mac-compactpro","cpt"],
41 ["application/mathml+xml","mathml"],
42 ["application/msword","doc"],
43 ["application/octet-stream","bin","dms","lha","lzh","exe","class","so","dll","dmg"],
44 ["application/oda","oda"],
45 ["application/ogg","ogg"],
46 ["application/pdf","pdf"],
47 ["application/postscript","ai","eps","ps"],
48 ["application/rdf+xml","rdf"],
49 ["application/smil","smi","smil"],
50 ["application/srgs","gram"],
51 ["application/srgs+xml","grxml"],
52 ["application/vnd.adobe.apollo-application-installer-package+zip","air"],
53 ["application/vnd.mif","mif"],
54 ["application/vnd.mozilla.xul+xml","xul"],
55 ["application/vnd.ms-excel","xls"],
56 ["application/vnd.ms-powerpoint","ppt"],
57 ["application/vnd.rn-realmedia","rm"],
58 ["application/vnd.wap.wbxml","wbxml"],
59 ["application/vnd.wap.wmlc","wmlc"],
60 ["application/vnd.wap.wmlscriptc","wmlsc"],
61 ["application/voicexml+xml","vxml"],
62 ["application/x-bcpio","bcpio"],
63 ["application/x-cdlink","vcd"],
64 ["application/x-chess-pgn","pgn"],
65 ["application/x-cpio","cpio"],
66 ["application/x-csh","csh"],
67 ["application/x-director","dcr","dir","dxr"],
68 ["application/x-dvi","dvi"],
69 ["application/x-futuresplash","spl"],
70 ["application/x-gtar","gtar"],
71 ["application/x-hdf","hdf"],
72 ["application/x-javascript","js"],
73 ["application/x-koan","skp","skd","skt","skm"],
74 ["application/x-latex","latex"],
75 ["application/x-netcdf","nc","cdf"],
76 ["application/x-sh","sh"],
77 ["application/x-shar","shar"],
78 ["application/x-shockwave-flash","swf"],
79 ["application/x-stuffit","sit"],
80 ["application/x-sv4cpio","sv4cpio"],
81 ["application/x-sv4crc","sv4crc"],
82 ["application/x-tar","tar"],
83 ["application/x-tcl","tcl"],
84 ["application/x-tex","tex"],
85 ["application/x-texinfo","texinfo","texi"],
86 ["application/x-troff","t","tr","roff"],
87 ["application/x-troff-man","man"],
88 ["application/x-troff-me","me"],
89 ["application/x-troff-ms","ms"],
90 ["application/x-ustar","ustar"],
91 ["application/x-wais-source","src"],
92 ["application/xhtml+xml","xhtml","xht"],
93 ["application/xml","xml","xsl"],
94 ["application/xml-dtd","dtd"],
95 ["application/xslt+xml","xslt"],
96 ["application/zip","zip"],
97 ["audio/basic","au","snd"],
98 ["audio/midi","mid","midi","kar"],
99 ["audio/mpeg","mp3","mpga","mp2"],
100 ["audio/x-aiff","aif","aiff","aifc"],
101 ["audio/x-mpegurl","m3u"],
102 ["audio/x-pn-realaudio","ram","ra"],
103 ["audio/x-wav","wav"],
104 ["chemical/x-pdb","pdb"],
105 ["chemical/x-xyz","xyz"],
106 ["image/bmp","bmp"],
107 ["image/cgm","cgm"],
108 ["image/gif","gif"],
109 ["image/ief","ief"],
110 ["image/jpeg","jpg","jpeg","jpe"],
111 ["image/png","png"],
112 ["image/svg+xml","svg"],
113 ["image/tiff","tiff","tif"],
114 ["image/vnd.djvu","djvu","djv"],
115 ["image/vnd.wap.wbmp","wbmp"],
116 ["image/x-cmu-raster","ras"],
117 ["image/x-icon","ico"],
118 ["image/x-portable-anymap","pnm"],
119 ["image/x-portable-bitmap","pbm"],
120 ["image/x-portable-graymap","pgm"],
121 ["image/x-portable-pixmap","ppm"],
122 ["image/x-rgb","rgb"],
123 ["image/x-xbitmap","xbm"],
124 ["image/x-xpixmap","xpm"],
125 ["image/x-xwindowdump","xwd"],
126 ["model/iges","igs","iges"],
127 ["model/mesh","msh","mesh","silo"],
128 ["model/vrml","wrl","vrml"],
129 ["text/calendar","ics","ifb"],
130 ["text/css","css"],
131 ["text/html","html","htm"],
132 ["text/plain","txt","asc"],
133 ["text/richtext","rtx"],
134 ["text/rtf","rtf"],
135 ["text/sgml","sgml","sgm"],
136 ["text/tab-separated-values","tsv"],
137 ["text/vnd.wap.wml","wml"],
138 ["text/vnd.wap.wmlscript","wmls"],
139 ["text/x-setext","etx"],
140 ["video/mpeg","mpg","mpeg","mpe"],
141 ["video/quicktime","mov","qt"],
142 ["video/vnd.mpegurl","m4u","mxu"],
143 ["video/x-flv","flv"],
144 ["video/x-msvideo","avi"],
145 ["video/x-sgi-movie","movie"],
146 ["x-conference/x-cooltalk","ice"]];
147
148 /**
149 * Returns the mimetype for the given extension.
150 */
151 public function getMimeType(extension:String):String
152 {
153 extension = extension.toLocaleLowerCase();
154 for each (var a:Array in types)
155 {
156 for each (var b:String in a)
157 {
158 if (b == extension)
159 {
160 return a[0];
161 }
162 }
163 }
164 return null;
165 }
166
167 /**
168 * Returns the prefered extension for the given mimetype.
169 */
170 public function getExtension(mimetype:String):String
171 {
172 mimetype = mimetype.toLocaleLowerCase();
173 for each (var a:Array in types)
174 {
175 if (a[0] == mimetype)
176 {
177 return a[1];
178 }
179 }
180 return null;
181 }
182
183 /**
184 * Adds a mimetype to the map. The order of the extensions matters. The most preferred should come first.
185 */
186 public function addMimeType(mimetype:String, extensions:Array):void
187 {
188 var newType:Array = [mimetype];
189 for each (var a:String in extensions)
190 {
191 newType.push(a);
192 }
193 types.push(newType);
194 }
195 }
196 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.net
34 {
35 import flash.utils.ByteArray;
36
37 /**
38 * This class implements an efficient lookup table for URI
39 * character escaping. This class is only needed if you
40 * create a derived class of URI to handle custom URI
41 * syntax. This class is used internally by URI.
42 *
43 * @langversion ActionScript 3.0
44 * @playerversion Flash 9.0*
45 */
46 public class URIEncodingBitmap extends ByteArray
47 {
48 /**
49 * Constructor. Creates an encoding bitmap using the given
50 * string of characters as the set of characters that need
51 * to be URI escaped.
52 *
53 * @langversion ActionScript 3.0
54 * @playerversion Flash 9.0
55 */
56 public function URIEncodingBitmap(charsToEscape:String) : void
57 {
58 var i:int;
59 var data:ByteArray = new ByteArray();
60
61 // Initialize our 128 bits (16 bytes) to zero
62 for (i = 0; i < 16; i++)
63 this.writeByte(0);
64
65 data.writeUTFBytes(charsToEscape);
66 data.position = 0;
67
68 while (data.bytesAvailable)
69 {
70 var c:int = data.readByte();
71
72 if (c > 0x7f)
73 continue; // only escape low bytes
74
75 var enc:int;
76 this.position = (c >> 3);
77 enc = this.readByte();
78 enc |= 1 << (c & 0x7);
79 this.position = (c >> 3);
80 this.writeByte(enc);
81 }
82 }
83
84 /**
85 * Based on the data table contained in this object, check
86 * if the given character should be escaped.
87 *
88 * @param char the character to be escaped. Only the first
89 * character in the string is used. Any other characters
90 * are ignored.
91 *
92 * @return the integer value of the raw UTF8 character. For
93 * example, if '%' is given, the return value is 37 (0x25).
94 * If the character given does not need to be escaped, the
95 * return value is zero.
96 *
97 * @langversion ActionScript 3.0
98 * @playerversion Flash 9.0
99 */
100 public function ShouldEscape(char:String) : int
101 {
102 var data:ByteArray = new ByteArray();
103 var c:int, mask:int;
104
105 // write the character into a ByteArray so
106 // we can pull it out as a raw byte value.
107 data.writeUTFBytes(char);
108 data.position = 0;
109 c = data.readByte();
110
111 if (c & 0x80)
112 {
113 // don't escape high byte characters. It can make international
114 // URI's unreadable. We just want to escape characters that would
115 // make URI syntax ambiguous.
116 return 0;
117 }
118 else if ((c < 0x1f) || (c == 0x7f))
119 {
120 // control characters must be escaped.
121 return c;
122 }
123
124 this.position = (c >> 3);
125 mask = this.readByte();
126
127 if (mask & (1 << (c & 0x7)))
128 {
129 // we need to escape this, return the numeric value
130 // of the character
131 return c;
132 }
133 else
134 {
135 return 0;
136 }
137 }
138 }
139 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 package com.adobe.net.proxies
33 {
34 import flash.events.Event;
35 import flash.events.IOErrorEvent;
36 import flash.events.ProgressEvent;
37 import flash.net.Socket;
38
39 /**
40 * This class allows TCP socket connections through HTTP proxies in accordance with
41 * RFC 2817:
42 *
43 * ftp://ftp.rfc-editor.org/in-notes/rfc2817.txt
44 *
45 * It can also be used to make direct connections to a destination, as well. If you
46 * pass the host and port into the constructor, no proxy will be used. You can also
47 * call connect, passing in the host and the port, and if you didn't set the proxy
48 * info, a direct connection will be made. A proxy is only used after you have called
49 * the setProxyInfo function.
50 *
51 * The connection to and negotiation with the proxy is completely hidden. All the
52 * same events are thrown whether you are using a proxy or not, and the data you
53 * receive from the target server will look exact as it would if you were connected
54 * to it directly rather than through a proxy.
55 *
56 * @author Christian Cantrell
57 *
58 **/
59 public class RFC2817Socket
60 extends Socket
61 {
62 private var proxyHost:String = null;
63 private var host:String = null;
64 private var proxyPort:int = 0;
65 private var port:int = 0;
66 private var deferredEventHandlers:Object = new Object();
67 private var buffer:String = new String();
68
69 /**
70 * Construct a new RFC2817Socket object. If you pass in the host and the port,
71 * no proxy will be used. If you want to use a proxy, instantiate with no
72 * arguments, call setProxyInfo, then call connect.
73 **/
74 public function RFC2817Socket(host:String = null, port:int = 0)
75 {
76 super(host, port);
77 }
78
79 /**
80 * Set the proxy host and port number. Your connection will only proxied if
81 * this function has been called.
82 **/
83 public function setProxyInfo(host:String, port:int):void
84 {
85 this.proxyHost = host;
86 this.proxyPort = port;
87
88 var deferredSocketDataHandler:Object = this.deferredEventHandlers[ProgressEvent.SOCKET_DATA];
89 var deferredConnectHandler:Object = this.deferredEventHandlers[Event.CONNECT];
90
91 if (deferredSocketDataHandler != null)
92 {
93 super.removeEventListener(ProgressEvent.SOCKET_DATA, deferredSocketDataHandler.listener, deferredSocketDataHandler.useCapture);
94 }
95
96 if (deferredConnectHandler != null)
97 {
98 super.removeEventListener(Event.CONNECT, deferredConnectHandler.listener, deferredConnectHandler.useCapture);
99 }
100 }
101
102 /**
103 * Connect to the specified host over the specified port. If you want your
104 * connection proxied, call the setProxyInfo function first.
105 **/
106 public override function connect(host:String, port:int):void
107 {
108 if (this.proxyHost == null)
109 {
110 this.redirectConnectEvent();
111 this.redirectSocketDataEvent();
112 super.connect(host, port);
113 }
114 else
115 {
116 this.host = host;
117 this.port = port;
118 super.addEventListener(Event.CONNECT, this.onConnect);
119 super.addEventListener(ProgressEvent.SOCKET_DATA, this.onSocketData);
120 super.connect(this.proxyHost, this.proxyPort);
121 }
122 }
123
124 private function onConnect(event:Event):void
125 {
126 this.writeUTFBytes("CONNECT "+this.host+":"+this.port+" HTTP/1.1\n\n");
127 this.flush();
128 this.redirectConnectEvent();
129 }
130
131 private function onSocketData(event:ProgressEvent):void
132 {
133 while (this.bytesAvailable != 0)
134 {
135 this.buffer += this.readUTFBytes(1);
136 if (this.buffer.search(/\r?\n\r?\n$/) != -1)
137 {
138 this.checkResponse(event);
139 break;
140 }
141 }
142 }
143
144 private function checkResponse(event:ProgressEvent):void
145 {
146 var responseCode:String = this.buffer.substr(this.buffer.indexOf(" ")+1, 3);
147
148 if (responseCode.search(/^2/) == -1)
149 {
150 var ioError:IOErrorEvent = new IOErrorEvent(IOErrorEvent.IO_ERROR);
151 ioError.text = "Error connecting to the proxy ["+this.proxyHost+"] on port ["+this.proxyPort+"]: " + this.buffer;
152 this.dispatchEvent(ioError);
153 }
154 else
155 {
156 this.redirectSocketDataEvent();
157 this.dispatchEvent(new Event(Event.CONNECT));
158 if (this.bytesAvailable > 0)
159 {
160 this.dispatchEvent(event);
161 }
162 }
163 this.buffer = null;
164 }
165
166 private function redirectConnectEvent():void
167 {
168 super.removeEventListener(Event.CONNECT, onConnect);
169 var deferredEventHandler:Object = this.deferredEventHandlers[Event.CONNECT];
170 if (deferredEventHandler != null)
171 {
172 super.addEventListener(Event.CONNECT, deferredEventHandler.listener, deferredEventHandler.useCapture, deferredEventHandler.priority, deferredEventHandler.useWeakReference);
173 }
174 }
175
176 private function redirectSocketDataEvent():void
177 {
178 super.removeEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
179 var deferredEventHandler:Object = this.deferredEventHandlers[ProgressEvent.SOCKET_DATA];
180 if (deferredEventHandler != null)
181 {
182 super.addEventListener(ProgressEvent.SOCKET_DATA, deferredEventHandler.listener, deferredEventHandler.useCapture, deferredEventHandler.priority, deferredEventHandler.useWeakReference);
183 }
184 }
185
186 public override function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int=0.0, useWeakReference:Boolean=false):void
187 {
188 if (type == Event.CONNECT || type == ProgressEvent.SOCKET_DATA)
189 {
190 this.deferredEventHandlers[type] = {listener:listener,useCapture:useCapture, priority:priority, useWeakReference:useWeakReference};
191 }
192 else
193 {
194 super.addEventListener(type, listener, useCapture, priority, useWeakReference);
195 }
196 }
197 }
198 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict
2 {
3 public class Database
4 {
5 private var _name:String;
6 private var _description:String;
7
8 public function Database(name:String, description:String)
9 {
10 this._name = name;
11 this._description = description;
12 }
13
14 public function set name(name:String):void
15 {
16 this._name = name;
17 }
18
19 public function get name():String
20 {
21 return this._name;
22 }
23
24 public function set description(description:String):void
25 {
26 this._description = description;
27 }
28
29 public function get description():String
30 {
31 return this._description;
32 }
33 }
34 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict
2 {
3 public class Definition
4 {
5 private var _definition:String;
6 private var _database:String;
7 private var _term:String;
8
9 public function set definition(definition:String):void
10 {
11 this._definition = definition;
12 }
13
14 public function get definition():String
15 {
16 return this._definition;
17 }
18
19 public function set database(database:String):void
20 {
21 this._database = database;
22 }
23
24 public function get database():String
25 {
26 return this._database;
27 }
28
29 public function set term(term:String):void
30 {
31 this._term = term;
32 }
33
34 public function get term():String
35 {
36 return this._term;
37 }
38 }
39 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict
2 {
3 import com.adobe.protocols.dict.events.*;
4 import com.adobe.protocols.dict.util.*;
5
6 import flash.events.Event;
7 import flash.events.EventDispatcher;
8 import flash.events.IOErrorEvent;
9 import flash.events.ProgressEvent;
10 import flash.events.SecurityErrorEvent;
11 import flash.net.Socket;
12 import mx.rpc.http.HTTPService;
13 import mx.rpc.events.ResultEvent;
14 import mx.rpc.events.FaultEvent;
15 import flash.xml.XMLNode;
16 import mx.utils.StringUtil;
17
18 public class Dict
19 extends EventDispatcher
20 {
21 // Event type names.
22 public static var CONNECTED:String = "connected";
23 public static var DISCONNECTED:String = "disconnected";
24 public static var IO_ERROR:String = IOErrorEvent.IO_ERROR;
25 public static var ERROR:String = "error";
26 public static var SERVERS:String = "servers";
27 public static var DATABASES:String = "databases";
28 public static var MATCH_STRATEGIES:String = "matchStrategies";
29 public static var DEFINITION:String = "definition";
30 public static var DEFINITION_HEADER:String = "definitionHeader";
31 public static var MATCH:String = "match";
32 public static var NO_MATCH:String = "noMatch";
33
34 public static var FIRST_MATCH:uint = 0;
35 public static var ALL_DATABASES:uint = 1;
36
37 private var socket:SocketHelper;
38
39 private var dbShortList:Boolean;
40
41 public function Dict()
42 {
43 this.socket = new SocketHelper();
44 this.socket.addEventListener(Event.CONNECT, connected);
45 this.socket.addEventListener(Event.CLOSE, disconnected);
46 this.socket.addEventListener(SocketHelper.COMPLETE_RESPONSE, incomingData);
47 this.socket.addEventListener(IOErrorEvent.IO_ERROR, ioError);
48 this.socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityError);
49 }
50
51 public function connect(server:String, port:uint = 2628):void
52 {
53 if (this.socket.connected)
54 {
55 this.socket.close();
56 }
57 this.socket.connect(server, port);
58 }
59
60 public function connectThroughProxy(proxyServer:String,
61 proxyPort:int,
62 server:String,
63 port:uint = 2628):void
64 {
65 if (this.socket.connected)
66 {
67 this.socket.close();
68 }
69 this.socket.setProxyInfo(proxyServer, proxyPort);
70 this.socket.connect(server, port);
71 }
72
73 public function disconnect():void
74 {
75 this.socket.close();
76 this.disconnected(null);
77 }
78
79 public function getServers():void
80 {
81 var http:HTTPService = new HTTPService();
82 http.url = "http://luetzschena-stahmeln.de/dictd/xmllist.php";
83 http.addEventListener(ResultEvent.RESULT, incomingServerXML);
84 http.addEventListener(FaultEvent.FAULT, httpError);
85 http.resultFormat = HTTPService.RESULT_FORMAT_E4X;
86 http.send();
87 }
88
89 public function getDatabases(shortList:Boolean=true):void
90 {
91 this.dbShortList = shortList;
92 this.socket.writeUTFBytes("show db\r\n");
93 this.socket.flush();
94 }
95
96 public function getMatchStrategies():void
97 {
98 this.socket.writeUTFBytes("show strat\r\n");
99 this.socket.flush();
100 }
101
102 public function match(database:String, term:String, scope:String="prefix"):void
103 {
104 this.socket.writeUTFBytes("match " + database + " " + scope + " \"" + term + "\"\r\n");
105 this.socket.flush();
106 }
107
108 public function define(database:String, term:String):void
109 {
110 this.socket.writeUTFBytes("define " + database + " \"" + term + "\"\r\n");
111 this.socket.flush();
112 }
113
114 public function lookup(term:String, scope:uint):void
115 {
116 var flag:String;
117 if (scope == Dict.ALL_DATABASES)
118 {
119 flag = "*";
120 }
121 else if (scope == Dict.FIRST_MATCH)
122 {
123 flag = "!";
124 }
125 this.socket.writeUTFBytes("define " + flag + " \"" + term + "\"\r\n");
126 this.socket.flush();
127 }
128
129 //// Private functions ////
130
131 private function connected(event:Event):void
132 {
133 // Wait to dispatch an event until we get the 220 response.
134 }
135
136 private function disconnected(event:Event):void
137 {
138 dispatchEvent(new DisconnectedEvent());
139 }
140
141 private function incomingServerXML(event:ResultEvent):void
142 {
143 var dictd:Namespace = new Namespace("http://www.luetzschena-stahmeln.de/dictd/");
144 var result:XML = event.result as XML;
145 var server:String, description:String;
146 var servers:Array = new Array();
147 for each (var serverNode:XML in result.dictd::server)
148 {
149 server = serverNode.dictd::dictdurl;
150 description = serverNode.dictd::description;
151 if (StringUtil.trim(server).length != 0 &&
152 StringUtil.trim(description).length != 0)
153 {
154 var dServer:DictionaryServer = new DictionaryServer();
155 dServer.server = server.replace("dict://", "");
156 dServer.description = description;
157 servers.push(dServer);
158 }
159 }
160 var dEvent:DictionaryServerEvent = new DictionaryServerEvent();
161 dEvent.servers = servers;
162 dispatchEvent(dEvent);
163 }
164
165 private function incomingData(event:CompleteResponseEvent):void
166 {
167 var rawResponse:String = event.response;
168 var response:Response = this.parseRawResponse(rawResponse);
169 var responseCode:uint = response.code;
170 if (responseCode == 552) // no matches
171 {
172 throwNoMatchEvent(response);
173 }
174 else if (responseCode >= 400 && responseCode <= 599) // error
175 {
176 throwErrorEvent(response);
177 }
178 else if (responseCode == 220) // successful connection
179 {
180 dispatchEvent(new ConnectedEvent());
181 }
182 else if (responseCode == 110) // databases are being returned
183 {
184 throwDatabasesEvent(response);
185 }
186 else if (responseCode == 111) // matches strategies
187 {
188 throwMatchStrategiesEvent(response);
189 }
190 else if (responseCode == 152) // matches
191 {
192 throwMatchEvent(response);
193 }
194 else if (responseCode == 150)
195 {
196 throwDefinitionHeaderEvent(response);
197 }
198 else if (responseCode == 151)
199 {
200 throwDefinitionEvent(response);
201 }
202 }
203
204 private function ioError(event:IOErrorEvent):void
205 {
206 dispatchEvent(event);
207 }
208
209 private function httpError(event:FaultEvent):void
210 {
211 trace("httpError!");
212 }
213
214 private function securityError(event:SecurityErrorEvent):void
215 {
216 trace("security error!");
217 trace(event.text);
218 }
219
220 // Dispatch new events.
221
222 private function throwDatabasesEvent(response:Response):void
223 {
224 var databases:Array = new Array();
225 var responseArray:Array = response.body.split("\r\n");
226 for each (var line:String in responseArray)
227 {
228 var name:String = line.substring(0, line.indexOf(" "));
229 if (name == "--exit--")
230 {
231 if (this.dbShortList)
232 {
233 break;
234 }
235 continue;
236 }
237 var description:String = line.substring(line.indexOf(" ")+1, line.length).replace(/\"/g,"");
238 databases.push(new Database(name, description));
239 }
240 var event:DatabaseEvent = new DatabaseEvent();
241 event.databases = databases;
242 dispatchEvent(event);
243 }
244
245 private function throwMatchStrategiesEvent(response:Response):void
246 {
247 var strategies:Array = new Array();
248 var responseArray:Array = response.body.split("\r\n");
249 for each (var line:String in responseArray)
250 {
251 var name:String = line.substring(0, line.indexOf(" "));
252 var description:String = line.substring(line.indexOf(" ")+1, line.length).replace(/\"/g,"");
253 strategies.push(new MatchStrategy(name, description));
254 }
255 var event:MatchStrategiesEvent = new MatchStrategiesEvent();
256 event.strategies = strategies;
257 dispatchEvent(event);
258 }
259
260 private function throwMatchEvent(response:Response):void
261 {
262 var matches:Array = new Array();
263 var responseArray:Array = response.body.split("\r\n");
264 for each (var line:String in responseArray)
265 {
266 var match:String = line.substring(line.indexOf(" ")+1, line.length).replace(/\"/g,"");
267 matches.push(match);
268 }
269 var event:MatchEvent = new MatchEvent();
270 event.matches = matches;
271 dispatchEvent(event);
272 }
273
274 private function throwErrorEvent(response:Response):void
275 {
276 var event:ErrorEvent = new ErrorEvent();
277 event.code = response.code;
278 event.message = response.headerText;
279 dispatchEvent(event);
280 }
281
282 private function throwNoMatchEvent(response:Response):void
283 {
284 dispatchEvent(new NoMatchEvent());
285 }
286
287 private function throwDefinitionHeaderEvent(response:Response):void
288 {
289 var event:DefinitionHeaderEvent = new DefinitionHeaderEvent();
290 event.definitionCount = uint(response.headerText.substring(0, response.headerText.indexOf(" ")));
291 dispatchEvent(event);
292 }
293
294 private function throwDefinitionEvent(response:Response):void
295 {
296 var event:DefinitionEvent = new DefinitionEvent();
297 var def:Definition = new Definition();
298 var headerText:String = response.headerText;
299 var tokens:Array = headerText.match(/"[^"]+"/g);
300 def.term = String(tokens[0]).replace(/"/g, "");
301 def.database = String(tokens[1]).replace(/"/g, "");
302 def.definition = response.body;
303 event.definition = def;
304 dispatchEvent(event);
305 }
306
307 private function parseRawResponse(rawResponse:String):Response
308 {
309 var response:Response = new Response();
310 var fullHeader:String;
311 if (rawResponse.indexOf("\r\n") != -1)
312 {
313 fullHeader = rawResponse.substring(0, rawResponse.indexOf("\r\n"));
314 }
315 else
316 {
317 fullHeader = rawResponse;
318 }
319 var responseCodeMatch:Array = fullHeader.match(/^\d{3}/);
320 response.code = uint(responseCodeMatch[0]);
321 response.headerText = fullHeader.substring(fullHeader.indexOf(" ")+1, fullHeader.length);
322 var body:String = rawResponse.substring(rawResponse.indexOf("\r\n")+2, rawResponse.length);
323 body = body.replace(/\r\n\.\./, "\r\n.");
324 response.body = body;
325 return response;
326 }
327 }
328 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict
2 {
3 public class DictionaryServer
4 {
5 private var _server:String;
6 private var _description:String;
7
8 public function set server(server:String):void
9 {
10 this._server = server;
11 }
12
13 public function get server():String
14 {
15 return this._server;
16 }
17
18 public function set description(description:String):void
19 {
20 this._description = description;
21 }
22
23 public function get description():String
24 {
25 return this._description;
26 }
27 }
28 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict
2 {
3 public class MatchStrategy
4 {
5 private var _name:String;
6 private var _description:String;
7
8 public function MatchStrategy(name:String, description:String)
9 {
10 this._name = name;
11 this._description = description;
12 }
13
14 public function set name(name:String):void
15 {
16 this._name = name;
17 }
18
19 public function get name():String
20 {
21 return this._name;
22 }
23
24 public function set description(description:String):void
25 {
26 this._description = description;
27 }
28
29 public function get description():String
30 {
31 return this._description;
32 }
33 }
34 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict
2 {
3 public class Response
4 {
5 private var _code:uint;
6 private var _headerText:String;
7 private var _body:String;
8
9 public function set code(code:uint):void
10 {
11 this._code = code;
12 }
13
14 public function set headerText(headerText:String):void
15 {
16 this._headerText = headerText;
17 }
18
19 public function set body(body:String):void
20 {
21 this._body = body;
22 }
23
24 public function get code():uint
25 {
26 return this._code;
27 }
28
29 public function get headerText():String
30 {
31 return this._headerText;
32 }
33
34 public function get body():String
35 {
36 return this._body;
37 }
38 }
39 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict.events
2 {
3 import flash.events.Event;
4 import com.adobe.protocols.dict.Dict;
5
6 public class ConnectedEvent extends Event
7 {
8 public function ConnectedEvent()
9 {
10 super(Dict.CONNECTED);
11 }
12
13 }
14 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict.events
2 {
3 import flash.events.Event;
4 import com.adobe.protocols.dict.Dict;
5
6 public class DatabaseEvent
7 extends Event
8 {
9 private var _databases:Array;
10
11 public function DatabaseEvent()
12 {
13 super(Dict.DATABASES);
14 }
15
16 public function set databases(databases:Array):void
17 {
18 this._databases = databases;
19 }
20
21 public function get databases():Array
22 {
23 return this._databases;
24 }
25 }
26 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict.events
2 {
3 import flash.events.Event;
4 import com.adobe.protocols.dict.Dict;
5 import com.adobe.protocols.dict.Definition;
6
7 public class DefinitionEvent
8 extends Event
9 {
10 private var _definition:Definition;
11
12 public function DefinitionEvent()
13 {
14 super(Dict.DEFINITION);
15 }
16
17 public function set definition(definition:Definition):void
18 {
19 this._definition = definition;
20 }
21
22 public function get definition():Definition
23 {
24 return this._definition;
25 }
26 }
27 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict.events
2 {
3 import flash.events.Event;
4 import com.adobe.protocols.dict.Dict;
5
6 public class DefinitionHeaderEvent
7 extends Event
8 {
9 private var _definitionCount:uint;
10
11 public function DefinitionHeaderEvent()
12 {
13 super(Dict.DEFINITION_HEADER);
14 }
15
16 public function set definitionCount(definitionCount:uint):void
17 {
18 this._definitionCount = definitionCount;
19 }
20
21 public function get definitionCount():uint
22 {
23 return this._definitionCount;
24 }
25 }
26 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict.events
2 {
3 import flash.events.Event;
4 import com.adobe.protocols.dict.Dict;
5
6 public class DictionaryServerEvent
7 extends Event
8 {
9 private var _servers:Array;
10
11 public function DictionaryServerEvent()
12 {
13 super(Dict.SERVERS);
14 }
15
16 public function set servers(servers:Array):void
17 {
18 this._servers = servers;
19 }
20
21 public function get servers():Array
22 {
23 return this._servers;
24 }
25 }
26 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict.events
2 {
3 import flash.events.Event;
4 import com.adobe.protocols.dict.Dict;
5
6 public class DisconnectedEvent extends Event
7 {
8 public function DisconnectedEvent()
9 {
10 super(Dict.DISCONNECTED);
11 }
12
13 }
14 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict.events
2 {
3 import flash.events.Event;
4 import com.adobe.protocols.dict.Dict;
5
6 public class ErrorEvent
7 extends Event
8 {
9 private var _code:uint;
10 private var _message:String;
11
12 public function ErrorEvent()
13 {
14 super(Dict.ERROR);
15 }
16
17 public function set code(code:uint):void
18 {
19 this._code = code;
20 }
21
22 public function set message(message:String):void
23 {
24 this._message = message;
25 }
26
27 public function get code():uint
28 {
29 return this._code;
30 }
31
32 public function get message():String
33 {
34 return this._message;
35 }
36 }
37 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict.events
2 {
3 import flash.events.Event;
4 import com.adobe.protocols.dict.Dict;
5
6 public class MatchEvent
7 extends Event
8 {
9 private var _matches:Array;
10
11 public function MatchEvent()
12 {
13 super(Dict.MATCH);
14 }
15
16 public function set matches(matches:Array):void
17 {
18 this._matches = matches;
19 }
20
21 public function get matches():Array
22 {
23 return this._matches;
24 }
25 }
26 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict.events
2 {
3 import flash.events.Event;
4 import com.adobe.protocols.dict.Dict;
5
6 public class MatchStrategiesEvent
7 extends Event
8 {
9 private var _strategies:Array;
10
11 public function MatchStrategiesEvent()
12 {
13 super(Dict.MATCH_STRATEGIES);
14 }
15
16 public function set strategies(strategies:Array):void
17 {
18 this._strategies = strategies;
19 }
20
21 public function get strategies():Array
22 {
23 return this._strategies;
24 }
25 }
26 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict.events
2 {
3 import flash.events.Event;
4 import com.adobe.protocols.dict.Dict;
5
6 public class NoMatchEvent
7 extends Event
8 {
9 public function NoMatchEvent()
10 {
11 super(Dict.NO_MATCH);
12 }
13 }
14 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict.util
2 {
3 import flash.events.Event;
4
5 public class CompleteResponseEvent
6 extends Event
7 {
8 private var _response:String;
9
10 public function CompleteResponseEvent()
11 {
12 super(SocketHelper.COMPLETE_RESPONSE);
13 }
14
15 public function set response(response:String):void
16 {
17 this._response = response;
18 }
19
20 public function get response():String
21 {
22 return this._response;
23 }
24 }
25 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.adobe.protocols.dict.util
2 {
3 import com.adobe.net.proxies.RFC2817Socket;
4 import flash.events.ProgressEvent;
5
6 public class SocketHelper
7 extends RFC2817Socket
8 {
9 private var terminator:String = "\r\n.\r\n";
10 private var buffer:String;
11 public static var COMPLETE_RESPONSE:String = "completeResponse";
12
13 public function SocketHelper()
14 {
15 super();
16 buffer = new String();
17 addEventListener(ProgressEvent.SOCKET_DATA, incomingData);
18 }
19
20 private function incomingData(event:ProgressEvent):void
21 {
22 buffer += readUTFBytes(bytesAvailable);
23 buffer = buffer.replace(/250[^\r\n]+\r\n/, ""); // Get rid of all 250s. Don't need them.
24 var codeStr:String = buffer.substring(0, 3);
25 if (!isNaN(parseInt(codeStr)))
26 {
27 var code:uint = uint(codeStr);
28 if (code == 150 || code >= 200)
29 {
30 buffer = buffer.replace("\r\n", this.terminator);
31 }
32 }
33
34 while (buffer.indexOf(this.terminator) != -1)
35 {
36 var chunk:String = buffer.substring(0, buffer.indexOf(this.terminator));
37 buffer = buffer.substring(chunk.length + this.terminator.length, buffer.length);
38 throwResponseEvent(chunk);
39 }
40 }
41
42 private function throwResponseEvent(response:String):void
43 {
44 var responseEvent:CompleteResponseEvent = new CompleteResponseEvent();
45 responseEvent.response = response;
46 dispatchEvent(responseEvent);
47 }
48 }
49 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.serialization.json {
34
35 /**
36 * This class provides encoding and decoding of the JSON format.
37 *
38 * Example usage:
39 * <code>
40 * // create a JSON string from an internal object
41 * JSON.encode( myObject );
42 *
43 * // read a JSON string into an internal object
44 * var myObject:Object = JSON.decode( jsonString );
45 * </code>
46 */
47 public class JSON {
48
49
50 /**
51 * Encodes a object into a JSON string.
52 *
53 * @param o The object to create a JSON string for
54 * @return the JSON string representing o
55 * @langversion ActionScript 3.0
56 * @playerversion Flash 9.0
57 * @tiptext
58 */
59 public static function encode( o:Object ):String {
60
61 var encoder:JSONEncoder = new JSONEncoder( o );
62 return encoder.getString();
63
64 }
65
66 /**
67 * Decodes a JSON string into a native object.
68 *
69 * @param s The JSON string representing the object
70 * @return A native object as specified by s
71 * @throw JSONParseError
72 * @langversion ActionScript 3.0
73 * @playerversion Flash 9.0
74 * @tiptext
75 */
76 public static function decode( s:String ):* {
77
78 var decoder:JSONDecoder = new JSONDecoder( s )
79 return decoder.getValue();
80
81 }
82
83 }
84
85 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.serialization.json {
34
35 public class JSONDecoder {
36
37 /** The value that will get parsed from the JSON string */
38 private var value:*;
39
40 /** The tokenizer designated to read the JSON string */
41 private var tokenizer:JSONTokenizer;
42
43 /** The current token from the tokenizer */
44 private var token:JSONToken;
45
46 /**
47 * Constructs a new JSONDecoder to parse a JSON string
48 * into a native object.
49 *
50 * @param s The JSON string to be converted
51 * into a native object
52 * @langversion ActionScript 3.0
53 * @playerversion Flash 9.0
54 * @tiptext
55 */
56 public function JSONDecoder( s:String ) {
57
58 tokenizer = new JSONTokenizer( s );
59
60 nextToken();
61 value = parseValue();
62 }
63
64 /**
65 * Gets the internal object that was created by parsing
66 * the JSON string passed to the constructor.
67 *
68 * @return The internal object representation of the JSON
69 * string that was passed to the constructor
70 * @langversion ActionScript 3.0
71 * @playerversion Flash 9.0
72 * @tiptext
73 */
74 public function getValue():* {
75 return value;
76 }
77
78 /**
79 * Returns the next token from the tokenzier reading
80 * the JSON string
81 */
82 private function nextToken():JSONToken {
83 return token = tokenizer.getNextToken();
84 }
85
86 /**
87 * Attempt to parse an array
88 */
89 private function parseArray():Array {
90 // create an array internally that we're going to attempt
91 // to parse from the tokenizer
92 var a:Array = new Array();
93
94 // grab the next token from the tokenizer to move
95 // past the opening [
96 nextToken();
97
98 // check to see if we have an empty array
99 if ( token.type == JSONTokenType.RIGHT_BRACKET ) {
100 // we're done reading the array, so return it
101 return a;
102 }
103
104 // deal with elements of the array, and use an "infinite"
105 // loop because we could have any amount of elements
106 while ( true ) {
107 // read in the value and add it to the array
108 a.push ( parseValue() );
109
110 // after the value there should be a ] or a ,
111 nextToken();
112
113 if ( token.type == JSONTokenType.RIGHT_BRACKET ) {
114 // we're done reading the array, so return it
115 return a;
116 } else if ( token.type == JSONTokenType.COMMA ) {
117 // move past the comma and read another value
118 nextToken();
119 } else {
120 tokenizer.parseError( "Expecting ] or , but found " + token.value );
121 }
122 }
123 return null;
124 }
125
126 /**
127 * Attempt to parse an object
128 */
129 private function parseObject():Object {
130 // create the object internally that we're going to
131 // attempt to parse from the tokenizer
132 var o:Object = new Object();
133
134 // store the string part of an object member so
135 // that we can assign it a value in the object
136 var key:String
137
138 // grab the next token from the tokenizer
139 nextToken();
140
141 // check to see if we have an empty object
142 if ( token.type == JSONTokenType.RIGHT_BRACE ) {
143 // we're done reading the object, so return it
144 return o;
145 }
146
147 // deal with members of the object, and use an "infinite"
148 // loop because we could have any amount of members
149 while ( true ) {
150
151 if ( token.type == JSONTokenType.STRING ) {
152 // the string value we read is the key for the object
153 key = String( token.value );
154
155 // move past the string to see what's next
156 nextToken();
157
158 // after the string there should be a :
159 if ( token.type == JSONTokenType.COLON ) {
160
161 // move past the : and read/assign a value for the key
162 nextToken();
163 o[key] = parseValue();
164
165 // move past the value to see what's next
166 nextToken();
167
168 // after the value there's either a } or a ,
169 if ( token.type == JSONTokenType.RIGHT_BRACE ) {
170 // // we're done reading the object, so return it
171 return o;
172
173 } else if ( token.type == JSONTokenType.COMMA ) {
174 // skip past the comma and read another member
175 nextToken();
176 } else {
177 tokenizer.parseError( "Expecting } or , but found " + token.value );
178 }
179 } else {
180 tokenizer.parseError( "Expecting : but found " + token.value );
181 }
182 } else {
183 tokenizer.parseError( "Expecting string but found " + token.value );
184 }
185 }
186 return null;
187 }
188
189 /**
190 * Attempt to parse a value
191 */
192 private function parseValue():Object
193 {
194 // Catch errors when the input stream ends abruptly
195 if ( token == null )
196 {
197 tokenizer.parseError( "Unexpected end of input" );
198 }
199
200 switch ( token.type ) {
201 case JSONTokenType.LEFT_BRACE:
202 return parseObject();
203
204 case JSONTokenType.LEFT_BRACKET:
205 return parseArray();
206
207 case JSONTokenType.STRING:
208 case JSONTokenType.NUMBER:
209 case JSONTokenType.TRUE:
210 case JSONTokenType.FALSE:
211 case JSONTokenType.NULL:
212 return token.value;
213
214 default:
215 tokenizer.parseError( "Unexpected " + token.value );
216
217 }
218 return null;
219 }
220 }
221 }
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.serialization.json
34 {
35
36 import flash.utils.describeType;
37
38 public class JSONEncoder {
39
40 /** The string that is going to represent the object we're encoding */
41 private var jsonString:String;
42
43 /**
44 * Creates a new JSONEncoder.
45 *
46 * @param o The object to encode as a JSON string
47 * @langversion ActionScript 3.0
48 * @playerversion Flash 9.0
49 * @tiptext
50 */
51 public function JSONEncoder( value:* ) {
52 jsonString = convertToString( value );
53
54 }
55
56 /**
57 * Gets the JSON string from the encoder.
58 *
59 * @return The JSON string representation of the object
60 * that was passed to the constructor
61 * @langversion ActionScript 3.0
62 * @playerversion Flash 9.0
63 * @tiptext
64 */
65 public function getString():String {
66 return jsonString;
67 }
68
69 /**
70 * Converts a value to it's JSON string equivalent.
71 *
72 * @param value The value to convert. Could be any
73 * type (object, number, array, etc)
74 */
75 private function convertToString( value:* ):String {
76
77 // determine what value is and convert it based on it's type
78 if ( value is String ) {
79
80 // escape the string so it's formatted correctly
81 return escapeString( value as String );
82
83 } else if ( value is Number ) {
84
85 // only encode numbers that finate
86 return isFinite( value as Number) ? value.toString() : "null";
87
88 } else if ( value is Boolean ) {
89
90 // convert boolean to string easily
91 return value ? "true" : "false";
92
93 } else if ( value is Array ) {
94
95 // call the helper method to convert an array
96 return arrayToString( value as Array );
97
98 } else if ( value is Object && value != null ) {
99
100 // call the helper method to convert an object
101 return objectToString( value );
102 }
103 return "null";
104 }
105
106 /**
107 * Escapes a string accoding to the JSON specification.
108 *
109 * @param str The string to be escaped
110 * @return The string with escaped special characters
111 * according to the JSON specification
112 */
113 private function escapeString( str:String ):String {
114 // create a string to store the string's jsonstring value
115 var s:String = "";
116 // current character in the string we're processing
117 var ch:String;
118 // store the length in a local variable to reduce lookups
119 var len:Number = str.length;
120
121 // loop over all of the characters in the string
122 for ( var i:int = 0; i < len; i++ ) {
123
124 // examine the character to determine if we have to escape it
125 ch = str.charAt( i );
126 switch ( ch ) {
127
128 case '"': // quotation mark
129 s += "\\\"";
130 break;
131
132 //case '/': // solidus
133 // s += "\\/";
134 // break;
135
136 case '\\': // reverse solidus
137 s += "\\\\";
138 break;
139
140 case '\b': // bell
141 s += "\\b";
142 break;
143
144 case '\f': // form feed
145 s += "\\f";
146 break;
147
148 case '\n': // newline
149 s += "\\n";
150 break;
151
152 case '\r': // carriage return
153 s += "\\r";
154 break;
155
156 case '\t': // horizontal tab
157 s += "\\t";
158 break;
159
160 default: // everything else
161
162 // check for a control character and escape as unicode
163 if ( ch < ' ' ) {
164 // get the hex digit(s) of the character (either 1 or 2 digits)
165 var hexCode:String = ch.charCodeAt( 0 ).toString( 16 );
166
167 // ensure that there are 4 digits by adjusting
168 // the # of zeros accordingly.
169 var zeroPad:String = hexCode.length == 2 ? "00" : "000";
170
171 // create the unicode escape sequence with 4 hex digits
172 s += "\\u" + zeroPad + hexCode;
173 } else {
174
175 // no need to do any special encoding, just pass-through
176 s += ch;
177
178 }
179 } // end switch
180
181 } // end for loop
182
183 return "\"" + s + "\"";
184 }
185
186 /**
187 * Converts an array to it's JSON string equivalent
188 *
189 * @param a The array to convert
190 * @return The JSON string representation of <code>a</code>
191 */
192 private function arrayToString( a:Array ):String {
193 // create a string to store the array's jsonstring value
194 var s:String = "";
195
196 // loop over the elements in the array and add their converted
197 // values to the string
198 for ( var i:int = 0; i < a.length; i++ ) {
199 // when the length is 0 we're adding the first element so
200 // no comma is necessary
201 if ( s.length > 0 ) {
202 // we've already added an element, so add the comma separator
203 s += ","
204 }
205
206 // convert the value to a string
207 s += convertToString( a[i] );
208 }
209
210 // KNOWN ISSUE: In ActionScript, Arrays can also be associative
211 // objects and you can put anything in them, ie:
212 // myArray["foo"] = "bar";
213 //
214 // These properties aren't picked up in the for loop above because
215 // the properties don't correspond to indexes. However, we're
216 // sort of out luck because the JSON specification doesn't allow
217 // these types of array properties.
218 //
219 // So, if the array was also used as an associative object, there
220 // may be some values in the array that don't get properly encoded.
221 //
222 // A possible solution is to instead encode the Array as an Object
223 // but then it won't get decoded correctly (and won't be an
224 // Array instance)
225
226 // close the array and return it's string value
227 return "[" + s + "]";
228 }
229
230 /**
231 * Converts an object to it's JSON string equivalent
232 *
233 * @param o The object to convert
234 * @return The JSON string representation of <code>o</code>
235 */
236 private function objectToString( o:Object ):String
237 {
238 // create a string to store the object's jsonstring value
239 var s:String = "";
240
241 // determine if o is a class instance or a plain object
242 var classInfo:XML = describeType( o );
243 if ( classInfo.@name.toString() == "Object" )
244 {
245 // the value of o[key] in the loop below - store this
246 // as a variable so we don't have to keep looking up o[key]
247 // when testing for valid values to convert
248 var value:Object;
249
250 // loop over the keys in the object and add their converted
251 // values to the string
252 for ( var key:String in o )
253 {
254 // assign value to a variable for quick lookup
255 value = o[key];
256
257 // don't add function's to the JSON string
258 if ( value is Function )
259 {
260 // skip this key and try another
261 continue;
262 }
263
264 // when the length is 0 we're adding the first item so
265 // no comma is necessary
266 if ( s.length > 0 ) {
267 // we've already added an item, so add the comma separator
268 s += ","
269 }
270
271 s += escapeString( key ) + ":" + convertToString( value );
272 }
273 }
274 else // o is a class instance
275 {
276 // Loop over all of the variables and accessors in the class and
277 // serialize them along with their values.
278 for each ( var v:XML in classInfo..*.( name() == "variable" || name() == "accessor" ) )
279 {
280 // When the length is 0 we're adding the first item so
281 // no comma is necessary
282 if ( s.length > 0 ) {
283 // We've already added an item, so add the comma separator
284 s += ","
285 }
286
287 s += escapeString( v.@name.toString() ) + ":"
288 + convertToString( o[ v.@name ] );
289 }
290
291 }
292
293 return "{" + s + "}";
294 }
295
296
297 }
298
299 }
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.serialization.json {
34
35 /**
36 *
37 *
38 */
39 public class JSONParseError extends Error {
40
41 /** The location in the string where the error occurred */
42 private var _location:int;
43
44 /** The string in which the parse error occurred */
45 private var _text:String;
46
47 /**
48 * Constructs a new JSONParseError.
49 *
50 * @param message The error message that occured during parsing
51 * @langversion ActionScript 3.0
52 * @playerversion Flash 9.0
53 * @tiptext
54 */
55 public function JSONParseError( message:String = "", location:int = 0, text:String = "") {
56 super( message );
57 name = "JSONParseError";
58 _location = location;
59 _text = text;
60 }
61
62 /**
63 * Provides read-only access to the location variable.
64 *
65 * @return The location in the string where the error occurred
66 * @langversion ActionScript 3.0
67 * @playerversion Flash 9.0
68 * @tiptext
69 */
70 public function get location():int {
71 return _location;
72 }
73
74 /**
75 * Provides read-only access to the text variable.
76 *
77 * @return The string in which the error occurred
78 * @langversion ActionScript 3.0
79 * @playerversion Flash 9.0
80 * @tiptext
81 */
82 public function get text():String {
83 return _text;
84 }
85 }
86
87 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.serialization.json {
34
35 public class JSONToken {
36
37 private var _type:int;
38 private var _value:Object;
39
40 /**
41 * Creates a new JSONToken with a specific token type and value.
42 *
43 * @param type The JSONTokenType of the token
44 * @param value The value of the token
45 * @langversion ActionScript 3.0
46 * @playerversion Flash 9.0
47 * @tiptext
48 */
49 public function JSONToken( type:int = -1 /* JSONTokenType.UNKNOWN */, value:Object = null ) {
50 _type = type;
51 _value = value;
52 }
53
54 /**
55 * Returns the type of the token.
56 *
57 * @see com.adobe.serialization.json.JSONTokenType
58 * @langversion ActionScript 3.0
59 * @playerversion Flash 9.0
60 * @tiptext
61 */
62 public function get type():int {
63 return _type;
64 }
65
66 /**
67 * Sets the type of the token.
68 *
69 * @see com.adobe.serialization.json.JSONTokenType
70 * @langversion ActionScript 3.0
71 * @playerversion Flash 9.0
72 * @tiptext
73 */
74 public function set type( value:int ):void {
75 _type = value;
76 }
77
78 /**
79 * Gets the value of the token
80 *
81 * @see com.adobe.serialization.json.JSONTokenType
82 * @langversion ActionScript 3.0
83 * @playerversion Flash 9.0
84 * @tiptext
85 */
86 public function get value():Object {
87 return _value;
88 }
89
90 /**
91 * Sets the value of the token
92 *
93 * @see com.adobe.serialization.json.JSONTokenType
94 * @langversion ActionScript 3.0
95 * @playerversion Flash 9.0
96 * @tiptext
97 */
98 public function set value ( v:Object ):void {
99 _value = v;
100 }
101
102 }
103
104 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.serialization.json {
34
35 /**
36 * Class containing constant values for the different types
37 * of tokens in a JSON encoded string.
38 */
39 public class JSONTokenType {
40
41 public static const UNKNOWN:int = -1;
42
43 public static const COMMA:int = 0;
44
45 public static const LEFT_BRACE:int = 1;
46
47 public static const RIGHT_BRACE:int = 2;
48
49 public static const LEFT_BRACKET:int = 3;
50
51 public static const RIGHT_BRACKET:int = 4;
52
53 public static const COLON:int = 6;
54
55 public static const TRUE:int = 7;
56
57 public static const FALSE:int = 8;
58
59 public static const NULL:int = 9;
60
61 public static const STRING:int = 10;
62
63 public static const NUMBER:int = 11;
64
65 }
66
67 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.utils
34 {
35
36 /**
37 * Class that contains static utility methods for manipulating and working
38 * with Arrays.
39 *
40 * Note that all APIs assume that they are working with well formed arrays.
41 * i.e. they will only manipulate indexed values.
42 *
43 * @langversion ActionScript 3.0
44 * @playerversion Flash 9.0
45 * @tiptext
46 */
47 public class ArrayUtil
48 {
49
50 /**
51 * Determines whether the specified array contains the specified value.
52 *
53 * @param arr The array that will be checked for the specified value.
54 *
55 * @param value The object which will be searched for within the array
56 *
57 * @return True if the array contains the value, False if it does not.
58 *
59 * @langversion ActionScript 3.0
60 * @playerversion Flash 9.0
61 * @tiptext
62 */
63 public static function arrayContainsValue(arr:Array, value:Object):Boolean
64 {
65 return (arr.indexOf(value) != -1);
66 }
67
68 /**
69 * Remove all instances of the specified value from the array,
70 *
71 * @param arr The array from which the value will be removed
72 *
73 * @param value The object that will be removed from the array.
74 *
75 * @langversion ActionScript 3.0
76 * @playerversion Flash 9.0
77 * @tiptext
78 */
79 public static function removeValueFromArray(arr:Array, value:Object):void
80 {
81 var len:uint = arr.length;
82
83 for(var i:Number = len; i > -1; i--)
84 {
85 if(arr[i] === value)
86 {
87 arr.splice(i, 1);
88 }
89 }
90 }
91
92 /**
93 * Create a new array that only contains unique instances of objects
94 * in the specified array.
95 *
96 * Basically, this can be used to remove duplication object instances
97 * from an array
98 *
99 * @param arr The array which contains the values that will be used to
100 * create the new array that contains no duplicate values.
101 *
102 * @return A new array which only contains unique items from the specified
103 * array.
104 *
105 * @langversion ActionScript 3.0
106 * @playerversion Flash 9.0
107 * @tiptext
108 */
109 public static function createUniqueCopy(a:Array):Array
110 {
111 var newArray:Array = new Array();
112
113 var len:Number = a.length;
114 var item:Object;
115
116 for (var i:uint = 0; i < len; ++i)
117 {
118 item = a[i];
119
120 if(ArrayUtil.arrayContainsValue(newArray, item))
121 {
122 continue;
123 }
124
125 newArray.push(item);
126 }
127
128 return newArray;
129 }
130
131 /**
132 * Creates a copy of the specified array.
133 *
134 * Note that the array returned is a new array but the items within the
135 * array are not copies of the items in the original array (but rather
136 * references to the same items)
137 *
138 * @param arr The array that will be copies
139 *
140 * @return A new array which contains the same items as the array passed
141 * in.
142 *
143 * @langversion ActionScript 3.0
144 * @playerversion Flash 9.0
145 * @tiptext
146 */
147 public static function copyArray(arr:Array):Array
148 {
149 return arr.slice();
150 }
151
152 /**
153 * Compares two arrays and returns a boolean indicating whether the arrays
154 * contain the same values at the same indexes.
155 *
156 * @param arr1 The first array that will be compared to the second.
157 *
158 * @param arr2 The second array that will be compared to the first.
159 *
160 * @return True if the arrays contains the same values at the same indexes.
161 False if they do not.
162 *
163 * @langversion ActionScript 3.0
164 * @playerversion Flash 9.0
165 * @tiptext
166 */
167 public static function arraysAreEqual(arr1:Array, arr2:Array):Boolean
168 {
169 if(arr1.length != arr2.length)
170 {
171 return false;
172 }
173
174 var len:Number = arr1.length;
175
176 for(var i:Number = 0; i < len; i++)
177 {
178 if(arr1[i] !== arr2[i])
179 {
180 return false;
181 }
182 }
183
184 return true;
185 }
186 }
187 }
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.utils
34 {
35 import flash.utils.Dictionary;
36
37 public class DictionaryUtil
38 {
39
40 /**
41 * Returns an Array of all keys within the specified dictionary.
42 *
43 * @param d The Dictionary instance whose keys will be returned.
44 *
45 * @return Array of keys contained within the Dictionary
46 *
47 * @langversion ActionScript 3.0
48 * @playerversion Flash 9.0
49 * @tiptext
50 */
51 public static function getKeys(d:Dictionary):Array
52 {
53 var a:Array = new Array();
54
55 for (var key:Object in d)
56 {
57 a.push(key);
58 }
59
60 return a;
61 }
62
63 /**
64 * Returns an Array of all values within the specified dictionary.
65 *
66 * @param d The Dictionary instance whose values will be returned.
67 *
68 * @return Array of values contained within the Dictionary
69 *
70 * @langversion ActionScript 3.0
71 * @playerversion Flash 9.0
72 * @tiptext
73 */
74 public static function getValues(d:Dictionary):Array
75 {
76 var a:Array = new Array();
77
78 for each (var value:Object in d)
79 {
80 a.push(value);
81 }
82
83 return a;
84 }
85
86 }
87 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 package com.adobe.utils {
33
34 import flash.utils.Endian;
35
36 /**
37 * Contains reusable methods for operations pertaining
38 * to int values.
39 */
40 public class IntUtil {
41
42 /**
43 * Rotates x left n bits
44 *
45 * @langversion ActionScript 3.0
46 * @playerversion Flash 9.0
47 * @tiptext
48 */
49 public static function rol ( x:int, n:int ):int {
50 return ( x << n ) | ( x >>> ( 32 - n ) );
51 }
52
53 /**
54 * Rotates x right n bits
55 *
56 * @langversion ActionScript 3.0
57 * @playerversion Flash 9.0
58 * @tiptext
59 */
60 public static function ror ( x:int, n:int ):uint {
61 var nn:int = 32 - n;
62 return ( x << nn ) | ( x >>> ( 32 - nn ) );
63 }
64
65 /** String for quick lookup of a hex character based on index */
66 private static var hexChars:String = "0123456789abcdef";
67
68 /**
69 * Outputs the hex value of a int, allowing the developer to specify
70 * the endinaness in the process. Hex output is lowercase.
71 *
72 * @param n The int value to output as hex
73 * @param bigEndian Flag to output the int as big or little endian
74 * @return A string of length 8 corresponding to the
75 * hex representation of n ( minus the leading "0x" )
76 * @langversion ActionScript 3.0
77 * @playerversion Flash 9.0
78 * @tiptext
79 */
80 public static function toHex( n:int, bigEndian:Boolean = false ):String {
81 var s:String = "";
82
83 if ( bigEndian ) {
84 for ( var i:int = 0; i < 4; i++ ) {
85 s += hexChars.charAt( ( n >> ( ( 3 - i ) * 8 + 4 ) ) & 0xF )
86 + hexChars.charAt( ( n >> ( ( 3 - i ) * 8 ) ) & 0xF );
87 }
88 } else {
89 for ( var x:int = 0; x < 4; x++ ) {
90 s += hexChars.charAt( ( n >> ( x * 8 + 4 ) ) & 0xF )
91 + hexChars.charAt( ( n >> ( x * 8 ) ) & 0xF );
92 }
93 }
94
95 return s;
96 }
97 }
98
99 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.utils
34 {
35
36 /**
37 * Class that contains static utility methods for formatting Numbers
38 *
39 * @langversion ActionScript 3.0
40 * @playerversion Flash 9.0
41 * @tiptext
42 *
43 * @see #mx.formatters.NumberFormatter
44 */
45 public class NumberFormatter
46 {
47
48 /**
49 * Formats a number to include a leading zero if it is a single digit
50 * between -1 and 10.
51 *
52 * @param n The number that will be formatted
53 *
54 * @return A string with single digits between -1 and 10 padded with a
55 * leading zero.
56 *
57 * @langversion ActionScript 3.0
58 * @playerversion Flash 9.0
59 * @tiptext
60 */
61 public static function addLeadingZero(n:Number):String
62 {
63 var out:String = String(n);
64
65 if(n < 10 && n > -1)
66 {
67 out = "0" + out;
68 }
69
70 return out;
71 }
72
73 }
74 }
...\ No newline at end of file ...\ No newline at end of file
1 /*
2 Copyright (c) 2008, Adobe Systems Incorporated
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 * Neither the name of Adobe Systems Incorporated nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package com.adobe.utils
34 {
35
36 /**
37 * Class that contains static utility methods for manipulating Strings.
38 *
39 * @langversion ActionScript 3.0
40 * @playerversion Flash 9.0
41 * @tiptext
42 */
43 public class StringUtil
44 {
45
46
47 /**
48 * Does a case insensitive compare or two strings and returns true if
49 * they are equal.
50 *
51 * @param s1 The first string to compare.
52 *
53 * @param s2 The second string to compare.
54 *
55 * @returns A boolean value indicating whether the strings' values are
56 * equal in a case sensitive compare.
57 *
58 * @langversion ActionScript 3.0
59 * @playerversion Flash 9.0
60 * @tiptext
61 */
62 public static function stringsAreEqual(s1:String, s2:String,
63 caseSensitive:Boolean):Boolean
64 {
65 if(caseSensitive)
66 {
67 return (s1 == s2);
68 }
69 else
70 {
71 return (s1.toUpperCase() == s2.toUpperCase());
72 }
73 }
74
75 /**
76 * Removes whitespace from the front and the end of the specified
77 * string.
78 *
79 * @param input The String whose beginning and ending whitespace will
80 * will be removed.
81 *
82 * @returns A String with whitespace removed from the begining and end
83 *
84 * @langversion ActionScript 3.0
85 * @playerversion Flash 9.0
86 * @tiptext
87 */
88 public static function trim(input:String):String
89 {
90 return StringUtil.ltrim(StringUtil.rtrim(input));
91 }
92
93 /**
94 * Removes whitespace from the front of the specified string.
95 *
96 * @param input The String whose beginning whitespace will will be removed.
97 *
98 * @returns A String with whitespace removed from the begining
99 *
100 * @langversion ActionScript 3.0
101 * @playerversion Flash 9.0
102 * @tiptext
103 */
104 public static function ltrim(input:String):String
105 {
106 var size:Number = input.length;
107 for(var i:Number = 0; i < size; i++)
108 {
109 if(input.charCodeAt(i) > 32)
110 {
111 return input.substring(i);
112 }
113 }
114 return "";
115 }
116
117 /**
118 * Removes whitespace from the end of the specified string.
119 *
120 * @param input The String whose ending whitespace will will be removed.
121 *
122 * @returns A String with whitespace removed from the end
123 *
124 * @langversion ActionScript 3.0
125 * @playerversion Flash 9.0
126 * @tiptext
127 */
128 public static function rtrim(input:String):String
129 {
130 var size:Number = input.length;
131 for(var i:Number = size; i > 0; i--)
132 {
133 if(input.charCodeAt(i - 1) > 32)
134 {
135 return input.substring(0, i);
136 }
137 }
138
139 return "";
140 }
141
142 /**
143 * Determines whether the specified string begins with the spcified prefix.
144 *
145 * @param input The string that the prefix will be checked against.
146 *
147 * @param prefix The prefix that will be tested against the string.
148 *
149 * @returns True if the string starts with the prefix, false if it does not.
150 *
151 * @langversion ActionScript 3.0
152 * @playerversion Flash 9.0
153 * @tiptext
154 */
155 public static function beginsWith(input:String, prefix:String):Boolean
156 {
157 return (prefix == input.substring(0, prefix.length));
158 }
159
160 /**
161 * Determines whether the specified string ends with the spcified suffix.
162 *
163 * @param input The string that the suffic will be checked against.
164 *
165 * @param prefix The suffic that will be tested against the string.
166 *
167 * @returns True if the string ends with the suffix, false if it does not.
168 *
169 * @langversion ActionScript 3.0
170 * @playerversion Flash 9.0
171 * @tiptext
172 */
173 public static function endsWith(input:String, suffix:String):Boolean
174 {
175 return (suffix == input.substring(input.length - suffix.length));
176 }
177
178 /**
179 * Removes all instances of the remove string in the input string.
180 *
181 * @param input The string that will be checked for instances of remove
182 * string
183 *
184 * @param remove The string that will be removed from the input string.
185 *
186 * @returns A String with the remove string removed.
187 *
188 * @langversion ActionScript 3.0
189 * @playerversion Flash 9.0
190 * @tiptext
191 */
192 public static function remove(input:String, remove:String):String
193 {
194 return StringUtil.replace(input, remove, "");
195 }
196
197 /**
198 * Replaces all instances of the replace string in the input string
199 * with the replaceWith string.
200 *
201 * @param input The string that instances of replace string will be
202 * replaces with removeWith string.
203 *
204 * @param replace The string that will be replaced by instances of
205 * the replaceWith string.
206 *
207 * @param replaceWith The string that will replace instances of replace
208 * string.
209 *
210 * @returns A new String with the replace string replaced with the
211 * replaceWith string.
212 *
213 * @langversion ActionScript 3.0
214 * @playerversion Flash 9.0
215 * @tiptext
216 */
217 public static function replace(input:String, replace:String, replaceWith:String):String
218 {
219 //change to StringBuilder
220 var sb:String = new String();
221 var found:Boolean = false;
222
223 var sLen:Number = input.length;
224 var rLen:Number = replace.length;
225
226 for (var i:Number = 0; i < sLen; i++)
227 {
228 if(input.charAt(i) == replace.charAt(0))
229 {
230 found = true;
231 for(var j:Number = 0; j < rLen; j++)
232 {
233 if(!(input.charAt(i + j) == replace.charAt(j)))
234 {
235 found = false;
236 break;
237 }
238 }
239
240 if(found)
241 {
242 sb += replaceWith;
243 i = i + (rLen - 1);
244 continue;
245 }
246 }
247 sb += input.charAt(i);
248 }
249 //TODO : if the string is not found, should we return the original
250 //string?
251 return sb;
252 }
253
254 /**
255 * Specifies whether the specified string is either non-null, or contains
256 * characters (i.e. length is greater that 0)
257 *
258 * @param s The string which is being checked for a value
259 *
260 * @langversion ActionScript 3.0
261 * @playerversion Flash 9.0
262 * @tiptext
263 */
264 public static function stringHasValue(s:String):Boolean
265 {
266 //todo: this needs a unit test
267 return (s != null && s.length > 0);
268 }
269 }
270 }
...\ No newline at end of file ...\ No newline at end of file
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type