root / trunk / web / dojo / dojox / xmpp / util.js @ 11
History | View | Annotate | Download (2.49 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
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.xmpp.util"]){ |
||
9 | dojo._hasResource["dojox.xmpp.util"]=true; |
||
10 | dojo.provide("dojox.xmpp.util");
|
||
11 | dojo.require("dojox.string.Builder");
|
||
12 | dojo.require("dojox.encoding.base64");
|
||
13 | dojox.xmpp.util.xmlEncode=function(_1){ |
||
14 | if(_1){
|
||
15 | _1=_1.replace("&","&").replace(">",">").replace("<","<").replace("'","'").replace("\"","""); |
||
16 | } |
||
17 | return _1;
|
||
18 | }; |
||
19 | dojox.xmpp.util.encodeJid=function(_2){ |
||
20 | var _3=new dojox.string.Builder(); |
||
21 | for(var i=0;i<_2.length;i++){ |
||
22 | var ch=_2.charAt(i);
|
||
23 | var _4=ch;
|
||
24 | switch(ch){
|
||
25 | case " ": |
||
26 | _4="\\20";
|
||
27 | break;
|
||
28 | case "\"": |
||
29 | _4="\\22";
|
||
30 | break;
|
||
31 | case "#": |
||
32 | _4="\\23";
|
||
33 | break;
|
||
34 | case "&": |
||
35 | _4="\\26";
|
||
36 | break;
|
||
37 | case "'": |
||
38 | _4="\\27";
|
||
39 | break;
|
||
40 | case "/": |
||
41 | _4="\\2f";
|
||
42 | break;
|
||
43 | case ":": |
||
44 | _4="\\3a";
|
||
45 | break;
|
||
46 | case "<": |
||
47 | _4="\\3c";
|
||
48 | break;
|
||
49 | case ">": |
||
50 | _4="\\3e";
|
||
51 | break;
|
||
52 | } |
||
53 | _3.append(_4); |
||
54 | } |
||
55 | return _3.toString();
|
||
56 | }; |
||
57 | dojox.xmpp.util.decodeJid=function(_5){ |
||
58 | _5=_5.replace(/\\([23][02367acef])/g,function(_6){ |
||
59 | switch(_6){
|
||
60 | case "\\20": |
||
61 | return " "; |
||
62 | case "\\22": |
||
63 | return "\""; |
||
64 | case "\\23": |
||
65 | return "#"; |
||
66 | case "\\26": |
||
67 | return "&"; |
||
68 | case "\\27": |
||
69 | return "'"; |
||
70 | case "\\2f": |
||
71 | return "/"; |
||
72 | case "\\3a": |
||
73 | return ":"; |
||
74 | case "\\3c": |
||
75 | return "<"; |
||
76 | case "\\3e": |
||
77 | return ">"; |
||
78 | } |
||
79 | return "ARG"; |
||
80 | }); |
||
81 | return _5;
|
||
82 | }; |
||
83 | dojox.xmpp.util.createElement=function(_7,_8,_9){ |
||
84 | var _a=new dojox.string.Builder("<"); |
||
85 | _a.append(_7+" ");
|
||
86 | for(var _b in _8){ |
||
87 | _a.append(_b+"=\"");
|
||
88 | _a.append(_8[_b]); |
||
89 | _a.append("\" ");
|
||
90 | } |
||
91 | if(_9){
|
||
92 | _a.append("/>");
|
||
93 | }else{
|
||
94 | _a.append(">");
|
||
95 | } |
||
96 | return _a.toString();
|
||
97 | }; |
||
98 | dojox.xmpp.util.stripHtml=function(_c){ |
||
99 | var re=/<[^>]*?>/gi; |
||
100 | for(var i=0;i<arguments.length;i++){ |
||
101 | } |
||
102 | return _c.replace(re,""); |
||
103 | }; |
||
104 | dojox.xmpp.util.decodeHtmlEntities=function(_d){ |
||
105 | var ta=dojo.doc.createElement("textarea"); |
||
106 | ta.innerHTML=_d.replace(/</g,"<").replace(/>/g,">"); |
||
107 | return ta.value;
|
||
108 | }; |
||
109 | dojox.xmpp.util.htmlToPlain=function(_e){ |
||
110 | _e=dojox.xmpp.util.decodeHtmlEntities(_e); |
||
111 | _e=_e.replace(/<br\s*[i\/]{0,1}>/gi,"\n"); |
||
112 | _e=dojox.xmpp.util.stripHtml(_e); |
||
113 | return _e;
|
||
114 | }; |
||
115 | dojox.xmpp.util.Base64={}; |
||
116 | dojox.xmpp.util.Base64.encode=function(_f){ |
||
117 | var s2b=function(s){ |
||
118 | var b=[];
|
||
119 | for(var i=0;i<s.length;++i){ |
||
120 | b.push(s.charCodeAt(i)); |
||
121 | } |
||
122 | return b;
|
||
123 | }; |
||
124 | return dojox.encoding.base64.encode(s2b(_f));
|
||
125 | }; |
||
126 | dojox.xmpp.util.Base64.decode=function(_10){ |
||
127 | var b2s=function(b){ |
||
128 | var s=[];
|
||
129 | dojo.forEach(b,function(c){
|
||
130 | s.push(String.fromCharCode(c)); |
||
131 | }); |
||
132 | return s.join(""); |
||
133 | }; |
||
134 | return b2s(dojox.encoding.base64.decode(_10));
|
||
135 | }; |
||
136 | } |