Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1318 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.data.old.provider.FlatFile");
13
dojo.provide("dojo.data.old.provider.FlatFile");
12
dojo.require("dojo.data.old.provider.Base");
14
dojo.require("dojo.data.old.provider.Base");
13
dojo.require("dojo.data.old.Item");
15
dojo.require("dojo.data.old.Item");
14
dojo.require("dojo.data.old.Attribute");
16
dojo.require("dojo.data.old.Attribute");
15
dojo.require("dojo.data.old.ResultSet");
17
dojo.require("dojo.data.old.ResultSet");
16
dojo.require("dojo.data.old.format.Json");
18
dojo.require("dojo.data.old.format.Json");
17
dojo.require("dojo.data.old.format.Csv");
19
dojo.require("dojo.data.old.format.Csv");
18
dojo.require("dojo.lang.assert");
20
dojo.require("dojo.lang.assert");
19
dojo.data.old.provider.FlatFile = function (keywordParameters) {
21
dojo.data.old.provider.FlatFile = function (keywordParameters) {
20
	dojo.lang.assertType(keywordParameters, "pureobject", {optional:true});
22
	dojo.lang.assertType(keywordParameters, "pureobject", {optional:true});
21
	dojo.data.old.provider.Base.call(this);
23
	dojo.data.old.provider.Base.call(this);
22
	this._arrayOfItems = [];
24
	this._arrayOfItems = [];
23
	this._resultSet = null;
25
	this._resultSet = null;
24
	this._dictionaryOfAttributes = {};
26
	this._dictionaryOfAttributes = {};
25
	if (keywordParameters) {
27
	if (keywordParameters) {
26
		var jsonObjects = keywordParameters["jsonObjects"];
28
		var jsonObjects = keywordParameters["jsonObjects"];
27
		var jsonString = keywordParameters["jsonString"];
29
		var jsonString = keywordParameters["jsonString"];
28
		var fileUrl = keywordParameters["url"];
30
		var fileUrl = keywordParameters["url"];
29
		if (jsonObjects) {
31
		if (jsonObjects) {
30
			dojo.data.old.format.Json.loadDataProviderFromArrayOfJsonData(this, jsonObjects);
32
			dojo.data.old.format.Json.loadDataProviderFromArrayOfJsonData(this, jsonObjects);
31
		}
33
		}
32
		if (jsonString) {
34
		if (jsonString) {
33
			dojo.data.old.format.Json.loadDataProviderFromFileContents(this, jsonString);
35
			dojo.data.old.format.Json.loadDataProviderFromFileContents(this, jsonString);
34
		}
36
		}
35
		if (fileUrl) {
37
		if (fileUrl) {
36
			var arrayOfParts = fileUrl.split(".");
38
			var arrayOfParts = fileUrl.split(".");
37
			var lastPart = arrayOfParts[(arrayOfParts.length - 1)];
39
			var lastPart = arrayOfParts[(arrayOfParts.length - 1)];
38
			var formatParser = null;
40
			var formatParser = null;
39
			if (lastPart == "json") {
41
			if (lastPart == "json") {
40
				formatParser = dojo.data.old.format.Json;
42
				formatParser = dojo.data.old.format.Json;
41
			}
43
			}
42
			if (lastPart == "csv") {
44
			if (lastPart == "csv") {
43
				formatParser = dojo.data.old.format.Csv;
45
				formatParser = dojo.data.old.format.Csv;
44
			}
46
			}
45
			if (formatParser) {
47
			if (formatParser) {
46
				var fileContents = dojo.hostenv.getText(fileUrl);
48
				var fileContents = dojo.hostenv.getText(fileUrl);
47
				formatParser.loadDataProviderFromFileContents(this, fileContents);
49
				formatParser.loadDataProviderFromFileContents(this, fileContents);
48
			} else {
50
			} else {
49
				dojo.lang.assert(false, "new dojo.data.old.provider.FlatFile({url: }) was passed a file without a .csv or .json suffix");
51
				dojo.lang.assert(false, "new dojo.data.old.provider.FlatFile({url: }) was passed a file without a .csv or .json suffix");
50
			}
52
			}
51
		}
53
		}
52
	}
54
	}
53
};
55
};
54
dojo.inherits(dojo.data.old.provider.FlatFile, dojo.data.old.provider.Base);
56
dojo.inherits(dojo.data.old.provider.FlatFile, dojo.data.old.provider.Base);
55
dojo.data.old.provider.FlatFile.prototype.getProviderCapabilities = function (keyword) {
57
dojo.data.old.provider.FlatFile.prototype.getProviderCapabilities = function (keyword) {
56
	dojo.lang.assertType(keyword, String, {optional:true});
58
	dojo.lang.assertType(keyword, String, {optional:true});
57
	if (!this._ourCapabilities) {
59
	if (!this._ourCapabilities) {
58
		this._ourCapabilities = {transactions:false, undo:false, login:false, versioning:false, anonymousRead:true, anonymousWrite:false, permissions:false, queries:false, strongTyping:false, datatypes:[String, Date, Number]};
60
		this._ourCapabilities = {transactions:false, undo:false, login:false, versioning:false, anonymousRead:true, anonymousWrite:false, permissions:false, queries:false, strongTyping:false, datatypes:[String, Date, Number]};
59
	}
61
	}
60
	if (keyword) {
62
	if (keyword) {
61
		return this._ourCapabilities[keyword];
63
		return this._ourCapabilities[keyword];
62
	} else {
64
	} else {
63
		return this._ourCapabilities;
65
		return this._ourCapabilities;
64
	}
66
	}
65
};
67
};
66
dojo.data.old.provider.FlatFile.prototype.registerAttribute = function (attributeId) {
68
dojo.data.old.provider.FlatFile.prototype.registerAttribute = function (attributeId) {
67
	var registeredAttribute = this.getAttribute(attributeId);
69
	var registeredAttribute = this.getAttribute(attributeId);
68
	if (!registeredAttribute) {
70
	if (!registeredAttribute) {
69
		var newAttribute = new dojo.data.old.Attribute(this, attributeId);
71
		var newAttribute = new dojo.data.old.Attribute(this, attributeId);
70
		this._dictionaryOfAttributes[attributeId] = newAttribute;
72
		this._dictionaryOfAttributes[attributeId] = newAttribute;
71
		registeredAttribute = newAttribute;
73
		registeredAttribute = newAttribute;
72
	}
74
	}
73
	return registeredAttribute;
75
	return registeredAttribute;
74
};
76
};
75
dojo.data.old.provider.FlatFile.prototype.getAttribute = function (attributeId) {
77
dojo.data.old.provider.FlatFile.prototype.getAttribute = function (attributeId) {
76
	var attribute = (this._dictionaryOfAttributes[attributeId] || null);
78
	var attribute = (this._dictionaryOfAttributes[attributeId] || null);
77
	return attribute;
79
	return attribute;
78
};
80
};
79
dojo.data.old.provider.FlatFile.prototype.getAttributes = function () {
81
dojo.data.old.provider.FlatFile.prototype.getAttributes = function () {
80
	var arrayOfAttributes = [];
82
	var arrayOfAttributes = [];
81
	for (var key in this._dictionaryOfAttributes) {
83
	for (var key in this._dictionaryOfAttributes) {
82
		var attribute = this._dictionaryOfAttributes[key];
84
		var attribute = this._dictionaryOfAttributes[key];
83
		arrayOfAttributes.push(attribute);
85
		arrayOfAttributes.push(attribute);
84
	}
86
	}
85
	return arrayOfAttributes;
87
	return arrayOfAttributes;
86
};
88
};
87
dojo.data.old.provider.FlatFile.prototype.fetchArray = function (query) {
89
dojo.data.old.provider.FlatFile.prototype.fetchArray = function (query) {
88
	return this._arrayOfItems;
90
	return this._arrayOfItems;
89
};
91
};
90
dojo.data.old.provider.FlatFile.prototype.fetchResultSet = function (query) {
92
dojo.data.old.provider.FlatFile.prototype.fetchResultSet = function (query) {
91
	if (!this._resultSet) {
93
	if (!this._resultSet) {
92
		this._resultSet = new dojo.data.old.ResultSet(this, this.fetchArray(query));
94
		this._resultSet = new dojo.data.old.ResultSet(this, this.fetchArray(query));
93
	}
95
	}
94
	return this._resultSet;
96
	return this._resultSet;
95
};
97
};
96
dojo.data.old.provider.FlatFile.prototype._newItem = function () {
98
dojo.data.old.provider.FlatFile.prototype._newItem = function () {
97
	var item = new dojo.data.old.Item(this);
99
	var item = new dojo.data.old.Item(this);
98
	this._arrayOfItems.push(item);
100
	this._arrayOfItems.push(item);
99
	return item;
101
	return item;
100
};
102
};
101
dojo.data.old.provider.FlatFile.prototype._newAttribute = function (attributeId) {
103
dojo.data.old.provider.FlatFile.prototype._newAttribute = function (attributeId) {
102
	dojo.lang.assertType(attributeId, String);
104
	dojo.lang.assertType(attributeId, String);
103
	dojo.lang.assert(this.getAttribute(attributeId) === null);
105
	dojo.lang.assert(this.getAttribute(attributeId) === null);
104
	var attribute = new dojo.data.old.Attribute(this, attributeId);
106
	var attribute = new dojo.data.old.Attribute(this, attributeId);
105
	this._dictionaryOfAttributes[attributeId] = attribute;
107
	this._dictionaryOfAttributes[attributeId] = attribute;
106
	return attribute;
108
	return attribute;
107
};
109
};
108
dojo.data.old.provider.Base.prototype._getResultSets = function () {
110
dojo.data.old.provider.Base.prototype._getResultSets = function () {
109
	return [this._resultSet];
111
	return [this._resultSet];
110
};
112
};
111
 
113