/** * CPAINT - Cross-Platform Asynchronous INterface Toolkit * * http://sf.net/projects/cpaint * * released under the terms of the LGPL * see http://www.fsf.org/licensing/licenses/lgpl.txt for details * * @package CPAINT * @access public * @copyright Copyright (c) 2005-2006 Paul Sullivan, Dominique Stender - http://sf.net/projects/cpaint * @author Paul Sullivan * @author Dominique Stender * @version $Id$ */ function cpaint(){this.version='2.0.2';var config=new Array();config['debugging']=0;config['proxy_url']='';config['transfer_mode']='GET';config['async']=true;config['response_type']='OBJECT';config['persistent_connection']=false;config['use_cpaint_api']=true;var stack_count=0;this.capable=test_ajax_capability();this.set_debug=function(){if(typeof arguments[0]=='boolean'){if(arguments[0]===true){config['debugging']=1;}else{config['debugging']=0;}}else if(typeof arguments[0]=='number'){config['debugging']=Math.round(arguments[0]);}} this.set_proxy_url=function(){if(typeof arguments[0]=='string'){config['proxy_url']=arguments[0];}} this.set_transfer_mode=function(){if(arguments[0].toUpperCase()=='GET'||arguments[0].toUpperCase()=='POST'){config['transfer_mode']=arguments[0].toUpperCase();}} this.set_async=function(){if(typeof arguments[0]=='boolean'){config['async']=arguments[0];}} this.set_response_type=function(){if(arguments[0].toUpperCase()=='TEXT'||arguments[0].toUpperCase()=='XML'||arguments[0].toUpperCase()=='OBJECT'||arguments[0].toUpperCase()=='E4X'||arguments[0].toUpperCase()=='JSON'){config['response_type']=arguments[0].toUpperCase();}} this.set_persistent_connection=function(){if(typeof arguments[0]=='boolean'){config['persistent_connection']=arguments[0];}} this.set_use_cpaint_api=function(){if(typeof arguments[0]=='boolean'){config['use_cpaint_api']=arguments[0];}} function test_ajax_capability(){var cpc=new cpaint_call(0,config,this.version);return cpc.test_ajax_capability();} this.call=function(){var use_stack=-1;if(config['persistent_connection']==true&&__cpaint_stack[0]!=null){switch(__cpaint_stack[0].get_http_state()){case-1:use_stack=0;debug('no XMLHttpObject object to re-use for persistence, creating new one later',2);break;case 4:use_stack=0 debug('re-using the persistent connection',2);break;default:debug('the persistent connection is in use - skipping this request',2);}}else if(config['persistent_connection']==true){use_stack=0;__cpaint_stack[use_stack]=new cpaint_call(use_stack,config,this.version);debug('no cpaint_call object available for re-use, created new one',2);}else{use_stack=stack_count;__cpaint_stack[use_stack]=new cpaint_call(use_stack,config,this.version);debug('no cpaint_call object created new one',2);} if(use_stack!=-1){__cpaint_stack[use_stack].set_client_callback(arguments[2]);if(config['proxy_url']!=''){__cpaint_stack[use_stack].call_proxy(arguments);}else{__cpaint_stack[use_stack].call_direct(arguments);} stack_count++;debug('stack size: '+__cpaint_stack.length,2);}} var debug=function(message,debug_level){var prefix='[CPAINT Debug] ';if(debug_level<1){prefix='[CPAINT Error] ';} if(config['debugging']>=debug_level){alert(prefix+message);}}} var __cpaint_stack=new Array();var __cpaint_transformer=new cpaint_transformer();function cpaint_call(){var version=arguments[2];var config=new Array();config['debugging']=arguments[1]['debugging'];config['proxy_url']=arguments[1]['proxy_url'];config['transfer_mode']=arguments[1]['transfer_mode'];config['async']=arguments[1]['async'];config['response_type']=arguments[1]['response_type'];config['persistent_connection']=arguments[1]['persistent_connection'];config['use_cpaint_api']=arguments[1]['use_cpaint_api'];var httpobj=false;var client_callback;var stack_id=arguments[0];this.set_client_callback=function(){if(typeof arguments[0]=='function'){client_callback=arguments[0];}} this.get_http_state=function(){var return_value=-1;if(typeof httpobj=='object'){return_value=httpobj.readyState;} return return_value;} this.call_direct=function(call_arguments){var url=call_arguments[0];var remote_method=call_arguments[1];var querystring='';var i=0;if(url=='SELF'){url=document.location.href;} if(config['use_cpaint_api']==true){for(i=3;i=debug_level){alert(prefix+message);}}} function cpaint_transformer(){this.object_conversion=function(xml_document){var return_value=new cpaint_result_object();var i=0;var firstNodeName='';if(typeof xml_document=='object'&&xml_document!=null){for(i=0;i]+\>/,'');return new XML(text);} this.json_conversion=function(text){return JSON.parse(text);} var create_object_structure=function(stream){var return_value=new cpaint_result_object();var node_name='';var i=0;var attrib=0;if(stream.hasChildNodes()==true){for(i=0;i=' '){if(c=='\\'||c=='"'){s+='\\';} s+=c;}else{switch(c){case'\b':s+='\\b';break;case'\f':s+='\\f';break;case'\n':s+='\\n';break;case'\r':s+='\\r';break;case'\t':s+='\\t';break;default:c=c.charCodeAt();s+='\\u00'+Math.floor(c/16).toString(16)+ (c%16).toString(16);}}} return s+'"';case'boolean':return String(arg);default:return'null';}},parse:function(text){var at=0;var ch=' ';function error(m){throw{name:'JSONError',message:m,at:at-1,text:text};} function next(){ch=text.charAt(at);at+=1;return ch;} function white(){while(ch!=''&&ch<=' '){next();}} function str(){var i,s='',t,u;if(ch=='"'){outer:while(next()){if(ch=='"'){next();return s;}else if(ch=='\\'){switch(next()){case'b':s+='\b';break;case'f':s+='\f';break;case'n':s+='\n';break;case'r':s+='\r';break;case't':s+='\t';break;case'u':u=0;for(i=0;i<4;i+=1){t=parseInt(next(),16);if(!isFinite(t)){break outer;} u=u*16+t;} s+=String.fromCharCode(u);break;default:s+=ch;}}else{s+=ch;}}} error("Bad string");} function arr(){var a=[];if(ch=='['){next();white();if(ch==']'){next();return a;} while(ch){a.push(val());white();if(ch==']'){next();return a;}else if(ch!=','){break;} next();white();}} error("Bad array");} function obj(){var k,o={};if(ch=='{'){next();white();if(ch=='}'){next();return o;} while(ch){k=str();white();if(ch!=':'){break;} next();o[k]=val();white();if(ch=='}'){next();return o;}else if(ch!=','){break;} next();white();}} error("Bad object");} function assoc(){var k,a=[];if(ch=='<'){next();white();if(ch=='>'){next();return a;} while(ch){k=str();white();if(ch!=':'){break;} next();a[k]=val();white();if(ch=='>'){next();return a;}else if(ch!=','){break;} next();white();}} error("Bad associative array");} function num(){var n='',v;if(ch=='-'){n='-';next();} while(ch>='0'&&ch<='9'){n+=ch;next();} if(ch=='.'){n+='.';while(next()&&ch>='0'&&ch<='9'){n+=ch;}} if(ch=='e'||ch=='E'){n+='e';next();if(ch=='-'||ch=='+'){n+=ch;next();} while(ch>='0'&&ch<='9'){n+=ch;next();}} v=+n;if(!isFinite(v)){error("Bad number");}else{return v;}} function word(){switch(ch){case't':if(next()=='r'&&next()=='u'&&next()=='e'){next();return true;} break;case'f':if(next()=='a'&&next()=='l'&&next()=='s'&&next()=='e'){next();return false;} break;case'n':if(next()=='u'&&next()=='l'&&next()=='l'){next();return null;} break;} error("Syntax error");} function val(){white();switch(ch){case'{':return obj();case'[':return arr();case'<':return assoc();case'"':return str();case'-':return num();default:return ch>='0'&&ch<='9'?num():word();}} return val();}};