Diff for /books/www/chapters/ch10.html between versions 1.10 and 1.14

version 1.10, 2002/12/11 19:10:24 version 1.14, 2003/03/29 10:13:48
Line 287  xmlns:comp="my.computer.hardware#" Line 287  xmlns:comp="my.computer.hardware#"
       RDF recommendation document.</p>        RDF recommendation document.</p>
     </blockquote>      </blockquote>
     <h4><a name="77068"></a> Examining a simple RDF file</h4>      <h4><a name="77068"></a> Examining a simple RDF file</h4>
    <p>We begin     
    <!--INDEX RDF (Resource Description Framework):syntax:files --><p>We begin 
    <!--INDEX syntax, RDF:files --> <!--INDEX files:RDF:syntax -->  <!--INDEX RDF (Resource Description Framework):syntax:files -->
    with an example of an RDF file whose basic layout and simple  <!--INDEX syntax, RDF:files -->
    syntax can be a model for the more advanced data introduced  <!--INDEX files:RDF:syntax -->
    later. The RDF file shown in <a href="#77026">Example 10-1</a>  with an example of an RDF file whose basic layout and simple syntax can be a 
    is a list of three types of "flies," with the context of those  model for the more advanced data introduced later. The RDF file shown in <a href="#77026">Example 
    "flies" inside a "jar." <a href="#77026">Example 10-1</a> also  10-1</a> is a list of three types of "flies", with the context of those "flies" 
    contains a namespace that defines these types of flies and  inside a "jar." <a href="#77026">Example 10-1</a> also contains a namespace 
    shows the <tt>rdf</tt> and <tt>fly</tt> XML intertwined.</p>  that defines these types of flies and shows the <tt>rdf</tt> and <tt>fly</tt> 
   XML intertwined.</p>
     <p><i>Example 10-1: <a name="77026"></a></i> <i>Simple RDF file      <p><i>Example 10-1: <a name="77026"></a></i> <i>Simple RDF file
     with "fly" namespace</i></p>      with "fly" namespace</i></p>
 <pre>  <pre>
Line 306  xmlns:comp="my.computer.hardware#" Line 307  xmlns:comp="my.computer.hardware#"
 "http://www.w3.org/1999/02/22-rdf-syntax-ns">http://www.w3.org/1999/02/22-rdf-syntax-ns</a>#"  "http://www.w3.org/1999/02/22-rdf-syntax-ns">http://www.w3.org/1999/02/22-rdf-syntax-ns</a>#"
       xmlns:fly="<a href=        xmlns:fly="<a href=
 "http://xfly.mozdev.org/fly-rdf">http://xfly.mozdev.org/fly-rdf</a>#"&gt;  "http://xfly.mozdev.org/fly-rdf">http://xfly.mozdev.org/fly-rdf</a>#"&gt;
     &lt;rdf:Description about="<a href=     &lt;rdf:Description about="urn:root"&gt;
"http://my.jar-of-flies.com">http://my.jar-of-flies.com</a>"&gt; 
        &lt;fly:types&gt;         &lt;fly:types&gt;
          &lt;rdf:Bag&gt;           &lt;rdf:Bag&gt;
            &lt;rdf:li&gt;             &lt;rdf:li&gt;
Line 334  xmlns:comp="my.computer.hardware#" Line 334  xmlns:comp="my.computer.hardware#"
     attributes guarantee the unique nature of each element and      attributes guarantee the unique nature of each element and
     relationship.</p>      relationship.</p>
 <pre>  <pre>
&lt;rdf:Description about="<a href=&lt;rdf:Description about="urn:root"&gt;
"http://my.jar-of-flies.com">http://my.jar-of-flies.com</a>"&gt; 
 &lt;fly:types&gt;  &lt;fly:types&gt;
 &lt;rdf:Bag&gt;  &lt;rdf:Bag&gt;
 </pre>  </pre>
    <p><tt><a href=    
    "http://my.jar-of-flies.com">http://my.jar-of-flies.com</a></tt>,<p><tt>urn:root</tt>, is the subject shown in the previous code snippet. It is 
    is the subject shown in the previous code snippet. <i>My jar of  also a resource definition and defines only what flies are inside of the statement. 
    flies</i> is a resource definition and defines only what  The predicate, which addresses a property in the resource, is defined by the 
    <i>flies</i> are inside of the statement. The predicate, which  tag <tt>&lt;types&gt;</tt> (of the <tt><a href=
    addresses a property in the resource, is defined by the tag    "http://xfly.mozdev.org/fly-rdf">http://xfly.mozdev.org/fly-rdf</a>#</tt> 
    <tt>&lt;types&gt;</tt> (of the <tt><a href=  namespace).</p>
    "http://xfly.mozdev.org/fly-rdf">http://xfly.mozdev.org/fly-rdf</a>#</tt>    
    namespace).</p><p>The final part of the statement, the object, is the actual data of the predicate 
    <p>The final part of the statement, the object, is the actual  and a container of type bag. The container is an RDF resource that "holds", 
    data of the predicate and a container of type bag. The  or points to, a collection of other resources. In the next section, container 
    container is an RDF resource that "holds," or points to, a  types are discussed in depth. <a href="#77010">Figure 10-5</a> illustrates how 
    collection of other resources. In the next section, container  the triple originates from the root subject and includes the container object.</p>
    types are discussed in depth. <a href="#77010">Figure 10-5</a> 
    illustrates how the triple originates from the root subject and 
    includes the container object.</p> 
     <div class="c22">      <div class="c22">
       <img src="foo.gif">        <img src="foo.gif">
     </div>      </div>
Line 869  xmlns:location="fly-location#"&gt; Line 865  xmlns:location="fly-location#"&gt;
       </tr>        </tr>
       <tr>        <tr>
         <td>Local datasource</td>          <td>Local datasource</td>
        <td>A local datasource is an RDF graph contained in an        
        RDF/XML file on a local disk. All RDF files in the chrome    <td>A local datasource is an RDF graph contained in an RDF/XML file on a local 
        registry (e.g.,</td>      disk. All RDF files in the chrome directory (e.g., <i>all-packages.rdf</i> 
       in the <i>chrome</i> directory, which keeps track of packages installed 
       in Mozilla) are local datasources.</td>
       </tr>        </tr>
       <tr>        <tr>
         <td>Remote datasource</td>          <td>Remote datasource</td>
Line 881  xmlns:location="fly-location#"&gt; Line 879  xmlns:location="fly-location#"&gt;
       </tr>        </tr>
       <tr>        <tr>
         <td>In-memory datasource</td>          <td>In-memory datasource</td>
        <td>An in-memory datasource exists only in memory during a        
        Mozilla session. In-memory datasources are built with</td>    <td>An in-memory datasource exists only in memory during a Mozilla session. 
       In-memory datasources are built with <i>assertions</i>, statements that 
       build an in-memory data model by adding resources, add properties, and value 
       those.</td>
       </tr>        </tr>
       <tr>        <tr>
         <td>Built-in datasource</td>          <td>Built-in datasource</td>
        <td>These unique, prefabricated datasources represent        
        something used often in Mozilla, such as a built-in</td>    <td>These unique, prefabricated datasources represent something used often 
       in Mozilla, such as a built-in <i>filesystem</i> datasource and a <i>history</i> 
       datasource.</td>
       </tr>        </tr>
       <tr>        <tr>
         <td>Composite datasource</td>          <td>Composite datasource</td>
Line 1006  searchDS.RememberLastSearchText(escapedS Line 1009  searchDS.RememberLastSearchText(escapedS
 <pre>  <pre>
 rdf:SomeName  rdf:SomeName
 </pre>  </pre>
      The URI is also accessible as a datasource property:      
      <hr>  <p>The URI, such as <i>rdf:someName</i>, is also accessible as a datasource 
     property: </p>
   <pre>foo-ds.URI</pre>
   <hr>
     </blockquote>      </blockquote>
     foo-ds.URI   
     <h3><a name="77083"></a> What Are RDF Interfaces?</h3>      <h3><a name="77083"></a> What Are RDF Interfaces?</h3>
     <p>RDF interfaces       <p>RDF interfaces 
     <!--INDEX RDF (Resource Description Framework):interfaces:overview -->      <!--INDEX RDF (Resource Description Framework):interfaces:overview -->
Line 1024  rdf:SomeName Line 1029  rdf:SomeName
     node</i></p>      node</i></p>
 <pre>  <pre>
  // get the nsIRDFService interface and assign it to RDF   // get the nsIRDFService interface and assign it to RDF
 RDF = Components.classes&lt;/td&gt;<a href= RDF = Components.classes.["@mozilla.org/rdf/rdf-service;1"].
"MAILTO:[`@mozilla.org/rdf/rdf-service;1">[`@mozilla.org/rdf/rdf-service;1</a>']. 
        getService(Components.interfaces.nsIRDFService);         getService(Components.interfaces.nsIRDFService);
  // call the GetResource method from the interface   // call the GetResource method from the interface
  rootResource = RDF.GetResource('urn:root');   rootResource = RDF.GetResource('urn:root');
Line 1048  rdf:SomeName Line 1052  rdf:SomeName
       </tr>        </tr>
       <tr>        <tr>
         <td>nsIRDFService</td>          <td>nsIRDFService</td>
        <td>Mostly used for retrieving, datasources, resources, and        
        literals. It also registers and unregisters datasources and    <td>Mostly used for retrieving datasources, resources, and literals. It also 
        resources.</td>      registers and unregisters datasources and resources.</td>
       </tr>        </tr>
       <tr>        <tr>
         <td>nsIRDFCompositeDataSource</td>          <td>nsIRDFCompositeDataSource</td>
Line 1066  rdf:SomeName Line 1070  rdf:SomeName
       </tr>        </tr>
       <tr>        <tr>
         <td>nsIRDFNode, nsIRDFResource, nsIRDFLiteral</td>          <td>nsIRDFNode, nsIRDFResource, nsIRDFLiteral</td>
        <td>Provide an equality function. Values for resources and        
        literals can be retrieved. Objects of these types are    <td>Provide an equality function. Values for resources and literals can be 
        retrieved from</td>      retrieved. Objects of these types are retrieved from nsIRDFService.</td>
       </tr>        </tr>
       <tr>        <tr>
         <td>nsIRDFContainer</td>          <td>nsIRDFContainer</td>
Line 1557  aValue = literal.Value; Line 1561  aValue = literal.Value;
     only <tt>sequence</tt> is covered here.) To create an instance      only <tt>sequence</tt> is covered here.) To create an instance
     of <i>nsIRDFContainerUtils</i>, use the following:</p>      of <i>nsIRDFContainerUtils</i>, use the following:</p>
 <pre>  <pre>
containerUtils = Components.classes['@mozilla.org/rdf/container-utils;1'containerUtils = Components.classes['@mozilla.org/rdf/container-utils;1'].
 getService(Components.interfaces.nsIRDFContainerUtils);  getService(Components.interfaces.nsIRDFContainerUtils);
 </pre>  </pre>
     <p>Once you create an anonymous resource, you can create a      <p>Once you create an anonymous resource, you can create a
Line 1809  tree.builder.rebuild( ); Line 1813  tree.builder.rebuild( );
 <pre>  <pre>
 &lt;people names="Brian King,Eric Murphy,Ian Oeschger,Pete Collins,David Boswell"/&gt;  &lt;people names="Brian King,Eric Murphy,Ian Oeschger,Pete Collins,David Boswell"/&gt;
 </pre>  </pre>
    <p>Obviously, the comma is used as the delimiter for this list.    
    The constructor element in <a href="#77046">Example 10-11</a><p>Obviously, the comma is used as the delimiter for this list. The constructor 
    uses JavaScript to break up this string. Example 10-11<a name=  element in <a href="#77046">Example 10-11</a> uses JavaScript to break up this 
    "77046"></a> <i>Binding with in-memory datasource and  string. </p>
    &lt;listbox&gt; template</i></p><p>Example 10-11<a name=
     "77046"></a> <i>Binding with in-memory datasource and &lt;listbox&gt; template</i></p>
 <pre>  <pre>
  &lt;?xml version="1.0"?&gt;   &lt;?xml version="1.0"?&gt;
  &lt;bindings xmlns ="<a href=   &lt;bindings xmlns ="<a href=
Line 1876  tree.builder.rebuild( ); Line 1881  tree.builder.rebuild( );
              &lt;xul:conditions&gt;               &lt;xul:conditions&gt;
                &lt;xul:content uri="?uri"/&gt;                 &lt;xul:content uri="?uri"/&gt;
                &lt;xul:triple subject="?uri"                 &lt;xul:triple subject="?uri"
                        predicate="<a href=                           predicate="<a href=
"http://www.mozdev.org/rdf">http://www.mozdev.org/rdf</a>#people"                              object="?people"/&gt;"http://www.mozdev.org/rdf">http://www.mozdev.org/rdf</a>#people"
                            object="?people"/&gt;
                &lt;xul:member container="?people" child="?person"/&gt;                 &lt;xul:member container="?people" child="?person"/&gt;
                &lt;xul:triple subject="?person"                 &lt;xul:triple subject="?person"
                        predicate="<a href=                           predicate="<a href=
"http://www.mozdev.org/rdf">http://www.mozdev.org/rdf</a>#name"                         object="?name"/&gt;"http://www.mozdev.org/rdf">http://www.mozdev.org/rdf</a>#name"
                            object="?name"/&gt;
              &lt;/xul:conditions&gt;               &lt;/xul:conditions&gt;
              &lt;xul:action&gt;               &lt;xul:action&gt;
                &lt;xul:listitem uri="?person"&gt;                 &lt;xul:listitem uri="?person"&gt;
Line 1908  tree.builder.rebuild( ); Line 1915  tree.builder.rebuild( );
     displayed dynamically in the UI with templates in this      displayed dynamically in the UI with templates in this
     manner.</p>      manner.</p>
     <h2><a name="77112"></a> JSLib RDF Files</h2>      <h2><a name="77112"></a> JSLib RDF Files</h2>
    <p>Working     
    <!--INDEX STARTRANGE==RDF (Resource Description Framework):files:JSLib --><p>Working 
    <!--INDEX STARTRANGE==JSLib libraries:RDF files -->   <!--INDEX STARTRANGE==RDF (Resource Description Framework):files:JSLib -->
    <!--INDEX STARTRANGE==files:RDF:JSLib --> with actual RDF files  <!--INDEX STARTRANGE==JSLib libraries:RDF files -->
    is not easy. However, JSLib (<i><a href=  <!--INDEX STARTRANGE==files:RDF:JSLib -->
    "http://jslib.mozdev.org">http://jslib.mozdev.org</a></i>)  with actual RDF files is not easy. However, JSLib (<i><a href=
    provides an RDF file library that can help you develop an    "http://jslib.mozdev.org">http://jslib.mozdev.org</a></i>) provides an RDF 
    RDF-based application. The library provides many types of error  file library that can help you develop an RDF-based application. The library 
    checking, as well as a friendly abstraction away from the  provides many types of error checking, as well as a friendly abstraction away 
    RDF/XML interfaces of Mozilla (see <a href="#77107">"nsIRDFXML  from the RDF/XML interfaces of Mozilla (see <a href="#77107">"nsIRDFXML Interfaces</a>," 
    Interfaces</a>," later in this chapter). <a href=  later in this chapter). <a href=
    "#77048">Example 10-12</a> shows some common uses of the    "#77048">Example 10-12</a> shows some common uses of the <tt>RDFFile</tt> 
    <tt>RDFFile</tt> class in JSLib. This functionality can be used  class in JSLib. This functionality can be used in situations in which you have 
    in situations in which you have data in RDF that you want to  data in RDF that you want to pull out "manually" and use piece by piece (rather 
    pull out "manually" and use piece by piece (rather than as a  than as a whole datasource in a template). </p>
    whole datasource in a template). Example 10-12<a name=<p>Example 10-12<a name=
    "77048"></a> <i>Creating and modifying an RDF file using    "77048"></a> <i>Creating and modifying an RDF file using JSLib</i></p>
    JSLib</i></p> 
 <pre>  <pre>
  var rdfFileURL = 'chrome://jarfly/content/jar.rdf';   var rdfFileURL = 'chrome://jarfly/content/jar.rdf';
  var gTreeBody = null;   var gTreeBody = null;
Line 2058  tree.builder.rebuild( ); Line 2064  tree.builder.rebuild( );
     <tt>FileUtils</tt> is initialized, which will create a path to      <tt>FileUtils</tt> is initialized, which will create a path to
     the RDF file. If the file doesn't already exist, JSLib      the RDF file. If the file doesn't already exist, JSLib
     automatically creates it.</p>      automatically creates it.</p>
    <p>Finally, the <tt>RDFFile</tt> is created by using the path    
    and a root resource identifier, and the "xFly" namespace is<p>Finally, the <tt>RDFFile</tt> is created by using the path and a root resource 
    used for the data references. <a href="#77052">Example  identifier, and the "xFly" namespace is used for the data references. <a href="#77052">Example 
    10-14</a> shows that the RDF file is ready to have its data  10-14</a> shows that the RDF file is ready to have its data added and deleted. 
    added and deleted. Example 10-14<a name="77052"></a> <i>Data</p>
    updating</i></p><p>Example 10-14<a name="77052"></a> <i>Data updating</i></p>
 <pre>  <pre>
  function update( )   function update( )
  {   {
Line 2072  tree.builder.rebuild( ); Line 2078  tree.builder.rebuild( );
    if(gRDF.doesSeqExist('types'))     if(gRDF.doesSeqExist('types'))
    {     {
      seqLength = gRDF.getSeqSubNodes('types').length;       seqLength = gRDF.getSeqSubNodes('types').length;
     //if(del)gRDF.removeSeq('types',false);
    }     }
    else     else
      gRDF.addSeq('types');       gRDF.addSeq('types');
Line 2136  tree.builder.rebuild( ); Line 2142  tree.builder.rebuild( );
     Mozilla. They can be added seamlessly because RDF provides a      Mozilla. They can be added seamlessly because RDF provides a
     platform-like environment that facilitates the installation and      platform-like environment that facilitates the installation and
     use of new Mozilla software.</p>      use of new Mozilla software.</p>
    <p>All packages, including the ones that come preinstalled with    
    Mozilla (such as the browser, the MailNews component, and the<p>All packages, including the ones that come preinstalled with Mozilla (such 
    en-US language pack), have manifests describing them in terms  as the browser, the MailNews component, and the en-US language pack), have manifests 
    of their relation to other packages. The manifests are  describing them in terms of their relation to other packages. The manifests 
    typically files called <i>contents.rdf</i>, but they may also  are typically files called <i>contents.rdf</i>, but they may also be called 
    be called <i>manifest.rdf</i>. <a href="#77054">Example  <i>manifest.rdf</i>. <a href="#77054">Example 10-15</a> presents a <i>contents.rdf</i> 
    10-15</a> presents a <i>contents.rdf</i> file that describes a  file that describes a new skin for Mozilla. </p>
    new skin for Mozilla. Example 10-15<a name="77054"></a> <i>Skin<p>Example 10-15<a name="77054"></a> <i>Skin manifest</i></p>
    manifest</i></p> 
 <pre>  <pre>
  &lt;?xml version="1.0"?&gt;   &lt;?xml version="1.0"?&gt;
  &lt;RDF:RDF xmlns:RDF="&lt;/td&gt;<i><a href=   &lt;RDF:RDF xmlns:RDF="&lt;/td&gt;<i><a href=
Line 2215  tree.builder.rebuild( ); Line 2220  tree.builder.rebuild( );
     runtime. This latter method will be used here to add an "xFly"      runtime. This latter method will be used here to add an "xFly"
     item to the Tools menu of the Mozilla suite of      item to the Tools menu of the Mozilla suite of
     applications.</p>      applications.</p>
    <p><a href="#77056">Example 10-16</a> shows the    
    <i>contents.rdf</i> manifest format that alerts Mozilla of the<p><a href="#77056">Example 10-16</a> shows the <i>contents.rdf</i> manifest format 
    presence of an overlay, its target in the Mozilla application,  that alerts Mozilla of the presence of an overlay, its target in the Mozilla 
    and the package of which it is a part. Example 10-16<a name=  application, and the package of which it is a part. </p>
 <p>Example 10-16<a name=
     "77056"></a> <i>Overlay for a sample application menu</i></p>      "77056"></a> <i>Overlay for a sample application menu</i></p>
 <pre>  <pre>
  &lt;?xml version="1.0"?&gt;   &lt;?xml version="1.0"?&gt;
Line 2287  tree.builder.rebuild( ); Line 2293  tree.builder.rebuild( );
     File a <a href=      File a <a href=
     "http://mozdev.org/bugs/enter_bug.cgi?product=books">Bug</a>      "http://mozdev.org/bugs/enter_bug.cgi?product=books">Bug</a>
     for chapter 10. <!-- ?php require(NOTES); ? -->      for chapter 10. <!-- ?php require(NOTES); ? -->
    <?php $post_to_list=NO; $author='reviewers@mozdev.org'; $target_page='ch10'; require(NOTES); ?>    <?php $hide_text_control=1; $post_to_list=NO; $author='reviewers@mozdev.org'; $target_page='ch10'; require(NOTES); ?>

Removed from v.1.10  
changed lines
  Added in v.1.14


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>