Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.uri.Uri");
14
dojo.uri = new function () {
15
	this.dojoUri = function (uri) {
16
		return new dojo.uri.Uri(dojo.hostenv.getBaseScriptUri(), uri);
17
	};
18
	this.moduleUri = function (module, uri) {
19
		var loc = dojo.hostenv.getModuleSymbols(module).join("/");
20
		if (!loc) {
21
			return null;
22
		}
23
		if (loc.lastIndexOf("/") != loc.length - 1) {
24
			loc += "/";
25
		}
26
		var colonIndex = loc.indexOf(":");
27
		var slashIndex = loc.indexOf("/");
28
		if (loc.charAt(0) != "/" && (colonIndex == -1 || colonIndex > slashIndex)) {
29
			loc = dojo.hostenv.getBaseScriptUri() + loc;
30
		}
31
		return new dojo.uri.Uri(loc, uri);
32
	};
33
	this.Uri = function () {
34
		var uri = arguments[0];
35
		for (var i = 1; i < arguments.length; i++) {
36
			if (!arguments[i]) {
37
				continue;
38
			}
39
			var relobj = new dojo.uri.Uri(arguments[i].toString());
40
			var uriobj = new dojo.uri.Uri(uri.toString());
41
			if ((relobj.path == "") && (relobj.scheme == null) && (relobj.authority == null) && (relobj.query == null)) {
42
				if (relobj.fragment != null) {
43
					uriobj.fragment = relobj.fragment;
44
				}
45
				relobj = uriobj;
46
			} else {
47
				if (relobj.scheme == null) {
48
					relobj.scheme = uriobj.scheme;
49
					if (relobj.authority == null) {
50
						relobj.authority = uriobj.authority;
51
						if (relobj.path.charAt(0) != "/") {
52
							var path = uriobj.path.substring(0, uriobj.path.lastIndexOf("/") + 1) + relobj.path;
53
							var segs = path.split("/");
54
							for (var j = 0; j < segs.length; j++) {
55
								if (segs[j] == ".") {
56
									if (j == segs.length - 1) {
57
										segs[j] = "";
58
									} else {
59
										segs.splice(j, 1);
60
										j--;
61
									}
62
								} else {
63
									if (j > 0 && !(j == 1 && segs[0] == "") && segs[j] == ".." && segs[j - 1] != "..") {
64
										if (j == segs.length - 1) {
65
											segs.splice(j, 1);
66
											segs[j - 1] = "";
67
										} else {
68
											segs.splice(j - 1, 2);
69
											j -= 2;
70
										}
71
									}
72
								}
73
							}
74
							relobj.path = segs.join("/");
75
						}
76
					}
77
				}
78
			}
79
			uri = "";
80
			if (relobj.scheme != null) {
81
				uri += relobj.scheme + ":";
82
			}
83
			if (relobj.authority != null) {
84
				uri += "//" + relobj.authority;
85
			}
86
			uri += relobj.path;
87
			if (relobj.query != null) {
88
				uri += "?" + relobj.query;
89
			}
90
			if (relobj.fragment != null) {
91
				uri += "#" + relobj.fragment;
92
			}
93
		}
94
		this.uri = uri.toString();
95
		var regexp = "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?$";
96
		var r = this.uri.match(new RegExp(regexp));
97
		this.scheme = r[2] || (r[1] ? "" : null);
98
		this.authority = r[4] || (r[3] ? "" : null);
99
		this.path = r[5];
100
		this.query = r[7] || (r[6] ? "" : null);
101
		this.fragment = r[9] || (r[8] ? "" : null);
102
		if (this.authority != null) {
103
			regexp = "^((([^:]+:)?([^@]+))@)?([^:]*)(:([0-9]+))?$";
104
			r = this.authority.match(new RegExp(regexp));
105
			this.user = r[3] || null;
106
			this.password = r[4] || null;
107
			this.host = r[5];
108
			this.port = r[7] || null;
109
		}
110
		this.toString = function () {
111
			return this.uri;
112
		};
113
	};
114
};
115