|
Page Updated: June 06, 2001
Latest Version: 0.1.375 |
|
Debug |
Install | File
I/O |
RDF |
Network |
Sound | Utils |
XUL | Zip
|
|
|
Home | Mailing List |
Install |
Source Code |
Downloads | Bugs
| docs
| clients |
RDF Manipulation classes
RDF class
Generic class to load and manipulate rdfs.RDF(src, root, nc, flags)
Constructor
[in] src --> A url to an rdf
[in] root --> Root sequence for the
data (i.e. 'urn:animals' or 'urn:data')
[in] nc --> nc for the rdf
file (i.e. 'http://www.urbanrage.com/rdf#')
Example:
var src = "http://www.foo.com/bob.rdf";
var root = "urn:foodata";
var nc = "http://www.urbanrage.com/rdf#";
var gRDF = new RDF(src, root, nc);
RDF File Class
Requires:
file.js
RDFFile does everything RDF does except it takes a path or file url as its first parameter. It then takes this and checks wether or not the file exist, and creates it if it isn't (optional).
RDFFile(path, root, nc, flags)
Constructor
[in] path --> A path to the rdf
file (you must have permissions)
[in] root --> Root sequence for the
data (i.e. 'urn:animals' or 'urn:data')
[in] nc --> nc for the rdf
file (i.e. 'http://www.urbanrage.com/rdf#')
Example:
var path = "/tmp/foo.rdf";
var root = "urn:foodata";
var nc = "http://www.urbanrage.com/rdf#";
var gRDF = new RDFFile(path, root,
nc);
loaded
Tells if the datasource has finished loading
addSeq(aSeq)
Addes a "Sequence" to the rdf file (i.e. a catagory)
Checks if the given name, value exists.
[in] aSeq --> The name of the sequence
(i.e. "birds" or "cities:minneapolis").
Example:
gRDF.addSeq("city")
removeSeq(aSeq, deep)
Removes the "Sequence" from the datasource and the rdf file.
[in] aSeq --> The name of the sequence
(i.e. "birds" or "cities:minneapolis").
[in] deep --> Recursively remove
sequeces and nodes. WARNING, if you have circular references,
you could run into some real problems here.
Example:
gRDF.addSeq("cities:minneapolis");
gRDF.addSeq("cities:st paul");
gRDF.removeSeq("cities", true);
// removes both minneapolis, st paul, and cities from the rdf file.
isSeq(aSeq)
Returns true if it is a sequence.
[in] aSeq --> The name of the sequence
(i.e. "birds" or "cities:minneapolis").
Example:
if(gRDF.isSeq("cities")) {
gRDF.removeSeq("cities",
true); // removes both minneapolis, st paul, and cities from the
rdf file.
}
doesSeqExist(aSeq)
Returns true if the sequence exists in the rdf file.
[in] aSeq --> The name of the sequence
(i.e. "birds" or "cities:minneapolis").
Example:
if(gRDF.doesSeqExist("cities"))
{
...
}
getSeqSubNodes(aSeq)
Returns and "Array" of Nodes that are contained by "aSeq".
[in] aSeq --> The name of the sequence
(i.e. "birds" or "cities:minneapolis").
Example:
var list = gRDF.getSeqSubNodes("cities:minneapolis");
for(var i=0; i<list.length();
i++) {
// do something....
}
getSeqSubSeqs(aSeq)
Returns and "Array" of Sequences that are contained by "aSeq".
[in] aSeq --> The name of the sequence
(i.e. "birds" or "cities:minneapolis").
Example:
var list = gRDF.getSeqSubNodes("cities");
for(var i=0; i<list.length();
i++) {
// do something....
}
addNode(aNode)
Addes a node to a sequence. This can be the default one
that already set up.
[in] aNode --> The name of the node
(i.e. "birds" or "cities:minneapolis").
Example:
gRDF = new rdf(file, "urn:cities",
"http://www.urbanrage.com/rdf#");
gRDF.addNode("prefs"); //
adds the node "urn:cities:prefs"
removeNode(aNode)
Removes the node from the rdf file.
[in] aNode --> The name of the node
(i.e. "birds" or "cities:minneapolis").
Example:
gRDF.removeNode("prefs");
// removes the node "urn:cities:prefs"
isNode(aNode)
Returns true if it is a node.
[in] aNode --> The name of the node
(i.e. "prefs" or "cities:minneapolis").
Example:
if(gRDF.isNode("prefs")) {
gRDF.removeNode("prefs");
// removes the prefs node
}
doesNodeExist(aNode)
Returns true if the node exists in the rdf file.
[in] aNode --> The name of the node
(i.e. "prefs" or "cities:minneapolis").
Example:
if(gRDF.doesNodeExist("prefs"))
{
...
}
setAttribute(aNode, name, value)
Sets an attribute to a node with the given name/value pair
[in] aNode --> The name of the node
(i.e. "prefs" or "cities:minneapolis").
[in] name --> The attribute name.
[in] value --> The value of the attribute.
Example:
gRDF.setAttribute("prefs", "currentCity",
"minneapolis");
getAttribute(aNode, name)
Gets an attribute to a node with the given name.
[in] aNode --> The name of the node
(i.e. "prefs" or "cities:minneapolis").
[in] name --> The attribute name.
Example:
gRDF.getAttribute("prefs", "currentCity");
// returns "minneapolis"
removeAttribute(aNode, name)
Removes an attribute that is associated with the given node.
[in] aNode --> The name of the node
(i.e. "prefs" or "cities:minneapolis").
[in] name --> The attribute name.
Example:
gRDF.removeAttribute("prefs",
"currentCity"); // removes the attribute "currentCity"
doesAttributeExist(aNode, name)
Returns true if there is an attribute with the given "name"
arc'd off of aNode.
[in] aNode --> The name of the node
(i.e. "prefs" or "cities:minneapolis").
[in] name --> The attribute name.
Example:
if(gRDF.doesAttributeExist("prefs",
"currentCity")) {
// do something....
}
flush()
Writes changed information out to the rdf file. NOTE:
If you delete nodes or sequences, it
doesn't take affect until you call this function. This
was done to increase processing time.
Example:
gRDF.removeAttribute("prefs",
"currentCity"); // removes the attribute "currentCity"
gRDF.flush();
Full source code is available under the MPL license and has been added to the core Mozilla distribution.
If you do not get a response to a question posted in this forum, please try sending a message to the project's mailing list or to the project owner directly.
- [1] Submitted by: Allan on Wednesday September 10th 2003
-
Nice project!