RDFHelper.jsm File Reference

Go to the source code of this file.

Functions

function RDFHelper (aRdf, aDatasource, aResource, aNamespaces)
 

Variables

 EXPORTED_SYMBOLS = [ "RDFHelper" ]
 
 Ci = Components.interfaces
 
 Cc = Components.classes
 
RDFHelper help
 
RDFHelper DEFAULT_RDF_NAMESPACES
 
RDFHelper DEFAULT_RDF_NAMESPACES_PREFIXED
 

Function Documentation

function RDFHelper (   aRdf,
  aDatasource,
  aResource,
  aNamespaces 
)

Definition at line 61 of file RDFHelper.jsm.

Variable Documentation

Cc = Components.classes

Definition at line 58 of file RDFHelper.jsm.

Definition at line 57 of file RDFHelper.jsm.

RDFHelper DEFAULT_RDF_NAMESPACES
Initial value:
= {
"http://www.w3.org/1999/02/22-rdf-syntax-ns#": "",
"http://www.mozilla.org/2004/em-rdf#": "",
"http://www.songbirdnest.com/2007/addon-metadata-rdf#": ""
}

Definition at line 182 of file RDFHelper.jsm.

RDFHelper DEFAULT_RDF_NAMESPACES_PREFIXED
Initial value:
= {
"http://www.w3.org/1999/02/22-rdf-syntax-ns#": "rdf_",
"http://www.mozilla.org/2004/em-rdf#": "moz_",
"http://www.songbirdnest.com/2007/addon-metadata-rdf#": "sb_"
}

Definition at line 188 of file RDFHelper.jsm.

EXPORTED_SYMBOLS = [ "RDFHelper" ]

RDFHelper.jsm

USE: RDFHelper(aRdf, aRDFDatasource, aRDFResource, aNamespacesHash)

This class allows you to treat an RDF datasource as though it were a read-only structured object. (Please, don't try to write to it. It will only lead to grief.)

Arcs are mapped to properties by trimming their namespaces (they can be reduced to prefixes if you prefer). Because there may be several arcs leading from a resource, each property is returned as an array of the targets. Literals become values directly, and all other arcs lead to further arcs.

STATIC RDF SOURCE: The RDFHelper is not so clever as to notice changes to your datasource after it creates the value. As a result, you should not reuse RDFHelpers unless you are sure your data has not changed in-between.

CYCLIC RELATIONSHIPS: Links are evaluated lazily, so creating an RDFHelper object on a cyclic graph will not kill your process, but trying to crawl it probably will! Objects are not reused, so if you return to the same place twice, you won't be able to tell through naive object comparison, and infinitely traversing a graph cycle will be a race between overflowing your stack and eating all your memory.

CONTAINERS: Containers are a special case where the object returned appears to be array-like, insofar as it has numeric indices and a .length property, but is not actually an instanceof Array.

HELP: Because looking up RDF resources is tedious and unpleasant, a few helper bits are provided.

RDFHelper.help: Accepts URI strings representing a datasource, a resource, and an object containing namespaces. namespaces look like: { "rdf:/namespace/prefix/whatever": "prefix_", "trimmed-prefix": "" } EXAMPLE: RDFHelper.help("rdf:addon-metadata", "urn:songbird:addon:root", RDFHelper.prototype.DEFAULT_RDF_NAMESPACES);

RDFHelper.DEFAULT_RDF_NAMESPACES{PREFIXED}: For convenience, provides rdf, mozilla, and songbird namespace objects that translate namespaces into object property prefixes. With _PREFIXED, your properties will begin with rdf, moz_ or sb_. Without, namespaces will simply be removed. If you are concerned about collisions, be sure to map only one prefix to "".

USAGE EXAMPLE:

get the first display pane from the first addon and copy its properties into the "info" object.

var addons = RDFHelper.help("rdf:addon-metadata", "urn:songbird:addon:root", RDFHelper.prototype.DEFAULT_RDF_NAMESPACES); if (addons[0].displayPanes && addons[0].displayPanes[0].displayPane[0]) { var pane = addons[0].displayPanes[0].displayPane[0] var info = {}; for (property in pane) { if (pane[property]) info[property] = pane[property][0]; } }

Definition at line 55 of file RDFHelper.jsm.

RDFHelper help
Initial value:
= function(datasource, resource, namespaces) {
var rdf = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
var helper = new RDFHelper(
rdf,
rdf.GetDataSourceBlocking(datasource),
rdf.GetResource(resource),
namespaces
);
return helper;
}
Ci
Definition: RDFHelper.jsm:57
Cc
Definition: RDFHelper.jsm:58
function RDFHelper(aRdf, aDatasource, aResource, aNamespaces)
Definition: RDFHelper.jsm:61

Definition at line 170 of file RDFHelper.jsm.