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,246 @@
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
+ }
@@ -0,0 +1,39 @@
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
+ }