root / trunk / web / dojo / dojox / uuid / _base.js @ 12
History | View | Annotate | Download (3.22 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.uuid._base"]){ |
9 |
dojo._hasResource["dojox.uuid._base"]=true; |
10 |
dojo.provide("dojox.uuid._base");
|
11 |
dojox.uuid.NIL_UUID="00000000-0000-0000-0000-000000000000";
|
12 |
dojox.uuid.version={UNKNOWN:0,TIME_BASED:1,DCE_SECURITY:2,NAME_BASED_MD5:3,RANDOM:4,NAME_BASED_SHA1:5}; |
13 |
dojox.uuid.variant={NCS:"0",DCE:"10",MICROSOFT:"110",UNKNOWN:"111"}; |
14 |
dojox.uuid.assert=function(_1,_2){ |
15 |
if(!_1){
|
16 |
if(!_2){
|
17 |
_2="An assert statement failed.\n"+"The method dojox.uuid.assert() was called with a 'false' value.\n"; |
18 |
} |
19 |
throw new Error(_2); |
20 |
} |
21 |
}; |
22 |
dojox.uuid.generateNilUuid=function(){ |
23 |
return dojox.uuid.NIL_UUID;
|
24 |
}; |
25 |
dojox.uuid.isValid=function(_3){ |
26 |
_3=_3.toString(); |
27 |
var _4=(dojo.isString(_3)&&(_3.length==36)&&(_3==_3.toLowerCase())); |
28 |
if(_4){
|
29 |
var _5=_3.split("-"); |
30 |
_4=((_5.length==5)&&(_5[0].length==8)&&(_5[1].length==4)&&(_5[2].length==4)&&(_5[3].length==4)&&(_5[4].length==12)); |
31 |
var _6=16; |
32 |
for(var i in _5){ |
33 |
var _7=_5[i];
|
34 |
var _8=parseInt(_7,_6);
|
35 |
_4=_4&&isFinite(_8); |
36 |
} |
37 |
} |
38 |
return _4;
|
39 |
}; |
40 |
dojox.uuid.getVariant=function(_9){ |
41 |
if(!dojox.uuid._ourVariantLookupTable){
|
42 |
var _a=dojox.uuid.variant;
|
43 |
var _b=[];
|
44 |
_b[0]=_a.NCS;
|
45 |
_b[1]=_a.NCS;
|
46 |
_b[2]=_a.NCS;
|
47 |
_b[3]=_a.NCS;
|
48 |
_b[4]=_a.NCS;
|
49 |
_b[5]=_a.NCS;
|
50 |
_b[6]=_a.NCS;
|
51 |
_b[7]=_a.NCS;
|
52 |
_b[8]=_a.DCE;
|
53 |
_b[9]=_a.DCE;
|
54 |
_b[10]=_a.DCE;
|
55 |
_b[11]=_a.DCE;
|
56 |
_b[12]=_a.MICROSOFT;
|
57 |
_b[13]=_a.MICROSOFT;
|
58 |
_b[14]=_a.UNKNOWN;
|
59 |
_b[15]=_a.UNKNOWN;
|
60 |
dojox.uuid._ourVariantLookupTable=_b; |
61 |
} |
62 |
_9=_9.toString(); |
63 |
var _c=_9.charAt(19); |
64 |
var _d=16; |
65 |
var _e=parseInt(_c,_d);
|
66 |
dojox.uuid.assert((_e>=0)&&(_e<=16)); |
67 |
return dojox.uuid._ourVariantLookupTable[_e];
|
68 |
}; |
69 |
dojox.uuid.getVersion=function(_f){ |
70 |
var _10="dojox.uuid.getVersion() was not passed a DCE Variant UUID."; |
71 |
dojox.uuid.assert(dojox.uuid.getVariant(_f)==dojox.uuid.variant.DCE,_10); |
72 |
_f=_f.toString(); |
73 |
var _11=_f.charAt(14); |
74 |
var _12=16; |
75 |
var _13=parseInt(_11,_12);
|
76 |
return _13;
|
77 |
}; |
78 |
dojox.uuid.getNode=function(_14){ |
79 |
var _15="dojox.uuid.getNode() was not passed a TIME_BASED UUID."; |
80 |
dojox.uuid.assert(dojox.uuid.getVersion(_14)==dojox.uuid.version.TIME_BASED,_15); |
81 |
_14=_14.toString(); |
82 |
var _16=_14.split("-"); |
83 |
var _17=_16[4]; |
84 |
return _17;
|
85 |
}; |
86 |
dojox.uuid.getTimestamp=function(_18,_19){ |
87 |
var _1a="dojox.uuid.getTimestamp() was not passed a TIME_BASED UUID."; |
88 |
dojox.uuid.assert(dojox.uuid.getVersion(_18)==dojox.uuid.version.TIME_BASED,_1a); |
89 |
_18=_18.toString(); |
90 |
if(!_19){
|
91 |
_19=null;
|
92 |
} |
93 |
switch(_19){
|
94 |
case "string": |
95 |
case String:
|
96 |
return dojox.uuid.getTimestamp(_18,Date).toUTCString();
|
97 |
break;
|
98 |
case "hex": |
99 |
var _1b=_18.split("-"); |
100 |
var _1c=_1b[0]; |
101 |
var _1d=_1b[1]; |
102 |
var _1e=_1b[2]; |
103 |
_1e=_1e.slice(1);
|
104 |
var _1f=_1e+_1d+_1c;
|
105 |
dojox.uuid.assert(_1f.length==15);
|
106 |
return _1f;
|
107 |
break;
|
108 |
case null: |
109 |
case "date": |
110 |
case Date:
|
111 |
var _20=3394248; |
112 |
var _21=16; |
113 |
var _22=_18.split("-"); |
114 |
var _23=parseInt(_22[0],_21); |
115 |
var _24=parseInt(_22[1],_21); |
116 |
var _25=parseInt(_22[2],_21); |
117 |
var _26=_25&4095; |
118 |
_26<<=16;
|
119 |
_26+=_24; |
120 |
_26*=4294967296;
|
121 |
_26+=_23; |
122 |
var _27=_26/10000; |
123 |
var _28=60*60; |
124 |
var _29=_20;
|
125 |
var _2a=_29*_28;
|
126 |
var _2b=_2a*1000; |
127 |
var _2c=_27-_2b;
|
128 |
var _2d=new Date(_2c); |
129 |
return _2d;
|
130 |
break;
|
131 |
default:
|
132 |
dojox.uuid.assert(false,"dojox.uuid.getTimestamp was not passed a valid returnType: "+_19); |
133 |
break;
|
134 |
} |
135 |
}; |
136 |
} |