mas01mj@732
|
1 /*
|
mas01mj@732
|
2 Copyright (c) 2008, Adobe Systems Incorporated
|
mas01mj@732
|
3 All rights reserved.
|
mas01mj@732
|
4
|
mas01mj@732
|
5 Redistribution and use in source and binary forms, with or without
|
mas01mj@732
|
6 modification, are permitted provided that the following conditions are
|
mas01mj@732
|
7 met:
|
mas01mj@732
|
8
|
mas01mj@732
|
9 * Redistributions of source code must retain the above copyright notice,
|
mas01mj@732
|
10 this list of conditions and the following disclaimer.
|
mas01mj@732
|
11
|
mas01mj@732
|
12 * Redistributions in binary form must reproduce the above copyright
|
mas01mj@732
|
13 notice, this list of conditions and the following disclaimer in the
|
mas01mj@732
|
14 documentation and/or other materials provided with the distribution.
|
mas01mj@732
|
15
|
mas01mj@732
|
16 * Neither the name of Adobe Systems Incorporated nor the names of its
|
mas01mj@732
|
17 contributors may be used to endorse or promote products derived from
|
mas01mj@732
|
18 this software without specific prior written permission.
|
mas01mj@732
|
19
|
mas01mj@732
|
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
mas01mj@732
|
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
mas01mj@732
|
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
mas01mj@732
|
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
mas01mj@732
|
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
mas01mj@732
|
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
mas01mj@732
|
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
mas01mj@732
|
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
mas01mj@732
|
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
mas01mj@732
|
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
mas01mj@732
|
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
mas01mj@732
|
31 */
|
mas01mj@732
|
32
|
mas01mj@732
|
33 package com.adobe.net
|
mas01mj@732
|
34 {
|
mas01mj@732
|
35 import flash.utils.ByteArray;
|
mas01mj@732
|
36
|
mas01mj@732
|
37 /**
|
mas01mj@732
|
38 * This class implements functions and utilities for working with URI's
|
mas01mj@732
|
39 * (Universal Resource Identifiers). For technical description of the
|
mas01mj@732
|
40 * URI syntax, please see RFC 3986 at http://www.ietf.org/rfc/rfc3986.txt
|
mas01mj@732
|
41 * or do a web search for "rfc 3986".
|
mas01mj@732
|
42 *
|
mas01mj@732
|
43 * <p>The most important aspect of URI's to understand is that URI's
|
mas01mj@732
|
44 * and URL's are not strings. URI's are complex data structures that
|
mas01mj@732
|
45 * encapsulate many pieces of information. The string version of a
|
mas01mj@732
|
46 * URI is the serialized representation of that data structure. This
|
mas01mj@732
|
47 * string serialization is used to provide a human readable
|
mas01mj@732
|
48 * representation and a means to transport the data over the network
|
mas01mj@732
|
49 * where it can then be parsed back into its' component parts.</p>
|
mas01mj@732
|
50 *
|
mas01mj@732
|
51 * <p>URI's fall into one of three categories:
|
mas01mj@732
|
52 * <ul>
|
mas01mj@732
|
53 * <li><scheme>:<scheme-specific-part>#<fragment> (non-hierarchical)</li>
|
mas01mj@732
|
54 * <li><scheme>:<authority><path>?<query>#<fragment> (hierarchical)</li>
|
mas01mj@732
|
55 * <li><path>?<query>#<fragment> (relative hierarchical)</li>
|
mas01mj@732
|
56 * </ul></p>
|
mas01mj@732
|
57 *
|
mas01mj@732
|
58 * <p>The query and fragment parts are optional.</p>
|
mas01mj@732
|
59 *
|
mas01mj@732
|
60 * <p>This class supports both non-hierarchical and hierarchical URI's</p>
|
mas01mj@732
|
61 *
|
mas01mj@732
|
62 * <p>This class is intended to be used "as-is" for the vast majority
|
mas01mj@732
|
63 * of common URI's. However, if your application requires a custom
|
mas01mj@732
|
64 * URI syntax (e.g. custom query syntax or special handling of
|
mas01mj@732
|
65 * non-hierarchical URI's), this class can be fully subclassed. If you
|
mas01mj@732
|
66 * intended to subclass URI, please see the source code for complete
|
mas01mj@732
|
67 * documation on protected members and protected fuctions.</p>
|
mas01mj@732
|
68 *
|
mas01mj@732
|
69 * @langversion ActionScript 3.0
|
mas01mj@732
|
70 * @playerversion Flash 9.0
|
mas01mj@732
|
71 */
|
mas01mj@732
|
72 public class URI
|
mas01mj@732
|
73 {
|
mas01mj@732
|
74 // Here we define which characters must be escaped for each
|
mas01mj@732
|
75 // URI part. The characters that must be escaped for each
|
mas01mj@732
|
76 // part differ depending on what would cause ambiguous parsing.
|
mas01mj@732
|
77 // RFC 3986 sec. 2.4 states that characters should only be
|
mas01mj@732
|
78 // encoded when they would conflict with subcomponent delimiters.
|
mas01mj@732
|
79 // We don't want to over-do the escaping. We only want to escape
|
mas01mj@732
|
80 // the minimum needed to prevent parsing problems.
|
mas01mj@732
|
81
|
mas01mj@732
|
82 // space and % must be escaped in all cases. '%' is the delimiter
|
mas01mj@732
|
83 // for escaped characters.
|
mas01mj@732
|
84 public static const URImustEscape:String = " %";
|
mas01mj@732
|
85
|
mas01mj@732
|
86 // Baseline of what characters must be escaped
|
mas01mj@732
|
87 public static const URIbaselineEscape:String = URImustEscape + ":?#/@";
|
mas01mj@732
|
88
|
mas01mj@732
|
89 // Characters that must be escaped in the part part.
|
mas01mj@732
|
90 public static const URIpathEscape:String = URImustEscape + "?#";
|
mas01mj@732
|
91
|
mas01mj@732
|
92 // Characters that must be escaped in the query part, if setting
|
mas01mj@732
|
93 // the query as a whole string. If the query is set by
|
mas01mj@732
|
94 // name/value, URIqueryPartEscape is used instead.
|
mas01mj@732
|
95 public static const URIqueryEscape:String = URImustEscape + "#";
|
mas01mj@732
|
96
|
mas01mj@732
|
97 // This is what each name/value pair must escape "&=" as well
|
mas01mj@732
|
98 // so they don't conflict with the "param=value¶m2=value2"
|
mas01mj@732
|
99 // syntax.
|
mas01mj@732
|
100 public static const URIqueryPartEscape:String = URImustEscape + "#&=";
|
mas01mj@732
|
101
|
mas01mj@732
|
102 // Non-hierarchical URI's can have query and fragment parts, but
|
mas01mj@732
|
103 // we also want to prevent '/' otherwise it might end up looking
|
mas01mj@732
|
104 // like a hierarchical URI to the parser.
|
mas01mj@732
|
105 public static const URInonHierEscape:String = URImustEscape + "?#/";
|
mas01mj@732
|
106
|
mas01mj@732
|
107 // Baseline uninitialized setting for the URI scheme.
|
mas01mj@732
|
108 public static const UNKNOWN_SCHEME:String = "unknown";
|
mas01mj@732
|
109
|
mas01mj@732
|
110 // The following bitmaps are used for performance enhanced
|
mas01mj@732
|
111 // character escaping.
|
mas01mj@732
|
112
|
mas01mj@732
|
113 // Baseline characters that need to be escaped. Many parts use
|
mas01mj@732
|
114 // this.
|
mas01mj@732
|
115 protected static const URIbaselineExcludedBitmap:URIEncodingBitmap =
|
mas01mj@732
|
116 new URIEncodingBitmap(URIbaselineEscape);
|
mas01mj@732
|
117
|
mas01mj@732
|
118 // Scheme escaping bitmap
|
mas01mj@732
|
119 protected static const URIschemeExcludedBitmap:URIEncodingBitmap =
|
mas01mj@732
|
120 URIbaselineExcludedBitmap;
|
mas01mj@732
|
121
|
mas01mj@732
|
122 // User/pass escaping bitmap
|
mas01mj@732
|
123 protected static const URIuserpassExcludedBitmap:URIEncodingBitmap =
|
mas01mj@732
|
124 URIbaselineExcludedBitmap;
|
mas01mj@732
|
125
|
mas01mj@732
|
126 // Authority escaping bitmap
|
mas01mj@732
|
127 protected static const URIauthorityExcludedBitmap:URIEncodingBitmap =
|
mas01mj@732
|
128 URIbaselineExcludedBitmap;
|
mas01mj@732
|
129
|
mas01mj@732
|
130 // Port escaping bitmap
|
mas01mj@732
|
131 protected static const URIportExludedBitmap:URIEncodingBitmap =
|
mas01mj@732
|
132 URIbaselineExcludedBitmap;
|
mas01mj@732
|
133
|
mas01mj@732
|
134 // Path escaping bitmap
|
mas01mj@732
|
135 protected static const URIpathExcludedBitmap:URIEncodingBitmap =
|
mas01mj@732
|
136 new URIEncodingBitmap(URIpathEscape);
|
mas01mj@732
|
137
|
mas01mj@732
|
138 // Query (whole) escaping bitmap
|
mas01mj@732
|
139 protected static const URIqueryExcludedBitmap:URIEncodingBitmap =
|
mas01mj@732
|
140 new URIEncodingBitmap(URIqueryEscape);
|
mas01mj@732
|
141
|
mas01mj@732
|
142 // Query (individual parts) escaping bitmap
|
mas01mj@732
|
143 protected static const URIqueryPartExcludedBitmap:URIEncodingBitmap =
|
mas01mj@732
|
144 new URIEncodingBitmap(URIqueryPartEscape);
|
mas01mj@732
|
145
|
mas01mj@732
|
146 // Fragments are the last part in the URI. They only need to
|
mas01mj@732
|
147 // escape space, '#', and '%'. Turns out that is what query
|
mas01mj@732
|
148 // uses too.
|
mas01mj@732
|
149 protected static const URIfragmentExcludedBitmap:URIEncodingBitmap =
|
mas01mj@732
|
150 URIqueryExcludedBitmap;
|
mas01mj@732
|
151
|
mas01mj@732
|
152 // Characters that need to be escaped in the non-hierarchical part
|
mas01mj@732
|
153 protected static const URInonHierexcludedBitmap:URIEncodingBitmap =
|
mas01mj@732
|
154 new URIEncodingBitmap(URInonHierEscape);
|
mas01mj@732
|
155
|
mas01mj@732
|
156 // Values used by getRelation()
|
mas01mj@732
|
157 public static const NOT_RELATED:int = 0;
|
mas01mj@732
|
158 public static const CHILD:int = 1;
|
mas01mj@732
|
159 public static const EQUAL:int = 2;
|
mas01mj@732
|
160 public static const PARENT:int = 3;
|
mas01mj@732
|
161
|
mas01mj@732
|
162 //-------------------------------------------------------------------
|
mas01mj@732
|
163 // protected class members
|
mas01mj@732
|
164 //-------------------------------------------------------------------
|
mas01mj@732
|
165 protected var _valid:Boolean = false;
|
mas01mj@732
|
166 protected var _relative:Boolean = false;
|
mas01mj@732
|
167 protected var _scheme:String = "";
|
mas01mj@732
|
168 protected var _authority:String = "";
|
mas01mj@732
|
169 protected var _username:String = "";
|
mas01mj@732
|
170 protected var _password:String = "";
|
mas01mj@732
|
171 protected var _port:String = "";
|
mas01mj@732
|
172 protected var _path:String = "";
|
mas01mj@732
|
173 protected var _query:String = "";
|
mas01mj@732
|
174 protected var _fragment:String = "";
|
mas01mj@732
|
175 protected var _nonHierarchical:String = "";
|
mas01mj@732
|
176 protected static var _resolver:IURIResolver = null;
|
mas01mj@732
|
177
|
mas01mj@732
|
178
|
mas01mj@732
|
179 /**
|
mas01mj@732
|
180 * URI Constructor. If no string is given, this will initialize
|
mas01mj@732
|
181 * this URI object to a blank URI.
|
mas01mj@732
|
182 */
|
mas01mj@732
|
183 public function URI(uri:String = null) : void
|
mas01mj@732
|
184 {
|
mas01mj@732
|
185 if (uri == null)
|
mas01mj@732
|
186 initialize();
|
mas01mj@732
|
187 else
|
mas01mj@732
|
188 constructURI(uri);
|
mas01mj@732
|
189 }
|
mas01mj@732
|
190
|
mas01mj@732
|
191
|
mas01mj@732
|
192 /**
|
mas01mj@732
|
193 * @private
|
mas01mj@732
|
194 * Method that loads the URI from the given string.
|
mas01mj@732
|
195 */
|
mas01mj@732
|
196 protected function constructURI(uri:String) : Boolean
|
mas01mj@732
|
197 {
|
mas01mj@732
|
198 if (!parseURI(uri))
|
mas01mj@732
|
199 _valid = false;
|
mas01mj@732
|
200
|
mas01mj@732
|
201 return isValid();
|
mas01mj@732
|
202 }
|
mas01mj@732
|
203
|
mas01mj@732
|
204
|
mas01mj@732
|
205 /**
|
mas01mj@732
|
206 * @private Private initializiation.
|
mas01mj@732
|
207 */
|
mas01mj@732
|
208 protected function initialize() : void
|
mas01mj@732
|
209 {
|
mas01mj@732
|
210 _valid = false;
|
mas01mj@732
|
211 _relative = false;
|
mas01mj@732
|
212
|
mas01mj@732
|
213 _scheme = UNKNOWN_SCHEME;
|
mas01mj@732
|
214 _authority = "";
|
mas01mj@732
|
215 _username = "";
|
mas01mj@732
|
216 _password = "";
|
mas01mj@732
|
217 _port = "";
|
mas01mj@732
|
218 _path = "";
|
mas01mj@732
|
219 _query = "";
|
mas01mj@732
|
220 _fragment = "";
|
mas01mj@732
|
221
|
mas01mj@732
|
222 _nonHierarchical = "";
|
mas01mj@732
|
223 }
|
mas01mj@732
|
224
|
mas01mj@732
|
225 /**
|
mas01mj@732
|
226 * @private Accessor to explicitly set/get the hierarchical
|
mas01mj@732
|
227 * state of the URI.
|
mas01mj@732
|
228 */
|
mas01mj@732
|
229 protected function set hierState(state:Boolean) : void
|
mas01mj@732
|
230 {
|
mas01mj@732
|
231 if (state)
|
mas01mj@732
|
232 {
|
mas01mj@732
|
233 // Clear the non-hierarchical data
|
mas01mj@732
|
234 _nonHierarchical = "";
|
mas01mj@732
|
235
|
mas01mj@732
|
236 // Also set the state vars while we are at it
|
mas01mj@732
|
237 if (_scheme == "" || _scheme == UNKNOWN_SCHEME)
|
mas01mj@732
|
238 _relative = true;
|
mas01mj@732
|
239 else
|
mas01mj@732
|
240 _relative = false;
|
mas01mj@732
|
241
|
mas01mj@732
|
242 if (_authority.length == 0 && _path.length == 0)
|
mas01mj@732
|
243 _valid = false;
|
mas01mj@732
|
244 else
|
mas01mj@732
|
245 _valid = true;
|
mas01mj@732
|
246 }
|
mas01mj@732
|
247 else
|
mas01mj@732
|
248 {
|
mas01mj@732
|
249 // Clear the hierarchical data
|
mas01mj@732
|
250 _authority = "";
|
mas01mj@732
|
251 _username = "";
|
mas01mj@732
|
252 _password = "";
|
mas01mj@732
|
253 _port = "";
|
mas01mj@732
|
254 _path = "";
|
mas01mj@732
|
255
|
mas01mj@732
|
256 _relative = false;
|
mas01mj@732
|
257
|
mas01mj@732
|
258 if (_scheme == "" || _scheme == UNKNOWN_SCHEME)
|
mas01mj@732
|
259 _valid = false;
|
mas01mj@732
|
260 else
|
mas01mj@732
|
261 _valid = true;
|
mas01mj@732
|
262 }
|
mas01mj@732
|
263 }
|
mas01mj@732
|
264 protected function get hierState() : Boolean
|
mas01mj@732
|
265 {
|
mas01mj@732
|
266 return (_nonHierarchical.length == 0);
|
mas01mj@732
|
267 }
|
mas01mj@732
|
268
|
mas01mj@732
|
269
|
mas01mj@732
|
270 /**
|
mas01mj@732
|
271 * @private Functions that performs some basic consistency validation.
|
mas01mj@732
|
272 */
|
mas01mj@732
|
273 protected function validateURI() : Boolean
|
mas01mj@732
|
274 {
|
mas01mj@732
|
275 // Check the scheme
|
mas01mj@732
|
276 if (isAbsolute())
|
mas01mj@732
|
277 {
|
mas01mj@732
|
278 if (_scheme.length <= 1 || _scheme == UNKNOWN_SCHEME)
|
mas01mj@732
|
279 {
|
mas01mj@732
|
280 // we probably parsed a C:\ type path or no scheme
|
mas01mj@732
|
281 return false;
|
mas01mj@732
|
282 }
|
mas01mj@732
|
283 else if (verifyAlpha(_scheme) == false)
|
mas01mj@732
|
284 return false; // Scheme contains bad characters
|
mas01mj@732
|
285 }
|
mas01mj@732
|
286
|
mas01mj@732
|
287 if (hierState)
|
mas01mj@732
|
288 {
|
mas01mj@732
|
289 if (_path.search('\\') != -1)
|
mas01mj@732
|
290 return false; // local path
|
mas01mj@732
|
291 else if (isRelative() == false && _scheme == UNKNOWN_SCHEME)
|
mas01mj@732
|
292 return false; // It's an absolute URI, but it has a bad scheme
|
mas01mj@732
|
293 }
|
mas01mj@732
|
294 else
|
mas01mj@732
|
295 {
|
mas01mj@732
|
296 if (_nonHierarchical.search('\\') != -1)
|
mas01mj@732
|
297 return false; // some kind of local path
|
mas01mj@732
|
298 }
|
mas01mj@732
|
299
|
mas01mj@732
|
300 // Looks like it's ok.
|
mas01mj@732
|
301 return true;
|
mas01mj@732
|
302 }
|
mas01mj@732
|
303
|
mas01mj@732
|
304
|
mas01mj@732
|
305 /**
|
mas01mj@732
|
306 * @private
|
mas01mj@732
|
307 *
|
mas01mj@732
|
308 * Given a URI in string format, parse that sucker into its basic
|
mas01mj@732
|
309 * components and assign them to this object. A URI is of the form:
|
mas01mj@732
|
310 * <scheme>:<authority><path>?<query>#<fragment>
|
mas01mj@732
|
311 *
|
mas01mj@732
|
312 * For simplicity, we parse the URI in the following order:
|
mas01mj@732
|
313 *
|
mas01mj@732
|
314 * 1. Fragment (anchors)
|
mas01mj@732
|
315 * 2. Query (CGI stuff)
|
mas01mj@732
|
316 * 3. Scheme ("http")
|
mas01mj@732
|
317 * 4. Authority (host name)
|
mas01mj@732
|
318 * 5. Username/Password (if any)
|
mas01mj@732
|
319 * 6. Port (server port if any)
|
mas01mj@732
|
320 * 7. Path (/homepages/mypage.html)
|
mas01mj@732
|
321 *
|
mas01mj@732
|
322 * The reason for this order is to minimize any parsing ambiguities.
|
mas01mj@732
|
323 * Fragments and queries can contain almost anything (they are parts
|
mas01mj@732
|
324 * that can contain custom data with their own syntax). Parsing
|
mas01mj@732
|
325 * them out first removes a large chance of parsing errors. This
|
mas01mj@732
|
326 * method expects well formed URI's, but performing the parse in
|
mas01mj@732
|
327 * this order makes us a little more tolerant of user error.
|
mas01mj@732
|
328 *
|
mas01mj@732
|
329 * REGEXP
|
mas01mj@732
|
330 * Why doesn't this use regular expressions to parse the URI? We
|
mas01mj@732
|
331 * have found that in a real world scenario, URI's are not always
|
mas01mj@732
|
332 * well formed. Sometimes characters that should have been escaped
|
mas01mj@732
|
333 * are not, and those situations would break a regexp pattern. This
|
mas01mj@732
|
334 * function attempts to be smart about what it is parsing based on
|
mas01mj@732
|
335 * location of characters relative to eachother. This function has
|
mas01mj@732
|
336 * been proven through real-world use to parse the vast majority
|
mas01mj@732
|
337 * of URI's correctly.
|
mas01mj@732
|
338 *
|
mas01mj@732
|
339 * NOTE
|
mas01mj@732
|
340 * It is assumed that the string in URI form is escaped. This function
|
mas01mj@732
|
341 * does not escape anything. If you constructed the URI string by
|
mas01mj@732
|
342 * hand, and used this to parse in the URI and still need it escaped,
|
mas01mj@732
|
343 * call forceEscape() on your URI object.
|
mas01mj@732
|
344 *
|
mas01mj@732
|
345 * Parsing Assumptions
|
mas01mj@732
|
346 * This routine assumes that the URI being passed is well formed.
|
mas01mj@732
|
347 * Passing things like local paths, malformed URI's, and the such
|
mas01mj@732
|
348 * will result in parsing errors. This function can handle
|
mas01mj@732
|
349 * - absolute hierarchical (e.g. "http://something.com/index.html),
|
mas01mj@732
|
350 * - relative hierarchical (e.g. "../images/flower.gif"), or
|
mas01mj@732
|
351 * - non-hierarchical URIs (e.g. "mailto:jsmith@fungoo.com").
|
mas01mj@732
|
352 *
|
mas01mj@732
|
353 * Anything else will probably result in a parsing error, or a bogus
|
mas01mj@732
|
354 * URI object.
|
mas01mj@732
|
355 *
|
mas01mj@732
|
356 * Note that non-hierarchical URIs *MUST* have a scheme, otherwise
|
mas01mj@732
|
357 * they will be mistaken for relative URI's.
|
mas01mj@732
|
358 *
|
mas01mj@732
|
359 * If you are not sure what is being passed to you (like manually
|
mas01mj@732
|
360 * entered text from UI), you can construct a blank URI object and
|
mas01mj@732
|
361 * call unknownToURI() passing in the unknown string.
|
mas01mj@732
|
362 *
|
mas01mj@732
|
363 * @return true if successful, false if there was some kind of
|
mas01mj@732
|
364 * parsing error
|
mas01mj@732
|
365 */
|
mas01mj@732
|
366 protected function parseURI(uri:String) : Boolean
|
mas01mj@732
|
367 {
|
mas01mj@732
|
368 var baseURI:String = uri;
|
mas01mj@732
|
369 var index:int, index2:int;
|
mas01mj@732
|
370
|
mas01mj@732
|
371 // Make sure this object is clean before we start. If it was used
|
mas01mj@732
|
372 // before and we are now parsing a new URI, we don't want any stale
|
mas01mj@732
|
373 // info lying around.
|
mas01mj@732
|
374 initialize();
|
mas01mj@732
|
375
|
mas01mj@732
|
376 // Remove any fragments (anchors) from the URI
|
mas01mj@732
|
377 index = baseURI.indexOf("#");
|
mas01mj@732
|
378 if (index != -1)
|
mas01mj@732
|
379 {
|
mas01mj@732
|
380 // Store the fragment piece if any
|
mas01mj@732
|
381 if (baseURI.length > (index + 1)) // +1 is to skip the '#'
|
mas01mj@732
|
382 _fragment = baseURI.substr(index + 1, baseURI.length - (index + 1));
|
mas01mj@732
|
383
|
mas01mj@732
|
384 // Trim off the fragment
|
mas01mj@732
|
385 baseURI = baseURI.substr(0, index);
|
mas01mj@732
|
386 }
|
mas01mj@732
|
387
|
mas01mj@732
|
388 // We need to strip off any CGI parameters (eg '?param=bob')
|
mas01mj@732
|
389 index = baseURI.indexOf("?");
|
mas01mj@732
|
390 if (index != -1)
|
mas01mj@732
|
391 {
|
mas01mj@732
|
392 if (baseURI.length > (index + 1))
|
mas01mj@732
|
393 _query = baseURI.substr(index + 1, baseURI.length - (index + 1)); // +1 is to skip the '?'
|
mas01mj@732
|
394
|
mas01mj@732
|
395 // Trim off the query
|
mas01mj@732
|
396 baseURI = baseURI.substr(0, index);
|
mas01mj@732
|
397 }
|
mas01mj@732
|
398
|
mas01mj@732
|
399 // Now try to find the scheme part
|
mas01mj@732
|
400 index = baseURI.search(':');
|
mas01mj@732
|
401 index2 = baseURI.search('/');
|
mas01mj@732
|
402
|
mas01mj@732
|
403 var containsColon:Boolean = (index != -1);
|
mas01mj@732
|
404 var containsSlash:Boolean = (index2 != -1);
|
mas01mj@732
|
405
|
mas01mj@732
|
406 // This value is indeterminate if "containsColon" is false.
|
mas01mj@732
|
407 // (if there is no colon, does the slash come before or
|
mas01mj@732
|
408 // after said non-existing colon?)
|
mas01mj@732
|
409 var colonBeforeSlash:Boolean = (!containsSlash || index < index2);
|
mas01mj@732
|
410
|
mas01mj@732
|
411 // If it has a colon and it's before the first slash, we will treat
|
mas01mj@732
|
412 // it as a scheme. If a slash is before a colon, there must be a
|
mas01mj@732
|
413 // stray colon in a path or something. In which case, the colon is
|
mas01mj@732
|
414 // not the separator for the scheme. Technically, we could consider
|
mas01mj@732
|
415 // this an error, but since this is not an ambiguous state (we know
|
mas01mj@732
|
416 // 100% that this has no scheme), we will keep going.
|
mas01mj@732
|
417 if (containsColon && colonBeforeSlash)
|
mas01mj@732
|
418 {
|
mas01mj@732
|
419 // We found a scheme
|
mas01mj@732
|
420 _scheme = baseURI.substr(0, index);
|
mas01mj@732
|
421
|
mas01mj@732
|
422 // Normalize the scheme
|
mas01mj@732
|
423 _scheme = _scheme.toLowerCase();
|
mas01mj@732
|
424
|
mas01mj@732
|
425 baseURI = baseURI.substr(index + 1);
|
mas01mj@732
|
426
|
mas01mj@732
|
427 if (baseURI.substr(0, 2) == "//")
|
mas01mj@732
|
428 {
|
mas01mj@732
|
429 // This is a hierarchical URI
|
mas01mj@732
|
430 _nonHierarchical = "";
|
mas01mj@732
|
431
|
mas01mj@732
|
432 // Trim off the "//"
|
mas01mj@732
|
433 baseURI = baseURI.substr(2, baseURI.length - 2);
|
mas01mj@732
|
434 }
|
mas01mj@732
|
435 else
|
mas01mj@732
|
436 {
|
mas01mj@732
|
437 // This is a non-hierarchical URI like "mailto:bob@mail.com"
|
mas01mj@732
|
438 _nonHierarchical = baseURI;
|
mas01mj@732
|
439
|
mas01mj@732
|
440 if ((_valid = validateURI()) == false)
|
mas01mj@732
|
441 initialize(); // Bad URI. Clear it.
|
mas01mj@732
|
442
|
mas01mj@732
|
443 // No more parsing to do for this case
|
mas01mj@732
|
444 return isValid();
|
mas01mj@732
|
445 }
|
mas01mj@732
|
446 }
|
mas01mj@732
|
447 else
|
mas01mj@732
|
448 {
|
mas01mj@732
|
449 // No scheme. We will consider this a relative URI
|
mas01mj@732
|
450 _scheme = "";
|
mas01mj@732
|
451 _relative = true;
|
mas01mj@732
|
452 _nonHierarchical = "";
|
mas01mj@732
|
453 }
|
mas01mj@732
|
454
|
mas01mj@732
|
455 // Ok, what we have left is everything after the <scheme>://
|
mas01mj@732
|
456
|
mas01mj@732
|
457 // Now that we have stripped off any query and fragment parts, we
|
mas01mj@732
|
458 // need to split the authority from the path
|
mas01mj@732
|
459
|
mas01mj@732
|
460 if (isRelative())
|
mas01mj@732
|
461 {
|
mas01mj@732
|
462 // Don't bother looking for the authority. It's a relative URI
|
mas01mj@732
|
463 _authority = "";
|
mas01mj@732
|
464 _port = "";
|
mas01mj@732
|
465 _path = baseURI;
|
mas01mj@732
|
466 }
|
mas01mj@732
|
467 else
|
mas01mj@732
|
468 {
|
mas01mj@732
|
469 // Check for malformed UNC style file://///server/type/path/
|
mas01mj@732
|
470 // By the time we get here, we have already trimmed the "file://"
|
mas01mj@732
|
471 // so baseURI will be ///server/type/path. If baseURI only
|
mas01mj@732
|
472 // has one slash, we leave it alone because that is valid (that
|
mas01mj@732
|
473 // is the case of "file:///path/to/file.txt" where there is no
|
mas01mj@732
|
474 // server - implicit "localhost").
|
mas01mj@732
|
475 if (baseURI.substr(0, 2) == "//")
|
mas01mj@732
|
476 {
|
mas01mj@732
|
477 // Trim all leading slashes
|
mas01mj@732
|
478 while(baseURI.charAt(0) == "/")
|
mas01mj@732
|
479 baseURI = baseURI.substr(1, baseURI.length - 1);
|
mas01mj@732
|
480 }
|
mas01mj@732
|
481
|
mas01mj@732
|
482 index = baseURI.search('/');
|
mas01mj@732
|
483 if (index == -1)
|
mas01mj@732
|
484 {
|
mas01mj@732
|
485 // No path. We must have passed something like "http://something.com"
|
mas01mj@732
|
486 _authority = baseURI;
|
mas01mj@732
|
487 _path = "";
|
mas01mj@732
|
488 }
|
mas01mj@732
|
489 else
|
mas01mj@732
|
490 {
|
mas01mj@732
|
491 _authority = baseURI.substr(0, index);
|
mas01mj@732
|
492 _path = baseURI.substr(index, baseURI.length - index);
|
mas01mj@732
|
493 }
|
mas01mj@732
|
494
|
mas01mj@732
|
495 // Check to see if the URI has any username or password information.
|
mas01mj@732
|
496 // For example: ftp://username:password@server.com
|
mas01mj@732
|
497 index = _authority.search('@');
|
mas01mj@732
|
498 if (index != -1)
|
mas01mj@732
|
499 {
|
mas01mj@732
|
500 // We have a username and possibly a password
|
mas01mj@732
|
501 _username = _authority.substr(0, index);
|
mas01mj@732
|
502
|
mas01mj@732
|
503 // Remove the username/password from the authority
|
mas01mj@732
|
504 _authority = _authority.substr(index + 1); // Skip the '@'
|
mas01mj@732
|
505
|
mas01mj@732
|
506 // Now check to see if the username also has a password
|
mas01mj@732
|
507 index = _username.search(':');
|
mas01mj@732
|
508 if (index != -1)
|
mas01mj@732
|
509 {
|
mas01mj@732
|
510 _password = _username.substring(index + 1, _username.length);
|
mas01mj@732
|
511 _username = _username.substr(0, index);
|
mas01mj@732
|
512 }
|
mas01mj@732
|
513 else
|
mas01mj@732
|
514 _password = "";
|
mas01mj@732
|
515 }
|
mas01mj@732
|
516 else
|
mas01mj@732
|
517 {
|
mas01mj@732
|
518 _username = "";
|
mas01mj@732
|
519 _password = "";
|
mas01mj@732
|
520 }
|
mas01mj@732
|
521
|
mas01mj@732
|
522 // Lastly, check to see if the authorty has a port number.
|
mas01mj@732
|
523 // This is parsed after the username/password to avoid conflicting
|
mas01mj@732
|
524 // with the ':' in the 'username:password' if one exists.
|
mas01mj@732
|
525 index = _authority.search(':');
|
mas01mj@732
|
526 if (index != -1)
|
mas01mj@732
|
527 {
|
mas01mj@732
|
528 _port = _authority.substring(index + 1, _authority.length); // skip the ':'
|
mas01mj@732
|
529 _authority = _authority.substr(0, index);
|
mas01mj@732
|
530 }
|
mas01mj@732
|
531 else
|
mas01mj@732
|
532 {
|
mas01mj@732
|
533 _port = "";
|
mas01mj@732
|
534 }
|
mas01mj@732
|
535
|
mas01mj@732
|
536 // Lastly, normalize the authority. Domain names
|
mas01mj@732
|
537 // are case insensitive.
|
mas01mj@732
|
538 _authority = _authority.toLowerCase();
|
mas01mj@732
|
539 }
|
mas01mj@732
|
540
|
mas01mj@732
|
541 if ((_valid = validateURI()) == false)
|
mas01mj@732
|
542 initialize(); // Bad URI. Clear it
|
mas01mj@732
|
543
|
mas01mj@732
|
544 return isValid();
|
mas01mj@732
|
545 }
|
mas01mj@732
|
546
|
mas01mj@732
|
547
|
mas01mj@732
|
548 /********************************************************************
|
mas01mj@732
|
549 * Copy function.
|
mas01mj@732
|
550 */
|
mas01mj@732
|
551 public function copyURI(uri:URI) : void
|
mas01mj@732
|
552 {
|
mas01mj@732
|
553 this._scheme = uri._scheme;
|
mas01mj@732
|
554 this._authority = uri._authority;
|
mas01mj@732
|
555 this._username = uri._username;
|
mas01mj@732
|
556 this._password = uri._password;
|
mas01mj@732
|
557 this._port = uri._port;
|
mas01mj@732
|
558 this._path = uri._path;
|
mas01mj@732
|
559 this._query = uri._query;
|
mas01mj@732
|
560 this._fragment = uri._fragment;
|
mas01mj@732
|
561 this._nonHierarchical = uri._nonHierarchical;
|
mas01mj@732
|
562
|
mas01mj@732
|
563 this._valid = uri._valid;
|
mas01mj@732
|
564 this._relative = uri._relative;
|
mas01mj@732
|
565 }
|
mas01mj@732
|
566
|
mas01mj@732
|
567
|
mas01mj@732
|
568 /**
|
mas01mj@732
|
569 * @private
|
mas01mj@732
|
570 * Checks if the given string only contains a-z or A-Z.
|
mas01mj@732
|
571 */
|
mas01mj@732
|
572 protected function verifyAlpha(str:String) : Boolean
|
mas01mj@732
|
573 {
|
mas01mj@732
|
574 var pattern:RegExp = /[^a-z]/;
|
mas01mj@732
|
575 var index:int;
|
mas01mj@732
|
576
|
mas01mj@732
|
577 str = str.toLowerCase();
|
mas01mj@732
|
578 index = str.search(pattern);
|
mas01mj@732
|
579
|
mas01mj@732
|
580 if (index == -1)
|
mas01mj@732
|
581 return true;
|
mas01mj@732
|
582 else
|
mas01mj@732
|
583 return false;
|
mas01mj@732
|
584 }
|
mas01mj@732
|
585
|
mas01mj@732
|
586 /**
|
mas01mj@732
|
587 * Is this a valid URI?
|
mas01mj@732
|
588 *
|
mas01mj@732
|
589 * @return true if this object represents a valid URI, false
|
mas01mj@732
|
590 * otherwise.
|
mas01mj@732
|
591 */
|
mas01mj@732
|
592 public function isValid() : Boolean
|
mas01mj@732
|
593 {
|
mas01mj@732
|
594 return this._valid;
|
mas01mj@732
|
595 }
|
mas01mj@732
|
596
|
mas01mj@732
|
597
|
mas01mj@732
|
598 /**
|
mas01mj@732
|
599 * Is this URI an absolute URI? An absolute URI is a complete, fully
|
mas01mj@732
|
600 * qualified reference to a resource. e.g. http://site.com/index.htm
|
mas01mj@732
|
601 * Non-hierarchical URI's are always absolute.
|
mas01mj@732
|
602 */
|
mas01mj@732
|
603 public function isAbsolute() : Boolean
|
mas01mj@732
|
604 {
|
mas01mj@732
|
605 return !this._relative;
|
mas01mj@732
|
606 }
|
mas01mj@732
|
607
|
mas01mj@732
|
608
|
mas01mj@732
|
609 /**
|
mas01mj@732
|
610 * Is this URI a relative URI? Relative URI's do not have a scheme
|
mas01mj@732
|
611 * and only contain a relative path with optional anchor and query
|
mas01mj@732
|
612 * parts. e.g. "../reports/index.htm". Non-hierarchical URI's
|
mas01mj@732
|
613 * will never be relative.
|
mas01mj@732
|
614 */
|
mas01mj@732
|
615 public function isRelative() : Boolean
|
mas01mj@732
|
616 {
|
mas01mj@732
|
617 return this._relative;
|
mas01mj@732
|
618 }
|
mas01mj@732
|
619
|
mas01mj@732
|
620
|
mas01mj@732
|
621 /**
|
mas01mj@732
|
622 * Does this URI point to a resource that is a directory/folder?
|
mas01mj@732
|
623 * The URI specification dictates that any path that ends in a slash
|
mas01mj@732
|
624 * is a directory. This is needed to be able to perform correct path
|
mas01mj@732
|
625 * logic when combining relative URI's with absolute URI's to
|
mas01mj@732
|
626 * obtain the correct absolute URI to a resource.
|
mas01mj@732
|
627 *
|
mas01mj@732
|
628 * @see URI.chdir
|
mas01mj@732
|
629 *
|
mas01mj@732
|
630 * @return true if this URI represents a directory resource, false
|
mas01mj@732
|
631 * if this URI represents a file resource.
|
mas01mj@732
|
632 */
|
mas01mj@732
|
633 public function isDirectory() : Boolean
|
mas01mj@732
|
634 {
|
mas01mj@732
|
635 if (_path.length == 0)
|
mas01mj@732
|
636 return false;
|
mas01mj@732
|
637
|
mas01mj@732
|
638 return (_path.charAt(path.length - 1) == '/');
|
mas01mj@732
|
639 }
|
mas01mj@732
|
640
|
mas01mj@732
|
641
|
mas01mj@732
|
642 /**
|
mas01mj@732
|
643 * Is this URI a hierarchical URI? URI's can be
|
mas01mj@732
|
644 */
|
mas01mj@732
|
645 public function isHierarchical() : Boolean
|
mas01mj@732
|
646 {
|
mas01mj@732
|
647 return hierState;
|
mas01mj@732
|
648 }
|
mas01mj@732
|
649
|
mas01mj@732
|
650
|
mas01mj@732
|
651 /**
|
mas01mj@732
|
652 * The scheme of the URI.
|
mas01mj@732
|
653 */
|
mas01mj@732
|
654 public function get scheme() : String
|
mas01mj@732
|
655 {
|
mas01mj@732
|
656 return URI.unescapeChars(_scheme);
|
mas01mj@732
|
657 }
|
mas01mj@732
|
658 public function set scheme(schemeStr:String) : void
|
mas01mj@732
|
659 {
|
mas01mj@732
|
660 // Normalize the scheme
|
mas01mj@732
|
661 var normalized:String = schemeStr.toLowerCase();
|
mas01mj@732
|
662 _scheme = URI.fastEscapeChars(normalized, URI.URIschemeExcludedBitmap);
|
mas01mj@732
|
663 }
|
mas01mj@732
|
664
|
mas01mj@732
|
665
|
mas01mj@732
|
666 /**
|
mas01mj@732
|
667 * The authority (host) of the URI. Only valid for
|
mas01mj@732
|
668 * hierarchical URI's. If the URI is relative, this will
|
mas01mj@732
|
669 * be an empty string. When setting this value, the string
|
mas01mj@732
|
670 * given is assumed to be unescaped. When retrieving this
|
mas01mj@732
|
671 * value, the resulting string is unescaped.
|
mas01mj@732
|
672 */
|
mas01mj@732
|
673 public function get authority() : String
|
mas01mj@732
|
674 {
|
mas01mj@732
|
675 return URI.unescapeChars(_authority);
|
mas01mj@732
|
676 }
|
mas01mj@732
|
677 public function set authority(authorityStr:String) : void
|
mas01mj@732
|
678 {
|
mas01mj@732
|
679 // Normalize the authority
|
mas01mj@732
|
680 authorityStr = authorityStr.toLowerCase();
|
mas01mj@732
|
681
|
mas01mj@732
|
682 _authority = URI.fastEscapeChars(authorityStr,
|
mas01mj@732
|
683 URI.URIauthorityExcludedBitmap);
|
mas01mj@732
|
684
|
mas01mj@732
|
685 // Only hierarchical URI's can have an authority, make
|
mas01mj@732
|
686 // sure this URI is of the proper format.
|
mas01mj@732
|
687 this.hierState = true;
|
mas01mj@732
|
688 }
|
mas01mj@732
|
689
|
mas01mj@732
|
690
|
mas01mj@732
|
691 /**
|
mas01mj@732
|
692 * The username of the URI. Only valid for hierarchical
|
mas01mj@732
|
693 * URI's. If the URI is relative, this will be an empty
|
mas01mj@732
|
694 * string.
|
mas01mj@732
|
695 *
|
mas01mj@732
|
696 * <p>The URI specification allows for authentication
|
mas01mj@732
|
697 * credentials to be embedded in the URI as such:</p>
|
mas01mj@732
|
698 *
|
mas01mj@732
|
699 * <p>http://user:passwd@host/path/to/file.htm</p>
|
mas01mj@732
|
700 *
|
mas01mj@732
|
701 * <p>When setting this value, the string
|
mas01mj@732
|
702 * given is assumed to be unescaped. When retrieving this
|
mas01mj@732
|
703 * value, the resulting string is unescaped.</p>
|
mas01mj@732
|
704 */
|
mas01mj@732
|
705 public function get username() : String
|
mas01mj@732
|
706 {
|
mas01mj@732
|
707 return URI.unescapeChars(_username);
|
mas01mj@732
|
708 }
|
mas01mj@732
|
709 public function set username(usernameStr:String) : void
|
mas01mj@732
|
710 {
|
mas01mj@732
|
711 _username = URI.fastEscapeChars(usernameStr, URI.URIuserpassExcludedBitmap);
|
mas01mj@732
|
712
|
mas01mj@732
|
713 // Only hierarchical URI's can have a username.
|
mas01mj@732
|
714 this.hierState = true;
|
mas01mj@732
|
715 }
|
mas01mj@732
|
716
|
mas01mj@732
|
717
|
mas01mj@732
|
718 /**
|
mas01mj@732
|
719 * The password of the URI. Similar to username.
|
mas01mj@732
|
720 * @see URI.username
|
mas01mj@732
|
721 */
|
mas01mj@732
|
722 public function get password() : String
|
mas01mj@732
|
723 {
|
mas01mj@732
|
724 return URI.unescapeChars(_password);
|
mas01mj@732
|
725 }
|
mas01mj@732
|
726 public function set password(passwordStr:String) : void
|
mas01mj@732
|
727 {
|
mas01mj@732
|
728 _password = URI.fastEscapeChars(passwordStr,
|
mas01mj@732
|
729 URI.URIuserpassExcludedBitmap);
|
mas01mj@732
|
730
|
mas01mj@732
|
731 // Only hierarchical URI's can have a password.
|
mas01mj@732
|
732 this.hierState = true;
|
mas01mj@732
|
733 }
|
mas01mj@732
|
734
|
mas01mj@732
|
735
|
mas01mj@732
|
736 /**
|
mas01mj@732
|
737 * The host port number. Only valid for hierarchical URI's. If
|
mas01mj@732
|
738 * the URI is relative, this will be an empty string. URI's can
|
mas01mj@732
|
739 * contain the port number of the remote host:
|
mas01mj@732
|
740 *
|
mas01mj@732
|
741 * <p>http://site.com:8080/index.htm</p>
|
mas01mj@732
|
742 */
|
mas01mj@732
|
743 public function get port() : String
|
mas01mj@732
|
744 {
|
mas01mj@732
|
745 return URI.unescapeChars(_port);
|
mas01mj@732
|
746 }
|
mas01mj@732
|
747 public function set port(portStr:String) : void
|
mas01mj@732
|
748 {
|
mas01mj@732
|
749 _port = URI.escapeChars(portStr);
|
mas01mj@732
|
750
|
mas01mj@732
|
751 // Only hierarchical URI's can have a port.
|
mas01mj@732
|
752 this.hierState = true;
|
mas01mj@732
|
753 }
|
mas01mj@732
|
754
|
mas01mj@732
|
755
|
mas01mj@732
|
756 /**
|
mas01mj@732
|
757 * The path portion of the URI. Only valid for hierarchical
|
mas01mj@732
|
758 * URI's. When setting this value, the string
|
mas01mj@732
|
759 * given is assumed to be unescaped. When retrieving this
|
mas01mj@732
|
760 * value, the resulting string is unescaped.
|
mas01mj@732
|
761 *
|
mas01mj@732
|
762 * <p>The path portion can be in one of two formats. 1) an absolute
|
mas01mj@732
|
763 * path, or 2) a relative path. An absolute path starts with a
|
mas01mj@732
|
764 * slash ('/'), a relative path does not.</p>
|
mas01mj@732
|
765 *
|
mas01mj@732
|
766 * <p>An absolute path may look like:</p>
|
mas01mj@732
|
767 * <listing>/full/path/to/my/file.htm</listing>
|
mas01mj@732
|
768 *
|
mas01mj@732
|
769 * <p>A relative path may look like:</p>
|
mas01mj@732
|
770 * <listing>
|
mas01mj@732
|
771 * path/to/my/file.htm
|
mas01mj@732
|
772 * ../images/logo.gif
|
mas01mj@732
|
773 * ../../reports/index.htm
|
mas01mj@732
|
774 * </listing>
|
mas01mj@732
|
775 *
|
mas01mj@732
|
776 * <p>Paths can be absolute or relative. Note that this not the same as
|
mas01mj@732
|
777 * an absolute or relative URI. An absolute URI can only have absolute
|
mas01mj@732
|
778 * paths. For example:</p>
|
mas01mj@732
|
779 *
|
mas01mj@732
|
780 * <listing>http:/site.com/path/to/file.htm</listing>
|
mas01mj@732
|
781 *
|
mas01mj@732
|
782 * <p>This absolute URI has an absolute path of "/path/to/file.htm".</p>
|
mas01mj@732
|
783 *
|
mas01mj@732
|
784 * <p>Relative URI's can have either absolute paths or relative paths.
|
mas01mj@732
|
785 * All of the following relative URI's are valid:</p>
|
mas01mj@732
|
786 *
|
mas01mj@732
|
787 * <listing>
|
mas01mj@732
|
788 * /absolute/path/to/file.htm
|
mas01mj@732
|
789 * path/to/file.htm
|
mas01mj@732
|
790 * ../path/to/file.htm
|
mas01mj@732
|
791 * </listing>
|
mas01mj@732
|
792 */
|
mas01mj@732
|
793 public function get path() : String
|
mas01mj@732
|
794 {
|
mas01mj@732
|
795 return URI.unescapeChars(_path);
|
mas01mj@732
|
796 }
|
mas01mj@732
|
797 public function set path(pathStr:String) : void
|
mas01mj@732
|
798 {
|
mas01mj@732
|
799 this._path = URI.fastEscapeChars(pathStr, URI.URIpathExcludedBitmap);
|
mas01mj@732
|
800
|
mas01mj@732
|
801 if (this._scheme == UNKNOWN_SCHEME)
|
mas01mj@732
|
802 {
|
mas01mj@732
|
803 // We set the path. This is a valid URI now.
|
mas01mj@732
|
804 this._scheme = "";
|
mas01mj@732
|
805 }
|
mas01mj@732
|
806
|
mas01mj@732
|
807 // Only hierarchical URI's can have a path.
|
mas01mj@732
|
808 hierState = true;
|
mas01mj@732
|
809 }
|
mas01mj@732
|
810
|
mas01mj@732
|
811
|
mas01mj@732
|
812 /**
|
mas01mj@732
|
813 * The query (CGI) portion of the URI. This part is valid for
|
mas01mj@732
|
814 * both hierarchical and non-hierarchical URI's.
|
mas01mj@732
|
815 *
|
mas01mj@732
|
816 * <p>This accessor should only be used if a custom query syntax
|
mas01mj@732
|
817 * is used. This URI class supports the common "param=value"
|
mas01mj@732
|
818 * style query syntax via the get/setQueryValue() and
|
mas01mj@732
|
819 * get/setQueryByMap() functions. Those functions should be used
|
mas01mj@732
|
820 * instead if the common syntax is being used.
|
mas01mj@732
|
821 *
|
mas01mj@732
|
822 * <p>The URI RFC does not specify any particular
|
mas01mj@732
|
823 * syntax for the query part of a URI. It is intended to allow
|
mas01mj@732
|
824 * any format that can be agreed upon by the two communicating hosts.
|
mas01mj@732
|
825 * However, most systems have standardized on the typical CGI
|
mas01mj@732
|
826 * format:</p>
|
mas01mj@732
|
827 *
|
mas01mj@732
|
828 * <listing>http://site.com/script.php?param1=value1¶m2=value2</listing>
|
mas01mj@732
|
829 *
|
mas01mj@732
|
830 * <p>This class has specific support for this query syntax</p>
|
mas01mj@732
|
831 *
|
mas01mj@732
|
832 * <p>This common query format is an array of name/value
|
mas01mj@732
|
833 * pairs with its own syntax that is different from the overall URI
|
mas01mj@732
|
834 * syntax. The query has its own escaping logic. For a query part
|
mas01mj@732
|
835 * to be properly escaped and unescaped, it must be split into its
|
mas01mj@732
|
836 * component parts. This accessor escapes/unescapes the entire query
|
mas01mj@732
|
837 * part without regard for it's component parts. This has the
|
mas01mj@732
|
838 * possibliity of leaving the query string in an ambiguious state in
|
mas01mj@732
|
839 * regards to its syntax. If the contents of the query part are
|
mas01mj@732
|
840 * important, it is recommended that get/setQueryValue() or
|
mas01mj@732
|
841 * get/setQueryByMap() are used instead.</p>
|
mas01mj@732
|
842 *
|
mas01mj@732
|
843 * If a different query syntax is being used, a subclass of URI
|
mas01mj@732
|
844 * can be created to handle that specific syntax.
|
mas01mj@732
|
845 *
|
mas01mj@732
|
846 * @see URI.getQueryValue, URI.getQueryByMap
|
mas01mj@732
|
847 */
|
mas01mj@732
|
848 public function get query() : String
|
mas01mj@732
|
849 {
|
mas01mj@732
|
850 return URI.unescapeChars(_query);
|
mas01mj@732
|
851 }
|
mas01mj@732
|
852 public function set query(queryStr:String) : void
|
mas01mj@732
|
853 {
|
mas01mj@732
|
854 _query = URI.fastEscapeChars(queryStr, URI.URIqueryExcludedBitmap);
|
mas01mj@732
|
855
|
mas01mj@732
|
856 // both hierarchical and non-hierarchical URI's can
|
mas01mj@732
|
857 // have a query. Do not set the hierState.
|
mas01mj@732
|
858 }
|
mas01mj@732
|
859
|
mas01mj@732
|
860 /**
|
mas01mj@732
|
861 * Accessor to the raw query data. If you are using a custom query
|
mas01mj@732
|
862 * syntax, this accessor can be used to get and set the query part
|
mas01mj@732
|
863 * directly with no escaping/unescaping. This should ONLY be used
|
mas01mj@732
|
864 * if your application logic is handling custom query logic and
|
mas01mj@732
|
865 * handling the proper escaping of the query part.
|
mas01mj@732
|
866 */
|
mas01mj@732
|
867 public function get queryRaw() : String
|
mas01mj@732
|
868 {
|
mas01mj@732
|
869 return _query;
|
mas01mj@732
|
870 }
|
mas01mj@732
|
871 public function set queryRaw(queryStr:String) : void
|
mas01mj@732
|
872 {
|
mas01mj@732
|
873 _query = queryStr;
|
mas01mj@732
|
874 }
|
mas01mj@732
|
875
|
mas01mj@732
|
876
|
mas01mj@732
|
877 /**
|
mas01mj@732
|
878 * The fragment (anchor) portion of the URI. This is valid for
|
mas01mj@732
|
879 * both hierarchical and non-hierarchical URI's.
|
mas01mj@732
|
880 */
|
mas01mj@732
|
881 public function get fragment() : String
|
mas01mj@732
|
882 {
|
mas01mj@732
|
883 return URI.unescapeChars(_fragment);
|
mas01mj@732
|
884 }
|
mas01mj@732
|
885 public function set fragment(fragmentStr:String) : void
|
mas01mj@732
|
886 {
|
mas01mj@732
|
887 _fragment = URI.fastEscapeChars(fragmentStr, URIfragmentExcludedBitmap);
|
mas01mj@732
|
888
|
mas01mj@732
|
889 // both hierarchical and non-hierarchical URI's can
|
mas01mj@732
|
890 // have a fragment. Do not set the hierState.
|
mas01mj@732
|
891 }
|
mas01mj@732
|
892
|
mas01mj@732
|
893
|
mas01mj@732
|
894 /**
|
mas01mj@732
|
895 * The non-hierarchical part of the URI. For example, if
|
mas01mj@732
|
896 * this URI object represents "mailto:somebody@company.com",
|
mas01mj@732
|
897 * this will contain "somebody@company.com". This is valid only
|
mas01mj@732
|
898 * for non-hierarchical URI's.
|
mas01mj@732
|
899 */
|
mas01mj@732
|
900 public function get nonHierarchical() : String
|
mas01mj@732
|
901 {
|
mas01mj@732
|
902 return URI.unescapeChars(_nonHierarchical);
|
mas01mj@732
|
903 }
|
mas01mj@732
|
904 public function set nonHierarchical(nonHier:String) : void
|
mas01mj@732
|
905 {
|
mas01mj@732
|
906 _nonHierarchical = URI.fastEscapeChars(nonHier, URInonHierexcludedBitmap);
|
mas01mj@732
|
907
|
mas01mj@732
|
908 // This is a non-hierarchical URI.
|
mas01mj@732
|
909 this.hierState = false;
|
mas01mj@732
|
910 }
|
mas01mj@732
|
911
|
mas01mj@732
|
912
|
mas01mj@732
|
913 /**
|
mas01mj@732
|
914 * Quick shorthand accessor to set the parts of this URI.
|
mas01mj@732
|
915 * The given parts are assumed to be in unescaped form. If
|
mas01mj@732
|
916 * the URI is non-hierarchical (e.g. mailto:) you will need
|
mas01mj@732
|
917 * to call SetScheme() and SetNonHierarchical().
|
mas01mj@732
|
918 */
|
mas01mj@732
|
919 public function setParts(schemeStr:String, authorityStr:String,
|
mas01mj@732
|
920 portStr:String, pathStr:String, queryStr:String,
|
mas01mj@732
|
921 fragmentStr:String) : void
|
mas01mj@732
|
922 {
|
mas01mj@732
|
923 this.scheme = schemeStr;
|
mas01mj@732
|
924 this.authority = authorityStr;
|
mas01mj@732
|
925 this.port = portStr;
|
mas01mj@732
|
926 this.path = pathStr;
|
mas01mj@732
|
927 this.query = queryStr;
|
mas01mj@732
|
928 this.fragment = fragmentStr;
|
mas01mj@732
|
929
|
mas01mj@732
|
930 hierState = true;
|
mas01mj@732
|
931 }
|
mas01mj@732
|
932
|
mas01mj@732
|
933
|
mas01mj@732
|
934 /**
|
mas01mj@732
|
935 * URI escapes the given character string. This is similar in function
|
mas01mj@732
|
936 * to the global encodeURIComponent() function in ActionScript, but is
|
mas01mj@732
|
937 * slightly different in regards to which characters get escaped. This
|
mas01mj@732
|
938 * escapes the characters specified in the URIbaselineExluded set (see class
|
mas01mj@732
|
939 * static members). This is needed for this class to work properly.
|
mas01mj@732
|
940 *
|
mas01mj@732
|
941 * <p>If a different set of characters need to be used for the escaping,
|
mas01mj@732
|
942 * you may use fastEscapeChars() and specify a custom URIEncodingBitmap
|
mas01mj@732
|
943 * that contains the characters your application needs escaped.</p>
|
mas01mj@732
|
944 *
|
mas01mj@732
|
945 * <p>Never pass a full URI to this function. A URI can only be properly
|
mas01mj@732
|
946 * escaped/unescaped when split into its component parts (see RFC 3986
|
mas01mj@732
|
947 * section 2.4). This is due to the fact that the URI component separators
|
mas01mj@732
|
948 * could be characters that would normally need to be escaped.</p>
|
mas01mj@732
|
949 *
|
mas01mj@732
|
950 * @param unescaped character string to be escaped.
|
mas01mj@732
|
951 *
|
mas01mj@732
|
952 * @return escaped character string
|
mas01mj@732
|
953 *
|
mas01mj@732
|
954 * @see encodeURIComponent
|
mas01mj@732
|
955 * @see fastEscapeChars
|
mas01mj@732
|
956 */
|
mas01mj@732
|
957 static public function escapeChars(unescaped:String) : String
|
mas01mj@732
|
958 {
|
mas01mj@732
|
959 // This uses the excluded set by default.
|
mas01mj@732
|
960 return fastEscapeChars(unescaped, URI.URIbaselineExcludedBitmap);
|
mas01mj@732
|
961 }
|
mas01mj@732
|
962
|
mas01mj@732
|
963
|
mas01mj@732
|
964 /**
|
mas01mj@732
|
965 * Unescape any URI escaped characters in the given character
|
mas01mj@732
|
966 * string.
|
mas01mj@732
|
967 *
|
mas01mj@732
|
968 * <p>Never pass a full URI to this function. A URI can only be properly
|
mas01mj@732
|
969 * escaped/unescaped when split into its component parts (see RFC 3986
|
mas01mj@732
|
970 * section 2.4). This is due to the fact that the URI component separators
|
mas01mj@732
|
971 * could be characters that would normally need to be escaped.</p>
|
mas01mj@732
|
972 *
|
mas01mj@732
|
973 * @param escaped the escaped string to be unescaped.
|
mas01mj@732
|
974 *
|
mas01mj@732
|
975 * @return unescaped string.
|
mas01mj@732
|
976 */
|
mas01mj@732
|
977 static public function unescapeChars(escaped:String /*, onlyHighASCII:Boolean = false*/) : String
|
mas01mj@732
|
978 {
|
mas01mj@732
|
979 // We can just use the default AS function. It seems to
|
mas01mj@732
|
980 // decode everything correctly
|
mas01mj@732
|
981 var unescaped:String;
|
mas01mj@732
|
982 unescaped = decodeURIComponent(escaped);
|
mas01mj@732
|
983 return unescaped;
|
mas01mj@732
|
984 }
|
mas01mj@732
|
985
|
mas01mj@732
|
986 /**
|
mas01mj@732
|
987 * Performance focused function that escapes the given character
|
mas01mj@732
|
988 * string using the given URIEncodingBitmap as the rule for what
|
mas01mj@732
|
989 * characters need to be escaped. This function is used by this
|
mas01mj@732
|
990 * class and can be used externally to this class to perform
|
mas01mj@732
|
991 * escaping on custom character sets.
|
mas01mj@732
|
992 *
|
mas01mj@732
|
993 * <p>Never pass a full URI to this function. A URI can only be properly
|
mas01mj@732
|
994 * escaped/unescaped when split into its component parts (see RFC 3986
|
mas01mj@732
|
995 * section 2.4). This is due to the fact that the URI component separators
|
mas01mj@732
|
996 * could be characters that would normally need to be escaped.</p>
|
mas01mj@732
|
997 *
|
mas01mj@732
|
998 * @param unescaped the unescaped string to be escaped
|
mas01mj@732
|
999 * @param bitmap the set of characters that need to be escaped
|
mas01mj@732
|
1000 *
|
mas01mj@732
|
1001 * @return the escaped string.
|
mas01mj@732
|
1002 */
|
mas01mj@732
|
1003 static public function fastEscapeChars(unescaped:String, bitmap:URIEncodingBitmap) : String
|
mas01mj@732
|
1004 {
|
mas01mj@732
|
1005 var escaped:String = "";
|
mas01mj@732
|
1006 var c:String;
|
mas01mj@732
|
1007 var x:int, i:int;
|
mas01mj@732
|
1008
|
mas01mj@732
|
1009 for (i = 0; i < unescaped.length; i++)
|
mas01mj@732
|
1010 {
|
mas01mj@732
|
1011 c = unescaped.charAt(i);
|
mas01mj@732
|
1012
|
mas01mj@732
|
1013 x = bitmap.ShouldEscape(c);
|
mas01mj@732
|
1014 if (x)
|
mas01mj@732
|
1015 {
|
mas01mj@732
|
1016 c = x.toString(16);
|
mas01mj@732
|
1017 if (c.length == 1)
|
mas01mj@732
|
1018 c = "0" + c;
|
mas01mj@732
|
1019
|
mas01mj@732
|
1020 c = "%" + c;
|
mas01mj@732
|
1021 c = c.toUpperCase();
|
mas01mj@732
|
1022 }
|
mas01mj@732
|
1023
|
mas01mj@732
|
1024 escaped += c;
|
mas01mj@732
|
1025 }
|
mas01mj@732
|
1026
|
mas01mj@732
|
1027 return escaped;
|
mas01mj@732
|
1028 }
|
mas01mj@732
|
1029
|
mas01mj@732
|
1030
|
mas01mj@732
|
1031 /**
|
mas01mj@732
|
1032 * Is this URI of a particular scheme type? For example,
|
mas01mj@732
|
1033 * passing "http" to a URI object that represents the URI
|
mas01mj@732
|
1034 * "http://site.com/" would return true.
|
mas01mj@732
|
1035 *
|
mas01mj@732
|
1036 * @param scheme scheme to check for
|
mas01mj@732
|
1037 *
|
mas01mj@732
|
1038 * @return true if this URI object is of the given type, false
|
mas01mj@732
|
1039 * otherwise.
|
mas01mj@732
|
1040 */
|
mas01mj@732
|
1041 public function isOfType(scheme:String) : Boolean
|
mas01mj@732
|
1042 {
|
mas01mj@732
|
1043 // Schemes are never case sensitive. Ignore case.
|
mas01mj@732
|
1044 scheme = scheme.toLowerCase();
|
mas01mj@732
|
1045 return (this._scheme == scheme);
|
mas01mj@732
|
1046 }
|
mas01mj@732
|
1047
|
mas01mj@732
|
1048
|
mas01mj@732
|
1049 /**
|
mas01mj@732
|
1050 * Get the value for the specified named in the query part. This
|
mas01mj@732
|
1051 * assumes the query part of the URI is in the common
|
mas01mj@732
|
1052 * "name1=value1&name2=value2" syntax. Do not call this function
|
mas01mj@732
|
1053 * if you are using a custom query syntax.
|
mas01mj@732
|
1054 *
|
mas01mj@732
|
1055 * @param name name of the query value to get.
|
mas01mj@732
|
1056 *
|
mas01mj@732
|
1057 * @return the value of the query name, empty string if the
|
mas01mj@732
|
1058 * query name does not exist.
|
mas01mj@732
|
1059 */
|
mas01mj@732
|
1060 public function getQueryValue(name:String) : String
|
mas01mj@732
|
1061 {
|
mas01mj@732
|
1062 var map:Object;
|
mas01mj@732
|
1063 var item:String;
|
mas01mj@732
|
1064 var value:String;
|
mas01mj@732
|
1065
|
mas01mj@732
|
1066 map = getQueryByMap();
|
mas01mj@732
|
1067
|
mas01mj@732
|
1068 for (item in map)
|
mas01mj@732
|
1069 {
|
mas01mj@732
|
1070 if (item == name)
|
mas01mj@732
|
1071 {
|
mas01mj@732
|
1072 value = map[item];
|
mas01mj@732
|
1073 return value;
|
mas01mj@732
|
1074 }
|
mas01mj@732
|
1075 }
|
mas01mj@732
|
1076
|
mas01mj@732
|
1077 // Didn't find the specified key
|
mas01mj@732
|
1078 return new String("");
|
mas01mj@732
|
1079 }
|
mas01mj@732
|
1080
|
mas01mj@732
|
1081
|
mas01mj@732
|
1082 /**
|
mas01mj@732
|
1083 * Set the given value on the given query name. If the given name
|
mas01mj@732
|
1084 * does not exist, it will automatically add this name/value pair
|
mas01mj@732
|
1085 * to the query. If null is passed as the value, it will remove
|
mas01mj@732
|
1086 * the given item from the query.
|
mas01mj@732
|
1087 *
|
mas01mj@732
|
1088 * <p>This automatically escapes any characters that may conflict with
|
mas01mj@732
|
1089 * the query syntax so that they are "safe" within the query. The
|
mas01mj@732
|
1090 * strings passed are assumed to be literal unescaped name and value.</p>
|
mas01mj@732
|
1091 *
|
mas01mj@732
|
1092 * @param name name of the query value to set
|
mas01mj@732
|
1093 * @param value value of the query item to set. If null, this will
|
mas01mj@732
|
1094 * force the removal of this item from the query.
|
mas01mj@732
|
1095 */
|
mas01mj@732
|
1096 public function setQueryValue(name:String, value:String) : void
|
mas01mj@732
|
1097 {
|
mas01mj@732
|
1098 var map:Object;
|
mas01mj@732
|
1099
|
mas01mj@732
|
1100 map = getQueryByMap();
|
mas01mj@732
|
1101
|
mas01mj@732
|
1102 // If the key doesn't exist yet, this will create a new pair in
|
mas01mj@732
|
1103 // the map. If it does exist, this will overwrite the previous
|
mas01mj@732
|
1104 // value, which is what we want.
|
mas01mj@732
|
1105 map[name] = value;
|
mas01mj@732
|
1106
|
mas01mj@732
|
1107 setQueryByMap(map);
|
mas01mj@732
|
1108 }
|
mas01mj@732
|
1109
|
mas01mj@732
|
1110
|
mas01mj@732
|
1111 /**
|
mas01mj@732
|
1112 * Get the query of the URI in an Object class that allows for easy
|
mas01mj@732
|
1113 * access to the query data via Object accessors. For example:
|
mas01mj@732
|
1114 *
|
mas01mj@732
|
1115 * <listing>
|
mas01mj@732
|
1116 * var query:Object = uri.getQueryByMap();
|
mas01mj@732
|
1117 * var value:String = query["param"]; // get a value
|
mas01mj@732
|
1118 * query["param2"] = "foo"; // set a new value
|
mas01mj@732
|
1119 * </listing>
|
mas01mj@732
|
1120 *
|
mas01mj@732
|
1121 * @return Object that contains the name/value pairs of the query.
|
mas01mj@732
|
1122 *
|
mas01mj@732
|
1123 * @see #setQueryByMap
|
mas01mj@732
|
1124 * @see #getQueryValue
|
mas01mj@732
|
1125 * @see #setQueryValue
|
mas01mj@732
|
1126 */
|
mas01mj@732
|
1127 public function getQueryByMap() : Object
|
mas01mj@732
|
1128 {
|
mas01mj@732
|
1129 var queryStr:String;
|
mas01mj@732
|
1130 var pair:String;
|
mas01mj@732
|
1131 var pairs:Array;
|
mas01mj@732
|
1132 var item:Array;
|
mas01mj@732
|
1133 var name:String, value:String;
|
mas01mj@732
|
1134 var index:int;
|
mas01mj@732
|
1135 var map:Object = new Object();
|
mas01mj@732
|
1136
|
mas01mj@732
|
1137
|
mas01mj@732
|
1138 // We need the raw query string, no unescaping.
|
mas01mj@732
|
1139 queryStr = this._query;
|
mas01mj@732
|
1140
|
mas01mj@732
|
1141 pairs = queryStr.split('&');
|
mas01mj@732
|
1142 for each (pair in pairs)
|
mas01mj@732
|
1143 {
|
mas01mj@732
|
1144 if (pair.length == 0)
|
mas01mj@732
|
1145 continue;
|
mas01mj@732
|
1146
|
mas01mj@732
|
1147 item = pair.split('=');
|
mas01mj@732
|
1148
|
mas01mj@732
|
1149 if (item.length > 0)
|
mas01mj@732
|
1150 name = item[0];
|
mas01mj@732
|
1151 else
|
mas01mj@732
|
1152 continue; // empty array
|
mas01mj@732
|
1153
|
mas01mj@732
|
1154 if (item.length > 1)
|
mas01mj@732
|
1155 value = item[1];
|
mas01mj@732
|
1156 else
|
mas01mj@732
|
1157 value = "";
|
mas01mj@732
|
1158
|
mas01mj@732
|
1159 name = queryPartUnescape(name);
|
mas01mj@732
|
1160 value = queryPartUnescape(value);
|
mas01mj@732
|
1161
|
mas01mj@732
|
1162 map[name] = value;
|
mas01mj@732
|
1163 }
|
mas01mj@732
|
1164
|
mas01mj@732
|
1165 return map;
|
mas01mj@732
|
1166 }
|
mas01mj@732
|
1167
|
mas01mj@732
|
1168
|
mas01mj@732
|
1169 /**
|
mas01mj@732
|
1170 * Set the query part of this URI using the given object as the
|
mas01mj@732
|
1171 * content source. Any member of the object that has a value of
|
mas01mj@732
|
1172 * null will not be in the resulting query.
|
mas01mj@732
|
1173 *
|
mas01mj@732
|
1174 * @param map object that contains the name/value pairs as
|
mas01mj@732
|
1175 * members of that object.
|
mas01mj@732
|
1176 *
|
mas01mj@732
|
1177 * @see #getQueryByMap
|
mas01mj@732
|
1178 * @see #getQueryValue
|
mas01mj@732
|
1179 * @see #setQueryValue
|
mas01mj@732
|
1180 */
|
mas01mj@732
|
1181 public function setQueryByMap(map:Object) : void
|
mas01mj@732
|
1182 {
|
mas01mj@732
|
1183 var item:String;
|
mas01mj@732
|
1184 var name:String, value:String;
|
mas01mj@732
|
1185 var queryStr:String = "";
|
mas01mj@732
|
1186 var tmpPair:String;
|
mas01mj@732
|
1187 var foo:String;
|
mas01mj@732
|
1188
|
mas01mj@732
|
1189 for (item in map)
|
mas01mj@732
|
1190 {
|
mas01mj@732
|
1191 name = item;
|
mas01mj@732
|
1192 value = map[item];
|
mas01mj@732
|
1193
|
mas01mj@732
|
1194 if (value == null)
|
mas01mj@732
|
1195 value = "";
|
mas01mj@732
|
1196
|
mas01mj@732
|
1197 // Need to escape the name/value pair so that they
|
mas01mj@732
|
1198 // don't conflict with the query syntax (specifically
|
mas01mj@732
|
1199 // '=', '&', and <whitespace>).
|
mas01mj@732
|
1200 name = queryPartEscape(name);
|
mas01mj@732
|
1201 value = queryPartEscape(value);
|
mas01mj@732
|
1202
|
mas01mj@732
|
1203 tmpPair = name;
|
mas01mj@732
|
1204
|
mas01mj@732
|
1205 if (value.length > 0)
|
mas01mj@732
|
1206 {
|
mas01mj@732
|
1207 tmpPair += "=";
|
mas01mj@732
|
1208 tmpPair += value;
|
mas01mj@732
|
1209 }
|
mas01mj@732
|
1210
|
mas01mj@732
|
1211 if (queryStr.length != 0)
|
mas01mj@732
|
1212 queryStr += '&'; // Add the separator
|
mas01mj@732
|
1213
|
mas01mj@732
|
1214 queryStr += tmpPair;
|
mas01mj@732
|
1215 }
|
mas01mj@732
|
1216
|
mas01mj@732
|
1217 // We don't want to escape. We already escaped the
|
mas01mj@732
|
1218 // individual name/value pairs. If we escaped the
|
mas01mj@732
|
1219 // query string again by assigning it to "query",
|
mas01mj@732
|
1220 // we would have double escaping.
|
mas01mj@732
|
1221 _query = queryStr;
|
mas01mj@732
|
1222 }
|
mas01mj@732
|
1223
|
mas01mj@732
|
1224
|
mas01mj@732
|
1225 /**
|
mas01mj@732
|
1226 * Similar to Escape(), except this also escapes characters that
|
mas01mj@732
|
1227 * would conflict with the name/value pair query syntax. This is
|
mas01mj@732
|
1228 * intended to be called on each individual "name" and "value"
|
mas01mj@732
|
1229 * in the query making sure that nothing in the name or value
|
mas01mj@732
|
1230 * strings contain characters that would conflict with the query
|
mas01mj@732
|
1231 * syntax (e.g. '=' and '&').
|
mas01mj@732
|
1232 *
|
mas01mj@732
|
1233 * @param unescaped unescaped string that is to be escaped.
|
mas01mj@732
|
1234 *
|
mas01mj@732
|
1235 * @return escaped string.
|
mas01mj@732
|
1236 *
|
mas01mj@732
|
1237 * @see #queryUnescape
|
mas01mj@732
|
1238 */
|
mas01mj@732
|
1239 static public function queryPartEscape(unescaped:String) : String
|
mas01mj@732
|
1240 {
|
mas01mj@732
|
1241 var escaped:String = unescaped;
|
mas01mj@732
|
1242 escaped = URI.fastEscapeChars(unescaped, URI.URIqueryPartExcludedBitmap);
|
mas01mj@732
|
1243 return escaped;
|
mas01mj@732
|
1244 }
|
mas01mj@732
|
1245
|
mas01mj@732
|
1246
|
mas01mj@732
|
1247 /**
|
mas01mj@732
|
1248 * Unescape the individual name/value string pairs.
|
mas01mj@732
|
1249 *
|
mas01mj@732
|
1250 * @param escaped escaped string to be unescaped
|
mas01mj@732
|
1251 *
|
mas01mj@732
|
1252 * @return unescaped string
|
mas01mj@732
|
1253 *
|
mas01mj@732
|
1254 * @see #queryEscape
|
mas01mj@732
|
1255 */
|
mas01mj@732
|
1256 static public function queryPartUnescape(escaped:String) : String
|
mas01mj@732
|
1257 {
|
mas01mj@732
|
1258 var unescaped:String = escaped;
|
mas01mj@732
|
1259 unescaped = unescapeChars(unescaped);
|
mas01mj@732
|
1260 return unescaped;
|
mas01mj@732
|
1261 }
|
mas01mj@732
|
1262
|
mas01mj@732
|
1263 /**
|
mas01mj@732
|
1264 * Output this URI as a string. The resulting string is properly
|
mas01mj@732
|
1265 * escaped and well formed for machine processing.
|
mas01mj@732
|
1266 */
|
mas01mj@732
|
1267 public function toString() : String
|
mas01mj@732
|
1268 {
|
mas01mj@732
|
1269 if (this == null)
|
mas01mj@732
|
1270 return "";
|
mas01mj@732
|
1271 else
|
mas01mj@732
|
1272 return toStringInternal(false);
|
mas01mj@732
|
1273 }
|
mas01mj@732
|
1274
|
mas01mj@732
|
1275 /**
|
mas01mj@732
|
1276 * Output the URI as a string that is easily readable by a human.
|
mas01mj@732
|
1277 * This outputs the URI with all escape sequences unescaped to
|
mas01mj@732
|
1278 * their character representation. This makes the URI easier for
|
mas01mj@732
|
1279 * a human to read, but the URI could be completely invalid
|
mas01mj@732
|
1280 * because some unescaped characters may now cause ambiguous parsing.
|
mas01mj@732
|
1281 * This function should only be used if you want to display a URI to
|
mas01mj@732
|
1282 * a user. This function should never be used outside that specific
|
mas01mj@732
|
1283 * case.
|
mas01mj@732
|
1284 *
|
mas01mj@732
|
1285 * @return the URI in string format with all escape sequences
|
mas01mj@732
|
1286 * unescaped.
|
mas01mj@732
|
1287 *
|
mas01mj@732
|
1288 * @see #toString
|
mas01mj@732
|
1289 */
|
mas01mj@732
|
1290 public function toDisplayString() : String
|
mas01mj@732
|
1291 {
|
mas01mj@732
|
1292 return toStringInternal(true);
|
mas01mj@732
|
1293 }
|
mas01mj@732
|
1294
|
mas01mj@732
|
1295
|
mas01mj@732
|
1296 /**
|
mas01mj@732
|
1297 * @private
|
mas01mj@732
|
1298 *
|
mas01mj@732
|
1299 * The guts of toString()
|
mas01mj@732
|
1300 */
|
mas01mj@732
|
1301 protected function toStringInternal(forDisplay:Boolean) : String
|
mas01mj@732
|
1302 {
|
mas01mj@732
|
1303 var uri:String = "";
|
mas01mj@732
|
1304 var part:String = "";
|
mas01mj@732
|
1305
|
mas01mj@732
|
1306 if (isHierarchical() == false)
|
mas01mj@732
|
1307 {
|
mas01mj@732
|
1308 // non-hierarchical URI
|
mas01mj@732
|
1309
|
mas01mj@732
|
1310 uri += (forDisplay ? this.scheme : _scheme);
|
mas01mj@732
|
1311 uri += ":";
|
mas01mj@732
|
1312 uri += (forDisplay ? this.nonHierarchical : _nonHierarchical);
|
mas01mj@732
|
1313 }
|
mas01mj@732
|
1314 else
|
mas01mj@732
|
1315 {
|
mas01mj@732
|
1316 // Hierarchical URI
|
mas01mj@732
|
1317
|
mas01mj@732
|
1318 if (isRelative() == false)
|
mas01mj@732
|
1319 {
|
mas01mj@732
|
1320 // If it is not a relative URI, then we want the scheme and
|
mas01mj@732
|
1321 // authority parts in the string. If it is relative, we
|
mas01mj@732
|
1322 // do NOT want this stuff.
|
mas01mj@732
|
1323
|
mas01mj@732
|
1324 if (_scheme.length != 0)
|
mas01mj@732
|
1325 {
|
mas01mj@732
|
1326 part = (forDisplay ? this.scheme : _scheme);
|
mas01mj@732
|
1327 uri += part + ":";
|
mas01mj@732
|
1328 }
|
mas01mj@732
|
1329
|
mas01mj@732
|
1330 if (_authority.length != 0 || isOfType("file"))
|
mas01mj@732
|
1331 {
|
mas01mj@732
|
1332 uri += "//";
|
mas01mj@732
|
1333
|
mas01mj@732
|
1334 // Add on any username/password associated with this
|
mas01mj@732
|
1335 // authority
|
mas01mj@732
|
1336 if (_username.length != 0)
|
mas01mj@732
|
1337 {
|
mas01mj@732
|
1338 part = (forDisplay ? this.username : _username);
|
mas01mj@732
|
1339 uri += part;
|
mas01mj@732
|
1340
|
mas01mj@732
|
1341 if (_password.length != 0)
|
mas01mj@732
|
1342 {
|
mas01mj@732
|
1343 part = (forDisplay ? this.password : _password);
|
mas01mj@732
|
1344 uri += ":" + part;
|
mas01mj@732
|
1345 }
|
mas01mj@732
|
1346
|
mas01mj@732
|
1347 uri += "@";
|
mas01mj@732
|
1348 }
|
mas01mj@732
|
1349
|
mas01mj@732
|
1350 // add the authority
|
mas01mj@732
|
1351 part = (forDisplay ? this.authority : _authority);
|
mas01mj@732
|
1352 uri += part;
|
mas01mj@732
|
1353
|
mas01mj@732
|
1354 // Tack on the port number, if any
|
mas01mj@732
|
1355 if (port.length != 0)
|
mas01mj@732
|
1356 uri += ":" + port;
|
mas01mj@732
|
1357 }
|
mas01mj@732
|
1358 }
|
mas01mj@732
|
1359
|
mas01mj@732
|
1360 // Tack on the path
|
mas01mj@732
|
1361 part = (forDisplay ? this.path : _path);
|
mas01mj@732
|
1362 uri += part;
|
mas01mj@732
|
1363
|
mas01mj@732
|
1364 } // end hierarchical part
|
mas01mj@732
|
1365
|
mas01mj@732
|
1366 // Both non-hier and hierarchical have query and fragment parts
|
mas01mj@732
|
1367
|
mas01mj@732
|
1368 // Add on the query and fragment parts
|
mas01mj@732
|
1369 if (_query.length != 0)
|
mas01mj@732
|
1370 {
|
mas01mj@732
|
1371 part = (forDisplay ? this.query : _query);
|
mas01mj@732
|
1372 uri += "?" + part;
|
mas01mj@732
|
1373 }
|
mas01mj@732
|
1374
|
mas01mj@732
|
1375 if (fragment.length != 0)
|
mas01mj@732
|
1376 {
|
mas01mj@732
|
1377 part = (forDisplay ? this.fragment : _fragment);
|
mas01mj@732
|
1378 uri += "#" + part;
|
mas01mj@732
|
1379 }
|
mas01mj@732
|
1380
|
mas01mj@732
|
1381 return uri;
|
mas01mj@732
|
1382 }
|
mas01mj@732
|
1383
|
mas01mj@732
|
1384 /**
|
mas01mj@732
|
1385 * Forcefully ensure that this URI is properly escaped.
|
mas01mj@732
|
1386 *
|
mas01mj@732
|
1387 * <p>Sometimes URI's are constructed by hand using strings outside
|
mas01mj@732
|
1388 * this class. In those cases, it is unlikely the URI has been
|
mas01mj@732
|
1389 * properly escaped. This function forcefully escapes this URI
|
mas01mj@732
|
1390 * by unescaping each part and then re-escaping it. If the URI
|
mas01mj@732
|
1391 * did not have any escaping, the first unescape will do nothing
|
mas01mj@732
|
1392 * and then the re-escape will properly escape everything. If
|
mas01mj@732
|
1393 * the URI was already escaped, the unescape and re-escape will
|
mas01mj@732
|
1394 * essentally be a no-op. This provides a safe way to make sure
|
mas01mj@732
|
1395 * a URI is in the proper escaped form.</p>
|
mas01mj@732
|
1396 */
|
mas01mj@732
|
1397 public function forceEscape() : void
|
mas01mj@732
|
1398 {
|
mas01mj@732
|
1399 // The accessors for each of the members will unescape
|
mas01mj@732
|
1400 // and then re-escape as we get and assign them.
|
mas01mj@732
|
1401
|
mas01mj@732
|
1402 // Handle the parts that are common for both hierarchical
|
mas01mj@732
|
1403 // and non-hierarchical URI's
|
mas01mj@732
|
1404 this.scheme = this.scheme;
|
mas01mj@732
|
1405 this.setQueryByMap(this.getQueryByMap());
|
mas01mj@732
|
1406 this.fragment = this.fragment;
|
mas01mj@732
|
1407
|
mas01mj@732
|
1408 if (isHierarchical())
|
mas01mj@732
|
1409 {
|
mas01mj@732
|
1410 this.authority = this.authority;
|
mas01mj@732
|
1411 this.path = this.path;
|
mas01mj@732
|
1412 this.port = this.port;
|
mas01mj@732
|
1413 this.username = this.username;
|
mas01mj@732
|
1414 this.password = this.password;
|
mas01mj@732
|
1415 }
|
mas01mj@732
|
1416 else
|
mas01mj@732
|
1417 {
|
mas01mj@732
|
1418 this.nonHierarchical = this.nonHierarchical;
|
mas01mj@732
|
1419 }
|
mas01mj@732
|
1420 }
|
mas01mj@732
|
1421
|
mas01mj@732
|
1422
|
mas01mj@732
|
1423 /**
|
mas01mj@732
|
1424 * Does this URI point to a resource of the given file type?
|
mas01mj@732
|
1425 * Given a file extension (or just a file name, this will strip the
|
mas01mj@732
|
1426 * extension), check to see if this URI points to a file of that
|
mas01mj@732
|
1427 * type.
|
mas01mj@732
|
1428 *
|
mas01mj@732
|
1429 * @param extension string that contains a file extension with or
|
mas01mj@732
|
1430 * without a dot ("html" and ".html" are both valid), or a file
|
mas01mj@732
|
1431 * name with an extension (e.g. "index.html").
|
mas01mj@732
|
1432 *
|
mas01mj@732
|
1433 * @return true if this URI points to a resource with the same file
|
mas01mj@732
|
1434 * file extension as the extension provided, false otherwise.
|
mas01mj@732
|
1435 */
|
mas01mj@732
|
1436 public function isOfFileType(extension:String) : Boolean
|
mas01mj@732
|
1437 {
|
mas01mj@732
|
1438 var thisExtension:String;
|
mas01mj@732
|
1439 var index:int;
|
mas01mj@732
|
1440
|
mas01mj@732
|
1441 index = extension.lastIndexOf(".");
|
mas01mj@732
|
1442 if (index != -1)
|
mas01mj@732
|
1443 {
|
mas01mj@732
|
1444 // Strip the extension
|
mas01mj@732
|
1445 extension = extension.substr(index + 1);
|
mas01mj@732
|
1446 }
|
mas01mj@732
|
1447 else
|
mas01mj@732
|
1448 {
|
mas01mj@732
|
1449 // The caller passed something without a dot in it. We
|
mas01mj@732
|
1450 // will assume that it is just a plain extension (e.g. "html").
|
mas01mj@732
|
1451 // What they passed is exactly what we want
|
mas01mj@732
|
1452 }
|
mas01mj@732
|
1453
|
mas01mj@732
|
1454 thisExtension = getExtension(true);
|
mas01mj@732
|
1455
|
mas01mj@732
|
1456 if (thisExtension == "")
|
mas01mj@732
|
1457 return false;
|
mas01mj@732
|
1458
|
mas01mj@732
|
1459 // Compare the extensions ignoring case
|
mas01mj@732
|
1460 if (compareStr(thisExtension, extension, false) == 0)
|
mas01mj@732
|
1461 return true;
|
mas01mj@732
|
1462 else
|
mas01mj@732
|
1463 return false;
|
mas01mj@732
|
1464 }
|
mas01mj@732
|
1465
|
mas01mj@732
|
1466
|
mas01mj@732
|
1467 /**
|
mas01mj@732
|
1468 * Get the ".xyz" file extension from the filename in the URI.
|
mas01mj@732
|
1469 * For example, if we have the following URI:
|
mas01mj@732
|
1470 *
|
mas01mj@732
|
1471 * <listing>http://something.com/path/to/my/page.html?form=yes&name=bob#anchor</listing>
|
mas01mj@732
|
1472 *
|
mas01mj@732
|
1473 * <p>This will return ".html".</p>
|
mas01mj@732
|
1474 *
|
mas01mj@732
|
1475 * @param minusDot If true, this will strip the dot from the extension.
|
mas01mj@732
|
1476 * If true, the above example would have returned "html".
|
mas01mj@732
|
1477 *
|
mas01mj@732
|
1478 * @return the file extension
|
mas01mj@732
|
1479 */
|
mas01mj@732
|
1480 public function getExtension(minusDot:Boolean = false) : String
|
mas01mj@732
|
1481 {
|
mas01mj@732
|
1482 var filename:String = getFilename();
|
mas01mj@732
|
1483 var extension:String;
|
mas01mj@732
|
1484 var index:int;
|
mas01mj@732
|
1485
|
mas01mj@732
|
1486 if (filename == "")
|
mas01mj@732
|
1487 return String("");
|
mas01mj@732
|
1488
|
mas01mj@732
|
1489 index = filename.lastIndexOf(".");
|
mas01mj@732
|
1490
|
mas01mj@732
|
1491 // If it doesn't have an extension, or if it is a "hidden" file,
|
mas01mj@732
|
1492 // it doesn't have an extension. Hidden files on unix start with
|
mas01mj@732
|
1493 // a dot (e.g. ".login").
|
mas01mj@732
|
1494 if (index == -1 || index == 0)
|
mas01mj@732
|
1495 return String("");
|
mas01mj@732
|
1496
|
mas01mj@732
|
1497 extension = filename.substr(index);
|
mas01mj@732
|
1498
|
mas01mj@732
|
1499 // If the caller does not want the dot, remove it.
|
mas01mj@732
|
1500 if (minusDot && extension.charAt(0) == ".")
|
mas01mj@732
|
1501 extension = extension.substr(1);
|
mas01mj@732
|
1502
|
mas01mj@732
|
1503 return extension;
|
mas01mj@732
|
1504 }
|
mas01mj@732
|
1505
|
mas01mj@732
|
1506 /**
|
mas01mj@732
|
1507 * Quick function to retrieve the file name off the end of a URI.
|
mas01mj@732
|
1508 *
|
mas01mj@732
|
1509 * <p>For example, if the URI is:</p>
|
mas01mj@732
|
1510 * <listing>http://something.com/some/path/to/my/file.html</listing>
|
mas01mj@732
|
1511 * <p>this function will return "file.html".</p>
|
mas01mj@732
|
1512 *
|
mas01mj@732
|
1513 * @param minusExtension true if the file extension should be stripped
|
mas01mj@732
|
1514 *
|
mas01mj@732
|
1515 * @return the file name. If this URI is a directory, the return
|
mas01mj@732
|
1516 * value will be empty string.
|
mas01mj@732
|
1517 */
|
mas01mj@732
|
1518 public function getFilename(minusExtension:Boolean = false) : String
|
mas01mj@732
|
1519 {
|
mas01mj@732
|
1520 if (isDirectory())
|
mas01mj@732
|
1521 return String("");
|
mas01mj@732
|
1522
|
mas01mj@732
|
1523 var pathStr:String = this.path;
|
mas01mj@732
|
1524 var filename:String;
|
mas01mj@732
|
1525 var index:int;
|
mas01mj@732
|
1526
|
mas01mj@732
|
1527 // Find the last path separator.
|
mas01mj@732
|
1528 index = pathStr.lastIndexOf("/");
|
mas01mj@732
|
1529
|
mas01mj@732
|
1530 if (index != -1)
|
mas01mj@732
|
1531 filename = pathStr.substr(index + 1);
|
mas01mj@732
|
1532 else
|
mas01mj@732
|
1533 filename = pathStr;
|
mas01mj@732
|
1534
|
mas01mj@732
|
1535 if (minusExtension)
|
mas01mj@732
|
1536 {
|
mas01mj@732
|
1537 // The caller has requested that the extension be removed
|
mas01mj@732
|
1538 index = filename.lastIndexOf(".");
|
mas01mj@732
|
1539
|
mas01mj@732
|
1540 if (index != -1)
|
mas01mj@732
|
1541 filename = filename.substr(0, index);
|
mas01mj@732
|
1542 }
|
mas01mj@732
|
1543
|
mas01mj@732
|
1544 return filename;
|
mas01mj@732
|
1545 }
|
mas01mj@732
|
1546
|
mas01mj@732
|
1547
|
mas01mj@732
|
1548 /**
|
mas01mj@732
|
1549 * @private
|
mas01mj@732
|
1550 * Helper function to compare strings.
|
mas01mj@732
|
1551 *
|
mas01mj@732
|
1552 * @return true if the two strings are identical, false otherwise.
|
mas01mj@732
|
1553 */
|
mas01mj@732
|
1554 static protected function compareStr(str1:String, str2:String,
|
mas01mj@732
|
1555 sensitive:Boolean = true) : Boolean
|
mas01mj@732
|
1556 {
|
mas01mj@732
|
1557 if (sensitive == false)
|
mas01mj@732
|
1558 {
|
mas01mj@732
|
1559 str1 = str1.toLowerCase();
|
mas01mj@732
|
1560 str2 = str2.toLowerCase();
|
mas01mj@732
|
1561 }
|
mas01mj@732
|
1562
|
mas01mj@732
|
1563 return (str1 == str2)
|
mas01mj@732
|
1564 }
|
mas01mj@732
|
1565
|
mas01mj@732
|
1566 /**
|
mas01mj@732
|
1567 * Based on the type of this URI (http, ftp, etc.) get
|
mas01mj@732
|
1568 * the default port used for that protocol. This is
|
mas01mj@732
|
1569 * just intended to be a helper function for the most
|
mas01mj@732
|
1570 * common cases.
|
mas01mj@732
|
1571 */
|
mas01mj@732
|
1572 public function getDefaultPort() : String
|
mas01mj@732
|
1573 {
|
mas01mj@732
|
1574 if (_scheme == "http")
|
mas01mj@732
|
1575 return String("80");
|
mas01mj@732
|
1576 else if (_scheme == "ftp")
|
mas01mj@732
|
1577 return String("21");
|
mas01mj@732
|
1578 else if (_scheme == "file")
|
mas01mj@732
|
1579 return String("");
|
mas01mj@732
|
1580 else if (_scheme == "sftp")
|
mas01mj@732
|
1581 return String("22"); // ssh standard port
|
mas01mj@732
|
1582 else
|
mas01mj@732
|
1583 {
|
mas01mj@732
|
1584 // Don't know the port for this URI type
|
mas01mj@732
|
1585 return String("");
|
mas01mj@732
|
1586 }
|
mas01mj@732
|
1587 }
|
mas01mj@732
|
1588
|
mas01mj@732
|
1589 /**
|
mas01mj@732
|
1590 * @private
|
mas01mj@732
|
1591 *
|
mas01mj@732
|
1592 * This resolves the given URI if the application has a
|
mas01mj@732
|
1593 * resolver interface defined. This function does not
|
mas01mj@732
|
1594 * modify the passed in URI and returns a new URI.
|
mas01mj@732
|
1595 */
|
mas01mj@732
|
1596 static protected function resolve(uri:URI) : URI
|
mas01mj@732
|
1597 {
|
mas01mj@732
|
1598 var copy:URI = new URI();
|
mas01mj@732
|
1599 copy.copyURI(uri);
|
mas01mj@732
|
1600
|
mas01mj@732
|
1601 if (_resolver != null)
|
mas01mj@732
|
1602 {
|
mas01mj@732
|
1603 // A resolver class has been registered. Call it.
|
mas01mj@732
|
1604 return _resolver.resolve(copy);
|
mas01mj@732
|
1605 }
|
mas01mj@732
|
1606 else
|
mas01mj@732
|
1607 {
|
mas01mj@732
|
1608 // No resolver. Nothing to do, but we don't
|
mas01mj@732
|
1609 // want to reuse the one passed in.
|
mas01mj@732
|
1610 return copy;
|
mas01mj@732
|
1611 }
|
mas01mj@732
|
1612 }
|
mas01mj@732
|
1613
|
mas01mj@732
|
1614 /**
|
mas01mj@732
|
1615 * Accessor to set and get the resolver object used by all URI
|
mas01mj@732
|
1616 * objects to dynamically resolve URI's before comparison.
|
mas01mj@732
|
1617 */
|
mas01mj@732
|
1618 static public function set resolver(resolver:IURIResolver) : void
|
mas01mj@732
|
1619 {
|
mas01mj@732
|
1620 _resolver = resolver;
|
mas01mj@732
|
1621 }
|
mas01mj@732
|
1622 static public function get resolver() : IURIResolver
|
mas01mj@732
|
1623 {
|
mas01mj@732
|
1624 return _resolver;
|
mas01mj@732
|
1625 }
|
mas01mj@732
|
1626
|
mas01mj@732
|
1627 /**
|
mas01mj@732
|
1628 * Given another URI, return this URI object's relation to the one given.
|
mas01mj@732
|
1629 * URI's can have 1 of 4 possible relationships. They can be unrelated,
|
mas01mj@732
|
1630 * equal, parent, or a child of the given URI.
|
mas01mj@732
|
1631 *
|
mas01mj@732
|
1632 * @param uri URI to compare this URI object to.
|
mas01mj@732
|
1633 * @param caseSensitive true if the URI comparison should be done
|
mas01mj@732
|
1634 * taking case into account, false if the comparison should be
|
mas01mj@732
|
1635 * performed case insensitive.
|
mas01mj@732
|
1636 *
|
mas01mj@732
|
1637 * @return URI.NOT_RELATED, URI.CHILD, URI.PARENT, or URI.EQUAL
|
mas01mj@732
|
1638 */
|
mas01mj@732
|
1639 public function getRelation(uri:URI, caseSensitive:Boolean = true) : int
|
mas01mj@732
|
1640 {
|
mas01mj@732
|
1641 // Give the app a chance to resolve these URI's before we compare them.
|
mas01mj@732
|
1642 var thisURI:URI = URI.resolve(this);
|
mas01mj@732
|
1643 var thatURI:URI = URI.resolve(uri);
|
mas01mj@732
|
1644
|
mas01mj@732
|
1645 if (thisURI.isRelative() || thatURI.isRelative())
|
mas01mj@732
|
1646 {
|
mas01mj@732
|
1647 // You cannot compare relative URI's due to their lack of context.
|
mas01mj@732
|
1648 // You could have two relative URI's that look like:
|
mas01mj@732
|
1649 // ../../images/
|
mas01mj@732
|
1650 // ../../images/marketing/logo.gif
|
mas01mj@732
|
1651 // These may appear related, but you have no overall context
|
mas01mj@732
|
1652 // from which to make the comparison. The first URI could be
|
mas01mj@732
|
1653 // from one site and the other URI could be from another site.
|
mas01mj@732
|
1654 return URI.NOT_RELATED;
|
mas01mj@732
|
1655 }
|
mas01mj@732
|
1656 else if (thisURI.isHierarchical() == false || thatURI.isHierarchical() == false)
|
mas01mj@732
|
1657 {
|
mas01mj@732
|
1658 // One or both of the URI's are non-hierarchical.
|
mas01mj@732
|
1659 if (((thisURI.isHierarchical() == false) && (thatURI.isHierarchical() == true)) ||
|
mas01mj@732
|
1660 ((thisURI.isHierarchical() == true) && (thatURI.isHierarchical() == false)))
|
mas01mj@732
|
1661 {
|
mas01mj@732
|
1662 // XOR. One is hierarchical and the other is
|
mas01mj@732
|
1663 // non-hierarchical. They cannot be compared.
|
mas01mj@732
|
1664 return URI.NOT_RELATED;
|
mas01mj@732
|
1665 }
|
mas01mj@732
|
1666 else
|
mas01mj@732
|
1667 {
|
mas01mj@732
|
1668 // They are both non-hierarchical
|
mas01mj@732
|
1669 if (thisURI.scheme != thatURI.scheme)
|
mas01mj@732
|
1670 return URI.NOT_RELATED;
|
mas01mj@732
|
1671
|
mas01mj@732
|
1672 if (thisURI.nonHierarchical != thatURI.nonHierarchical)
|
mas01mj@732
|
1673 return URI.NOT_RELATED;
|
mas01mj@732
|
1674
|
mas01mj@732
|
1675 // The two non-hierarcical URI's are equal.
|
mas01mj@732
|
1676 return URI.EQUAL;
|
mas01mj@732
|
1677 }
|
mas01mj@732
|
1678 }
|
mas01mj@732
|
1679
|
mas01mj@732
|
1680 // Ok, this URI and the one we are being compared to are both
|
mas01mj@732
|
1681 // absolute hierarchical URI's.
|
mas01mj@732
|
1682
|
mas01mj@732
|
1683 if (thisURI.scheme != thatURI.scheme)
|
mas01mj@732
|
1684 return URI.NOT_RELATED;
|
mas01mj@732
|
1685
|
mas01mj@732
|
1686 if (thisURI.authority != thatURI.authority)
|
mas01mj@732
|
1687 return URI.NOT_RELATED;
|
mas01mj@732
|
1688
|
mas01mj@732
|
1689 var thisPort:String = thisURI.port;
|
mas01mj@732
|
1690 var thatPort:String = thatURI.port;
|
mas01mj@732
|
1691
|
mas01mj@732
|
1692 // Different ports are considered completely different servers.
|
mas01mj@732
|
1693 if (thisPort == "")
|
mas01mj@732
|
1694 thisPort = thisURI.getDefaultPort();
|
mas01mj@732
|
1695 if (thatPort == "")
|
mas01mj@732
|
1696 thatPort = thatURI.getDefaultPort();
|
mas01mj@732
|
1697
|
mas01mj@732
|
1698 // Check to see if the port is the default port.
|
mas01mj@732
|
1699 if (thisPort != thatPort)
|
mas01mj@732
|
1700 return URI.NOT_RELATED;
|
mas01mj@732
|
1701
|
mas01mj@732
|
1702 if (compareStr(thisURI.path, thatURI.path, caseSensitive))
|
mas01mj@732
|
1703 return URI.EQUAL;
|
mas01mj@732
|
1704
|
mas01mj@732
|
1705 // Special case check. If we are here, the scheme, authority,
|
mas01mj@732
|
1706 // and port match, and it is not a relative path, but the
|
mas01mj@732
|
1707 // paths did not match. There is a special case where we
|
mas01mj@732
|
1708 // could have:
|
mas01mj@732
|
1709 // http://something.com/
|
mas01mj@732
|
1710 // http://something.com
|
mas01mj@732
|
1711 // Technically, these are equal. So lets, check for this case.
|
mas01mj@732
|
1712 var thisPath:String = thisURI.path;
|
mas01mj@732
|
1713 var thatPath:String = thatURI.path;
|
mas01mj@732
|
1714
|
mas01mj@732
|
1715 if ( (thisPath == "/" || thatPath == "/") &&
|
mas01mj@732
|
1716 (thisPath == "" || thatPath == "") )
|
mas01mj@732
|
1717 {
|
mas01mj@732
|
1718 // We hit the special case. These two are equal.
|
mas01mj@732
|
1719 return URI.EQUAL;
|
mas01mj@732
|
1720 }
|
mas01mj@732
|
1721
|
mas01mj@732
|
1722 // Ok, the paths do not match, but one path may be a parent/child
|
mas01mj@732
|
1723 // of the other. For example, we may have:
|
mas01mj@732
|
1724 // http://something.com/path/to/homepage/
|
mas01mj@732
|
1725 // http://something.com/path/to/homepage/images/logo.gif
|
mas01mj@732
|
1726 // In this case, the first is a parent of the second (or the second
|
mas01mj@732
|
1727 // is a child of the first, depending on which you compare to the
|
mas01mj@732
|
1728 // other). To make this comparison, we must split the path into
|
mas01mj@732
|
1729 // its component parts (split the string on the '/' path delimiter).
|
mas01mj@732
|
1730 // We then compare the
|
mas01mj@732
|
1731 var thisParts:Array, thatParts:Array;
|
mas01mj@732
|
1732 var thisPart:String, thatPart:String;
|
mas01mj@732
|
1733 var i:int;
|
mas01mj@732
|
1734
|
mas01mj@732
|
1735 thisParts = thisPath.split("/");
|
mas01mj@732
|
1736 thatParts = thatPath.split("/");
|
mas01mj@732
|
1737
|
mas01mj@732
|
1738 if (thisParts.length > thatParts.length)
|
mas01mj@732
|
1739 {
|
mas01mj@732
|
1740 thatPart = thatParts[thatParts.length - 1];
|
mas01mj@732
|
1741 if (thatPart.length > 0)
|
mas01mj@732
|
1742 {
|
mas01mj@732
|
1743 // if the last part is not empty, the passed URI is
|
mas01mj@732
|
1744 // not a directory. There is no way the passed URI
|
mas01mj@732
|
1745 // can be a parent.
|
mas01mj@732
|
1746 return URI.NOT_RELATED;
|
mas01mj@732
|
1747 }
|
mas01mj@732
|
1748 else
|
mas01mj@732
|
1749 {
|
mas01mj@732
|
1750 // Remove the empty trailing part
|
mas01mj@732
|
1751 thatParts.pop();
|
mas01mj@732
|
1752 }
|
mas01mj@732
|
1753
|
mas01mj@732
|
1754 // This may be a child of the one passed in
|
mas01mj@732
|
1755 for (i = 0; i < thatParts.length; i++)
|
mas01mj@732
|
1756 {
|
mas01mj@732
|
1757 thisPart = thisParts[i];
|
mas01mj@732
|
1758 thatPart = thatParts[i];
|
mas01mj@732
|
1759
|
mas01mj@732
|
1760 if (compareStr(thisPart, thatPart, caseSensitive) == false)
|
mas01mj@732
|
1761 return URI.NOT_RELATED;
|
mas01mj@732
|
1762 }
|
mas01mj@732
|
1763
|
mas01mj@732
|
1764 return URI.CHILD;
|
mas01mj@732
|
1765 }
|
mas01mj@732
|
1766 else if (thisParts.length < thatParts.length)
|
mas01mj@732
|
1767 {
|
mas01mj@732
|
1768 thisPart = thisParts[thisParts.length - 1];
|
mas01mj@732
|
1769 if (thisPart.length > 0)
|
mas01mj@732
|
1770 {
|
mas01mj@732
|
1771 // if the last part is not empty, this URI is not a
|
mas01mj@732
|
1772 // directory. There is no way this object can be
|
mas01mj@732
|
1773 // a parent.
|
mas01mj@732
|
1774 return URI.NOT_RELATED;
|
mas01mj@732
|
1775 }
|
mas01mj@732
|
1776 else
|
mas01mj@732
|
1777 {
|
mas01mj@732
|
1778 // Remove the empty trailing part
|
mas01mj@732
|
1779 thisParts.pop();
|
mas01mj@732
|
1780 }
|
mas01mj@732
|
1781
|
mas01mj@732
|
1782 // This may be the parent of the one passed in
|
mas01mj@732
|
1783 for (i = 0; i < thisParts.length; i++)
|
mas01mj@732
|
1784 {
|
mas01mj@732
|
1785 thisPart = thisParts[i];
|
mas01mj@732
|
1786 thatPart = thatParts[i];
|
mas01mj@732
|
1787
|
mas01mj@732
|
1788 if (compareStr(thisPart, thatPart, caseSensitive) == false)
|
mas01mj@732
|
1789 return URI.NOT_RELATED;
|
mas01mj@732
|
1790 }
|
mas01mj@732
|
1791
|
mas01mj@732
|
1792 return URI.PARENT;
|
mas01mj@732
|
1793 }
|
mas01mj@732
|
1794 else
|
mas01mj@732
|
1795 {
|
mas01mj@732
|
1796 // Both URI's have the same number of path components, but
|
mas01mj@732
|
1797 // it failed the equivelence check above. This means that
|
mas01mj@732
|
1798 // the two URI's are not related.
|
mas01mj@732
|
1799 return URI.NOT_RELATED;
|
mas01mj@732
|
1800 }
|
mas01mj@732
|
1801
|
mas01mj@732
|
1802 // If we got here, the scheme and authority are the same,
|
mas01mj@732
|
1803 // but the paths pointed to two different locations that
|
mas01mj@732
|
1804 // were in different parts of the file system tree
|
mas01mj@732
|
1805 return URI.NOT_RELATED;
|
mas01mj@732
|
1806 }
|
mas01mj@732
|
1807
|
mas01mj@732
|
1808 /**
|
mas01mj@732
|
1809 * Given another URI, return the common parent between this one
|
mas01mj@732
|
1810 * and the provided URI.
|
mas01mj@732
|
1811 *
|
mas01mj@732
|
1812 * @param uri the other URI from which to find a common parent
|
mas01mj@732
|
1813 * @para caseSensitive true if this operation should be done
|
mas01mj@732
|
1814 * with case sensitive comparisons.
|
mas01mj@732
|
1815 *
|
mas01mj@732
|
1816 * @return the parent URI if successful, null otherwise.
|
mas01mj@732
|
1817 */
|
mas01mj@732
|
1818 public function getCommonParent(uri:URI, caseSensitive:Boolean = true) : URI
|
mas01mj@732
|
1819 {
|
mas01mj@732
|
1820 var thisURI:URI = URI.resolve(this);
|
mas01mj@732
|
1821 var thatURI:URI = URI.resolve(uri);
|
mas01mj@732
|
1822
|
mas01mj@732
|
1823 if(!thisURI.isAbsolute() || !thatURI.isAbsolute() ||
|
mas01mj@732
|
1824 thisURI.isHierarchical() == false ||
|
mas01mj@732
|
1825 thatURI.isHierarchical() == false)
|
mas01mj@732
|
1826 {
|
mas01mj@732
|
1827 // Both URI's must be absolute hierarchical for this to
|
mas01mj@732
|
1828 // make sense.
|
mas01mj@732
|
1829 return null;
|
mas01mj@732
|
1830 }
|
mas01mj@732
|
1831
|
mas01mj@732
|
1832 var relation:int = thisURI.getRelation(thatURI);
|
mas01mj@732
|
1833 if (relation == URI.NOT_RELATED)
|
mas01mj@732
|
1834 {
|
mas01mj@732
|
1835 // The given URI is not related to this one. No
|
mas01mj@732
|
1836 // common parent.
|
mas01mj@732
|
1837 return null;
|
mas01mj@732
|
1838 }
|
mas01mj@732
|
1839
|
mas01mj@732
|
1840 thisURI.chdir(".");
|
mas01mj@732
|
1841 thatURI.chdir(".");
|
mas01mj@732
|
1842
|
mas01mj@732
|
1843 var strBefore:String, strAfter:String;
|
mas01mj@732
|
1844 do
|
mas01mj@732
|
1845 {
|
mas01mj@732
|
1846 relation = thisURI.getRelation(thatURI, caseSensitive);
|
mas01mj@732
|
1847 if(relation == URI.EQUAL || relation == URI.PARENT)
|
mas01mj@732
|
1848 break;
|
mas01mj@732
|
1849
|
mas01mj@732
|
1850 // If strBefore and strAfter end up being the same,
|
mas01mj@732
|
1851 // we know we are at the root of the path because
|
mas01mj@732
|
1852 // chdir("..") is doing nothing.
|
mas01mj@732
|
1853 strBefore = thisURI.toString();
|
mas01mj@732
|
1854 thisURI.chdir("..");
|
mas01mj@732
|
1855 strAfter = thisURI.toString();
|
mas01mj@732
|
1856 }
|
mas01mj@732
|
1857 while(strBefore != strAfter);
|
mas01mj@732
|
1858
|
mas01mj@732
|
1859 return thisURI;
|
mas01mj@732
|
1860 }
|
mas01mj@732
|
1861
|
mas01mj@732
|
1862
|
mas01mj@732
|
1863 /**
|
mas01mj@732
|
1864 * This function is used to move around in a URI in a way similar
|
mas01mj@732
|
1865 * to the 'cd' or 'chdir' commands on Unix. These operations are
|
mas01mj@732
|
1866 * completely string based, using the context of the URI to
|
mas01mj@732
|
1867 * determine the position within the path. The heuristics used
|
mas01mj@732
|
1868 * to determine the action are based off Appendix C in RFC 2396.
|
mas01mj@732
|
1869 *
|
mas01mj@732
|
1870 * <p>URI paths that end in '/' are considered paths that point to
|
mas01mj@732
|
1871 * directories, while paths that do not end in '/' are files. For
|
mas01mj@732
|
1872 * example, if you execute chdir("d") on the following URI's:<br/>
|
mas01mj@732
|
1873 * 1. http://something.com/a/b/c/ (directory)<br/>
|
mas01mj@732
|
1874 * 2. http://something.com/a/b/c (not directory)<br/>
|
mas01mj@732
|
1875 * you will get:<br/>
|
mas01mj@732
|
1876 * 1. http://something.com/a/b/c/d<br/>
|
mas01mj@732
|
1877 * 2. http://something.com/a/b/d<br/></p>
|
mas01mj@732
|
1878 *
|
mas01mj@732
|
1879 * <p>See RFC 2396, Appendix C for more info.</p>
|
mas01mj@732
|
1880 *
|
mas01mj@732
|
1881 * @param reference the URI or path to "cd" to.
|
mas01mj@732
|
1882 * @param escape true if the passed reference string should be URI
|
mas01mj@732
|
1883 * escaped before using it.
|
mas01mj@732
|
1884 *
|
mas01mj@732
|
1885 * @return true if the chdir was successful, false otherwise.
|
mas01mj@732
|
1886 */
|
mas01mj@732
|
1887 public function chdir(reference:String, escape:Boolean = false) : Boolean
|
mas01mj@732
|
1888 {
|
mas01mj@732
|
1889 var uriReference:URI;
|
mas01mj@732
|
1890 var ref:String = reference;
|
mas01mj@732
|
1891
|
mas01mj@732
|
1892 if (escape)
|
mas01mj@732
|
1893 ref = URI.escapeChars(reference);
|
mas01mj@732
|
1894
|
mas01mj@732
|
1895 if (ref == "")
|
mas01mj@732
|
1896 {
|
mas01mj@732
|
1897 // NOOP
|
mas01mj@732
|
1898 return true;
|
mas01mj@732
|
1899 }
|
mas01mj@732
|
1900 else if (ref.substr(0, 2) == "//")
|
mas01mj@732
|
1901 {
|
mas01mj@732
|
1902 // Special case. This is an absolute URI but without the scheme.
|
mas01mj@732
|
1903 // Take the scheme from this URI and tack it on. This is
|
mas01mj@732
|
1904 // intended to make working with chdir() a little more
|
mas01mj@732
|
1905 // tolerant.
|
mas01mj@732
|
1906 var f:String = this.scheme + ":" + ref;
|
mas01mj@732
|
1907
|
mas01mj@732
|
1908 return constructURI(f);
|
mas01mj@732
|
1909 }
|
mas01mj@732
|
1910 else if (ref.charAt(0) == "?")
|
mas01mj@732
|
1911 {
|
mas01mj@732
|
1912 // A relative URI that is just a query part is essentially
|
mas01mj@732
|
1913 // a "./?query". We tack on the "./" here to make the rest
|
mas01mj@732
|
1914 // of our logic work.
|
mas01mj@732
|
1915 ref = "./" + ref;
|
mas01mj@732
|
1916 }
|
mas01mj@732
|
1917
|
mas01mj@732
|
1918 // Parse the reference passed in as a URI. This way we
|
mas01mj@732
|
1919 // get any query and fragments parsed out as well.
|
mas01mj@732
|
1920 uriReference = new URI(ref);
|
mas01mj@732
|
1921
|
mas01mj@732
|
1922 if (uriReference.isAbsolute() ||
|
mas01mj@732
|
1923 uriReference.isHierarchical() == false)
|
mas01mj@732
|
1924 {
|
mas01mj@732
|
1925 // If the URI given is a full URI, it replaces this one.
|
mas01mj@732
|
1926 copyURI(uriReference);
|
mas01mj@732
|
1927 return true;
|
mas01mj@732
|
1928 }
|
mas01mj@732
|
1929
|
mas01mj@732
|
1930
|
mas01mj@732
|
1931 var thisPath:String, thatPath:String;
|
mas01mj@732
|
1932 var thisParts:Array, thatParts:Array;
|
mas01mj@732
|
1933 var thisIsDir:Boolean = false, thatIsDir:Boolean = false;
|
mas01mj@732
|
1934 var thisIsAbs:Boolean = false, thatIsAbs:Boolean = false;
|
mas01mj@732
|
1935 var lastIsDotOperation:Boolean = false;
|
mas01mj@732
|
1936 var curDir:String;
|
mas01mj@732
|
1937 var i:int;
|
mas01mj@732
|
1938
|
mas01mj@732
|
1939 thisPath = this.path;
|
mas01mj@732
|
1940 thatPath = uriReference.path;
|
mas01mj@732
|
1941
|
mas01mj@732
|
1942 if (thisPath.length > 0)
|
mas01mj@732
|
1943 thisParts = thisPath.split("/");
|
mas01mj@732
|
1944 else
|
mas01mj@732
|
1945 thisParts = new Array();
|
mas01mj@732
|
1946
|
mas01mj@732
|
1947 if (thatPath.length > 0)
|
mas01mj@732
|
1948 thatParts = thatPath.split("/");
|
mas01mj@732
|
1949 else
|
mas01mj@732
|
1950 thatParts = new Array();
|
mas01mj@732
|
1951
|
mas01mj@732
|
1952 if (thisParts.length > 0 && thisParts[0] == "")
|
mas01mj@732
|
1953 {
|
mas01mj@732
|
1954 thisIsAbs = true;
|
mas01mj@732
|
1955 thisParts.shift(); // pop the first one off the array
|
mas01mj@732
|
1956 }
|
mas01mj@732
|
1957 if (thisParts.length > 0 && thisParts[thisParts.length - 1] == "")
|
mas01mj@732
|
1958 {
|
mas01mj@732
|
1959 thisIsDir = true;
|
mas01mj@732
|
1960 thisParts.pop(); // pop the last one off the array
|
mas01mj@732
|
1961 }
|
mas01mj@732
|
1962
|
mas01mj@732
|
1963 if (thatParts.length > 0 && thatParts[0] == "")
|
mas01mj@732
|
1964 {
|
mas01mj@732
|
1965 thatIsAbs = true;
|
mas01mj@732
|
1966 thatParts.shift(); // pop the first one off the array
|
mas01mj@732
|
1967 }
|
mas01mj@732
|
1968 if (thatParts.length > 0 && thatParts[thatParts.length - 1] == "")
|
mas01mj@732
|
1969 {
|
mas01mj@732
|
1970 thatIsDir = true;
|
mas01mj@732
|
1971 thatParts.pop(); // pop the last one off the array
|
mas01mj@732
|
1972 }
|
mas01mj@732
|
1973
|
mas01mj@732
|
1974 if (thatIsAbs)
|
mas01mj@732
|
1975 {
|
mas01mj@732
|
1976 // The reference is an absolute path (starts with a slash).
|
mas01mj@732
|
1977 // It replaces this path wholesale.
|
mas01mj@732
|
1978 this.path = uriReference.path;
|
mas01mj@732
|
1979
|
mas01mj@732
|
1980 // And it inherits the query and fragment
|
mas01mj@732
|
1981 this.queryRaw = uriReference.queryRaw;
|
mas01mj@732
|
1982 this.fragment = uriReference.fragment;
|
mas01mj@732
|
1983
|
mas01mj@732
|
1984 return true;
|
mas01mj@732
|
1985 }
|
mas01mj@732
|
1986 else if (thatParts.length == 0 && uriReference.query == "")
|
mas01mj@732
|
1987 {
|
mas01mj@732
|
1988 // The reference must have only been a fragment. Fragments just
|
mas01mj@732
|
1989 // get appended to whatever the current path is. We don't want
|
mas01mj@732
|
1990 // to overwrite any query that may already exist, so this case
|
mas01mj@732
|
1991 // only takes on the new fragment.
|
mas01mj@732
|
1992 this.fragment = uriReference.fragment;
|
mas01mj@732
|
1993 return true;
|
mas01mj@732
|
1994 }
|
mas01mj@732
|
1995 else if (thisIsDir == false && thisParts.length > 0)
|
mas01mj@732
|
1996 {
|
mas01mj@732
|
1997 // This path ends in a file. It goes away no matter what.
|
mas01mj@732
|
1998 thisParts.pop();
|
mas01mj@732
|
1999 }
|
mas01mj@732
|
2000
|
mas01mj@732
|
2001 // By default, this assumes the query and fragment of the reference
|
mas01mj@732
|
2002 this.queryRaw = uriReference.queryRaw;
|
mas01mj@732
|
2003 this.fragment = uriReference.fragment;
|
mas01mj@732
|
2004
|
mas01mj@732
|
2005 // Append the parts of the path from the passed in reference
|
mas01mj@732
|
2006 // to this object's path.
|
mas01mj@732
|
2007 thisParts = thisParts.concat(thatParts);
|
mas01mj@732
|
2008
|
mas01mj@732
|
2009 for(i = 0; i < thisParts.length; i++)
|
mas01mj@732
|
2010 {
|
mas01mj@732
|
2011 curDir = thisParts[i];
|
mas01mj@732
|
2012 lastIsDotOperation = false;
|
mas01mj@732
|
2013
|
mas01mj@732
|
2014 if (curDir == ".")
|
mas01mj@732
|
2015 {
|
mas01mj@732
|
2016 thisParts.splice(i, 1);
|
mas01mj@732
|
2017 i = i - 1; // account for removing this item
|
mas01mj@732
|
2018 lastIsDotOperation = true;
|
mas01mj@732
|
2019 }
|
mas01mj@732
|
2020 else if (curDir == "..")
|
mas01mj@732
|
2021 {
|
mas01mj@732
|
2022 if (i >= 1)
|
mas01mj@732
|
2023 {
|
mas01mj@732
|
2024 if (thisParts[i - 1] == "..")
|
mas01mj@732
|
2025 {
|
mas01mj@732
|
2026 // If the previous is a "..", we must have skipped
|
mas01mj@732
|
2027 // it due to this URI being relative. We can't
|
mas01mj@732
|
2028 // collapse leading ".."s in a relative URI, so
|
mas01mj@732
|
2029 // do nothing.
|
mas01mj@732
|
2030 }
|
mas01mj@732
|
2031 else
|
mas01mj@732
|
2032 {
|
mas01mj@732
|
2033 thisParts.splice(i - 1, 2);
|
mas01mj@732
|
2034 i = i - 2; // move back to account for the 2 we removed
|
mas01mj@732
|
2035 }
|
mas01mj@732
|
2036 }
|
mas01mj@732
|
2037 else
|
mas01mj@732
|
2038 {
|
mas01mj@732
|
2039 // This is the first thing in the path.
|
mas01mj@732
|
2040
|
mas01mj@732
|
2041 if (isRelative())
|
mas01mj@732
|
2042 {
|
mas01mj@732
|
2043 // We can't collapse leading ".."s in a relative
|
mas01mj@732
|
2044 // path. Do noting.
|
mas01mj@732
|
2045 }
|
mas01mj@732
|
2046 else
|
mas01mj@732
|
2047 {
|
mas01mj@732
|
2048 // This is an abnormal case. We have dot-dotted up
|
mas01mj@732
|
2049 // past the base of our "file system". This is a
|
mas01mj@732
|
2050 // case where we had a /path/like/this.htm and were
|
mas01mj@732
|
2051 // given a path to chdir to like this:
|
mas01mj@732
|
2052 // ../../../../../../mydir
|
mas01mj@732
|
2053 // Obviously, it has too many ".." and will take us
|
mas01mj@732
|
2054 // up beyond the top of the URI. However, according
|
mas01mj@732
|
2055 // RFC 2396 Appendix C.2, we should try to handle
|
mas01mj@732
|
2056 // these abnormal cases appropriately. In this case,
|
mas01mj@732
|
2057 // we will do what UNIX command lines do if you are
|
mas01mj@732
|
2058 // at the root (/) of the filesystem and execute:
|
mas01mj@732
|
2059 // # cd ../../../../../bin
|
mas01mj@732
|
2060 // Which will put you in /bin. Essentially, the extra
|
mas01mj@732
|
2061 // ".."'s will just get eaten.
|
mas01mj@732
|
2062
|
mas01mj@732
|
2063 thisParts.splice(i, 1);
|
mas01mj@732
|
2064 i = i - 1; // account for the ".." we just removed
|
mas01mj@732
|
2065 }
|
mas01mj@732
|
2066 }
|
mas01mj@732
|
2067
|
mas01mj@732
|
2068 lastIsDotOperation = true;
|
mas01mj@732
|
2069 }
|
mas01mj@732
|
2070 }
|
mas01mj@732
|
2071
|
mas01mj@732
|
2072 var finalPath:String = "";
|
mas01mj@732
|
2073
|
mas01mj@732
|
2074 // If the last thing in the path was a "." or "..", then this thing is a
|
mas01mj@732
|
2075 // directory. If the last thing isn't a dot-op, then we don't want to
|
mas01mj@732
|
2076 // blow away any information about the directory (hence the "|=" binary
|
mas01mj@732
|
2077 // assignment).
|
mas01mj@732
|
2078 thatIsDir = thatIsDir || lastIsDotOperation;
|
mas01mj@732
|
2079
|
mas01mj@732
|
2080 // Reconstruct the path with the abs/dir info we have
|
mas01mj@732
|
2081 finalPath = joinPath(thisParts, thisIsAbs, thatIsDir);
|
mas01mj@732
|
2082
|
mas01mj@732
|
2083 // Set the path (automatically escaping it)
|
mas01mj@732
|
2084 this.path = finalPath;
|
mas01mj@732
|
2085
|
mas01mj@732
|
2086 return true;
|
mas01mj@732
|
2087 }
|
mas01mj@732
|
2088
|
mas01mj@732
|
2089 /**
|
mas01mj@732
|
2090 * @private
|
mas01mj@732
|
2091 * Join an array of path parts back into a URI style path string.
|
mas01mj@732
|
2092 * This is used by the various path logic functions to recombine
|
mas01mj@732
|
2093 * a path. This is different than the standard Array.join()
|
mas01mj@732
|
2094 * function because we need to take into account the starting and
|
mas01mj@732
|
2095 * ending path delimiters if this is an absolute path or a
|
mas01mj@732
|
2096 * directory.
|
mas01mj@732
|
2097 *
|
mas01mj@732
|
2098 * @param parts the Array that contains strings of each path part.
|
mas01mj@732
|
2099 * @param isAbs true if the given path is absolute
|
mas01mj@732
|
2100 * @param isDir true if the given path is a directory
|
mas01mj@732
|
2101 *
|
mas01mj@732
|
2102 * @return the combined path string.
|
mas01mj@732
|
2103 */
|
mas01mj@732
|
2104 protected function joinPath(parts:Array, isAbs:Boolean, isDir:Boolean) : String
|
mas01mj@732
|
2105 {
|
mas01mj@732
|
2106 var pathStr:String = "";
|
mas01mj@732
|
2107 var i:int;
|
mas01mj@732
|
2108
|
mas01mj@732
|
2109 for (i = 0; i < parts.length; i++)
|
mas01mj@732
|
2110 {
|
mas01mj@732
|
2111 if (pathStr.length > 0)
|
mas01mj@732
|
2112 pathStr += "/";
|
mas01mj@732
|
2113
|
mas01mj@732
|
2114 pathStr += parts[i];
|
mas01mj@732
|
2115 }
|
mas01mj@732
|
2116
|
mas01mj@732
|
2117 // If this path is a directory, tack on the directory delimiter,
|
mas01mj@732
|
2118 // but only if the path contains something. Adding this to an
|
mas01mj@732
|
2119 // empty path would make it "/", which is an absolute path that
|
mas01mj@732
|
2120 // starts at the root.
|
mas01mj@732
|
2121 if (isDir && pathStr.length > 0)
|
mas01mj@732
|
2122 pathStr += "/";
|
mas01mj@732
|
2123
|
mas01mj@732
|
2124 if (isAbs)
|
mas01mj@732
|
2125 pathStr = "/" + pathStr;
|
mas01mj@732
|
2126
|
mas01mj@732
|
2127 return pathStr;
|
mas01mj@732
|
2128 }
|
mas01mj@732
|
2129
|
mas01mj@732
|
2130 /**
|
mas01mj@732
|
2131 * Given an absolute URI, make this relative URI absolute using
|
mas01mj@732
|
2132 * the given URI as a base. This URI instance must be relative
|
mas01mj@732
|
2133 * and the base_uri must be absolute.
|
mas01mj@732
|
2134 *
|
mas01mj@732
|
2135 * @param base_uri URI to use as the base from which to make
|
mas01mj@732
|
2136 * this relative URI into an absolute URI.
|
mas01mj@732
|
2137 *
|
mas01mj@732
|
2138 * @return true if successful, false otherwise.
|
mas01mj@732
|
2139 */
|
mas01mj@732
|
2140 public function makeAbsoluteURI(base_uri:URI) : Boolean
|
mas01mj@732
|
2141 {
|
mas01mj@732
|
2142 if (isAbsolute() || base_uri.isRelative())
|
mas01mj@732
|
2143 {
|
mas01mj@732
|
2144 // This URI needs to be relative, and the base needs to be
|
mas01mj@732
|
2145 // absolute otherwise we won't know what to do!
|
mas01mj@732
|
2146 return false;
|
mas01mj@732
|
2147 }
|
mas01mj@732
|
2148
|
mas01mj@732
|
2149 // Make a copy of the base URI. We don't want to modify
|
mas01mj@732
|
2150 // the passed URI.
|
mas01mj@732
|
2151 var base:URI = new URI();
|
mas01mj@732
|
2152 base.copyURI(base_uri);
|
mas01mj@732
|
2153
|
mas01mj@732
|
2154 // ChDir on the base URI. This will preserve any query
|
mas01mj@732
|
2155 // and fragment we have.
|
mas01mj@732
|
2156 if (base.chdir(toString()) == false)
|
mas01mj@732
|
2157 return false;
|
mas01mj@732
|
2158
|
mas01mj@732
|
2159 // It worked, so copy the base into this one
|
mas01mj@732
|
2160 copyURI(base);
|
mas01mj@732
|
2161
|
mas01mj@732
|
2162 return true;
|
mas01mj@732
|
2163 }
|
mas01mj@732
|
2164
|
mas01mj@732
|
2165
|
mas01mj@732
|
2166 /**
|
mas01mj@732
|
2167 * Given a URI to use as a base from which this object should be
|
mas01mj@732
|
2168 * relative to, convert this object into a relative URI. For example,
|
mas01mj@732
|
2169 * if you have:
|
mas01mj@732
|
2170 *
|
mas01mj@732
|
2171 * <listing>
|
mas01mj@732
|
2172 * var uri1:URI = new URI("http://something.com/path/to/some/file.html");
|
mas01mj@732
|
2173 * var uri2:URI = new URI("http://something.com/path/to/another/file.html");
|
mas01mj@732
|
2174 *
|
mas01mj@732
|
2175 * uri1.MakeRelativePath(uri2);</listing>
|
mas01mj@732
|
2176 *
|
mas01mj@732
|
2177 * <p>uri1 will have a final value of "../some/file.html"</p>
|
mas01mj@732
|
2178 *
|
mas01mj@732
|
2179 * <p>Note! This function is brute force. If you have two URI's
|
mas01mj@732
|
2180 * that are completely unrelated, this will still attempt to make
|
mas01mj@732
|
2181 * the relative URI. In that case, you will most likely get a
|
mas01mj@732
|
2182 * relative path that looks something like:</p>
|
mas01mj@732
|
2183 *
|
mas01mj@732
|
2184 * <p>../../../../../../some/path/to/my/file.html</p>
|
mas01mj@732
|
2185 *
|
mas01mj@732
|
2186 * @param base_uri the URI from which to make this URI relative
|
mas01mj@732
|
2187 *
|
mas01mj@732
|
2188 * @return true if successful, false if the base_uri and this URI
|
mas01mj@732
|
2189 * are not related, of if error.
|
mas01mj@732
|
2190 */
|
mas01mj@732
|
2191 public function makeRelativeURI(base_uri:URI, caseSensitive:Boolean = true) : Boolean
|
mas01mj@732
|
2192 {
|
mas01mj@732
|
2193 var base:URI = new URI();
|
mas01mj@732
|
2194 base.copyURI(base_uri);
|
mas01mj@732
|
2195
|
mas01mj@732
|
2196 var thisParts:Array, thatParts:Array;
|
mas01mj@732
|
2197 var finalParts:Array = new Array();
|
mas01mj@732
|
2198 var thisPart:String, thatPart:String, finalPath:String;
|
mas01mj@732
|
2199 var pathStr:String = this.path;
|
mas01mj@732
|
2200 var queryStr:String = this.queryRaw;
|
mas01mj@732
|
2201 var fragmentStr:String = this.fragment;
|
mas01mj@732
|
2202 var i:int;
|
mas01mj@732
|
2203 var diff:Boolean = false;
|
mas01mj@732
|
2204 var isDir:Boolean = false;
|
mas01mj@732
|
2205
|
mas01mj@732
|
2206 if (isRelative())
|
mas01mj@732
|
2207 {
|
mas01mj@732
|
2208 // We're already relative.
|
mas01mj@732
|
2209 return true;
|
mas01mj@732
|
2210 }
|
mas01mj@732
|
2211
|
mas01mj@732
|
2212 if (base.isRelative())
|
mas01mj@732
|
2213 {
|
mas01mj@732
|
2214 // The base is relative. A relative base doesn't make sense.
|
mas01mj@732
|
2215 return false;
|
mas01mj@732
|
2216 }
|
mas01mj@732
|
2217
|
mas01mj@732
|
2218
|
mas01mj@732
|
2219 if ( (isOfType(base_uri.scheme) == false) ||
|
mas01mj@732
|
2220 (this.authority != base_uri.authority) )
|
mas01mj@732
|
2221 {
|
mas01mj@732
|
2222 // The schemes and/or authorities are different. We can't
|
mas01mj@732
|
2223 // make a relative path to something that is completely
|
mas01mj@732
|
2224 // unrelated.
|
mas01mj@732
|
2225 return false;
|
mas01mj@732
|
2226 }
|
mas01mj@732
|
2227
|
mas01mj@732
|
2228 // Record the state of this URI
|
mas01mj@732
|
2229 isDir = isDirectory();
|
mas01mj@732
|
2230
|
mas01mj@732
|
2231 // We are based of the directory of the given URI. We need to
|
mas01mj@732
|
2232 // make sure the URI is pointing to a directory. Changing
|
mas01mj@732
|
2233 // directory to "." will remove any file name if the base is
|
mas01mj@732
|
2234 // not a directory.
|
mas01mj@732
|
2235 base.chdir(".");
|
mas01mj@732
|
2236
|
mas01mj@732
|
2237 thisParts = pathStr.split("/");
|
mas01mj@732
|
2238 thatParts = base.path.split("/");
|
mas01mj@732
|
2239
|
mas01mj@732
|
2240 if (thisParts.length > 0 && thisParts[0] == "")
|
mas01mj@732
|
2241 thisParts.shift();
|
mas01mj@732
|
2242
|
mas01mj@732
|
2243 if (thisParts.length > 0 && thisParts[thisParts.length - 1] == "")
|
mas01mj@732
|
2244 {
|
mas01mj@732
|
2245 isDir = true;
|
mas01mj@732
|
2246 thisParts.pop();
|
mas01mj@732
|
2247 }
|
mas01mj@732
|
2248
|
mas01mj@732
|
2249 if (thatParts.length > 0 && thatParts[0] == "")
|
mas01mj@732
|
2250 thatParts.shift();
|
mas01mj@732
|
2251 if (thatParts.length > 0 && thatParts[thatParts.length - 1] == "")
|
mas01mj@732
|
2252 thatParts.pop();
|
mas01mj@732
|
2253
|
mas01mj@732
|
2254
|
mas01mj@732
|
2255 // Now that we have the paths split into an array of directories,
|
mas01mj@732
|
2256 // we can compare the two paths. We start from the left of side
|
mas01mj@732
|
2257 // of the path and start comparing. When we either run out of
|
mas01mj@732
|
2258 // directories (one path is longer than the other), or we find
|
mas01mj@732
|
2259 // a directory that is different, we stop. The remaining parts
|
mas01mj@732
|
2260 // of each path is then used to determine the relative path. For
|
mas01mj@732
|
2261 // example, lets say we have:
|
mas01mj@732
|
2262 // path we want to make relative: /a/b/c/d/e.txt
|
mas01mj@732
|
2263 // path to use as base for relative: /a/b/f/
|
mas01mj@732
|
2264 //
|
mas01mj@732
|
2265 // This loop will start at the left, and remove directories
|
mas01mj@732
|
2266 // until we get a mismatch or run off the end of one of them.
|
mas01mj@732
|
2267 // In this example, the result will be:
|
mas01mj@732
|
2268 // c/d/e.txt
|
mas01mj@732
|
2269 // f
|
mas01mj@732
|
2270 //
|
mas01mj@732
|
2271 // For every part left over in the base path, we prepend a ".."
|
mas01mj@732
|
2272 // to the relative to get the final path:
|
mas01mj@732
|
2273 // ../c/d/e.txt
|
mas01mj@732
|
2274 while(thatParts.length > 0)
|
mas01mj@732
|
2275 {
|
mas01mj@732
|
2276 if (thisParts.length == 0)
|
mas01mj@732
|
2277 {
|
mas01mj@732
|
2278 // we matched all there is to match, we are done.
|
mas01mj@732
|
2279 // This is the case where "this" object is a parent
|
mas01mj@732
|
2280 // path of the given URI. eg:
|
mas01mj@732
|
2281 // this.path = /a/b/ (thisParts)
|
mas01mj@732
|
2282 // base.path = /a/b/c/d/e/ (thatParts)
|
mas01mj@732
|
2283 break;
|
mas01mj@732
|
2284 }
|
mas01mj@732
|
2285
|
mas01mj@732
|
2286 thisPart = thisParts[0];
|
mas01mj@732
|
2287 thatPart = thatParts[0];
|
mas01mj@732
|
2288
|
mas01mj@732
|
2289 if (compareStr(thisPart, thatPart, caseSensitive))
|
mas01mj@732
|
2290 {
|
mas01mj@732
|
2291 thisParts.shift();
|
mas01mj@732
|
2292 thatParts.shift();
|
mas01mj@732
|
2293 }
|
mas01mj@732
|
2294 else
|
mas01mj@732
|
2295 break;
|
mas01mj@732
|
2296 }
|
mas01mj@732
|
2297
|
mas01mj@732
|
2298 // If there are any path info left from the base URI, that means
|
mas01mj@732
|
2299 // **this** object is above the given URI in the file tree. For
|
mas01mj@732
|
2300 // each part left over in the given URI, we need to move up one
|
mas01mj@732
|
2301 // directory to get where we are.
|
mas01mj@732
|
2302 var dotdot:String = "..";
|
mas01mj@732
|
2303 for (i = 0; i < thatParts.length; i++)
|
mas01mj@732
|
2304 {
|
mas01mj@732
|
2305 finalParts.push(dotdot);
|
mas01mj@732
|
2306 }
|
mas01mj@732
|
2307
|
mas01mj@732
|
2308 // Append the parts of this URI to any dot-dot's we have
|
mas01mj@732
|
2309 finalParts = finalParts.concat(thisParts);
|
mas01mj@732
|
2310
|
mas01mj@732
|
2311 // Join the parts back into a path
|
mas01mj@732
|
2312 finalPath = joinPath(finalParts, false /* not absolute */, isDir);
|
mas01mj@732
|
2313
|
mas01mj@732
|
2314 if (finalPath.length == 0)
|
mas01mj@732
|
2315 {
|
mas01mj@732
|
2316 // The two URI's are exactly the same. The proper relative
|
mas01mj@732
|
2317 // path is:
|
mas01mj@732
|
2318 finalPath = "./";
|
mas01mj@732
|
2319 }
|
mas01mj@732
|
2320
|
mas01mj@732
|
2321 // Set the parts of the URI, preserving the original query and
|
mas01mj@732
|
2322 // fragment parts.
|
mas01mj@732
|
2323 setParts("", "", "", finalPath, queryStr, fragmentStr);
|
mas01mj@732
|
2324
|
mas01mj@732
|
2325 return true;
|
mas01mj@732
|
2326 }
|
mas01mj@732
|
2327
|
mas01mj@732
|
2328 /**
|
mas01mj@732
|
2329 * Given a string, convert it to a URI. The string could be a
|
mas01mj@732
|
2330 * full URI that is improperly escaped, a malformed URI (e.g.
|
mas01mj@732
|
2331 * missing a protocol like "www.something.com"), a relative URI,
|
mas01mj@732
|
2332 * or any variation there of.
|
mas01mj@732
|
2333 *
|
mas01mj@732
|
2334 * <p>The intention of this function is to take anything that a
|
mas01mj@732
|
2335 * user might manually enter as a URI/URL and try to determine what
|
mas01mj@732
|
2336 * they mean. This function differs from the URI constructor in
|
mas01mj@732
|
2337 * that it makes some assumptions to make it easy to import user
|
mas01mj@732
|
2338 * entered URI data.</p>
|
mas01mj@732
|
2339 *
|
mas01mj@732
|
2340 * <p>This function is intended to be a helper function.
|
mas01mj@732
|
2341 * It is not all-knowning and will probably make mistakes
|
mas01mj@732
|
2342 * when attempting to parse a string of unknown origin. If
|
mas01mj@732
|
2343 * your applicaiton is receiving input from the user, your
|
mas01mj@732
|
2344 * application should already have a good idea what the user
|
mas01mj@732
|
2345 * should be entering, and your application should be
|
mas01mj@732
|
2346 * pre-processing the user's input to make sure it is well formed
|
mas01mj@732
|
2347 * before passing it to this function.</p>
|
mas01mj@732
|
2348 *
|
mas01mj@732
|
2349 * <p>It is assumed that the string given to this function is
|
mas01mj@732
|
2350 * something the user may have manually entered. Given this,
|
mas01mj@732
|
2351 * the URI string is probably unescaped or improperly escaped.
|
mas01mj@732
|
2352 * This function will attempt to properly escape the URI by
|
mas01mj@732
|
2353 * using forceEscape(). The result is that a toString() call
|
mas01mj@732
|
2354 * on a URI that was created from unknownToURI() may not match
|
mas01mj@732
|
2355 * the input string due to the difference in escaping.</p>
|
mas01mj@732
|
2356 *
|
mas01mj@732
|
2357 * @param unknown a potental URI string that should be parsed
|
mas01mj@732
|
2358 * and loaded into this object.
|
mas01mj@732
|
2359 * @param defaultScheme if it is determined that the passed string
|
mas01mj@732
|
2360 * looks like a URI, but it is missing the scheme part, this
|
mas01mj@732
|
2361 * string will be used as the missing scheme.
|
mas01mj@732
|
2362 *
|
mas01mj@732
|
2363 * @return true if the given string was successfully parsed into
|
mas01mj@732
|
2364 * a valid URI object, false otherwise.
|
mas01mj@732
|
2365 */
|
mas01mj@732
|
2366 public function unknownToURI(unknown:String, defaultScheme:String = "http") : Boolean
|
mas01mj@732
|
2367 {
|
mas01mj@732
|
2368 var temp:String;
|
mas01mj@732
|
2369
|
mas01mj@732
|
2370 if (unknown.length == 0)
|
mas01mj@732
|
2371 {
|
mas01mj@732
|
2372 this.initialize();
|
mas01mj@732
|
2373 return false;
|
mas01mj@732
|
2374 }
|
mas01mj@732
|
2375
|
mas01mj@732
|
2376 // Some users love the backslash key. Fix it.
|
mas01mj@732
|
2377 unknown = unknown.replace(/\\/g, "/");
|
mas01mj@732
|
2378
|
mas01mj@732
|
2379 // Check for any obviously missing scheme.
|
mas01mj@732
|
2380 if (unknown.length >= 2)
|
mas01mj@732
|
2381 {
|
mas01mj@732
|
2382 temp = unknown.substr(0, 2);
|
mas01mj@732
|
2383 if (temp == "//")
|
mas01mj@732
|
2384 unknown = defaultScheme + ":" + unknown;
|
mas01mj@732
|
2385 }
|
mas01mj@732
|
2386
|
mas01mj@732
|
2387 if (unknown.length >= 3)
|
mas01mj@732
|
2388 {
|
mas01mj@732
|
2389 temp = unknown.substr(0, 3);
|
mas01mj@732
|
2390 if (temp == "://")
|
mas01mj@732
|
2391 unknown = defaultScheme + unknown;
|
mas01mj@732
|
2392 }
|
mas01mj@732
|
2393
|
mas01mj@732
|
2394 // Try parsing it as a normal URI
|
mas01mj@732
|
2395 var uri:URI = new URI(unknown);
|
mas01mj@732
|
2396
|
mas01mj@732
|
2397 if (uri.isHierarchical() == false)
|
mas01mj@732
|
2398 {
|
mas01mj@732
|
2399 if (uri.scheme == UNKNOWN_SCHEME)
|
mas01mj@732
|
2400 {
|
mas01mj@732
|
2401 this.initialize();
|
mas01mj@732
|
2402 return false;
|
mas01mj@732
|
2403 }
|
mas01mj@732
|
2404
|
mas01mj@732
|
2405 // It's a non-hierarchical URI
|
mas01mj@732
|
2406 copyURI(uri);
|
mas01mj@732
|
2407 forceEscape();
|
mas01mj@732
|
2408 return true;
|
mas01mj@732
|
2409 }
|
mas01mj@732
|
2410 else if ((uri.scheme != UNKNOWN_SCHEME) &&
|
mas01mj@732
|
2411 (uri.scheme.length > 0))
|
mas01mj@732
|
2412 {
|
mas01mj@732
|
2413 if ( (uri.authority.length > 0) ||
|
mas01mj@732
|
2414 (uri.scheme == "file") )
|
mas01mj@732
|
2415 {
|
mas01mj@732
|
2416 // file://... URI
|
mas01mj@732
|
2417 copyURI(uri);
|
mas01mj@732
|
2418 forceEscape(); // ensure proper escaping
|
mas01mj@732
|
2419 return true;
|
mas01mj@732
|
2420 }
|
mas01mj@732
|
2421 else if (uri.authority.length == 0 && uri.path.length == 0)
|
mas01mj@732
|
2422 {
|
mas01mj@732
|
2423 // It's is an incomplete URI (eg "http://")
|
mas01mj@732
|
2424
|
mas01mj@732
|
2425 setParts(uri.scheme, "", "", "", "", "");
|
mas01mj@732
|
2426 return false;
|
mas01mj@732
|
2427 }
|
mas01mj@732
|
2428 }
|
mas01mj@732
|
2429 else
|
mas01mj@732
|
2430 {
|
mas01mj@732
|
2431 // Possible relative URI. We can only detect relative URI's
|
mas01mj@732
|
2432 // that start with "." or "..". If it starts with something
|
mas01mj@732
|
2433 // else, the parsing is ambiguous.
|
mas01mj@732
|
2434 var path:String = uri.path;
|
mas01mj@732
|
2435
|
mas01mj@732
|
2436 if (path == ".." || path == "." ||
|
mas01mj@732
|
2437 (path.length >= 3 && path.substr(0, 3) == "../") ||
|
mas01mj@732
|
2438 (path.length >= 2 && path.substr(0, 2) == "./") )
|
mas01mj@732
|
2439 {
|
mas01mj@732
|
2440 // This is a relative URI.
|
mas01mj@732
|
2441 copyURI(uri);
|
mas01mj@732
|
2442 forceEscape();
|
mas01mj@732
|
2443 return true;
|
mas01mj@732
|
2444 }
|
mas01mj@732
|
2445 }
|
mas01mj@732
|
2446
|
mas01mj@732
|
2447 // Ok, it looks like we are just a normal URI missing the scheme. Tack
|
mas01mj@732
|
2448 // on the scheme.
|
mas01mj@732
|
2449 uri = new URI(defaultScheme + "://" + unknown);
|
mas01mj@732
|
2450
|
mas01mj@732
|
2451 // Check to see if we are good now
|
mas01mj@732
|
2452 if (uri.scheme.length > 0 && uri.authority.length > 0)
|
mas01mj@732
|
2453 {
|
mas01mj@732
|
2454 // It was just missing the scheme.
|
mas01mj@732
|
2455 copyURI(uri);
|
mas01mj@732
|
2456 forceEscape(); // Make sure we are properly encoded.
|
mas01mj@732
|
2457 return true;
|
mas01mj@732
|
2458 }
|
mas01mj@732
|
2459
|
mas01mj@732
|
2460 // don't know what this is
|
mas01mj@732
|
2461 this.initialize();
|
mas01mj@732
|
2462 return false;
|
mas01mj@732
|
2463 }
|
mas01mj@732
|
2464
|
mas01mj@732
|
2465 } // end URI class
|
mas01mj@732
|
2466 } // end package |