bonjour.

si vous allez sur la page : http://en.wikipedia.org/wiki/URI_scheme
vous trouverez une doc sur la syntaxe des URI (URN, URL)
dont voici un résumé:
Code plaintext : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  foo://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose
  \_/   \_______________/ \_________/ \__/            \___/ \_/ \______________________/ \__/
   |           |               |       |                |    |            |                |
   |       userinfo         hostname  port              |    |          query          fragment
   |    \________________________________/\_____________|____|/ \__/ \____/ \__/ \_____/
   |                    |                          |    |    |    |     |     |     |
scheme              authority                    path   |    |    interpretable as keys
 name   \_______________________________________________|____|/         |           |
   |                         |                          |    |    interpretable as values
   |                 hierarchical part                  |    |
   |                                                    |    |
   |            path               interpretable as filename |
   |   ___________|____________                              |
  / \ /                        \                             |
  urn:example:animal:ferret:nose               interpretable as extension
 
 scheme
  name  userinfo  hostname       query
  _|__   ___|__   ____|____   _____|_____
 /    \ /      \ /         \ /           \
 mailto:username@example.com?subject=Topic

créant dynamiquement beaucoup d'uri à partir de nombreuses informations issues de diverses source je me suis fait une classe URIBuilder qui propose un DSL pour créer une URI. je travaille en java mais un portage vers JavaScript était peut coûteux le voici donc.
Code javascript : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
URIBuilder = function() {
	this.schemename = null;
	this.username = null;
	this.pass = null;
	this.hostname = null;
	this.portnumber = null;
	this.fullpath = null;
	this.querystring = null;
	this.fragmentname = null;
 
	this.schemeName = function(string) {
		this.schemename = string;
		return this;
	};
	this.userName = function(string) {
		this.username = string;
		return this;
	};
	this.password = function(string) {
		this.pass = string;
		return this;
	};
	this.hostName = function(string) {
		this.hostname = string;
		return this;
	};
	this.port = function(string) {
		this.portnumber = string;
		return this;
	};
	this.path = function(string) {
		this.fullpath = string;
		return this;
	};
	this.query = function(string) {
		this.querystring = string;
		return this;
	};
	this.fragment = function(string) {
		this.fragmentname = string;
		return this;
	};
 
	this.getSchemeName = function(string) {
		return this.schemename;
	};
	this.getUserName = function(string) {
		return this.username;
	};
	this.getPassword = function(string) {
		return this.pass;
	};
	this.getHostName = function(string) {
		return this.hostname;
	};
	this.getPort = function(string) {
		return this.portnumber;
	};
	this.getPath = function(string) {
		return this.fullpath;
	};
	this.getQuery = function(string) {
		return this.querystring;
	};
	this.getFragment = function(string) {
		return this.fragmentname;
	};
 
	this.getUserinfo = function(string) {
		if (null != this.getPassword()) {
			return this.getUserName() + ":" + this.getPassword();
		} else {
			return this.getUserName()
		}
	};
	this.getLocation = function(string) {
		if (null != this.getPort()) {
			return this.getHostName() + ":" + this.getPort();
		} else {
			return this.getHostName()
		}
	};
	this.getAuthority = function(string) {
		if (null != this.getUserinfo()) {
			return this.getUserinfo() + "@" + this.getLocation();
		} else {
			return this.getLocation()
		}
	};
	this.getHierarchical = function(string) {
		return this.getAuthority() + this.getPath();
	};
 
	this.getUri = function(string) {
		uri = this.getSchemeName();
		if (null != this.getAuthority()) {
			uri = uri + "://" + this.getHierarchical();
		} else {
			uri = uri + ":" + this.getPath()
		}
		if (null != this.getQuery()) {
			uri = uri + "?" + this.getQuery()
		}
		if (null != this.getFragment()) {
			uri = uri + "#" + this.getFragment()
		}
		return uri;
	};
}
//une petite facilité
URIBuilder.newBuilder = function(){
	return new URIBuilder();
}
Pour mieux comprendre comment cela fonctionne quelques exemples
Code javascript : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
uriBuilder = new URIBuilder();
//une URN
console.log(uriBuilder
	.schemeName('urn')
	.path('org.jsunit.test')
	.getUri());
 
//un url http avec le même builder (recyclé)
console.log(uriBuilder
	.schemeName('http')
	.hostName('localhost')
	.port(8081)
	.path('/org/jsunit/test.php')
	.getUri());
 
//ajout d'un login à l'url
console.log(uriBuilder
	.userName('jhon')
	.password('doe')
	.getUri());
 
//ajout d'une query et une ancre à l'url
console.log(uriBuilder
	.query('var=15&sort=desc')
	.fragment('ancre1')
	.getUri());
 
//création d'une url en une seule ligne
console.log(URIBuilder.newBuilder()
	.schemeName('http')
	.userName('jhon')
	.password('doe')
	.hostName('localhost')
	.port(8081)
	.path('/org/jsunit/test.php')
	.query('var=15&sort=desc')
	.fragment('ancre1')
	.getUri());
A+JYT