Inmental commited on
Commit
343e5a8
·
verified ·
1 Parent(s): e0f20a0

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +2 -0
  2. DISPLAYER/Displayer-app.xml +38 -0
  3. DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Adobe AIR.dll +3 -0
  4. DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/Adobe AIR.vch +0 -0
  5. DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/CaptiveAppEntry.exe +0 -0
  6. DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/Licenses/cairo/COPYING +33 -0
  7. DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/Licenses/cairo/COPYING-LGPL-2.1 +510 -0
  8. DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/Licenses/cairo/COPYING-MPL-1.1 +470 -0
  9. DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/Licenses/pcre2/COPYING +5 -0
  10. DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/Licenses/pixman/COPYING +42 -0
  11. DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/adobecp.vch +0 -0
  12. DISPLAYER/Displayer.app/Displayer.exe +0 -0
  13. DISPLAYER/Displayer.app/Displayer.swf +0 -0
  14. DISPLAYER/Displayer.app/META-INF/AIR/application.xml +38 -0
  15. DISPLAYER/Displayer.app/META-INF/AIR/hash +1 -0
  16. DISPLAYER/Displayer.app/META-INF/signatures.xml +125 -0
  17. DISPLAYER/Displayer.app/config.json +11 -0
  18. DISPLAYER/Displayer.app/mimetype +1 -0
  19. DISPLAYER/Displayer.fla +0 -0
  20. DISPLAYER/Displayer.swf +0 -0
  21. DISPLAYER/FullScreenImageLoader.as +149 -0
  22. DISPLAYER/Main.as +1 -0
  23. DISPLAYER/com/adobe/air/crypto/EncryptionKeyGenerator.as +313 -0
  24. DISPLAYER/com/adobe/air/filesystem/FileMonitor.as +245 -0
  25. DISPLAYER/com/adobe/air/filesystem/FileUtil.as +63 -0
  26. DISPLAYER/com/adobe/air/filesystem/VolumeMonitor.as +184 -0
  27. DISPLAYER/com/adobe/air/filesystem/events/FileMonitorEvent.as +61 -0
  28. DISPLAYER/com/adobe/air/logging/FileTarget.as +95 -0
  29. DISPLAYER/com/adobe/air/net/ResourceCache.as +165 -0
  30. DISPLAYER/com/adobe/air/net/events/ResourceCacheEvent.as +70 -0
  31. DISPLAYER/com/adobe/crypto/HMAC.as +127 -0
  32. DISPLAYER/com/adobe/crypto/MD5.as +281 -0
  33. DISPLAYER/com/adobe/crypto/MD5Stream.as +402 -0
  34. DISPLAYER/com/adobe/crypto/SHA1.as +289 -0
  35. DISPLAYER/com/adobe/crypto/SHA224.as +257 -0
  36. DISPLAYER/com/adobe/crypto/SHA256.as +261 -0
  37. DISPLAYER/com/adobe/crypto/WSSEUsernameToken.as +114 -0
  38. DISPLAYER/com/adobe/errors/IllegalStateError.as +63 -0
  39. DISPLAYER/com/adobe/fileformats/vcard/Address.as +47 -0
  40. DISPLAYER/com/adobe/fileformats/vcard/Email.as +39 -0
  41. DISPLAYER/com/adobe/fileformats/vcard/Phone.as +39 -0
  42. DISPLAYER/com/adobe/fileformats/vcard/VCard.as +54 -0
  43. DISPLAYER/com/adobe/fileformats/vcard/VCardParser.as +246 -0
  44. DISPLAYER/com/adobe/images/BitString.as +39 -0
  45. DISPLAYER/com/adobe/images/JPGEncoder.as +648 -0
  46. DISPLAYER/com/adobe/images/PNGEncoder.as +141 -0
  47. DISPLAYER/com/adobe/net/DynamicURLLoader.as +55 -0
  48. DISPLAYER/com/adobe/net/IURIResolver.as +76 -0
  49. DISPLAYER/com/adobe/net/MimeTypeMap.as +200 -0
  50. DISPLAYER/com/adobe/net/URI.as +2466 -0
.gitattributes CHANGED
@@ -44,3 +44,5 @@ assets/night2day_results.jpg filter=lfs diff=lfs merge=lfs -text
44
  assets/rainy2clear.jpg filter=lfs diff=lfs merge=lfs -text
45
  assets/teaser_results.jpg filter=lfs diff=lfs merge=lfs -text
46
  triton-2.1.0-cp310-cp310-win_amd64.whl filter=lfs diff=lfs merge=lfs -text
 
 
 
44
  assets/rainy2clear.jpg filter=lfs diff=lfs merge=lfs -text
45
  assets/teaser_results.jpg filter=lfs diff=lfs merge=lfs -text
46
  triton-2.1.0-cp310-cp310-win_amd64.whl filter=lfs diff=lfs merge=lfs -text
47
+ DISPLAYER/Displayer.app/Adobe[[:space:]]AIR/Versions/1.0/Adobe[[:space:]]AIR.dll filter=lfs diff=lfs merge=lfs -text
48
+ Displayer.app/Adobe[[:space:]]AIR/Versions/1.0/Adobe[[:space:]]AIR.dll filter=lfs diff=lfs merge=lfs -text
DISPLAYER/Displayer-app.xml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8" standalone="no" ?>
2
+ <!--
3
+ Usage:
4
+
5
+ To localize the description, use the following format for the description element.
6
+ <description>
7
+ <text xml:lang="en">English App description goes here</text>
8
+ <text xml:lang="fr">French App description goes here</text>
9
+ <text xml:lang="ja">Japanese App description goes here</text>
10
+ </description>
11
+
12
+ To localize the name, use the following format for the name element.
13
+ <name>
14
+ <text xml:lang="en">English App name goes here</text>
15
+ <text xml:lang="fr">French App name goes here</text>
16
+ <text xml:lang="ja">Japanese App name goes here</text>
17
+ </name>
18
+ -->
19
+ <application xmlns="http://ns.adobe.com/air/application/50.2">
20
+ <id>Displayer</id>
21
+ <versionNumber>1.0</versionNumber>
22
+ <filename>Displayer</filename>
23
+ <description/>
24
+ <name>Displayer</name>
25
+ <copyright/>
26
+ <initialWindow>
27
+ <content>Displayer.swf</content>
28
+ <systemChrome>standard</systemChrome>
29
+ <transparent>false</transparent>
30
+ <visible>true</visible>
31
+ <fullScreen>false</fullScreen>
32
+ <aspectRatio>portrait</aspectRatio>
33
+ <renderMode>auto</renderMode>
34
+ </initialWindow>
35
+ <icon/>
36
+ <customUpdateUI>false</customUpdateUI>
37
+ <allowBrowserInvocation>false</allowBrowserInvocation>
38
+ </application>
DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Adobe AIR.dll ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a819617159ddc7aab0c1c495ec3a7baf7ebb8715e382a63745cffdb366429d48
3
+ size 15256032
DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/Adobe AIR.vch ADDED
Binary file (358 kB). View file
 
DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/CaptiveAppEntry.exe ADDED
Binary file (82.9 kB). View file
 
DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/Licenses/cairo/COPYING ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Cairo is free software.
2
+
3
+ Every source file in the implementation[*] of cairo is available to be
4
+ redistributed and/or modified under the terms of either the GNU Lesser
5
+ General Public License (LGPL) version 2.1 or the Mozilla Public
6
+ License (MPL) version 1.1. Some files are available under more
7
+ liberal terms, but we believe that in all cases, each file may be used
8
+ under either the LGPL or the MPL.
9
+
10
+ See the following files in this directory for the precise terms and
11
+ conditions of either license:
12
+
13
+ COPYING-LGPL-2.1
14
+ COPYING-MPL-1.1
15
+
16
+ Please see each file in the implementation for copyright and licensing
17
+ information, (in the opening comment of each file).
18
+
19
+ [*] The implementation of cairo is contained entirely within the "src"
20
+ directory of the cairo source distribution. There are other components
21
+ of the cairo source distribution (such as the "test", "util", and "perf")
22
+ that are auxiliary to the library itself. None of the source code in these
23
+ directories contributes to a build of the cairo library itself, (libcairo.so
24
+ or cairo.dll or similar).
25
+
26
+ These auxiliary components are also free software, but may be under
27
+ different license terms than cairo itself. For example, most of the
28
+ test cases in the perf and test directories are made available under
29
+ an MIT license to simplify any use of this code for reference purposes
30
+ in using cairo itself. Other files might be available under the GNU
31
+ General Public License (GPL), for example. Again, please see the COPYING
32
+ file under each directory and the opening comment of each file for copyright
33
+ and licensing information.
DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/Licenses/cairo/COPYING-LGPL-2.1 ADDED
@@ -0,0 +1,510 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ GNU LESSER GENERAL PUBLIC LICENSE
3
+ Version 2.1, February 1999
4
+
5
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
6
+ 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
7
+ Everyone is permitted to copy and distribute verbatim copies
8
+ of this license document, but changing it is not allowed.
9
+
10
+ [This is the first released version of the Lesser GPL. It also counts
11
+ as the successor of the GNU Library Public License, version 2, hence
12
+ the version number 2.1.]
13
+
14
+ Preamble
15
+
16
+ The licenses for most software are designed to take away your
17
+ freedom to share and change it. By contrast, the GNU General Public
18
+ Licenses are intended to guarantee your freedom to share and change
19
+ free software--to make sure the software is free for all its users.
20
+
21
+ This license, the Lesser General Public License, applies to some
22
+ specially designated software packages--typically libraries--of the
23
+ Free Software Foundation and other authors who decide to use it. You
24
+ can use it too, but we suggest you first think carefully about whether
25
+ this license or the ordinary General Public License is the better
26
+ strategy to use in any particular case, based on the explanations
27
+ below.
28
+
29
+ When we speak of free software, we are referring to freedom of use,
30
+ not price. Our General Public Licenses are designed to make sure that
31
+ you have the freedom to distribute copies of free software (and charge
32
+ for this service if you wish); that you receive source code or can get
33
+ it if you want it; that you can change the software and use pieces of
34
+ it in new free programs; and that you are informed that you can do
35
+ these things.
36
+
37
+ To protect your rights, we need to make restrictions that forbid
38
+ distributors to deny you these rights or to ask you to surrender these
39
+ rights. These restrictions translate to certain responsibilities for
40
+ you if you distribute copies of the library or if you modify it.
41
+
42
+ For example, if you distribute copies of the library, whether gratis
43
+ or for a fee, you must give the recipients all the rights that we gave
44
+ you. You must make sure that they, too, receive or can get the source
45
+ code. If you link other code with the library, you must provide
46
+ complete object files to the recipients, so that they can relink them
47
+ with the library after making changes to the library and recompiling
48
+ it. And you must show them these terms so they know their rights.
49
+
50
+ We protect your rights with a two-step method: (1) we copyright the
51
+ library, and (2) we offer you this license, which gives you legal
52
+ permission to copy, distribute and/or modify the library.
53
+
54
+ To protect each distributor, we want to make it very clear that
55
+ there is no warranty for the free library. Also, if the library is
56
+ modified by someone else and passed on, the recipients should know
57
+ that what they have is not the original version, so that the original
58
+ author's reputation will not be affected by problems that might be
59
+ introduced by others.
60
+
61
+ Finally, software patents pose a constant threat to the existence of
62
+ any free program. We wish to make sure that a company cannot
63
+ effectively restrict the users of a free program by obtaining a
64
+ restrictive license from a patent holder. Therefore, we insist that
65
+ any patent license obtained for a version of the library must be
66
+ consistent with the full freedom of use specified in this license.
67
+
68
+ Most GNU software, including some libraries, is covered by the
69
+ ordinary GNU General Public License. This license, the GNU Lesser
70
+ General Public License, applies to certain designated libraries, and
71
+ is quite different from the ordinary General Public License. We use
72
+ this license for certain libraries in order to permit linking those
73
+ libraries into non-free programs.
74
+
75
+ When a program is linked with a library, whether statically or using
76
+ a shared library, the combination of the two is legally speaking a
77
+ combined work, a derivative of the original library. The ordinary
78
+ General Public License therefore permits such linking only if the
79
+ entire combination fits its criteria of freedom. The Lesser General
80
+ Public License permits more lax criteria for linking other code with
81
+ the library.
82
+
83
+ We call this license the "Lesser" General Public License because it
84
+ does Less to protect the user's freedom than the ordinary General
85
+ Public License. It also provides other free software developers Less
86
+ of an advantage over competing non-free programs. These disadvantages
87
+ are the reason we use the ordinary General Public License for many
88
+ libraries. However, the Lesser license provides advantages in certain
89
+ special circumstances.
90
+
91
+ For example, on rare occasions, there may be a special need to
92
+ encourage the widest possible use of a certain library, so that it
93
+ becomes a de-facto standard. To achieve this, non-free programs must
94
+ be allowed to use the library. A more frequent case is that a free
95
+ library does the same job as widely used non-free libraries. In this
96
+ case, there is little to gain by limiting the free library to free
97
+ software only, so we use the Lesser General Public License.
98
+
99
+ In other cases, permission to use a particular library in non-free
100
+ programs enables a greater number of people to use a large body of
101
+ free software. For example, permission to use the GNU C Library in
102
+ non-free programs enables many more people to use the whole GNU
103
+ operating system, as well as its variant, the GNU/Linux operating
104
+ system.
105
+
106
+ Although the Lesser General Public License is Less protective of the
107
+ users' freedom, it does ensure that the user of a program that is
108
+ linked with the Library has the freedom and the wherewithal to run
109
+ that program using a modified version of the Library.
110
+
111
+ The precise terms and conditions for copying, distribution and
112
+ modification follow. Pay close attention to the difference between a
113
+ "work based on the library" and a "work that uses the library". The
114
+ former contains code derived from the library, whereas the latter must
115
+ be combined with the library in order to run.
116
+
117
+ GNU LESSER GENERAL PUBLIC LICENSE
118
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
119
+
120
+ 0. This License Agreement applies to any software library or other
121
+ program which contains a notice placed by the copyright holder or
122
+ other authorized party saying it may be distributed under the terms of
123
+ this Lesser General Public License (also called "this License").
124
+ Each licensee is addressed as "you".
125
+
126
+ A "library" means a collection of software functions and/or data
127
+ prepared so as to be conveniently linked with application programs
128
+ (which use some of those functions and data) to form executables.
129
+
130
+ The "Library", below, refers to any such software library or work
131
+ which has been distributed under these terms. A "work based on the
132
+ Library" means either the Library or any derivative work under
133
+ copyright law: that is to say, a work containing the Library or a
134
+ portion of it, either verbatim or with modifications and/or translated
135
+ straightforwardly into another language. (Hereinafter, translation is
136
+ included without limitation in the term "modification".)
137
+
138
+ "Source code" for a work means the preferred form of the work for
139
+ making modifications to it. For a library, complete source code means
140
+ all the source code for all modules it contains, plus any associated
141
+ interface definition files, plus the scripts used to control
142
+ compilation and installation of the library.
143
+
144
+ Activities other than copying, distribution and modification are not
145
+ covered by this License; they are outside its scope. The act of
146
+ running a program using the Library is not restricted, and output from
147
+ such a program is covered only if its contents constitute a work based
148
+ on the Library (independent of the use of the Library in a tool for
149
+ writing it). Whether that is true depends on what the Library does
150
+ and what the program that uses the Library does.
151
+
152
+ 1. You may copy and distribute verbatim copies of the Library's
153
+ complete source code as you receive it, in any medium, provided that
154
+ you conspicuously and appropriately publish on each copy an
155
+ appropriate copyright notice and disclaimer of warranty; keep intact
156
+ all the notices that refer to this License and to the absence of any
157
+ warranty; and distribute a copy of this License along with the
158
+ Library.
159
+
160
+ You may charge a fee for the physical act of transferring a copy,
161
+ and you may at your option offer warranty protection in exchange for a
162
+ fee.
163
+
164
+ 2. You may modify your copy or copies of the Library or any portion
165
+ of it, thus forming a work based on the Library, and copy and
166
+ distribute such modifications or work under the terms of Section 1
167
+ above, provided that you also meet all of these conditions:
168
+
169
+ a) The modified work must itself be a software library.
170
+
171
+ b) You must cause the files modified to carry prominent notices
172
+ stating that you changed the files and the date of any change.
173
+
174
+ c) You must cause the whole of the work to be licensed at no
175
+ charge to all third parties under the terms of this License.
176
+
177
+ d) If a facility in the modified Library refers to a function or a
178
+ table of data to be supplied by an application program that uses
179
+ the facility, other than as an argument passed when the facility
180
+ is invoked, then you must make a good faith effort to ensure that,
181
+ in the event an application does not supply such function or
182
+ table, the facility still operates, and performs whatever part of
183
+ its purpose remains meaningful.
184
+
185
+ (For example, a function in a library to compute square roots has
186
+ a purpose that is entirely well-defined independent of the
187
+ application. Therefore, Subsection 2d requires that any
188
+ application-supplied function or table used by this function must
189
+ be optional: if the application does not supply it, the square
190
+ root function must still compute square roots.)
191
+
192
+ These requirements apply to the modified work as a whole. If
193
+ identifiable sections of that work are not derived from the Library,
194
+ and can be reasonably considered independent and separate works in
195
+ themselves, then this License, and its terms, do not apply to those
196
+ sections when you distribute them as separate works. But when you
197
+ distribute the same sections as part of a whole which is a work based
198
+ on the Library, the distribution of the whole must be on the terms of
199
+ this License, whose permissions for other licensees extend to the
200
+ entire whole, and thus to each and every part regardless of who wrote
201
+ it.
202
+
203
+ Thus, it is not the intent of this section to claim rights or contest
204
+ your rights to work written entirely by you; rather, the intent is to
205
+ exercise the right to control the distribution of derivative or
206
+ collective works based on the Library.
207
+
208
+ In addition, mere aggregation of another work not based on the Library
209
+ with the Library (or with a work based on the Library) on a volume of
210
+ a storage or distribution medium does not bring the other work under
211
+ the scope of this License.
212
+
213
+ 3. You may opt to apply the terms of the ordinary GNU General Public
214
+ License instead of this License to a given copy of the Library. To do
215
+ this, you must alter all the notices that refer to this License, so
216
+ that they refer to the ordinary GNU General Public License, version 2,
217
+ instead of to this License. (If a newer version than version 2 of the
218
+ ordinary GNU General Public License has appeared, then you can specify
219
+ that version instead if you wish.) Do not make any other change in
220
+ these notices.
221
+
222
+ Once this change is made in a given copy, it is irreversible for
223
+ that copy, so the ordinary GNU General Public License applies to all
224
+ subsequent copies and derivative works made from that copy.
225
+
226
+ This option is useful when you wish to copy part of the code of
227
+ the Library into a program that is not a library.
228
+
229
+ 4. You may copy and distribute the Library (or a portion or
230
+ derivative of it, under Section 2) in object code or executable form
231
+ under the terms of Sections 1 and 2 above provided that you accompany
232
+ it with the complete corresponding machine-readable source code, which
233
+ must be distributed under the terms of Sections 1 and 2 above on a
234
+ medium customarily used for software interchange.
235
+
236
+ If distribution of object code is made by offering access to copy
237
+ from a designated place, then offering equivalent access to copy the
238
+ source code from the same place satisfies the requirement to
239
+ distribute the source code, even though third parties are not
240
+ compelled to copy the source along with the object code.
241
+
242
+ 5. A program that contains no derivative of any portion of the
243
+ Library, but is designed to work with the Library by being compiled or
244
+ linked with it, is called a "work that uses the Library". Such a
245
+ work, in isolation, is not a derivative work of the Library, and
246
+ therefore falls outside the scope of this License.
247
+
248
+ However, linking a "work that uses the Library" with the Library
249
+ creates an executable that is a derivative of the Library (because it
250
+ contains portions of the Library), rather than a "work that uses the
251
+ library". The executable is therefore covered by this License.
252
+ Section 6 states terms for distribution of such executables.
253
+
254
+ When a "work that uses the Library" uses material from a header file
255
+ that is part of the Library, the object code for the work may be a
256
+ derivative work of the Library even though the source code is not.
257
+ Whether this is true is especially significant if the work can be
258
+ linked without the Library, or if the work is itself a library. The
259
+ threshold for this to be true is not precisely defined by law.
260
+
261
+ If such an object file uses only numerical parameters, data
262
+ structure layouts and accessors, and small macros and small inline
263
+ functions (ten lines or less in length), then the use of the object
264
+ file is unrestricted, regardless of whether it is legally a derivative
265
+ work. (Executables containing this object code plus portions of the
266
+ Library will still fall under Section 6.)
267
+
268
+ Otherwise, if the work is a derivative of the Library, you may
269
+ distribute the object code for the work under the terms of Section 6.
270
+ Any executables containing that work also fall under Section 6,
271
+ whether or not they are linked directly with the Library itself.
272
+
273
+ 6. As an exception to the Sections above, you may also combine or
274
+ link a "work that uses the Library" with the Library to produce a
275
+ work containing portions of the Library, and distribute that work
276
+ under terms of your choice, provided that the terms permit
277
+ modification of the work for the customer's own use and reverse
278
+ engineering for debugging such modifications.
279
+
280
+ You must give prominent notice with each copy of the work that the
281
+ Library is used in it and that the Library and its use are covered by
282
+ this License. You must supply a copy of this License. If the work
283
+ during execution displays copyright notices, you must include the
284
+ copyright notice for the Library among them, as well as a reference
285
+ directing the user to the copy of this License. Also, you must do one
286
+ of these things:
287
+
288
+ a) Accompany the work with the complete corresponding
289
+ machine-readable source code for the Library including whatever
290
+ changes were used in the work (which must be distributed under
291
+ Sections 1 and 2 above); and, if the work is an executable linked
292
+ with the Library, with the complete machine-readable "work that
293
+ uses the Library", as object code and/or source code, so that the
294
+ user can modify the Library and then relink to produce a modified
295
+ executable containing the modified Library. (It is understood
296
+ that the user who changes the contents of definitions files in the
297
+ Library will not necessarily be able to recompile the application
298
+ to use the modified definitions.)
299
+
300
+ b) Use a suitable shared library mechanism for linking with the
301
+ Library. A suitable mechanism is one that (1) uses at run time a
302
+ copy of the library already present on the user's computer system,
303
+ rather than copying library functions into the executable, and (2)
304
+ will operate properly with a modified version of the library, if
305
+ the user installs one, as long as the modified version is
306
+ interface-compatible with the version that the work was made with.
307
+
308
+ c) Accompany the work with a written offer, valid for at least
309
+ three years, to give the same user the materials specified in
310
+ Subsection 6a, above, for a charge no more than the cost of
311
+ performing this distribution.
312
+
313
+ d) If distribution of the work is made by offering access to copy
314
+ from a designated place, offer equivalent access to copy the above
315
+ specified materials from the same place.
316
+
317
+ e) Verify that the user has already received a copy of these
318
+ materials or that you have already sent this user a copy.
319
+
320
+ For an executable, the required form of the "work that uses the
321
+ Library" must include any data and utility programs needed for
322
+ reproducing the executable from it. However, as a special exception,
323
+ the materials to be distributed need not include anything that is
324
+ normally distributed (in either source or binary form) with the major
325
+ components (compiler, kernel, and so on) of the operating system on
326
+ which the executable runs, unless that component itself accompanies
327
+ the executable.
328
+
329
+ It may happen that this requirement contradicts the license
330
+ restrictions of other proprietary libraries that do not normally
331
+ accompany the operating system. Such a contradiction means you cannot
332
+ use both them and the Library together in an executable that you
333
+ distribute.
334
+
335
+ 7. You may place library facilities that are a work based on the
336
+ Library side-by-side in a single library together with other library
337
+ facilities not covered by this License, and distribute such a combined
338
+ library, provided that the separate distribution of the work based on
339
+ the Library and of the other library facilities is otherwise
340
+ permitted, and provided that you do these two things:
341
+
342
+ a) Accompany the combined library with a copy of the same work
343
+ based on the Library, uncombined with any other library
344
+ facilities. This must be distributed under the terms of the
345
+ Sections above.
346
+
347
+ b) Give prominent notice with the combined library of the fact
348
+ that part of it is a work based on the Library, and explaining
349
+ where to find the accompanying uncombined form of the same work.
350
+
351
+ 8. You may not copy, modify, sublicense, link with, or distribute
352
+ the Library except as expressly provided under this License. Any
353
+ attempt otherwise to copy, modify, sublicense, link with, or
354
+ distribute the Library is void, and will automatically terminate your
355
+ rights under this License. However, parties who have received copies,
356
+ or rights, from you under this License will not have their licenses
357
+ terminated so long as such parties remain in full compliance.
358
+
359
+ 9. You are not required to accept this License, since you have not
360
+ signed it. However, nothing else grants you permission to modify or
361
+ distribute the Library or its derivative works. These actions are
362
+ prohibited by law if you do not accept this License. Therefore, by
363
+ modifying or distributing the Library (or any work based on the
364
+ Library), you indicate your acceptance of this License to do so, and
365
+ all its terms and conditions for copying, distributing or modifying
366
+ the Library or works based on it.
367
+
368
+ 10. Each time you redistribute the Library (or any work based on the
369
+ Library), the recipient automatically receives a license from the
370
+ original licensor to copy, distribute, link with or modify the Library
371
+ subject to these terms and conditions. You may not impose any further
372
+ restrictions on the recipients' exercise of the rights granted herein.
373
+ You are not responsible for enforcing compliance by third parties with
374
+ this License.
375
+
376
+ 11. If, as a consequence of a court judgment or allegation of patent
377
+ infringement or for any other reason (not limited to patent issues),
378
+ conditions are imposed on you (whether by court order, agreement or
379
+ otherwise) that contradict the conditions of this License, they do not
380
+ excuse you from the conditions of this License. If you cannot
381
+ distribute so as to satisfy simultaneously your obligations under this
382
+ License and any other pertinent obligations, then as a consequence you
383
+ may not distribute the Library at all. For example, if a patent
384
+ license would not permit royalty-free redistribution of the Library by
385
+ all those who receive copies directly or indirectly through you, then
386
+ the only way you could satisfy both it and this License would be to
387
+ refrain entirely from distribution of the Library.
388
+
389
+ If any portion of this section is held invalid or unenforceable under
390
+ any particular circumstance, the balance of the section is intended to
391
+ apply, and the section as a whole is intended to apply in other
392
+ circumstances.
393
+
394
+ It is not the purpose of this section to induce you to infringe any
395
+ patents or other property right claims or to contest validity of any
396
+ such claims; this section has the sole purpose of protecting the
397
+ integrity of the free software distribution system which is
398
+ implemented by public license practices. Many people have made
399
+ generous contributions to the wide range of software distributed
400
+ through that system in reliance on consistent application of that
401
+ system; it is up to the author/donor to decide if he or she is willing
402
+ to distribute software through any other system and a licensee cannot
403
+ impose that choice.
404
+
405
+ This section is intended to make thoroughly clear what is believed to
406
+ be a consequence of the rest of this License.
407
+
408
+ 12. If the distribution and/or use of the Library is restricted in
409
+ certain countries either by patents or by copyrighted interfaces, the
410
+ original copyright holder who places the Library under this License
411
+ may add an explicit geographical distribution limitation excluding those
412
+ countries, so that distribution is permitted only in or among
413
+ countries not thus excluded. In such case, this License incorporates
414
+ the limitation as if written in the body of this License.
415
+
416
+ 13. The Free Software Foundation may publish revised and/or new
417
+ versions of the Lesser General Public License from time to time.
418
+ Such new versions will be similar in spirit to the present version,
419
+ but may differ in detail to address new problems or concerns.
420
+
421
+ Each version is given a distinguishing version number. If the Library
422
+ specifies a version number of this License which applies to it and
423
+ "any later version", you have the option of following the terms and
424
+ conditions either of that version or of any later version published by
425
+ the Free Software Foundation. If the Library does not specify a
426
+ license version number, you may choose any version ever published by
427
+ the Free Software Foundation.
428
+
429
+ 14. If you wish to incorporate parts of the Library into other free
430
+ programs whose distribution conditions are incompatible with these,
431
+ write to the author to ask for permission. For software which is
432
+ copyrighted by the Free Software Foundation, write to the Free
433
+ Software Foundation; we sometimes make exceptions for this. Our
434
+ decision will be guided by the two goals of preserving the free status
435
+ of all derivatives of our free software and of promoting the sharing
436
+ and reuse of software generally.
437
+
438
+ NO WARRANTY
439
+
440
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
441
+ WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
442
+ EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
443
+ OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
444
+ KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
445
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
446
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
447
+ LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
448
+ THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
449
+
450
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
451
+ WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
452
+ AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
453
+ FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
454
+ CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
455
+ LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
456
+ RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
457
+ FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
458
+ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
459
+ DAMAGES.
460
+
461
+ END OF TERMS AND CONDITIONS
462
+
463
+ How to Apply These Terms to Your New Libraries
464
+
465
+ If you develop a new library, and you want it to be of the greatest
466
+ possible use to the public, we recommend making it free software that
467
+ everyone can redistribute and change. You can do so by permitting
468
+ redistribution under these terms (or, alternatively, under the terms
469
+ of the ordinary General Public License).
470
+
471
+ To apply these terms, attach the following notices to the library.
472
+ It is safest to attach them to the start of each source file to most
473
+ effectively convey the exclusion of warranty; and each file should
474
+ have at least the "copyright" line and a pointer to where the full
475
+ notice is found.
476
+
477
+
478
+ <one line to give the library's name and a brief idea of what it does.>
479
+ Copyright (C) <year> <name of author>
480
+
481
+ This library is free software; you can redistribute it and/or
482
+ modify it under the terms of the GNU Lesser General Public
483
+ License as published by the Free Software Foundation; either
484
+ version 2.1 of the License, or (at your option) any later version.
485
+
486
+ This library is distributed in the hope that it will be useful,
487
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
488
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
489
+ Lesser General Public License for more details.
490
+
491
+ You should have received a copy of the GNU Lesser General Public
492
+ License along with this library; if not, write to the Free Software
493
+ Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
494
+
495
+ Also add information on how to contact you by electronic and paper mail.
496
+
497
+ You should also get your employer (if you work as a programmer) or
498
+ your school, if any, to sign a "copyright disclaimer" for the library,
499
+ if necessary. Here is a sample; alter the names:
500
+
501
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
502
+ library `Frob' (a library for tweaking knobs) written by James
503
+ Random Hacker.
504
+
505
+ <signature of Ty Coon>, 1 April 1990
506
+ Ty Coon, President of Vice
507
+
508
+ That's all there is to it!
509
+
510
+
DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/Licenses/cairo/COPYING-MPL-1.1 ADDED
@@ -0,0 +1,470 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MOZILLA PUBLIC LICENSE
2
+ Version 1.1
3
+
4
+ ---------------
5
+
6
+ 1. Definitions.
7
+
8
+ 1.0.1. "Commercial Use" means distribution or otherwise making the
9
+ Covered Code available to a third party.
10
+
11
+ 1.1. "Contributor" means each entity that creates or contributes to
12
+ the creation of Modifications.
13
+
14
+ 1.2. "Contributor Version" means the combination of the Original
15
+ Code, prior Modifications used by a Contributor, and the Modifications
16
+ made by that particular Contributor.
17
+
18
+ 1.3. "Covered Code" means the Original Code or Modifications or the
19
+ combination of the Original Code and Modifications, in each case
20
+ including portions thereof.
21
+
22
+ 1.4. "Electronic Distribution Mechanism" means a mechanism generally
23
+ accepted in the software development community for the electronic
24
+ transfer of data.
25
+
26
+ 1.5. "Executable" means Covered Code in any form other than Source
27
+ Code.
28
+
29
+ 1.6. "Initial Developer" means the individual or entity identified
30
+ as the Initial Developer in the Source Code notice required by Exhibit
31
+ A.
32
+
33
+ 1.7. "Larger Work" means a work which combines Covered Code or
34
+ portions thereof with code not governed by the terms of this License.
35
+
36
+ 1.8. "License" means this document.
37
+
38
+ 1.8.1. "Licensable" means having the right to grant, to the maximum
39
+ extent possible, whether at the time of the initial grant or
40
+ subsequently acquired, any and all of the rights conveyed herein.
41
+
42
+ 1.9. "Modifications" means any addition to or deletion from the
43
+ substance or structure of either the Original Code or any previous
44
+ Modifications. When Covered Code is released as a series of files, a
45
+ Modification is:
46
+ A. Any addition to or deletion from the contents of a file
47
+ containing Original Code or previous Modifications.
48
+
49
+ B. Any new file that contains any part of the Original Code or
50
+ previous Modifications.
51
+
52
+ 1.10. "Original Code" means Source Code of computer software code
53
+ which is described in the Source Code notice required by Exhibit A as
54
+ Original Code, and which, at the time of its release under this
55
+ License is not already Covered Code governed by this License.
56
+
57
+ 1.10.1. "Patent Claims" means any patent claim(s), now owned or
58
+ hereafter acquired, including without limitation, method, process,
59
+ and apparatus claims, in any patent Licensable by grantor.
60
+
61
+ 1.11. "Source Code" means the preferred form of the Covered Code for
62
+ making modifications to it, including all modules it contains, plus
63
+ any associated interface definition files, scripts used to control
64
+ compilation and installation of an Executable, or source code
65
+ differential comparisons against either the Original Code or another
66
+ well known, available Covered Code of the Contributor's choice. The
67
+ Source Code can be in a compressed or archival form, provided the
68
+ appropriate decompression or de-archiving software is widely available
69
+ for no charge.
70
+
71
+ 1.12. "You" (or "Your") means an individual or a legal entity
72
+ exercising rights under, and complying with all of the terms of, this
73
+ License or a future version of this License issued under Section 6.1.
74
+ For legal entities, "You" includes any entity which controls, is
75
+ controlled by, or is under common control with You. For purposes of
76
+ this definition, "control" means (a) the power, direct or indirect,
77
+ to cause the direction or management of such entity, whether by
78
+ contract or otherwise, or (b) ownership of more than fifty percent
79
+ (50%) of the outstanding shares or beneficial ownership of such
80
+ entity.
81
+
82
+ 2. Source Code License.
83
+
84
+ 2.1. The Initial Developer Grant.
85
+ The Initial Developer hereby grants You a world-wide, royalty-free,
86
+ non-exclusive license, subject to third party intellectual property
87
+ claims:
88
+ (a) under intellectual property rights (other than patent or
89
+ trademark) Licensable by Initial Developer to use, reproduce,
90
+ modify, display, perform, sublicense and distribute the Original
91
+ Code (or portions thereof) with or without Modifications, and/or
92
+ as part of a Larger Work; and
93
+
94
+ (b) under Patents Claims infringed by the making, using or
95
+ selling of Original Code, to make, have made, use, practice,
96
+ sell, and offer for sale, and/or otherwise dispose of the
97
+ Original Code (or portions thereof).
98
+
99
+ (c) the licenses granted in this Section 2.1(a) and (b) are
100
+ effective on the date Initial Developer first distributes
101
+ Original Code under the terms of this License.
102
+
103
+ (d) Notwithstanding Section 2.1(b) above, no patent license is
104
+ granted: 1) for code that You delete from the Original Code; 2)
105
+ separate from the Original Code; or 3) for infringements caused
106
+ by: i) the modification of the Original Code or ii) the
107
+ combination of the Original Code with other software or devices.
108
+
109
+ 2.2. Contributor Grant.
110
+ Subject to third party intellectual property claims, each Contributor
111
+ hereby grants You a world-wide, royalty-free, non-exclusive license
112
+
113
+ (a) under intellectual property rights (other than patent or
114
+ trademark) Licensable by Contributor, to use, reproduce, modify,
115
+ display, perform, sublicense and distribute the Modifications
116
+ created by such Contributor (or portions thereof) either on an
117
+ unmodified basis, with other Modifications, as Covered Code
118
+ and/or as part of a Larger Work; and
119
+
120
+ (b) under Patent Claims infringed by the making, using, or
121
+ selling of Modifications made by that Contributor either alone
122
+ and/or in combination with its Contributor Version (or portions
123
+ of such combination), to make, use, sell, offer for sale, have
124
+ made, and/or otherwise dispose of: 1) Modifications made by that
125
+ Contributor (or portions thereof); and 2) the combination of
126
+ Modifications made by that Contributor with its Contributor
127
+ Version (or portions of such combination).
128
+
129
+ (c) the licenses granted in Sections 2.2(a) and 2.2(b) are
130
+ effective on the date Contributor first makes Commercial Use of
131
+ the Covered Code.
132
+
133
+ (d) Notwithstanding Section 2.2(b) above, no patent license is
134
+ granted: 1) for any code that Contributor has deleted from the
135
+ Contributor Version; 2) separate from the Contributor Version;
136
+ 3) for infringements caused by: i) third party modifications of
137
+ Contributor Version or ii) the combination of Modifications made
138
+ by that Contributor with other software (except as part of the
139
+ Contributor Version) or other devices; or 4) under Patent Claims
140
+ infringed by Covered Code in the absence of Modifications made by
141
+ that Contributor.
142
+
143
+ 3. Distribution Obligations.
144
+
145
+ 3.1. Application of License.
146
+ The Modifications which You create or to which You contribute are
147
+ governed by the terms of this License, including without limitation
148
+ Section 2.2. The Source Code version of Covered Code may be
149
+ distributed only under the terms of this License or a future version
150
+ of this License released under Section 6.1, and You must include a
151
+ copy of this License with every copy of the Source Code You
152
+ distribute. You may not offer or impose any terms on any Source Code
153
+ version that alters or restricts the applicable version of this
154
+ License or the recipients' rights hereunder. However, You may include
155
+ an additional document offering the additional rights described in
156
+ Section 3.5.
157
+
158
+ 3.2. Availability of Source Code.
159
+ Any Modification which You create or to which You contribute must be
160
+ made available in Source Code form under the terms of this License
161
+ either on the same media as an Executable version or via an accepted
162
+ Electronic Distribution Mechanism to anyone to whom you made an
163
+ Executable version available; and if made available via Electronic
164
+ Distribution Mechanism, must remain available for at least twelve (12)
165
+ months after the date it initially became available, or at least six
166
+ (6) months after a subsequent version of that particular Modification
167
+ has been made available to such recipients. You are responsible for
168
+ ensuring that the Source Code version remains available even if the
169
+ Electronic Distribution Mechanism is maintained by a third party.
170
+
171
+ 3.3. Description of Modifications.
172
+ You must cause all Covered Code to which You contribute to contain a
173
+ file documenting the changes You made to create that Covered Code and
174
+ the date of any change. You must include a prominent statement that
175
+ the Modification is derived, directly or indirectly, from Original
176
+ Code provided by the Initial Developer and including the name of the
177
+ Initial Developer in (a) the Source Code, and (b) in any notice in an
178
+ Executable version or related documentation in which You describe the
179
+ origin or ownership of the Covered Code.
180
+
181
+ 3.4. Intellectual Property Matters
182
+ (a) Third Party Claims.
183
+ If Contributor has knowledge that a license under a third party's
184
+ intellectual property rights is required to exercise the rights
185
+ granted by such Contributor under Sections 2.1 or 2.2,
186
+ Contributor must include a text file with the Source Code
187
+ distribution titled "LEGAL" which describes the claim and the
188
+ party making the claim in sufficient detail that a recipient will
189
+ know whom to contact. If Contributor obtains such knowledge after
190
+ the Modification is made available as described in Section 3.2,
191
+ Contributor shall promptly modify the LEGAL file in all copies
192
+ Contributor makes available thereafter and shall take other steps
193
+ (such as notifying appropriate mailing lists or newsgroups)
194
+ reasonably calculated to inform those who received the Covered
195
+ Code that new knowledge has been obtained.
196
+
197
+ (b) Contributor APIs.
198
+ If Contributor's Modifications include an application programming
199
+ interface and Contributor has knowledge of patent licenses which
200
+ are reasonably necessary to implement that API, Contributor must
201
+ also include this information in the LEGAL file.
202
+
203
+ (c) Representations.
204
+ Contributor represents that, except as disclosed pursuant to
205
+ Section 3.4(a) above, Contributor believes that Contributor's
206
+ Modifications are Contributor's original creation(s) and/or
207
+ Contributor has sufficient rights to grant the rights conveyed by
208
+ this License.
209
+
210
+ 3.5. Required Notices.
211
+ You must duplicate the notice in Exhibit A in each file of the Source
212
+ Code. If it is not possible to put such notice in a particular Source
213
+ Code file due to its structure, then You must include such notice in a
214
+ location (such as a relevant directory) where a user would be likely
215
+ to look for such a notice. If You created one or more Modification(s)
216
+ You may add your name as a Contributor to the notice described in
217
+ Exhibit A. You must also duplicate this License in any documentation
218
+ for the Source Code where You describe recipients' rights or ownership
219
+ rights relating to Covered Code. You may choose to offer, and to
220
+ charge a fee for, warranty, support, indemnity or liability
221
+ obligations to one or more recipients of Covered Code. However, You
222
+ may do so only on Your own behalf, and not on behalf of the Initial
223
+ Developer or any Contributor. You must make it absolutely clear than
224
+ any such warranty, support, indemnity or liability obligation is
225
+ offered by You alone, and You hereby agree to indemnify the Initial
226
+ Developer and every Contributor for any liability incurred by the
227
+ Initial Developer or such Contributor as a result of warranty,
228
+ support, indemnity or liability terms You offer.
229
+
230
+ 3.6. Distribution of Executable Versions.
231
+ You may distribute Covered Code in Executable form only if the
232
+ requirements of Section 3.1-3.5 have been met for that Covered Code,
233
+ and if You include a notice stating that the Source Code version of
234
+ the Covered Code is available under the terms of this License,
235
+ including a description of how and where You have fulfilled the
236
+ obligations of Section 3.2. The notice must be conspicuously included
237
+ in any notice in an Executable version, related documentation or
238
+ collateral in which You describe recipients' rights relating to the
239
+ Covered Code. You may distribute the Executable version of Covered
240
+ Code or ownership rights under a license of Your choice, which may
241
+ contain terms different from this License, provided that You are in
242
+ compliance with the terms of this License and that the license for the
243
+ Executable version does not attempt to limit or alter the recipient's
244
+ rights in the Source Code version from the rights set forth in this
245
+ License. If You distribute the Executable version under a different
246
+ license You must make it absolutely clear that any terms which differ
247
+ from this License are offered by You alone, not by the Initial
248
+ Developer or any Contributor. You hereby agree to indemnify the
249
+ Initial Developer and every Contributor for any liability incurred by
250
+ the Initial Developer or such Contributor as a result of any such
251
+ terms You offer.
252
+
253
+ 3.7. Larger Works.
254
+ You may create a Larger Work by combining Covered Code with other code
255
+ not governed by the terms of this License and distribute the Larger
256
+ Work as a single product. In such a case, You must make sure the
257
+ requirements of this License are fulfilled for the Covered Code.
258
+
259
+ 4. Inability to Comply Due to Statute or Regulation.
260
+
261
+ If it is impossible for You to comply with any of the terms of this
262
+ License with respect to some or all of the Covered Code due to
263
+ statute, judicial order, or regulation then You must: (a) comply with
264
+ the terms of this License to the maximum extent possible; and (b)
265
+ describe the limitations and the code they affect. Such description
266
+ must be included in the LEGAL file described in Section 3.4 and must
267
+ be included with all distributions of the Source Code. Except to the
268
+ extent prohibited by statute or regulation, such description must be
269
+ sufficiently detailed for a recipient of ordinary skill to be able to
270
+ understand it.
271
+
272
+ 5. Application of this License.
273
+
274
+ This License applies to code to which the Initial Developer has
275
+ attached the notice in Exhibit A and to related Covered Code.
276
+
277
+ 6. Versions of the License.
278
+
279
+ 6.1. New Versions.
280
+ Netscape Communications Corporation ("Netscape") may publish revised
281
+ and/or new versions of the License from time to time. Each version
282
+ will be given a distinguishing version number.
283
+
284
+ 6.2. Effect of New Versions.
285
+ Once Covered Code has been published under a particular version of the
286
+ License, You may always continue to use it under the terms of that
287
+ version. You may also choose to use such Covered Code under the terms
288
+ of any subsequent version of the License published by Netscape. No one
289
+ other than Netscape has the right to modify the terms applicable to
290
+ Covered Code created under this License.
291
+
292
+ 6.3. Derivative Works.
293
+ If You create or use a modified version of this License (which you may
294
+ only do in order to apply it to code which is not already Covered Code
295
+ governed by this License), You must (a) rename Your license so that
296
+ the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape",
297
+ "MPL", "NPL" or any confusingly similar phrase do not appear in your
298
+ license (except to note that your license differs from this License)
299
+ and (b) otherwise make it clear that Your version of the license
300
+ contains terms which differ from the Mozilla Public License and
301
+ Netscape Public License. (Filling in the name of the Initial
302
+ Developer, Original Code or Contributor in the notice described in
303
+ Exhibit A shall not of themselves be deemed to be modifications of
304
+ this License.)
305
+
306
+ 7. DISCLAIMER OF WARRANTY.
307
+
308
+ COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS,
309
+ WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
310
+ WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF
311
+ DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING.
312
+ THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE
313
+ IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT,
314
+ YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
315
+ COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER
316
+ OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
317
+ ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
318
+
319
+ 8. TERMINATION.
320
+
321
+ 8.1. This License and the rights granted hereunder will terminate
322
+ automatically if You fail to comply with terms herein and fail to cure
323
+ such breach within 30 days of becoming aware of the breach. All
324
+ sublicenses to the Covered Code which are properly granted shall
325
+ survive any termination of this License. Provisions which, by their
326
+ nature, must remain in effect beyond the termination of this License
327
+ shall survive.
328
+
329
+ 8.2. If You initiate litigation by asserting a patent infringement
330
+ claim (excluding declatory judgment actions) against Initial Developer
331
+ or a Contributor (the Initial Developer or Contributor against whom
332
+ You file such action is referred to as "Participant") alleging that:
333
+
334
+ (a) such Participant's Contributor Version directly or indirectly
335
+ infringes any patent, then any and all rights granted by such
336
+ Participant to You under Sections 2.1 and/or 2.2 of this License
337
+ shall, upon 60 days notice from Participant terminate prospectively,
338
+ unless if within 60 days after receipt of notice You either: (i)
339
+ agree in writing to pay Participant a mutually agreeable reasonable
340
+ royalty for Your past and future use of Modifications made by such
341
+ Participant, or (ii) withdraw Your litigation claim with respect to
342
+ the Contributor Version against such Participant. If within 60 days
343
+ of notice, a reasonable royalty and payment arrangement are not
344
+ mutually agreed upon in writing by the parties or the litigation claim
345
+ is not withdrawn, the rights granted by Participant to You under
346
+ Sections 2.1 and/or 2.2 automatically terminate at the expiration of
347
+ the 60 day notice period specified above.
348
+
349
+ (b) any software, hardware, or device, other than such Participant's
350
+ Contributor Version, directly or indirectly infringes any patent, then
351
+ any rights granted to You by such Participant under Sections 2.1(b)
352
+ and 2.2(b) are revoked effective as of the date You first made, used,
353
+ sold, distributed, or had made, Modifications made by that
354
+ Participant.
355
+
356
+ 8.3. If You assert a patent infringement claim against Participant
357
+ alleging that such Participant's Contributor Version directly or
358
+ indirectly infringes any patent where such claim is resolved (such as
359
+ by license or settlement) prior to the initiation of patent
360
+ infringement litigation, then the reasonable value of the licenses
361
+ granted by such Participant under Sections 2.1 or 2.2 shall be taken
362
+ into account in determining the amount or value of any payment or
363
+ license.
364
+
365
+ 8.4. In the event of termination under Sections 8.1 or 8.2 above,
366
+ all end user license agreements (excluding distributors and resellers)
367
+ which have been validly granted by You or any distributor hereunder
368
+ prior to termination shall survive termination.
369
+
370
+ 9. LIMITATION OF LIABILITY.
371
+
372
+ UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
373
+ (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL
374
+ DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE,
375
+ OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR
376
+ ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY
377
+ CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL,
378
+ WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
379
+ COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
380
+ INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
381
+ LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY
382
+ RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW
383
+ PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
384
+ EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO
385
+ THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
386
+
387
+ 10. U.S. GOVERNMENT END USERS.
388
+
389
+ The Covered Code is a "commercial item," as that term is defined in
390
+ 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer
391
+ software" and "commercial computer software documentation," as such
392
+ terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48
393
+ C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
394
+ all U.S. Government End Users acquire Covered Code with only those
395
+ rights set forth herein.
396
+
397
+ 11. MISCELLANEOUS.
398
+
399
+ This License represents the complete agreement concerning subject
400
+ matter hereof. If any provision of this License is held to be
401
+ unenforceable, such provision shall be reformed only to the extent
402
+ necessary to make it enforceable. This License shall be governed by
403
+ California law provisions (except to the extent applicable law, if
404
+ any, provides otherwise), excluding its conflict-of-law provisions.
405
+ With respect to disputes in which at least one party is a citizen of,
406
+ or an entity chartered or registered to do business in the United
407
+ States of America, any litigation relating to this License shall be
408
+ subject to the jurisdiction of the Federal Courts of the Northern
409
+ District of California, with venue lying in Santa Clara County,
410
+ California, with the losing party responsible for costs, including
411
+ without limitation, court costs and reasonable attorneys' fees and
412
+ expenses. The application of the United Nations Convention on
413
+ Contracts for the International Sale of Goods is expressly excluded.
414
+ Any law or regulation which provides that the language of a contract
415
+ shall be construed against the drafter shall not apply to this
416
+ License.
417
+
418
+ 12. RESPONSIBILITY FOR CLAIMS.
419
+
420
+ As between Initial Developer and the Contributors, each party is
421
+ responsible for claims and damages arising, directly or indirectly,
422
+ out of its utilization of rights under this License and You agree to
423
+ work with Initial Developer and Contributors to distribute such
424
+ responsibility on an equitable basis. Nothing herein is intended or
425
+ shall be deemed to constitute any admission of liability.
426
+
427
+ 13. MULTIPLE-LICENSED CODE.
428
+
429
+ Initial Developer may designate portions of the Covered Code as
430
+ "Multiple-Licensed". "Multiple-Licensed" means that the Initial
431
+ Developer permits you to utilize portions of the Covered Code under
432
+ Your choice of the NPL or the alternative licenses, if any, specified
433
+ by the Initial Developer in the file described in Exhibit A.
434
+
435
+ EXHIBIT A -Mozilla Public License.
436
+
437
+ ``The contents of this file are subject to the Mozilla Public License
438
+ Version 1.1 (the "License"); you may not use this file except in
439
+ compliance with the License. You may obtain a copy of the License at
440
+ http://www.mozilla.org/MPL/
441
+
442
+ Software distributed under the License is distributed on an "AS IS"
443
+ basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
444
+ License for the specific language governing rights and limitations
445
+ under the License.
446
+
447
+ The Original Code is ______________________________________.
448
+
449
+ The Initial Developer of the Original Code is ________________________.
450
+ Portions created by ______________________ are Copyright (C) ______
451
+ _______________________. All Rights Reserved.
452
+
453
+ Contributor(s): ______________________________________.
454
+
455
+ Alternatively, the contents of this file may be used under the terms
456
+ of the _____ license (the "[___] License"), in which case the
457
+ provisions of [______] License are applicable instead of those
458
+ above. If you wish to allow use of your version of this file only
459
+ under the terms of the [____] License and not to allow others to use
460
+ your version of this file under the MPL, indicate your decision by
461
+ deleting the provisions above and replace them with the notice and
462
+ other provisions required by the [___] License. If you do not delete
463
+ the provisions above, a recipient may use your version of this file
464
+ under either the MPL or the [___] License."
465
+
466
+ [NOTE: The text of this Exhibit A may differ slightly from the text of
467
+ the notices in the Source Code files of the Original Code. You should
468
+ use the text of this Exhibit A rather than the text found in the
469
+ Original Code Source Code for Your Modifications.]
470
+
DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/Licenses/pcre2/COPYING ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ PCRE2 LICENCE
2
+
3
+ Please see the file LICENCE in the PCRE2 distribution for licensing details.
4
+
5
+ End
DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/Licenses/pixman/COPYING ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ The following is the MIT license, agreed upon by most contributors.
2
+ Copyright holders of new code should use this license statement where
3
+ possible. They may also add themselves to the list below.
4
+
5
+ /*
6
+ * Copyright 1987, 1988, 1989, 1998 The Open Group
7
+ * Copyright 1987, 1988, 1989 Digital Equipment Corporation
8
+ * Copyright 1999, 2004, 2008 Keith Packard
9
+ * Copyright 2000 SuSE, Inc.
10
+ * Copyright 2000 Keith Packard, member of The XFree86 Project, Inc.
11
+ * Copyright 2004, 2005, 2007, 2008, 2009, 2010 Red Hat, Inc.
12
+ * Copyright 2004 Nicholas Miell
13
+ * Copyright 2005 Lars Knoll & Zack Rusin, Trolltech
14
+ * Copyright 2005 Trolltech AS
15
+ * Copyright 2007 Luca Barbato
16
+ * Copyright 2008 Aaron Plattner, NVIDIA Corporation
17
+ * Copyright 2008 Rodrigo Kumpera
18
+ * Copyright 2008 André Tupinambá
19
+ * Copyright 2008 Mozilla Corporation
20
+ * Copyright 2008 Frederic Plourde
21
+ * Copyright 2009, Oracle and/or its affiliates. All rights reserved.
22
+ * Copyright 2009, 2010 Nokia Corporation
23
+ *
24
+ * Permission is hereby granted, free of charge, to any person obtaining a
25
+ * copy of this software and associated documentation files (the "Software"),
26
+ * to deal in the Software without restriction, including without limitation
27
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
28
+ * and/or sell copies of the Software, and to permit persons to whom the
29
+ * Software is furnished to do so, subject to the following conditions:
30
+ *
31
+ * The above copyright notice and this permission notice (including the next
32
+ * paragraph) shall be included in all copies or substantial portions of the
33
+ * Software.
34
+ *
35
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
38
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
40
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
41
+ * DEALINGS IN THE SOFTWARE.
42
+ */
DISPLAYER/Displayer.app/Adobe AIR/Versions/1.0/Resources/adobecp.vch ADDED
File without changes
DISPLAYER/Displayer.app/Displayer.exe ADDED
Binary file (84 kB). View file
 
DISPLAYER/Displayer.app/Displayer.swf ADDED
Binary file (3.56 kB). View file
 
DISPLAYER/Displayer.app/META-INF/AIR/application.xml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8" standalone="no" ?>
2
+ <!--
3
+ Usage:
4
+
5
+ To localize the description, use the following format for the description element.
6
+ <description>
7
+ <text xml:lang="en">English App description goes here</text>
8
+ <text xml:lang="fr">French App description goes here</text>
9
+ <text xml:lang="ja">Japanese App description goes here</text>
10
+ </description>
11
+
12
+ To localize the name, use the following format for the name element.
13
+ <name>
14
+ <text xml:lang="en">English App name goes here</text>
15
+ <text xml:lang="fr">French App name goes here</text>
16
+ <text xml:lang="ja">Japanese App name goes here</text>
17
+ </name>
18
+ -->
19
+ <application xmlns="http://ns.adobe.com/air/application/50.2">
20
+ <id>Displayer</id>
21
+ <versionNumber>1.0</versionNumber>
22
+ <filename>Displayer</filename>
23
+ <description/>
24
+ <name>Displayer</name>
25
+ <copyright/>
26
+ <initialWindow>
27
+ <content>Displayer.swf</content>
28
+ <systemChrome>standard</systemChrome>
29
+ <transparent>false</transparent>
30
+ <visible>true</visible>
31
+ <fullScreen>false</fullScreen>
32
+ <aspectRatio>portrait</aspectRatio>
33
+ <renderMode>auto</renderMode>
34
+ </initialWindow>
35
+ <icon/>
36
+ <customUpdateUI>false</customUpdateUI>
37
+ <allowBrowserInvocation>false</allowBrowserInvocation>
38
+ </application>
DISPLAYER/Displayer.app/META-INF/AIR/hash ADDED
@@ -0,0 +1 @@
 
 
1
+ *�x�\4�b�?ʈϱm���D��R�V�
DISPLAYER/Displayer.app/META-INF/signatures.xml ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <signatures>
2
+ <Signature xmlns="http://www.w3.org/2000/09/xmldsig#" Id="PackageSignature">
3
+ <SignedInfo>
4
+ <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
5
+ <SignatureMethod Algorithm="http://www.w3.org/TR/xmldsig-core#rsa-sha1"/>
6
+ <Reference URI="#PackageContents">
7
+ <Transforms>
8
+ <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
9
+ </Transforms>
10
+ <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
11
+ <DigestValue>8JU2vTHQXxN+oG7ajfcPThFxZw+4HaE/W1R701X0HmI=</DigestValue>
12
+ </Reference>
13
+ </SignedInfo>
14
+ <SignatureValue Id="PackageSignatureValue">Mh+++p7/aMCK6BDStU/uDfzIIDCkrRNIXilx77yZefzun3+wxjcDJgw5HQWfNe0HU+WzOBQTaVQE
15
+ g+hg36BRV5Nnt1r+aMuFnJ1VPck6oBR4zjcyhUa2flUHa5iki1hXXSYO+451XDXwsE8cWri4V7bj
16
+ cHw573SbPOUZsQ3VeQ1mw4WAlrKVPX4nE9sBQXqXmLqk73sFIxalKI9LnjGeHFsOWjbgauqnNF7r
17
+ kE4ANsyRAkwK8ypWeuvY9T6Yi4pL/K4q7uSi81xFwv6Cmdj9/f00N1JukBrnkIRM87sx53F3+Pse
18
+ 7ahqlLuuGXazzSzZ7MaQS0xLqePgOQXkR+z2ng==</SignatureValue>
19
+ <KeyInfo>
20
+ <X509Data>
21
+ <X509Certificate>MIIDNTCCAh2gAwIBAgIYODVmMDU4OjE4Zjg4NzgxZDQ2Oi04MDAwMA0GCSqGSIb3DQEBCwUAMEYx
22
+ CzAJBgNVBAYTAlVTMREwDwYDVQQKEwhJbm1lbnRhbDERMA8GA1UECxMISW5tZW50YWwxETAPBgNV
23
+ BAMTCElubWVudGFsMB4XDTI0MDUxNjIxMzIwNFoXDTQ5MDUxNzIxMzIwNFowRjELMAkGA1UEBhMC
24
+ VVMxETAPBgNVBAoTCElubWVudGFsMREwDwYDVQQLEwhJbm1lbnRhbDERMA8GA1UEAxMISW5tZW50
25
+ YWwwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCd5NZFzGtSp1bMuO9F96YKJdl92UnG
26
+ oBj8cj2rZsjMMyK+lcoiy4oWDFsqSLJoouJ3fRd1Gi56tqPlUyLSOfvGUbJk9IAh49KJYIdIqX18
27
+ GYq+FAlXS4zxvTs1rSQPly7eE495zYrW9CkVfSIl7BrNdQOPDoAg2JO2QhucUHom4fpd3amuitxD
28
+ 4QISGrzurLW6WHK5zFAnCKeO/CErOT0VV25SplRU/tr9xf9bQf0QEiS9hbuW1ZJh1P5MN9I3YUoV
29
+ 70gdFghnlgpsvmiA5j0zZdEFvj24+88o0FgL9gpZOsz/ezSRKC130GoNX0GNWIQLTgSAlWmfC/Yb
30
+ y5Ec2z7BAgMBAAGjFzAVMBMGA1UdJQQMMAoGCCsGAQUFBwMDMA0GCSqGSIb3DQEBCwUAA4IBAQCK
31
+ BcC/oA6as+QAJCzq5GeQxBnmfdlcPtOmfnIDv2yHpUw2gWnK0T9mH5XRfZsPb3y0l8EGTglMVm/S
32
+ gKrj6/HaS+d7Rvth8NNh4PmB1n5Tr2hh0ZdiK25Ph/Tc4GGk03j1FLcfy/Hanm137y1A2DpVdpch
33
+ YZs2LNorpdcqqjSgV4kHuMHtr5oL3fhD5Pgajoiy26vnslXsEjqqBgiwuc+3thN/rPWhQU2sLnzZ
34
+ Batun4MoatD0BGXT/VtJAYG8fJvQPyhNLrM8eXITl2/tkBHk3Mpd7ZMSe9WJbhLhp71OdK85XXo1
35
+ tRZggoqrlXN+3CJipLneIVlisSwqE4yB6hHs</X509Certificate>
36
+ </X509Data>
37
+ </KeyInfo>
38
+ <Object>
39
+ <Manifest Id="PackageContents">
40
+ <Reference URI="Displayer.swf"><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></DigestMethod><DigestValue>iukCSL+g97J7EboaWUezqKdwUou3wnQCYx8+27b24Bg=</DigestValue></Reference><Reference URI="META-INF/AIR/application.xml"><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></DigestMethod><DigestValue>b2hRKplC0bw3Cp0DaigsxuOcCGsL1RRnkYUxZ/hQOMY=</DigestValue></Reference><Reference URI="config.json"><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></DigestMethod><DigestValue>DHqY+sRs8drd4UUTYbab/OJkPSajd5CrU8r49eur8bE=</DigestValue></Reference><Reference URI="mimetype"><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></DigestMethod><DigestValue>0/oCb84THKMagtI0Dy0KogEu92TegdesqRr/clXct1c=</DigestValue></Reference>
41
+ </Manifest>
42
+ </Object>
43
+ <Object xmlns:xades="http://uri.etsi.org/01903/v1.1.1#" >
44
+ <xades:QualifyingProperties>
45
+ <xades:UnsignedProperties >
46
+ <xades:UnsignedSignatureProperties>
47
+ <xades:SignatureTimeStamp>
48
+ <xades:HashDataInfo uri="#PackageSignatureValue">
49
+ <Transforms>
50
+ <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
51
+ </Transforms>
52
+ <xades:EncapsulatedTimeStamp>
53
+ MIIOEwYJKoZIhvcNAQcCoIIOBDCCDgACAQMxDTALBglghkgBZQMEAgEwgf4GCyqGSIb3DQEJEAEE
54
+ oIHuBIHrMIHoAgEBBgtghkgBhvhFAQcXAzAhMAkGBSsOAwIaBQAEFJo2K9rurjIHaAT9QMO+qs4h
55
+ kp8dAhQhfTO+0bRYfMJ9WP0qlqG5X2d3WRgPMjAyNDA4MTQxNzI5MDNaMAMCAR6ggYakgYMwgYAx
56
+ CzAJBgNVBAYTAlVTMR0wGwYDVQQKExRTeW1hbnRlYyBDb3Jwb3JhdGlvbjEfMB0GA1UECxMWU3lt
57
+ YW50ZWMgVHJ1c3QgTmV0d29yazExMC8GA1UEAxMoU3ltYW50ZWMgU0hBMjU2IFRpbWVTdGFtcGlu
58
+ ZyBTaWduZXIgLSBHM6CCCoswggU4MIIEIKADAgECAhB7BbHUSWhRRPfJidKcGZ0SMA0GCSqGSIb3
59
+ DQEBCwUAMIG9MQswCQYDVQQGEwJVUzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsT
60
+ FlZlcmlTaWduIFRydXN0IE5ldHdvcmsxOjA4BgNVBAsTMShjKSAyMDA4IFZlcmlTaWduLCBJbmMu
61
+ IC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxODA2BgNVBAMTL1ZlcmlTaWduIFVuaXZlcnNhbCBS
62
+ b290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTE2MDExMjAwMDAwMFoXDTMxMDExMTIzNTk1
63
+ OVowdzELMAkGA1UEBhMCVVMxHTAbBgNVBAoTFFN5bWFudGVjIENvcnBvcmF0aW9uMR8wHQYDVQQL
64
+ ExZTeW1hbnRlYyBUcnVzdCBOZXR3b3JrMSgwJgYDVQQDEx9TeW1hbnRlYyBTSEEyNTYgVGltZVN0
65
+ YW1waW5nIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu1mdWVVPnYxyXRqBoutV
66
+ 87ABrTxxrDKPBWuGmicAMpdqTclkFEspu8LZKbku7GOz4c8/C1aQ+GIbfuumB+Lef15tQDjUkQbn
67
+ QXx5HMvLrRu/2JWR8/DubPitljkuf8EnuHg5xYSl7e2vh47Ojcdt6tKYtTofHjmdw/SaqPSE4cTR
68
+ fHHGBim0P+SDDSbDewg+TfkKtzNJ/8o71PWym0vhiJka9cDpMxTW38eA25Hu/rySV3J39M2ozP4J
69
+ 9ZM3vpWIasXc9LFL1M7oCZFftYR5NYp4rBkyjyPBMkEbWQ6pPrHM+dYr77fY5NUdbRE6kvaTyZzj
70
+ SO67Uw7UNpeGeMWhNwIDAQABo4IBdzCCAXMwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYB
71
+ Af8CAQAwZgYDVR0gBF8wXTBbBgtghkgBhvhFAQcXAzBMMCMGCCsGAQUFBwIBFhdodHRwczovL2Qu
72
+ c3ltY2IuY29tL2NwczAlBggrBgEFBQcCAjAZGhdodHRwczovL2Quc3ltY2IuY29tL3JwYTAuBggr
73
+ BgEFBQcBAQQiMCAwHgYIKwYBBQUHMAGGEmh0dHA6Ly9zLnN5bWNkLmNvbTA2BgNVHR8ELzAtMCug
74
+ KaAnhiVodHRwOi8vcy5zeW1jYi5jb20vdW5pdmVyc2FsLXJvb3QuY3JsMBMGA1UdJQQMMAoGCCsG
75
+ AQUFBwMIMCgGA1UdEQQhMB+kHTAbMRkwFwYDVQQDExBUaW1lU3RhbXAtMjA0OC0zMB0GA1UdDgQW
76
+ BBSvY9bKo06FcuCnvEHzKaI4f4B1YjAfBgNVHSMEGDAWgBS2d/ppSEefUxLVwuoHMnYH0ZcHGTAN
77
+ BgkqhkiG9w0BAQsFAAOCAQEAdeqwLdU0GVwyRf4O4dRPpnjBb9fq3dxP86HIgYj3p48V5kApreZd
78
+ 9KLZVmSEcTAq3R5hF2YgVgaYGY1dcfL4l7wJ/RyRR8ni6I0D+8yQL9YKbE4z7Na0k8hMkGNIOUAh
79
+ xN3WbomYPLWYl+ipBrcJyY9TV0GQL+EeTU7cyhB4bEJu8LbF+GFcUvVO9muN90p6vvPN/QPX2fYD
80
+ qA/jU/cKdezGdS6qZoUEmbf4Blfhxg726K/a7JsYH6q54zoAv86KlMsB257HOLsPUqvR45QDYApN
81
+ oP4nbRQy/D+XQOG/mYnb5DkUvdrk08PqK1qzlVhVBH3HmuwjA42FKtL/rqlhgTCCBUswggQzoAMC
82
+ AQICEHvU5a+6zAc/oQEjBCJBTRIwDQYJKoZIhvcNAQELBQAwdzELMAkGA1UEBhMCVVMxHTAbBgNV
83
+ BAoTFFN5bWFudGVjIENvcnBvcmF0aW9uMR8wHQYDVQQLExZTeW1hbnRlYyBUcnVzdCBOZXR3b3Jr
84
+ MSgwJgYDVQQDEx9TeW1hbnRlYyBTSEEyNTYgVGltZVN0YW1waW5nIENBMB4XDTE3MTIyMzAwMDAw
85
+ MFoXDTI5MDMyMjIzNTk1OVowgYAxCzAJBgNVBAYTAlVTMR0wGwYDVQQKExRTeW1hbnRlYyBDb3Jw
86
+ b3JhdGlvbjEfMB0GA1UECxMWU3ltYW50ZWMgVHJ1c3QgTmV0d29yazExMC8GA1UEAxMoU3ltYW50
87
+ ZWMgU0hBMjU2IFRpbWVTdGFtcGluZyBTaWduZXIgLSBHMzCCASIwDQYJKoZIhvcNAQEBBQADggEP
88
+ ADCCAQoCggEBAK8Oiqr43L9pe1QXcUcJvY08gfh0FXdnkJz93k4Cnkt29uU2PmXVJCBtMPndHYPp
89
+ PydKM05tForkjUCNIqq+pwsb0ge2PLUaJCj4G3JRPcgJiCYIOvn6QyN1R3AMs19bjwgdckhXZU2v
90
+ AjxA9/TdMjiTP+UspvNZI8uA3hNN+RDJqgoYbFVhV9HxAizEtavybCPSnw0PGWythWJp/U6FwYpS
91
+ Matb2Ml0UuNXbCK/VX9vygarP0q3InZl7Ow28paVgSYs/buYqgE4068lQJsJU/ApV4VYXuqFSEEh
92
+ h+XetNMmsntAU1h5jlIxBk2UA0XEzjwD7LcA8joixbRv5e+wipsCAwEAAaOCAccwggHDMAwGA1Ud
93
+ EwEB/wQCMAAwZgYDVR0gBF8wXTBbBgtghkgBhvhFAQcXAzBMMCMGCCsGAQUFBwIBFhdodHRwczov
94
+ L2Quc3ltY2IuY29tL2NwczAlBggrBgEFBQcCAjAZGhdodHRwczovL2Quc3ltY2IuY29tL3JwYTBA
95
+ BgNVHR8EOTA3MDWgM6Axhi9odHRwOi8vdHMtY3JsLndzLnN5bWFudGVjLmNvbS9zaGEyNTYtdHNz
96
+ LWNhLmNybDAWBgNVHSUBAf8EDDAKBggrBgEFBQcDCDAOBgNVHQ8BAf8EBAMCB4AwdwYIKwYBBQUH
97
+ AQEEazBpMCoGCCsGAQUFBzABhh5odHRwOi8vdHMtb2NzcC53cy5zeW1hbnRlYy5jb20wOwYIKwYB
98
+ BQUHMAKGL2h0dHA6Ly90cy1haWEud3Muc3ltYW50ZWMuY29tL3NoYTI1Ni10c3MtY2EuY2VyMCgG
99
+ A1UdEQQhMB+kHTAbMRkwFwYDVQQDExBUaW1lU3RhbXAtMjA0OC02MB0GA1UdDgQWBBSlEwGpn4XM
100
+ G24WHl87Map5NgB7HTAfBgNVHSMEGDAWgBSvY9bKo06FcuCnvEHzKaI4f4B1YjANBgkqhkiG9w0B
101
+ AQsFAAOCAQEARp6v8LiiX6KZSM+oJ0shzbK5pnJwYy/jVSl7OUZO535lBliLvFeKkg0I2BC6NiT6
102
+ Cnv7O9Niv0qUFeaC24pUbf8o/mfPcT/mMwnZolkQ9B5K/mXM3tRr41IpdQBKK6XMy5voqU33tBdZ
103
+ kkHDtz+G5vbAf0Q8RlwXWuOkO9VpJtUhfeGAZ35irLdOLhWa5Zwjr1sR6nGpQfkNeTipoQ3PtLHa
104
+ Ppp6xyLFdM3fRwmGxPyRJbIblumFCOjd6nRgbmClVnoNyERY3Ob5SBSe5b/eAL13sZgUchQk38cR
105
+ LB8AP8NLFMZnHMweBqOQX1xUiz7jM1uCD8W3hgJOcZ/pZkU/djGCAlowggJWAgEBMIGLMHcxCzAJ
106
+ BgNVBAYTAlVTMR0wGwYDVQQKExRTeW1hbnRlYyBDb3Jwb3JhdGlvbjEfMB0GA1UECxMWU3ltYW50
107
+ ZWMgVHJ1c3QgTmV0d29yazEoMCYGA1UEAxMfU3ltYW50ZWMgU0hBMjU2IFRpbWVTdGFtcGluZyBD
108
+ QQIQe9Tlr7rMBz+hASMEIkFNEjALBglghkgBZQMEAgGggaQwGgYJKoZIhvcNAQkDMQ0GCyqGSIb3
109
+ DQEJEAEEMBwGCSqGSIb3DQEJBTEPFw0yNDA4MTQxNzI5MDNaMC8GCSqGSIb3DQEJBDEiBCBf4Q1o
110
+ ml1a1/pJWAt7zhA6V0XBdEYe4uY/cHls7QwUOTA3BgsqhkiG9w0BCRACLzEoMCYwJDAiBCDEdM52
111
+ AH0COU4NpeTefBTGgPniggE8/vZT7123H99h+DALBgkqhkiG9w0BAQEEggEAC1vvkBB4O8KBEkyE
112
+ jlHgNSBFq+GUENZsNLC6vdM+elXtDcMffPOeCAR7SI+iAObHinCFrfoG33dp1vIJqr4CT1vzDgHg
113
+ 9i4HLoja/57MpjkvWplCqzgfyFXoeIqwv4cdjKzLlGRk+3Vtq3OBbiF/yuR1ADsmb0y2Km/vdZ7E
114
+ SDwUABFwQeD0dUdvm6XHpK8/Y74xHPjuLJIPe65ZuwuzsJsw2IpzG9xjlBPl8JtGNMMvZrItLG3t
115
+ Jbw9rW0m1o5wlguxOFzgaXW10RIOmffnR2lcfMVfdokPtpFNoRcesqxDBpBM7hFRTyiRHeG1StiF
116
+ K4462jFHhxW0RZ9t2mAgeg==
117
+ </xades:EncapsulatedTimeStamp>
118
+ </xades:HashDataInfo>
119
+ </xades:SignatureTimeStamp>
120
+ </xades:UnsignedSignatureProperties>
121
+ </xades:UnsignedProperties>
122
+ </xades:QualifyingProperties>
123
+ </Object>
124
+ </Signature>
125
+ </signatures>
DISPLAYER/Displayer.app/config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "api_url": "http://127.0.0.1:5000",
3
+ "size": {
4
+ "width": 1920,
5
+ "height": 1080
6
+ },
7
+ "position": {
8
+ "x": 0,
9
+ "y": 0
10
+ }
11
+ }
DISPLAYER/Displayer.app/mimetype ADDED
@@ -0,0 +1 @@
 
 
1
+ application/vnd.adobe.air-application-installer-package+zip
DISPLAYER/Displayer.fla ADDED
Binary file (4.36 kB). View file
 
DISPLAYER/Displayer.swf ADDED
Binary file (3.56 kB). View file
 
DISPLAYER/FullScreenImageLoader.as ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+  package {
2
+ import flash.display.*;
3
+ import flash.events.*;
4
+ import flash.net.*;
5
+ import flash.utils.*;
6
+ import flash.text.*;
7
+ import com.adobe.images.PNGEncoder;
8
+ import com.adobe.crypto.MD5;
9
+ import com.sociodox.utils.Base64;
10
+ import flash.filesystem.File;
11
+ import flash.filesystem.FileStream;
12
+ import flash.filesystem.FileMode;
13
+
14
+ public class FullScreenImageLoader extends Sprite {
15
+ private var apiUrl:String;
16
+ private var imageWidth:int;
17
+ private var imageHeight:int;
18
+ private var imageX:int;
19
+ private var imageY:int;
20
+ private var refreshInterval:int = 2000; // Refresh every 2 seconds
21
+ private var timer:Timer;
22
+ private var bitmap:Bitmap;
23
+ private var currentChecksum:String = ""; // Store the checksum of the currently displayed image
24
+ private var errorMessage:TextField;
25
+
26
+ public function FullScreenImageLoader() {
27
+ stage.scaleMode = StageScaleMode.NO_SCALE;
28
+ stage.align = StageAlign.TOP_LEFT;
29
+ stage.displayState = StageDisplayState.FULL_SCREEN;
30
+
31
+ // Load configuration from JSON file
32
+ loadConfig();
33
+
34
+ bitmap = new Bitmap();
35
+ addChild(bitmap);
36
+
37
+ // Set up the timer to refresh the image
38
+ timer = new Timer(refreshInterval);
39
+ timer.addEventListener(TimerEvent.TIMER, onTimer);
40
+ timer.start();
41
+
42
+ // Create an error message text field for display
43
+ errorMessage = new TextField();
44
+ errorMessage.defaultTextFormat = new TextFormat("Arial", 20, 0xFF0000);
45
+ errorMessage.width = stage.stageWidth;
46
+ errorMessage.height = 50;
47
+ errorMessage.y = stage.stageHeight - 50;
48
+ errorMessage.selectable = false;
49
+ addChild(errorMessage);
50
+
51
+ // Initial load
52
+ loadImage();
53
+ }
54
+
55
+ private function loadConfig():void {
56
+ var configFile:File = File.applicationDirectory.resolvePath("config.json");
57
+ if (configFile.exists) {
58
+ var fileStream:FileStream = new FileStream();
59
+ fileStream.open(configFile, FileMode.READ);
60
+ var configData:String = fileStream.readUTFBytes(fileStream.bytesAvailable);
61
+ fileStream.close();
62
+
63
+ var config:Object = JSON.parse(configData);
64
+ apiUrl = config.api_url;
65
+ imageWidth = config.size.width;
66
+ imageHeight = config.size.height;
67
+ imageX = config.position.x;
68
+ imageY = config.position.y;
69
+
70
+ trace("Configuration loaded: ", apiUrl, imageWidth, imageHeight, imageX, imageY);
71
+ } else {
72
+ trace("Config file not found: config.json");
73
+ errorMessage.text = "Config file not found: config.json";
74
+ }
75
+ }
76
+
77
+ private function onTimer(event:TimerEvent):void {
78
+ loadImage();
79
+ }
80
+
81
+ private function loadImage():void {
82
+ var request:URLRequest = new URLRequest(apiUrl + "/get_status");
83
+ var loader:URLLoader = new URLLoader();
84
+ loader.dataFormat = URLLoaderDataFormat.TEXT;
85
+ loader.addEventListener(Event.COMPLETE, onImageLoadComplete);
86
+ loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
87
+ loader.load(request);
88
+ }
89
+
90
+ private function onImageLoadComplete(event:Event):void {
91
+ var loader:URLLoader = URLLoader(event.target);
92
+ try {
93
+ var response:Object = JSON.parse(loader.data);
94
+
95
+ if (response.hasOwnProperty("checksum")) {
96
+ var newChecksum:String = response.checksum;
97
+
98
+ // Compare checksums, if different, update the image
99
+ if (newChecksum != currentChecksum) {
100
+ currentChecksum = newChecksum;
101
+
102
+ if (response.hasOwnProperty("image_base64") && response.image_base64 != "") {
103
+ displayNewImage(response.image_base64);
104
+ } else {
105
+ trace("No image data found.");
106
+ errorMessage.text = "No image data found.";
107
+ }
108
+ }
109
+ } else {
110
+ trace("Invalid response from server.");
111
+ errorMessage.text = "Invalid response from server.";
112
+ }
113
+ } catch (error:Error) {
114
+ trace("Error parsing response: " + error.message);
115
+ errorMessage.text = "Error parsing response: " + error.message;
116
+ }
117
+ }
118
+
119
+ private function displayNewImage(base64Image:String):void {
120
+ try {
121
+ var byteArray:ByteArray = Base64.decode(base64Image);
122
+ var loader:Loader = new Loader();
123
+ loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageDecoded);
124
+ loader.loadBytes(byteArray);
125
+ } catch (error:Error) {
126
+ trace("Error decoding image: " + error.message);
127
+ errorMessage.text = "Error decoding image: " + error.message;
128
+ }
129
+ }
130
+
131
+ private function onImageDecoded(event:Event):void {
132
+ var loader:Loader = Loader(event.target.loader);
133
+ var bitmapData:BitmapData = Bitmap(loader.content).bitmapData;
134
+
135
+ // Update the display
136
+ bitmap.bitmapData = bitmapData;
137
+ bitmap.width = imageWidth;
138
+ bitmap.height = imageHeight;
139
+ bitmap.x = imageX;
140
+ bitmap.y = imageY;
141
+ bitmap.smoothing = true;
142
+ }
143
+
144
+ private function onIOError(event:IOErrorEvent):void {
145
+ trace("Error loading image: " + event.text);
146
+ errorMessage.text = "Error loading image: " + event.text;
147
+ }
148
+ }
149
+ }
DISPLAYER/Main.as ADDED
@@ -0,0 +1 @@
 
 
1
+ 
DISPLAYER/com/adobe/air/crypto/EncryptionKeyGenerator.as ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.air.crypto
34
+ {
35
+ import com.adobe.crypto.SHA256;
36
+
37
+ import flash.data.EncryptedLocalStore;
38
+ import flash.utils.ByteArray;
39
+
40
+ /**
41
+ * The EncryptionKeyGenerator class generates an encryption key value, such as you would use
42
+ * to encrypt files or data. For example, the encryption key is suitable to use as
43
+ * an encryption key for an encrypted AIR local SQL (SQLite) database.
44
+ *
45
+ * <p>This class uses techniques and algorithms that are designed for maximum
46
+ * data privacy and security. Use this class to generate an encryption key if your
47
+ * application requires data to be encrypted on a per-user level (in other words,
48
+ * if only one user of the application should be able to access his or her data).
49
+ * In some situations you may also want to use per-user encryption for data even
50
+ * if the application design specifies that other users can access the data. For more
51
+ * information, see
52
+ * "<a href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS34990ABF-C893-47ec-B813-9C9D9587A398.html">Considerations for using encryption with a database</a>"
53
+ * in the guide
54
+ * "<a href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/">Developing Adobe AIR Applications with Flex</a>."</p>
55
+ *
56
+ * <p>The generated encryption key is based on a password that you provide. For any given
57
+ * password, in the same AIR application
58
+ * running in the same user account on the same machine, the encryption key result is
59
+ * the same.</p>
60
+ *
61
+ * <p>To generate an encryption key from a password, use the <code>getEncryptionKey()</code>
62
+ * method. To confirm that a password is a "strong" password before calling the
63
+ * <code>getEncryptionKey()</code> method, use the <code>validateStrongPassword()</code>
64
+ * method.</p>
65
+ *
66
+ * <p>In addition, the EncryptionKeyGenerator includes a utility constant,
67
+ * <code>ENCRYPTED_DB_PASSWORD_ERROR_ID</code>. This constant matches the error ID of
68
+ * the SQLError error that occurs when code that is attempting to open an encrypted database
69
+ * provides the wrong encryption key.</p>
70
+ *
71
+ * <p>This class is designed to create an encryption key suitable for providing the highest
72
+ * level of data privacy and security. In order to achieve that level of security, a few
73
+ * security principles must be followed:</p>
74
+ *
75
+ * <ul>
76
+ * <li>Your application should never store the user-entered password</li>
77
+ * <li>Your application should never store the encryption key returned by the
78
+ * <code>getEncryptionKey()</code> method.</li>
79
+ * <li>Instead, each time the user runs the application and attempts to access the database,
80
+ * your application code should call the <code>getEncryptionKey()</code> method to
81
+ * regenerate the encryption key.</li>
82
+ * </ul>
83
+ *
84
+ * <p>For more information about data security, and an explanation of the security techniques
85
+ * used in the EncryptionKeyGenerator class, see
86
+ * "<a href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS61068DCE-9499-4d40-82B8-B71CC35D832C.html">Example: Generating and using an encryption key</a>"
87
+ * in the guide
88
+ * "<a href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/">Developing Adobe AIR Applications with Flex</a>."</p>
89
+ */
90
+ public class EncryptionKeyGenerator
91
+ {
92
+ // ------- Constants -------
93
+ /**
94
+ * This constant matches the error ID (3138) of the SQLError error that occurs when
95
+ * code that is attempting to open an encrypted database provides the wrong
96
+ * encryption key.
97
+ */
98
+ public static const ENCRYPTED_DB_PASSWORD_ERROR_ID:uint = 3138;
99
+
100
+ private static const STRONG_PASSWORD_PATTERN:RegExp = /(?=^.{8,32}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/;
101
+ private static const SALT_ELS_KEY:String = "com.adobe.air.crypto::EncryptedDBSalt$$$";
102
+
103
+
104
+ // ------- Constructor -------
105
+
106
+ /**
107
+ * Creates a new EncryptionKeyGenerator instance.
108
+ */
109
+ public function EncryptionKeyGenerator() {}
110
+
111
+
112
+ // ------- Public methods -------
113
+
114
+ /**
115
+ * Checks a password and returns a value indicating whether the password is a "strong"
116
+ * password. The criteria for a strong password are:
117
+ *
118
+ * <ul>
119
+ * <li>Minimum 8 characters</li>
120
+ * <li>Maxmium 32 characters</li>
121
+ * <li>Contains at least one lowercase letter</li>
122
+ * <li>Contains at least one uppercase letter</li>
123
+ * <li>Contains at least one number or symbol character</li>
124
+ * </ul>
125
+ *
126
+ * @param password The password to check
127
+ *
128
+ * @return A value indicating whether the password is a strong password (<code>true</code>)
129
+ * or not (<code>false</code>).
130
+ */
131
+ public function validateStrongPassword(password:String):Boolean
132
+ {
133
+ if (password == null || password.length <= 0)
134
+ {
135
+ return false;
136
+ }
137
+
138
+ return STRONG_PASSWORD_PATTERN.test(password);
139
+ }
140
+
141
+
142
+ /**
143
+ * Uses a password to generate a 16-byte encryption key. The return value is suitable
144
+ * to use as an encryption key for an encrypted AIR local SQL (SQLite) database.
145
+ *
146
+ * <p>For any given
147
+ * password, calling the <code>getEncryptionKey()</code> method from the same AIR application
148
+ * running in the same user account on the same machine, the encryption key result is
149
+ * the same.</p>
150
+ *
151
+ * <p>This method is designed to create an encryption key suitable for providing the highest
152
+ * level of data privacy and security. In order to achieve that level of security, your
153
+ * application must follow several security principles:</p>
154
+ *
155
+ * <ul>
156
+ * <li>Your application can never store the user-entered password</li>
157
+ * <li>Your application can never store the encryption key returned by the
158
+ * <code>getEncryptionKey()</code> method.</li>
159
+ * <li>Instead, each time the user runs the application and attempts to access the database,
160
+ * call the <code>getEncryptionKey()</code> method to regenerate the encryption key.</li>
161
+ * </ul>
162
+ *
163
+ * <p>For more information about data security, and an explanation of the security techniques
164
+ * used in the EncryptionKeyGenerator class, see
165
+ * "<a href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS61068DCE-9499-4d40-82B8-B71CC35D832C.html">Example: Generating and using an encryption key</a>"
166
+ * in the guide
167
+ * "<a href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/">Developing Adobe AIR Applications with Flex</a>."</p>
168
+ *
169
+ * @param password The password to use to generate the encryption key.
170
+ * @param overrideSaltELSKey The EncryptionKeyGenerator creates and stores a random value
171
+ * (known as a <i>salt</i>) as part of the process of
172
+ * generating the encryption key. The first time an application
173
+ * calls the <code>getEncryptionKey()</code> method, the salt
174
+ * value is created and stored in the AIR application's encrypted
175
+ * local store (ELS). From then on, the salt value is loaded from the
176
+ * ELS.
177
+ * <p>If you wish to provide a custom String ELS key for storing
178
+ * the salt value, specify a value for the <code>overrideSaltELSKey</code>
179
+ * parameter. If the parameter is <code>null</code> (the default)
180
+ * a default key name is used.</p>
181
+ *
182
+ * @return The generated encryption key, a 16-byte ByteArray object.
183
+ *
184
+ * @throws ArgumentError If the specified password is not a "strong" password according to the
185
+ * criteria explained in the <code>validateStrongPassword()</code>
186
+ * method description
187
+ *
188
+ * @throws ArgumentError If a non-<code>null</code> value is specified for the <code>overrideSaltELSKey</code>
189
+ * parameter, and the value is an empty String (<code>""</code>)
190
+ */
191
+ public function getEncryptionKey(password:String, overrideSaltELSKey:String=null):ByteArray
192
+ {
193
+ if (!validateStrongPassword(password))
194
+ {
195
+ throw new ArgumentError("The password must be a strong password. It must be 8-32 characters long. It must contain at least one uppercase letter, at least one lowercase letter, and at least one number or symbol.");
196
+ }
197
+
198
+ if (overrideSaltELSKey != null && overrideSaltELSKey.length <= 0)
199
+ {
200
+ throw new ArgumentError("If an overrideSaltELSKey parameter value is specified, it can't be an empty String.");
201
+ }
202
+
203
+ var concatenatedPassword:String = concatenatePassword(password);
204
+
205
+ var saltKey:String;
206
+ if (overrideSaltELSKey == null)
207
+ {
208
+ saltKey = SALT_ELS_KEY;
209
+ }
210
+ else
211
+ {
212
+ saltKey = overrideSaltELSKey;
213
+ }
214
+
215
+ var salt:ByteArray = EncryptedLocalStore.getItem(saltKey);
216
+ if (salt == null)
217
+ {
218
+ salt = makeSalt();
219
+ EncryptedLocalStore.setItem(saltKey, salt);
220
+ }
221
+
222
+ var unhashedKey:ByteArray = xorBytes(concatenatedPassword, salt);
223
+
224
+ var hashedKey:String = SHA256.hashBytes(unhashedKey);
225
+
226
+ var encryptionKey:ByteArray = generateEncryptionKey(hashedKey);
227
+
228
+ return encryptionKey;
229
+ }
230
+
231
+
232
+ // ------- Creating encryption key -------
233
+
234
+ private function concatenatePassword(pwd:String):String
235
+ {
236
+ var len:int = pwd.length;
237
+ var targetLength:int = 32;
238
+
239
+ if (len == targetLength)
240
+ {
241
+ return pwd;
242
+ }
243
+
244
+ var repetitions:int = Math.floor(targetLength / len);
245
+ var excess:int = targetLength % len;
246
+
247
+ var result:String = "";
248
+
249
+ for (var i:uint = 0; i < repetitions; i++)
250
+ {
251
+ result += pwd;
252
+ }
253
+
254
+ result += pwd.substr(0, excess);
255
+
256
+ return result;
257
+ }
258
+
259
+
260
+ private function makeSalt():ByteArray
261
+ {
262
+ var result:ByteArray = new ByteArray;
263
+
264
+ for (var i:uint = 0; i < 8; i++)
265
+ {
266
+ result.writeUnsignedInt(Math.round(Math.random() * uint.MAX_VALUE));
267
+ }
268
+
269
+ return result;
270
+ }
271
+
272
+
273
+ private function xorBytes(passwordString:String, salt:ByteArray):ByteArray
274
+ {
275
+ var result:ByteArray = new ByteArray();
276
+
277
+ for (var i:uint = 0; i < 32; i += 4)
278
+ {
279
+ // Extract 4 bytes from the password string and convert to a uint
280
+ var o1:uint = passwordString.charCodeAt(i) << 24;
281
+ o1 += passwordString.charCodeAt(i + 1) << 16;
282
+ o1 += passwordString.charCodeAt(i + 2) << 8;
283
+ o1 += passwordString.charCodeAt(i + 3);
284
+
285
+ salt.position = i;
286
+ var o2:uint = salt.readUnsignedInt();
287
+
288
+ var xor:uint = o1 ^ o2;
289
+ result.writeUnsignedInt(xor);
290
+ }
291
+
292
+ return result;
293
+ }
294
+
295
+
296
+ private function generateEncryptionKey(hash:String):ByteArray
297
+ {
298
+ var result:ByteArray = new ByteArray();
299
+
300
+ // select a range of 128 bits (32 hex characters) from the hash
301
+ // In this case, we'll use the bits starting from position 17
302
+ for (var i:uint = 0; i < 32; i += 2)
303
+ {
304
+ var position:uint = i + 17;
305
+ var hex:String = hash.substr(position, 2);
306
+ var byte:int = parseInt(hex, 16);
307
+ result.writeByte(byte);
308
+ }
309
+
310
+ return result;
311
+ }
312
+ }
313
+ }
DISPLAYER/com/adobe/air/filesystem/FileMonitor.as ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.air.filesystem
34
+ {
35
+ import flash.filesystem.File;
36
+ import flash.utils.Timer;
37
+ import flash.events.TimerEvent;
38
+ import flash.events.Event;
39
+ import flash.events.EventDispatcher;
40
+ import com.adobe.air.filesystem.events.FileMonitorEvent;
41
+
42
+ /*
43
+ Todo:
44
+
45
+ -Cmonitor changes in multiple attributes
46
+ -add support for monitoring multiple files
47
+ */
48
+
49
+ /**
50
+ * Dispatched when the modified date of the file being modified changes.
51
+ *
52
+ * @eventType com.adobe.air.filesystem.events.FileMonitor.CHANGE
53
+ */
54
+ [Event(name="CHANGE", type="com.adobe.air.filesystem.events.FileMonitor")]
55
+
56
+ /**
57
+ * Dispatched when the file being monitored is moved or deleted. The file
58
+ * will be unwatched.
59
+ *
60
+ * @eventType com.adobe.air.filesystem.events.FileMonitor.MOVE
61
+ */
62
+ [Event(name="MOVE", type="com.adobe.air.filesystem.events.FileMonitor")]
63
+
64
+ /**
65
+ * Dispatched when the file being monitored is created.
66
+ *
67
+ * @eventType com.adobe.air.filesystem.events.FileMonitor.CREATE
68
+ */
69
+ [Event(name="CREATE", type="com.adobe.air.filesystem.events.FileMonitor")]
70
+
71
+ /**
72
+ * Class that monitors files for changes.
73
+ */
74
+ public class FileMonitor extends EventDispatcher
75
+ {
76
+ private var _file:File;
77
+ private var timer:Timer;
78
+ public static const DEFAULT_MONITOR_INTERVAL:Number = 1000;
79
+ private var _interval:Number;
80
+ private var fileExists:Boolean = false;
81
+
82
+ private var lastModifiedTime:Number;
83
+
84
+ /**
85
+ * Constructor
86
+ *
87
+ * @parameter file The File that will be monitored for changes.
88
+ *
89
+ * @param interval How often in milliseconds the file is polled for
90
+ * change events. Default value is 1000, minimum value is 1000
91
+ */
92
+ public function FileMonitor(file:File = null, interval:Number = -1)
93
+ {
94
+ this.file = file;
95
+
96
+ if(interval != -1)
97
+ {
98
+ if(interval < 1000)
99
+ {
100
+ _interval = 1000;
101
+ }
102
+ else
103
+ {
104
+ _interval = interval;
105
+ }
106
+ }
107
+ else
108
+ {
109
+ _interval = DEFAULT_MONITOR_INTERVAL;
110
+ }
111
+ }
112
+
113
+ /**
114
+ * File being monitored for changes.
115
+ *
116
+ * Setting the property will result in unwatch() being called.
117
+ */
118
+ public function get file():File
119
+ {
120
+ return _file;
121
+ }
122
+
123
+ public function set file(file:File):void
124
+ {
125
+ if(timer && timer.running)
126
+ {
127
+ unwatch();
128
+ }
129
+
130
+ _file = file;
131
+
132
+ if(!_file)
133
+ {
134
+ fileExists = false;
135
+ return;
136
+ }
137
+
138
+ //note : this will throw an error if new File() is passed in.
139
+ fileExists = _file.exists;
140
+ if(fileExists)
141
+ {
142
+ lastModifiedTime = _file.modificationDate.getTime();
143
+ }
144
+
145
+ }
146
+
147
+ /**
148
+ * How often the system is polled for Volume change events.
149
+ */
150
+ public function get interval():Number
151
+ {
152
+ return _interval;
153
+ }
154
+
155
+ /**
156
+ * Begins monitoring the specified file for changes.
157
+ *
158
+ * Broadcasts Event.CHANGE event when the file's modification date has changed.
159
+ */
160
+ public function watch():void
161
+ {
162
+ if(!file)
163
+ {
164
+ //should we throw an error?
165
+ return;
166
+ }
167
+
168
+ if(timer && timer.running)
169
+ {
170
+ return;
171
+ }
172
+
173
+ //check and see if timer is active. if it is, return
174
+ if(!timer)
175
+ {
176
+ timer = new Timer(_interval);
177
+ timer.addEventListener(TimerEvent.TIMER, onTimerEvent, false, 0, true);
178
+ }
179
+
180
+ timer.start();
181
+ }
182
+
183
+ /**
184
+ * Stops watching the specified file for changes.
185
+ */
186
+ public function unwatch():void
187
+ {
188
+ if(!timer)
189
+ {
190
+ return;
191
+ }
192
+
193
+ timer.stop();
194
+ timer.removeEventListener(TimerEvent.TIMER, onTimerEvent);
195
+ }
196
+
197
+ private function onTimerEvent(e:TimerEvent):void
198
+ {
199
+ var outEvent:FileMonitorEvent;
200
+
201
+ if(fileExists != _file.exists)
202
+ {
203
+ if(_file.exists)
204
+ {
205
+ //file was created
206
+ outEvent = new FileMonitorEvent(FileMonitorEvent.CREATE);
207
+ lastModifiedTime = _file.modificationDate.getTime();
208
+ }
209
+ else
210
+ {
211
+ //file was moved / deleted
212
+ outEvent = new FileMonitorEvent(FileMonitorEvent.MOVE);
213
+ unwatch();
214
+ }
215
+ fileExists = _file.exists;
216
+ }
217
+ else
218
+ {
219
+ if(!_file.exists)
220
+ {
221
+ return;
222
+ }
223
+
224
+ var modifiedTime:Number = _file.modificationDate.getTime();
225
+
226
+ if(modifiedTime == lastModifiedTime)
227
+ {
228
+ return;
229
+ }
230
+
231
+ lastModifiedTime = modifiedTime;
232
+
233
+ //file modified
234
+ outEvent = new FileMonitorEvent(FileMonitorEvent.CHANGE);
235
+ }
236
+
237
+ if(outEvent)
238
+ {
239
+ outEvent.file = _file;
240
+ dispatchEvent(outEvent);
241
+ }
242
+
243
+ }
244
+ }
245
+ }
DISPLAYER/com/adobe/air/filesystem/FileUtil.as ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.air.filesystem
34
+ {
35
+ import flash.system.Capabilities;
36
+ import flash.filesystem.File;
37
+
38
+
39
+ public class FileUtil
40
+ {
41
+ /**
42
+ * @return An Array of Files representing the root directories of the
43
+ * operating system.
44
+ */
45
+ public static function getRootDirectories():Array
46
+ {
47
+ var v:Array = File.getRootDirectories();
48
+ var os:String = Capabilities.os;
49
+
50
+ if(os.indexOf("Mac") > -1)
51
+ {
52
+ v = File(v[0]).resolvePath("Volumes").getDirectoryListing();
53
+ }
54
+ else if(os.indexOf("Linux") > -1)
55
+ {
56
+ //todo: need to impliment Linux
57
+ }
58
+
59
+ return v;
60
+ }
61
+
62
+ }
63
+ }
DISPLAYER/com/adobe/air/filesystem/VolumeMonitor.as ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.air.filesystem
34
+ {
35
+ import flash.events.EventDispatcher;
36
+ import flash.utils.Timer;
37
+ import flash.events.TimerEvent;
38
+ import flash.filesystem.File;
39
+ import flash.utils.Dictionary;
40
+ import com.adobe.air.filesystem.events.FileMonitorEvent;
41
+ import com.adobe.utils.ArrayUtil;
42
+
43
+ /**
44
+ * Dispatched when a volume is added to the system.
45
+ *
46
+ * @eventType com.adobe.air.filesystem.events.FileMonitor.ADD_VOLUME
47
+ */
48
+ [Event(name="ADD_VOLUME", type="com.adobe.air.filesystem.events.FileMonitor")]
49
+
50
+ /**
51
+ * Dispatched when a volume is removed from the system.
52
+ *
53
+ * @eventType com.adobe.air.filesystem.events.FileMonitor.REMOVE_VOLUME
54
+ */
55
+ [Event(name="REMOVE_VOLUME", type="com.adobe.air.filesystem.events.FileMonitor")]
56
+
57
+ /**
58
+ * Class that monitors changes to the File volumes attached to the operating
59
+ * system.
60
+ */
61
+ public class VolumeMonitor extends EventDispatcher
62
+ {
63
+ private var timer:Timer;
64
+ private var _interval:Number;
65
+ private static const DEFAULT_MONITOR_INTERVAL:Number = 2000;
66
+
67
+ private var volumes:Dictionary;
68
+
69
+ /**
70
+ * Constructor.
71
+ *
72
+ * @param interval How often in milliseconds the system is polled for
73
+ * volume change events. Default value is 2000, minimum value is 1000
74
+ */
75
+ public function VolumeMonitor(interval:Number = -1)
76
+ {
77
+ if(interval != -1)
78
+ {
79
+ if(interval < 1000)
80
+ {
81
+ _interval = 1000;
82
+ }
83
+ else
84
+ {
85
+ _interval = interval;
86
+ }
87
+ }
88
+ else
89
+ {
90
+ _interval = DEFAULT_MONITOR_INTERVAL;
91
+ }
92
+ }
93
+
94
+ /**
95
+ * How often the system is polled for Volume change events.
96
+ */
97
+ public function get interval():Number
98
+ {
99
+ return _interval;
100
+ }
101
+
102
+ /**
103
+ * Begins the monitoring of changes to the attached File volumes.
104
+ */
105
+ public function watch():void
106
+ {
107
+ if(!timer)
108
+ {
109
+ timer = new Timer(_interval);
110
+ timer.addEventListener(TimerEvent.TIMER, onTimerEvent,false,0, true);
111
+ }
112
+
113
+ //we reinitialize the hash everytime we start watching
114
+ volumes = new Dictionary();
115
+
116
+ var v:Array = FileUtil.getRootDirectories();
117
+ for each(var f:File in v)
118
+ {
119
+ //null or undefined
120
+ if(volumes[f.url] == null)
121
+ {
122
+ volumes[f.url] = f;
123
+ }
124
+ }
125
+
126
+ timer.start();
127
+ }
128
+
129
+ /**
130
+ * Stops monitoring for changes to the attached File volumes.
131
+ */
132
+ public function unwatch():void
133
+ {
134
+ timer.stop();
135
+ timer.removeEventListener(TimerEvent.TIMER, onTimerEvent);
136
+ }
137
+
138
+ private function onTimerEvent(e:TimerEvent):void
139
+ {
140
+ var v:Array = FileUtil.getRootDirectories();
141
+
142
+ var outEvent:FileMonitorEvent;
143
+ var found:Boolean = false;
144
+ for(var key:String in volumes)
145
+ {
146
+ for each(var f:File in v)
147
+ {
148
+ //trace("--\n" + key);
149
+ //trace(f.url);
150
+ if(f.url == key)
151
+ {
152
+ found = true;
153
+ break;
154
+ }
155
+ }
156
+
157
+ if(!found)
158
+ {
159
+ outEvent = new FileMonitorEvent(FileMonitorEvent.REMOVE_VOLUME);
160
+ outEvent.file = volumes[key];
161
+ dispatchEvent(outEvent);
162
+ delete volumes[key];
163
+ }
164
+
165
+ found = false;
166
+ }
167
+
168
+ for each(var f2:File in v)
169
+ {
170
+ //null or undefined
171
+ if(volumes[f2.url] == null)
172
+ {
173
+ volumes[f2.url] = f2;
174
+ outEvent = new FileMonitorEvent(FileMonitorEvent.ADD_VOLUME);
175
+ outEvent.file = f2;
176
+
177
+ dispatchEvent(outEvent);
178
+ }
179
+ }
180
+ }
181
+
182
+
183
+ }
184
+ }
DISPLAYER/com/adobe/air/filesystem/events/FileMonitorEvent.as ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.air.filesystem.events
34
+ {
35
+ import flash.events.Event;
36
+ import flash.filesystem.File;
37
+
38
+ public class FileMonitorEvent extends Event
39
+ {
40
+ public static const CHANGE:String = "onFileChange";
41
+ public static const MOVE:String = "onFileMove";
42
+ public static const CREATE:String = "onFileCreate";
43
+ public static const ADD_VOLUME:String = "onVolumeAdd";
44
+ public static const REMOVE_VOLUME:String = "onVolumeRemove";
45
+
46
+ public var file:File;
47
+ public function FileMonitorEvent(type:String, bubbles:Boolean=false,
48
+ cancelable:Boolean=false)
49
+ {
50
+ super(type, bubbles, cancelable);
51
+ }
52
+
53
+ public override function clone():Event
54
+ {
55
+ var out:FileMonitorEvent = new FileMonitorEvent(type, bubbles, cancelable);
56
+ out.file = file;
57
+
58
+ return out;
59
+ }
60
+ }
61
+ }
DISPLAYER/com/adobe/air/logging/FileTarget.as ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 flash.filesystem.File;
36
+ import flash.filesystem.FileMode;
37
+ import flash.filesystem.FileStream;
38
+
39
+ import mx.core.mx_internal;
40
+ import mx.logging.targets.LineFormattedTarget;
41
+
42
+ use namespace mx_internal;
43
+
44
+ /**
45
+ * An Adobe AIR only class that provides a log target for the Flex logging
46
+ * framework, that logs files to a file on the user's system.
47
+ *
48
+ * This class will only work when running within Adobe AIR>
49
+ */
50
+ public class FileTarget extends LineFormattedTarget
51
+ {
52
+ private const DEFAULT_LOG_PATH:String = "app-storage:/application.log";
53
+
54
+ private var log:File;
55
+
56
+ public function FileTarget(logFile:File = null)
57
+ {
58
+ if(logFile != null)
59
+ {
60
+ log = logFile;
61
+ }
62
+ else
63
+ {
64
+ log = new File(DEFAULT_LOG_PATH);
65
+ }
66
+ }
67
+
68
+ public function get logURI():String
69
+ {
70
+ return log.url;
71
+ }
72
+
73
+ mx_internal override function internalLog(message:String):void
74
+ {
75
+ write(message);
76
+ }
77
+
78
+ private function write(msg:String):void
79
+ {
80
+ var fs:FileStream = new FileStream();
81
+ fs.open(log, FileMode.APPEND);
82
+ fs.writeUTFBytes(msg + File.lineEnding);
83
+ fs.close();
84
+ }
85
+
86
+ public function clear():void
87
+ {
88
+ var fs:FileStream = new FileStream();
89
+ fs.open(log, FileMode.WRITE);
90
+ fs.writeUTFBytes("");
91
+ fs.close();
92
+ }
93
+
94
+ }
95
+ }
DISPLAYER/com/adobe/air/net/ResourceCache.as ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.air.net
34
+ {
35
+ import com.adobe.crypto.MD5;
36
+ import com.adobe.net.DynamicURLLoader;
37
+
38
+ import flash.events.Event;
39
+ import flash.events.EventDispatcher;
40
+ import flash.events.IOErrorEvent;
41
+ import flash.filesystem.File;
42
+ import flash.filesystem.FileMode;
43
+ import flash.filesystem.FileStream;
44
+ import flash.net.URLLoaderDataFormat;
45
+ import flash.net.URLRequest;
46
+ import flash.utils.ByteArray;
47
+ import com.adobe.air.net.events.ResourceCacheEvent;
48
+
49
+ //todo: add event metadata
50
+
51
+ public class ResourceCache extends EventDispatcher
52
+ {
53
+ private var _cacheName:String;
54
+ //maybe rename to make it clearer it loads data
55
+ public function ResourceCache(cacheName:String)
56
+ {
57
+ _cacheName = cacheName;
58
+ }
59
+
60
+ public function get cacheName():String
61
+ {
62
+ return _cacheName;
63
+ }
64
+
65
+ private function getStorageDir():File
66
+ {
67
+ return File.applicationStorageDirectory.resolvePath(_cacheName);
68
+ }
69
+
70
+ public function itemExists(key:String):Boolean
71
+ {
72
+ return getItemFile(key).exists;
73
+ }
74
+
75
+ public function clearCache():void
76
+ {
77
+ var cacheDir:File = getStorageDir();
78
+ try
79
+ {
80
+ cacheDir.deleteDirectory(true);
81
+ }
82
+ catch (e:IOErrorEvent)
83
+ {
84
+ // we tried!
85
+ }
86
+ }
87
+
88
+ public function getItemFile(key:String):File
89
+ {
90
+ var dir:File = getStorageDir();
91
+ var fName:String = generateKeyHash(key);
92
+ var file:File = dir.resolvePath(fName);
93
+
94
+ return file;
95
+ }
96
+
97
+ public function retrieve(url:String):void
98
+ {
99
+
100
+ var key:String = generateKeyHash(url);
101
+ var file:File = getItemFile(key);
102
+
103
+ //todo: do we need to check if the dir exists?
104
+
105
+ if(file.exists)
106
+ {
107
+ var e:ResourceCacheEvent = new ResourceCacheEvent(ResourceCacheEvent.ITEM_READY);
108
+ e.key = key;
109
+ e.file = file;
110
+
111
+ dispatchEvent(e);
112
+ return;
113
+ }
114
+
115
+
116
+ var loader:DynamicURLLoader = new DynamicURLLoader();
117
+ loader.file = file;
118
+ loader.key = key;
119
+
120
+ loader.addEventListener(Event.COMPLETE, onDataLoad);
121
+ loader.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
122
+
123
+ loader.dataFormat = URLLoaderDataFormat.BINARY;
124
+
125
+ loader.load(new URLRequest(url));
126
+
127
+ }
128
+
129
+ private function onLoadError(event:IOErrorEvent):void
130
+ {
131
+ trace("onLoadError : could not cache item");
132
+ }
133
+
134
+ private function onDataLoad(event:Event):void
135
+ {
136
+ var loader:DynamicURLLoader = DynamicURLLoader(event.target);
137
+
138
+ var f:File = File(loader.file);
139
+ var key:String = String(loader.key);
140
+
141
+ var fileStream:FileStream = new FileStream();
142
+ fileStream.open(f, FileMode.WRITE);
143
+ fileStream.writeBytes(loader.data as ByteArray);
144
+ fileStream.close();
145
+
146
+ var g:ResourceCacheEvent = new ResourceCacheEvent(ResourceCacheEvent.ITEM_CACHED);
147
+ g.key = key;
148
+ g.file = f;
149
+
150
+ dispatchEvent(g);
151
+
152
+ var e:ResourceCacheEvent = new ResourceCacheEvent(ResourceCacheEvent.ITEM_READY);
153
+ e.key = key;
154
+ e.file = f;
155
+
156
+ dispatchEvent(e);
157
+ }
158
+
159
+
160
+ private function generateKeyHash(key:String):String
161
+ {
162
+ return MD5.hash(key);
163
+ }
164
+ }
165
+ }
DISPLAYER/com/adobe/air/net/events/ResourceCacheEvent.as ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.air.net.events
34
+ {
35
+ import flash.events.Event;
36
+ import flash.filesystem.File;
37
+
38
+ public class ResourceCacheEvent extends Event
39
+ {
40
+
41
+ public static const ITEM_READY:String = "onPathReady";
42
+ public static const ITEM_CACHED:String = "onItemCached";
43
+
44
+ [Bindable]
45
+ public var key:String;
46
+
47
+ [Bindable]
48
+ public var file:File;
49
+
50
+ public function ResourceCacheEvent(type:String,
51
+ bubbles:Boolean=false,
52
+ cancelable:Boolean=false)
53
+ {
54
+ super(type, bubbles, cancelable);
55
+ }
56
+
57
+ public override function clone():Event
58
+ {
59
+ var out:ResourceCacheEvent = new ResourceCacheEvent(type,
60
+ bubbles,
61
+ cancelable);
62
+
63
+ out.key = key;
64
+ out.file = file;
65
+
66
+ return out;
67
+ }
68
+
69
+ }
70
+ }
DISPLAYER/com/adobe/crypto/HMAC.as ADDED
@@ -0,0 +1,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
+ 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
+ }
DISPLAYER/com/adobe/crypto/MD5.as ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /**
38
+ * The MD5 Message-Digest Algorithm
39
+ *
40
+ * Implementation based on algorithm description at
41
+ * http://www.faqs.org/rfcs/rfc1321.html
42
+ */
43
+ public class MD5 {
44
+
45
+ public static var digest:ByteArray;
46
+ /**
47
+ * Performs the MD5 hash algorithm on a string.
48
+ *
49
+ * @param s The string to hash
50
+ * @return A string containing the hash value of s
51
+ * @langversion ActionScript 3.0
52
+ * @playerversion Flash 8.5
53
+ * @tiptext
54
+ */
55
+
56
+ public static function hash(s:String) :String{
57
+ //Convert to byteArray and send through hashBinary function
58
+ // so as to only have complex code in one location
59
+ var ba:ByteArray = new ByteArray();
60
+ ba.writeUTFBytes(s);
61
+ return hashBinary(ba);
62
+ }
63
+
64
+ public static function hashBytes(s:ByteArray) :String{
65
+ return hashBinary(s);
66
+ }
67
+
68
+ /**
69
+ * Performs the MD5 hash algorithm on a ByteArray.
70
+ *
71
+ * @param s The string to hash
72
+ * @return A string containing the hash value of s
73
+ * @langversion ActionScript 3.0
74
+ * @playerversion Flash 8.5
75
+ * @tiptext
76
+ */
77
+ public static function hashBinary( s:ByteArray ):String {
78
+ // initialize the md buffers
79
+ var a:int = 1732584193;
80
+ var b:int = -271733879;
81
+ var c:int = -1732584194;
82
+ var d:int = 271733878;
83
+
84
+ // variables to store previous values
85
+ var aa:int;
86
+ var bb:int;
87
+ var cc:int;
88
+ var dd:int;
89
+
90
+ // create the blocks from the string and
91
+ // save the length as a local var to reduce
92
+ // lookup in the loop below
93
+ var x:Array = createBlocks( s );
94
+ var len:int = x.length;
95
+
96
+ // loop over all of the blocks
97
+ for ( var i:int = 0; i < len; i += 16) {
98
+ // save previous values
99
+ aa = a;
100
+ bb = b;
101
+ cc = c;
102
+ dd = d;
103
+
104
+ // Round 1
105
+ a = ff( a, b, c, d, x[int(i+ 0)], 7, -680876936 ); // 1
106
+ d = ff( d, a, b, c, x[int(i+ 1)], 12, -389564586 ); // 2
107
+ c = ff( c, d, a, b, x[int(i+ 2)], 17, 606105819 ); // 3
108
+ b = ff( b, c, d, a, x[int(i+ 3)], 22, -1044525330 ); // 4
109
+ a = ff( a, b, c, d, x[int(i+ 4)], 7, -176418897 ); // 5
110
+ d = ff( d, a, b, c, x[int(i+ 5)], 12, 1200080426 ); // 6
111
+ c = ff( c, d, a, b, x[int(i+ 6)], 17, -1473231341 ); // 7
112
+ b = ff( b, c, d, a, x[int(i+ 7)], 22, -45705983 ); // 8
113
+ a = ff( a, b, c, d, x[int(i+ 8)], 7, 1770035416 ); // 9
114
+ d = ff( d, a, b, c, x[int(i+ 9)], 12, -1958414417 ); // 10
115
+ c = ff( c, d, a, b, x[int(i+10)], 17, -42063 ); // 11
116
+ b = ff( b, c, d, a, x[int(i+11)], 22, -1990404162 ); // 12
117
+ a = ff( a, b, c, d, x[int(i+12)], 7, 1804603682 ); // 13
118
+ d = ff( d, a, b, c, x[int(i+13)], 12, -40341101 ); // 14
119
+ c = ff( c, d, a, b, x[int(i+14)], 17, -1502002290 ); // 15
120
+ b = ff( b, c, d, a, x[int(i+15)], 22, 1236535329 ); // 16
121
+
122
+ // Round 2
123
+ a = gg( a, b, c, d, x[int(i+ 1)], 5, -165796510 ); // 17
124
+ d = gg( d, a, b, c, x[int(i+ 6)], 9, -1069501632 ); // 18
125
+ c = gg( c, d, a, b, x[int(i+11)], 14, 643717713 ); // 19
126
+ b = gg( b, c, d, a, x[int(i+ 0)], 20, -373897302 ); // 20
127
+ a = gg( a, b, c, d, x[int(i+ 5)], 5, -701558691 ); // 21
128
+ d = gg( d, a, b, c, x[int(i+10)], 9, 38016083 ); // 22
129
+ c = gg( c, d, a, b, x[int(i+15)], 14, -660478335 ); // 23
130
+ b = gg( b, c, d, a, x[int(i+ 4)], 20, -405537848 ); // 24
131
+ a = gg( a, b, c, d, x[int(i+ 9)], 5, 568446438 ); // 25
132
+ d = gg( d, a, b, c, x[int(i+14)], 9, -1019803690 ); // 26
133
+ c = gg( c, d, a, b, x[int(i+ 3)], 14, -187363961 ); // 27
134
+ b = gg( b, c, d, a, x[int(i+ 8)], 20, 1163531501 ); // 28
135
+ a = gg( a, b, c, d, x[int(i+13)], 5, -1444681467 ); // 29
136
+ d = gg( d, a, b, c, x[int(i+ 2)], 9, -51403784 ); // 30
137
+ c = gg( c, d, a, b, x[int(i+ 7)], 14, 1735328473 ); // 31
138
+ b = gg( b, c, d, a, x[int(i+12)], 20, -1926607734 ); // 32
139
+
140
+ // Round 3
141
+ a = hh( a, b, c, d, x[int(i+ 5)], 4, -378558 ); // 33
142
+ d = hh( d, a, b, c, x[int(i+ 8)], 11, -2022574463 ); // 34
143
+ c = hh( c, d, a, b, x[int(i+11)], 16, 1839030562 ); // 35
144
+ b = hh( b, c, d, a, x[int(i+14)], 23, -35309556 ); // 36
145
+ a = hh( a, b, c, d, x[int(i+ 1)], 4, -1530992060 ); // 37
146
+ d = hh( d, a, b, c, x[int(i+ 4)], 11, 1272893353 ); // 38
147
+ c = hh( c, d, a, b, x[int(i+ 7)], 16, -155497632 ); // 39
148
+ b = hh( b, c, d, a, x[int(i+10)], 23, -1094730640 ); // 40
149
+ a = hh( a, b, c, d, x[int(i+13)], 4, 681279174 ); // 41
150
+ d = hh( d, a, b, c, x[int(i+ 0)], 11, -358537222 ); // 42
151
+ c = hh( c, d, a, b, x[int(i+ 3)], 16, -722521979 ); // 43
152
+ b = hh( b, c, d, a, x[int(i+ 6)], 23, 76029189 ); // 44
153
+ a = hh( a, b, c, d, x[int(i+ 9)], 4, -640364487 ); // 45
154
+ d = hh( d, a, b, c, x[int(i+12)], 11, -421815835 ); // 46
155
+ c = hh( c, d, a, b, x[int(i+15)], 16, 530742520 ); // 47
156
+ b = hh( b, c, d, a, x[int(i+ 2)], 23, -995338651 ); // 48
157
+
158
+ // Round 4
159
+ a = ii( a, b, c, d, x[int(i+ 0)], 6, -198630844 ); // 49
160
+ d = ii( d, a, b, c, x[int(i+ 7)], 10, 1126891415 ); // 50
161
+ c = ii( c, d, a, b, x[int(i+14)], 15, -1416354905 ); // 51
162
+ b = ii( b, c, d, a, x[int(i+ 5)], 21, -57434055 ); // 52
163
+ a = ii( a, b, c, d, x[int(i+12)], 6, 1700485571 ); // 53
164
+ d = ii( d, a, b, c, x[int(i+ 3)], 10, -1894986606 ); // 54
165
+ c = ii( c, d, a, b, x[int(i+10)], 15, -1051523 ); // 55
166
+ b = ii( b, c, d, a, x[int(i+ 1)], 21, -2054922799 ); // 56
167
+ a = ii( a, b, c, d, x[int(i+ 8)], 6, 1873313359 ); // 57
168
+ d = ii( d, a, b, c, x[int(i+15)], 10, -30611744 ); // 58
169
+ c = ii( c, d, a, b, x[int(i+ 6)], 15, -1560198380 ); // 59
170
+ b = ii( b, c, d, a, x[int(i+13)], 21, 1309151649 ); // 60
171
+ a = ii( a, b, c, d, x[int(i+ 4)], 6, -145523070 ); // 61
172
+ d = ii( d, a, b, c, x[int(i+11)], 10, -1120210379 ); // 62
173
+ c = ii( c, d, a, b, x[int(i+ 2)], 15, 718787259 ); // 63
174
+ b = ii( b, c, d, a, x[int(i+ 9)], 21, -343485551 ); // 64
175
+
176
+ a += aa;
177
+ b += bb;
178
+ c += cc;
179
+ d += dd;
180
+ }
181
+ digest = new ByteArray()
182
+ digest.writeInt(a);
183
+ digest.writeInt(b);
184
+ digest.writeInt(c);
185
+ digest.writeInt(d);
186
+ digest.position = 0;
187
+ // Finish up by concatening the buffers with their hex output
188
+ return IntUtil.toHex( a ) + IntUtil.toHex( b ) + IntUtil.toHex( c ) + IntUtil.toHex( d );
189
+ }
190
+
191
+ /**
192
+ * Auxiliary function f as defined in RFC
193
+ */
194
+ private static function f( x:int, y:int, z:int ):int {
195
+ return ( x & y ) | ( (~x) & z );
196
+ }
197
+
198
+ /**
199
+ * Auxiliary function g as defined in RFC
200
+ */
201
+ private static function g( x:int, y:int, z:int ):int {
202
+ return ( x & z ) | ( y & (~z) );
203
+ }
204
+
205
+ /**
206
+ * Auxiliary function h as defined in RFC
207
+ */
208
+ private static function h( x:int, y:int, z:int ):int {
209
+ return x ^ y ^ z;
210
+ }
211
+
212
+ /**
213
+ * Auxiliary function i as defined in RFC
214
+ */
215
+ private static function i( x:int, y:int, z:int ):int {
216
+ return y ^ ( x | (~z) );
217
+ }
218
+
219
+ /**
220
+ * A generic transformation function. The logic of ff, gg, hh, and
221
+ * ii are all the same, minus the function used, so pull that logic
222
+ * out and simplify the method bodies for the transoformation functions.
223
+ */
224
+ private static function transform( func:Function, a:int, b:int, c:int, d:int, x:int, s:int, t:int):int {
225
+ var tmp:int = a + int( func( b, c, d ) ) + x + t;
226
+ return IntUtil.rol( tmp, s ) + b;
227
+ }
228
+
229
+ /**
230
+ * ff transformation function
231
+ */
232
+ private static function ff ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
233
+ return transform( f, a, b, c, d, x, s, t );
234
+ }
235
+
236
+ /**
237
+ * gg transformation function
238
+ */
239
+ private static function gg ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
240
+ return transform( g, a, b, c, d, x, s, t );
241
+ }
242
+
243
+ /**
244
+ * hh transformation function
245
+ */
246
+ private static function hh ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
247
+ return transform( h, a, b, c, d, x, s, t );
248
+ }
249
+
250
+ /**
251
+ * ii transformation function
252
+ */
253
+ private static function ii ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
254
+ return transform( i, a, b, c, d, x, s, t );
255
+ }
256
+
257
+ /**
258
+ * Converts a string to a sequence of 16-word blocks
259
+ * that we'll do the processing on. Appends padding
260
+ * and length in the process.
261
+ *
262
+ * @param s The string to split into blocks
263
+ * @return An array containing the blocks that s was
264
+ * split into.
265
+ */
266
+ private static function createBlocks( s:ByteArray ):Array {
267
+ var blocks:Array = new Array();
268
+ var len:int = s.length * 8;
269
+ var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
270
+ for( var i:int = 0; i < len; i += 8 ) {
271
+ blocks[ int(i >> 5) ] |= ( s[ i / 8 ] & mask ) << ( i % 32 );
272
+ }
273
+
274
+ // append padding and length
275
+ blocks[ int(len >> 5) ] |= 0x80 << ( len % 32 );
276
+ blocks[ int(( ( ( len + 64 ) >>> 9 ) << 4 ) + 14) ] = len;
277
+ return blocks;
278
+ }
279
+
280
+ }
281
+ }
DISPLAYER/com/adobe/crypto/MD5Stream.as ADDED
@@ -0,0 +1,402 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
38
+ /**
39
+ * Perform MD5 hash of an input stream in chunks. This class is
40
+ * based on com.adobe.crypto.MD5 and can process data in
41
+ * chunks. Both block creation and hash computation are done
42
+ * together for whatever input is available so that the memory
43
+ * overhead at a time is always fixed. Memory usage is governed by
44
+ * two parameters: one is the amount of data passed in to update()
45
+ * and the other is memoryBlockSize. The latter comes into play
46
+ * only when the memory window exceeds the pre allocated memory
47
+ * window of flash player. Usage: create an instance, call
48
+ * update(data) repeatedly for all chunks and finally complete()
49
+ * which will return the md5 hash.
50
+ */
51
+ public class MD5Stream
52
+ {
53
+ private static var mask:int = 0xFF;
54
+
55
+ private var arr:Array = [];
56
+
57
+ /* running count of length */
58
+ private var arrLen:int;
59
+
60
+ // initialize the md buffers
61
+ private var a:int = 1732584193;
62
+ private var b:int = -271733879;
63
+ private var c:int = -1732584194;
64
+ private var d:int = 271733878;
65
+
66
+ // variables to store previous values
67
+ private var aa:int;
68
+ private var bb:int;
69
+ private var cc:int;
70
+ private var dd:int;
71
+
72
+ /* index for data read */
73
+ private var arrIndexLen:int = 0;
74
+ /* index for hash computation */
75
+ private var arrProcessIndex:int = 0;
76
+ /* index for removing stale arr values */
77
+ private var cleanIndex:int = 0;
78
+
79
+ /**
80
+ * Change this value from the default (16384) in the range of
81
+ * MBs to actually affect GC as GC allocates in pools of
82
+ * memory */
83
+ public var memoryBlockSize:int = 16384;
84
+
85
+
86
+ public function MD5Stream()
87
+ {
88
+
89
+ }
90
+
91
+
92
+ /**
93
+ * Pass in chunks of the input data with update(), call
94
+ * complete() with an optional chunk which will return the
95
+ * final hash. Equivalent to the way
96
+ * java.security.MessageDigest works.
97
+ *
98
+ * @param input The optional bytearray chunk which is the final part of the input
99
+ * @return A string containing the hash value
100
+ * @langversion ActionScript 3.0
101
+ * @playerversion Flash 8.5
102
+ * @tiptext
103
+ */
104
+ public function complete(input:ByteArray=null):String
105
+ {
106
+ if ( arr.length == 0 )
107
+ {
108
+ if ( input == null )
109
+ {
110
+ throw new Error("null input to complete without prior call to update. At least an empty bytearray must be passed.");
111
+ }
112
+ }
113
+
114
+ if ( input != null )
115
+ {
116
+ readIntoArray(input);
117
+ }
118
+
119
+ //pad, append length
120
+ padArray(arrLen);
121
+
122
+ hashRemainingChunks(false);
123
+
124
+ var res:String = IntUtil.toHex( a ) + IntUtil.toHex( b ) +
125
+ IntUtil.toHex( c ) + IntUtil.toHex( d );
126
+ resetFields();
127
+
128
+ return res;
129
+ }
130
+
131
+ /**
132
+ * Pass in chunks of the input data with update(), call
133
+ * complete() with an optional chunk which will return the
134
+ * final hash. Equivalent to the way
135
+ * java.security.MessageDigest works.
136
+ *
137
+ * @param input The bytearray chunk to perform the hash on
138
+ * @langversion ActionScript 3.0
139
+ * @playerversion Flash 8.5
140
+ * @tiptext
141
+ */
142
+ public function update(input:ByteArray):void
143
+ {
144
+ readIntoArray(input);
145
+ hashRemainingChunks();
146
+ }
147
+
148
+ /**
149
+ * Re-initialize this instance for use to perform hashing on
150
+ * another input stream. This is called automatically by
151
+ * complete().
152
+ *
153
+ * @langversion ActionScript 3.0
154
+ * @playerversion Flash 8.5
155
+ * @tiptext
156
+ */
157
+ public function resetFields():void
158
+ {
159
+ //truncate array
160
+ arr.length = 0;
161
+ arrLen = 0;
162
+
163
+ // initialize the md buffers
164
+ a = 1732584193;
165
+ b = -271733879;
166
+ c = -1732584194;
167
+ d = 271733878;
168
+
169
+ // variables to store previous values
170
+ aa = 0;
171
+ bb = 0;
172
+ cc = 0;
173
+ dd = 0;
174
+
175
+ arrIndexLen = 0;
176
+ arrProcessIndex = 0;
177
+ cleanIndex = 0;
178
+ }
179
+
180
+ /** read into arr and free up used blocks of arr */
181
+ private function readIntoArray(input:ByteArray):void
182
+ {
183
+ var closestChunkLen:int = input.length * 8;
184
+ arrLen += closestChunkLen;
185
+
186
+ /* clean up memory. if there are entries in the array that
187
+ * are already processed and the amount is greater than
188
+ * memoryBlockSize, create a new array, copy the last
189
+ * block into it and let the old one get picked up by
190
+ * GC. */
191
+ if ( arrProcessIndex - cleanIndex > memoryBlockSize )
192
+ {
193
+ var newarr:Array= new Array();
194
+
195
+ /* AS Arrays in sparse arrays. arr[2002] can exist
196
+ * without values for arr[0] - arr[2001] */
197
+ for ( var j:int = arrProcessIndex; j < arr.length; j++ )
198
+ {
199
+ newarr[j] = arr[j];
200
+ }
201
+
202
+ cleanIndex = arrProcessIndex;
203
+ arr = null;
204
+ arr = newarr;
205
+ }
206
+
207
+ for ( var k:int = 0; k < closestChunkLen; k+=8 )
208
+ {
209
+ //discard high bytes (convert to uint)
210
+ arr[ int(arrIndexLen >> 5) ] |= ( input[ k / 8 ] & mask ) << ( arrIndexLen % 32 );
211
+ arrIndexLen += 8;
212
+ }
213
+
214
+
215
+ }
216
+
217
+ private function hashRemainingChunks(bUpdate:Boolean=true):void
218
+ {
219
+ var len:int = arr.length;
220
+
221
+ /* leave a 16 word block untouched if we are called from
222
+ * update. This is because, padArray() can modify the last
223
+ * block and this modification has to happen before we
224
+ * compute the hash. */
225
+ if ( bUpdate )
226
+ {
227
+ len -= 16;
228
+ }
229
+
230
+ /* don't do anything if don't have a 16 word block. */
231
+ if ( arrProcessIndex >= len || len - arrProcessIndex < 15 )
232
+ {
233
+ return;
234
+ }
235
+
236
+
237
+ for ( var i:int = arrProcessIndex; i < len ; i += 16, arrProcessIndex += 16)
238
+ {
239
+ // save previous values
240
+ aa = a;
241
+ bb = b;
242
+ cc = c;
243
+ dd = d;
244
+
245
+ // Round 1
246
+ a = ff( a, b, c, d, arr[int(i+ 0)], 7, -680876936 ); // 1
247
+ d = ff( d, a, b, c, arr[int(i+ 1)], 12, -389564586 ); // 2
248
+ c = ff( c, d, a, b, arr[int(i+ 2)], 17, 606105819 ); // 3
249
+ b = ff( b, c, d, a, arr[int(i+ 3)], 22, -1044525330 ); // 4
250
+ a = ff( a, b, c, d, arr[int(i+ 4)], 7, -176418897 ); // 5
251
+ d = ff( d, a, b, c, arr[int(i+ 5)], 12, 1200080426 ); // 6
252
+ c = ff( c, d, a, b, arr[int(i+ 6)], 17, -1473231341 ); // 7
253
+ b = ff( b, c, d, a, arr[int(i+ 7)], 22, -45705983 ); // 8
254
+ a = ff( a, b, c, d, arr[int(i+ 8)], 7, 1770035416 ); // 9
255
+ d = ff( d, a, b, c, arr[int(i+ 9)], 12, -1958414417 ); // 10
256
+ c = ff( c, d, a, b, arr[int(i+10)], 17, -42063 ); // 11
257
+ b = ff( b, c, d, a, arr[int(i+11)], 22, -1990404162 ); // 12
258
+ a = ff( a, b, c, d, arr[int(i+12)], 7, 1804603682 ); // 13
259
+ d = ff( d, a, b, c, arr[int(i+13)], 12, -40341101 ); // 14
260
+ c = ff( c, d, a, b, arr[int(i+14)], 17, -1502002290 ); // 15
261
+ b = ff( b, c, d, a, arr[int(i+15)], 22, 1236535329 ); // 16
262
+
263
+ // Round 2
264
+ a = gg( a, b, c, d, arr[int(i+ 1)], 5, -165796510 ); // 17
265
+ d = gg( d, a, b, c, arr[int(i+ 6)], 9, -1069501632 ); // 18
266
+ c = gg( c, d, a, b, arr[int(i+11)], 14, 643717713 ); // 19
267
+ b = gg( b, c, d, a, arr[int(i+ 0)], 20, -373897302 ); // 20
268
+ a = gg( a, b, c, d, arr[int(i+ 5)], 5, -701558691 ); // 21
269
+ d = gg( d, a, b, c, arr[int(i+10)], 9, 38016083 ); // 22
270
+ c = gg( c, d, a, b, arr[int(i+15)], 14, -660478335 ); // 23
271
+ b = gg( b, c, d, a, arr[int(i+ 4)], 20, -405537848 ); // 24
272
+ a = gg( a, b, c, d, arr[int(i+ 9)], 5, 568446438 ); // 25
273
+ d = gg( d, a, b, c, arr[int(i+14)], 9, -1019803690 ); // 26
274
+ c = gg( c, d, a, b, arr[int(i+ 3)], 14, -187363961 ); // 27
275
+ b = gg( b, c, d, a, arr[int(i+ 8)], 20, 1163531501 ); // 28
276
+ a = gg( a, b, c, d, arr[int(i+13)], 5, -1444681467 ); // 29
277
+ d = gg( d, a, b, c, arr[int(i+ 2)], 9, -51403784 ); // 30
278
+ c = gg( c, d, a, b, arr[int(i+ 7)], 14, 1735328473 ); // 31
279
+ b = gg( b, c, d, a, arr[int(i+12)], 20, -1926607734 ); // 32
280
+
281
+ // Round 3
282
+ a = hh( a, b, c, d, arr[int(i+ 5)], 4, -378558 ); // 33
283
+ d = hh( d, a, b, c, arr[int(i+ 8)], 11, -2022574463 ); // 34
284
+ c = hh( c, d, a, b, arr[int(i+11)], 16, 1839030562 ); // 35
285
+ b = hh( b, c, d, a, arr[int(i+14)], 23, -35309556 ); // 36
286
+ a = hh( a, b, c, d, arr[int(i+ 1)], 4, -1530992060 ); // 37
287
+ d = hh( d, a, b, c, arr[int(i+ 4)], 11, 1272893353 ); // 38
288
+ c = hh( c, d, a, b, arr[int(i+ 7)], 16, -155497632 ); // 39
289
+ b = hh( b, c, d, a, arr[int(i+10)], 23, -1094730640 ); // 40
290
+ a = hh( a, b, c, d, arr[int(i+13)], 4, 681279174 ); // 41
291
+ d = hh( d, a, b, c, arr[int(i+ 0)], 11, -358537222 ); // 42
292
+ c = hh( c, d, a, b, arr[int(i+ 3)], 16, -722521979 ); // 43
293
+ b = hh( b, c, d, a, arr[int(i+ 6)], 23, 76029189 ); // 44
294
+ a = hh( a, b, c, d, arr[int(i+ 9)], 4, -640364487 ); // 45
295
+ d = hh( d, a, b, c, arr[int(i+12)], 11, -421815835 ); // 46
296
+ c = hh( c, d, a, b, arr[int(i+15)], 16, 530742520 ); // 47
297
+ b = hh( b, c, d, a, arr[int(i+ 2)], 23, -995338651 ); // 48
298
+
299
+ // Round 4
300
+ a = ii( a, b, c, d, arr[int(i+ 0)], 6, -198630844 ); // 49
301
+ d = ii( d, a, b, c, arr[int(i+ 7)], 10, 1126891415 ); // 50
302
+ c = ii( c, d, a, b, arr[int(i+14)], 15, -1416354905 ); // 51
303
+ b = ii( b, c, d, a, arr[int(i+ 5)], 21, -57434055 ); // 52
304
+ a = ii( a, b, c, d, arr[int(i+12)], 6, 1700485571 ); // 53
305
+ d = ii( d, a, b, c, arr[int(i+ 3)], 10, -1894986606 ); // 54
306
+ c = ii( c, d, a, b, arr[int(i+10)], 15, -1051523 ); // 55
307
+ b = ii( b, c, d, a, arr[int(i+ 1)], 21, -2054922799 ); // 56
308
+ a = ii( a, b, c, d, arr[int(i+ 8)], 6, 1873313359 ); // 57
309
+ d = ii( d, a, b, c, arr[int(i+15)], 10, -30611744 ); // 58
310
+ c = ii( c, d, a, b, arr[int(i+ 6)], 15, -1560198380 ); // 59
311
+ b = ii( b, c, d, a, arr[int(i+13)], 21, 1309151649 ); // 60
312
+ a = ii( a, b, c, d, arr[int(i+ 4)], 6, -145523070 ); // 61
313
+ d = ii( d, a, b, c, arr[int(i+11)], 10, -1120210379 ); // 62
314
+ c = ii( c, d, a, b, arr[int(i+ 2)], 15, 718787259 ); // 63
315
+ b = ii( b, c, d, a, arr[int(i+ 9)], 21, -343485551 ); // 64
316
+
317
+ a += aa;
318
+ b += bb;
319
+ c += cc;
320
+ d += dd;
321
+
322
+ }
323
+
324
+ }
325
+
326
+ private function padArray(len:int):void
327
+ {
328
+ arr[ int(len >> 5) ] |= 0x80 << ( len % 32 );
329
+ arr[ int(( ( ( len + 64 ) >>> 9 ) << 4 ) + 14) ] = len;
330
+ arrLen = arr.length;
331
+ }
332
+
333
+ /* Code below same as com.adobe.crypto.MD5 */
334
+
335
+ /**
336
+ * Auxiliary function f as defined in RFC
337
+ */
338
+ private static function f( x:int, y:int, z:int ):int {
339
+ return ( x & y ) | ( (~x) & z );
340
+ }
341
+
342
+ /**
343
+ * Auxiliary function g as defined in RFC
344
+ */
345
+ private static function g( x:int, y:int, z:int ):int {
346
+ return ( x & z ) | ( y & (~z) );
347
+ }
348
+
349
+ /**
350
+ * Auxiliary function h as defined in RFC
351
+ */
352
+ private static function h( x:int, y:int, z:int ):int {
353
+ return x ^ y ^ z;
354
+ }
355
+
356
+ /**
357
+ * Auxiliary function i as defined in RFC
358
+ */
359
+ private static function i( x:int, y:int, z:int ):int {
360
+ return y ^ ( x | (~z) );
361
+ }
362
+
363
+ /**
364
+ * A generic transformation function. The logic of ff, gg, hh, and
365
+ * ii are all the same, minus the function used, so pull that logic
366
+ * out and simplify the method bodies for the transoformation functions.
367
+ */
368
+ private static function transform( func:Function, a:int, b:int, c:int, d:int, x:int, s:int, t:int):int {
369
+ var tmp:int = a + int( func( b, c, d ) ) + x + t;
370
+ return IntUtil.rol( tmp, s ) + b;
371
+ }
372
+
373
+ /**
374
+ * ff transformation function
375
+ */
376
+ private static function ff ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
377
+ return transform( f, a, b, c, d, x, s, t );
378
+ }
379
+
380
+ /**
381
+ * gg transformation function
382
+ */
383
+ private static function gg ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
384
+ return transform( g, a, b, c, d, x, s, t );
385
+ }
386
+
387
+ /**
388
+ * hh transformation function
389
+ */
390
+ private static function hh ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
391
+ return transform( h, a, b, c, d, x, s, t );
392
+ }
393
+
394
+ /**
395
+ * ii transformation function
396
+ */
397
+ private static function ii ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
398
+ return transform( i, a, b, c, d, x, s, t );
399
+ }
400
+
401
+ }
402
+ }
DISPLAYER/com/adobe/crypto/SHA1.as ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ var temp:int;
134
+
135
+ // loop over all of the blocks
136
+ for ( var i:int = 0; i < len; i += 16 ) {
137
+
138
+ // 6.1.c
139
+ var a:int = h0;
140
+ var b:int = h1;
141
+ var c:int = h2;
142
+ var d:int = h3;
143
+ var e:int = h4;
144
+
145
+ // 80 steps to process each block
146
+ var t:int;
147
+ for ( t = 0; t < 20; t++ ) {
148
+
149
+ if ( t < 16 ) {
150
+ // 6.1.a
151
+ w[ t ] = blocks[ i + t ];
152
+ } else {
153
+ // 6.1.b
154
+ temp = w[ t - 3 ] ^ w[ t - 8 ] ^ w[ t - 14 ] ^ w[ t - 16 ];
155
+ w[ t ] = ( temp << 1 ) | ( temp >>> 31 )
156
+ }
157
+
158
+ // 6.1.d
159
+ temp = ( ( a << 5 ) | ( a >>> 27 ) ) + ( ( b & c ) | ( ~b & d ) ) + e + int( w[ t ] ) + 0x5a827999;
160
+
161
+ e = d;
162
+ d = c;
163
+ c = ( b << 30 ) | ( b >>> 2 );
164
+ b = a;
165
+ a = temp;
166
+ }
167
+ for ( ; t < 40; t++ )
168
+ {
169
+ // 6.1.b
170
+ temp = w[ t - 3 ] ^ w[ t - 8 ] ^ w[ t - 14 ] ^ w[ t - 16 ];
171
+ w[ t ] = ( temp << 1 ) | ( temp >>> 31 )
172
+
173
+ // 6.1.d
174
+ temp = ( ( a << 5 ) | ( a >>> 27 ) ) + ( b ^ c ^ d ) + e + int( w[ t ] ) + 0x6ed9eba1;
175
+
176
+ e = d;
177
+ d = c;
178
+ c = ( b << 30 ) | ( b >>> 2 );
179
+ b = a;
180
+ a = temp;
181
+ }
182
+ for ( ; t < 60; t++ )
183
+ {
184
+ // 6.1.b
185
+ temp = w[ t - 3 ] ^ w[ t - 8 ] ^ w[ t - 14 ] ^ w[ t - 16 ];
186
+ w[ t ] = ( temp << 1 ) | ( temp >>> 31 )
187
+
188
+ // 6.1.d
189
+ temp = ( ( a << 5 ) | ( a >>> 27 ) ) + ( ( b & c ) | ( b & d ) | ( c & d ) ) + e + int( w[ t ] ) + 0x8f1bbcdc;
190
+
191
+ e = d;
192
+ d = c;
193
+ c = ( b << 30 ) | ( b >>> 2 );
194
+ b = a;
195
+ a = temp;
196
+ }
197
+ for ( ; t < 80; t++ )
198
+ {
199
+ // 6.1.b
200
+ temp = w[ t - 3 ] ^ w[ t - 8 ] ^ w[ t - 14 ] ^ w[ t - 16 ];
201
+ w[ t ] = ( temp << 1 ) | ( temp >>> 31 )
202
+
203
+ // 6.1.d
204
+ temp = ( ( a << 5 ) | ( a >>> 27 ) ) + ( b ^ c ^ d ) + e + int( w[ t ] ) + 0xca62c1d6;
205
+
206
+ e = d;
207
+ d = c;
208
+ c = ( b << 30 ) | ( b >>> 2 );
209
+ b = a;
210
+ a = temp;
211
+ }
212
+
213
+ // 6.1.e
214
+ h0 += a;
215
+ h1 += b;
216
+ h2 += c;
217
+ h3 += d;
218
+ h4 += e;
219
+ }
220
+
221
+ var byteArray:ByteArray = new ByteArray();
222
+ byteArray.writeInt(h0);
223
+ byteArray.writeInt(h1);
224
+ byteArray.writeInt(h2);
225
+ byteArray.writeInt(h3);
226
+ byteArray.writeInt(h4);
227
+ byteArray.position = 0;
228
+
229
+ digest = new ByteArray();
230
+ digest.writeBytes(byteArray);
231
+ digest.position = 0;
232
+ return byteArray;
233
+ }
234
+
235
+ /**
236
+ * Converts a ByteArray to a sequence of 16-word blocks
237
+ * that we'll do the processing on. Appends padding
238
+ * and length in the process.
239
+ *
240
+ * @param data The data to split into blocks
241
+ * @return An array containing the blocks into which data was split
242
+ */
243
+ private static function createBlocksFromByteArray( data:ByteArray ):Array
244
+ {
245
+ var oldPosition:int = data.position;
246
+ data.position = 0;
247
+
248
+ var blocks:Array = new Array();
249
+ var len:int = data.length * 8;
250
+ var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
251
+ for( var i:int = 0; i < len; i += 8 )
252
+ {
253
+ blocks[ i >> 5 ] |= ( data.readByte() & mask ) << ( 24 - i % 32 );
254
+ }
255
+
256
+ // append padding and length
257
+ blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
258
+ blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
259
+
260
+ data.position = oldPosition;
261
+
262
+ return blocks;
263
+ }
264
+
265
+ /**
266
+ * Converts a string to a sequence of 16-word blocks
267
+ * that we'll do the processing on. Appends padding
268
+ * and length in the process.
269
+ *
270
+ * @param s The string to split into blocks
271
+ * @return An array containing the blocks that s was split into.
272
+ */
273
+ private static function createBlocksFromString( s:String ):Array
274
+ {
275
+ var blocks:Array = new Array();
276
+ var len:int = s.length * 8;
277
+ var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
278
+ for( var i:int = 0; i < len; i += 8 ) {
279
+ blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( 24 - i % 32 );
280
+ }
281
+
282
+ // append padding and length
283
+ blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
284
+ blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
285
+ return blocks;
286
+ }
287
+
288
+ }
289
+ }
DISPLAYER/com/adobe/crypto/SHA224.as ADDED
@@ -0,0 +1,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-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
+ }
DISPLAYER/com/adobe/crypto/SHA256.as ADDED
@@ -0,0 +1,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 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
+ }
DISPLAYER/com/adobe/crypto/WSSEUsernameToken.as ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
DISPLAYER/com/adobe/errors/IllegalStateError.as ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
DISPLAYER/com/adobe/fileformats/vcard/Address.as ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
DISPLAYER/com/adobe/fileformats/vcard/Email.as ADDED
@@ -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.fileformats.vcard
33
+ {
34
+ public class Email
35
+ {
36
+ public var type:String;
37
+ public var address:String;
38
+ }
39
+ }
DISPLAYER/com/adobe/fileformats/vcard/Phone.as ADDED
@@ -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.fileformats.vcard
33
+ {
34
+ public class Phone
35
+ {
36
+ public var type:String;
37
+ public var number:String;
38
+ }
39
+ }
DISPLAYER/com/adobe/fileformats/vcard/VCard.as ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
DISPLAYER/com/adobe/fileformats/vcard/VCardParser.as ADDED
@@ -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
+ }
DISPLAYER/com/adobe/images/BitString.as ADDED
@@ -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
+ }
DISPLAYER/com/adobe/images/JPGEncoder.as ADDED
@@ -0,0 +1,648 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.*;
36
+ import flash.utils.*;
37
+
38
+ /**
39
+ * Class that converts BitmapData into a valid JPEG
40
+ */
41
+ public class JPGEncoder
42
+ {
43
+
44
+ // Static table initialization
45
+
46
+ private var ZigZag:Array = [
47
+ 0, 1, 5, 6,14,15,27,28,
48
+ 2, 4, 7,13,16,26,29,42,
49
+ 3, 8,12,17,25,30,41,43,
50
+ 9,11,18,24,31,40,44,53,
51
+ 10,19,23,32,39,45,52,54,
52
+ 20,22,33,38,46,51,55,60,
53
+ 21,34,37,47,50,56,59,61,
54
+ 35,36,48,49,57,58,62,63
55
+ ];
56
+
57
+ private var YTable:Array = new Array(64);
58
+ private var UVTable:Array = new Array(64);
59
+ private var fdtbl_Y:Array = new Array(64);
60
+ private var fdtbl_UV:Array = new Array(64);
61
+
62
+ private function initQuantTables(sf:int):void
63
+ {
64
+ var i:int;
65
+ var t:Number;
66
+ var YQT:Array = [
67
+ 16, 11, 10, 16, 24, 40, 51, 61,
68
+ 12, 12, 14, 19, 26, 58, 60, 55,
69
+ 14, 13, 16, 24, 40, 57, 69, 56,
70
+ 14, 17, 22, 29, 51, 87, 80, 62,
71
+ 18, 22, 37, 56, 68,109,103, 77,
72
+ 24, 35, 55, 64, 81,104,113, 92,
73
+ 49, 64, 78, 87,103,121,120,101,
74
+ 72, 92, 95, 98,112,100,103, 99
75
+ ];
76
+ for (i = 0; i < 64; i++) {
77
+ t = Math.floor((YQT[i]*sf+50)/100);
78
+ if (t < 1) {
79
+ t = 1;
80
+ } else if (t > 255) {
81
+ t = 255;
82
+ }
83
+ YTable[ZigZag[i]] = t;
84
+ }
85
+ var UVQT:Array = [
86
+ 17, 18, 24, 47, 99, 99, 99, 99,
87
+ 18, 21, 26, 66, 99, 99, 99, 99,
88
+ 24, 26, 56, 99, 99, 99, 99, 99,
89
+ 47, 66, 99, 99, 99, 99, 99, 99,
90
+ 99, 99, 99, 99, 99, 99, 99, 99,
91
+ 99, 99, 99, 99, 99, 99, 99, 99,
92
+ 99, 99, 99, 99, 99, 99, 99, 99,
93
+ 99, 99, 99, 99, 99, 99, 99, 99
94
+ ];
95
+ for (i = 0; i < 64; i++) {
96
+ t = Math.floor((UVQT[i]*sf+50)/100);
97
+ if (t < 1) {
98
+ t = 1;
99
+ } else if (t > 255) {
100
+ t = 255;
101
+ }
102
+ UVTable[ZigZag[i]] = t;
103
+ }
104
+ var aasf:Array = [
105
+ 1.0, 1.387039845, 1.306562965, 1.175875602,
106
+ 1.0, 0.785694958, 0.541196100, 0.275899379
107
+ ];
108
+ i = 0;
109
+ for (var row:int = 0; row < 8; row++)
110
+ {
111
+ for (var col:int = 0; col < 8; col++)
112
+ {
113
+ fdtbl_Y[i] = (1.0 / (YTable [ZigZag[i]] * aasf[row] * aasf[col] * 8.0));
114
+ fdtbl_UV[i] = (1.0 / (UVTable[ZigZag[i]] * aasf[row] * aasf[col] * 8.0));
115
+ i++;
116
+ }
117
+ }
118
+ }
119
+
120
+ private var YDC_HT:Array;
121
+ private var UVDC_HT:Array;
122
+ private var YAC_HT:Array;
123
+ private var UVAC_HT:Array;
124
+
125
+ private function computeHuffmanTbl(nrcodes:Array, std_table:Array):Array
126
+ {
127
+ var codevalue:int = 0;
128
+ var pos_in_table:int = 0;
129
+ var HT:Array = new Array();
130
+ for (var k:int=1; k<=16; k++) {
131
+ for (var j:int=1; j<=nrcodes[k]; j++) {
132
+ HT[std_table[pos_in_table]] = new BitString();
133
+ HT[std_table[pos_in_table]].val = codevalue;
134
+ HT[std_table[pos_in_table]].len = k;
135
+ pos_in_table++;
136
+ codevalue++;
137
+ }
138
+ codevalue*=2;
139
+ }
140
+ return HT;
141
+ }
142
+
143
+ private var std_dc_luminance_nrcodes:Array = [0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0];
144
+ private var std_dc_luminance_values:Array = [0,1,2,3,4,5,6,7,8,9,10,11];
145
+ private var std_ac_luminance_nrcodes:Array = [0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d];
146
+ private var std_ac_luminance_values:Array = [
147
+ 0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,
148
+ 0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,
149
+ 0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08,
150
+ 0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,
151
+ 0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,
152
+ 0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28,
153
+ 0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,
154
+ 0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,
155
+ 0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,
156
+ 0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,
157
+ 0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,
158
+ 0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89,
159
+ 0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,
160
+ 0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,
161
+ 0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,
162
+ 0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,
163
+ 0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,
164
+ 0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,
165
+ 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,
166
+ 0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
167
+ 0xf9,0xfa
168
+ ];
169
+
170
+ private var std_dc_chrominance_nrcodes:Array = [0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0];
171
+ private var std_dc_chrominance_values:Array = [0,1,2,3,4,5,6,7,8,9,10,11];
172
+ private var std_ac_chrominance_nrcodes:Array = [0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77];
173
+ private var std_ac_chrominance_values:Array = [
174
+ 0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,
175
+ 0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,
176
+ 0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,
177
+ 0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,
178
+ 0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,
179
+ 0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26,
180
+ 0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,
181
+ 0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,
182
+ 0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,
183
+ 0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,
184
+ 0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,
185
+ 0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87,
186
+ 0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,
187
+ 0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,
188
+ 0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,
189
+ 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,
190
+ 0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,
191
+ 0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,
192
+ 0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,
193
+ 0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
194
+ 0xf9,0xfa
195
+ ];
196
+
197
+ private function initHuffmanTbl():void
198
+ {
199
+ YDC_HT = computeHuffmanTbl(std_dc_luminance_nrcodes,std_dc_luminance_values);
200
+ UVDC_HT = computeHuffmanTbl(std_dc_chrominance_nrcodes,std_dc_chrominance_values);
201
+ YAC_HT = computeHuffmanTbl(std_ac_luminance_nrcodes,std_ac_luminance_values);
202
+ UVAC_HT = computeHuffmanTbl(std_ac_chrominance_nrcodes,std_ac_chrominance_values);
203
+ }
204
+
205
+ private var bitcode:Array = new Array(65535);
206
+ private var category:Array = new Array(65535);
207
+
208
+ private function initCategoryNumber():void
209
+ {
210
+ var nrlower:int = 1;
211
+ var nrupper:int = 2;
212
+ var nr:int;
213
+ for (var cat:int=1; cat<=15; cat++) {
214
+ //Positive numbers
215
+ for (nr=nrlower; nr<nrupper; nr++) {
216
+ category[32767+nr] = cat;
217
+ bitcode[32767+nr] = new BitString();
218
+ bitcode[32767+nr].len = cat;
219
+ bitcode[32767+nr].val = nr;
220
+ }
221
+ //Negative numbers
222
+ for (nr=-(nrupper-1); nr<=-nrlower; nr++) {
223
+ category[32767+nr] = cat;
224
+ bitcode[32767+nr] = new BitString();
225
+ bitcode[32767+nr].len = cat;
226
+ bitcode[32767+nr].val = nrupper-1+nr;
227
+ }
228
+ nrlower <<= 1;
229
+ nrupper <<= 1;
230
+ }
231
+ }
232
+
233
+ // IO functions
234
+
235
+ private var byteout:ByteArray;
236
+ private var bytenew:int = 0;
237
+ private var bytepos:int = 7;
238
+
239
+ private function writeBits(bs:BitString):void
240
+ {
241
+ var value:int = bs.val;
242
+ var posval:int = bs.len-1;
243
+ while ( posval >= 0 ) {
244
+ if (value & uint(1 << posval) ) {
245
+ bytenew |= uint(1 << bytepos);
246
+ }
247
+ posval--;
248
+ bytepos--;
249
+ if (bytepos < 0) {
250
+ if (bytenew == 0xFF) {
251
+ writeByte(0xFF);
252
+ writeByte(0);
253
+ }
254
+ else {
255
+ writeByte(bytenew);
256
+ }
257
+ bytepos=7;
258
+ bytenew=0;
259
+ }
260
+ }
261
+ }
262
+
263
+ private function writeByte(value:int):void
264
+ {
265
+ byteout.writeByte(value);
266
+ }
267
+
268
+ private function writeWord(value:int):void
269
+ {
270
+ writeByte((value>>8)&0xFF);
271
+ writeByte((value )&0xFF);
272
+ }
273
+
274
+ // DCT & quantization core
275
+
276
+ private function fDCTQuant(data:Array, fdtbl:Array):Array
277
+ {
278
+ var tmp0:Number, tmp1:Number, tmp2:Number, tmp3:Number, tmp4:Number, tmp5:Number, tmp6:Number, tmp7:Number;
279
+ var tmp10:Number, tmp11:Number, tmp12:Number, tmp13:Number;
280
+ var z1:Number, z2:Number, z3:Number, z4:Number, z5:Number, z11:Number, z13:Number;
281
+ var i:int;
282
+ /* Pass 1: process rows. */
283
+ var dataOff:int=0;
284
+ for (i=0; i<8; i++) {
285
+ tmp0 = data[dataOff+0] + data[dataOff+7];
286
+ tmp7 = data[dataOff+0] - data[dataOff+7];
287
+ tmp1 = data[dataOff+1] + data[dataOff+6];
288
+ tmp6 = data[dataOff+1] - data[dataOff+6];
289
+ tmp2 = data[dataOff+2] + data[dataOff+5];
290
+ tmp5 = data[dataOff+2] - data[dataOff+5];
291
+ tmp3 = data[dataOff+3] + data[dataOff+4];
292
+ tmp4 = data[dataOff+3] - data[dataOff+4];
293
+
294
+ /* Even part */
295
+ tmp10 = tmp0 + tmp3; /* phase 2 */
296
+ tmp13 = tmp0 - tmp3;
297
+ tmp11 = tmp1 + tmp2;
298
+ tmp12 = tmp1 - tmp2;
299
+
300
+ data[dataOff+0] = tmp10 + tmp11; /* phase 3 */
301
+ data[dataOff+4] = tmp10 - tmp11;
302
+
303
+ z1 = (tmp12 + tmp13) * 0.707106781; /* c4 */
304
+ data[dataOff+2] = tmp13 + z1; /* phase 5 */
305
+ data[dataOff+6] = tmp13 - z1;
306
+
307
+ /* Odd part */
308
+ tmp10 = tmp4 + tmp5; /* phase 2 */
309
+ tmp11 = tmp5 + tmp6;
310
+ tmp12 = tmp6 + tmp7;
311
+
312
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
313
+ z5 = (tmp10 - tmp12) * 0.382683433; /* c6 */
314
+ z2 = 0.541196100 * tmp10 + z5; /* c2-c6 */
315
+ z4 = 1.306562965 * tmp12 + z5; /* c2+c6 */
316
+ z3 = tmp11 * 0.707106781; /* c4 */
317
+
318
+ z11 = tmp7 + z3; /* phase 5 */
319
+ z13 = tmp7 - z3;
320
+
321
+ data[dataOff+5] = z13 + z2; /* phase 6 */
322
+ data[dataOff+3] = z13 - z2;
323
+ data[dataOff+1] = z11 + z4;
324
+ data[dataOff+7] = z11 - z4;
325
+
326
+ dataOff += 8; /* advance pointer to next row */
327
+ }
328
+
329
+ /* Pass 2: process columns. */
330
+ dataOff = 0;
331
+ for (i=0; i<8; i++) {
332
+ tmp0 = data[dataOff+ 0] + data[dataOff+56];
333
+ tmp7 = data[dataOff+ 0] - data[dataOff+56];
334
+ tmp1 = data[dataOff+ 8] + data[dataOff+48];
335
+ tmp6 = data[dataOff+ 8] - data[dataOff+48];
336
+ tmp2 = data[dataOff+16] + data[dataOff+40];
337
+ tmp5 = data[dataOff+16] - data[dataOff+40];
338
+ tmp3 = data[dataOff+24] + data[dataOff+32];
339
+ tmp4 = data[dataOff+24] - data[dataOff+32];
340
+
341
+ /* Even part */
342
+ tmp10 = tmp0 + tmp3; /* phase 2 */
343
+ tmp13 = tmp0 - tmp3;
344
+ tmp11 = tmp1 + tmp2;
345
+ tmp12 = tmp1 - tmp2;
346
+
347
+ data[dataOff+ 0] = tmp10 + tmp11; /* phase 3 */
348
+ data[dataOff+32] = tmp10 - tmp11;
349
+
350
+ z1 = (tmp12 + tmp13) * 0.707106781; /* c4 */
351
+ data[dataOff+16] = tmp13 + z1; /* phase 5 */
352
+ data[dataOff+48] = tmp13 - z1;
353
+
354
+ /* Odd part */
355
+ tmp10 = tmp4 + tmp5; /* phase 2 */
356
+ tmp11 = tmp5 + tmp6;
357
+ tmp12 = tmp6 + tmp7;
358
+
359
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
360
+ z5 = (tmp10 - tmp12) * 0.382683433; /* c6 */
361
+ z2 = 0.541196100 * tmp10 + z5; /* c2-c6 */
362
+ z4 = 1.306562965 * tmp12 + z5; /* c2+c6 */
363
+ z3 = tmp11 * 0.707106781; /* c4 */
364
+
365
+ z11 = tmp7 + z3; /* phase 5 */
366
+ z13 = tmp7 - z3;
367
+
368
+ data[dataOff+40] = z13 + z2; /* phase 6 */
369
+ data[dataOff+24] = z13 - z2;
370
+ data[dataOff+ 8] = z11 + z4;
371
+ data[dataOff+56] = z11 - z4;
372
+
373
+ dataOff++; /* advance pointer to next column */
374
+ }
375
+
376
+ // Quantize/descale the coefficients
377
+ for (i=0; i<64; i++) {
378
+ // Apply the quantization and scaling factor & Round to nearest integer
379
+ data[i] = Math.round((data[i]*fdtbl[i]));
380
+ }
381
+ return data;
382
+ }
383
+
384
+ // Chunk writing
385
+
386
+ private function writeAPP0():void
387
+ {
388
+ writeWord(0xFFE0); // marker
389
+ writeWord(16); // length
390
+ writeByte(0x4A); // J
391
+ writeByte(0x46); // F
392
+ writeByte(0x49); // I
393
+ writeByte(0x46); // F
394
+ writeByte(0); // = "JFIF",'\0'
395
+ writeByte(1); // versionhi
396
+ writeByte(1); // versionlo
397
+ writeByte(0); // xyunits
398
+ writeWord(1); // xdensity
399
+ writeWord(1); // ydensity
400
+ writeByte(0); // thumbnwidth
401
+ writeByte(0); // thumbnheight
402
+ }
403
+
404
+ private function writeSOF0(width:int, height:int):void
405
+ {
406
+ writeWord(0xFFC0); // marker
407
+ writeWord(17); // length, truecolor YUV JPG
408
+ writeByte(8); // precision
409
+ writeWord(height);
410
+ writeWord(width);
411
+ writeByte(3); // nrofcomponents
412
+ writeByte(1); // IdY
413
+ writeByte(0x11); // HVY
414
+ writeByte(0); // QTY
415
+ writeByte(2); // IdU
416
+ writeByte(0x11); // HVU
417
+ writeByte(1); // QTU
418
+ writeByte(3); // IdV
419
+ writeByte(0x11); // HVV
420
+ writeByte(1); // QTV
421
+ }
422
+
423
+ private function writeDQT():void
424
+ {
425
+ writeWord(0xFFDB); // marker
426
+ writeWord(132); // length
427
+ writeByte(0);
428
+ var i:int;
429
+ for (i=0; i<64; i++) {
430
+ writeByte(YTable[i]);
431
+ }
432
+ writeByte(1);
433
+ for (i=0; i<64; i++) {
434
+ writeByte(UVTable[i]);
435
+ }
436
+ }
437
+
438
+ private function writeDHT():void
439
+ {
440
+ writeWord(0xFFC4); // marker
441
+ writeWord(0x01A2); // length
442
+ var i:int;
443
+
444
+ writeByte(0); // HTYDCinfo
445
+ for (i=0; i<16; i++) {
446
+ writeByte(std_dc_luminance_nrcodes[i+1]);
447
+ }
448
+ for (i=0; i<=11; i++) {
449
+ writeByte(std_dc_luminance_values[i]);
450
+ }
451
+
452
+ writeByte(0x10); // HTYACinfo
453
+ for (i=0; i<16; i++) {
454
+ writeByte(std_ac_luminance_nrcodes[i+1]);
455
+ }
456
+ for (i=0; i<=161; i++) {
457
+ writeByte(std_ac_luminance_values[i]);
458
+ }
459
+
460
+ writeByte(1); // HTUDCinfo
461
+ for (i=0; i<16; i++) {
462
+ writeByte(std_dc_chrominance_nrcodes[i+1]);
463
+ }
464
+ for (i=0; i<=11; i++) {
465
+ writeByte(std_dc_chrominance_values[i]);
466
+ }
467
+
468
+ writeByte(0x11); // HTUACinfo
469
+ for (i=0; i<16; i++) {
470
+ writeByte(std_ac_chrominance_nrcodes[i+1]);
471
+ }
472
+ for (i=0; i<=161; i++) {
473
+ writeByte(std_ac_chrominance_values[i]);
474
+ }
475
+ }
476
+
477
+ private function writeSOS():void
478
+ {
479
+ writeWord(0xFFDA); // marker
480
+ writeWord(12); // length
481
+ writeByte(3); // nrofcomponents
482
+ writeByte(1); // IdY
483
+ writeByte(0); // HTY
484
+ writeByte(2); // IdU
485
+ writeByte(0x11); // HTU
486
+ writeByte(3); // IdV
487
+ writeByte(0x11); // HTV
488
+ writeByte(0); // Ss
489
+ writeByte(0x3f); // Se
490
+ writeByte(0); // Bf
491
+ }
492
+
493
+ // Core processing
494
+ private var DU:Array = new Array(64);
495
+
496
+ private function processDU(CDU:Array, fdtbl:Array, DC:Number, HTDC:Array, HTAC:Array):Number
497
+ {
498
+ var EOB:BitString = HTAC[0x00];
499
+ var M16zeroes:BitString = HTAC[0xF0];
500
+ var i:int;
501
+
502
+ var DU_DCT:Array = fDCTQuant(CDU, fdtbl);
503
+ //ZigZag reorder
504
+ for (i=0;i<64;i++) {
505
+ DU[ZigZag[i]]=DU_DCT[i];
506
+ }
507
+ var Diff:int = DU[0] - DC; DC = DU[0];
508
+ //Encode DC
509
+ if (Diff==0) {
510
+ writeBits(HTDC[0]); // Diff might be 0
511
+ } else {
512
+ writeBits(HTDC[category[32767+Diff]]);
513
+ writeBits(bitcode[32767+Diff]);
514
+ }
515
+ //Encode ACs
516
+ var end0pos:int = 63;
517
+ for (; (end0pos>0)&&(DU[end0pos]==0); end0pos--) {
518
+ };
519
+ //end0pos = first element in reverse order !=0
520
+ if ( end0pos == 0) {
521
+ writeBits(EOB);
522
+ return DC;
523
+ }
524
+ i = 1;
525
+ while ( i <= end0pos ) {
526
+ var startpos:int = i;
527
+ for (; (DU[i]==0) && (i<=end0pos); i++) {
528
+ }
529
+ var nrzeroes:int = i-startpos;
530
+ if ( nrzeroes >= 16 ) {
531
+ for (var nrmarker:int=1; nrmarker <= nrzeroes/16; nrmarker++) {
532
+ writeBits(M16zeroes);
533
+ }
534
+ nrzeroes = int(nrzeroes&0xF);
535
+ }
536
+ writeBits(HTAC[nrzeroes*16+category[32767+DU[i]]]);
537
+ writeBits(bitcode[32767+DU[i]]);
538
+ i++;
539
+ }
540
+ if ( end0pos != 63 ) {
541
+ writeBits(EOB);
542
+ }
543
+ return DC;
544
+ }
545
+
546
+ private var YDU:Array = new Array(64);
547
+ private var UDU:Array = new Array(64);
548
+ private var VDU:Array = new Array(64);
549
+
550
+ private function RGB2YUV(img:BitmapData, xpos:int, ypos:int):void
551
+ {
552
+ var pos:int=0;
553
+ for (var y:int=0; y<8; y++) {
554
+ for (var x:int=0; x<8; x++) {
555
+ var P:uint = img.getPixel32(xpos+x,ypos+y);
556
+ var R:Number = Number((P>>16)&0xFF);
557
+ var G:Number = Number((P>> 8)&0xFF);
558
+ var B:Number = Number((P )&0xFF);
559
+ YDU[pos]=((( 0.29900)*R+( 0.58700)*G+( 0.11400)*B))-128;
560
+ UDU[pos]=(((-0.16874)*R+(-0.33126)*G+( 0.50000)*B));
561
+ VDU[pos]=((( 0.50000)*R+(-0.41869)*G+(-0.08131)*B));
562
+ pos++;
563
+ }
564
+ }
565
+ }
566
+
567
+ /**
568
+ * Constructor for JPEGEncoder class
569
+ *
570
+ * @param quality The quality level between 1 and 100 that detrmines the
571
+ * level of compression used in the generated JPEG
572
+ * @langversion ActionScript 3.0
573
+ * @playerversion Flash 9.0
574
+ * @tiptext
575
+ */
576
+ public function JPGEncoder(quality:Number = 50)
577
+ {
578
+ if (quality <= 0) {
579
+ quality = 1;
580
+ }
581
+ if (quality > 100) {
582
+ quality = 100;
583
+ }
584
+ var sf:int = 0;
585
+ if (quality < 50) {
586
+ sf = int(5000 / quality);
587
+ } else {
588
+ sf = int(200 - quality*2);
589
+ }
590
+ // Create tables
591
+ initHuffmanTbl();
592
+ initCategoryNumber();
593
+ initQuantTables(sf);
594
+ }
595
+
596
+ /**
597
+ * Created a JPEG image from the specified BitmapData
598
+ *
599
+ * @param image The BitmapData that will be converted into the JPEG format.
600
+ * @return a ByteArray representing the JPEG encoded image data.
601
+ * @langversion ActionScript 3.0
602
+ * @playerversion Flash 9.0
603
+ * @tiptext
604
+ */
605
+ public function encode(image:BitmapData):ByteArray
606
+ {
607
+ // Initialize bit writer
608
+ byteout = new ByteArray();
609
+ bytenew=0;
610
+ bytepos=7;
611
+
612
+ // Add JPEG headers
613
+ writeWord(0xFFD8); // SOI
614
+ writeAPP0();
615
+ writeDQT();
616
+ writeSOF0(image.width,image.height);
617
+ writeDHT();
618
+ writeSOS();
619
+
620
+
621
+ // Encode 8x8 macroblocks
622
+ var DCY:Number=0;
623
+ var DCU:Number=0;
624
+ var DCV:Number=0;
625
+ bytenew=0;
626
+ bytepos=7;
627
+ for (var ypos:int=0; ypos<image.height; ypos+=8) {
628
+ for (var xpos:int=0; xpos<image.width; xpos+=8) {
629
+ RGB2YUV(image, xpos, ypos);
630
+ DCY = processDU(YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT);
631
+ DCU = processDU(UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT);
632
+ DCV = processDU(VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT);
633
+ }
634
+ }
635
+
636
+ // Do the bit alignment of the EOI marker
637
+ if ( bytepos >= 0 ) {
638
+ var fillbits:BitString = new BitString();
639
+ fillbits.len = bytepos+1;
640
+ fillbits.val = (1<<(bytepos+1))-1;
641
+ writeBits(fillbits);
642
+ }
643
+
644
+ writeWord(0xFFD9); //EOI
645
+ return byteout;
646
+ }
647
+ }
648
+ }
DISPLAYER/com/adobe/images/PNGEncoder.as ADDED
@@ -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
+ }
DISPLAYER/com/adobe/net/DynamicURLLoader.as ADDED
@@ -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
+ }
DISPLAYER/com/adobe/net/IURIResolver.as ADDED
@@ -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.</p>
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
+ }
DISPLAYER/com/adobe/net/MimeTypeMap.as ADDED
@@ -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
+ }
DISPLAYER/com/adobe/net/URI.as ADDED
@@ -0,0 +1,2466 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 functions and utilities for working with URI's
39
+ * (Universal Resource Identifiers). For technical description of the
40
+ * URI syntax, please see RFC 3986 at http://www.ietf.org/rfc/rfc3986.txt
41
+ * or do a web search for "rfc 3986".
42
+ *
43
+ * <p>The most important aspect of URI's to understand is that URI's
44
+ * and URL's are not strings. URI's are complex data structures that
45
+ * encapsulate many pieces of information. The string version of a
46
+ * URI is the serialized representation of that data structure. This
47
+ * string serialization is used to provide a human readable
48
+ * representation and a means to transport the data over the network
49
+ * where it can then be parsed back into its' component parts.</p>
50
+ *
51
+ * <p>URI's fall into one of three categories:
52
+ * <ul>
53
+ * <li>&lt;scheme&gt;:&lt;scheme-specific-part&gt;#&lt;fragment&gt; (non-hierarchical)</li>
54
+ * <li>&lt;scheme&gt;:&lt;authority&gt;&lt;path&gt;?&lt;query&gt;#&lt;fragment&gt; (hierarchical)</li>
55
+ * <li>&lt;path&gt;?&lt;query&gt;#&lt;fragment&gt; (relative hierarchical)</li>
56
+ * </ul></p>
57
+ *
58
+ * <p>The query and fragment parts are optional.</p>
59
+ *
60
+ * <p>This class supports both non-hierarchical and hierarchical URI's</p>
61
+ *
62
+ * <p>This class is intended to be used "as-is" for the vast majority
63
+ * of common URI's. However, if your application requires a custom
64
+ * URI syntax (e.g. custom query syntax or special handling of
65
+ * non-hierarchical URI's), this class can be fully subclassed. If you
66
+ * intended to subclass URI, please see the source code for complete
67
+ * documation on protected members and protected fuctions.</p>
68
+ *
69
+ * @langversion ActionScript 3.0
70
+ * @playerversion Flash 9.0
71
+ */
72
+ public class URI
73
+ {
74
+ // Here we define which characters must be escaped for each
75
+ // URI part. The characters that must be escaped for each
76
+ // part differ depending on what would cause ambiguous parsing.
77
+ // RFC 3986 sec. 2.4 states that characters should only be
78
+ // encoded when they would conflict with subcomponent delimiters.
79
+ // We don't want to over-do the escaping. We only want to escape
80
+ // the minimum needed to prevent parsing problems.
81
+
82
+ // space and % must be escaped in all cases. '%' is the delimiter
83
+ // for escaped characters.
84
+ public static const URImustEscape:String = " %";
85
+
86
+ // Baseline of what characters must be escaped
87
+ public static const URIbaselineEscape:String = URImustEscape + ":?#/@";
88
+
89
+ // Characters that must be escaped in the part part.
90
+ public static const URIpathEscape:String = URImustEscape + "?#";
91
+
92
+ // Characters that must be escaped in the query part, if setting
93
+ // the query as a whole string. If the query is set by
94
+ // name/value, URIqueryPartEscape is used instead.
95
+ public static const URIqueryEscape:String = URImustEscape + "#";
96
+
97
+ // This is what each name/value pair must escape "&=" as well
98
+ // so they don't conflict with the "param=value&param2=value2"
99
+ // syntax.
100
+ public static const URIqueryPartEscape:String = URImustEscape + "#&=";
101
+
102
+ // Non-hierarchical URI's can have query and fragment parts, but
103
+ // we also want to prevent '/' otherwise it might end up looking
104
+ // like a hierarchical URI to the parser.
105
+ public static const URInonHierEscape:String = URImustEscape + "?#/";
106
+
107
+ // Baseline uninitialized setting for the URI scheme.
108
+ public static const UNKNOWN_SCHEME:String = "unknown";
109
+
110
+ // The following bitmaps are used for performance enhanced
111
+ // character escaping.
112
+
113
+ // Baseline characters that need to be escaped. Many parts use
114
+ // this.
115
+ protected static const URIbaselineExcludedBitmap:URIEncodingBitmap =
116
+ new URIEncodingBitmap(URIbaselineEscape);
117
+
118
+ // Scheme escaping bitmap
119
+ protected static const URIschemeExcludedBitmap:URIEncodingBitmap =
120
+ URIbaselineExcludedBitmap;
121
+
122
+ // User/pass escaping bitmap
123
+ protected static const URIuserpassExcludedBitmap:URIEncodingBitmap =
124
+ URIbaselineExcludedBitmap;
125
+
126
+ // Authority escaping bitmap
127
+ protected static const URIauthorityExcludedBitmap:URIEncodingBitmap =
128
+ URIbaselineExcludedBitmap;
129
+
130
+ // Port escaping bitmap
131
+ protected static const URIportExludedBitmap:URIEncodingBitmap =
132
+ URIbaselineExcludedBitmap;
133
+
134
+ // Path escaping bitmap
135
+ protected static const URIpathExcludedBitmap:URIEncodingBitmap =
136
+ new URIEncodingBitmap(URIpathEscape);
137
+
138
+ // Query (whole) escaping bitmap
139
+ protected static const URIqueryExcludedBitmap:URIEncodingBitmap =
140
+ new URIEncodingBitmap(URIqueryEscape);
141
+
142
+ // Query (individual parts) escaping bitmap
143
+ protected static const URIqueryPartExcludedBitmap:URIEncodingBitmap =
144
+ new URIEncodingBitmap(URIqueryPartEscape);
145
+
146
+ // Fragments are the last part in the URI. They only need to
147
+ // escape space, '#', and '%'. Turns out that is what query
148
+ // uses too.
149
+ protected static const URIfragmentExcludedBitmap:URIEncodingBitmap =
150
+ URIqueryExcludedBitmap;
151
+
152
+ // Characters that need to be escaped in the non-hierarchical part
153
+ protected static const URInonHierexcludedBitmap:URIEncodingBitmap =
154
+ new URIEncodingBitmap(URInonHierEscape);
155
+
156
+ // Values used by getRelation()
157
+ public static const NOT_RELATED:int = 0;
158
+ public static const CHILD:int = 1;
159
+ public static const EQUAL:int = 2;
160
+ public static const PARENT:int = 3;
161
+
162
+ //-------------------------------------------------------------------
163
+ // protected class members
164
+ //-------------------------------------------------------------------
165
+ protected var _valid:Boolean = false;
166
+ protected var _relative:Boolean = false;
167
+ protected var _scheme:String = "";
168
+ protected var _authority:String = "";
169
+ protected var _username:String = "";
170
+ protected var _password:String = "";
171
+ protected var _port:String = "";
172
+ protected var _path:String = "";
173
+ protected var _query:String = "";
174
+ protected var _fragment:String = "";
175
+ protected var _nonHierarchical:String = "";
176
+ protected static var _resolver:IURIResolver = null;
177
+
178
+
179
+ /**
180
+ * URI Constructor. If no string is given, this will initialize
181
+ * this URI object to a blank URI.
182
+ */
183
+ public function URI(uri:String = null) : void
184
+ {
185
+ if (uri == null)
186
+ initialize();
187
+ else
188
+ constructURI(uri);
189
+ }
190
+
191
+
192
+ /**
193
+ * @private
194
+ * Method that loads the URI from the given string.
195
+ */
196
+ protected function constructURI(uri:String) : Boolean
197
+ {
198
+ if (!parseURI(uri))
199
+ _valid = false;
200
+
201
+ return isValid();
202
+ }
203
+
204
+
205
+ /**
206
+ * @private Private initializiation.
207
+ */
208
+ protected function initialize() : void
209
+ {
210
+ _valid = false;
211
+ _relative = false;
212
+
213
+ _scheme = UNKNOWN_SCHEME;
214
+ _authority = "";
215
+ _username = "";
216
+ _password = "";
217
+ _port = "";
218
+ _path = "";
219
+ _query = "";
220
+ _fragment = "";
221
+
222
+ _nonHierarchical = "";
223
+ }
224
+
225
+ /**
226
+ * @private Accessor to explicitly set/get the hierarchical
227
+ * state of the URI.
228
+ */
229
+ protected function set hierState(state:Boolean) : void
230
+ {
231
+ if (state)
232
+ {
233
+ // Clear the non-hierarchical data
234
+ _nonHierarchical = "";
235
+
236
+ // Also set the state vars while we are at it
237
+ if (_scheme == "" || _scheme == UNKNOWN_SCHEME)
238
+ _relative = true;
239
+ else
240
+ _relative = false;
241
+
242
+ if (_authority.length == 0 && _path.length == 0)
243
+ _valid = false;
244
+ else
245
+ _valid = true;
246
+ }
247
+ else
248
+ {
249
+ // Clear the hierarchical data
250
+ _authority = "";
251
+ _username = "";
252
+ _password = "";
253
+ _port = "";
254
+ _path = "";
255
+
256
+ _relative = false;
257
+
258
+ if (_scheme == "" || _scheme == UNKNOWN_SCHEME)
259
+ _valid = false;
260
+ else
261
+ _valid = true;
262
+ }
263
+ }
264
+ protected function get hierState() : Boolean
265
+ {
266
+ return (_nonHierarchical.length == 0);
267
+ }
268
+
269
+
270
+ /**
271
+ * @private Functions that performs some basic consistency validation.
272
+ */
273
+ protected function validateURI() : Boolean
274
+ {
275
+ // Check the scheme
276
+ if (isAbsolute())
277
+ {
278
+ if (_scheme.length <= 1 || _scheme == UNKNOWN_SCHEME)
279
+ {
280
+ // we probably parsed a C:\ type path or no scheme
281
+ return false;
282
+ }
283
+ else if (verifyAlpha(_scheme) == false)
284
+ return false; // Scheme contains bad characters
285
+ }
286
+
287
+ if (hierState)
288
+ {
289
+ if (_path.search('\\') != -1)
290
+ return false; // local path
291
+ else if (isRelative() == false && _scheme == UNKNOWN_SCHEME)
292
+ return false; // It's an absolute URI, but it has a bad scheme
293
+ }
294
+ else
295
+ {
296
+ if (_nonHierarchical.search('\\') != -1)
297
+ return false; // some kind of local path
298
+ }
299
+
300
+ // Looks like it's ok.
301
+ return true;
302
+ }
303
+
304
+
305
+ /**
306
+ * @private
307
+ *
308
+ * Given a URI in string format, parse that sucker into its basic
309
+ * components and assign them to this object. A URI is of the form:
310
+ * &lt;scheme&gt;:&lt;authority&gt;&lt;path&gt;?&lt;query&gt;#&lt;fragment&gt;
311
+ *
312
+ * For simplicity, we parse the URI in the following order:
313
+ *
314
+ * 1. Fragment (anchors)
315
+ * 2. Query (CGI stuff)
316
+ * 3. Scheme ("http")
317
+ * 4. Authority (host name)
318
+ * 5. Username/Password (if any)
319
+ * 6. Port (server port if any)
320
+ * 7. Path (/homepages/mypage.html)
321
+ *
322
+ * The reason for this order is to minimize any parsing ambiguities.
323
+ * Fragments and queries can contain almost anything (they are parts
324
+ * that can contain custom data with their own syntax). Parsing
325
+ * them out first removes a large chance of parsing errors. This
326
+ * method expects well formed URI's, but performing the parse in
327
+ * this order makes us a little more tolerant of user error.
328
+ *
329
+ * REGEXP
330
+ * Why doesn't this use regular expressions to parse the URI? We
331
+ * have found that in a real world scenario, URI's are not always
332
+ * well formed. Sometimes characters that should have been escaped
333
+ * are not, and those situations would break a regexp pattern. This
334
+ * function attempts to be smart about what it is parsing based on
335
+ * location of characters relative to eachother. This function has
336
+ * been proven through real-world use to parse the vast majority
337
+ * of URI's correctly.
338
+ *
339
+ * NOTE
340
+ * It is assumed that the string in URI form is escaped. This function
341
+ * does not escape anything. If you constructed the URI string by
342
+ * hand, and used this to parse in the URI and still need it escaped,
343
+ * call forceEscape() on your URI object.
344
+ *
345
+ * Parsing Assumptions
346
+ * This routine assumes that the URI being passed is well formed.
347
+ * Passing things like local paths, malformed URI's, and the such
348
+ * will result in parsing errors. This function can handle
349
+ * - absolute hierarchical (e.g. "http://something.com/index.html),
350
+ * - relative hierarchical (e.g. "../images/flower.gif"), or
351
+ * - non-hierarchical URIs (e.g. "mailto:jsmith&#64;fungoo.com").
352
+ *
353
+ * Anything else will probably result in a parsing error, or a bogus
354
+ * URI object.
355
+ *
356
+ * Note that non-hierarchical URIs *MUST* have a scheme, otherwise
357
+ * they will be mistaken for relative URI's.
358
+ *
359
+ * If you are not sure what is being passed to you (like manually
360
+ * entered text from UI), you can construct a blank URI object and
361
+ * call unknownToURI() passing in the unknown string.
362
+ *
363
+ * @return true if successful, false if there was some kind of
364
+ * parsing error
365
+ */
366
+ protected function parseURI(uri:String) : Boolean
367
+ {
368
+ var baseURI:String = uri;
369
+ var index:int, index2:int;
370
+
371
+ // Make sure this object is clean before we start. If it was used
372
+ // before and we are now parsing a new URI, we don't want any stale
373
+ // info lying around.
374
+ initialize();
375
+
376
+ // Remove any fragments (anchors) from the URI
377
+ index = baseURI.indexOf("#");
378
+ if (index != -1)
379
+ {
380
+ // Store the fragment piece if any
381
+ if (baseURI.length > (index + 1)) // +1 is to skip the '#'
382
+ _fragment = baseURI.substr(index + 1, baseURI.length - (index + 1));
383
+
384
+ // Trim off the fragment
385
+ baseURI = baseURI.substr(0, index);
386
+ }
387
+
388
+ // We need to strip off any CGI parameters (eg '?param=bob')
389
+ index = baseURI.indexOf("?");
390
+ if (index != -1)
391
+ {
392
+ if (baseURI.length > (index + 1))
393
+ _query = baseURI.substr(index + 1, baseURI.length - (index + 1)); // +1 is to skip the '?'
394
+
395
+ // Trim off the query
396
+ baseURI = baseURI.substr(0, index);
397
+ }
398
+
399
+ // Now try to find the scheme part
400
+ index = baseURI.search(':');
401
+ index2 = baseURI.search('/');
402
+
403
+ var containsColon:Boolean = (index != -1);
404
+ var containsSlash:Boolean = (index2 != -1);
405
+
406
+ // This value is indeterminate if "containsColon" is false.
407
+ // (if there is no colon, does the slash come before or
408
+ // after said non-existing colon?)
409
+ var colonBeforeSlash:Boolean = (!containsSlash || index < index2);
410
+
411
+ // If it has a colon and it's before the first slash, we will treat
412
+ // it as a scheme. If a slash is before a colon, there must be a
413
+ // stray colon in a path or something. In which case, the colon is
414
+ // not the separator for the scheme. Technically, we could consider
415
+ // this an error, but since this is not an ambiguous state (we know
416
+ // 100% that this has no scheme), we will keep going.
417
+ if (containsColon && colonBeforeSlash)
418
+ {
419
+ // We found a scheme
420
+ _scheme = baseURI.substr(0, index);
421
+
422
+ // Normalize the scheme
423
+ _scheme = _scheme.toLowerCase();
424
+
425
+ baseURI = baseURI.substr(index + 1);
426
+
427
+ if (baseURI.substr(0, 2) == "//")
428
+ {
429
+ // This is a hierarchical URI
430
+ _nonHierarchical = "";
431
+
432
+ // Trim off the "//"
433
+ baseURI = baseURI.substr(2, baseURI.length - 2);
434
+ }
435
+ else
436
+ {
437
+ // This is a non-hierarchical URI like "mailto:bob@mail.com"
438
+ _nonHierarchical = baseURI;
439
+
440
+ if ((_valid = validateURI()) == false)
441
+ initialize(); // Bad URI. Clear it.
442
+
443
+ // No more parsing to do for this case
444
+ return isValid();
445
+ }
446
+ }
447
+ else
448
+ {
449
+ // No scheme. We will consider this a relative URI
450
+ _scheme = "";
451
+ _relative = true;
452
+ _nonHierarchical = "";
453
+ }
454
+
455
+ // Ok, what we have left is everything after the <scheme>://
456
+
457
+ // Now that we have stripped off any query and fragment parts, we
458
+ // need to split the authority from the path
459
+
460
+ if (isRelative())
461
+ {
462
+ // Don't bother looking for the authority. It's a relative URI
463
+ _authority = "";
464
+ _port = "";
465
+ _path = baseURI;
466
+ }
467
+ else
468
+ {
469
+ // Check for malformed UNC style file://///server/type/path/
470
+ // By the time we get here, we have already trimmed the "file://"
471
+ // so baseURI will be ///server/type/path. If baseURI only
472
+ // has one slash, we leave it alone because that is valid (that
473
+ // is the case of "file:///path/to/file.txt" where there is no
474
+ // server - implicit "localhost").
475
+ if (baseURI.substr(0, 2) == "//")
476
+ {
477
+ // Trim all leading slashes
478
+ while(baseURI.charAt(0) == "/")
479
+ baseURI = baseURI.substr(1, baseURI.length - 1);
480
+ }
481
+
482
+ index = baseURI.search('/');
483
+ if (index == -1)
484
+ {
485
+ // No path. We must have passed something like "http://something.com"
486
+ _authority = baseURI;
487
+ _path = "";
488
+ }
489
+ else
490
+ {
491
+ _authority = baseURI.substr(0, index);
492
+ _path = baseURI.substr(index, baseURI.length - index);
493
+ }
494
+
495
+ // Check to see if the URI has any username or password information.
496
+ // For example: ftp://username:password@server.com
497
+ index = _authority.search('@');
498
+ if (index != -1)
499
+ {
500
+ // We have a username and possibly a password
501
+ _username = _authority.substr(0, index);
502
+
503
+ // Remove the username/password from the authority
504
+ _authority = _authority.substr(index + 1); // Skip the '@'
505
+
506
+ // Now check to see if the username also has a password
507
+ index = _username.search(':');
508
+ if (index != -1)
509
+ {
510
+ _password = _username.substring(index + 1, _username.length);
511
+ _username = _username.substr(0, index);
512
+ }
513
+ else
514
+ _password = "";
515
+ }
516
+ else
517
+ {
518
+ _username = "";
519
+ _password = "";
520
+ }
521
+
522
+ // Lastly, check to see if the authorty has a port number.
523
+ // This is parsed after the username/password to avoid conflicting
524
+ // with the ':' in the 'username:password' if one exists.
525
+ index = _authority.search(':');
526
+ if (index != -1)
527
+ {
528
+ _port = _authority.substring(index + 1, _authority.length); // skip the ':'
529
+ _authority = _authority.substr(0, index);
530
+ }
531
+ else
532
+ {
533
+ _port = "";
534
+ }
535
+
536
+ // Lastly, normalize the authority. Domain names
537
+ // are case insensitive.
538
+ _authority = _authority.toLowerCase();
539
+ }
540
+
541
+ if ((_valid = validateURI()) == false)
542
+ initialize(); // Bad URI. Clear it
543
+
544
+ return isValid();
545
+ }
546
+
547
+
548
+ /********************************************************************
549
+ * Copy function.
550
+ */
551
+ public function copyURI(uri:URI) : void
552
+ {
553
+ this._scheme = uri._scheme;
554
+ this._authority = uri._authority;
555
+ this._username = uri._username;
556
+ this._password = uri._password;
557
+ this._port = uri._port;
558
+ this._path = uri._path;
559
+ this._query = uri._query;
560
+ this._fragment = uri._fragment;
561
+ this._nonHierarchical = uri._nonHierarchical;
562
+
563
+ this._valid = uri._valid;
564
+ this._relative = uri._relative;
565
+ }
566
+
567
+
568
+ /**
569
+ * @private
570
+ * Checks if the given string only contains a-z or A-Z.
571
+ */
572
+ protected function verifyAlpha(str:String) : Boolean
573
+ {
574
+ var pattern:RegExp = /[^a-z]/;
575
+ var index:int;
576
+
577
+ str = str.toLowerCase();
578
+ index = str.search(pattern);
579
+
580
+ if (index == -1)
581
+ return true;
582
+ else
583
+ return false;
584
+ }
585
+
586
+ /**
587
+ * Is this a valid URI?
588
+ *
589
+ * @return true if this object represents a valid URI, false
590
+ * otherwise.
591
+ */
592
+ public function isValid() : Boolean
593
+ {
594
+ return this._valid;
595
+ }
596
+
597
+
598
+ /**
599
+ * Is this URI an absolute URI? An absolute URI is a complete, fully
600
+ * qualified reference to a resource. e.g. http://site.com/index.htm
601
+ * Non-hierarchical URI's are always absolute.
602
+ */
603
+ public function isAbsolute() : Boolean
604
+ {
605
+ return !this._relative;
606
+ }
607
+
608
+
609
+ /**
610
+ * Is this URI a relative URI? Relative URI's do not have a scheme
611
+ * and only contain a relative path with optional anchor and query
612
+ * parts. e.g. "../reports/index.htm". Non-hierarchical URI's
613
+ * will never be relative.
614
+ */
615
+ public function isRelative() : Boolean
616
+ {
617
+ return this._relative;
618
+ }
619
+
620
+
621
+ /**
622
+ * Does this URI point to a resource that is a directory/folder?
623
+ * The URI specification dictates that any path that ends in a slash
624
+ * is a directory. This is needed to be able to perform correct path
625
+ * logic when combining relative URI's with absolute URI's to
626
+ * obtain the correct absolute URI to a resource.
627
+ *
628
+ * @see URI.chdir
629
+ *
630
+ * @return true if this URI represents a directory resource, false
631
+ * if this URI represents a file resource.
632
+ */
633
+ public function isDirectory() : Boolean
634
+ {
635
+ if (_path.length == 0)
636
+ return false;
637
+
638
+ return (_path.charAt(path.length - 1) == '/');
639
+ }
640
+
641
+
642
+ /**
643
+ * Is this URI a hierarchical URI? URI's can be
644
+ */
645
+ public function isHierarchical() : Boolean
646
+ {
647
+ return hierState;
648
+ }
649
+
650
+
651
+ /**
652
+ * The scheme of the URI.
653
+ */
654
+ public function get scheme() : String
655
+ {
656
+ return URI.unescapeChars(_scheme);
657
+ }
658
+ public function set scheme(schemeStr:String) : void
659
+ {
660
+ // Normalize the scheme
661
+ var normalized:String = schemeStr.toLowerCase();
662
+ _scheme = URI.fastEscapeChars(normalized, URI.URIschemeExcludedBitmap);
663
+ }
664
+
665
+
666
+ /**
667
+ * The authority (host) of the URI. Only valid for
668
+ * hierarchical URI's. If the URI is relative, this will
669
+ * be an empty string. When setting this value, the string
670
+ * given is assumed to be unescaped. When retrieving this
671
+ * value, the resulting string is unescaped.
672
+ */
673
+ public function get authority() : String
674
+ {
675
+ return URI.unescapeChars(_authority);
676
+ }
677
+ public function set authority(authorityStr:String) : void
678
+ {
679
+ // Normalize the authority
680
+ authorityStr = authorityStr.toLowerCase();
681
+
682
+ _authority = URI.fastEscapeChars(authorityStr,
683
+ URI.URIauthorityExcludedBitmap);
684
+
685
+ // Only hierarchical URI's can have an authority, make
686
+ // sure this URI is of the proper format.
687
+ this.hierState = true;
688
+ }
689
+
690
+
691
+ /**
692
+ * The username of the URI. Only valid for hierarchical
693
+ * URI's. If the URI is relative, this will be an empty
694
+ * string.
695
+ *
696
+ * <p>The URI specification allows for authentication
697
+ * credentials to be embedded in the URI as such:</p>
698
+ *
699
+ * <p>http://user:passwd&#64;host/path/to/file.htm</p>
700
+ *
701
+ * <p>When setting this value, the string
702
+ * given is assumed to be unescaped. When retrieving this
703
+ * value, the resulting string is unescaped.</p>
704
+ */
705
+ public function get username() : String
706
+ {
707
+ return URI.unescapeChars(_username);
708
+ }
709
+ public function set username(usernameStr:String) : void
710
+ {
711
+ _username = URI.fastEscapeChars(usernameStr, URI.URIuserpassExcludedBitmap);
712
+
713
+ // Only hierarchical URI's can have a username.
714
+ this.hierState = true;
715
+ }
716
+
717
+
718
+ /**
719
+ * The password of the URI. Similar to username.
720
+ * @see URI.username
721
+ */
722
+ public function get password() : String
723
+ {
724
+ return URI.unescapeChars(_password);
725
+ }
726
+ public function set password(passwordStr:String) : void
727
+ {
728
+ _password = URI.fastEscapeChars(passwordStr,
729
+ URI.URIuserpassExcludedBitmap);
730
+
731
+ // Only hierarchical URI's can have a password.
732
+ this.hierState = true;
733
+ }
734
+
735
+
736
+ /**
737
+ * The host port number. Only valid for hierarchical URI's. If
738
+ * the URI is relative, this will be an empty string. URI's can
739
+ * contain the port number of the remote host:
740
+ *
741
+ * <p>http://site.com:8080/index.htm</p>
742
+ */
743
+ public function get port() : String
744
+ {
745
+ return URI.unescapeChars(_port);
746
+ }
747
+ public function set port(portStr:String) : void
748
+ {
749
+ _port = URI.escapeChars(portStr);
750
+
751
+ // Only hierarchical URI's can have a port.
752
+ this.hierState = true;
753
+ }
754
+
755
+
756
+ /**
757
+ * The path portion of the URI. Only valid for hierarchical
758
+ * URI's. When setting this value, the string
759
+ * given is assumed to be unescaped. When retrieving this
760
+ * value, the resulting string is unescaped.
761
+ *
762
+ * <p>The path portion can be in one of two formats. 1) an absolute
763
+ * path, or 2) a relative path. An absolute path starts with a
764
+ * slash ('/'), a relative path does not.</p>
765
+ *
766
+ * <p>An absolute path may look like:</p>
767
+ * <listing>/full/path/to/my/file.htm</listing>
768
+ *
769
+ * <p>A relative path may look like:</p>
770
+ * <listing>
771
+ * path/to/my/file.htm
772
+ * ../images/logo.gif
773
+ * ../../reports/index.htm
774
+ * </listing>
775
+ *
776
+ * <p>Paths can be absolute or relative. Note that this not the same as
777
+ * an absolute or relative URI. An absolute URI can only have absolute
778
+ * paths. For example:</p>
779
+ *
780
+ * <listing>http:/site.com/path/to/file.htm</listing>
781
+ *
782
+ * <p>This absolute URI has an absolute path of "/path/to/file.htm".</p>
783
+ *
784
+ * <p>Relative URI's can have either absolute paths or relative paths.
785
+ * All of the following relative URI's are valid:</p>
786
+ *
787
+ * <listing>
788
+ * /absolute/path/to/file.htm
789
+ * path/to/file.htm
790
+ * ../path/to/file.htm
791
+ * </listing>
792
+ */
793
+ public function get path() : String
794
+ {
795
+ return URI.unescapeChars(_path);
796
+ }
797
+ public function set path(pathStr:String) : void
798
+ {
799
+ this._path = URI.fastEscapeChars(pathStr, URI.URIpathExcludedBitmap);
800
+
801
+ if (this._scheme == UNKNOWN_SCHEME)
802
+ {
803
+ // We set the path. This is a valid URI now.
804
+ this._scheme = "";
805
+ }
806
+
807
+ // Only hierarchical URI's can have a path.
808
+ hierState = true;
809
+ }
810
+
811
+
812
+ /**
813
+ * The query (CGI) portion of the URI. This part is valid for
814
+ * both hierarchical and non-hierarchical URI's.
815
+ *
816
+ * <p>This accessor should only be used if a custom query syntax
817
+ * is used. This URI class supports the common "param=value"
818
+ * style query syntax via the get/setQueryValue() and
819
+ * get/setQueryByMap() functions. Those functions should be used
820
+ * instead if the common syntax is being used.
821
+ *
822
+ * <p>The URI RFC does not specify any particular
823
+ * syntax for the query part of a URI. It is intended to allow
824
+ * any format that can be agreed upon by the two communicating hosts.
825
+ * However, most systems have standardized on the typical CGI
826
+ * format:</p>
827
+ *
828
+ * <listing>http://site.com/script.php?param1=value1&param2=value2</listing>
829
+ *
830
+ * <p>This class has specific support for this query syntax</p>
831
+ *
832
+ * <p>This common query format is an array of name/value
833
+ * pairs with its own syntax that is different from the overall URI
834
+ * syntax. The query has its own escaping logic. For a query part
835
+ * to be properly escaped and unescaped, it must be split into its
836
+ * component parts. This accessor escapes/unescapes the entire query
837
+ * part without regard for it's component parts. This has the
838
+ * possibliity of leaving the query string in an ambiguious state in
839
+ * regards to its syntax. If the contents of the query part are
840
+ * important, it is recommended that get/setQueryValue() or
841
+ * get/setQueryByMap() are used instead.</p>
842
+ *
843
+ * If a different query syntax is being used, a subclass of URI
844
+ * can be created to handle that specific syntax.
845
+ *
846
+ * @see URI.getQueryValue, URI.getQueryByMap
847
+ */
848
+ public function get query() : String
849
+ {
850
+ return URI.unescapeChars(_query);
851
+ }
852
+ public function set query(queryStr:String) : void
853
+ {
854
+ _query = URI.fastEscapeChars(queryStr, URI.URIqueryExcludedBitmap);
855
+
856
+ // both hierarchical and non-hierarchical URI's can
857
+ // have a query. Do not set the hierState.
858
+ }
859
+
860
+ /**
861
+ * Accessor to the raw query data. If you are using a custom query
862
+ * syntax, this accessor can be used to get and set the query part
863
+ * directly with no escaping/unescaping. This should ONLY be used
864
+ * if your application logic is handling custom query logic and
865
+ * handling the proper escaping of the query part.
866
+ */
867
+ public function get queryRaw() : String
868
+ {
869
+ return _query;
870
+ }
871
+ public function set queryRaw(queryStr:String) : void
872
+ {
873
+ _query = queryStr;
874
+ }
875
+
876
+
877
+ /**
878
+ * The fragment (anchor) portion of the URI. This is valid for
879
+ * both hierarchical and non-hierarchical URI's.
880
+ */
881
+ public function get fragment() : String
882
+ {
883
+ return URI.unescapeChars(_fragment);
884
+ }
885
+ public function set fragment(fragmentStr:String) : void
886
+ {
887
+ _fragment = URI.fastEscapeChars(fragmentStr, URIfragmentExcludedBitmap);
888
+
889
+ // both hierarchical and non-hierarchical URI's can
890
+ // have a fragment. Do not set the hierState.
891
+ }
892
+
893
+
894
+ /**
895
+ * The non-hierarchical part of the URI. For example, if
896
+ * this URI object represents "mailto:somebody&#64;company.com",
897
+ * this will contain "somebody&#64;company.com". This is valid only
898
+ * for non-hierarchical URI's.
899
+ */
900
+ public function get nonHierarchical() : String
901
+ {
902
+ return URI.unescapeChars(_nonHierarchical);
903
+ }
904
+ public function set nonHierarchical(nonHier:String) : void
905
+ {
906
+ _nonHierarchical = URI.fastEscapeChars(nonHier, URInonHierexcludedBitmap);
907
+
908
+ // This is a non-hierarchical URI.
909
+ this.hierState = false;
910
+ }
911
+
912
+
913
+ /**
914
+ * Quick shorthand accessor to set the parts of this URI.
915
+ * The given parts are assumed to be in unescaped form. If
916
+ * the URI is non-hierarchical (e.g. mailto:) you will need
917
+ * to call SetScheme() and SetNonHierarchical().
918
+ */
919
+ public function setParts(schemeStr:String, authorityStr:String,
920
+ portStr:String, pathStr:String, queryStr:String,
921
+ fragmentStr:String) : void
922
+ {
923
+ this.scheme = schemeStr;
924
+ this.authority = authorityStr;
925
+ this.port = portStr;
926
+ this.path = pathStr;
927
+ this.query = queryStr;
928
+ this.fragment = fragmentStr;
929
+
930
+ hierState = true;
931
+ }
932
+
933
+
934
+ /**
935
+ * URI escapes the given character string. This is similar in function
936
+ * to the global encodeURIComponent() function in ActionScript, but is
937
+ * slightly different in regards to which characters get escaped. This
938
+ * escapes the characters specified in the URIbaselineExluded set (see class
939
+ * static members). This is needed for this class to work properly.
940
+ *
941
+ * <p>If a different set of characters need to be used for the escaping,
942
+ * you may use fastEscapeChars() and specify a custom URIEncodingBitmap
943
+ * that contains the characters your application needs escaped.</p>
944
+ *
945
+ * <p>Never pass a full URI to this function. A URI can only be properly
946
+ * escaped/unescaped when split into its component parts (see RFC 3986
947
+ * section 2.4). This is due to the fact that the URI component separators
948
+ * could be characters that would normally need to be escaped.</p>
949
+ *
950
+ * @param unescaped character string to be escaped.
951
+ *
952
+ * @return escaped character string
953
+ *
954
+ * @see encodeURIComponent
955
+ * @see fastEscapeChars
956
+ */
957
+ static public function escapeChars(unescaped:String) : String
958
+ {
959
+ // This uses the excluded set by default.
960
+ return fastEscapeChars(unescaped, URI.URIbaselineExcludedBitmap);
961
+ }
962
+
963
+
964
+ /**
965
+ * Unescape any URI escaped characters in the given character
966
+ * string.
967
+ *
968
+ * <p>Never pass a full URI to this function. A URI can only be properly
969
+ * escaped/unescaped when split into its component parts (see RFC 3986
970
+ * section 2.4). This is due to the fact that the URI component separators
971
+ * could be characters that would normally need to be escaped.</p>
972
+ *
973
+ * @param escaped the escaped string to be unescaped.
974
+ *
975
+ * @return unescaped string.
976
+ */
977
+ static public function unescapeChars(escaped:String /*, onlyHighASCII:Boolean = false*/) : String
978
+ {
979
+ // We can just use the default AS function. It seems to
980
+ // decode everything correctly
981
+ var unescaped:String;
982
+ unescaped = decodeURIComponent(escaped);
983
+ return unescaped;
984
+ }
985
+
986
+ /**
987
+ * Performance focused function that escapes the given character
988
+ * string using the given URIEncodingBitmap as the rule for what
989
+ * characters need to be escaped. This function is used by this
990
+ * class and can be used externally to this class to perform
991
+ * escaping on custom character sets.
992
+ *
993
+ * <p>Never pass a full URI to this function. A URI can only be properly
994
+ * escaped/unescaped when split into its component parts (see RFC 3986
995
+ * section 2.4). This is due to the fact that the URI component separators
996
+ * could be characters that would normally need to be escaped.</p>
997
+ *
998
+ * @param unescaped the unescaped string to be escaped
999
+ * @param bitmap the set of characters that need to be escaped
1000
+ *
1001
+ * @return the escaped string.
1002
+ */
1003
+ static public function fastEscapeChars(unescaped:String, bitmap:URIEncodingBitmap) : String
1004
+ {
1005
+ var escaped:String = "";
1006
+ var c:String;
1007
+ var x:int, i:int;
1008
+
1009
+ for (i = 0; i < unescaped.length; i++)
1010
+ {
1011
+ c = unescaped.charAt(i);
1012
+
1013
+ x = bitmap.ShouldEscape(c);
1014
+ if (x)
1015
+ {
1016
+ c = x.toString(16);
1017
+ if (c.length == 1)
1018
+ c = "0" + c;
1019
+
1020
+ c = "%" + c;
1021
+ c = c.toUpperCase();
1022
+ }
1023
+
1024
+ escaped += c;
1025
+ }
1026
+
1027
+ return escaped;
1028
+ }
1029
+
1030
+
1031
+ /**
1032
+ * Is this URI of a particular scheme type? For example,
1033
+ * passing "http" to a URI object that represents the URI
1034
+ * "http://site.com/" would return true.
1035
+ *
1036
+ * @param scheme scheme to check for
1037
+ *
1038
+ * @return true if this URI object is of the given type, false
1039
+ * otherwise.
1040
+ */
1041
+ public function isOfType(scheme:String) : Boolean
1042
+ {
1043
+ // Schemes are never case sensitive. Ignore case.
1044
+ scheme = scheme.toLowerCase();
1045
+ return (this._scheme == scheme);
1046
+ }
1047
+
1048
+
1049
+ /**
1050
+ * Get the value for the specified named in the query part. This
1051
+ * assumes the query part of the URI is in the common
1052
+ * "name1=value1&name2=value2" syntax. Do not call this function
1053
+ * if you are using a custom query syntax.
1054
+ *
1055
+ * @param name name of the query value to get.
1056
+ *
1057
+ * @return the value of the query name, empty string if the
1058
+ * query name does not exist.
1059
+ */
1060
+ public function getQueryValue(name:String) : String
1061
+ {
1062
+ var map:Object;
1063
+ var item:String;
1064
+ var value:String;
1065
+
1066
+ map = getQueryByMap();
1067
+
1068
+ for (item in map)
1069
+ {
1070
+ if (item == name)
1071
+ {
1072
+ value = map[item];
1073
+ return value;
1074
+ }
1075
+ }
1076
+
1077
+ // Didn't find the specified key
1078
+ return new String("");
1079
+ }
1080
+
1081
+
1082
+ /**
1083
+ * Set the given value on the given query name. If the given name
1084
+ * does not exist, it will automatically add this name/value pair
1085
+ * to the query. If null is passed as the value, it will remove
1086
+ * the given item from the query.
1087
+ *
1088
+ * <p>This automatically escapes any characters that may conflict with
1089
+ * the query syntax so that they are "safe" within the query. The
1090
+ * strings passed are assumed to be literal unescaped name and value.</p>
1091
+ *
1092
+ * @param name name of the query value to set
1093
+ * @param value value of the query item to set. If null, this will
1094
+ * force the removal of this item from the query.
1095
+ */
1096
+ public function setQueryValue(name:String, value:String) : void
1097
+ {
1098
+ var map:Object;
1099
+
1100
+ map = getQueryByMap();
1101
+
1102
+ // If the key doesn't exist yet, this will create a new pair in
1103
+ // the map. If it does exist, this will overwrite the previous
1104
+ // value, which is what we want.
1105
+ map[name] = value;
1106
+
1107
+ setQueryByMap(map);
1108
+ }
1109
+
1110
+
1111
+ /**
1112
+ * Get the query of the URI in an Object class that allows for easy
1113
+ * access to the query data via Object accessors. For example:
1114
+ *
1115
+ * <listing>
1116
+ * var query:Object = uri.getQueryByMap();
1117
+ * var value:String = query["param"]; // get a value
1118
+ * query["param2"] = "foo"; // set a new value
1119
+ * </listing>
1120
+ *
1121
+ * @return Object that contains the name/value pairs of the query.
1122
+ *
1123
+ * @see #setQueryByMap
1124
+ * @see #getQueryValue
1125
+ * @see #setQueryValue
1126
+ */
1127
+ public function getQueryByMap() : Object
1128
+ {
1129
+ var queryStr:String;
1130
+ var pair:String;
1131
+ var pairs:Array;
1132
+ var item:Array;
1133
+ var name:String, value:String;
1134
+ var index:int;
1135
+ var map:Object = new Object();
1136
+
1137
+
1138
+ // We need the raw query string, no unescaping.
1139
+ queryStr = this._query;
1140
+
1141
+ pairs = queryStr.split('&');
1142
+ for each (pair in pairs)
1143
+ {
1144
+ if (pair.length == 0)
1145
+ continue;
1146
+
1147
+ item = pair.split('=');
1148
+
1149
+ if (item.length > 0)
1150
+ name = item[0];
1151
+ else
1152
+ continue; // empty array
1153
+
1154
+ if (item.length > 1)
1155
+ value = item[1];
1156
+ else
1157
+ value = "";
1158
+
1159
+ name = queryPartUnescape(name);
1160
+ value = queryPartUnescape(value);
1161
+
1162
+ map[name] = value;
1163
+ }
1164
+
1165
+ return map;
1166
+ }
1167
+
1168
+
1169
+ /**
1170
+ * Set the query part of this URI using the given object as the
1171
+ * content source. Any member of the object that has a value of
1172
+ * null will not be in the resulting query.
1173
+ *
1174
+ * @param map object that contains the name/value pairs as
1175
+ * members of that object.
1176
+ *
1177
+ * @see #getQueryByMap
1178
+ * @see #getQueryValue
1179
+ * @see #setQueryValue
1180
+ */
1181
+ public function setQueryByMap(map:Object) : void
1182
+ {
1183
+ var item:String;
1184
+ var name:String, value:String;
1185
+ var queryStr:String = "";
1186
+ var tmpPair:String;
1187
+ var foo:String;
1188
+
1189
+ for (item in map)
1190
+ {
1191
+ name = item;
1192
+ value = map[item];
1193
+
1194
+ if (value == null)
1195
+ value = "";
1196
+
1197
+ // Need to escape the name/value pair so that they
1198
+ // don't conflict with the query syntax (specifically
1199
+ // '=', '&', and <whitespace>).
1200
+ name = queryPartEscape(name);
1201
+ value = queryPartEscape(value);
1202
+
1203
+ tmpPair = name;
1204
+
1205
+ if (value.length > 0)
1206
+ {
1207
+ tmpPair += "=";
1208
+ tmpPair += value;
1209
+ }
1210
+
1211
+ if (queryStr.length != 0)
1212
+ queryStr += '&'; // Add the separator
1213
+
1214
+ queryStr += tmpPair;
1215
+ }
1216
+
1217
+ // We don't want to escape. We already escaped the
1218
+ // individual name/value pairs. If we escaped the
1219
+ // query string again by assigning it to "query",
1220
+ // we would have double escaping.
1221
+ _query = queryStr;
1222
+ }
1223
+
1224
+
1225
+ /**
1226
+ * Similar to Escape(), except this also escapes characters that
1227
+ * would conflict with the name/value pair query syntax. This is
1228
+ * intended to be called on each individual "name" and "value"
1229
+ * in the query making sure that nothing in the name or value
1230
+ * strings contain characters that would conflict with the query
1231
+ * syntax (e.g. '=' and '&').
1232
+ *
1233
+ * @param unescaped unescaped string that is to be escaped.
1234
+ *
1235
+ * @return escaped string.
1236
+ *
1237
+ * @see #queryUnescape
1238
+ */
1239
+ static public function queryPartEscape(unescaped:String) : String
1240
+ {
1241
+ var escaped:String = unescaped;
1242
+ escaped = URI.fastEscapeChars(unescaped, URI.URIqueryPartExcludedBitmap);
1243
+ return escaped;
1244
+ }
1245
+
1246
+
1247
+ /**
1248
+ * Unescape the individual name/value string pairs.
1249
+ *
1250
+ * @param escaped escaped string to be unescaped
1251
+ *
1252
+ * @return unescaped string
1253
+ *
1254
+ * @see #queryEscape
1255
+ */
1256
+ static public function queryPartUnescape(escaped:String) : String
1257
+ {
1258
+ var unescaped:String = escaped;
1259
+ unescaped = unescapeChars(unescaped);
1260
+ return unescaped;
1261
+ }
1262
+
1263
+ /**
1264
+ * Output this URI as a string. The resulting string is properly
1265
+ * escaped and well formed for machine processing.
1266
+ */
1267
+ public function toString() : String
1268
+ {
1269
+ if (this == null)
1270
+ return "";
1271
+ else
1272
+ return toStringInternal(false);
1273
+ }
1274
+
1275
+ /**
1276
+ * Output the URI as a string that is easily readable by a human.
1277
+ * This outputs the URI with all escape sequences unescaped to
1278
+ * their character representation. This makes the URI easier for
1279
+ * a human to read, but the URI could be completely invalid
1280
+ * because some unescaped characters may now cause ambiguous parsing.
1281
+ * This function should only be used if you want to display a URI to
1282
+ * a user. This function should never be used outside that specific
1283
+ * case.
1284
+ *
1285
+ * @return the URI in string format with all escape sequences
1286
+ * unescaped.
1287
+ *
1288
+ * @see #toString
1289
+ */
1290
+ public function toDisplayString() : String
1291
+ {
1292
+ return toStringInternal(true);
1293
+ }
1294
+
1295
+
1296
+ /**
1297
+ * @private
1298
+ *
1299
+ * The guts of toString()
1300
+ */
1301
+ protected function toStringInternal(forDisplay:Boolean) : String
1302
+ {
1303
+ var uri:String = "";
1304
+ var part:String = "";
1305
+
1306
+ if (isHierarchical() == false)
1307
+ {
1308
+ // non-hierarchical URI
1309
+
1310
+ uri += (forDisplay ? this.scheme : _scheme);
1311
+ uri += ":";
1312
+ uri += (forDisplay ? this.nonHierarchical : _nonHierarchical);
1313
+ }
1314
+ else
1315
+ {
1316
+ // Hierarchical URI
1317
+
1318
+ if (isRelative() == false)
1319
+ {
1320
+ // If it is not a relative URI, then we want the scheme and
1321
+ // authority parts in the string. If it is relative, we
1322
+ // do NOT want this stuff.
1323
+
1324
+ if (_scheme.length != 0)
1325
+ {
1326
+ part = (forDisplay ? this.scheme : _scheme);
1327
+ uri += part + ":";
1328
+ }
1329
+
1330
+ if (_authority.length != 0 || isOfType("file"))
1331
+ {
1332
+ uri += "//";
1333
+
1334
+ // Add on any username/password associated with this
1335
+ // authority
1336
+ if (_username.length != 0)
1337
+ {
1338
+ part = (forDisplay ? this.username : _username);
1339
+ uri += part;
1340
+
1341
+ if (_password.length != 0)
1342
+ {
1343
+ part = (forDisplay ? this.password : _password);
1344
+ uri += ":" + part;
1345
+ }
1346
+
1347
+ uri += "@";
1348
+ }
1349
+
1350
+ // add the authority
1351
+ part = (forDisplay ? this.authority : _authority);
1352
+ uri += part;
1353
+
1354
+ // Tack on the port number, if any
1355
+ if (port.length != 0)
1356
+ uri += ":" + port;
1357
+ }
1358
+ }
1359
+
1360
+ // Tack on the path
1361
+ part = (forDisplay ? this.path : _path);
1362
+ uri += part;
1363
+
1364
+ } // end hierarchical part
1365
+
1366
+ // Both non-hier and hierarchical have query and fragment parts
1367
+
1368
+ // Add on the query and fragment parts
1369
+ if (_query.length != 0)
1370
+ {
1371
+ part = (forDisplay ? this.query : _query);
1372
+ uri += "?" + part;
1373
+ }
1374
+
1375
+ if (fragment.length != 0)
1376
+ {
1377
+ part = (forDisplay ? this.fragment : _fragment);
1378
+ uri += "#" + part;
1379
+ }
1380
+
1381
+ return uri;
1382
+ }
1383
+
1384
+ /**
1385
+ * Forcefully ensure that this URI is properly escaped.
1386
+ *
1387
+ * <p>Sometimes URI's are constructed by hand using strings outside
1388
+ * this class. In those cases, it is unlikely the URI has been
1389
+ * properly escaped. This function forcefully escapes this URI
1390
+ * by unescaping each part and then re-escaping it. If the URI
1391
+ * did not have any escaping, the first unescape will do nothing
1392
+ * and then the re-escape will properly escape everything. If
1393
+ * the URI was already escaped, the unescape and re-escape will
1394
+ * essentally be a no-op. This provides a safe way to make sure
1395
+ * a URI is in the proper escaped form.</p>
1396
+ */
1397
+ public function forceEscape() : void
1398
+ {
1399
+ // The accessors for each of the members will unescape
1400
+ // and then re-escape as we get and assign them.
1401
+
1402
+ // Handle the parts that are common for both hierarchical
1403
+ // and non-hierarchical URI's
1404
+ this.scheme = this.scheme;
1405
+ this.setQueryByMap(this.getQueryByMap());
1406
+ this.fragment = this.fragment;
1407
+
1408
+ if (isHierarchical())
1409
+ {
1410
+ this.authority = this.authority;
1411
+ this.path = this.path;
1412
+ this.port = this.port;
1413
+ this.username = this.username;
1414
+ this.password = this.password;
1415
+ }
1416
+ else
1417
+ {
1418
+ this.nonHierarchical = this.nonHierarchical;
1419
+ }
1420
+ }
1421
+
1422
+
1423
+ /**
1424
+ * Does this URI point to a resource of the given file type?
1425
+ * Given a file extension (or just a file name, this will strip the
1426
+ * extension), check to see if this URI points to a file of that
1427
+ * type.
1428
+ *
1429
+ * @param extension string that contains a file extension with or
1430
+ * without a dot ("html" and ".html" are both valid), or a file
1431
+ * name with an extension (e.g. "index.html").
1432
+ *
1433
+ * @return true if this URI points to a resource with the same file
1434
+ * file extension as the extension provided, false otherwise.
1435
+ */
1436
+ public function isOfFileType(extension:String) : Boolean
1437
+ {
1438
+ var thisExtension:String;
1439
+ var index:int;
1440
+
1441
+ index = extension.lastIndexOf(".");
1442
+ if (index != -1)
1443
+ {
1444
+ // Strip the extension
1445
+ extension = extension.substr(index + 1);
1446
+ }
1447
+ else
1448
+ {
1449
+ // The caller passed something without a dot in it. We
1450
+ // will assume that it is just a plain extension (e.g. "html").
1451
+ // What they passed is exactly what we want
1452
+ }
1453
+
1454
+ thisExtension = getExtension(true);
1455
+
1456
+ if (thisExtension == "")
1457
+ return false;
1458
+
1459
+ // Compare the extensions ignoring case
1460
+ if (compareStr(thisExtension, extension, false) == 0)
1461
+ return true;
1462
+ else
1463
+ return false;
1464
+ }
1465
+
1466
+
1467
+ /**
1468
+ * Get the ".xyz" file extension from the filename in the URI.
1469
+ * For example, if we have the following URI:
1470
+ *
1471
+ * <listing>http://something.com/path/to/my/page.html?form=yes&name=bob#anchor</listing>
1472
+ *
1473
+ * <p>This will return ".html".</p>
1474
+ *
1475
+ * @param minusDot If true, this will strip the dot from the extension.
1476
+ * If true, the above example would have returned "html".
1477
+ *
1478
+ * @return the file extension
1479
+ */
1480
+ public function getExtension(minusDot:Boolean = false) : String
1481
+ {
1482
+ var filename:String = getFilename();
1483
+ var extension:String;
1484
+ var index:int;
1485
+
1486
+ if (filename == "")
1487
+ return String("");
1488
+
1489
+ index = filename.lastIndexOf(".");
1490
+
1491
+ // If it doesn't have an extension, or if it is a "hidden" file,
1492
+ // it doesn't have an extension. Hidden files on unix start with
1493
+ // a dot (e.g. ".login").
1494
+ if (index == -1 || index == 0)
1495
+ return String("");
1496
+
1497
+ extension = filename.substr(index);
1498
+
1499
+ // If the caller does not want the dot, remove it.
1500
+ if (minusDot && extension.charAt(0) == ".")
1501
+ extension = extension.substr(1);
1502
+
1503
+ return extension;
1504
+ }
1505
+
1506
+ /**
1507
+ * Quick function to retrieve the file name off the end of a URI.
1508
+ *
1509
+ * <p>For example, if the URI is:</p>
1510
+ * <listing>http://something.com/some/path/to/my/file.html</listing>
1511
+ * <p>this function will return "file.html".</p>
1512
+ *
1513
+ * @param minusExtension true if the file extension should be stripped
1514
+ *
1515
+ * @return the file name. If this URI is a directory, the return
1516
+ * value will be empty string.
1517
+ */
1518
+ public function getFilename(minusExtension:Boolean = false) : String
1519
+ {
1520
+ if (isDirectory())
1521
+ return String("");
1522
+
1523
+ var pathStr:String = this.path;
1524
+ var filename:String;
1525
+ var index:int;
1526
+
1527
+ // Find the last path separator.
1528
+ index = pathStr.lastIndexOf("/");
1529
+
1530
+ if (index != -1)
1531
+ filename = pathStr.substr(index + 1);
1532
+ else
1533
+ filename = pathStr;
1534
+
1535
+ if (minusExtension)
1536
+ {
1537
+ // The caller has requested that the extension be removed
1538
+ index = filename.lastIndexOf(".");
1539
+
1540
+ if (index != -1)
1541
+ filename = filename.substr(0, index);
1542
+ }
1543
+
1544
+ return filename;
1545
+ }
1546
+
1547
+
1548
+ /**
1549
+ * @private
1550
+ * Helper function to compare strings.
1551
+ *
1552
+ * @return true if the two strings are identical, false otherwise.
1553
+ */
1554
+ static protected function compareStr(str1:String, str2:String,
1555
+ sensitive:Boolean = true) : Boolean
1556
+ {
1557
+ if (sensitive == false)
1558
+ {
1559
+ str1 = str1.toLowerCase();
1560
+ str2 = str2.toLowerCase();
1561
+ }
1562
+
1563
+ return (str1 == str2)
1564
+ }
1565
+
1566
+ /**
1567
+ * Based on the type of this URI (http, ftp, etc.) get
1568
+ * the default port used for that protocol. This is
1569
+ * just intended to be a helper function for the most
1570
+ * common cases.
1571
+ */
1572
+ public function getDefaultPort() : String
1573
+ {
1574
+ if (_scheme == "http")
1575
+ return String("80");
1576
+ else if (_scheme == "ftp")
1577
+ return String("21");
1578
+ else if (_scheme == "file")
1579
+ return String("");
1580
+ else if (_scheme == "sftp")
1581
+ return String("22"); // ssh standard port
1582
+ else
1583
+ {
1584
+ // Don't know the port for this URI type
1585
+ return String("");
1586
+ }
1587
+ }
1588
+
1589
+ /**
1590
+ * @private
1591
+ *
1592
+ * This resolves the given URI if the application has a
1593
+ * resolver interface defined. This function does not
1594
+ * modify the passed in URI and returns a new URI.
1595
+ */
1596
+ static protected function resolve(uri:URI) : URI
1597
+ {
1598
+ var copy:URI = new URI();
1599
+ copy.copyURI(uri);
1600
+
1601
+ if (_resolver != null)
1602
+ {
1603
+ // A resolver class has been registered. Call it.
1604
+ return _resolver.resolve(copy);
1605
+ }
1606
+ else
1607
+ {
1608
+ // No resolver. Nothing to do, but we don't
1609
+ // want to reuse the one passed in.
1610
+ return copy;
1611
+ }
1612
+ }
1613
+
1614
+ /**
1615
+ * Accessor to set and get the resolver object used by all URI
1616
+ * objects to dynamically resolve URI's before comparison.
1617
+ */
1618
+ static public function set resolver(resolver:IURIResolver) : void
1619
+ {
1620
+ _resolver = resolver;
1621
+ }
1622
+ static public function get resolver() : IURIResolver
1623
+ {
1624
+ return _resolver;
1625
+ }
1626
+
1627
+ /**
1628
+ * Given another URI, return this URI object's relation to the one given.
1629
+ * URI's can have 1 of 4 possible relationships. They can be unrelated,
1630
+ * equal, parent, or a child of the given URI.
1631
+ *
1632
+ * @param uri URI to compare this URI object to.
1633
+ * @param caseSensitive true if the URI comparison should be done
1634
+ * taking case into account, false if the comparison should be
1635
+ * performed case insensitive.
1636
+ *
1637
+ * @return URI.NOT_RELATED, URI.CHILD, URI.PARENT, or URI.EQUAL
1638
+ */
1639
+ public function getRelation(uri:URI, caseSensitive:Boolean = true) : int
1640
+ {
1641
+ // Give the app a chance to resolve these URI's before we compare them.
1642
+ var thisURI:URI = URI.resolve(this);
1643
+ var thatURI:URI = URI.resolve(uri);
1644
+
1645
+ if (thisURI.isRelative() || thatURI.isRelative())
1646
+ {
1647
+ // You cannot compare relative URI's due to their lack of context.
1648
+ // You could have two relative URI's that look like:
1649
+ // ../../images/
1650
+ // ../../images/marketing/logo.gif
1651
+ // These may appear related, but you have no overall context
1652
+ // from which to make the comparison. The first URI could be
1653
+ // from one site and the other URI could be from another site.
1654
+ return URI.NOT_RELATED;
1655
+ }
1656
+ else if (thisURI.isHierarchical() == false || thatURI.isHierarchical() == false)
1657
+ {
1658
+ // One or both of the URI's are non-hierarchical.
1659
+ if (((thisURI.isHierarchical() == false) && (thatURI.isHierarchical() == true)) ||
1660
+ ((thisURI.isHierarchical() == true) && (thatURI.isHierarchical() == false)))
1661
+ {
1662
+ // XOR. One is hierarchical and the other is
1663
+ // non-hierarchical. They cannot be compared.
1664
+ return URI.NOT_RELATED;
1665
+ }
1666
+ else
1667
+ {
1668
+ // They are both non-hierarchical
1669
+ if (thisURI.scheme != thatURI.scheme)
1670
+ return URI.NOT_RELATED;
1671
+
1672
+ if (thisURI.nonHierarchical != thatURI.nonHierarchical)
1673
+ return URI.NOT_RELATED;
1674
+
1675
+ // The two non-hierarcical URI's are equal.
1676
+ return URI.EQUAL;
1677
+ }
1678
+ }
1679
+
1680
+ // Ok, this URI and the one we are being compared to are both
1681
+ // absolute hierarchical URI's.
1682
+
1683
+ if (thisURI.scheme != thatURI.scheme)
1684
+ return URI.NOT_RELATED;
1685
+
1686
+ if (thisURI.authority != thatURI.authority)
1687
+ return URI.NOT_RELATED;
1688
+
1689
+ var thisPort:String = thisURI.port;
1690
+ var thatPort:String = thatURI.port;
1691
+
1692
+ // Different ports are considered completely different servers.
1693
+ if (thisPort == "")
1694
+ thisPort = thisURI.getDefaultPort();
1695
+ if (thatPort == "")
1696
+ thatPort = thatURI.getDefaultPort();
1697
+
1698
+ // Check to see if the port is the default port.
1699
+ if (thisPort != thatPort)
1700
+ return URI.NOT_RELATED;
1701
+
1702
+ if (compareStr(thisURI.path, thatURI.path, caseSensitive))
1703
+ return URI.EQUAL;
1704
+
1705
+ // Special case check. If we are here, the scheme, authority,
1706
+ // and port match, and it is not a relative path, but the
1707
+ // paths did not match. There is a special case where we
1708
+ // could have:
1709
+ // http://something.com/
1710
+ // http://something.com
1711
+ // Technically, these are equal. So lets, check for this case.
1712
+ var thisPath:String = thisURI.path;
1713
+ var thatPath:String = thatURI.path;
1714
+
1715
+ if ( (thisPath == "/" || thatPath == "/") &&
1716
+ (thisPath == "" || thatPath == "") )
1717
+ {
1718
+ // We hit the special case. These two are equal.
1719
+ return URI.EQUAL;
1720
+ }
1721
+
1722
+ // Ok, the paths do not match, but one path may be a parent/child
1723
+ // of the other. For example, we may have:
1724
+ // http://something.com/path/to/homepage/
1725
+ // http://something.com/path/to/homepage/images/logo.gif
1726
+ // In this case, the first is a parent of the second (or the second
1727
+ // is a child of the first, depending on which you compare to the
1728
+ // other). To make this comparison, we must split the path into
1729
+ // its component parts (split the string on the '/' path delimiter).
1730
+ // We then compare the
1731
+ var thisParts:Array, thatParts:Array;
1732
+ var thisPart:String, thatPart:String;
1733
+ var i:int;
1734
+
1735
+ thisParts = thisPath.split("/");
1736
+ thatParts = thatPath.split("/");
1737
+
1738
+ if (thisParts.length > thatParts.length)
1739
+ {
1740
+ thatPart = thatParts[thatParts.length - 1];
1741
+ if (thatPart.length > 0)
1742
+ {
1743
+ // if the last part is not empty, the passed URI is
1744
+ // not a directory. There is no way the passed URI
1745
+ // can be a parent.
1746
+ return URI.NOT_RELATED;
1747
+ }
1748
+ else
1749
+ {
1750
+ // Remove the empty trailing part
1751
+ thatParts.pop();
1752
+ }
1753
+
1754
+ // This may be a child of the one passed in
1755
+ for (i = 0; i < thatParts.length; i++)
1756
+ {
1757
+ thisPart = thisParts[i];
1758
+ thatPart = thatParts[i];
1759
+
1760
+ if (compareStr(thisPart, thatPart, caseSensitive) == false)
1761
+ return URI.NOT_RELATED;
1762
+ }
1763
+
1764
+ return URI.CHILD;
1765
+ }
1766
+ else if (thisParts.length < thatParts.length)
1767
+ {
1768
+ thisPart = thisParts[thisParts.length - 1];
1769
+ if (thisPart.length > 0)
1770
+ {
1771
+ // if the last part is not empty, this URI is not a
1772
+ // directory. There is no way this object can be
1773
+ // a parent.
1774
+ return URI.NOT_RELATED;
1775
+ }
1776
+ else
1777
+ {
1778
+ // Remove the empty trailing part
1779
+ thisParts.pop();
1780
+ }
1781
+
1782
+ // This may be the parent of the one passed in
1783
+ for (i = 0; i < thisParts.length; i++)
1784
+ {
1785
+ thisPart = thisParts[i];
1786
+ thatPart = thatParts[i];
1787
+
1788
+ if (compareStr(thisPart, thatPart, caseSensitive) == false)
1789
+ return URI.NOT_RELATED;
1790
+ }
1791
+
1792
+ return URI.PARENT;
1793
+ }
1794
+ else
1795
+ {
1796
+ // Both URI's have the same number of path components, but
1797
+ // it failed the equivelence check above. This means that
1798
+ // the two URI's are not related.
1799
+ return URI.NOT_RELATED;
1800
+ }
1801
+
1802
+ // If we got here, the scheme and authority are the same,
1803
+ // but the paths pointed to two different locations that
1804
+ // were in different parts of the file system tree
1805
+ return URI.NOT_RELATED;
1806
+ }
1807
+
1808
+ /**
1809
+ * Given another URI, return the common parent between this one
1810
+ * and the provided URI.
1811
+ *
1812
+ * @param uri the other URI from which to find a common parent
1813
+ * @para caseSensitive true if this operation should be done
1814
+ * with case sensitive comparisons.
1815
+ *
1816
+ * @return the parent URI if successful, null otherwise.
1817
+ */
1818
+ public function getCommonParent(uri:URI, caseSensitive:Boolean = true) : URI
1819
+ {
1820
+ var thisURI:URI = URI.resolve(this);
1821
+ var thatURI:URI = URI.resolve(uri);
1822
+
1823
+ if(!thisURI.isAbsolute() || !thatURI.isAbsolute() ||
1824
+ thisURI.isHierarchical() == false ||
1825
+ thatURI.isHierarchical() == false)
1826
+ {
1827
+ // Both URI's must be absolute hierarchical for this to
1828
+ // make sense.
1829
+ return null;
1830
+ }
1831
+
1832
+ var relation:int = thisURI.getRelation(thatURI);
1833
+ if (relation == URI.NOT_RELATED)
1834
+ {
1835
+ // The given URI is not related to this one. No
1836
+ // common parent.
1837
+ return null;
1838
+ }
1839
+
1840
+ thisURI.chdir(".");
1841
+ thatURI.chdir(".");
1842
+
1843
+ var strBefore:String, strAfter:String;
1844
+ do
1845
+ {
1846
+ relation = thisURI.getRelation(thatURI, caseSensitive);
1847
+ if(relation == URI.EQUAL || relation == URI.PARENT)
1848
+ break;
1849
+
1850
+ // If strBefore and strAfter end up being the same,
1851
+ // we know we are at the root of the path because
1852
+ // chdir("..") is doing nothing.
1853
+ strBefore = thisURI.toString();
1854
+ thisURI.chdir("..");
1855
+ strAfter = thisURI.toString();
1856
+ }
1857
+ while(strBefore != strAfter);
1858
+
1859
+ return thisURI;
1860
+ }
1861
+
1862
+
1863
+ /**
1864
+ * This function is used to move around in a URI in a way similar
1865
+ * to the 'cd' or 'chdir' commands on Unix. These operations are
1866
+ * completely string based, using the context of the URI to
1867
+ * determine the position within the path. The heuristics used
1868
+ * to determine the action are based off Appendix C in RFC 2396.
1869
+ *
1870
+ * <p>URI paths that end in '/' are considered paths that point to
1871
+ * directories, while paths that do not end in '/' are files. For
1872
+ * example, if you execute chdir("d") on the following URI's:<br/>
1873
+ * 1. http://something.com/a/b/c/ (directory)<br/>
1874
+ * 2. http://something.com/a/b/c (not directory)<br/>
1875
+ * you will get:<br/>
1876
+ * 1. http://something.com/a/b/c/d<br/>
1877
+ * 2. http://something.com/a/b/d<br/></p>
1878
+ *
1879
+ * <p>See RFC 2396, Appendix C for more info.</p>
1880
+ *
1881
+ * @param reference the URI or path to "cd" to.
1882
+ * @param escape true if the passed reference string should be URI
1883
+ * escaped before using it.
1884
+ *
1885
+ * @return true if the chdir was successful, false otherwise.
1886
+ */
1887
+ public function chdir(reference:String, escape:Boolean = false) : Boolean
1888
+ {
1889
+ var uriReference:URI;
1890
+ var ref:String = reference;
1891
+
1892
+ if (escape)
1893
+ ref = URI.escapeChars(reference);
1894
+
1895
+ if (ref == "")
1896
+ {
1897
+ // NOOP
1898
+ return true;
1899
+ }
1900
+ else if (ref.substr(0, 2) == "//")
1901
+ {
1902
+ // Special case. This is an absolute URI but without the scheme.
1903
+ // Take the scheme from this URI and tack it on. This is
1904
+ // intended to make working with chdir() a little more
1905
+ // tolerant.
1906
+ var f:String = this.scheme + ":" + ref;
1907
+
1908
+ return constructURI(f);
1909
+ }
1910
+ else if (ref.charAt(0) == "?")
1911
+ {
1912
+ // A relative URI that is just a query part is essentially
1913
+ // a "./?query". We tack on the "./" here to make the rest
1914
+ // of our logic work.
1915
+ ref = "./" + ref;
1916
+ }
1917
+
1918
+ // Parse the reference passed in as a URI. This way we
1919
+ // get any query and fragments parsed out as well.
1920
+ uriReference = new URI(ref);
1921
+
1922
+ if (uriReference.isAbsolute() ||
1923
+ uriReference.isHierarchical() == false)
1924
+ {
1925
+ // If the URI given is a full URI, it replaces this one.
1926
+ copyURI(uriReference);
1927
+ return true;
1928
+ }
1929
+
1930
+
1931
+ var thisPath:String, thatPath:String;
1932
+ var thisParts:Array, thatParts:Array;
1933
+ var thisIsDir:Boolean = false, thatIsDir:Boolean = false;
1934
+ var thisIsAbs:Boolean = false, thatIsAbs:Boolean = false;
1935
+ var lastIsDotOperation:Boolean = false;
1936
+ var curDir:String;
1937
+ var i:int;
1938
+
1939
+ thisPath = this.path;
1940
+ thatPath = uriReference.path;
1941
+
1942
+ if (thisPath.length > 0)
1943
+ thisParts = thisPath.split("/");
1944
+ else
1945
+ thisParts = new Array();
1946
+
1947
+ if (thatPath.length > 0)
1948
+ thatParts = thatPath.split("/");
1949
+ else
1950
+ thatParts = new Array();
1951
+
1952
+ if (thisParts.length > 0 && thisParts[0] == "")
1953
+ {
1954
+ thisIsAbs = true;
1955
+ thisParts.shift(); // pop the first one off the array
1956
+ }
1957
+ if (thisParts.length > 0 && thisParts[thisParts.length - 1] == "")
1958
+ {
1959
+ thisIsDir = true;
1960
+ thisParts.pop(); // pop the last one off the array
1961
+ }
1962
+
1963
+ if (thatParts.length > 0 && thatParts[0] == "")
1964
+ {
1965
+ thatIsAbs = true;
1966
+ thatParts.shift(); // pop the first one off the array
1967
+ }
1968
+ if (thatParts.length > 0 && thatParts[thatParts.length - 1] == "")
1969
+ {
1970
+ thatIsDir = true;
1971
+ thatParts.pop(); // pop the last one off the array
1972
+ }
1973
+
1974
+ if (thatIsAbs)
1975
+ {
1976
+ // The reference is an absolute path (starts with a slash).
1977
+ // It replaces this path wholesale.
1978
+ this.path = uriReference.path;
1979
+
1980
+ // And it inherits the query and fragment
1981
+ this.queryRaw = uriReference.queryRaw;
1982
+ this.fragment = uriReference.fragment;
1983
+
1984
+ return true;
1985
+ }
1986
+ else if (thatParts.length == 0 && uriReference.query == "")
1987
+ {
1988
+ // The reference must have only been a fragment. Fragments just
1989
+ // get appended to whatever the current path is. We don't want
1990
+ // to overwrite any query that may already exist, so this case
1991
+ // only takes on the new fragment.
1992
+ this.fragment = uriReference.fragment;
1993
+ return true;
1994
+ }
1995
+ else if (thisIsDir == false && thisParts.length > 0)
1996
+ {
1997
+ // This path ends in a file. It goes away no matter what.
1998
+ thisParts.pop();
1999
+ }
2000
+
2001
+ // By default, this assumes the query and fragment of the reference
2002
+ this.queryRaw = uriReference.queryRaw;
2003
+ this.fragment = uriReference.fragment;
2004
+
2005
+ // Append the parts of the path from the passed in reference
2006
+ // to this object's path.
2007
+ thisParts = thisParts.concat(thatParts);
2008
+
2009
+ for(i = 0; i < thisParts.length; i++)
2010
+ {
2011
+ curDir = thisParts[i];
2012
+ lastIsDotOperation = false;
2013
+
2014
+ if (curDir == ".")
2015
+ {
2016
+ thisParts.splice(i, 1);
2017
+ i = i - 1; // account for removing this item
2018
+ lastIsDotOperation = true;
2019
+ }
2020
+ else if (curDir == "..")
2021
+ {
2022
+ if (i >= 1)
2023
+ {
2024
+ if (thisParts[i - 1] == "..")
2025
+ {
2026
+ // If the previous is a "..", we must have skipped
2027
+ // it due to this URI being relative. We can't
2028
+ // collapse leading ".."s in a relative URI, so
2029
+ // do nothing.
2030
+ }
2031
+ else
2032
+ {
2033
+ thisParts.splice(i - 1, 2);
2034
+ i = i - 2; // move back to account for the 2 we removed
2035
+ }
2036
+ }
2037
+ else
2038
+ {
2039
+ // This is the first thing in the path.
2040
+
2041
+ if (isRelative())
2042
+ {
2043
+ // We can't collapse leading ".."s in a relative
2044
+ // path. Do noting.
2045
+ }
2046
+ else
2047
+ {
2048
+ // This is an abnormal case. We have dot-dotted up
2049
+ // past the base of our "file system". This is a
2050
+ // case where we had a /path/like/this.htm and were
2051
+ // given a path to chdir to like this:
2052
+ // ../../../../../../mydir
2053
+ // Obviously, it has too many ".." and will take us
2054
+ // up beyond the top of the URI. However, according
2055
+ // RFC 2396 Appendix C.2, we should try to handle
2056
+ // these abnormal cases appropriately. In this case,
2057
+ // we will do what UNIX command lines do if you are
2058
+ // at the root (/) of the filesystem and execute:
2059
+ // # cd ../../../../../bin
2060
+ // Which will put you in /bin. Essentially, the extra
2061
+ // ".."'s will just get eaten.
2062
+
2063
+ thisParts.splice(i, 1);
2064
+ i = i - 1; // account for the ".." we just removed
2065
+ }
2066
+ }
2067
+
2068
+ lastIsDotOperation = true;
2069
+ }
2070
+ }
2071
+
2072
+ var finalPath:String = "";
2073
+
2074
+ // If the last thing in the path was a "." or "..", then this thing is a
2075
+ // directory. If the last thing isn't a dot-op, then we don't want to
2076
+ // blow away any information about the directory (hence the "|=" binary
2077
+ // assignment).
2078
+ thatIsDir = thatIsDir || lastIsDotOperation;
2079
+
2080
+ // Reconstruct the path with the abs/dir info we have
2081
+ finalPath = joinPath(thisParts, thisIsAbs, thatIsDir);
2082
+
2083
+ // Set the path (automatically escaping it)
2084
+ this.path = finalPath;
2085
+
2086
+ return true;
2087
+ }
2088
+
2089
+ /**
2090
+ * @private
2091
+ * Join an array of path parts back into a URI style path string.
2092
+ * This is used by the various path logic functions to recombine
2093
+ * a path. This is different than the standard Array.join()
2094
+ * function because we need to take into account the starting and
2095
+ * ending path delimiters if this is an absolute path or a
2096
+ * directory.
2097
+ *
2098
+ * @param parts the Array that contains strings of each path part.
2099
+ * @param isAbs true if the given path is absolute
2100
+ * @param isDir true if the given path is a directory
2101
+ *
2102
+ * @return the combined path string.
2103
+ */
2104
+ protected function joinPath(parts:Array, isAbs:Boolean, isDir:Boolean) : String
2105
+ {
2106
+ var pathStr:String = "";
2107
+ var i:int;
2108
+
2109
+ for (i = 0; i < parts.length; i++)
2110
+ {
2111
+ if (pathStr.length > 0)
2112
+ pathStr += "/";
2113
+
2114
+ pathStr += parts[i];
2115
+ }
2116
+
2117
+ // If this path is a directory, tack on the directory delimiter,
2118
+ // but only if the path contains something. Adding this to an
2119
+ // empty path would make it "/", which is an absolute path that
2120
+ // starts at the root.
2121
+ if (isDir && pathStr.length > 0)
2122
+ pathStr += "/";
2123
+
2124
+ if (isAbs)
2125
+ pathStr = "/" + pathStr;
2126
+
2127
+ return pathStr;
2128
+ }
2129
+
2130
+ /**
2131
+ * Given an absolute URI, make this relative URI absolute using
2132
+ * the given URI as a base. This URI instance must be relative
2133
+ * and the base_uri must be absolute.
2134
+ *
2135
+ * @param base_uri URI to use as the base from which to make
2136
+ * this relative URI into an absolute URI.
2137
+ *
2138
+ * @return true if successful, false otherwise.
2139
+ */
2140
+ public function makeAbsoluteURI(base_uri:URI) : Boolean
2141
+ {
2142
+ if (isAbsolute() || base_uri.isRelative())
2143
+ {
2144
+ // This URI needs to be relative, and the base needs to be
2145
+ // absolute otherwise we won't know what to do!
2146
+ return false;
2147
+ }
2148
+
2149
+ // Make a copy of the base URI. We don't want to modify
2150
+ // the passed URI.
2151
+ var base:URI = new URI();
2152
+ base.copyURI(base_uri);
2153
+
2154
+ // ChDir on the base URI. This will preserve any query
2155
+ // and fragment we have.
2156
+ if (base.chdir(toString()) == false)
2157
+ return false;
2158
+
2159
+ // It worked, so copy the base into this one
2160
+ copyURI(base);
2161
+
2162
+ return true;
2163
+ }
2164
+
2165
+
2166
+ /**
2167
+ * Given a URI to use as a base from which this object should be
2168
+ * relative to, convert this object into a relative URI. For example,
2169
+ * if you have:
2170
+ *
2171
+ * <listing>
2172
+ * var uri1:URI = new URI("http://something.com/path/to/some/file.html");
2173
+ * var uri2:URI = new URI("http://something.com/path/to/another/file.html");
2174
+ *
2175
+ * uri1.MakeRelativePath(uri2);</listing>
2176
+ *
2177
+ * <p>uri1 will have a final value of "../some/file.html"</p>
2178
+ *
2179
+ * <p>Note! This function is brute force. If you have two URI's
2180
+ * that are completely unrelated, this will still attempt to make
2181
+ * the relative URI. In that case, you will most likely get a
2182
+ * relative path that looks something like:</p>
2183
+ *
2184
+ * <p>../../../../../../some/path/to/my/file.html</p>
2185
+ *
2186
+ * @param base_uri the URI from which to make this URI relative
2187
+ *
2188
+ * @return true if successful, false if the base_uri and this URI
2189
+ * are not related, of if error.
2190
+ */
2191
+ public function makeRelativeURI(base_uri:URI, caseSensitive:Boolean = true) : Boolean
2192
+ {
2193
+ var base:URI = new URI();
2194
+ base.copyURI(base_uri);
2195
+
2196
+ var thisParts:Array, thatParts:Array;
2197
+ var finalParts:Array = new Array();
2198
+ var thisPart:String, thatPart:String, finalPath:String;
2199
+ var pathStr:String = this.path;
2200
+ var queryStr:String = this.queryRaw;
2201
+ var fragmentStr:String = this.fragment;
2202
+ var i:int;
2203
+ var diff:Boolean = false;
2204
+ var isDir:Boolean = false;
2205
+
2206
+ if (isRelative())
2207
+ {
2208
+ // We're already relative.
2209
+ return true;
2210
+ }
2211
+
2212
+ if (base.isRelative())
2213
+ {
2214
+ // The base is relative. A relative base doesn't make sense.
2215
+ return false;
2216
+ }
2217
+
2218
+
2219
+ if ( (isOfType(base_uri.scheme) == false) ||
2220
+ (this.authority != base_uri.authority) )
2221
+ {
2222
+ // The schemes and/or authorities are different. We can't
2223
+ // make a relative path to something that is completely
2224
+ // unrelated.
2225
+ return false;
2226
+ }
2227
+
2228
+ // Record the state of this URI
2229
+ isDir = isDirectory();
2230
+
2231
+ // We are based of the directory of the given URI. We need to
2232
+ // make sure the URI is pointing to a directory. Changing
2233
+ // directory to "." will remove any file name if the base is
2234
+ // not a directory.
2235
+ base.chdir(".");
2236
+
2237
+ thisParts = pathStr.split("/");
2238
+ thatParts = base.path.split("/");
2239
+
2240
+ if (thisParts.length > 0 && thisParts[0] == "")
2241
+ thisParts.shift();
2242
+
2243
+ if (thisParts.length > 0 && thisParts[thisParts.length - 1] == "")
2244
+ {
2245
+ isDir = true;
2246
+ thisParts.pop();
2247
+ }
2248
+
2249
+ if (thatParts.length > 0 && thatParts[0] == "")
2250
+ thatParts.shift();
2251
+ if (thatParts.length > 0 && thatParts[thatParts.length - 1] == "")
2252
+ thatParts.pop();
2253
+
2254
+
2255
+ // Now that we have the paths split into an array of directories,
2256
+ // we can compare the two paths. We start from the left of side
2257
+ // of the path and start comparing. When we either run out of
2258
+ // directories (one path is longer than the other), or we find
2259
+ // a directory that is different, we stop. The remaining parts
2260
+ // of each path is then used to determine the relative path. For
2261
+ // example, lets say we have:
2262
+ // path we want to make relative: /a/b/c/d/e.txt
2263
+ // path to use as base for relative: /a/b/f/
2264
+ //
2265
+ // This loop will start at the left, and remove directories
2266
+ // until we get a mismatch or run off the end of one of them.
2267
+ // In this example, the result will be:
2268
+ // c/d/e.txt
2269
+ // f
2270
+ //
2271
+ // For every part left over in the base path, we prepend a ".."
2272
+ // to the relative to get the final path:
2273
+ // ../c/d/e.txt
2274
+ while(thatParts.length > 0)
2275
+ {
2276
+ if (thisParts.length == 0)
2277
+ {
2278
+ // we matched all there is to match, we are done.
2279
+ // This is the case where "this" object is a parent
2280
+ // path of the given URI. eg:
2281
+ // this.path = /a/b/ (thisParts)
2282
+ // base.path = /a/b/c/d/e/ (thatParts)
2283
+ break;
2284
+ }
2285
+
2286
+ thisPart = thisParts[0];
2287
+ thatPart = thatParts[0];
2288
+
2289
+ if (compareStr(thisPart, thatPart, caseSensitive))
2290
+ {
2291
+ thisParts.shift();
2292
+ thatParts.shift();
2293
+ }
2294
+ else
2295
+ break;
2296
+ }
2297
+
2298
+ // If there are any path info left from the base URI, that means
2299
+ // **this** object is above the given URI in the file tree. For
2300
+ // each part left over in the given URI, we need to move up one
2301
+ // directory to get where we are.
2302
+ var dotdot:String = "..";
2303
+ for (i = 0; i < thatParts.length; i++)
2304
+ {
2305
+ finalParts.push(dotdot);
2306
+ }
2307
+
2308
+ // Append the parts of this URI to any dot-dot's we have
2309
+ finalParts = finalParts.concat(thisParts);
2310
+
2311
+ // Join the parts back into a path
2312
+ finalPath = joinPath(finalParts, false /* not absolute */, isDir);
2313
+
2314
+ if (finalPath.length == 0)
2315
+ {
2316
+ // The two URI's are exactly the same. The proper relative
2317
+ // path is:
2318
+ finalPath = "./";
2319
+ }
2320
+
2321
+ // Set the parts of the URI, preserving the original query and
2322
+ // fragment parts.
2323
+ setParts("", "", "", finalPath, queryStr, fragmentStr);
2324
+
2325
+ return true;
2326
+ }
2327
+
2328
+ /**
2329
+ * Given a string, convert it to a URI. The string could be a
2330
+ * full URI that is improperly escaped, a malformed URI (e.g.
2331
+ * missing a protocol like "www.something.com"), a relative URI,
2332
+ * or any variation there of.
2333
+ *
2334
+ * <p>The intention of this function is to take anything that a
2335
+ * user might manually enter as a URI/URL and try to determine what
2336
+ * they mean. This function differs from the URI constructor in
2337
+ * that it makes some assumptions to make it easy to import user
2338
+ * entered URI data.</p>
2339
+ *
2340
+ * <p>This function is intended to be a helper function.
2341
+ * It is not all-knowning and will probably make mistakes
2342
+ * when attempting to parse a string of unknown origin. If
2343
+ * your applicaiton is receiving input from the user, your
2344
+ * application should already have a good idea what the user
2345
+ * should be entering, and your application should be
2346
+ * pre-processing the user's input to make sure it is well formed
2347
+ * before passing it to this function.</p>
2348
+ *
2349
+ * <p>It is assumed that the string given to this function is
2350
+ * something the user may have manually entered. Given this,
2351
+ * the URI string is probably unescaped or improperly escaped.
2352
+ * This function will attempt to properly escape the URI by
2353
+ * using forceEscape(). The result is that a toString() call
2354
+ * on a URI that was created from unknownToURI() may not match
2355
+ * the input string due to the difference in escaping.</p>
2356
+ *
2357
+ * @param unknown a potental URI string that should be parsed
2358
+ * and loaded into this object.
2359
+ * @param defaultScheme if it is determined that the passed string
2360
+ * looks like a URI, but it is missing the scheme part, this
2361
+ * string will be used as the missing scheme.
2362
+ *
2363
+ * @return true if the given string was successfully parsed into
2364
+ * a valid URI object, false otherwise.
2365
+ */
2366
+ public function unknownToURI(unknown:String, defaultScheme:String = "http") : Boolean
2367
+ {
2368
+ var temp:String;
2369
+
2370
+ if (unknown.length == 0)
2371
+ {
2372
+ this.initialize();
2373
+ return false;
2374
+ }
2375
+
2376
+ // Some users love the backslash key. Fix it.
2377
+ unknown = unknown.replace(/\\/g, "/");
2378
+
2379
+ // Check for any obviously missing scheme.
2380
+ if (unknown.length >= 2)
2381
+ {
2382
+ temp = unknown.substr(0, 2);
2383
+ if (temp == "//")
2384
+ unknown = defaultScheme + ":" + unknown;
2385
+ }
2386
+
2387
+ if (unknown.length >= 3)
2388
+ {
2389
+ temp = unknown.substr(0, 3);
2390
+ if (temp == "://")
2391
+ unknown = defaultScheme + unknown;
2392
+ }
2393
+
2394
+ // Try parsing it as a normal URI
2395
+ var uri:URI = new URI(unknown);
2396
+
2397
+ if (uri.isHierarchical() == false)
2398
+ {
2399
+ if (uri.scheme == UNKNOWN_SCHEME)
2400
+ {
2401
+ this.initialize();
2402
+ return false;
2403
+ }
2404
+
2405
+ // It's a non-hierarchical URI
2406
+ copyURI(uri);
2407
+ forceEscape();
2408
+ return true;
2409
+ }
2410
+ else if ((uri.scheme != UNKNOWN_SCHEME) &&
2411
+ (uri.scheme.length > 0))
2412
+ {
2413
+ if ( (uri.authority.length > 0) ||
2414
+ (uri.scheme == "file") )
2415
+ {
2416
+ // file://... URI
2417
+ copyURI(uri);
2418
+ forceEscape(); // ensure proper escaping
2419
+ return true;
2420
+ }
2421
+ else if (uri.authority.length == 0 && uri.path.length == 0)
2422
+ {
2423
+ // It's is an incomplete URI (eg "http://")
2424
+
2425
+ setParts(uri.scheme, "", "", "", "", "");
2426
+ return false;
2427
+ }
2428
+ }
2429
+ else
2430
+ {
2431
+ // Possible relative URI. We can only detect relative URI's
2432
+ // that start with "." or "..". If it starts with something
2433
+ // else, the parsing is ambiguous.
2434
+ var path:String = uri.path;
2435
+
2436
+ if (path == ".." || path == "." ||
2437
+ (path.length >= 3 && path.substr(0, 3) == "../") ||
2438
+ (path.length >= 2 && path.substr(0, 2) == "./") )
2439
+ {
2440
+ // This is a relative URI.
2441
+ copyURI(uri);
2442
+ forceEscape();
2443
+ return true;
2444
+ }
2445
+ }
2446
+
2447
+ // Ok, it looks like we are just a normal URI missing the scheme. Tack
2448
+ // on the scheme.
2449
+ uri = new URI(defaultScheme + "://" + unknown);
2450
+
2451
+ // Check to see if we are good now
2452
+ if (uri.scheme.length > 0 && uri.authority.length > 0)
2453
+ {
2454
+ // It was just missing the scheme.
2455
+ copyURI(uri);
2456
+ forceEscape(); // Make sure we are properly encoded.
2457
+ return true;
2458
+ }
2459
+
2460
+ // don't know what this is
2461
+ this.initialize();
2462
+ return false;
2463
+ }
2464
+
2465
+ } // end URI class
2466
+ } // end package