-
- function checkData(data) {
- if ( data !== undefined ) {
- var testFunction = s.dataCheckers[srcDataType];
- if ( isFunction( testFunction ) ) {
- testFunction(data);
- }
- }
- }
-
- function convertData (data) {
- var conversionFunction = dataConverters[srcDataType+" => "+destDataType] ||
- dataConverters["* => "+destDataType],
- noFunction = ! isFunction( conversionFunction );
- if ( noFunction ) {
- if ( srcDataType != "text" && destDataType != "text" ) {
- // We try to put text inbetween
- var first = dataConverters[srcDataType+" => text"] ||
- dataConverters["* => text"],
- second = dataConverters["text => "+destDataType] ||
- dataConverters["* => "+destDataType],
- areFunctions = isFunction( first ) && isFunction( second );
- if ( areFunctions ) {
- conversionFunction = function (data) {
- return second( first ( data ) );
- };
+
+ var i,
+ current,
+ prev,
+ checker,
+ conv1,
+ conv2,
+ oneConv,
+ convertion,
+ dataTypes = s.dataTypes,
+ dataCheckers = s.dataCheckers,
+ dataConverters = s.dataConverters,
+ dataFilter = s.dataFilter,
+ responses = {
+ "xml": "XML",
+ "text": "Text"
+ };
+
+ for( i = 0 ; i < dataTypes.length ; i++ ) {
+
+ current = dataTypes[ i ];
+
+ if ( i ) {
+
+ prev = dataTypes[ i - 1 ];
+
+ if ( prev === "*" ) {
+
+ prev = current;
+
+ } else if ( current !== "*" && prev !== current ) {
+
+ oneConv = conv1 =
+ dataConverters[ ( conversion = prev + " => " + current ) ] ||
+ dataConverters[ "* => " + current ];
+
+ if ( ! oneConv && prev !== "text" && current !== "text" ) {
+ conv1 = dataConverters[ prev + " => text" ] || dataConverters[ "* => text" ];
+ conv2 = dataConverters[ "text => " + current ];
+ }
+ if ( oneConv || conv1 && conv2 ) {
+ response = oneConv ? conv1( response ) : conv2( conv1( response ) );
+ } else {
+ throw "no " + conversion;