as3corelib 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -0
- data/Gemfile.lock +28 -0
- data/README.textile +79 -0
- data/Rakefile +3 -0
- data/as3corelib.gemspec +23 -0
- data/build/build.properties +48 -0
- data/build/build.xml +104 -0
- data/examples/JSONExample/JSONExample.mxml +73 -0
- data/lib/as3corelib.rb +15 -0
- data/src/com/adobe/air/crypto/EncryptionKeyGenerator.as +313 -0
- data/src/com/adobe/air/filesystem/FileMonitor.as +245 -0
- data/src/com/adobe/air/filesystem/FileUtil.as +63 -0
- data/src/com/adobe/air/filesystem/VolumeMonitor.as +184 -0
- data/src/com/adobe/air/filesystem/events/FileMonitorEvent.as +61 -0
- data/src/com/adobe/air/logging/FileTarget.as +95 -0
- data/src/com/adobe/air/net/ResourceCache.as +165 -0
- data/src/com/adobe/air/net/events/ResourceCacheEvent.as +70 -0
- data/src/com/adobe/crypto/HMAC.as +127 -0
- data/src/com/adobe/crypto/MD5.as +281 -0
- data/src/com/adobe/crypto/MD5Stream.as +402 -0
- data/src/com/adobe/crypto/SHA1.as +289 -0
- data/src/com/adobe/crypto/SHA224.as +257 -0
- data/src/com/adobe/crypto/SHA256.as +261 -0
- data/src/com/adobe/crypto/WSSEUsernameToken.as +114 -0
- data/src/com/adobe/errors/IllegalStateError.as +63 -0
- data/src/com/adobe/fileformats/vcard/Address.as +47 -0
- data/src/com/adobe/fileformats/vcard/Email.as +39 -0
- data/src/com/adobe/fileformats/vcard/Phone.as +39 -0
- data/src/com/adobe/fileformats/vcard/VCard.as +54 -0
- data/src/com/adobe/fileformats/vcard/VCardParser.as +246 -0
- data/src/com/adobe/images/BitString.as +39 -0
- data/src/com/adobe/images/JPGEncoder.as +648 -0
- data/src/com/adobe/images/PNGEncoder.as +141 -0
- data/src/com/adobe/net/DynamicURLLoader.as +55 -0
- data/src/com/adobe/net/IURIResolver.as +76 -0
- data/src/com/adobe/net/MimeTypeMap.as +200 -0
- data/src/com/adobe/net/URI.as +2466 -0
- data/src/com/adobe/net/URIEncodingBitmap.as +139 -0
- data/src/com/adobe/net/proxies/RFC2817Socket.as +198 -0
- data/src/com/adobe/protocols/dict/Database.as +66 -0
- data/src/com/adobe/protocols/dict/Definition.as +71 -0
- data/src/com/adobe/protocols/dict/Dict.as +360 -0
- data/src/com/adobe/protocols/dict/DictionaryServer.as +60 -0
- data/src/com/adobe/protocols/dict/MatchStrategy.as +66 -0
- data/src/com/adobe/protocols/dict/Response.as +71 -0
- data/src/com/adobe/protocols/dict/events/ConnectedEvent.as +53 -0
- data/src/com/adobe/protocols/dict/events/DatabaseEvent.as +67 -0
- data/src/com/adobe/protocols/dict/events/DefinitionEvent.as +70 -0
- data/src/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as +69 -0
- data/src/com/adobe/protocols/dict/events/DictionaryServerEvent.as +69 -0
- data/src/com/adobe/protocols/dict/events/DisconnectedEvent.as +55 -0
- data/src/com/adobe/protocols/dict/events/ErrorEvent.as +80 -0
- data/src/com/adobe/protocols/dict/events/MatchEvent.as +67 -0
- data/src/com/adobe/protocols/dict/events/MatchStrategiesEvent.as +70 -0
- data/src/com/adobe/protocols/dict/events/NoMatchEvent.as +54 -0
- data/src/com/adobe/protocols/dict/util/CompleteResponseEvent.as +68 -0
- data/src/com/adobe/protocols/dict/util/SocketHelper.as +81 -0
- data/src/com/adobe/serialization/json/JSON.as +86 -0
- data/src/com/adobe/serialization/json/JSONDecoder.as +327 -0
- data/src/com/adobe/serialization/json/JSONEncoder.as +312 -0
- data/src/com/adobe/serialization/json/JSONParseError.as +87 -0
- data/src/com/adobe/serialization/json/JSONToken.as +104 -0
- data/src/com/adobe/serialization/json/JSONTokenType.as +69 -0
- data/src/com/adobe/serialization/json/JSONTokenizer.as +702 -0
- data/src/com/adobe/utils/ArrayUtil.as +187 -0
- data/src/com/adobe/utils/DateUtil.as +701 -0
- data/src/com/adobe/utils/DictionaryUtil.as +87 -0
- data/src/com/adobe/utils/IntUtil.as +99 -0
- data/src/com/adobe/utils/NumberFormatter.as +74 -0
- data/src/com/adobe/utils/StringUtil.as +239 -0
- data/src/com/adobe/utils/XMLUtil.as +168 -0
- data/src/com/adobe/webapis/ServiceBase.as +48 -0
- data/src/com/adobe/webapis/URLLoaderBase.as +108 -0
- data/src/com/adobe/webapis/events/ServiceEvent.as +82 -0
- data/tests/src/CoreLibTestRunner-app.xml +135 -0
- data/tests/src/CoreLibTestRunner.as +138 -0
- data/tests/src/CoreLibTestRunner.mxml +46 -0
- data/tests/src/com/adobe/air/crypto/EncryptionKeyGeneratorTest.as +176 -0
- data/tests/src/com/adobe/air/filesystem/FileMonitorTest.as +63 -0
- data/tests/src/com/adobe/air/filesystem/VolumeMonitorTest.as +57 -0
- data/tests/src/com/adobe/air/filesystem/events/FileMonitorEventTest.as +59 -0
- data/tests/src/com/adobe/air/net/events/ResourceCacheEventTest.as +72 -0
- data/tests/src/com/adobe/crypto/HMACMD5Test.as +134 -0
- data/tests/src/com/adobe/crypto/HMACSHA1Test.as +138 -0
- data/tests/src/com/adobe/crypto/MD5Test.as +82 -0
- data/tests/src/com/adobe/crypto/SHA1Test.as +151 -0
- data/tests/src/com/adobe/crypto/SHA224Test.as +104 -0
- data/tests/src/com/adobe/crypto/SHA256Test.as +116 -0
- data/tests/src/com/adobe/crypto/WSSEUsernameTokenTest.as +87 -0
- data/tests/src/com/adobe/images/JPGEncoderTest.as +54 -0
- data/tests/src/com/adobe/images/PNGEncoderTest.as +54 -0
- data/tests/src/com/adobe/net/URITest.as +589 -0
- data/tests/src/com/adobe/protocols/events/ConnectedEventTest.as +59 -0
- data/tests/src/com/adobe/protocols/events/DatabaseEventTest.as +62 -0
- data/tests/src/com/adobe/protocols/events/DefinitionEventTest.as +61 -0
- data/tests/src/com/adobe/protocols/events/DefinitionHeaderEventTest.as +61 -0
- data/tests/src/com/adobe/protocols/events/DictionaryServerEventTest.as +61 -0
- data/tests/src/com/adobe/protocols/events/DisconnectedEventTest.as +59 -0
- data/tests/src/com/adobe/protocols/events/ErrorEventTest.as +63 -0
- data/tests/src/com/adobe/protocols/events/MatchEventTest.as +61 -0
- data/tests/src/com/adobe/protocols/events/MatchStrategiesEventTest.as +61 -0
- data/tests/src/com/adobe/protocols/events/NoMatchEventTest.as +58 -0
- data/tests/src/com/adobe/protocols/util/CompletedResponseEventTest.as +60 -0
- data/tests/src/com/adobe/serialization/json/JSONTest.as +522 -0
- data/tests/src/com/adobe/serialization/json/SimpleClass.as +85 -0
- data/tests/src/com/adobe/utils/ArrayUtilTest.as +173 -0
- data/tests/src/com/adobe/utils/DateUtilTest.as +436 -0
- data/tests/src/com/adobe/utils/DictionaryUtilTest.as +93 -0
- data/tests/src/com/adobe/utils/IntUtilTest.as +73 -0
- data/tests/src/com/adobe/utils/NumberFormatterTest.as +70 -0
- data/tests/src/com/adobe/utils/StringUtilTest.as +304 -0
- data/tests/src/com/adobe/utils/XMLUtilTest.as +101 -0
- data/tests/src/com/adobe/webapis/events/ServiceEventTest.as +66 -0
- metadata +196 -0
@@ -0,0 +1,360 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2009, 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.protocols.dict
|
34
|
+
{
|
35
|
+
import com.adobe.protocols.dict.events.*;
|
36
|
+
import com.adobe.protocols.dict.util.*;
|
37
|
+
|
38
|
+
import flash.events.Event;
|
39
|
+
import flash.events.EventDispatcher;
|
40
|
+
import flash.events.IOErrorEvent;
|
41
|
+
import flash.events.ProgressEvent;
|
42
|
+
import flash.events.SecurityErrorEvent;
|
43
|
+
import flash.net.Socket;
|
44
|
+
import mx.rpc.http.HTTPService;
|
45
|
+
import mx.rpc.events.ResultEvent;
|
46
|
+
import mx.rpc.events.FaultEvent;
|
47
|
+
import flash.xml.XMLNode;
|
48
|
+
import mx.utils.StringUtil;
|
49
|
+
|
50
|
+
public class Dict
|
51
|
+
extends EventDispatcher
|
52
|
+
{
|
53
|
+
// Event type names.
|
54
|
+
//public static var CONNECTED:String = "connected";
|
55
|
+
//public static var DISCONNECTED:String = "disconnected";
|
56
|
+
public static var IO_ERROR:String = IOErrorEvent.IO_ERROR;
|
57
|
+
//public static var ERROR:String = "error";
|
58
|
+
//public static var SERVERS:String = "servers";
|
59
|
+
//public static var DATABASES:String = "databases";
|
60
|
+
//public static var MATCH_STRATEGIES:String = "matchStrategies";
|
61
|
+
//public static var DEFINITION:String = "definition";
|
62
|
+
//public static var DEFINITION_HEADER:String = "definitionHeader";
|
63
|
+
//public static var MATCH:String = "match";
|
64
|
+
//public static var NO_MATCH:String = "noMatch";
|
65
|
+
|
66
|
+
public static var FIRST_MATCH:uint = 0;
|
67
|
+
public static var ALL_DATABASES:uint = 1;
|
68
|
+
|
69
|
+
private var socket:SocketHelper;
|
70
|
+
|
71
|
+
private var dbShortList:Boolean;
|
72
|
+
|
73
|
+
public function Dict()
|
74
|
+
{
|
75
|
+
this.socket = new SocketHelper();
|
76
|
+
this.socket.addEventListener(Event.CONNECT, connected);
|
77
|
+
this.socket.addEventListener(Event.CLOSE, disconnected);
|
78
|
+
this.socket.addEventListener(SocketHelper.COMPLETE_RESPONSE, incomingData);
|
79
|
+
this.socket.addEventListener(IOErrorEvent.IO_ERROR, ioError);
|
80
|
+
this.socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityError);
|
81
|
+
}
|
82
|
+
|
83
|
+
public function connect(server:String, port:uint = 2628):void
|
84
|
+
{
|
85
|
+
if (this.socket.connected)
|
86
|
+
{
|
87
|
+
this.socket.close();
|
88
|
+
}
|
89
|
+
this.socket.connect(server, port);
|
90
|
+
}
|
91
|
+
|
92
|
+
public function connectThroughProxy(proxyServer:String,
|
93
|
+
proxyPort:int,
|
94
|
+
server:String,
|
95
|
+
port:uint = 2628):void
|
96
|
+
{
|
97
|
+
if (this.socket.connected)
|
98
|
+
{
|
99
|
+
this.socket.close();
|
100
|
+
}
|
101
|
+
this.socket.setProxyInfo(proxyServer, proxyPort);
|
102
|
+
this.socket.connect(server, port);
|
103
|
+
}
|
104
|
+
|
105
|
+
public function disconnect():void
|
106
|
+
{
|
107
|
+
this.socket.close();
|
108
|
+
this.disconnected(null);
|
109
|
+
}
|
110
|
+
|
111
|
+
public function getServers():void
|
112
|
+
{
|
113
|
+
var http:HTTPService = new HTTPService();
|
114
|
+
http.url = "http://luetzschena-stahmeln.de/dictd/xmllist.php";
|
115
|
+
http.addEventListener(ResultEvent.RESULT, incomingServerXML);
|
116
|
+
http.addEventListener(FaultEvent.FAULT, httpError);
|
117
|
+
http.resultFormat = HTTPService.RESULT_FORMAT_E4X;
|
118
|
+
http.send();
|
119
|
+
}
|
120
|
+
|
121
|
+
public function getDatabases(shortList:Boolean=true):void
|
122
|
+
{
|
123
|
+
this.dbShortList = shortList;
|
124
|
+
this.socket.writeUTFBytes("show db\r\n");
|
125
|
+
this.socket.flush();
|
126
|
+
}
|
127
|
+
|
128
|
+
public function getMatchStrategies():void
|
129
|
+
{
|
130
|
+
this.socket.writeUTFBytes("show strat\r\n");
|
131
|
+
this.socket.flush();
|
132
|
+
}
|
133
|
+
|
134
|
+
public function match(database:String, term:String, scope:String="prefix"):void
|
135
|
+
{
|
136
|
+
this.socket.writeUTFBytes("match " + database + " " + scope + " \"" + term + "\"\r\n");
|
137
|
+
this.socket.flush();
|
138
|
+
}
|
139
|
+
|
140
|
+
public function define(database:String, term:String):void
|
141
|
+
{
|
142
|
+
this.socket.writeUTFBytes("define " + database + " \"" + term + "\"\r\n");
|
143
|
+
this.socket.flush();
|
144
|
+
}
|
145
|
+
|
146
|
+
public function lookup(term:String, scope:uint):void
|
147
|
+
{
|
148
|
+
var flag:String;
|
149
|
+
if (scope == Dict.ALL_DATABASES)
|
150
|
+
{
|
151
|
+
flag = "*";
|
152
|
+
}
|
153
|
+
else if (scope == Dict.FIRST_MATCH)
|
154
|
+
{
|
155
|
+
flag = "!";
|
156
|
+
}
|
157
|
+
this.socket.writeUTFBytes("define " + flag + " \"" + term + "\"\r\n");
|
158
|
+
this.socket.flush();
|
159
|
+
}
|
160
|
+
|
161
|
+
//// Private functions ////
|
162
|
+
|
163
|
+
private function connected(event:Event):void
|
164
|
+
{
|
165
|
+
// Wait to dispatch an event until we get the 220 response.
|
166
|
+
}
|
167
|
+
|
168
|
+
private function disconnected(event:Event):void
|
169
|
+
{
|
170
|
+
dispatchEvent(new DisconnectedEvent(DisconnectedEvent.DISCONNECTED));
|
171
|
+
}
|
172
|
+
|
173
|
+
private function incomingServerXML(event:ResultEvent):void
|
174
|
+
{
|
175
|
+
var dictd:Namespace = new Namespace("http://www.luetzschena-stahmeln.de/dictd/");
|
176
|
+
var result:XML = event.result as XML;
|
177
|
+
var server:String, description:String;
|
178
|
+
var servers:Array = new Array();
|
179
|
+
for each (var serverNode:XML in result.dictd::server)
|
180
|
+
{
|
181
|
+
server = serverNode.dictd::dictdurl;
|
182
|
+
description = serverNode.dictd::description;
|
183
|
+
if (StringUtil.trim(server).length != 0 &&
|
184
|
+
StringUtil.trim(description).length != 0)
|
185
|
+
{
|
186
|
+
var dServer:DictionaryServer = new DictionaryServer();
|
187
|
+
dServer.server = server.replace("dict://", "");
|
188
|
+
dServer.description = description;
|
189
|
+
servers.push(dServer);
|
190
|
+
}
|
191
|
+
}
|
192
|
+
var dEvent:DictionaryServerEvent = new DictionaryServerEvent(DictionaryServerEvent.SERVERS);
|
193
|
+
dEvent.servers = servers;
|
194
|
+
dispatchEvent(dEvent);
|
195
|
+
}
|
196
|
+
|
197
|
+
private function incomingData(event:CompleteResponseEvent):void
|
198
|
+
{
|
199
|
+
var rawResponse:String = event.response;
|
200
|
+
var response:Response = this.parseRawResponse(rawResponse);
|
201
|
+
var responseCode:uint = response.code;
|
202
|
+
if (responseCode == 552) // no matches
|
203
|
+
{
|
204
|
+
throwNoMatchEvent(response);
|
205
|
+
}
|
206
|
+
else if (responseCode >= 400 && responseCode <= 599) // error
|
207
|
+
{
|
208
|
+
throwErrorEvent(response);
|
209
|
+
}
|
210
|
+
else if (responseCode == 220) // successful connection
|
211
|
+
{
|
212
|
+
dispatchEvent(new ConnectedEvent(ConnectedEvent.CONNECTED));
|
213
|
+
}
|
214
|
+
else if (responseCode == 110) // databases are being returned
|
215
|
+
{
|
216
|
+
throwDatabasesEvent(response);
|
217
|
+
}
|
218
|
+
else if (responseCode == 111) // matches strategies
|
219
|
+
{
|
220
|
+
throwMatchStrategiesEvent(response);
|
221
|
+
}
|
222
|
+
else if (responseCode == 152) // matches
|
223
|
+
{
|
224
|
+
throwMatchEvent(response);
|
225
|
+
}
|
226
|
+
else if (responseCode == 150)
|
227
|
+
{
|
228
|
+
throwDefinitionHeaderEvent(response);
|
229
|
+
}
|
230
|
+
else if (responseCode == 151)
|
231
|
+
{
|
232
|
+
throwDefinitionEvent(response);
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
private function ioError(event:IOErrorEvent):void
|
237
|
+
{
|
238
|
+
dispatchEvent(event);
|
239
|
+
}
|
240
|
+
|
241
|
+
private function httpError(event:FaultEvent):void
|
242
|
+
{
|
243
|
+
trace("httpError!");
|
244
|
+
}
|
245
|
+
|
246
|
+
private function securityError(event:SecurityErrorEvent):void
|
247
|
+
{
|
248
|
+
trace("security error!");
|
249
|
+
trace(event.text);
|
250
|
+
}
|
251
|
+
|
252
|
+
// Dispatch new events.
|
253
|
+
|
254
|
+
private function throwDatabasesEvent(response:Response):void
|
255
|
+
{
|
256
|
+
var databases:Array = new Array();
|
257
|
+
var responseArray:Array = response.body.split("\r\n");
|
258
|
+
for each (var line:String in responseArray)
|
259
|
+
{
|
260
|
+
var name:String = line.substring(0, line.indexOf(" "));
|
261
|
+
if (name == "--exit--")
|
262
|
+
{
|
263
|
+
if (this.dbShortList)
|
264
|
+
{
|
265
|
+
break;
|
266
|
+
}
|
267
|
+
continue;
|
268
|
+
}
|
269
|
+
var description:String = line.substring(line.indexOf(" ")+1, line.length).replace(/\"/g,"");
|
270
|
+
databases.push(new Database(name, description));
|
271
|
+
}
|
272
|
+
var event:DatabaseEvent = new DatabaseEvent(DatabaseEvent.DATABASES);
|
273
|
+
event.databases = databases;
|
274
|
+
dispatchEvent(event);
|
275
|
+
}
|
276
|
+
|
277
|
+
private function throwMatchStrategiesEvent(response:Response):void
|
278
|
+
{
|
279
|
+
var strategies:Array = new Array();
|
280
|
+
var responseArray:Array = response.body.split("\r\n");
|
281
|
+
for each (var line:String in responseArray)
|
282
|
+
{
|
283
|
+
var name:String = line.substring(0, line.indexOf(" "));
|
284
|
+
var description:String = line.substring(line.indexOf(" ")+1, line.length).replace(/\"/g,"");
|
285
|
+
strategies.push(new MatchStrategy(name, description));
|
286
|
+
}
|
287
|
+
var event:MatchStrategiesEvent = new MatchStrategiesEvent(MatchStrategiesEvent.MATCH_STRATEGIES);
|
288
|
+
event.strategies = strategies;
|
289
|
+
dispatchEvent(event);
|
290
|
+
}
|
291
|
+
|
292
|
+
private function throwMatchEvent(response:Response):void
|
293
|
+
{
|
294
|
+
var matches:Array = new Array();
|
295
|
+
var responseArray:Array = response.body.split("\r\n");
|
296
|
+
for each (var line:String in responseArray)
|
297
|
+
{
|
298
|
+
var match:String = line.substring(line.indexOf(" ")+1, line.length).replace(/\"/g,"");
|
299
|
+
matches.push(match);
|
300
|
+
}
|
301
|
+
var event:MatchEvent = new MatchEvent(MatchEvent.MATCH);
|
302
|
+
event.matches = matches;
|
303
|
+
dispatchEvent(event);
|
304
|
+
}
|
305
|
+
|
306
|
+
private function throwErrorEvent(response:Response):void
|
307
|
+
{
|
308
|
+
var event:ErrorEvent = new ErrorEvent(ErrorEvent.ERROR);
|
309
|
+
event.code = response.code;
|
310
|
+
event.message = response.headerText;
|
311
|
+
dispatchEvent(event);
|
312
|
+
}
|
313
|
+
|
314
|
+
private function throwNoMatchEvent(response:Response):void
|
315
|
+
{
|
316
|
+
dispatchEvent(new NoMatchEvent(NoMatchEvent.NO_MATCH));
|
317
|
+
}
|
318
|
+
|
319
|
+
private function throwDefinitionHeaderEvent(response:Response):void
|
320
|
+
{
|
321
|
+
var event:DefinitionHeaderEvent = new DefinitionHeaderEvent(DefinitionHeaderEvent.DEFINITION_HEADER);
|
322
|
+
event.definitionCount = uint(response.headerText.substring(0, response.headerText.indexOf(" ")));
|
323
|
+
dispatchEvent(event);
|
324
|
+
}
|
325
|
+
|
326
|
+
private function throwDefinitionEvent(response:Response):void
|
327
|
+
{
|
328
|
+
var event:DefinitionEvent = new DefinitionEvent(DefinitionEvent.DEFINITION);
|
329
|
+
var def:Definition = new Definition();
|
330
|
+
var headerText:String = response.headerText;
|
331
|
+
var tokens:Array = headerText.match(/"[^"]+"/g);
|
332
|
+
def.term = String(tokens[0]).replace(/"/g, "");
|
333
|
+
def.database = String(tokens[1]).replace(/"/g, "");
|
334
|
+
def.definition = response.body;
|
335
|
+
event.definition = def;
|
336
|
+
dispatchEvent(event);
|
337
|
+
}
|
338
|
+
|
339
|
+
private function parseRawResponse(rawResponse:String):Response
|
340
|
+
{
|
341
|
+
var response:Response = new Response();
|
342
|
+
var fullHeader:String;
|
343
|
+
if (rawResponse.indexOf("\r\n") != -1)
|
344
|
+
{
|
345
|
+
fullHeader = rawResponse.substring(0, rawResponse.indexOf("\r\n"));
|
346
|
+
}
|
347
|
+
else
|
348
|
+
{
|
349
|
+
fullHeader = rawResponse;
|
350
|
+
}
|
351
|
+
var responseCodeMatch:Array = fullHeader.match(/^\d{3}/);
|
352
|
+
response.code = uint(responseCodeMatch[0]);
|
353
|
+
response.headerText = fullHeader.substring(fullHeader.indexOf(" ")+1, fullHeader.length);
|
354
|
+
var body:String = rawResponse.substring(rawResponse.indexOf("\r\n")+2, rawResponse.length);
|
355
|
+
body = body.replace(/\r\n\.\./, "\r\n.");
|
356
|
+
response.body = body;
|
357
|
+
return response;
|
358
|
+
}
|
359
|
+
}
|
360
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2009, 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.protocols.dict
|
34
|
+
{
|
35
|
+
public class DictionaryServer
|
36
|
+
{
|
37
|
+
private var _server:String;
|
38
|
+
private var _description:String;
|
39
|
+
|
40
|
+
public function set server(server:String):void
|
41
|
+
{
|
42
|
+
this._server = server;
|
43
|
+
}
|
44
|
+
|
45
|
+
public function get server():String
|
46
|
+
{
|
47
|
+
return this._server;
|
48
|
+
}
|
49
|
+
|
50
|
+
public function set description(description:String):void
|
51
|
+
{
|
52
|
+
this._description = description;
|
53
|
+
}
|
54
|
+
|
55
|
+
public function get description():String
|
56
|
+
{
|
57
|
+
return this._description;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2009, 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.protocols.dict
|
34
|
+
{
|
35
|
+
public class MatchStrategy
|
36
|
+
{
|
37
|
+
private var _name:String;
|
38
|
+
private var _description:String;
|
39
|
+
|
40
|
+
public function MatchStrategy(name:String, description:String)
|
41
|
+
{
|
42
|
+
this._name = name;
|
43
|
+
this._description = description;
|
44
|
+
}
|
45
|
+
|
46
|
+
public function set name(name:String):void
|
47
|
+
{
|
48
|
+
this._name = name;
|
49
|
+
}
|
50
|
+
|
51
|
+
public function get name():String
|
52
|
+
{
|
53
|
+
return this._name;
|
54
|
+
}
|
55
|
+
|
56
|
+
public function set description(description:String):void
|
57
|
+
{
|
58
|
+
this._description = description;
|
59
|
+
}
|
60
|
+
|
61
|
+
public function get description():String
|
62
|
+
{
|
63
|
+
return this._description;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
@@ -0,0 +1,71 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2009, 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.protocols.dict
|
34
|
+
{
|
35
|
+
public class Response
|
36
|
+
{
|
37
|
+
private var _code:uint;
|
38
|
+
private var _headerText:String;
|
39
|
+
private var _body:String;
|
40
|
+
|
41
|
+
public function set code(code:uint):void
|
42
|
+
{
|
43
|
+
this._code = code;
|
44
|
+
}
|
45
|
+
|
46
|
+
public function set headerText(headerText:String):void
|
47
|
+
{
|
48
|
+
this._headerText = headerText;
|
49
|
+
}
|
50
|
+
|
51
|
+
public function set body(body:String):void
|
52
|
+
{
|
53
|
+
this._body = body;
|
54
|
+
}
|
55
|
+
|
56
|
+
public function get code():uint
|
57
|
+
{
|
58
|
+
return this._code;
|
59
|
+
}
|
60
|
+
|
61
|
+
public function get headerText():String
|
62
|
+
{
|
63
|
+
return this._headerText;
|
64
|
+
}
|
65
|
+
|
66
|
+
public function get body():String
|
67
|
+
{
|
68
|
+
return this._body;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2009, 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.protocols.dict.events
|
34
|
+
{
|
35
|
+
import flash.events.Event;
|
36
|
+
|
37
|
+
public class ConnectedEvent extends Event
|
38
|
+
{
|
39
|
+
public static const CONNECTED:String = "connected";
|
40
|
+
|
41
|
+
public function ConnectedEvent(type:String, bubbles:Boolean = false,
|
42
|
+
cancelable:Boolean = false)
|
43
|
+
{
|
44
|
+
super(type, bubbles, cancelable);
|
45
|
+
}
|
46
|
+
|
47
|
+
public override function clone():Event
|
48
|
+
{
|
49
|
+
var out:ConnectedEvent = new ConnectedEvent(type, bubbles, cancelable);
|
50
|
+
return out;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2009, 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.protocols.dict.events
|
34
|
+
{
|
35
|
+
import flash.events.Event;
|
36
|
+
|
37
|
+
public class DatabaseEvent extends Event
|
38
|
+
{
|
39
|
+
private var _databases:Array;
|
40
|
+
|
41
|
+
public static const DATABASES:String = "databases";
|
42
|
+
|
43
|
+
public function DatabaseEvent(type:String, bubbles:Boolean = false,
|
44
|
+
cancelable:Boolean = false)
|
45
|
+
{
|
46
|
+
super(type, bubbles, cancelable);
|
47
|
+
}
|
48
|
+
|
49
|
+
public function set databases(databases:Array):void
|
50
|
+
{
|
51
|
+
this._databases = databases;
|
52
|
+
}
|
53
|
+
|
54
|
+
public function get databases():Array
|
55
|
+
{
|
56
|
+
return this._databases;
|
57
|
+
}
|
58
|
+
|
59
|
+
public override function clone():Event
|
60
|
+
{
|
61
|
+
var out:DatabaseEvent = new DatabaseEvent(type, bubbles, cancelable);
|
62
|
+
out.databases = _databases;
|
63
|
+
|
64
|
+
return out;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|