-
2007-07-31
RDF and template - [related Mozilla]
1. RDF and template1.1. Resourece descrīption framework
RDF (Resource Descrīption Framework) is a format that can be used to store resources such as bookmarks or mail. Alternatively, data in other formats can be used and code written that will read the file and create RDF data from it. This is how Mozilla works when it reads data such as bookmarks, the history or mail messages. Mozilla provides datasources for this common data so that you can easily use them.
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"xmlns:ANIMALS="http://www.some-fictitious-zoo.com/rdf#"><RDF:Seq about="http://www.some-fictitious-zoo.com/all-animals"><RDF:li><RDF:Descrīption about="http://www.some-fictitious-zoo.com/mammals/lion"><ANIMALS:name>Lion</ANIMALS:name><ANIMALS:species>Panthera leo</ANIMALS:species><ANIMALS:class>Mammal</ANIMALS:class></RDF:Descrīption></RDF:li><RDF:li><RDF:Descrīption about="http://www.some-fictitious-zoo.com/arachnids/tarantula"><ANIMALS:name>Tarantula</ANIMALS:name><ANIMALS:species>Avicularia avicularia</ANIMALS:species><ANIMALS:class>Arachnid</ANIMALS:class></RDF:Descrīption></RDF:li><RDF:li><RDF:Descrīption about="http://www.some-fictitious-zoo.com/mammals/hippopotamus"><ANIMALS:name>Hippopotamus</ANIMALS:name><ANIMALS:species>Hippopotamus amphibius</ANIMALS:species><ANIMALS:class>Mammal</ANIMALS:class></RDF:Descrīption></RDF:li></RDF:Seq></RDF:RDF>1.2. template
<?xml version="1.0"?><?xml-stylesheet href="chrome://global/skin/" type="text/css"?><window id="example-window" title="Example 9.2.1"xmlns:html="http://www.w3.org/1999/xhtml"xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"><vbox datasources="rdf:bookmarks" ref="NC:BookmarksRoot" flex="1"><template><button uri="rdf:*" label="rdf:http://home.netscape.com/NC-rdf#Name"/></template></vbox></window>In this case, rdf:bookmarks is used. You can probably guess that this means to use the bookmarks datasource. This datasource is provided by Mozilla. The ref attribute indicates where in the datasource you would like to retrieve data from. In the case of the bookmarks, the value NC:BookmarksRoot is used to indicate the root of the bookmarks hierarchy. An attribute value inside the template that begins with 'rdf:' indicates that the value should be taken from the datasource. In the example earlier, this is the case for the label attribute. The remainder of the value refers to the name property is the datasource. It is constructed by taking the namespace URL used by the datasource and appending the property name.1.3. Rules
We define a rule for each variation of elements that we want to have created. In our case, we would need a rule for bookmarks and a rule for separators. Attributes placed on the rule element determine which rules apply to which RDF resource.
<vbox datasources="rdf:bookmarks" ref="NC:BookmarksRoot" flex="1"><template><rule rdf:type="http://home.netscape.com/NC-rdf#BookmarkSeparator"><spacer uri="rdf:*" height="16"/></rule><rule><button uri="rdf:*" label="rdf:http://home.netscape.com/NC-rdf#Name"/></rule></template></vbox>
1.4. Adding Datasources to Trees
<tree id="my-tree" flex="1"
datasources="rdf:files" ref="file:///" flags="dont-built-content">
<treecols>
<treecol id="Name" label="Name" primary="true" flex="1"/>
<splitter/>
<treecol id="Date" label="Date" flex="1"/>
</treecols>
<template>
<rule>
<treechildren>
<treeitem uri="rdf.*">
<treerow>
<treecell label="rdf://http://home.netscape.com/NC-rdf#Name"/>
<treecell label="rdf://http:home.netscape.com/WEB-rdf#LastModifiedDate"/>
</treerow>
</treeitem>
</treechildren>
</rule>
</template>
</tree>
An interesting part of RDF datasources is that the resource values are only determined when the data is needed. This means that values that are deeper in the resource hierarchy are not determined until the user navigates to that node in the tree. This becomes useful for certain datasources where the data is determined dynamically.
1.5. Sorting columns
sortDirection sortActive and sortDirectionIndicator
<treecols><treecol id="Name" label="Name" flex="1" primary="true"class="sortDirectionIndicator" sortActive="true"sortDirection="ascending"sort="rdf:http://home.netscape.com/NC-rdf#Name"/><splitter/><treecol id="Date" label="Date" flex="1" class="sortDirectionIndicator"sort="rdf:http://home.netscape.com/WEB-rdf#LastModifiedDate"/></treecols>1.6. RDF Datasources
History list Bookmarks and Files
1.7. Custom RDF Datasources
<?xml version="1.0"?><RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"xmlns:ANIMALS="http://www.some-fictitious-zoo.com/rdf#"><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/arachnids"><ANIMALS:name>Arachnids</ANIMALS:name></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/arachnids/tarantula" ANIMALS:specimens="0"><ANIMALS:name>Tarantula</ANIMALS:name><ANIMALS:species>Avicularia avicularia</ANIMALS:species></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/birds"><ANIMALS:name>Birds</ANIMALS:name></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/birds/emu" ANIMALS:specimens="12"><ANIMALS:name>Emu</ANIMALS:name><ANIMALS:species>Dromaius novaehollandiae</ANIMALS:species></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/birds/barnowl" ANIMALS:specimens="4"><ANIMALS:name>Barn Owl</ANIMALS:name><ANIMALS:species>Tyto alba</ANIMALS:species></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/birds/raven" ANIMALS:specimens="0"><ANIMALS:name>Raven</ANIMALS:name><ANIMALS:species>Corvus corax</ANIMALS:species></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/fish"><ANIMALS:name>Fish</ANIMALS:name></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/fish/cod" ANIMALS:specimens="0"><ANIMALS:name>Cod</ANIMALS:name><ANIMALS:species>Gadus morhua</ANIMALS:species></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/fish/swordfish" ANIMALS:specimens="3"><ANIMALS:name>Swordfish</ANIMALS:name><ANIMALS:species>Xiphias gladius</ANIMALS:species></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/mammals"><ANIMALS:name>Mammals</ANIMALS:name></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/mammals/lion" ANIMALS:specimens="4"><ANIMALS:name>Lion</ANIMALS:name><ANIMALS:species>Panthera leo</ANIMALS:species></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/mammals/hippopotamus" ANIMALS:specimens="2"><ANIMALS:name>Hippopotamus</ANIMALS:name><ANIMALS:species>Hippopotamus amphibius</ANIMALS:species></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/mammals/africanelephant" ANIMALS:specimens="4"><ANIMALS:name>African Elephant</ANIMALS:name><ANIMALS:species>Loxodonta africana</ANIMALS:species></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/mammals/llama" ANIMALS:specimens="3"><ANIMALS:name>Llama</ANIMALS:name><ANIMALS:species>Lama glama</ANIMALS:species></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/mammals/polarbear" ANIMALS:specimens="0"><ANIMALS:name>Polar Bear</ANIMALS:name><ANIMALS:species>Thalarctos maritimus</ANIMALS:species></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/mammals/aardvark" ANIMALS:specimens="2"><ANIMALS:name>Aardvark</ANIMALS:name><ANIMALS:species>Orycteropus afer</ANIMALS:species></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/mammals/ninebandedarmadillo" ANIMALS:specimens="0"><ANIMALS:name>Nine-banded Armadillo</ANIMALS:name><ANIMALS:species>Dasypus novemcinctus</ANIMALS:species></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/reptiles"><ANIMALS:name>Reptiles</ANIMALS:name></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/reptiles/anaconda" ANIMALS:specimens="1"><ANIMALS:name>Anaconda</ANIMALS:name><ANIMALS:species>Eunectes murinus</ANIMALS:species></RDF:Descrīption><RDF:Descrīption RDF:about="http://www.some-fictitious-zoo.com/reptiles/chameleon" ANIMALS:specimens="2"><ANIMALS:name>Chameleon</ANIMALS:name><ANIMALS:species>Chamaeleo chamaelon</ANIMALS:species></RDF:Descrīption><RDF:Seq RDF:about="http://www.some-fictitious-zoo.com/all-animals"><RDF:li><RDF:Seq RDF:about="http://www.some-fictitious-zoo.com/arachnids"><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/arachnids/tarantula"/></RDF:Seq></RDF:li><RDF:li><RDF:Seq RDF:about="http://www.some-fictitious-zoo.com/birds"><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/birds/emu"/><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/birds/barnowl"/><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/birds/raven"/></RDF:Seq></RDF:li><RDF:li><RDF:Seq RDF:about="http://www.some-fictitious-zoo.com/fish"><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/fish/cod"/><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/fish/swordfish"/></RDF:Seq></RDF:li><RDF:li><RDF:Seq RDF:about="http://www.some-fictitious-zoo.com/mammals"><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/mammals/lion"/><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/mammals/hippopotamus"/><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/mammals/africanelephant"/><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/mammals/llama"/><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/mammals/polarbear"/><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/mammals/aardvark"/><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/mammals/ninebandedarmadillo"/></RDF:Seq></RDF:li><RDF:li><RDF:Seq RDF:about="http://www.some-fictitious-zoo.com/reptiles"><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/reptiles/anaconda"/><RDF:li RDF:resource="http://www.some-fictitious-zoo.com/reptiles/chameleon"/></RDF:Seq></RDF:li></RDF:Seq></RDF:RDF><?xml version="1.0"?><?xml-stylesheet href="chrome://global/skin/" type="text/css"?><windowid="example-window"title="History List"xmlns:ANIMALS="http://www.some-fictitious-zoo.com/rdf#"xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"><button label="Click here to see the mammals the zoo has" type="menu"datasources="animals.rdf" ref="http://www.some-fictitious-zoo.com/mammals"><template><rule ANIMALS:specimens="0"></rule><rule><menupopup><menuitem uri="rdf:*" label="rdf:http://www.some-fictitious-zoo.com/rdf#name"/></menupopup></rule></template></button></window>1.8. advanced rules
Full rules contain three child tags, a conditions tag, a bindings tag and an action tag, although the bindings tag is not always needed. If the conditions match for that resource, the content in the actions element is generated for that resource. If the conditions do not match, no content is







