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 RDFHelper | ( | aRdf, | |
aDatasource, | |||
aResource, | |||
aNamespaces | |||
) |
Definition at line 61 of file RDFHelper.jsm.
Cc = Components.classes |
Definition at line 58 of file RDFHelper.jsm.
Definition at line 57 of file RDFHelper.jsm.
RDFHelper DEFAULT_RDF_NAMESPACES |
Definition at line 182 of file RDFHelper.jsm.
RDFHelper DEFAULT_RDF_NAMESPACES_PREFIXED |
Definition at line 188 of file RDFHelper.jsm.
EXPORTED_SYMBOLS = [ "RDFHelper" ] |
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 |
Definition at line 170 of file RDFHelper.jsm.