Commit 10aa7bcb authored by Tristan Cavelier's avatar Tristan Cavelier

Merge branch 'master' into erp5storage

parents 7bbd7745 ea956c97
......@@ -26,11 +26,10 @@ zip:
@mkdir $(TMPDIR)/jio
@mkdir $(TMPDIR)/jio/storage
@cp jio.js $(TMPDIR)/jio/
@cp jiodate.js $(TMPDIR)/jio/
@cp jioquery.js $(TMPDIR)/jio/
@cp src/sha1.amd.js $(TMPDIR)/jio/
@cp src/sha2.amd.js $(TMPDIR)/jio/
@cp src/sha256.amd.js $(TMPDIR)/jio/
@cp src/jio.date/jiodate.js $(TMPDIR)/jio/
@cp lib/rsvp/rsvp-custom.js $(TMPDIR)/jio/
@cp lib/rsvp/rsvp-custom.amd.js $(TMPDIR)/jio/
@cp lib/jquery/jquery.js $(TMPDIR)/jio/
......
......@@ -34,11 +34,11 @@ See below XML and its JSON equivalent:
+============================================+=======================================+
| .. code-block:: xml | .. code-block:: javascript |
| | |
| <dc:title>My Title</dc:title> | {"title":"My Title"} |
| <dc:title>My Title</dc:title> | {"title": "My Title"} |
+--------------------------------------------+---------------------------------------+
| .. code-block:: xml | .. code-block:: javascript |
| | |
| <dc:contributor>Me</dc:contributor> | {"contributor":["Me", "And You"]} |
| <dc:contributor>Me</dc:contributor> | {"contributor": ["Me", "And You"]} |
| <dc:contributor>And You</dc:contributor> | |
+--------------------------------------------+---------------------------------------+
| .. code-block:: xml | .. code-block:: javascript |
......@@ -63,7 +63,7 @@ Identification
A specific jIO metadata which helps the storage to find a document
(can be a real path name, a dc:identifier, a uuid, ...). **String Only**
* **identifer**
* **identifier**
| ``{"identifier": "http://domain/jio_home_page"}``
| ``{"identifier": "urn:ISBN:978-1-2345-6789-X"}``
......@@ -73,7 +73,7 @@ Identification
best practice is to identify the resource with a string or number
conforming to a formal identification system. Examples of formal identification
systems include the `Uniform Resource Identifier <http://en.wikipedia.org/wiki/URI>`_ (URI)
(including the `Uniform Resource Locator <http://en.wikipedia.org/wiki/URL>`_ (URL),
(including the `Uniform Resource Locator <http://en.wikipedia.org/wiki/URL>`_ (URL)),
the `Digital Object Identifier <http://en.wikipedia.org/wiki/Digital_object_identifier>`_ (DOI)
and the `International Standard Book Number <http://en.wikipedia.org/wiki/Isbn>`_ (ISBN).
......
......@@ -4773,8 +4773,17 @@ SimpleQuery.prototype.match = function (item) {
cast_to = this._key_schema.cast_lookup[cast_to];
}
value = cast_to(value);
object_value = cast_to(object_value);
try {
value = cast_to(value);
} catch (e) {
value = undefined;
}
try {
object_value = cast_to(object_value);
} catch (e) {
object_value = undefined;
}
}
} else {
object_value = item[key];
......
......@@ -5,7 +5,7 @@
*/
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, regexp: true */
/*global jIO, localStorage, setTimeout, window, define,
/*global jIO, localStorage, setTimeout, window, define, Blob, Uint8Array,
exports, require */
/**
......@@ -286,7 +286,7 @@
* @param {Object} options The command options
*/
LocalStorage.prototype.getAttachment = function (command, param) {
var doc;
var doc, i, uint8array, binarystring;
doc = this._storage.getItem(this._localpath + "/" + param._id);
if (doc === null) {
return command.error(
......@@ -305,13 +305,22 @@
);
}
// Storing data twice in binarystring and in uint8array (in memory)
// is not a problem here because localStorage <= 5MB
binarystring = this._storage.getItem(
this._localpath + "/" + param._id + "/" + param._attachment
) || "";
uint8array = new Uint8Array(binarystring.length);
for (i = 0; i < binarystring.length; i += 1) {
uint8array[i] = binarystring.charCodeAt(i); // mask `& 0xFF` not necessary
}
uint8array = new Blob([uint8array], {
"type": doc._attachments[param._attachment].content_type || ""
});
command.success({
"data": this._storage.getItem(
this._localpath + "/" + param._id +
"/" + param._attachment
) || "",
"digest": doc._attachments[param._attachment].digest,
"content_type": doc._attachments[param._attachment].content_type || ""
"data": uint8array,
"digest": doc._attachments[param._attachment].digest
});
};
......
......@@ -159,8 +159,17 @@ SimpleQuery.prototype.match = function (item) {
cast_to = this._key_schema.cast_lookup[cast_to];
}
value = cast_to(value);
object_value = cast_to(object_value);
try {
value = cast_to(value);
} catch (e) {
value = undefined;
}
try {
object_value = cast_to(object_value);
} catch (e) {
object_value = undefined;
}
}
} else {
object_value = item[key];
......
......@@ -106,8 +106,59 @@
////////////////////////////////////////////////////////////
function Uint8Array(one) { // , two, three
/*jslint bitwise: true */
var i;
if (one instanceof Uint8Array) {
for (i = 0; i < one.length; i += 1) {
this[i] = one[i] & 0xFF;
}
this.length = one.length;
return;
}
if (typeof one === "number" && isFinite(one)) {
for (i = 0; i < one; i += 1) {
this[i] = 0;
}
this.length = one;
return;
}
// if (one instanceof ArrayBuffer) {
// two === byteOffset
// three === length
// }
this.length = 0;
}
Uint8Array.prototype.set = function () {
throw new Error("Not implemented");
};
Uint8Array.prototype.subarray = function (begin, end) {
if (typeof begin !== "number" || !isFinite(begin) || begin < 0) {
begin = 0;
}
if (begin > this.length) {
begin = this.length;
}
if (typeof end !== "number" || !isFinite(end) || end > this.length) {
end = this.length;
}
if (end < begin) {
end = begin;
}
var i, j, uint8array = new Uint8Array(end - begin);
/*jslint bitwise: true */
for (i = begin, j = 0; i < end; i += 1, j += 1) {
uint8array[j] = this[i] & 0xFF;
}
return uint8array;
};
////////////////////////////////////////////////////////////
function Blob(parts, properties) {
var i, part, raw = '', type;
var i, j, part, raw = '', type;
type = (properties && properties.type && properties.type.toString()) || "";
if (!Array.isArray(parts)) {
throw new TypeError("The method parameter is missing or invalid.");
......@@ -121,6 +172,11 @@
part = parts[i];
if (part instanceof Blob) {
raw += part._data;
} else if (part instanceof Uint8Array) {
/*jslint bitwise: true */
for (j = 0; j < part.length; j += 1) {
raw += String.fromCharCode(part[j] & 0xFF);
}
} else if (part) {
raw += stringToUtf8ByteString(part.toString());
} else if (part === undefined) {
......@@ -160,8 +216,7 @@
};
////////////////////////////////////////////////////////////
// https://github.com/TristanCavelier/notesntools/blob/\
// master/javascript/emitter.js
function FileReader() {
return;
}
......@@ -263,7 +318,8 @@
(/\bPhantomJS\b/i).test(navigator.userAgent)) {
window.Blob = Blob;
window.FileReader = FileReader;
//console.warn("Blob and FileReader have been replaced!");
window.Uint8Array = Uint8Array;
//console.warn("Blob, FileReader and Uint8Array have been replaced!");
}
if (!Function.prototype.bind) {
......
......@@ -130,6 +130,10 @@
read_from: 'date',
cast_to: dateCast,
equal_match: sameYear
},
broken: {
read_from: 'date',
cast_to: function () { throw new Error('Broken!'); }
}
};
......@@ -178,6 +182,19 @@
})
);
promise.push(
jIO.QueryFactory.create({
type: 'simple',
key: keys.broken,
value: '2013-02-10'
}).
exec(docList()).
then(function (dl) {
deepEqual(dl.length, 0,
'Constructors that throw exceptions should not break a query, but silently fail comparisons');
})
);
RSVP.all(promise).then(noop).always(start);
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment