[Jslib] Re: Creating a new RDF file with the rdf libraries
Pete Collins
pete@mozdev.org
Sat, 06 Apr 2002 22:58:40 -0500
Eric Hodel wrote:
> I'm trying to use the following code to create a new RDF file to cache
> data for a livejournal client. The Filesystem stuff I stole out of
> mozcalc as jslib does not have a getProfileDir() function in DirUtils (I
> didn't check the actual code yet).
Yes it does, its called getMozUserHomeDir()
dirUtils covers all af the constants defined here:
http://lxr.mozilla.org/seamonkey/source/xpcom/io/nsAppDirectoryServiceDefs.h
And even has some documentation here:
http://jslib.mozdev.org/libraries/io/dirUtils.js.html
--pete
>
> The only thing I get so far is the file "livelizard.rdf" created in my
> profile directory. However, the seq (urn:livelizard:moods) is always
> null, so none of the data gets copied. I've looked through the docs,
> but can't seem to figure out how to put the pieces together to make it
> do what I want.
>
> (Looking through mozcalc wasn't any help either, apparently it suffers
> from a similar problem.)
>
> function saveMoods() {
> var file = Filesystem.concatPath(Filesystem.getMozUserHomeDir(),
> "livelizard.rdf");
> var livelizardRDF = new RDFFile(file);
>
> var seq = livelizardRDF.addRootSeq("urn:livelizard:moods");
> if (seq != null) {
> for (var i = 1; i <= moods.length; i++) {
> var mood = moods[i];
> var mood_id = mood[MOOD_ID];
> var mood_name = mood[MOOD_NAME];
> //alert(i + " id: " + mood_id + ", name: " + mood_name);
> var node = seq.addNode(mood_id);
> seq.setAttribute("urn:livelizard:moods:" + mood_id,
> "Name", mood_name);
> }
> }
>
> livelizardRDF.flush();
> }