Diff for /books/www/chapters/ch10.html between versions 1.1 and 1.2

version 1.1, 2002/09/17 21:10:35 version 1.2, 2002/09/23 15:23:31
Line 1 Line 1
 <HTML>  <HTML>
 <HEAD><TITLE>Chapter 10</TITLE></HEAD><BODY BGCOLOR=WHITE><H2>Chapter 10</H2>  <HEAD><TITLE>Chapter 10</TITLE></HEAD><BODY BGCOLOR=WHITE><H2>Chapter 10</H2>
 <H1><A NAME="77061"></A> RDF, RDF Tools, and the Content Model</H1>  <H1><A NAME="77061"></A> RDF, RDF Tools, and the Content Model</H1>
<P><A HREF="ch09.htm#77034">Chapter 9</A> introduced the Resource Description Framework (RDF) as the basis for building display data in the interface, where XUL templates take RDF-based data and transform it into regular widgets. But RDF is used in many other more subtle ways in Mozilla. In fact, it is the technology Mozilla uses for much of its own internal data handling and manipulation.<P><A HREF="ch09.html#77034">Chapter 9</A> introduced the Resource Description Framework (RDF) as the basis for building display data in the 
 interface, where XUL templates take RDF-based data and transform it into regular widgets. But RDF is used in many other more subtle ways in Mozilla. In fact, it is the technology Mozilla uses for much of its own internal data handling and manipulation.
 <P>RDF is, as its name suggests, a framework for integrating many types of data that go into the browser, including bookmarks, mail messages, user profiles, IRC channels, new Mozilla applications, and your collection of sidebar tabs. All these items are sets of data that RDF represents and incorporates into the browser consistently. RDF is used prolifically in Mozilla, which is why this chapter is so dense.  <P>RDF is, as its name suggests, a framework for integrating many types of data that go into the browser, including bookmarks, mail messages, user profiles, IRC channels, new Mozilla applications, and your collection of sidebar tabs. All these items are sets of data that RDF represents and incorporates into the browser consistently. RDF is used prolifically in Mozilla, which is why this chapter is so dense.
 <P>This chapter introduces RDF, provides some detail about how Mozilla uses RDF for its own purposes, and describes the RDF tools that are available on the Mozilla platform. The chapter includes information on special JavaScript libraries that make RDF processing much easier, and on the use of RDF in manifests to represent JAR file contents and cross-platform installation archives to Mozilla.  <P>This chapter introduces RDF, provides some detail about how Mozilla uses RDF for its own purposes, and describes the RDF tools that are available on the Mozilla platform. The chapter includes information on special JavaScript libraries that make RDF processing much easier, and on the use of RDF in manifests to represent JAR file contents and cross-platform installation archives to Mozilla.
 <P>Once you understand the concepts in this chapter, you can make better use of data and metadata in your own application development.  <P>Once you understand the concepts in this chapter, you can make better use of data and metadata in your own application development.
Line 36 Line 37
 <BLOCKQUOTE>Eric wrote a book of unknown information. Eric's computer is 700 MHz and has an Athlon CPU.</BLOCKQUOTE>  <BLOCKQUOTE>Eric wrote a book of unknown information. Eric's computer is 700 MHz and has an Athlon CPU.</BLOCKQUOTE>
 <P>Note that if Eric wrote a poem and a book, it would be possible to have two <I>wrote</I> properties for the same resource. Using the same property to point to separate resources is confusing, however. Instead, RDF containers (see the section <A HREF="#77069">"RDF containers</A>," later in this chapter) are the best way to organize data that would otherwise need a single property to branch in this way.  <P>Note that if Eric wrote a poem and a book, it would be possible to have two <I>wrote</I> properties for the same resource. Using the same property to point to separate resources is confusing, however. Instead, RDF containers (see the section <A HREF="#77069">"RDF containers</A>," later in this chapter) are the best way to organize data that would otherwise need a single property to branch in this way.
 <H4><A NAME="77064"></A> RDF URIs relating to namespaces</H4>  <H4><A NAME="77064"></A> RDF URIs relating to namespaces</H4>
<P>The  <!--INDEX RDF (Resource Description Framework):data model:URIs -->  <!--INDEX data model (RDF):URIs -->  <!--INDEX URIs (Universal Resource Identifiers):RDF:namespaces -->  <!--INDEX namespaces:RDF, URIs and --> URIs used in RDF can be part of the element namespace. (See <A HREF="ch02.htm#77053">"The XUL Namespace" in Chapter 2</A> and in <A HREF="ch07.htm#77031">"Namespaces and XBL" in Chapter 7</A> for more information about XML namespaces.) This use is especially true for properties. Some namespaces can be created from previous examples:<P>The  <!--INDEX RDF (Resource Description Framework):data model:URIs -->  <!--INDEX data model (RDF):URIs -->  <!--INDEX URIs (Universal 
 Resource Identifiers):RDF:namespaces -->  <!--INDEX namespaces:RDF, URIs and --> URIs used in RDF can be part of the element namespace. (See <A 
 HREF="ch02.html#77053">"The XUL Namespace" in Chapter 2</A> and in <A HREF="ch07.html#77031">"Namespaces and XBL" in Chapter 7</A> for more information about XML namespaces.) This use is especially true for properties. Some namespaces can be created from previous examples:
 <PRE>xmlns:rdf="<A HREF="http://www.w3.org/1999/02/22-rdf-syntax-ns">http://www.w3.org/1999/02/22-rdf-syntax-ns</A>#"  <PRE>xmlns:rdf="<A HREF="http://www.w3.org/1999/02/22-rdf-syntax-ns">http://www.w3.org/1999/02/22-rdf-syntax-ns</A>#"
 xmlns:book="<A HREF="http://www.oreilly.com/rdf">http://www.oreilly.com/rdf</A>#"  xmlns:book="<A HREF="http://www.oreilly.com/rdf">http://www.oreilly.com/rdf</A>#"
 xmlns:comp="my.computer.hardware#"</PRE>  xmlns:comp="my.computer.hardware#"</PRE>
Line 292  xmlns:location="fly-location#"&gt; Line 295  xmlns:location="fly-location#"&gt;
    &lt;/rdf:Description&gt;     &lt;/rdf:Description&gt;
  &lt;/rdf:RDF&gt;</PRE>   &lt;/rdf:RDF&gt;</PRE>
   
<P><A HREF="#77032">Example 10-4</A> shows the RDF data used in several template examples in <A HREF="ch09.htm#77034">Chapter 9</A>. <A HREF="ch09.htm#77022">Example 9-4</A> includes the <I>10-4.rdf</I> datasource, as do many of those templates. You can copy the data out of <A HREF="#77032">Example 10-4</A> and into a file of the same name to use as a datasource.<P><A HREF="#77032">Example 10-4</A> shows the RDF data used in several template examples in <A HREF="ch09.html#77034">Chapter 9</A>. <A 
 HREF="ch09.html#77022">Example 9-4</A> includes the <I>10-4.rdf</I> datasource, as do many of those templates. You can copy the data out of <A 
 HREF="#77032">Example 10-4</A> and into a file of the same name to use as a datasource.
 <H2><A NAME="77077"></A> The Mozilla Content Model</H2>  <H2><A NAME="77077"></A> The Mozilla Content Model</H2>
 <P>One theme  <!--INDEX content model:overview -->  <!--INDEX Gecko rendering engine:Mozilla content model --> of this book-and a general goal of the Mozilla development environment-is that developers can create real applications using many of the same technologies they use to create a web page. The Gecko rendering engine, sitting at the heart of Mozilla and happily rendering web content, XML files, XUL interfaces, and whatever else they can support, is what makes this type of development possible. But how does Gecko know what to render and how? How can RDF data be handed over so that Gecko knows how to draw it?  <P>One theme  <!--INDEX content model:overview -->  <!--INDEX Gecko rendering engine:Mozilla content model --> of this book-and a general goal of the Mozilla development environment-is that developers can create real applications using many of the same technologies they use to create a web page. The Gecko rendering engine, sitting at the heart of Mozilla and happily rendering web content, XML files, XUL interfaces, and whatever else they can support, is what makes this type of development possible. But how does Gecko know what to render and how? How can RDF data be handed over so that Gecko knows how to draw it?
 <P>When a browser uses the same engine to draw everything-its own interface as well as the various kinds of content it supports-that engine treats everything as content. Gecko needs a way to understand all the various parts of the Mozilla browser itself-such as the sidebar, the toolbars, and the mail folders and mail messages-as resources it can render and display in the Mozilla chrome. This approach to the Mozilla application interface is called the content model.  <P>When a browser uses the same engine to draw everything-its own interface as well as the various kinds of content it supports-that engine treats everything as content. Gecko needs a way to understand all the various parts of the Mozilla browser itself-such as the sidebar, the toolbars, and the mail folders and mail messages-as resources it can render and display in the Mozilla chrome. This approach to the Mozilla application interface is called the content model.
Line 349  xmlns:location="fly-location#"&gt; Line 354  xmlns:location="fly-location#"&gt;
 <TR><TD>  Composite datasource</TD>     <TD>  A composite datasource may be a combination of any of the datasources previously listed. RDF allows you to merge different graphs.</TD></TR></TABLE><P>  <TR><TD>  Composite datasource</TD>     <TD>  A composite datasource may be a combination of any of the datasources previously listed. RDF allows you to merge different graphs.</TD></TR></TABLE><P>
   
 <H2><A NAME="77081"></A> RDF Components and Interfaces</H2>  <H2><A NAME="77081"></A> RDF Components and Interfaces</H2>
<P>Once you are comfortable using XUL templates to display RDF data (see <A HREF="ch09.htm#77034">Chapter 9</A>), you should explore the various ways to create and change that data. In Mozilla, data is generally RDF, since all data in Mozilla is either represented formally in RDF or passed through the RDF-based content model for display. Use the tools described in this section to manipulate RDF and the data it represents.<P>Once you are comfortable using XUL templates to display RDF data (see <A HREF="ch09.html#77034">Chapter 9</A>), you should explore the various 
 ways to create and change that data. In Mozilla, data is generally RDF, since all data in Mozilla is either represented formally in RDF or passed through the RDF-based content model for display. Use the tools described in this section to manipulate RDF and the data it represents.
 <P>Mozilla has a great set of interfaces for creating, manipulating, and managing RDF, and it also provides ready-made RDF components that represent datasources used in Mozilla. Think of RDF interfaces as ways to manipulate RDF directly and of RDF components as sets of the interfaces already associated with a particular kind of data, such as bookmarks. Interfaces tend to deal with the RDF model itself, without regard to the kinds of data being handled, while RDF components give you control over specific Mozilla data. See the next two sections for more information on RDF interfaces and components.  <P>Mozilla has a great set of interfaces for creating, manipulating, and managing RDF, and it also provides ready-made RDF components that represent datasources used in Mozilla. Think of RDF interfaces as ways to manipulate RDF directly and of RDF components as sets of the interfaces already associated with a particular kind of data, such as bookmarks. Interfaces tend to deal with the RDF model itself, without regard to the kinds of data being handled, while RDF components give you control over specific Mozilla data. See the next two sections for more information on RDF interfaces and components.
 <H3><A NAME="77082"></A> What Is an RDF Component?</H3>  <H3><A NAME="77082"></A> What Is an RDF Component?</H3>
 <P>An RDF  <!--INDEX RDF (Resource Description Framework):components, overview -->  <!--INDEX components:RDF, overview --> component may implement any number of the general RDF interfaces described here, in addition to special interfaces for accessing and controlling the data the datasource represents. For example, <TT>@mozilla.org/rdf/data-source;1?name=internetsearch</TT> is an RDF component used to control Mozilla's internet searching facility. In Mozilla, a component can act as a library of code specific to a given set of data or domain. The <TT> <!--INDEX internetsearch component --> internetsearch</TT> component is instantiated and used to recall text entered in a previous search:  <P>An RDF  <!--INDEX RDF (Resource Description Framework):components, overview -->  <!--INDEX components:RDF, overview --> component may implement any number of the general RDF interfaces described here, in addition to special interfaces for accessing and controlling the data the datasource represents. For example, <TT>@mozilla.org/rdf/data-source;1?name=internetsearch</TT> is an RDF component used to control Mozilla's internet searching facility. In Mozilla, a component can act as a library of code specific to a given set of data or domain. The <TT> <!--INDEX internetsearch component --> internetsearch</TT> component is instantiated and used to recall text entered in a previous search:
Line 455  isAnon = RDF.isAnonymousResource(anonRes Line 461  isAnon = RDF.isAnonymousResource(anonRes
 <PRE>myName = RDF.GetLiteral('Eric');</PRE>  <PRE>myName = RDF.GetLiteral('Eric');</PRE>
 <P>Variations on this function are <TT>GetIntLiteral</TT> and <TT>GetDateLiteral</TT>.  <P>Variations on this function are <TT>GetIntLiteral</TT> and <TT>GetDateLiteral</TT>.
 <H4><A NAME="77088"></A> Registering and unregistering datasources</H4>  <H4><A NAME="77088"></A> Registering and unregistering datasources</H4>
<P>If you create  <!--INDEX datasources:registering -->  <!--INDEX registering:datasources -->  <!--INDEX RDF (Resource Description Framework):datasources, registering --> a Mozilla application that uses the same datasource or RDF resources in different ways, you may want to register the datasource with Mozilla. When you register a datasource, you register it as a component in Mozilla (see <A HREF="ch08.htm#77062">"Component Manager" in Chapter 8</A> for more information on Mozilla's component model), which means it can be accessed and used as easily as any other XPCOM component, and from anywhere in Mozilla.<P>If you create  <!--INDEX datasources:registering -->  <!--INDEX registering:datasources -->  <!--INDEX RDF (Resource Description 
 Framework):datasources, registering --> a Mozilla application that uses the same datasource or RDF resources in different ways, you may want to register the datasource with Mozilla. When you register a datasource, you register it as a component in Mozilla (see <A HREF="ch08.html#77062">"Component Manager" in Chapter 8</A> for more information on Mozilla's component model), which means it can be accessed and used as easily as any other XPCOM component, and from anywhere in Mozilla.
 <P>To register a datasource, call the <TT> <!--INDEX RegisterDatasource method --> RegisterDatasource</TT> method of the RDF Service. In this example, the datasource already exists and is assigned to a variable named <I>myDatasource</I>:  <P>To register a datasource, call the <TT> <!--INDEX RegisterDatasource method --> RegisterDatasource</TT> method of the RDF Service. In this example, the datasource already exists and is assigned to a variable named <I>myDatasource</I>:
 <PRE>RDF.RegisterDataSource(myDatasource, false);</PRE>  <PRE>RDF.RegisterDataSource(myDatasource, false);</PRE>
 <P>In this case, <I>myDatasource</I> is the datasource name, and the <TT>false</TT> parameter specifies that this datasource is not replacing a datasource with the same name. Once a datasource is registered with the component manager in this way, it can be retrieved by name and associated with another instance:  <P>In this case, <I>myDatasource</I> is the datasource name, and the <TT>false</TT> parameter specifies that this datasource is not replacing a datasource with the same name. Once a datasource is registered with the component manager in this way, it can be retrieved by name and associated with another instance:
Line 1015  Example 10-15<A NAME="77054"></A> Line 1022  Example 10-15<A NAME="77054"></A>
 <P>The next section gives more information on the theme, such as the author, the theme name, and a description. The <TT>chrome:packages</TT> structure that completes the manifest describes the packages to which this theme should be applied. All major components of the Netscape browser are listed in this example-including the AIM client that is not a part of Mozilla-but is skinned by themes such as Modern.  <P>The next section gives more information on the theme, such as the author, the theme name, and a description. The <TT>chrome:packages</TT> structure that completes the manifest describes the packages to which this theme should be applied. All major components of the Netscape browser are listed in this example-including the AIM client that is not a part of Mozilla-but is skinned by themes such as Modern.
 <H3><A NAME="77114"></A> RDF and Dynamic Overlays</H3>  <H3><A NAME="77114"></A> RDF and Dynamic Overlays</H3>
 <P>Manifests can <!--INDEX dynamic overlays:RDF -->  <!--INDEX overlays:RDF -->  <!--INDEX RDF (Resource Description Framework):manifest files:dynamic overalys and -->  <!--INDEX manifests:RDF:dynamic overlays and -->  also add new menu items to existing Mozilla menus. When you add a new package to Mozilla, you should make it accessible from within the browser application, where users can access it easily. This is where RDF and dynamic overlays come in.  <P>Manifests can <!--INDEX dynamic overlays:RDF -->  <!--INDEX overlays:RDF -->  <!--INDEX RDF (Resource Description Framework):manifest files:dynamic overalys and -->  <!--INDEX manifests:RDF:dynamic overlays and -->  also add new menu items to existing Mozilla menus. When you add a new package to Mozilla, you should make it accessible from within the browser application, where users can access it easily. This is where RDF and dynamic overlays come in.
<P>The RDF you provide in your package makes it possible for the chrome registry, discussed in <A HREF="ch06.htm#77063">Chapter 6</A>, to find, understand, and register your new files. Packages must be registered if they are to be skinned, localized, or accessed using the special tools Mozilla provides (e.g., the chrome URL or XPConnect to the XPCOM libraries). If you do not register your package by providing the necessary RDF manifests, it cannot be accessed except as a disparate collection of files in the browser's main content window, which is not what you want.<P>The RDF you provide in your package makes it possible for the chrome registry, discussed in <A HREF="ch06.html#77063">Chapter 6</A>, to find, 
 understand, and register your new files. Packages must be registered if they are to be skinned, localized, or accessed using the special tools Mozilla provides (e.g., the chrome URL or XPConnect to the XPCOM libraries). If you do not register your package by providing the necessary RDF manifests, it cannot be accessed except as a disparate collection of files in the browser's main content window, which is not what you want.
 <P>You can add overlays in Mozilla in two ways: import them explicitly by using an overlay processing instruction at the top of the XUL file into which items in the overlay file are to be "composed," or use RDF to register and load overlay files at runtime. This latter method will be used here to add an "xFly" item to the Tools menu of the Mozilla suite of applications.  <P>You can add overlays in Mozilla in two ways: import them explicitly by using an overlay processing instruction at the top of the XUL file into which items in the overlay file are to be "composed," or use RDF to register and load overlay files at runtime. This latter method will be used here to add an "xFly" item to the Tools menu of the Mozilla suite of applications.
 <P><A HREF="#77056">Example 10-16</A> shows the <I>contents.rdf</I> manifest format that alerts Mozilla of the presence of an overlay, its target in the Mozilla application, and the package of which it is a part.  <P><A HREF="#77056">Example 10-16</A> shows the <I>contents.rdf</I> manifest format that alerts Mozilla of the presence of an overlay, its target in the Mozilla application, and the package of which it is a part.
   
Line 1041  Example 10-16<A NAME="77056"></A> Line 1049  Example 10-16<A NAME="77056"></A>
    &lt;/RDF:Seq&gt;     &lt;/RDF:Seq&gt;
  &lt;/RDF:RDF&gt;</PRE>   &lt;/RDF:RDF&gt;</PRE>
   
<P>The manifest in <A HREF="#77056">Example 10-16</A> names the file <I>xflyOverlay.xul</I> as an overlay. Then it names <I>tasksOverlay.xul</I> as the base file into which the contents are placed. In this case, the overlays can overlay other overlay files arbitrarily. An overlay can define new content anywhere in the application. Overlays are often responsible for putting new items in menus. As long as the target and overlay <TT>id</TT>s match, any two RDF datasources are merged. You can try this example by putting a single new menu item in an overlay structure like the one shown in <A HREF="#77058">Example 10-17</A>. Save it as <I>xflyOverlay.xul</I> in the <I>xfly</I> content subdirectory and use the manifest information in <A HREF="#77056">Example 10-16</A> as part of the packaging process described in <A HREF="ch06.htm#77063">Chapter 6</A>.<P>The manifest in <A HREF="#77056">Example 10-16</A> names the file <I>xflyOverlay.xul</I> as an overlay. Then it names <I>tasksOverlay.xul</I> 
 as the base file into which the contents are placed. In this case, the overlays can overlay other overlay files arbitrarily. An overlay can define new content anywhere in the application. Overlays are often responsible for putting new items in menus. As long as the target and overlay <TT>id</TT>s match, any two RDF datasources are merged. You can try this example by putting a single new menu item in an overlay structure like the one shown in <A HREF="#77058">Example 10-17</A>. Save it as <I>xflyOverlay.xul</I> in the <I>xfly</I> content subdirectory and use the manifest information in <A HREF="#77056">Example 10-16</A> as part of the packaging process described in <A HREF="ch06.html#77063">Chapter 6</A>.
   
 Example 10-17<A NAME="77058"></A>  Example 10-17<A NAME="77058"></A>
 <I>Overlay for an xFly menu item in the browser</I>  <I>Overlay for an xFly menu item in the browser</I>

Removed from v.1.1  
changed lines
  Added in v.1.2


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