as3corelib 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. data/Gemfile +5 -0
  2. data/Gemfile.lock +28 -0
  3. data/README.textile +79 -0
  4. data/Rakefile +3 -0
  5. data/as3corelib.gemspec +23 -0
  6. data/build/build.properties +48 -0
  7. data/build/build.xml +104 -0
  8. data/examples/JSONExample/JSONExample.mxml +73 -0
  9. data/lib/as3corelib.rb +15 -0
  10. data/src/com/adobe/air/crypto/EncryptionKeyGenerator.as +313 -0
  11. data/src/com/adobe/air/filesystem/FileMonitor.as +245 -0
  12. data/src/com/adobe/air/filesystem/FileUtil.as +63 -0
  13. data/src/com/adobe/air/filesystem/VolumeMonitor.as +184 -0
  14. data/src/com/adobe/air/filesystem/events/FileMonitorEvent.as +61 -0
  15. data/src/com/adobe/air/logging/FileTarget.as +95 -0
  16. data/src/com/adobe/air/net/ResourceCache.as +165 -0
  17. data/src/com/adobe/air/net/events/ResourceCacheEvent.as +70 -0
  18. data/src/com/adobe/crypto/HMAC.as +127 -0
  19. data/src/com/adobe/crypto/MD5.as +281 -0
  20. data/src/com/adobe/crypto/MD5Stream.as +402 -0
  21. data/src/com/adobe/crypto/SHA1.as +289 -0
  22. data/src/com/adobe/crypto/SHA224.as +257 -0
  23. data/src/com/adobe/crypto/SHA256.as +261 -0
  24. data/src/com/adobe/crypto/WSSEUsernameToken.as +114 -0
  25. data/src/com/adobe/errors/IllegalStateError.as +63 -0
  26. data/src/com/adobe/fileformats/vcard/Address.as +47 -0
  27. data/src/com/adobe/fileformats/vcard/Email.as +39 -0
  28. data/src/com/adobe/fileformats/vcard/Phone.as +39 -0
  29. data/src/com/adobe/fileformats/vcard/VCard.as +54 -0
  30. data/src/com/adobe/fileformats/vcard/VCardParser.as +246 -0
  31. data/src/com/adobe/images/BitString.as +39 -0
  32. data/src/com/adobe/images/JPGEncoder.as +648 -0
  33. data/src/com/adobe/images/PNGEncoder.as +141 -0
  34. data/src/com/adobe/net/DynamicURLLoader.as +55 -0
  35. data/src/com/adobe/net/IURIResolver.as +76 -0
  36. data/src/com/adobe/net/MimeTypeMap.as +200 -0
  37. data/src/com/adobe/net/URI.as +2466 -0
  38. data/src/com/adobe/net/URIEncodingBitmap.as +139 -0
  39. data/src/com/adobe/net/proxies/RFC2817Socket.as +198 -0
  40. data/src/com/adobe/protocols/dict/Database.as +66 -0
  41. data/src/com/adobe/protocols/dict/Definition.as +71 -0
  42. data/src/com/adobe/protocols/dict/Dict.as +360 -0
  43. data/src/com/adobe/protocols/dict/DictionaryServer.as +60 -0
  44. data/src/com/adobe/protocols/dict/MatchStrategy.as +66 -0
  45. data/src/com/adobe/protocols/dict/Response.as +71 -0
  46. data/src/com/adobe/protocols/dict/events/ConnectedEvent.as +53 -0
  47. data/src/com/adobe/protocols/dict/events/DatabaseEvent.as +67 -0
  48. data/src/com/adobe/protocols/dict/events/DefinitionEvent.as +70 -0
  49. data/src/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as +69 -0
  50. data/src/com/adobe/protocols/dict/events/DictionaryServerEvent.as +69 -0
  51. data/src/com/adobe/protocols/dict/events/DisconnectedEvent.as +55 -0
  52. data/src/com/adobe/protocols/dict/events/ErrorEvent.as +80 -0
  53. data/src/com/adobe/protocols/dict/events/MatchEvent.as +67 -0
  54. data/src/com/adobe/protocols/dict/events/MatchStrategiesEvent.as +70 -0
  55. data/src/com/adobe/protocols/dict/events/NoMatchEvent.as +54 -0
  56. data/src/com/adobe/protocols/dict/util/CompleteResponseEvent.as +68 -0
  57. data/src/com/adobe/protocols/dict/util/SocketHelper.as +81 -0
  58. data/src/com/adobe/serialization/json/JSON.as +86 -0
  59. data/src/com/adobe/serialization/json/JSONDecoder.as +327 -0
  60. data/src/com/adobe/serialization/json/JSONEncoder.as +312 -0
  61. data/src/com/adobe/serialization/json/JSONParseError.as +87 -0
  62. data/src/com/adobe/serialization/json/JSONToken.as +104 -0
  63. data/src/com/adobe/serialization/json/JSONTokenType.as +69 -0
  64. data/src/com/adobe/serialization/json/JSONTokenizer.as +702 -0
  65. data/src/com/adobe/utils/ArrayUtil.as +187 -0
  66. data/src/com/adobe/utils/DateUtil.as +701 -0
  67. data/src/com/adobe/utils/DictionaryUtil.as +87 -0
  68. data/src/com/adobe/utils/IntUtil.as +99 -0
  69. data/src/com/adobe/utils/NumberFormatter.as +74 -0
  70. data/src/com/adobe/utils/StringUtil.as +239 -0
  71. data/src/com/adobe/utils/XMLUtil.as +168 -0
  72. data/src/com/adobe/webapis/ServiceBase.as +48 -0
  73. data/src/com/adobe/webapis/URLLoaderBase.as +108 -0
  74. data/src/com/adobe/webapis/events/ServiceEvent.as +82 -0
  75. data/tests/src/CoreLibTestRunner-app.xml +135 -0
  76. data/tests/src/CoreLibTestRunner.as +138 -0
  77. data/tests/src/CoreLibTestRunner.mxml +46 -0
  78. data/tests/src/com/adobe/air/crypto/EncryptionKeyGeneratorTest.as +176 -0
  79. data/tests/src/com/adobe/air/filesystem/FileMonitorTest.as +63 -0
  80. data/tests/src/com/adobe/air/filesystem/VolumeMonitorTest.as +57 -0
  81. data/tests/src/com/adobe/air/filesystem/events/FileMonitorEventTest.as +59 -0
  82. data/tests/src/com/adobe/air/net/events/ResourceCacheEventTest.as +72 -0
  83. data/tests/src/com/adobe/crypto/HMACMD5Test.as +134 -0
  84. data/tests/src/com/adobe/crypto/HMACSHA1Test.as +138 -0
  85. data/tests/src/com/adobe/crypto/MD5Test.as +82 -0
  86. data/tests/src/com/adobe/crypto/SHA1Test.as +151 -0
  87. data/tests/src/com/adobe/crypto/SHA224Test.as +104 -0
  88. data/tests/src/com/adobe/crypto/SHA256Test.as +116 -0
  89. data/tests/src/com/adobe/crypto/WSSEUsernameTokenTest.as +87 -0
  90. data/tests/src/com/adobe/images/JPGEncoderTest.as +54 -0
  91. data/tests/src/com/adobe/images/PNGEncoderTest.as +54 -0
  92. data/tests/src/com/adobe/net/URITest.as +589 -0
  93. data/tests/src/com/adobe/protocols/events/ConnectedEventTest.as +59 -0
  94. data/tests/src/com/adobe/protocols/events/DatabaseEventTest.as +62 -0
  95. data/tests/src/com/adobe/protocols/events/DefinitionEventTest.as +61 -0
  96. data/tests/src/com/adobe/protocols/events/DefinitionHeaderEventTest.as +61 -0
  97. data/tests/src/com/adobe/protocols/events/DictionaryServerEventTest.as +61 -0
  98. data/tests/src/com/adobe/protocols/events/DisconnectedEventTest.as +59 -0
  99. data/tests/src/com/adobe/protocols/events/ErrorEventTest.as +63 -0
  100. data/tests/src/com/adobe/protocols/events/MatchEventTest.as +61 -0
  101. data/tests/src/com/adobe/protocols/events/MatchStrategiesEventTest.as +61 -0
  102. data/tests/src/com/adobe/protocols/events/NoMatchEventTest.as +58 -0
  103. data/tests/src/com/adobe/protocols/util/CompletedResponseEventTest.as +60 -0
  104. data/tests/src/com/adobe/serialization/json/JSONTest.as +522 -0
  105. data/tests/src/com/adobe/serialization/json/SimpleClass.as +85 -0
  106. data/tests/src/com/adobe/utils/ArrayUtilTest.as +173 -0
  107. data/tests/src/com/adobe/utils/DateUtilTest.as +436 -0
  108. data/tests/src/com/adobe/utils/DictionaryUtilTest.as +93 -0
  109. data/tests/src/com/adobe/utils/IntUtilTest.as +73 -0
  110. data/tests/src/com/adobe/utils/NumberFormatterTest.as +70 -0
  111. data/tests/src/com/adobe/utils/StringUtilTest.as +304 -0
  112. data/tests/src/com/adobe/utils/XMLUtilTest.as +101 -0
  113. data/tests/src/com/adobe/webapis/events/ServiceEventTest.as +66 -0
  114. metadata +196 -0
@@ -0,0 +1,141 @@
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
+ }
@@ -0,0 +1,55 @@
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
+ }
@@ -0,0 +1,76 @@
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
+ }
@@ -0,0 +1,200 @@
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/mp4","f4a"],
100
+ ["audio/mp4","f4b"],
101
+ ["audio/mpeg","mp3","mpga","mp2"],
102
+ ["audio/x-aiff","aif","aiff","aifc"],
103
+ ["audio/x-mpegurl","m3u"],
104
+ ["audio/x-pn-realaudio","ram","ra"],
105
+ ["audio/x-wav","wav"],
106
+ ["chemical/x-pdb","pdb"],
107
+ ["chemical/x-xyz","xyz"],
108
+ ["image/bmp","bmp"],
109
+ ["image/cgm","cgm"],
110
+ ["image/gif","gif"],
111
+ ["image/ief","ief"],
112
+ ["image/jpeg","jpg","jpeg","jpe"],
113
+ ["image/png","png"],
114
+ ["image/svg+xml","svg"],
115
+ ["image/tiff","tiff","tif"],
116
+ ["image/vnd.djvu","djvu","djv"],
117
+ ["image/vnd.wap.wbmp","wbmp"],
118
+ ["image/x-cmu-raster","ras"],
119
+ ["image/x-icon","ico"],
120
+ ["image/x-portable-anymap","pnm"],
121
+ ["image/x-portable-bitmap","pbm"],
122
+ ["image/x-portable-graymap","pgm"],
123
+ ["image/x-portable-pixmap","ppm"],
124
+ ["image/x-rgb","rgb"],
125
+ ["image/x-xbitmap","xbm"],
126
+ ["image/x-xpixmap","xpm"],
127
+ ["image/x-xwindowdump","xwd"],
128
+ ["model/iges","igs","iges"],
129
+ ["model/mesh","msh","mesh","silo"],
130
+ ["model/vrml","wrl","vrml"],
131
+ ["text/calendar","ics","ifb"],
132
+ ["text/css","css"],
133
+ ["text/html","html","htm"],
134
+ ["text/plain","txt","asc"],
135
+ ["text/richtext","rtx"],
136
+ ["text/rtf","rtf"],
137
+ ["text/sgml","sgml","sgm"],
138
+ ["text/tab-separated-values","tsv"],
139
+ ["text/vnd.wap.wml","wml"],
140
+ ["text/vnd.wap.wmlscript","wmls"],
141
+ ["text/x-setext","etx"],
142
+ ["video/mp4","f4v"],
143
+ ["video/mp4","f4p"],
144
+ ["video/mpeg","mpg","mpeg","mpe"],
145
+ ["video/quicktime","mov","qt"],
146
+ ["video/vnd.mpegurl","m4u","mxu"],
147
+ ["video/x-flv","flv"],
148
+ ["video/x-msvideo","avi"],
149
+ ["video/x-sgi-movie","movie"],
150
+ ["x-conference/x-cooltalk","ice"]];
151
+
152
+ /**
153
+ * Returns the mimetype for the given extension.
154
+ */
155
+ public function getMimeType(extension:String):String
156
+ {
157
+ extension = extension.toLocaleLowerCase();
158
+ for each (var a:Array in types)
159
+ {
160
+ for each (var b:String in a)
161
+ {
162
+ if (b == extension)
163
+ {
164
+ return a[0];
165
+ }
166
+ }
167
+ }
168
+ return null;
169
+ }
170
+
171
+ /**
172
+ * Returns the prefered extension for the given mimetype.
173
+ */
174
+ public function getExtension(mimetype:String):String
175
+ {
176
+ mimetype = mimetype.toLocaleLowerCase();
177
+ for each (var a:Array in types)
178
+ {
179
+ if (a[0] == mimetype)
180
+ {
181
+ return a[1];
182
+ }
183
+ }
184
+ return null;
185
+ }
186
+
187
+ /**
188
+ * Adds a mimetype to the map. The order of the extensions matters. The most preferred should come first.
189
+ */
190
+ public function addMimeType(mimetype:String, extensions:Array):void
191
+ {
192
+ var newType:Array = [mimetype];
193
+ for each (var a:String in extensions)
194
+ {
195
+ newType.push(a);
196
+ }
197
+ types.push(newType);
198
+ }
199
+ }
200
+ }