Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | 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
 
11
dojo.provide("dojo.uri.Uri");
12
dojo.uri = new function () {
13
	this.dojoUri = function (uri) {
14
		return new dojo.uri.Uri(dojo.hostenv.getBaseScriptUri(), uri);
15
	};
16
	this.moduleUri = function (module, uri) {
17
		var loc = dojo.hostenv.getModuleSymbols(module).join("/");
18
		if (!loc) {
19
			return null;
20
		}
21
		if (loc.lastIndexOf("/") != loc.length - 1) {
22
			loc += "/";
23
		}
24
		var colonIndex = loc.indexOf(":");
25
		var slashIndex = loc.indexOf("/");
26
		if (loc.charAt(0) != "/" && (colonIndex == -1 || colonIndex > slashIndex)) {
27
			loc = dojo.hostenv.getBaseScriptUri() + loc;
28
		}
29
		return new dojo.uri.Uri(loc, uri);
30
	};
31
	this.Uri = function () {
32
		var uri = arguments[0];
33
		for (var i = 1; i < arguments.length; i++) {
34
			if (!arguments[i]) {
35
				continue;
36
			}
37
			var relobj = new dojo.uri.Uri(arguments[i].toString());
38
			var uriobj = new dojo.uri.Uri(uri.toString());
39
			if ((relobj.path == "") && (relobj.scheme == null) && (relobj.authority == null) && (relobj.query == null)) {
40
				if (relobj.fragment != null) {
41
					uriobj.fragment = relobj.fragment;
42
				}
43
				relobj = uriobj;
44
			} else {
45
				if (relobj.scheme == null) {
46
					relobj.scheme = uriobj.scheme;
47
					if (relobj.authority == null) {
48
						relobj.authority = uriobj.authority;
49
						if (relobj.path.charAt(0) != "/") {
50
							var path = uriobj.path.substring(0, uriobj.path.lastIndexOf("/") + 1) + relobj.path;
51
							var segs = path.split("/");
52
							for (var j = 0; j < segs.length; j++) {
53
								if (segs[j] == ".") {
54
									if (j == segs.length - 1) {
55
										segs[j] = "";
56
									} else {
57
										segs.splice(j, 1);
58
										j--;
59
									}
60
								} else {
61
									if (j > 0 && !(j == 1 && segs[0] == "") && segs[j] == ".." && segs[j - 1] != "..") {
62
										if (j == segs.length - 1) {
63
											segs.splice(j, 1);
64
											segs[j - 1] = "";
65
										} else {
66
											segs.splice(j - 1, 2);
67
											j -= 2;
68
										}
69
									}
70
								}
71
							}
72
							relobj.path = segs.join("/");
73
						}
74
					}
75
				}
76
			}
77
			uri = "";
78
			if (relobj.scheme != null) {
79
				uri += relobj.scheme + ":";
80
			}
81
			if (relobj.authority != null) {
82
				uri += "//" + relobj.authority;
83
			}
84
			uri += relobj.path;
85
			if (relobj.query != null) {
86
				uri += "?" + relobj.query;
87
			}
88
			if (relobj.fragment != null) {
89
				uri += "#" + relobj.fragment;
90
			}
91
		}
92
		this.uri = uri.toString();
93
		var regexp = "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?$";
94
		var r = this.uri.match(new RegExp(regexp));
95
		this.scheme = r[2] || (r[1] ? "" : null);
96
		this.authority = r[4] || (r[3] ? "" : null);
97
		this.path = r[5];
98
		this.query = r[7] || (r[6] ? "" : null);
99
		this.fragment = r[9] || (r[8] ? "" : null);
100
		if (this.authority != null) {
101
			regexp = "^((([^:]+:)?([^@]+))@)?([^:]*)(:([0-9]+))?$";
102
			r = this.authority.match(new RegExp(regexp));
103
			this.user = r[3] || null;
104
			this.password = r[4] || null;
105
			this.host = r[5];
106
			this.port = r[7] || null;
107
		}
108
		this.toString = function () {
109
			return this.uri;
110
		};
111
	};
112
};
113