Uri.js
上传用户:kimgenplus
上传日期:2016-06-05
资源大小:20877k
文件大小:3k
源码类别:

OA系统

开发平台:

Java

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