You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2006/09/23 01:22:51 UTC
svn commit: r449122 [6/40] - in
/tapestry/tapestry4/trunk/tapestry-framework/src: java/org/apache/tapestry/
java/org/apache/tapestry/dojo/ java/org/apache/tapestry/dojo/form/
java/org/apache/tapestry/dojo/html/ java/org/apache/tapestry/form/
java/org/a...
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Read.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Read.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Read.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Read.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,210 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.Read");
+dojo.require("dojo.lang.declare");
+dojo.require("dojo.data.Result");
+dojo.require("dojo.experimental");
+
+
+/* summary:
+ * This is an abstract API that data provider implementations conform to.
+ * This file defines methods signatures and intentionally leaves all the
+ * methods unimplemented.
+ */
+dojo.experimental("dojo.data.Read");
+
+dojo.declare("dojo.data.Read", null, {
+ get:
+ function(/* item */ item, /* attribute or attribute-name-string */ attribute, /* value? */ defaultValue) {
+ /* summary:
+ * Returns a single attribute value.
+ * Returns defaultValue if item does not have a value for attribute.
+ * Returns null if null was explicitly set as the attribute value.
+ * Returns undefined if the item does not have a value for the given attribute.
+ * (So, if store.hasAttribute(item, attribute) returns false, then
+ * store.get(item, attribute) will return undefined.)
+ * exceptions:
+ * Conforming implementations should throw an exception if *item* is not
+ * an item, or *attribute* is neither an attribute object or a string.
+ * examples:
+ * var darthVader = store.get(lukeSkywalker, "father");
+ */
+ dojo.unimplemented('dojo.data.Read.get');
+ var attributeValue = null;
+ return attributeValue; // a literal, an item, null, or undefined (never an array)
+ },
+ getValues:
+ function(/* item */ item, /* attribute or attribute-name-string */ attribute) {
+ /* summary:
+ * This getValues() method works just like the get() method, but getValues()
+ * always returns an array rather than a single attribute value. The array
+ * may be empty, may contain a single attribute value, or may contain many
+ * attribute values.
+ * If the item does not have a value for the given attribute, then getValues()
+ * will return an empty array: []. (So, if store.hasAttribute(item, attribute)
+ * returns false, then store.getValues(item, attribute) will return [].)
+ * exceptions:
+ * Throws an exception if item is not an item, or attribute is neither an
+ * attribute object or a string.
+ * examples:
+ * var friendsOfLuke = store.get(lukeSkywalker, "friends");
+ */
+ dojo.unimplemented('dojo.data.Read.getValues');
+ var array = null;
+ return array; // an array that may contain literals and items
+ },
+ getAttributes:
+ function(/* item */ item) {
+ /* summary:
+ * Returns an array with all the attributes that this item has.
+ * exceptions:
+ * Throws an exception if item is not an item.
+ * examples:
+ * var array = store.getAttributes(kermit);
+ */
+ dojo.unimplemented('dojo.data.Read.getAttributes');
+ var array = null;
+ return array; // array
+ },
+ hasAttribute:
+ function(/* item */ item, /* attribute or attribute-name-string */ attribute) {
+ /* summary:
+ * Returns true if the given *item* has a value or the given *attribute*.
+ * exceptions:
+ * Throws an exception if item is not an item, or attribute is neither an
+ * attribute object or a string.
+ * examples:
+ * var yes = store.hasAttribute(kermit, "color");
+ */
+ dojo.unimplemented('dojo.data.Read.hasAttribute');
+ return false; // boolean
+ },
+ hasAttributeValue:
+ function(/* item */ item, /* attribute or attribute-name-string */ attribute, /* anything */ value) {
+ /* summary:
+ * Returns true if the given *value* is one of the values that getValue()
+ * would return.
+ * issue:
+ * This is really just a convenience-method -- it doesn't add any functionality
+ * that you couldn't do by calling getValues() and looping through the results.
+ * Maybe we should cut this method from the API, or at least move it out of
+ * the basic Read portion of the API?
+ * exceptions:
+ * Throws an exception if item is not an item, or attribute is neither an
+ * attribute object or a string.
+ * examples:
+ * var yes = store.hasAttributeValue(kermit, "color", "green");
+ */
+ dojo.unimplemented('dojo.data.Read.hasAttributeValue');
+ return false; // boolean
+ },
+ isItem:
+ function(/* anything */ something) {
+ /* summary:
+ * Returns true if *something* is an item. Returns false if *something*
+ * is a literal or is any object other than an item.
+ * examples:
+ * var yes = store.isItem(store.newItem());
+ * var no = store.isItem("green");
+ */
+ dojo.unimplemented('dojo.data.Read.isItem');
+ return false; // boolean
+ },
+ find:
+ function(/* implementation-dependent */ query, /* object */ optionalKeywordArgs ) {
+ /* summary:
+ * Given a query, this method returns a Result object containing
+ * all the items in the query result set.
+ * queries:
+ * The query may be optional in some data store implementations.
+ * The dojo.data.Read API does not specify the syntax or semantics
+ * of the query itself -- each different data store implementation
+ * may have its own notion of what a query should look like.
+ * In most implementations the query will probably be a string, but
+ * in some implementations the query might be a Date, or a number,
+ * or some complex keyword parameter object. The dojo.data.Read
+ * API is completely agnostic about what the query actually is.
+ * optionalKeywordArgs:
+ * The optionalKeywordArgs argument is a object like {async: true}.
+ * All implementations should accept {async: true} and {async: false}
+ * as valid parameters, although the API does not require that the
+ * the implementation actually perform asynchronously when
+ * {async: true} is set. Some implementations may take additional
+ * keyword options, such as {async: true, maxResults:100}.
+ * result lists:
+ * A Result object will always be returned, even if the result set
+ * is empty. A Result object will always be returned immediately.
+ * By default the Result object will be fully populated with result
+ * items as soon as it is created (synchronously). The caller may request
+ * an asynchronous Result, meaning a Result that will be populated
+ * with result items at some point in the future. If the caller requests
+ * an asynchronous Result, the data store may return either a synchronous
+ * or asynchronous Result, whichever it prefers. Simple data store
+ * implementations may always return synchronous Results.
+ * For more info about the Result API, see dojo.data.Result
+ * exceptions:
+ * Throws an exception if the query is not valid, or if the query
+ * is required but was not supplied.
+ * examples:
+ * var results = store.find("all books");
+ * var results = store.find();
+ * var results = store.find("foo/bar", {async: true});
+ * var results = store.find("foo/bar", {async: false});
+ * var results = store.find({author:"King", {async: true, maxResults:100});
+ */
+ dojo.unimplemented('dojo.data.Read.find');
+ var result = null; // new dojo.data.Result().
+ return result; // an object that implements dojo.data.Result
+ },
+ getIdentity:
+ function(/* item */ item) {
+ /* summary:
+ * Returns a unique identifer for an item. The return value will be
+ * either a string or something that has a toString() method (such as,
+ * for example, a dojo.uuid.Uuid object).
+ * exceptions:
+ * Conforming implementations may throw an exception or return null if
+ * item is not an item.
+ * issue:
+ * Should we move this method out of dojo.data.Read, and put it somewhere
+ * else, like maybe dojo.data.Identity?
+ * examples:
+ * var itemId = store.getIdentity(kermit);
+ * assert(kermit === store.getByIdentity(store.getIdentity(kermit)));
+ */
+ dojo.unimplemented('dojo.data.Read.getIdentity');
+ var itemIdentifyString = null;
+ return itemIdentifyString; // string
+ },
+ getByIdentity:
+ function(/* string */ id) {
+ /* summary:
+ * Given an the id of an item, this method returns the item that has that id.
+ * Conforming implementations should return null if there is no item with
+ * the given id.
+ * issue:
+ * We may want to change the name from getByIdentity() to findByIdentity(),
+ * to reflect the fact that an implementation may not be able to get the
+ * item from a local cache, and may need to send a request to the server.
+ * issue:
+ * Can this method run asynchronously? Should the return value be a Deferred?
+ * issue:
+ * Should we move this method out of dojo.data.Read, and put it somewhere
+ * else, like maybe dojo.data.Identity?
+ * examples:
+ * var alaska = store.byIdentity("AK");
+ * assert("AK" == store.getIdentity(store.getByIdentity("AK")));
+ */
+ dojo.unimplemented('dojo.data.Read.getByIdentity');
+ var item = null;
+ return item; // item
+ }
+});
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Read.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Result.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Result.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Result.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Result.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,125 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.Result");
+dojo.require("dojo.lang.declare");
+dojo.require("dojo.experimental");
+
+/* summary:
+ * This is an abstract API used by data provider implementations.
+ * This file defines methods signatures and intentionally leaves all the
+ * methods unimplemented.
+ */
+dojo.experimental("dojo.data.Result");
+
+dojo.declare("dojo.data.Result", null, {
+ forEach:
+ function(/* function or object */ functionOrKeywordObject) {
+ /* summary:
+ * Loops through the result list, calling a callback function
+ * for each item in the result list.
+ * description:
+ * The forEach() method will pass two arguments to the callback
+ * function: an item, and the result list object itself.
+ * Returns true if the entire result list has been looped through.
+ * After the forEach() operation has finished (or been cancelled)
+ * result.forEach() can be called again on the same result object.
+ * functionOrKeywordObject:
+ * The forEach() method always takes exactly one argument,
+ * which is either a simple callback function or an object
+ * with keyword parameters. Conforming implementations must
+ * accept 'object' and 'callback' as keyword parameters. If
+ * the caller provides 'object', then the value of 'callback'
+ * must be a string with the name of a method available on that
+ * object. If the caller does not provide 'object', then the
+ * 'callback' value must be a function. Different implementations
+ * may support additional keywords, but implementations are not
+ * required to support anything else.
+ * examples:
+ * var results = store.find("recent books"); // synchronous
+ * var results = store.find("all books", {async: true}); // asynchronous
+ * someCallbackFunction = function(item, resultObject) {};
+ * results.forEach(someCallbackFunction);
+ * results.forEach({object:someHandlerObject, callback:"someCallbackMethod"});
+ * issues:
+ * We haven't yet decided what other parameters we might allow to
+ * support fancy features. Here are some ideas:
+ * results.forEach({callback:callbackFunction, onCompletion: finishedFunction});
+ * results.forEach({callback:callbackFunction, first: 201, last: 300}); // partial loop
+ * results.forEach({callback:callbackFunction, first: 200, numItems: 50}); // partial loop from 200 to 250
+ * CCM: How to specify datastore-specific options to allow caching n
+ * items before/after current window of items being viewed?
+ */
+ dojo.unimplemented('dojo.data.Result.forEach');
+ return false; // boolean
+ },
+ getLength:
+ function() {
+ /* summary:
+ * Returns an integer -- the number of items in the result list.
+ * Returns -1 if the length is not known when the method is called.
+ */
+ dojo.unimplemented('dojo.data.Result.getLength');
+ return -1; // integer
+ },
+ inProgress:
+ function() {
+ /* summary:
+ * Returns true if a forEach() loop is in progress.
+ */
+ dojo.unimplemented('dojo.data.Result.inProgress');
+ return false; // boolean
+ },
+ cancel:
+ function() {
+ /* summary:
+ * If a forEach() loop is in progress, calling cancel() stops
+ * the loop.
+ */
+ dojo.unimplemented('dojo.data.Result.cancel');
+ },
+ addCallback:
+ function(/* function */ callbackFunction) {
+ /* summary:
+ * Allows you to register a callbackFunction that will
+ * be called when all the results are available.
+ * Patterned after dojo.Deferred.addCallback()
+ * issues:
+ * I (Brian) am not clear on exactly how this shoul work:
+ * what parameters it takes, what the return value should
+ * be, whether the callback gets called before or after the
+ * forEach() loop, whether you can chain callbacks (as with
+ * a real Deferred. I'm worried that doing everything that
+ * dojo.Deferred does is too much to ask of basic data-store
+ * implementations like a simple CSV store. Maybe someone
+ * else can suggest simple answers to how addCallback should
+ * work.
+ */
+ dojo.unimplemented('dojo.data.Result.addCallback');
+ },
+ addErrback:
+ function(/* function */ errorCallbackFunction) {
+ /* summary:
+ * Allows you to register a errorCallbackFunction that
+ * will be called if there is any sort of error.
+ * issues:
+ * See the notes under addCallback(), above.
+ */
+ dojo.unimplemented('dojo.data.Result.addErrback');
+ },
+ getStore:
+ function() {
+ /* summary:
+ * Returns the datastore object that created this result list
+ */
+ dojo.unimplemented('dojo.data.Result.getStore');
+ return null; // an object that implements dojo.data.Read
+ }
+});
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Result.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/SimpleStore.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/SimpleStore.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/SimpleStore.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/SimpleStore.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,16 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.SimpleStore");
+dojo.require("dojo.collections.Store");
+
+dojo.deprecated("dojo.data.SimpleStore has been moved to dojo.collections.Store and will be removed before the 0.4 release", "0.4");
+
+dojo.data.SimpleStore = dojo.collections.Store;
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/SimpleStore.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Write.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Write.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Write.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Write.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,152 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.Write");
+dojo.require("dojo.lang.declare");
+dojo.require("dojo.data.Read");
+dojo.require("dojo.experimental");
+
+/* summary:
+ * This is an abstract API that data provider implementations conform to.
+ * This file defines methods signatures and intentionally leaves all the
+ * methods unimplemented.
+ */
+dojo.experimental("dojo.data.Write");
+
+dojo.declare("dojo.data.Write", dojo.data.Read, {
+ newItem:
+ function(/* keyword arguments (optional) */ keywordArgs) {
+ /* summary:
+ * Returns a newly created item. Sets the attributes of the new
+ * item based on the keywordArgs provided.
+ * exceptions:
+ * Throws an exception if *keywordArgs* is a string or a number or
+ * anything other than a simple anonymous object.
+ * examples:
+ * var kermit = store.newItem({name: "Kermit"});
+ */
+ var newItem;
+ dojo.unimplemented('dojo.data.Write.newItem');
+ return newItem; // item
+ },
+ deleteItem:
+ function(/* item */ item) {
+ /* summary:
+ * Deletes an item from the store.
+ * exceptions:
+ * Throws an exception if *item* is not an item (if store.isItem(item)
+ * returns false).
+ * examples:
+ * var success = store.deleteItem(kermit);
+ */
+ dojo.unimplemented('dojo.data.Write.deleteItem');
+ return false; // boolean
+ },
+ set:
+ function(/* item */ item, /* attribute or string */ attribute, /* almost anything */ value) {
+ /* summary:
+ * Sets the value of an attribute on an item.
+ * Replaces any previous value or values.
+ * exceptions:
+ * Throws an exception if *item* is not an item, or if *attribute*
+ * is neither an attribute object or a string.
+ * Throws an exception if *value* is undefined.
+ * examples:
+ * var success = store.set(kermit, "color", "green");
+ */
+ dojo.unimplemented('dojo.data.Write.set');
+ return false; // boolean
+ },
+ setValues:
+ function(/* item */ item, /* attribute or string */ attribute, /* array */ values) {
+ /* summary:
+ * Adds each value in the *values* array as a value of the given
+ * attribute on the given item.
+ * Replaces any previous value or values.
+ * Calling store.setValues(x, y, []) (with *values* as an empty array) has
+ * the same effect as calling store.clear(x, y).
+ * exceptions:
+ * Throws an exception if *values* is not an array, if *item* is not an
+ * item, or if *attribute* is neither an attribute object or a string.
+ * examples:
+ * var success = store.setValues(kermit, "color", ["green", "aqua"]);
+ * success = store.setValues(kermit, "color", []);
+ * if (success) {assert(!store.hasAttribute(kermit, "color"));}
+ */
+ dojo.unimplemented('dojo.data.Write.setValues');
+ return false; // boolean
+ },
+ clear:
+ function(/* item */ item, /* attribute or string */ attribute) {
+ /* summary:
+ * Deletes all the values of an attribute on an item.
+ * exceptions:
+ * Throws an exception if *item* is not an item, or if *attribute*
+ * is neither an attribute object or a string.
+ * examples:
+ * var success = store.clear(kermit, "color");
+ * if (success) {assert(!store.hasAttribute(kermit, "color"));}
+ */
+ dojo.unimplemented('dojo.data.Write.clear');
+ return false; // boolean
+ },
+ save:
+ function() {
+ /* summary:
+ * Saves to the server all the changes that have been made locally.
+ * The save operation may take some time. By default the save will
+ * be done synchronously, before the call returns. The caller may
+ * be request an asynchronous save by passing {async: true}.
+ * If the caller requests an asynchronous save, the data store may do
+ * either a synchronous or asynchronous save, whichever it prefers.
+ * Different data store implementations may take additional optional
+ * parameters.
+ * issue:
+ * Should the async save take a callback, like this:
+ * store.save({async: true, onComplete: callback});
+ * Or should the async save return a Deferred, like this:
+ * var deferred = store.save({async: true});
+ * deferred.addCallbacks(successCallback, errorCallback);
+ * Or should save() return boolean, like this:
+ * var success = store.save();
+ * examples:
+ * var success = store.save();
+ * var success = store.save({async: true});
+ */
+ dojo.unimplemented('dojo.data.Write.save');
+ return false; // boolean
+ },
+ revert:
+ function() {
+ /* summary:
+ * Discards any unsaved changes.
+ * examples:
+ * var success = store.revert();
+ */
+ dojo.unimplemented('dojo.data.Write.revert');
+ return false; // boolean
+ },
+ isDirty:
+ function(/* item (or store) */ item) {
+ /* summary:
+ * Returns true if the given item has been modified since the last save().
+ * If the datastore object itself is given as a parameter instead of an
+ * item, then this method returns true if any item has been modified since
+ * the last save().
+ * exceptions:
+ * Throws an exception if *item* is neither an item nor the datastore itself.
+ * examples:
+ * var trueOrFalse = store.isDirty(kermit); // true if kermit is dirty
+ * var trueOrFalse = store.isDirty(store); // true if any item is dirty
+ */
+ dojo.unimplemented('dojo.data.Write.isDirty');
+ return false; // boolean
+ }
+});
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/Write.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/CsvStore.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/CsvStore.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/CsvStore.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/CsvStore.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,214 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.csv.CsvStore");
+dojo.require("dojo.data.Read");
+dojo.require("dojo.lang.assert");
+
+dojo.declare("dojo.data.csv.CsvStore", dojo.data.Read, {
+ /* Summary:
+ * The CsvStore implements the dojo.data.Read API.
+ * Examples:
+ * var csvStore = new dojo.data.csv.CsvStore({url:"movies.csv");
+ * var csvStore = new dojo.data.csv.CsvStore({url:"http://example.com/movies.csv");
+ * var fileContents = dojo.hostenv.getText("movies.csv");
+ * var csvStore = new dojo.data.csv.CsvStore({string:fileContents);
+ */
+ initializer:
+ function(/* object */ keywordParameters) {
+ // keywordParameters: object {string: String, url: String}
+ this._arrayOfItems = [];
+ this._loadFinished = false;
+ this._csvFileUrl = keywordParameters["url"];
+ this._csvFileContents = keywordParameters["string"];
+ },
+ get:
+ function(/* item */ item, /* attribute or attribute-name-string */ attribute, /* value? */ defaultValue) {
+ // Summary: See dojo.data.Read.get()
+ var attributeValue = item[attribute] || defaultValue;
+ return attributeValue; // a literal, an item, null, or undefined (never an array)
+ },
+ getValues:
+ function(/* item */ item, /* attribute or attribute-name-string */ attribute) {
+ // Summary: See dojo.data.Read.getValues()
+ var array = [this.get(item, attribute)];
+ return array; // an array that may contain literals and items
+ },
+ getAttributes:
+ function(/* item */ item) {
+ // Summary: See dojo.data.Read.getAttributes()
+ var array = this._arrayOfKeys;
+ return array; // array
+ },
+ hasAttribute:
+ function(/* item */ item, /* attribute or attribute-name-string */ attribute) {
+ // Summary: See dojo.data.Read.hasAttribute()
+ for (var i in this._arrayOfKeys) {
+ if (this._arrayOfKeys[i] == attribute) {
+ return true;
+ }
+ }
+ return false; // boolean
+ },
+ hasAttributeValue:
+ function(/* item */ item, /* attribute or attribute-name-string */ attribute, /* anything */ value) {
+ // Summary: See dojo.data.Read.hasAttributeValue()
+ return (this.get(item, attribute) == value); // boolean
+ },
+ isItem:
+ function(/* anything */ something) {
+ // Summary: See dojo.data.Read.isItem()
+ for (var i in this._arrayOfItems) {
+ if (this._arrayOfItems[i] == something) {
+ return true;
+ }
+ }
+ return false; // boolean
+ },
+ find:
+ function(/* implementation-dependent */ query, /* object */ optionalKeywordArgs ) {
+ // Summary: See dojo.data.Read.find()
+ if (!this._loadFinished) {
+ if (this._csvFileUrl) {
+ this._csvFileContents = dojo.hostenv.getText(this._csvFileUrl);
+ }
+ var arrayOfArrays = this._getArrayOfArraysFromCsvFileContents(this._csvFileContents);
+ if (arrayOfArrays.length == 0) {
+ this._arrayOfKeys = [];
+ } else {
+ this._arrayOfKeys = arrayOfArrays[0];
+ }
+ this._arrayOfItems = this._getArrayOfItemsFromArrayOfArrays(arrayOfArrays);
+ }
+ var result = new dojo.data.csv.Result(this._arrayOfItems, this);
+ return result; // dojo.data.csv.Result
+ },
+ getIdentity:
+ function(/* item */ item) {
+ // Summary: See dojo.data.Read.getIdentity()
+ for (var i in this._arrayOfItems) {
+ if (this._arrayOfItems[i] == item) {
+ return i;
+ }
+ }
+ return null; // boolean
+ },
+ getByIdentity:
+ function(/* string */ id) {
+ // Summary: See dojo.data.Read.getByIdentity()
+ var i = parseInt(id);
+ if (i < this._arrayOfItems.length) {
+ return this._arrayOfItems[i];
+ } else {
+ return null;
+ }
+ },
+
+ // -------------------------------------------------------------------
+ // Private methods
+ _getArrayOfArraysFromCsvFileContents:
+ function(/* string */ csvFileContents) {
+ /* Summary:
+ * Parses a string of CSV records into a nested array structure.
+ * Description:
+ * Given a string containing CSV records, this method parses
+ * the string and returns a data structure containing the parsed
+ * content. The data structure we return is an array of length
+ * R, where R is the number of rows (lines) in the CSV data. The
+ * return array contains one sub-array for each CSV line, and each
+ * sub-array contains C string values, where C is the number of
+ * columns in the CSV data.
+ * Example:
+ * For example, given this CSV string as input:
+ * "Title, Year, Producer \n Alien, 1979, Ridley Scott \n Blade Runner, 1982, Ridley Scott"
+ * We will return this data structure:
+ * [["Title", "Year", "Producer"]
+ * ["Alien", "1979", "Ridley Scott"],
+ * ["Blade Runner", "1982", "Ridley Scott"]]
+ */
+ dojo.lang.assertType(csvFileContents, String);
+
+ var lineEndingCharacters = new RegExp("\r\n|\n|\r");
+ var leadingWhiteSpaceCharacters = new RegExp("^\\s+",'g');
+ var trailingWhiteSpaceCharacters = new RegExp("\\s+$",'g');
+ var doubleQuotes = new RegExp('""','g');
+ var arrayOfOutputRecords = [];
+
+ var arrayOfInputLines = csvFileContents.split(lineEndingCharacters);
+ for (var i in arrayOfInputLines) {
+ var singleLine = arrayOfInputLines[i];
+ if (singleLine.length > 0) {
+ var listOfFields = singleLine.split(',');
+ var j = 0;
+ while (j < listOfFields.length) {
+ var space_field_space = listOfFields[j];
+ var field_space = space_field_space.replace(leadingWhiteSpaceCharacters, ''); // trim leading whitespace
+ var field = field_space.replace(trailingWhiteSpaceCharacters, ''); // trim trailing whitespace
+ var firstChar = field.charAt(0);
+ var lastChar = field.charAt(field.length - 1);
+ var secondToLastChar = field.charAt(field.length - 2);
+ var thirdToLastChar = field.charAt(field.length - 3);
+ if ((firstChar == '"') &&
+ ((lastChar != '"') ||
+ ((lastChar == '"') && (secondToLastChar == '"') && (thirdToLastChar != '"')) )) {
+ if (j+1 === listOfFields.length) {
+ // alert("The last field in record " + i + " is corrupted:\n" + field);
+ return null;
+ }
+ var nextField = listOfFields[j+1];
+ listOfFields[j] = field_space + ',' + nextField;
+ listOfFields.splice(j+1, 1); // delete element [j+1] from the list
+ } else {
+ if ((firstChar == '"') && (lastChar == '"')) {
+ field = field.slice(1, (field.length - 1)); // trim the " characters off the ends
+ field = field.replace(doubleQuotes, '"'); // replace "" with "
+ }
+ listOfFields[j] = field;
+ j += 1;
+ }
+ }
+ arrayOfOutputRecords.push(listOfFields);
+ }
+ }
+ return arrayOfOutputRecords; // Array
+ },
+
+ _getArrayOfItemsFromArrayOfArrays:
+ function(/* array */ arrayOfArrays) {
+ /* Summary:
+ * Converts a nested array structure into an array of keyword objects.
+ * Example:
+ * For example, given this as input:
+ * [["Title", "Year", "Producer"]
+ * ["Alien", "1979", "Ridley Scott"],
+ * ["Blade Runner", "1982", "Ridley Scott"]]
+ * We will return this as output:
+ * [{"Title":"Alien", "Year":"1979", "Producer":"Ridley Scott"},
+ * {"Title":"Blade Runner", "Year":"1982", "Producer":"Ridley Scott"}]
+ */
+ dojo.lang.assertType(arrayOfArrays, Array);
+ var arrayOfItems = [];
+ if (arrayOfArrays.length > 1) {
+ var arrayOfKeys = arrayOfArrays[0];
+ for (var i = 1; i < arrayOfArrays.length; ++i) {
+ var row = arrayOfArrays[i];
+ var item = {};
+ for (var j in row) {
+ var value = row[j];
+ var key = arrayOfKeys[j];
+ item[key] = value;
+ }
+ arrayOfItems.push(item);
+ }
+ }
+ return arrayOfItems; // Array
+ }
+});
+
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/CsvStore.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/Result.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/Result.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/Result.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/Result.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,91 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.csv.Result");
+dojo.require("dojo.data.Result");
+dojo.require("dojo.lang.assert");
+
+dojo.declare("dojo.data.csv.Result", dojo.data.Result, {
+ /* Summary:
+ * dojo.data.csv.Result implements the dojo.data.Result API.
+ */
+ initializer:
+ function(/* array */ arrayOfItems, /* object */ dataStore) {
+ dojo.lang.assertType(arrayOfItems, Array);
+ this._arrayOfItems = arrayOfItems;
+ this._dataStore = dataStore;
+ this._cancel = false;
+ this._inProgress = false;
+ },
+ forEach:
+ function(/* function or object */ functionOrKeywordObject) {
+ // Summary: See dojo.data.Result.forEach()
+ dojo.lang.assertType(functionOrKeywordObject, [Function, "pureobject"]);
+ var callbackFunction = null;
+ var callbackObject = null;
+ var callbackFunctionName = null;
+ if (dojo.lang.isFunction(functionOrKeywordObject)) {
+ callbackFunction = functionOrKeywordObject;
+ } else {
+ var keywordObject = functionOrKeywordObject;
+ dojo.lang.assertType(keywordObject, "pureobject");
+ var callbackObject = keywordObject["object"];
+ var callbackFunctionName = keywordObject["callback"];
+ }
+ this._inProgress = true;
+ for (var i in this._arrayOfItems) {
+ var item = this._arrayOfItems[i];
+ if (!this._cancel) {
+ if (callbackFunction) {
+ callbackFunction(item, this);
+ } else {
+ callbackObject[callbackFunctionName](item, this);
+ }
+ }
+ }
+ this._inProgress = false;
+ this._cancel = false;
+
+ return true; // boolean
+ },
+ getLength:
+ function() {
+ // Summary: See dojo.data.Result.getLength()
+ return this._arrayOfItems.length; // integer
+ },
+ inProgress:
+ function() {
+ // Summary: See dojo.data.Result.inProgress()
+ return this._inProgress; // boolean
+ },
+ cancel:
+ function() {
+ // Summary: See dojo.data.Result.cancel()
+ if (this._inProgress) {
+ this._cancel = true;
+ }
+ },
+ addCallback:
+ function(/* function */ callbackFunction) {
+ // Summary: See dojo.data.Result.addCallback()
+ dojo.unimplemented('dojo.data.csv.Result.addCallback');
+ },
+ addErrback:
+ function(/* function */ errorCallbackFunction) {
+ // Summary: See dojo.data.Result.addErrback()
+ dojo.unimplemented('dojo.data.csv.Result.addErrback');
+ },
+ getStore:
+ function() {
+ // Summary: See dojo.data.Result.getStore()
+ return this._dataStore; // an object that implements dojo.data.Read
+ }
+});
+
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/Result.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/__package__.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/__package__.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/__package__.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/__package__.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,21 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.require("dojo.experimental");
+
+dojo.experimental("dojo.data.csv.*");
+dojo.kwCompoundRequire({
+ common: [
+ "dojo.data.csv.CsvStore",
+ "dojo.data.csv.Result"
+ ]
+});
+dojo.provide("dojo.data.csv.*");
+
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/csv/__package__.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Attribute.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Attribute.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Attribute.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Attribute.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,62 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.old.Attribute");
+dojo.require("dojo.data.old.Item");
+dojo.require("dojo.lang.assert");
+
+// -------------------------------------------------------------------
+// Constructor
+// -------------------------------------------------------------------
+dojo.data.old.Attribute = function(/* dojo.data.old.provider.Base */ dataProvider, /* string */ attributeId) {
+ /**
+ * summary:
+ * An Attribute object represents something like a column in
+ * a relational database.
+ */
+ dojo.lang.assertType(dataProvider, dojo.data.old.provider.Base, {optional: true});
+ dojo.lang.assertType(attributeId, String);
+ dojo.data.old.Item.call(this, dataProvider);
+ this._attributeId = attributeId;
+};
+dojo.inherits(dojo.data.old.Attribute, dojo.data.old.Item);
+
+// -------------------------------------------------------------------
+// Public instance methods
+// -------------------------------------------------------------------
+dojo.data.old.Attribute.prototype.toString = function() {
+ return this._attributeId; // string
+};
+
+dojo.data.old.Attribute.prototype.getAttributeId = function() {
+ /**
+ * summary:
+ * Returns the string token that uniquely identifies this
+ * attribute within the context of a data provider.
+ * For a data provider that accesses relational databases,
+ * typical attributeIds might be tokens like "name", "age",
+ * "ssn", or "dept_key".
+ */
+ return this._attributeId; // string
+};
+
+dojo.data.old.Attribute.prototype.getType = function() {
+ /**
+ * summary: Returns the data type of the values of this attribute.
+ */
+ return this.get('type'); // dojo.data.old.Type or null
+};
+
+dojo.data.old.Attribute.prototype.setType = function(/* dojo.data.old.Type or null */ type) {
+ /**
+ * summary: Sets the data type for this attribute.
+ */
+ this.set('type', type);
+};
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Attribute.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Item.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Item.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Item.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Item.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,327 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.old.Item");
+dojo.require("dojo.data.old.Observable");
+dojo.require("dojo.data.old.Value");
+dojo.require("dojo.lang.common");
+dojo.require("dojo.lang.assert");
+
+// -------------------------------------------------------------------
+// Constructor
+// -------------------------------------------------------------------
+dojo.data.old.Item = function(/* dojo.data.old.provider.Base */ dataProvider) {
+ /**
+ * summary:
+ * An Item has attributes and attribute values, sort of like
+ * a record in a database, or a 'struct' in C. Instances of
+ * the Item class know how to store and retrieve their
+ * attribute values.
+ */
+ dojo.lang.assertType(dataProvider, dojo.data.old.provider.Base, {optional: true});
+ dojo.data.old.Observable.call(this);
+ this._dataProvider = dataProvider;
+ this._dictionaryOfAttributeValues = {};
+};
+dojo.inherits(dojo.data.old.Item, dojo.data.old.Observable);
+
+// -------------------------------------------------------------------
+// Public class methods
+// -------------------------------------------------------------------
+dojo.data.old.Item.compare = function(/* dojo.data.old.Item */ itemOne, /* dojo.data.old.Item */ itemTwo) {
+ /**
+ * summary:
+ * Given two Items to compare, this method returns 0, 1, or -1.
+ * This method is designed to be used by sorting routines, like
+ * the JavaScript built-in Array sort() method.
+ *
+ * Example:
+ * <pre>
+ * var a = dataProvider.newItem("kermit");
+ * var b = dataProvider.newItem("elmo");
+ * var c = dataProvider.newItem("grover");
+ * var array = new Array(a, b, c);
+ * array.sort(dojo.data.old.Item.compare);
+ * </pre>
+ */
+ dojo.lang.assertType(itemOne, dojo.data.old.Item);
+ if (!dojo.lang.isOfType(itemTwo, dojo.data.old.Item)) {
+ return -1;
+ }
+ var nameOne = itemOne.getName();
+ var nameTwo = itemTwo.getName();
+ if (nameOne == nameTwo) {
+ var attributeArrayOne = itemOne.getAttributes();
+ var attributeArrayTwo = itemTwo.getAttributes();
+ if (attributeArrayOne.length != attributeArrayTwo.length) {
+ if (attributeArrayOne.length > attributeArrayTwo.length) {
+ return 1;
+ } else {
+ return -1;
+ }
+ }
+ for (var i in attributeArrayOne) {
+ var attribute = attributeArrayOne[i];
+ var arrayOfValuesOne = itemOne.getValues(attribute);
+ var arrayOfValuesTwo = itemTwo.getValues(attribute);
+ dojo.lang.assert(arrayOfValuesOne && (arrayOfValuesOne.length > 0));
+ if (!arrayOfValuesTwo) {
+ return 1;
+ }
+ if (arrayOfValuesOne.length != arrayOfValuesTwo.length) {
+ if (arrayOfValuesOne.length > arrayOfValuesTwo.length) {
+ return 1;
+ } else {
+ return -1;
+ }
+ }
+ for (var j in arrayOfValuesOne) {
+ var value = arrayOfValuesOne[j];
+ if (!itemTwo.hasAttributeValue(value)) {
+ return 1;
+ }
+ }
+ return 0;
+ }
+ } else {
+ if (nameOne > nameTwo) {
+ return 1;
+ } else {
+ return -1; // 0, 1, or -1
+ }
+ }
+};
+
+// -------------------------------------------------------------------
+// Public instance methods
+// -------------------------------------------------------------------
+dojo.data.old.Item.prototype.toString = function() {
+ /**
+ * Returns a simple string representation of the item.
+ */
+ var arrayOfStrings = [];
+ var attributes = this.getAttributes();
+ for (var i in attributes) {
+ var attribute = attributes[i];
+ var arrayOfValues = this.getValues(attribute);
+ var valueString;
+ if (arrayOfValues.length == 1) {
+ valueString = arrayOfValues[0];
+ } else {
+ valueString = '[';
+ valueString += arrayOfValues.join(', ');
+ valueString += ']';
+ }
+ arrayOfStrings.push(' ' + attribute + ': ' + valueString);
+ }
+ var returnString = '{ ';
+ returnString += arrayOfStrings.join(',\n');
+ returnString += ' }';
+ return returnString; // string
+};
+
+dojo.data.old.Item.prototype.compare = function(/* dojo.data.old.Item */ otherItem) {
+ /**
+ * summary: Compares this Item to another Item, and returns 0, 1, or -1.
+ */
+ return dojo.data.old.Item.compare(this, otherItem); // 0, 1, or -1
+};
+
+dojo.data.old.Item.prototype.isEqual = function(/* dojo.data.old.Item */ otherItem) {
+ /**
+ * summary: Returns true if this Item is equal to the otherItem, or false otherwise.
+ */
+ return (this.compare(otherItem) == 0); // boolean
+};
+
+dojo.data.old.Item.prototype.getName = function() {
+ return this.get('name');
+};
+
+dojo.data.old.Item.prototype.get = function(/* string or dojo.data.old.Attribute */ attributeId) {
+ /**
+ * summary: Returns a single literal value, like "foo" or 33.
+ */
+ // dojo.lang.assertType(attributeId, [String, dojo.data.old.Attribute]);
+ var literalOrValueOrArray = this._dictionaryOfAttributeValues[attributeId];
+ if (dojo.lang.isUndefined(literalOrValueOrArray)) {
+ return null; // null
+ }
+ if (literalOrValueOrArray instanceof dojo.data.old.Value) {
+ return literalOrValueOrArray.getValue(); // literal
+ }
+ if (dojo.lang.isArray(literalOrValueOrArray)) {
+ var dojoDataValue = literalOrValueOrArray[0];
+ return dojoDataValue.getValue(); // literal
+ }
+ return literalOrValueOrArray; // literal
+};
+
+dojo.data.old.Item.prototype.getValue = function(/* string or dojo.data.old.Attribute */ attributeId) {
+ /**
+ * summary: Returns a single instance of dojo.data.old.Value.
+ */
+ // dojo.lang.assertType(attributeId, [String, dojo.data.old.Attribute]);
+ var literalOrValueOrArray = this._dictionaryOfAttributeValues[attributeId];
+ if (dojo.lang.isUndefined(literalOrValueOrArray)) {
+ return null; // null
+ }
+ if (literalOrValueOrArray instanceof dojo.data.old.Value) {
+ return literalOrValueOrArray; // dojo.data.old.Value
+ }
+ if (dojo.lang.isArray(literalOrValueOrArray)) {
+ var dojoDataValue = literalOrValueOrArray[0];
+ return dojoDataValue; // dojo.data.old.Value
+ }
+ var literal = literalOrValueOrArray;
+ dojoDataValue = new dojo.data.old.Value(literal);
+ this._dictionaryOfAttributeValues[attributeId] = dojoDataValue;
+ return dojoDataValue; // dojo.data.old.Value
+};
+
+dojo.data.old.Item.prototype.getValues = function(/* string or dojo.data.old.Attribute */ attributeId) {
+ /**
+ * summary: Returns an array of dojo.data.old.Value objects.
+ */
+ // dojo.lang.assertType(attributeId, [String, dojo.data.old.Attribute]);
+ var literalOrValueOrArray = this._dictionaryOfAttributeValues[attributeId];
+ if (dojo.lang.isUndefined(literalOrValueOrArray)) {
+ return null; // null
+ }
+ if (literalOrValueOrArray instanceof dojo.data.old.Value) {
+ var array = [literalOrValueOrArray];
+ this._dictionaryOfAttributeValues[attributeId] = array;
+ return array; // Array
+ }
+ if (dojo.lang.isArray(literalOrValueOrArray)) {
+ return literalOrValueOrArray; // Array
+ }
+ var literal = literalOrValueOrArray;
+ var dojoDataValue = new dojo.data.old.Value(literal);
+ array = [dojoDataValue];
+ this._dictionaryOfAttributeValues[attributeId] = array;
+ return array; // Array
+};
+
+dojo.data.old.Item.prototype.load = function(/* string or dojo.data.old.Attribute */ attributeId, /* anything */ value) {
+ /**
+ * summary:
+ * Used for loading an attribute value into an item when
+ * the item is first being loaded into memory from some
+ * data store (such as a file).
+ */
+ // dojo.lang.assertType(attributeId, [String, dojo.data.old.Attribute]);
+ this._dataProvider.registerAttribute(attributeId);
+ var literalOrValueOrArray = this._dictionaryOfAttributeValues[attributeId];
+ if (dojo.lang.isUndefined(literalOrValueOrArray)) {
+ this._dictionaryOfAttributeValues[attributeId] = value;
+ return;
+ }
+ if (!(value instanceof dojo.data.old.Value)) {
+ value = new dojo.data.old.Value(value);
+ }
+ if (literalOrValueOrArray instanceof dojo.data.old.Value) {
+ var array = [literalOrValueOrArray, value];
+ this._dictionaryOfAttributeValues[attributeId] = array;
+ return;
+ }
+ if (dojo.lang.isArray(literalOrValueOrArray)) {
+ literalOrValueOrArray.push(value);
+ return;
+ }
+ var literal = literalOrValueOrArray;
+ var dojoDataValue = new dojo.data.old.Value(literal);
+ array = [dojoDataValue, value];
+ this._dictionaryOfAttributeValues[attributeId] = array;
+};
+
+dojo.data.old.Item.prototype.set = function(/* string or dojo.data.old.Attribute */ attributeId, /* anything */ value) {
+ /**
+ * summary:
+ * Used for setting an attribute value as a result of a
+ * user action.
+ */
+ // dojo.lang.assertType(attributeId, [String, dojo.data.old.Attribute]);
+ this._dataProvider.registerAttribute(attributeId);
+ this._dictionaryOfAttributeValues[attributeId] = value;
+ this._dataProvider.noteChange(this, attributeId, value);
+};
+
+dojo.data.old.Item.prototype.setValue = function(/* string or dojo.data.old.Attribute */ attributeId, /* dojo.data.old.Value */ value) {
+ this.set(attributeId, value);
+};
+
+dojo.data.old.Item.prototype.addValue = function(/* string or dojo.data.old.Attribute */ attributeId, /* anything */ value) {
+ /**
+ * summary:
+ * Used for adding an attribute value as a result of a
+ * user action.
+ */
+ this.load(attributeId, value);
+ this._dataProvider.noteChange(this, attributeId, value);
+};
+
+dojo.data.old.Item.prototype.setValues = function(/* string or dojo.data.old.Attribute */ attributeId, /* Array */ arrayOfValues) {
+ /**
+ * summary:
+ * Used for setting an array of attribute values as a result of a
+ * user action.
+ */
+ // dojo.lang.assertType(attributeId, [String, dojo.data.old.Attribute]);
+ dojo.lang.assertType(arrayOfValues, Array);
+ this._dataProvider.registerAttribute(attributeId);
+ var finalArray = [];
+ this._dictionaryOfAttributeValues[attributeId] = finalArray;
+ for (var i in arrayOfValues) {
+ var value = arrayOfValues[i];
+ if (!(value instanceof dojo.data.old.Value)) {
+ value = new dojo.data.old.Value(value);
+ }
+ finalArray.push(value);
+ this._dataProvider.noteChange(this, attributeId, value);
+ }
+};
+
+dojo.data.old.Item.prototype.getAttributes = function() {
+ /**
+ * summary:
+ * Returns an array containing all of the attributes for which
+ * this item has attribute values.
+ */
+ var arrayOfAttributes = [];
+ for (var key in this._dictionaryOfAttributeValues) {
+ arrayOfAttributes.push(this._dataProvider.getAttribute(key));
+ }
+ return arrayOfAttributes; // Array
+};
+
+dojo.data.old.Item.prototype.hasAttribute = function(/* string or dojo.data.old.Attribute */ attributeId) {
+ /**
+ * summary: Returns true if the given attribute of the item has been assigned any value.
+ */
+ // dojo.lang.assertType(attributeId, [String, dojo.data.old.Attribute]);
+ return (attributeId in this._dictionaryOfAttributeValues); // boolean
+};
+
+dojo.data.old.Item.prototype.hasAttributeValue = function(/* string or dojo.data.old.Attribute */ attributeId, /* anything */ value) {
+ /**
+ * summary: Returns true if the given attribute of the item has been assigned the given value.
+ */
+ var arrayOfValues = this.getValues(attributeId);
+ for (var i in arrayOfValues) {
+ var candidateValue = arrayOfValues[i];
+ if (candidateValue.isEqual(value)) {
+ return true; // boolean
+ }
+ }
+ return false; // boolean
+};
+
+
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Item.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Kind.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Kind.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Kind.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Kind.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,28 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.old.Kind");
+dojo.require("dojo.data.old.Item");
+
+// -------------------------------------------------------------------
+// Constructor
+// -------------------------------------------------------------------
+dojo.data.old.Kind = function(/* dojo.data.old.provider.Base */ dataProvider) {
+ /**
+ * summary:
+ * A Kind represents a kind of item. In the dojo data model
+ * the item Snoopy might belong to the 'kind' Dog, where in
+ * a Java program the object Snoopy would belong to the 'class'
+ * Dog, and in MySQL the record for Snoopy would be in the
+ * table Dog.
+ */
+ dojo.data.old.Item.call(this, dataProvider);
+};
+dojo.inherits(dojo.data.old.Kind, dojo.data.old.Item);
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Kind.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Observable.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Observable.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Observable.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Observable.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,59 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.old.Observable");
+dojo.require("dojo.lang.common");
+dojo.require("dojo.lang.assert");
+
+// -------------------------------------------------------------------
+// Constructor
+// -------------------------------------------------------------------
+dojo.data.old.Observable = function() {
+};
+
+// -------------------------------------------------------------------
+// Public instance methods
+// -------------------------------------------------------------------
+dojo.data.old.Observable.prototype.addObserver = function(/* object */ observer) {
+ /**
+ * summary: Registers an object as an observer of this item,
+ * so that the object will be notified when the item changes.
+ */
+ dojo.lang.assertType(observer, Object);
+ dojo.lang.assertType(observer.observedObjectHasChanged, Function);
+ if (!this._arrayOfObservers) {
+ this._arrayOfObservers = [];
+ }
+ if (!dojo.lang.inArray(this._arrayOfObservers, observer)) {
+ this._arrayOfObservers.push(observer);
+ }
+};
+
+dojo.data.old.Observable.prototype.removeObserver = function(/* object */ observer) {
+ /**
+ * summary: Removes the observer registration for a previously
+ * registered object.
+ */
+ if (!this._arrayOfObservers) {
+ return;
+ }
+ var index = dojo.lang.indexOf(this._arrayOfObservers, observer);
+ if (index != -1) {
+ this._arrayOfObservers.splice(index, 1);
+ }
+};
+
+dojo.data.old.Observable.prototype.getObservers = function() {
+ /**
+ * summary: Returns an array with all the observers of this item.
+ */
+ return this._arrayOfObservers; // Array or undefined
+};
+
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Observable.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/ResultSet.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/ResultSet.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/ResultSet.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/ResultSet.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,70 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.old.ResultSet");
+dojo.require("dojo.lang.assert");
+dojo.require("dojo.collections.Collections");
+
+// -------------------------------------------------------------------
+// Constructor
+// -------------------------------------------------------------------
+dojo.data.old.ResultSet = function(/* dojo.data.old.provider.Base */ dataProvider, /* Array */ arrayOfItems) {
+ /**
+ * summary:
+ * A ResultSet holds a collection of Items. A data provider
+ * returns a ResultSet in reponse to a query.
+ * (The name "Result Set" comes from the MySQL terminology.)
+ */
+ dojo.lang.assertType(dataProvider, dojo.data.old.provider.Base, {optional: true});
+ dojo.lang.assertType(arrayOfItems, Array, {optional: true});
+ dojo.data.old.Observable.call(this);
+ this._dataProvider = dataProvider;
+ this._arrayOfItems = [];
+ if (arrayOfItems) {
+ this._arrayOfItems = arrayOfItems;
+ }
+};
+dojo.inherits(dojo.data.old.ResultSet, dojo.data.old.Observable);
+
+// -------------------------------------------------------------------
+// Public instance methods
+// -------------------------------------------------------------------
+dojo.data.old.ResultSet.prototype.toString = function() {
+ var returnString = this._arrayOfItems.join(', ');
+ return returnString; // string
+};
+
+dojo.data.old.ResultSet.prototype.toArray = function() {
+ return this._arrayOfItems; // Array
+};
+
+dojo.data.old.ResultSet.prototype.getIterator = function() {
+ return new dojo.collections.Iterator(this._arrayOfItems);
+};
+
+dojo.data.old.ResultSet.prototype.getLength = function() {
+ return this._arrayOfItems.length; // integer
+};
+
+dojo.data.old.ResultSet.prototype.getItemAt = function(/* numeric */ index) {
+ return this._arrayOfItems[index];
+};
+
+dojo.data.old.ResultSet.prototype.indexOf = function(/* dojo.data.old.Item */ item) {
+ return dojo.lang.indexOf(this._arrayOfItems, item); // integer
+};
+
+dojo.data.old.ResultSet.prototype.contains = function(/* dojo.data.old.Item */ item) {
+ return dojo.lang.inArray(this._arrayOfItems, item); // boolean
+};
+
+dojo.data.old.ResultSet.prototype.getDataProvider = function() {
+ return this._dataProvider; // dojo.data.old.provider.Base
+};
\ No newline at end of file
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/ResultSet.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Type.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Type.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Type.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Type.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,25 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.old.Type");
+dojo.require("dojo.data.old.Item");
+
+// -------------------------------------------------------------------
+// Constructor
+// -------------------------------------------------------------------
+dojo.data.old.Type = function(/* dojo.data.old.provider.Base */ dataProvider) {
+ /**
+ * summary:
+ * A Type represents a type of value, like Text, Number, Picture,
+ * or Varchar.
+ */
+ dojo.data.old.Item.call(this, dataProvider);
+};
+dojo.inherits(dojo.data.old.Type, dojo.data.old.Item);
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Type.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Value.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Value.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Value.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Value.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,55 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.old.Value");
+dojo.require("dojo.lang.assert");
+
+// -------------------------------------------------------------------
+// Constructor
+// -------------------------------------------------------------------
+dojo.data.old.Value = function(/* anything */ value) {
+ /**
+ * summary:
+ * A Value represents a simple literal value (like "foo" or 334),
+ * or a reference value (a pointer to an Item).
+ */
+ this._value = value;
+ this._type = null;
+};
+
+// -------------------------------------------------------------------
+// Public instance methods
+// -------------------------------------------------------------------
+dojo.data.old.Value.prototype.toString = function() {
+ return this._value.toString(); // string
+};
+
+dojo.data.old.Value.prototype.getValue = function() {
+ /**
+ * summary: Returns the value itself.
+ */
+ return this._value; // anything
+};
+
+dojo.data.old.Value.prototype.getType = function() {
+ /**
+ * summary: Returns the data type of the value.
+ */
+ dojo.unimplemented('dojo.data.old.Value.prototype.getType');
+ return this._type; // dojo.data.old.Type
+};
+
+dojo.data.old.Value.prototype.compare = function() {
+ dojo.unimplemented('dojo.data.old.Value.prototype.compare');
+};
+
+dojo.data.old.Value.prototype.isEqual = function() {
+ dojo.unimplemented('dojo.data.old.Value.prototype.isEqual');
+};
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/Value.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/__package__.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/__package__.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/__package__.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/__package__.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,22 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.require("dojo.experimental");
+
+dojo.experimental("dojo.data.old.*");
+dojo.kwCompoundRequire({
+ common: [
+ "dojo.data.old.Item",
+ "dojo.data.old.ResultSet",
+ "dojo.data.old.provider.FlatFile"
+ ]
+});
+dojo.provide("dojo.data.old.*");
+
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/__package__.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/format/Csv.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/format/Csv.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/format/Csv.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/format/Csv.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,112 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.old.format.Csv");
+dojo.require("dojo.lang.assert");
+
+
+dojo.data.old.format.Csv = new function() {
+
+ // -------------------------------------------------------------------
+ // Public functions
+ // -------------------------------------------------------------------
+ this.getArrayStructureFromCsvFileContents = function(/* string */ csvFileContents) {
+ /**
+ * Given a string containing CSV records, this method parses
+ * the string and returns a data structure containing the parsed
+ * content. The data structure we return is an array of length
+ * R, where R is the number of rows (lines) in the CSV data. The
+ * return array contains one sub-array for each CSV line, and each
+ * sub-array contains C string values, where C is the number of
+ * columns in the CSV data.
+ *
+ * For example, given this CSV string as input:
+ * <pre>
+ * "Title, Year, Producer \n Alien, 1979, Ridley Scott \n Blade Runner, 1982, Ridley Scott"
+ * </pre>
+ * We will return this data structure:
+ * <pre>
+ * [["Title", "Year", "Producer"]
+ * ["Alien", "1979", "Ridley Scott"],
+ * ["Blade Runner", "1982", "Ridley Scott"]]
+ * </pre>
+ */
+ dojo.lang.assertType(csvFileContents, String);
+
+ var lineEndingCharacters = new RegExp("\r\n|\n|\r");
+ var leadingWhiteSpaceCharacters = new RegExp("^\\s+",'g');
+ var trailingWhiteSpaceCharacters = new RegExp("\\s+$",'g');
+ var doubleQuotes = new RegExp('""','g');
+ var arrayOfOutputRecords = [];
+
+ var arrayOfInputLines = csvFileContents.split(lineEndingCharacters);
+ for (var i in arrayOfInputLines) {
+ var singleLine = arrayOfInputLines[i];
+ if (singleLine.length > 0) {
+ var listOfFields = singleLine.split(',');
+ var j = 0;
+ while (j < listOfFields.length) {
+ var space_field_space = listOfFields[j];
+ var field_space = space_field_space.replace(leadingWhiteSpaceCharacters, ''); // trim leading whitespace
+ var field = field_space.replace(trailingWhiteSpaceCharacters, ''); // trim trailing whitespace
+ var firstChar = field.charAt(0);
+ var lastChar = field.charAt(field.length - 1);
+ var secondToLastChar = field.charAt(field.length - 2);
+ var thirdToLastChar = field.charAt(field.length - 3);
+ if ((firstChar == '"') &&
+ ((lastChar != '"') ||
+ ((lastChar == '"') && (secondToLastChar == '"') && (thirdToLastChar != '"')) )) {
+ if (j+1 === listOfFields.length) {
+ // alert("The last field in record " + i + " is corrupted:\n" + field);
+ return null;
+ }
+ var nextField = listOfFields[j+1];
+ listOfFields[j] = field_space + ',' + nextField;
+ listOfFields.splice(j+1, 1); // delete element [j+1] from the list
+ } else {
+ if ((firstChar == '"') && (lastChar == '"')) {
+ field = field.slice(1, (field.length - 1)); // trim the " characters off the ends
+ field = field.replace(doubleQuotes, '"'); // replace "" with "
+ }
+ listOfFields[j] = field;
+ j += 1;
+ }
+ }
+ arrayOfOutputRecords.push(listOfFields);
+ }
+ }
+ return arrayOfOutputRecords; // Array
+ };
+
+ this.loadDataProviderFromFileContents = function(/* dojo.data.old.provider.Base */ dataProvider, /* string */ csvFileContents) {
+ dojo.lang.assertType(dataProvider, dojo.data.old.provider.Base);
+ dojo.lang.assertType(csvFileContents, String);
+ var arrayOfArrays = this.getArrayStructureFromCsvFileContents(csvFileContents);
+ if (arrayOfArrays) {
+ var arrayOfKeys = arrayOfArrays[0];
+ for (var i = 1; i < arrayOfArrays.length; ++i) {
+ var row = arrayOfArrays[i];
+ var item = dataProvider.getNewItemToLoad();
+ for (var j in row) {
+ var value = row[j];
+ var key = arrayOfKeys[j];
+ item.load(key, value);
+ }
+ }
+ }
+ };
+
+ this.getCsvStringFromResultSet = function(/* dojo.data.old.ResultSet */ resultSet) {
+ dojo.unimplemented('dojo.data.old.format.Csv.getCsvStringFromResultSet');
+ var csvString = null;
+ return csvString; // String
+ };
+
+}();
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/format/Csv.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/format/Json.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/format/Json.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/format/Json.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/format/Json.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,103 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.old.format.Json");
+dojo.require("dojo.lang.assert");
+
+dojo.data.old.format.Json = new function() {
+
+ // -------------------------------------------------------------------
+ // Public functions
+ // -------------------------------------------------------------------
+ this.loadDataProviderFromFileContents = function(/* dojo.data.old.provider.Base */ dataProvider, /* string */ jsonFileContents) {
+ dojo.lang.assertType(dataProvider, dojo.data.old.provider.Base);
+ dojo.lang.assertType(jsonFileContents, String);
+ var arrayOfJsonData = eval("(" + jsonFileContents + ")");
+ this.loadDataProviderFromArrayOfJsonData(dataProvider, arrayOfJsonData);
+ };
+
+ this.loadDataProviderFromArrayOfJsonData = function(/* dojo.data.old.provider.Base */ dataProvider, /* Array */ arrayOfJsonData) {
+ dojo.lang.assertType(arrayOfJsonData, Array, {optional: true});
+ if (arrayOfJsonData && (arrayOfJsonData.length > 0)) {
+ var firstRow = arrayOfJsonData[0];
+ dojo.lang.assertType(firstRow, [Array, "pureobject"]);
+ if (dojo.lang.isArray(firstRow)) {
+ _loadDataProviderFromArrayOfArrays(dataProvider, arrayOfJsonData);
+ } else {
+ dojo.lang.assertType(firstRow, "pureobject");
+ _loadDataProviderFromArrayOfObjects(dataProvider, arrayOfJsonData);
+ }
+ }
+ };
+
+ this.getJsonStringFromResultSet = function(/* dojo.data.old.ResultSet */ resultSet) {
+ dojo.unimplemented('dojo.data.old.format.Json.getJsonStringFromResultSet');
+ var jsonString = null;
+ return jsonString; // String
+ };
+
+ // -------------------------------------------------------------------
+ // Private functions
+ // -------------------------------------------------------------------
+ function _loadDataProviderFromArrayOfArrays(/* dojo.data.old.provider.Base */ dataProvider, /* Array */ arrayOfJsonData) {
+ /**
+ * Example:
+ * var arrayOfJsonStates = [
+ * [ "abbr", "population", "name" ]
+ * [ "WA", 5894121, "Washington" ],
+ * [ "WV", 1808344, "West Virginia" ],
+ * [ "WI", 5453896, "Wisconsin" ],
+ * [ "WY", 493782, "Wyoming" ] ];
+ * this._loadFromArrayOfArrays(arrayOfJsonStates);
+ */
+ var arrayOfKeys = arrayOfJsonData[0];
+ for (var i = 1; i < arrayOfJsonData.length; ++i) {
+ var row = arrayOfJsonData[i];
+ var item = dataProvider.getNewItemToLoad();
+ for (var j in row) {
+ var value = row[j];
+ var key = arrayOfKeys[j];
+ item.load(key, value);
+ }
+ }
+ }
+
+ function _loadDataProviderFromArrayOfObjects(/* dojo.data.old.provider.Base */ dataProvider, /* Array */ arrayOfJsonData) {
+ /**
+ * Example:
+ * var arrayOfJsonStates = [
+ * { abbr: "WA", name: "Washington" },
+ * { abbr: "WV", name: "West Virginia" },
+ * { abbr: "WI", name: "Wisconsin", song: "On, Wisconsin!" },
+ * { abbr: "WY", name: "Wyoming", cities: ["Lander", "Cheyenne", "Laramie"] } ];
+ * this._loadFromArrayOfArrays(arrayOfJsonStates);
+ */
+ // dojo.debug("_loadDataProviderFromArrayOfObjects");
+ for (var i in arrayOfJsonData) {
+ var row = arrayOfJsonData[i];
+ var item = dataProvider.getNewItemToLoad();
+ for (var key in row) {
+ var value = row[key];
+ if (dojo.lang.isArray(value)) {
+ var arrayOfValues = value;
+ for (var j in arrayOfValues) {
+ value = arrayOfValues[j];
+ item.load(key, value);
+ // dojo.debug("loaded: " + key + " = " + value);
+ }
+ } else {
+ item.load(key, value);
+ }
+ }
+ }
+ }
+
+}();
+
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/format/Json.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/provider/Base.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/provider/Base.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/provider/Base.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/provider/Base.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,183 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.old.provider.Base");
+dojo.require("dojo.lang.assert");
+
+// -------------------------------------------------------------------
+// Constructor
+// -------------------------------------------------------------------
+dojo.data.old.provider.Base = function() {
+ /**
+ * summary:
+ * A Data Provider serves as a connection to some data source,
+ * like a relational database. This data provider Base class
+ * serves as an abstract superclass for other data provider
+ * classes.
+ */
+ this._countOfNestedTransactions = 0;
+ this._changesInCurrentTransaction = null;
+};
+
+// -------------------------------------------------------------------
+// Public instance methods
+// -------------------------------------------------------------------
+dojo.data.old.provider.Base.prototype.beginTransaction = function() {
+ /**
+ * Marks the beginning of a transaction.
+ *
+ * Each time you call beginTransaction() you open a new transaction,
+ * which you need to close later using endTransaction(). Transactions
+ * may be nested, but the beginTransaction and endTransaction calls
+ * always need to come in pairs.
+ */
+ if (this._countOfNestedTransactions === 0) {
+ this._changesInCurrentTransaction = [];
+ }
+ this._countOfNestedTransactions += 1;
+};
+
+dojo.data.old.provider.Base.prototype.endTransaction = function() {
+ /**
+ * Marks the end of a transaction.
+ */
+ this._countOfNestedTransactions -= 1;
+ dojo.lang.assert(this._countOfNestedTransactions >= 0);
+
+ if (this._countOfNestedTransactions === 0) {
+ var listOfChangesMade = this._saveChanges();
+ this._changesInCurrentTransaction = null;
+ if (listOfChangesMade.length > 0) {
+ // dojo.debug("endTransaction: " + listOfChangesMade.length + " changes made");
+ this._notifyObserversOfChanges(listOfChangesMade);
+ }
+ }
+};
+
+dojo.data.old.provider.Base.prototype.getNewItemToLoad = function() {
+ return this._newItem(); // dojo.data.old.Item
+};
+
+dojo.data.old.provider.Base.prototype.newItem = function(/* string */ itemName) {
+ /**
+ * Creates a new item.
+ */
+ dojo.lang.assertType(itemName, String, {optional: true});
+ var item = this._newItem();
+ if (itemName) {
+ item.set('name', itemName);
+ }
+ return item; // dojo.data.old.Item
+};
+
+dojo.data.old.provider.Base.prototype.newAttribute = function(/* string */ attributeId) {
+ /**
+ * Creates a new attribute.
+ */
+ dojo.lang.assertType(attributeId, String, {optional: true});
+ var attribute = this._newAttribute(attributeId);
+ return attribute; // dojo.data.old.Attribute
+};
+
+dojo.data.old.provider.Base.prototype.getAttribute = function(/* string */ attributeId) {
+ dojo.unimplemented('dojo.data.old.provider.Base');
+ var attribute;
+ return attribute; // dojo.data.old.Attribute
+};
+
+dojo.data.old.provider.Base.prototype.getAttributes = function() {
+ dojo.unimplemented('dojo.data.old.provider.Base');
+ return this._arrayOfAttributes; // Array
+};
+
+dojo.data.old.provider.Base.prototype.fetchArray = function() {
+ dojo.unimplemented('dojo.data.old.provider.Base');
+ return []; // Array
+};
+
+dojo.data.old.provider.Base.prototype.fetchResultSet = function() {
+ dojo.unimplemented('dojo.data.old.provider.Base');
+ var resultSet;
+ return resultSet; // dojo.data.old.ResultSet
+};
+
+dojo.data.old.provider.Base.prototype.noteChange = function(/* dojo.data.old.Item */ item, /* string or dojo.data.old.Attribute */ attribute, /* anything */ value) {
+ var change = {item: item, attribute: attribute, value: value};
+ if (this._countOfNestedTransactions === 0) {
+ this.beginTransaction();
+ this._changesInCurrentTransaction.push(change);
+ this.endTransaction();
+ } else {
+ this._changesInCurrentTransaction.push(change);
+ }
+};
+
+dojo.data.old.provider.Base.prototype.addItemObserver = function(/* dojo.data.old.Item */ item, /* object */ observer) {
+ /**
+ * summary: Registers an object as an observer of an item,
+ * so that the object will be notified when the item changes.
+ */
+ dojo.lang.assertType(item, dojo.data.old.Item);
+ item.addObserver(observer);
+};
+
+dojo.data.old.provider.Base.prototype.removeItemObserver = function(/* dojo.data.old.Item */ item, /* object */ observer) {
+ /**
+ * summary: Removes the observer registration for a previously
+ * registered object.
+ */
+ dojo.lang.assertType(item, dojo.data.old.Item);
+ item.removeObserver(observer);
+};
+
+// -------------------------------------------------------------------
+// Private instance methods
+// -------------------------------------------------------------------
+dojo.data.old.provider.Base.prototype._newItem = function() {
+ var item = new dojo.data.old.Item(this);
+ return item; // dojo.data.old.Item
+};
+
+dojo.data.old.provider.Base.prototype._newAttribute = function(/* String */ attributeId) {
+ var attribute = new dojo.data.old.Attribute(this);
+ return attribute; // dojo.data.old.Attribute
+};
+
+dojo.data.old.provider.Base.prototype._saveChanges = function() {
+ var arrayOfChangesMade = this._changesInCurrentTransaction;
+ return arrayOfChangesMade; // Array
+};
+
+dojo.data.old.provider.Base.prototype._notifyObserversOfChanges = function(/* Array */ arrayOfChanges) {
+ var arrayOfResultSets = this._getResultSets();
+ for (var i in arrayOfChanges) {
+ var change = arrayOfChanges[i];
+ var changedItem = change.item;
+ var arrayOfItemObservers = changedItem.getObservers();
+ for (var j in arrayOfItemObservers) {
+ var observer = arrayOfItemObservers[j];
+ observer.observedObjectHasChanged(changedItem, change);
+ }
+ for (var k in arrayOfResultSets) {
+ var resultSet = arrayOfResultSets[k];
+ var arrayOfResultSetObservers = resultSet.getObservers();
+ for (var m in arrayOfResultSetObservers) {
+ observer = arrayOfResultSetObservers[m];
+ observer.observedObjectHasChanged(resultSet, change);
+ }
+ }
+ }
+};
+
+dojo.data.old.provider.Base.prototype._getResultSets = function() {
+ dojo.unimplemented('dojo.data.old.provider.Base');
+ return []; // Array
+};
+
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/provider/Base.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/provider/Delicious.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/provider/Delicious.js?view=auto&rev=449122
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/provider/Delicious.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/provider/Delicious.js Fri Sep 22 16:22:30 2006
@@ -0,0 +1,85 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.data.old.provider.Delicious");
+dojo.require("dojo.data.old.provider.FlatFile");
+dojo.require("dojo.data.old.format.Json");
+
+// -------------------------------------------------------------------
+// Constructor
+// -------------------------------------------------------------------
+dojo.data.old.provider.Delicious = function() {
+ /**
+ * summary:
+ * The Delicious Data Provider can be used to take data from
+ * del.icio.us and make it available as dojo.data.old.Items
+ * In order to use the Delicious Data Provider, you need
+ * to have loaded a script tag that looks like this:
+ * <script type="text/javascript" src="http://del.icio.us/feeds/json/gumption?count=8"></script>
+ */
+ dojo.data.old.provider.FlatFile.call(this);
+ // Delicious = null;
+ if (Delicious && Delicious.posts) {
+ dojo.data.old.format.Json.loadDataProviderFromArrayOfJsonData(this, Delicious.posts);
+ } else {
+ // document.write("<script type='text/javascript'>dojo.data.old.provider.Delicious._fetchComplete()</script>");
+ /*
+ document.write("<script type='text/javascript'>alert('boo!');</script>");
+ document.write("<script type='text/javascript'>var foo = 'not dojo'; alert('dojo == ' + foo);</script>");
+ document.write("<script type='text/javascript'>var foo = fetchComplete; alert('dojo == ' + foo);</script>");
+ fetchComplete();
+ */
+ // dojo.debug("Delicious line 29: constructor");
+ }
+ var u = this.registerAttribute('u');
+ var d = this.registerAttribute('d');
+ var t = this.registerAttribute('t');
+
+ u.load('name', 'Bookmark');
+ d.load('name', 'Description');
+ t.load('name', 'Tags');
+
+ u.load('type', 'String');
+ d.load('type', 'String');
+ t.load('type', 'String');
+};
+dojo.inherits(dojo.data.old.provider.Delicious, dojo.data.old.provider.FlatFile);
+
+/********************************************************************
+ * FIXME: the rest of this is work in progress
+ *
+
+dojo.data.old.provider.Delicious.prototype.getNewItemToLoad = function() {
+ var newItem = this._newItem();
+ this._currentArray.push(newItem);
+ return newItem; // dojo.data.old.Item
+};
+
+dojo.data.old.provider.Delicious.prototype.fetchArray = function(query) {
+ if (!query) {
+ query = "gumption";
+ }
+ this._currentArray = [];
+ alert("Delicious line 60: loadDataProviderFromArrayOfJsonData");
+ alert("Delicious line 61: " + dojo);
+ var sourceUrl = "http://del.icio.us/feeds/json/" + query + "?count=8";
+ document.write("<script type='text/javascript' src='" + sourceUrl + "'></script>");
+ document.write("<script type='text/javascript'>alert('line 63: ' + Delicious.posts[0].u);</script>");
+ document.write("<script type='text/javascript'>callMe();</script>");
+ alert("line 66");
+ dojo.data.old.format.Json.loadDataProviderFromArrayOfJsonData(this, Delicious.posts);
+ return this._currentArray; // Array
+};
+
+callMe = function() {
+ alert("callMe!");
+};
+
+*/
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/data/old/provider/Delicious.js
------------------------------------------------------------------------------
svn:eol-style = native