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();
} |
Partager