LocalStore.jsm
Go to the documentation of this file.
1 
5 EXPORTED_SYMBOLS = [ "LocalStore" ];
6 
7 Ci = Components.interfaces;
8 Cc = Components.classes;
9 
10 var LocalStore = {
11  _dirty: false,
12  _rdf: null,
13  _localStore: null,
14 
15  _initialize: function() {
16  this._rdf = Cc["@mozilla.org/rdf/rdf-service;1"]
17  .getService(Ci.nsIRDFService);
18  this._localStore = this._rdf.GetDataSource("rdf:local-store");
19  },
20 
21  // Get an attribute value for an element id in a given file
22  getPersistedAttribute: function(file, id, attribute) {
23  if (!this._localStore)
24  this._initialize();
25 
26  var source = this._rdf.GetResource(file + "#" + id);
27  var property = this._rdf.GetResource(attribute);
28  var target = this._localStore.GetTarget(source, property, true);
29  if (target instanceof Ci.nsIRDFLiteral)
30  return target.Value;
31  return null;
32  },
33 
34  // Set an attribute on an element id in a given file
35  setPersistedAttribute: function(file, id, attribute, value) {
36  if (!this._localStore)
37  this._initialize();
38 
39  var source = this._rdf.GetResource(file + "#" + id);
40  var property = this._rdf.GetResource(attribute);
41  try {
42  var oldTarget = this._localStore.GetTarget(source, property, true);
43  if (oldTarget) {
44  if (value)
45  this._localStore.Change(source, property, oldTarget,
46  this._rdf.GetLiteral(value));
47  else
48  this._localStore.Unassert(source, property, oldTarget);
49  }
50  else {
51  this._localStore.Assert(source, property,
52  this._rdf.GetLiteral(value), true);
53  }
54  this._dirty = true;
55  }
56  catch(ex) {
57  Components.utils.reportError(ex);
58  }
59  },
60 
61  // Save changes if needed
62  flush: function flush() {
63  if (this._localStore && this._dirty) {
64  this._localStore.QueryInterface(Ci.nsIRDFRemoteDataSource).Flush();
65  this._dirty = false;
66  }
67  }
68 }
menuItem id
Definition: FeedWriter.js:971
Ci
Definition: LocalStore.jsm:7
return null
Definition: FeedWriter.js:1143
Cc
Definition: LocalStore.jsm:8
EXPORTED_SYMBOLS
Definition: LocalStore.jsm:5
countRef value
Definition: FeedWriter.js:1423
var file