1 | /** |
---|
2 | * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. |
---|
3 | * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior |
---|
4 | * |
---|
5 | * This program is free software: you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU Affero General Public License as |
---|
7 | * published by the Free Software Foundation, either version 3 of the |
---|
8 | * License, or (at your option) any later version. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU Affero General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU Affero General Public License |
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | */ |
---|
18 | |
---|
19 | /******************************************************************************\ |
---|
20 | * |
---|
21 | * This product was developed by |
---|
22 | * |
---|
23 | * SERVIÃO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), |
---|
24 | * |
---|
25 | * a government company established under Brazilian law (5.615/70), |
---|
26 | * at Department of Development of Porto Alegre. |
---|
27 | * |
---|
28 | \******************************************************************************/ |
---|
29 | <!-- |
---|
30 | function cxf_cors_request_object(){ |
---|
31 | this.clientid = null; |
---|
32 | this.clientversion = null; |
---|
33 | this.clientagent = null; |
---|
34 | this.clientcompatible = false; |
---|
35 | this.type = null; |
---|
36 | this.handler = null; |
---|
37 | this.data = null; |
---|
38 | this.timeout = 10000; |
---|
39 | } |
---|
40 | |
---|
41 | //Initialize object method |
---|
42 | cxf_cors_request_object.prototype.init = function(){ |
---|
43 | try{ |
---|
44 | this.getClient(); |
---|
45 | this.validateClient(); |
---|
46 | if(this.clientcompatible){ |
---|
47 | this.setCoreHandler(); |
---|
48 | //window.alert('this.handler native type = ' + typeof(this.handler) + '\nthis.type = ' + this.type); |
---|
49 | //this.setHandlers(callbackOK, callbackFailure, arrayargs); |
---|
50 | } |
---|
51 | else |
---|
52 | throw "00-CLIENT_INCOMPATIBLE"; |
---|
53 | } |
---|
54 | catch(e){ |
---|
55 | window.alert('cxf_cors_request_object "init" exception caught: ' + ((e.message)?e.message:e)); |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | //Get client browser data for CORS/XHR level2 support |
---|
60 | cxf_cors_request_object.prototype.getClient = function(){ |
---|
61 | try{ |
---|
62 | this.clientagent = navigator.userAgent; |
---|
63 | //IE match |
---|
64 | if (/MSIE (\d+\.\d+);/.test(this.clientagent)){ |
---|
65 | this.clientid = 'IE'; |
---|
66 | var ieversion=new Number(RegExp.$1) |
---|
67 | this.clientversion = ieversion; |
---|
68 | } |
---|
69 | //Firefox match |
---|
70 | else{ |
---|
71 | if (/Firefox[\/\s](\d+\.\d+)/.test(this.clientagent)){ |
---|
72 | this.clientid = 'FF'; |
---|
73 | var ffversion=new Number(RegExp.$1) |
---|
74 | this.clientversion = ffversion; |
---|
75 | } |
---|
76 | //Chrome match |
---|
77 | else{ |
---|
78 | if (/Chrome[\/\s](\d+\.\d+)/.test(this.clientagent)){ |
---|
79 | this.clientid = 'CR'; |
---|
80 | var crversion=new Number(RegExp.$1) |
---|
81 | this.clientversion = crversion; |
---|
82 | } |
---|
83 | //Safari match |
---|
84 | else{ |
---|
85 | if (/Safari[\/\s](\d+\.\d+)/.test(this.clientagent)){ |
---|
86 | this.clientid = 'SF'; |
---|
87 | var sfversion=new Number(RegExp.$1) |
---|
88 | this.clientversion = sfversion; |
---|
89 | } |
---|
90 | //Other browser with CORS2/xdomain support, should be added here |
---|
91 | else |
---|
92 | throw "01-GET_CLIENT_FAIL"; |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|
96 | } |
---|
97 | catch(e){ |
---|
98 | window.alert('cxf_cors_request_object "getClient" exception caught = ' + ((e.message)?e.message:e)); |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | //Validate client browser support method |
---|
103 | cxf_cors_request_object.prototype.validateClient = function(){ |
---|
104 | try{ |
---|
105 | switch(this.clientid){ |
---|
106 | case 'IE': |
---|
107 | if (this.clientversion>=8) |
---|
108 | this.clientcompatible = true; //only ie 8/9 supports cors2/xdomain |
---|
109 | else |
---|
110 | this.clientcompatible = false; |
---|
111 | break; |
---|
112 | case 'FF': |
---|
113 | if(this.clientversion>=3) |
---|
114 | this.clientcompatible = true; //only ff 3.5/4/5 supports cors2/xdomain |
---|
115 | else |
---|
116 | this.clientcompatible = false; |
---|
117 | break; |
---|
118 | case 'CR': |
---|
119 | if(this.clientversion>=13) |
---|
120 | this.clientcompatible = true; //only cr 13/14 supports cors2/xdomain |
---|
121 | else |
---|
122 | this.clientcompatible = false; |
---|
123 | break; |
---|
124 | case 'SF': |
---|
125 | if(this.clientversion>=5) |
---|
126 | this.clientcompatible = true; //only sf 5 supports cors2/xdomain |
---|
127 | else |
---|
128 | this.clientcompatible = false; |
---|
129 | break; |
---|
130 | default: |
---|
131 | this.clientcompatible = false; |
---|
132 | throw "02-CLIENT_VALIDATE_FAIL"; |
---|
133 | } |
---|
134 | } |
---|
135 | catch(e){ |
---|
136 | window.alert('cxf_cors_request_object "validateClient" exception caught: ' + ((e.message)?e.message:e)); |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | //Sets core request handler object |
---|
141 | cxf_cors_request_object.prototype.setCoreHandler = function(){ |
---|
142 | try{ |
---|
143 | //MS IE-8.0, IE-9.0 & compatibles |
---|
144 | if (window.XDomainRequest){ |
---|
145 | var xdrhandler = new XDRAdapter(); |
---|
146 | this.handler = xdrhandler.getHandler(); |
---|
147 | this.type = 'MS-XDR'; |
---|
148 | } |
---|
149 | else |
---|
150 | throw "03-SET_COREHANDLER_MS_FAIL"; |
---|
151 | } |
---|
152 | catch (e){ |
---|
153 | try{ |
---|
154 | //Mozilla 3.5 >= and derivates api compatibles |
---|
155 | if (window.XMLHttpRequest){ |
---|
156 | var xhr2 = new XMLHttpRequest(); |
---|
157 | if ("withCredentials" in xhr2){//XMLHttpRequest Level 2, cors support on |
---|
158 | this.handler = xhr2; |
---|
159 | this.type='MZ-XHR'; |
---|
160 | } |
---|
161 | else{ |
---|
162 | this.type = 'MZ-LV1';//XMLHttpRequest Level 1 object, no cors support |
---|
163 | this.handler = null; |
---|
164 | } |
---|
165 | } |
---|
166 | //Ops: no CORS suported on client browser |
---|
167 | else |
---|
168 | throw "03-SET_COREHANDLER_MZ_FAIL"; |
---|
169 | } |
---|
170 | catch (e){ |
---|
171 | window.alert('\nO seu navegador nao esta configurado para utilizar os recursos Ajax da plataforma. Habilite-o ou atualize seu navegador.\nErro = ' + ((e.message)?e.message:e)); |
---|
172 | this.handler = null; |
---|
173 | this.type = null; |
---|
174 | } |
---|
175 | } |
---|
176 | } |
---|
177 | --> |
---|