Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

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