Resources.xml Tutorial

What is it? What does it do?

Resources.xml is the central repository for data that is common across different pages in your application. This is accomplished by the folowing two methods
  1. Store common formatting for the header and side bar (can be actor specific). Allows you to put the side bar and header in one place so they can be repeated on every page. You can also have diffrent formats for different actors (eg customer, admin, etc)
  2. Central repository for commonly used "objects" on pages. If you had a block of code that is repeated several times you can save by time by putting it in resourcse then just put a pointer back to it wherever you need to use it. This not only saves you time when coding up the page, but if you have to go back and change it you only have to make the change in one place.

We will now go through setting up the Resources

Setting up resources with user information for use with Page.xsl

For information on how Page.xsl uses resources please refer to Page.xsl tutorial

The first thing we will need to do is to create the resources file with the following text in it.
<resources>
 <class name="users">
  <class name="customer">
   <meta>
    <name>John Q. Customer</name>
    <userType>Customer</userType>
   </meta>
  </class>
 </class>
</resources>

This sets up the user John Q. Customer with the usertype "Customer". The class structure of the resources.xml file is hierarchical so the path to this user is user/customer.

This information doesn't do any good unless we use it somewhere so we should create a page to use this information. We will create a page with the following text (for this example we will use page not in the root directory for more information refer to the main tutorial)
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="../../page.xsl"?>
<html>
<head>
  <meta>
    <actor id="users/customer"/>
    <blade root="../../"/>
  </meta>
</head>
<body>
  hello world!
</body>
</html>


If we view our test page we can see how the username and usertype were automatically put in the header that is becuase of the <actor id="users/customer"/> line in our sample page told page.xsl that this page was for the actor users/customer and page.xsl looked up the appropriate information from the resources.xml file

We can now proceed and add additional data to our resourcse file. Say we wanted to put a title on the page that would span every page for every user we could just edit our resources.xml file to look like this:
<resources>
 <class name="users">
   <formatting>
     <!-- all users share the same title -->
     <title>Sample Page</title>
   </formatting>
  <class name="customer">
   <meta>
    <name>John Q. Customer</name>
    <userType>Customer</userType>
   </meta>
  </class>
 </class>
</resources>

If you refresh your sample page you will notice that the title has been changed to "Sample Page" this happens becuase of the heirarchial nature of the resources file.
Now we can finish up defining the formatting for this user. We will now change resources to have the folowing text:
<resources>
 <class name="users">
  <formatting>
    <!-- all users share the same title -->
    <title>Sample Page</title>
  </formatting>
   <class name="customer">
    <meta>
     <name>John Q. Customer</name>
     <userType>Customer</userType>
    </meta>
     <formatting>
       <title>Sample Page for Customer</title>
       <top> <!-- formatting options for the header -->
         <table width="100%"  cellspacing="0" cellpadding="0">
           <tr>
             <td>
               <!-- NOTE: it is important to give the navbar tabstrip an id of "navbar" -->
               <tabstrip theme="otis" type="rollover" id="navbar">
                 <tab id="tab_home"  noclick="noclick">Home<  ab>
                 <tab id="tab_events" noclick="noclick">Events<  ab>
                 <tab id="tab_action" noclick="noclick">Action Items<  ab>
                 <tab id="tab_search" noclick="noclick">Search<  ab>
                 <tab id="tab_setup" noclick="noclick">Account Setup<  ab>
               </tabstrip>
             </td>
           </tr>
         </table>
       </top>
      <side width="100px"> <!--  formatting options for the sidebar -->
          <br/>
          <pane header="Quick Links" theme="y-blue">
            My Stocks<br/>
            My Weather<br/>
            My Traffic<br/>
          </pane>
      </side>
    </formatting>
    </class>
   </class>
 </resources>

If we refresh our sample page we will notice that we now have a tabstrip for a navigation bar and a sidebar.

Things to note: