##// END OF EJS Templates
Added childContainer service to container services, ServiceContaier is destroyable, fixed browser Uuid version
Added childContainer service to container services, ServiceContaier is destroyable, fixed browser Uuid version

File last commit:

r65:0c74a0572161 v1.2.13 default
r146:f3f5c56d3b3e v1.4.0-rc5 default
Show More
Uri.js
235 lines | 6.1 KiB | application/javascript | JavascriptLexer
cin
fixed "singleton" activation type handling in container configuration...
r65 define(["dojo/_base/declare", "./log/trace!"], function (declare, trace) {
cin
working on support commonjs modules format
r59 trace.warn("THIS MODULE IS DEPRECATED! use uri-js or similar alternatives.");
function parseURI(uri) {
var schema, host, port, path, query, hash, i;
if (typeof (uri) == "string") {
if ((i = uri.indexOf(":")) >= 0 &&
uri.substr(0, i).match(/^\w+$/)) {
schema = uri.substr(0, i);
uri = uri.substr(i + 1);
}
cin
working version...
r51
cin
working on support commonjs modules format
r59 if (uri.indexOf("//") === 0) {
uri = uri.substr(2);
if ((i = uri.indexOf("/")) >= 0) {
host = uri.substr(0, i);
uri = uri.substr(i);
} else {
host = uri;
uri = "";
cin
working version...
r51 }
cin
working on support commonjs modules format
r59 }
cin
working version...
r51
cin
working on support commonjs modules format
r59 if ((i = uri.indexOf("?")) >= 0) {
path = uri.substr(0, i);
uri = uri.substr(i + 1);
cin
working version...
r51
cin
working on support commonjs modules format
r59 } else {
path = uri;
uri = "";
cin
working version...
r51
cin
working on support commonjs modules format
r59 if ((i = path.indexOf("#")) >= 0) {
hash = path.substr(i + 1);
path = path.substr(0, i);
cin
working version...
r51 }
}
cin
working on support commonjs modules format
r59 if ((i = uri.indexOf("#")) >= 0) {
query = uri.substr(0, i);
hash = uri.substr(i + 1);
} else {
query = uri;
cin
working version...
r51 }
cin
working on support commonjs modules format
r59 }
cin
working version...
r51
cin
working on support commonjs modules format
r59 if (host && (i = host.lastIndexOf(":")) >= 0) {
port = host.substr(i + 1);
host = host.substr(0, i);
cin
working version...
r51 }
cin
working on support commonjs modules format
r59 return {
schema: schema,
host: host,
port: port,
path: path,
query: query,
hash: hash
};
}
cin
working version...
r51
cin
working on support commonjs modules format
r59 function makeURI(options) {
var uri = [];
cin
working version...
r51
cin
working on support commonjs modules format
r59 if (options.schema)
uri.push(options.schema, ":");
if (options.host)
uri.push("//", options.host);
if (options.host && options.port)
uri.push(":", options.port);
if (options.path) {
if (options.host && options.path[0] != "/")
cin
working version...
r51 uri.push("/");
cin
working on support commonjs modules format
r59 uri.push(options.path);
} else if (options.host) {
uri.push("/");
cin
working version...
r51 }
cin
working on support commonjs modules format
r59 if (options.query)
uri.push("?", options.query);
if (options.hash)
uri.push("#", options.hash);
return uri.join("");
}
cin
working version...
r51
cin
working on support commonjs modules format
r59 function reducePath(parts) {
var balance = 0,
result = [],
isRoot;
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
switch (part) {
cin
working version...
r51 case "..":
if (balance > 0) {
result.pop();
} else {
if (isRoot)
throw new Error("Unbalanced path: " + parts);
result.push(part);
}
balance--;
break;
case ".":
break;
case "":
if (i === 0) {
isRoot = true;
result.push(part);
}
break;
default:
result.push(part);
balance++;
break;
}
}
cin
working on support commonjs modules format
r59 return result.join("/");
}
cin
working version...
r51
cin
working on support commonjs modules format
r59 var meta = {
schema: null,
host: null,
port: null,
path: null,
query: null,
hash: null
};
cin
working version...
r51
cin
working on support commonjs modules format
r59 var URI = declare(null, {
constructor: function (opts) {
trace.warn("This class is deprecated use uri-js or similar");
if (typeof (opts) == "string")
opts = parseURI(opts);
for (var p in meta)
if (p in opts)
this[p] = opts[p];
},
cin
working version...
r51
cin
working on support commonjs modules format
r59 clone: function () {
return new URI(this);
},
cin
working version...
r51
cin
working on support commonjs modules format
r59 combine: function (rel) {
var me = this;
cin
working version...
r51
cin
working on support commonjs modules format
r59 if (typeof (rel) === "string")
rel = new URI(rel);
else
rel = rel.clone();
cin
working version...
r51
cin
working on support commonjs modules format
r59 // //some.host:123/path?q=a#123
if (rel.host)
return rel;
cin
working version...
r51
cin
working on support commonjs modules format
r59 // /abs/path?q=a#123
if (rel.path && rel.path[0] == "/") {
if (me.host) {
rel.schema = me.schema;
rel.host = me.host;
rel.port = me.port;
cin
working version...
r51 }
cin
working on support commonjs modules format
r59 return rel;
cin
working version...
r51 }
cin
working on support commonjs modules format
r59 var base = me.clone();
// rel/path?a=b#cd
if (rel.path) {
var segments = base.getSegments();
segments.pop();
segments.push.apply(segments, rel.getSegments());
base.path = reducePath(segments);
}
// ?q=a#123
if (rel.query)
base.query = rel.query;
if (rel.hash)
base.hase = rel.hash;
return base;
},
optimize: function () {
this.path = reducePath(this.getSegments());
},
getSegments: function () {
if (typeof (this.path) === "string")
return this.path.split("/");
else
return [];
},
cin
working version...
r51
cin
working on support commonjs modules format
r59 toString: function () {
var uri = [],
me = this;
if (me.schema)
uri.push(me.schema, ":");
if (me.host)
uri.push("//", me.host);
if (me.host && me.port)
uri.push(":", me.port);
if (me.path) {
if (me.host && me.path[0] != "/")
uri.push("/");
uri.push(me.path);
} else if (me.host) {
uri.push("/");
}
cin
working version...
r51
cin
working on support commonjs modules format
r59 if (me.query)
uri.push("?", me.query);
if (me.hash)
uri.push("#", me.hash);
return uri.join("");
}
});
URI.combine = function (base, rel) {
if (typeof (base) === "string")
base = new URI(base);
return base.combine(rel).toString();
};
return URI;
});