|
Page Updated: January 28, 2002
Latest Version: 0.1.359 |
|
Debug |
Install | File
I/O |
RDF |
Network |
Sound | Utils |
XUL | Zip
|
|
|
Home | Mailing List |
Install |
Source Code |
Downloads | Bugs
| docs
| clients |
RDFResource ( will include rdfBase.js )
RDFResource
RDFResource is a class to manipulate rdf resources.
Note: This class is not intended to be directly created. RDF, RDFFile or RDFContainer should create this for you. See those classes for an example.
void RDFResource (string aType, string aPath, string aParent,
nsIRDFDataSource aDatasource)
Constructs an RDFResource by its type and paths in the datasource.aType - defines the type (this is used in the derived class of RDFContainer as well), see below.
aPath - a resource path of the container.
aParent - a resource path to the parent if any (null if no parent).
aDatasource - an nsIRDFDataSource object.
Possible aTypes values:
- "node" - a resource.
Example:
var node = new RDFResource("node", aContainer, this.parent, this.dsource);
RDFResource.prototype.getResource
Get the nsIRDFResource for the resource.
nsIRDFResource getResource ()Example:
This returns the internal nsIRDFResource so you can directly manipulate the resource.
var gRDF = new RDFFile(path);
var node = gRDF.getRootNode("urn:test:bob");
var res = node.getResource();
RDFResource.prototype.getSubject
Get the subject from the resource.
nsIRDFResource getSubject ()Example:
This returns the resource path of the resource (or the subject). For example, "urn:test:bob" is a subject.
var gRDF = new RDFFile(path );
var node = gRDF.getRootNode("urn:test:bob");
dump("node: "+node.getSubject()+"\n");
prints:
node: urn:test:bob
RDFResource.prototype.makeSeq
Change this node into a sequence.
RDFContainer makeSeq ()Example:
Returns the RDFContainer that this node was changed into. All attributes on this container are the same as was on the node. For example, if we had a node called "urn:test:emp100" with an attribute "name=bob". This information would also be on the container. The only difference would be, you could now create nodes under "urn:test:emp100".
var gRDF = new RDFFile(path );
var node = gRDF.getRootNode("urn:test:bob");
var newseq = node.makeSeq();
var addressnode = newseq.addNode("address");
RDFResource.prototype.makeBag
Change this node into a bag.
RDFContainer makeBag ()Example:
This is just like makeSeq(), except it creates a bag.
var gRDF = new RDFFile(path );
var node = gRDF.getRootNode("urn:test:bob");
var newbag = node.makeBag();
var addressnode = newbag.addNode("address");
RDFResource.prototype.makeAlt
Change this node into a alt.
RDFContainer makeAlt ()Example:
This is just like makeSeq(), except it creates a alt.
var gRDF = new RDFFile(path );
var node = gRDF.getRootNode("urn:test:bob");
var newalt = node.makeAlt();
var addressnode = newalt.addNode("address");
RDFResource.prototype.setAttribute
Sets an attribute for this resource.
boolean setAttribute (string aName, string aValue)
Returns success of failure. Failure in this case means that the node is not valid, and can not set the attribute. Attributes come in name, value pairs. For example, "name=bob".aName - Name of the attribute.
Example:
aValue - Value of the attribute.
var gRDF = new RDFFile(path );
var node = gRDF.getRootNode("urn:test:bob");
var rv = node.setAttribute("hobbies", "jslib");
RDFResource.prototype.getAttribute
Get an attributes value.
string getAttribute (string aName)
Returns the value of the specified attribute name. Will return null if invalid.aName - Name of the attribute.
Example:
var gRDF = new RDFFile(path );
var node = gRDF.getRootNode("urn:test:bob");
var hobbies = node.getAttribute("hobbies");
dump("hobbies: "+hobbies+"\n");
prints:
hobbies: jslib
RDFResource.prototype.removeAttribute
Removes an attribute.
void removeAttribute (string aName)
Removes an attribute specified by aName from the datasource. This won't take affect until you flush the datasource (i.e. gRDF.flush()).
aName - Name of the attribute.
Example:
var gRDF = new RDFFile(path );
var node = gRDF.getRootNode("urn:test:bob");
node.removeAttribute("hobbies");
gRDF.flush();
RDFResource.prototype.setAllAttributes
Set all attributes for a resource.
boolean setAllAttributes (Array of name/value pairs aList)Example:
With this call, you can set all the attributes on a resource at once. This will also remove attributes that are not in the list provided.
var gRDF = new RDFFile(path );
var node = gRDF.getRootNode("urn:test:bob");
var list = new Array();
list[0] = new Object();
list[0].name = "address";
list[0].value = "123 somewhere street";
node.setAllAttributes(list);
RDFResource.prototype.getAllAttributes
Get all the attributes for this resource.
Array of name/value pairs getAllAttributes ()Example:
Returns a list of name/value pairs for this resource.
var gRDF = new RDFFile(path );
var node = gRDF.getRootNode("urn:test:bob");
var list = node.getAllAttributes();
for(var i=0; i<list.length; i++) {
dump("name: "+list[i].name+" value: "+list[i].value+"\n");
}
RDFResource.prototype.remove
Remove this resource from the datasource.
void remove ()
Removes the resource from the datasource. Remember, that you have to flush the datasource to have this actually take affect. An internal valid boolean will be set to false, and any manipulation of this container will fail.
Example:
var gRDF = new RDFFile(path);
var node = gRDF.getRootNode("urn:test:bob");
node.remove();
// the variable alt is no longer valid.
gRDF.flush();