[Dojo-checkins] kzyp - r15179 - in dojox/trunk: cometd data json json/tests rpc
dojo-checkins-admin at dojotoolkit.org
dojo-checkins-admin at dojotoolkit.org
Mon Sep 8 18:11:08 UTC 2008
Author: kzyp
Date: Mon Sep 8 11:11:05 2008
New Revision: 15179
Modified:
dojox/trunk/cometd/RestChannels.js
dojox/trunk/data/restListener.js
dojox/trunk/json/ref.js
dojox/trunk/json/tests/ref.js
dojox/trunk/rpc/JsonRest.js
Log:
Fixed a problem with absolute URL/id handling (with dots in the host name) and remove console.log statements
Modified: dojox/trunk/cometd/RestChannels.js
==============================================================================
--- dojox/trunk/cometd/RestChannels.js (original)
+++ dojox/trunk/cometd/RestChannels.js Mon Sep 8 11:11:05 2008
@@ -93,14 +93,12 @@
if(!this.connected){
this.connectionId = dojox._clientId;
var clientIdHeader = this.started ? 'X-Client-Id' : 'X-Create-Client-Id';
- console.log("opening connection");
var headers = {Accept:this.acceptType};
headers[clientIdHeader] = this.connectionId;
var dfd = dojo.xhrPost({headers:headers, url: this.url, noStatus: true});
var self = this;
this.lastIndex = 0;
var onerror, onprogress = function(data){ // get all the possible event handlers
- console.log("xhr.status", xhr.status);
if(typeof dojo == 'undefined'){
return null;// this can be called after dojo is unloaded, just do nothing in that case
}
Modified: dojox/trunk/data/restListener.js
==============================================================================
--- dojox/trunk/data/restListener.js (original)
+++ dojox/trunk/data/restListener.js Mon Sep 8 11:11:05 2008
@@ -18,7 +18,8 @@
idPrefix: service.servicePath,
idAttribute: jr.getIdAttribute(service),
schemas: jr.schemas,
- loader: jr._loader
+ loader: jr._loader,
+ assignAbsoluteIds: true
});
var target = dojox.rpc.Rest._index && dojox.rpc.Rest._index[channel];
var onEvent = 'on' + message.event.toLowerCase();
Modified: dojox/trunk/json/ref.js
==============================================================================
--- dojox/trunk/json/ref.js (original)
+++ dojox/trunk/json/ref.js Mon Sep 8 11:11:05 2008
@@ -33,6 +33,9 @@
// index as "/Table/4".
// The *idAttribute* parameter.
// This indicates what property is the identity property. This defaults to "id"
+ // The *assignAbsoluteIds* parameter.
+ // This indicates that the resolveJson should assign absolute ids (__id) as the objects are being parsed.
+ //
// The *schemas* parameter
// This provides a map of schemas, from which prototypes can be retrieved
// The *loader* parameter
@@ -42,6 +45,7 @@
args = args || {};
var idAttribute = args.idAttribute || 'id';
var prefix = args.idPrefix || '/';
+ var assignAbsoluteIds = args.assignAbsoluteIds;
var index = args.index || {}; // create an index if one doesn't exist
var ref,reWalk=[];
var pathResolveRegex = /^(.*\/)?(\w+:\/\/)|[^\/\.]+\/\.\.\/|^.*\/(\/)/;
@@ -54,7 +58,9 @@
}
var target = it;
if(id !== undefined){ // if there is an id available...
- it.__id = id;
+ if(assignAbsoluteIds){
+ it.__id = id;
+ }
// if the id already exists in the system, we should use the existing object, and just
// update it... as long as the object is compatible
if(index[id] && ((it instanceof Array) == (index[id] instanceof Array))){
@@ -81,14 +87,14 @@
ref=val.$ref;
if(ref){ // a reference was found
var stripped = ref.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');// trim it
- if(/[\w\[\]\.\$ \/\r\n\t]/.test(stripped) && !/\=|((^|\W)new\W)/.test(stripped)){
+ if(/[\w\[\]\.\$# \/\r\n\t]/.test(stripped) && !/\=|((^|\W)new\W)/.test(stripped)){
// make sure it is a safe reference
delete it[i];// remove the property so it doesn't resolve to itself in the case of id.propertyName lazy values
- var path = ref.match(/(^\.*[^\.\[]+)([\.\[].*)?/); // divide along the path
- if((ref = (path[1]=='$' || path[1]=='this') ? root : index[(prefix + path[1]).replace(pathResolveRegex,'$2$3')]) && // a $ indicates to start with the root, otherwise start with an id
+ var path = ref.match(/(^([^\[]*\/)?[^\.\[]*)([\.\[].*)?/); // divide along the path
+ if((ref = (path[1]=='$' || path[1]=='this' || path[1]=='#') ? root : index[(prefix + path[1]).replace(pathResolveRegex,'$2$3')]) && // a $ indicates to start with the root, otherwise start with an id
// // starting point was found, use eval to resolve remaining property references
// // need to also make reserved words safe by replacing with index operator
- (ref = path[2] ? eval('ref' + path[2].replace(/\.([^\.]+)/g,'["$1"]')) : ref)){
+ (ref = path[3] ? eval('ref' + path[3].replace(/^#/,'').replace(/\.([^\.]+)/g,'["$1"]')) : ref)){
// otherwise, no starting point was found (id not found), if stop is set, it does not exist, we have
// unloaded reference, if stop is not set, it may be in a part of the graph not walked yet,
// we will wait for the second loop
@@ -209,10 +215,10 @@
}
var id = it.__id;
if(id){ // we found an identifiable object, we will just serialize a reference to it... unless it is the root
- if(path != '$' && (useRefs || paths[id])){
+ if(path != '#' && (useRefs || paths[id])){
var ref = id; // a pure path based reference, leave it alone
- if(id.charAt(0)!='$'){
+ if(id.charAt(0)!='#'){
if(id.substring(0, idPrefix.length) == idPrefix){ // see if the reference is in the current context
// a reference with a prefix matching the current context, the prefix should be removed
ref = id.substring(idPrefix.length);
@@ -248,6 +254,9 @@
}
var output = [];
+ if(path && !path.match(/#/)){
+ path += '#';
+ }
for(var i in it){
if(it.hasOwnProperty(i)){
var keyStr;
@@ -276,7 +285,7 @@
return dojo.toJson(it); // use the default serializer for primitives
}
- var json = serialize(it,'$','');
+ var json = serialize(it,'#','');
if(!assignPaths){
for(i in paths) {// cleanup the temporary path-generated ids
delete paths[i].__id;
Modified: dojox/trunk/json/tests/ref.js
==============================================================================
--- dojox/trunk/json/tests/ref.js (original)
+++ dojox/trunk/json/tests/ref.js Mon Sep 8 11:11:05 2008
@@ -3,7 +3,7 @@
doh.register("dojox.json.tests.ref", [
function fromRefJson(t) {
- var testStr = '{a:{$ref:"$"},id:"root",c:{d:"e",f:{$ref:"root.c"}},b:{$ref:"$.c"}}';
+ var testStr = '{a:{$ref:"#"},id:"root",c:{d:"e",f:{$ref:"root.c"}},b:{$ref:"#.c"}}';
var mirrorObj = dojox.json.ref.fromJson(testStr);
t.assertEqual(mirrorObj, mirrorObj.a);
Modified: dojox/trunk/rpc/JsonRest.js
==============================================================================
--- dojox/trunk/rpc/JsonRest.js (original)
+++ dojox/trunk/rpc/JsonRest.js Mon Sep 8 11:11:05 2008
@@ -226,7 +226,7 @@
// absoluteId:
// This is the absolute id of the object
var parts = absoluteId.match(/^(.*\/)([^\/]*)$/);
- var svc = jr.services[parts[1]] || new dojox.rpc.Rest(parts[1]); // use an existing or create one
+ var svc = jr.services[parts[1]] || new dojox.rpc.Rest(parts[1], true); // use an existing or create one
return { service: svc, id:parts[2] };
},
services:{},
@@ -268,7 +268,8 @@
idPrefix: service.servicePath,
idAttribute: jr.getIdAttribute(service),
schemas: jr.schemas,
- loader: jr._loader
+ loader: jr._loader,
+ assignAbsoluteIds: true
});
});
return deferred;
More information about the Dojo-checkins
mailing list